Issue with declaring structure variable and array under instance label in xdc fi [message #481192] |
Thu, 20 August 2009 05:07 |
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 #481409 is a reply to message #481192] |
Thu, 20 August 2009 20:30 |
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 #482334 is a reply to message #481409] |
Wed, 26 August 2009 09:32 |
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 #482581 is a reply to message #482517] |
Thu, 27 August 2009 07:21 |
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 17:33 |
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(¶ms);
for (i = 0; i < Mod_ARR_SIZE; i++) {
params.myArr[i] = i; /* ERROR: myArr has just 2 elements */
}
inst = Mod_create(¶ms, 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(¶ms);
inst = Mod_create(¶ms, 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
>
|
|
|
Powered by
FUDForum. Page generated in 0.05689 seconds