Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Real-Time Software Components (RTSC) » Issue with declaring structure variable and array under instance label in xdc fi
Issue with declaring structure variable and array under instance label in xdc fi [message #481192] Thu, 20 August 2009 01:07 Go to next message
Eclipse User
Originally posted by: ravindranath.a.ti.com

Hi,

I have to declare a variable of type array/structure in my xdc file under
instance label so that the <module>_Params structure will contain the
structure/array variable.

But xdc is giving error saying that element should be statically
initialized. Can anybody know how to initialize the structure
variable/array declared under instance label with some default values? I
am using xdctools_3_15_00_50.

Regards,
Ravindranath Andela
Re: Issue with declaring structure variable and array under instance label in xdc fi [message #481376 is a reply to message #481192] Thu, 20 August 2009 12:57 Go to previous messageGo to next message
Dave Russo is currently offline Dave Russo
Messages: 172
Registered: July 2009
Senior Member
The instance config parameters must be initialized in the .xdc file.
This is because instance config parameters are used to define a default
parameters structure (<module>_Params) which is used when instances are
created and the user passes in NULL for the parameters.

However the instance state object itself may be initialized in the
module's .xs file; see
http://rtsc.eclipse.org/docs-tip/Extending_xdc.runtime_Gates /Example_1
for an example of initializing a buffer declared in the .xdc file to all
zeros. Look at the Lock.xdc file and the Lock.xs file.

Ravindranath wrote:
> Hi,
>
> I have to declare a variable of type array/structure in my xdc file
> under instance label so that the <module>_Params structure will contain
> the structure/array variable.
>
> But xdc is giving error saying that element should be statically
> initialized. Can anybody know how to initialize the structure
> variable/array declared under instance label with some default values?
> I am using xdctools_3_15_00_50.
>
> Regards,
> Ravindranath Andela
>
>
>
>
>
Re: Issue with declaring structure variable and array under instance label in xdc fi [message #481409 is a reply to message #481192] Thu, 20 August 2009 16:30 Go to previous messageGo to next message
Dave Russo is currently offline Dave Russo
Messages: 172
Registered: July 2009
Senior Member
The following Carr module generates an error because we require
_explicit_ initialization of all instance configs.

Although it may be possible to initialize these in the module's .xs
file, it requires accessing a structure we don't yet document. So,
instance configs should be _fully_ initialized in the .xdc file.

module CArr {

instance:
config int iarr[2]; // fails: due to lack of initial values
}

The following alternatives also fail:
config int iarr[2] = [0]; // fails: too few initial values
and
config int iarr[2] = [0,0,0]; // fails: too many initial values

But the following variants do work:
config int iarr[2] = [0,0]; // works: just the right number
and
config int iarr[] = [0, 0]; // works: same as above

So, there is really no reason to ever explicitly place a dimension in
the array. Doing so only makes it clearer to the reader how many
initial values appear in the initializer.


Ravindranath wrote:
> Hi,
>
> I have to declare a variable of type array/structure in my xdc file
> under instance label so that the <module>_Params structure will contain
> the structure/array variable.
>
> But xdc is giving error saying that element should be statically
> initialized. Can anybody know how to initialize the structure
> variable/array declared under instance label with some default values?
> I am using xdctools_3_15_00_50.
>
> Regards,
> Ravindranath Andela
>
>
>
>
>
Re: Issue with declaring structure variable and array under instance label in xdc fi [message #482324 is a reply to message #481409] Wed, 26 August 2009 05:14 Go to previous messageGo to next message
Eclipse User
Originally posted by: ravindranath.a.ti.com

my requirement is such that dimension of the array needs to be set
thorough the cfg file. And in xdc/xs file array elements should be
initialized.

Regards,
Ravindranath Andela
Re: Issue with declaring structure variable and array under instance label in xdc fi [message #482334 is a reply to message #481409] Wed, 26 August 2009 05:32 Go to previous messageGo to next message
Eclipse User
Originally posted by: ravindranath.a.ti.com

dave,
you said

Although it may be possible to initialize these in the module's .xs
> file, it requires accessing a structure we don't yet document. So,
> instance configs should be _fully_ initialized in the .xdc file.


please let me know how to initialize arrays and structures in params
through xs file.

dave russo wrote:

> The following Carr module generates an error because we require
> _explicit_ initialization of all instance configs.

> Although it may be possible to initialize these in the module's .xs
> file, it requires accessing a structure we don't yet document. So,
> instance configs should be _fully_ initialized in the .xdc file.

> module CArr {

> instance:
> config int iarr[2]; // fails: due to lack of initial values
> }

> The following alternatives also fail:
> config int iarr[2] = [0]; // fails: too few initial values
> and
> config int iarr[2] = [0,0,0]; // fails: too many initial values

> But the following variants do work:
> config int iarr[2] = [0,0]; // works: just the right number
> and
> config int iarr[] = [0, 0]; // works: same as above

> So, there is really no reason to ever explicitly place a dimension in
> the array. Doing so only makes it clearer to the reader how many
> initial values appear in the initializer.


> Ravindranath wrote:
>> Hi,
>>
>> I have to declare a variable of type array/structure in my xdc file
>> under instance label so that the <module>_Params structure will contain
>> the structure/array variable.
>>
>> But xdc is giving error saying that element should be statically
>> initialized. Can anybody know how to initialize the structure
>> variable/array declared under instance label with some default values?
>> I am using xdctools_3_15_00_50.
>>
>> Regards,
>> Ravindranath Andela
>>
>>
>>
>>
>>
Re: Issue with declaring structure variable and array under instance label in xdc fi [message #482517 is a reply to message #482324] Wed, 26 August 2009 17:01 Go to previous messageGo to next message
Dave Russo is currently offline Dave Russo
Messages: 172
Registered: July 2009
Senior Member
Do you need the instance state to contain a config time
generated/initialized array whose length is settable during
configuration? If so, you don't need to modify the params structure.

Static arrays can be created (and placed) via Memory.staticPlace() when
you create static instances; see
http://rtsc.eclipse.org/cdoc-tip/index.html#xdc/runtime/Memo ry.html#static.Place.

An example of it's usage is the HeapMin module in the xdc.runtime
package; see HeapMin.xdc and HeapMin.xs.

Can you describe a bit more about what you are trying to do? It would
make it easier to help craft an appropriate solution.

Ravindranath wrote:
> my requirement is such that dimension of the array needs to be set
> thorough the cfg file. And in xdc/xs file array elements should be
> initialized.
>
> Regards,
> Ravindranath Andela
>
>
>
>
>
Re: Issue with declaring structure variable and array under instance label in xdc fi [message #482581 is a reply to message #482517] Thu, 27 August 2009 03:21 Go to previous messageGo to next message
Eclipse User
Originally posted by: ravindranath.a.ti.com

dave,

For example i have the following configuration in xdc file

config UInt32 ARR_SIZE = 2;

instance:

config UInt32 myArr[ARR_SIZE ]= [0,0] /* here normal procedure is to
initialize all the 2 elements. Suppose if ARR_SIZE is changed to a higher
value through the cfg file static initialization of myArr gives error. To
avoid this static initialization of myArr needs to be done some how
either in xs file or some other place.

why we need this type of declaration is application users does not like
to have pointers to which they have to declare variables and assign them
to pointers in Params.

Regards,
Ravindranath Andela
Re: Issue with declaring structure variable and array under instance label in xdc fi [message #482731 is a reply to message #482581] Thu, 27 August 2009 13:33 Go to previous message
Dave Russo is currently offline Dave Russo
Messages: 172
Registered: July 2009
Senior Member
If I understand what you're looking for, I don't believe it's possible.

It sounds like you want specify the size of a module instance's creation
parameters at configuration time. For example

Mod.xdc:
module Mod {
config Int ARR_SIZE = 2;
instance:
config Int myArr[ARR_SIZE] = [0, 0];
}

User's .cfg script:
var Mod = xdc.useModule("...Mod");
Mod.ARR_SIZE = 10;

User's .c code:
main() {
Mod_Params params;
Mod_Handle inst;

Mod_Params_init(&params);
for (i = 0; i < Mod_ARR_SIZE; i++) {
params.myArr[i] = i; /* ERROR: myArr has just 2 elements */
}
inst = Mod_create(&params, NULL);
}

But the .c file is, in general, compiled before the configuration script
is run. As a result, the space allocated by the compiler on the stack
for params (i.e., sizeof(Mod_Params)), can't change as the result of
configuration.

An alternative might be to "allocate" the array in the instance object
itself and allow the user to initialize this array via an instance
method, say Mod_initArray(). The params structure can be initialized to
a default array whose size and values are controlled by config
parameters. This makes the instance usable even if the user does not
call Mod_initArray().

User's .c code:
Int myArr[10] = [1, ...];

main() {
Mod_Params params;
Mod_Handle inst;

Mod_Params_init(&params);
inst = Mod_create(&params, NULL);
Mod_initArray(inst, myArr, sizeof(arr));
}

Ravindranath wrote:
> dave,
>
> For example i have the following configuration in xdc file
>
> config UInt32 ARR_SIZE = 2;
>
> instance:
>
> config UInt32 myArr[ARR_SIZE ]= [0,0] /* here normal procedure is to
> initialize all the 2 elements. Suppose if ARR_SIZE is changed to a
> higher value through the cfg file static initialization of myArr gives
> error. To avoid this static initialization of myArr needs to be done
> some how either in xs file or some other place.
>
> why we need this type of declaration is application users does not
> like to have pointers to which they have to declare variables and
> assign them to pointers in Params.
>
> Regards,
> Ravindranath Andela
>
Previous Topic:Getting module id from an instance
Next Topic:Using GateSwi_Handle_upCast
Goto Forum:
  


Current Time: Thu Apr 17 05:51:32 EDT 2014

Powered by FUDForum. Page generated in 0.07388 seconds