This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Initializing RTSC struct values in .xdc file

Hi,

Can values of a struct be statically initialized in a module .xdc file?  For example, I've got the following module:

module MyModule
{
 
   struct s{
      Bits16 Spare0;
      Bits16 Spare1;
      Bits16 Num1;
      Bits16 Num2;      
   };
      
   instance:
   
      config s MyStruct = {0xFFFF, 0, 0, 0};
   
   internal:        
      struct Instance_State
      {
         s              MyStruct;         
      }
      
} // module MyModule

I'd like to be able to do something like obj.MyStruct.Spare0 = params.MyStruct.Spare0 in the MyModule.xs file and have the default value be 0xFFFF if not set to something else in the .cfg file.  Is that the correct way to initialize the values for MyStruct?  I keep getting errors as follows regarding the 'config s MyStruct = ...' line:

mismatched input '0xFFFF' expecting RCUR
mismatched input ',' expecting SEMI
no viable alternative at input ','

Also, do the values declared in the .xdc file for structs effect the default values for MyModule_params variables when dynamically creating instances?

Nick

  • Looking at TI's RTSC modules, it appears that structs are generally only used as metaonly variables.  Is there a reason for that?  Do I have to do something with a metaonly struct to initialize my config struct variable?

  • I believe I found the solution to my first question.  I think .xdc struct can be initialized with:

    config s MyStruct = {Spare0:0xFFFF, Spare1:0, Num0:0, Num1:0};

    I'm not sure how to initialize arrays within a struct.  Lines a follows cause errors at the [ ] characters:

    config s MyStruct = {Spare[0]:0xFFFF, Spare[1]:0, Num[0]:0, Num[1]:0};

    I think these default values only effect statically created instances and params in the meta-domain (.cfg or .xs files).  To get around that for dynamic instances, I think I can write a Params_init() function in C.

  • You might be able to do it with an encoded type:

    http://rtsc.eclipse.org/docs-tip/Using_Encoded_Types

    If you work it out, perhaps you could post an example.  I'd be interested, especially if you can crack the representation of arrays.  The page above gives an example with bitfields which is slightly different.

  • Nick,
    that's a correct way to initialize a structure. It's defined in the language spec here, under the heading "initializer" and "struct-initializer".

    The default config parameter values specified in an XDC file have effect in both domains.
    If you create a dynamic instance of MyModule, and you pass NULL for 'params' argument, the default values will be used. When you call Params_init(&p), the default values from the XDC spec are copied to p. When you call
    MyModule_create(NULL, NULL);
    it's a shorthand for
    MyModule_Params_init(&p);
    MyModule_create(&p, NULL);

    About the arrays, I'll have to check some cases first before I answer. I remember that some cases that should be working do not compile. What's the declaration of your structure s that contains arrays?

  • I have a struct with arrays is similar to the above declaration,
       struct s{
          Bits16 Spare;
          Bits16 Num[2];     
       };
          

    I haven't tried yet, but I think this can be initialized with something like:

    config s MyStruct = {Spare:0, Num:{0, 0}};

     

    Just to be clear, you said that dynamic params variables inherit the values defined in the .xdc file?  So, for my first example the params would be a memory initialized to {0xFFFF, 0, 0, 0} after calling Params_init(&params) ?  Otherwise, I need to figure out how to override the default Params_init function (which looks like is possible based on the MessageQ module).

    Thanks,

    Nick

     


     

  • The initializer in that case is
    config s MyStruct = {Spare: 0, Num: [0, 0]};

    You probably want to make it little bit more flexible with a constant that keeps track of the size of the array:
    const UInt NUMSIZE = 2;
    because you'll probably need to traverse that array in your runtime code, and it might be better to use MyModule_NUMSIZE instead of a literal constant.

    Nick Bedbury78040 said:

    Just to be clear, you said that dynamic params variables inherit the values defined in the .xdc file?  So, for my first example the params would be a memory initialized to {0xFFFF, 0, 0, 0} after calling Params_init(&params) ?  Otherwise, I need to figure out how to override the default Params_init function (which looks like is possible based on the MessageQ module).

    Yes. The purpose of Params_init is to initialize 'params' with the values you specified in the xdc file.