I should be able to use packed structures with TI Code Generation Tools v7.2.2. Is there anyway can I declare a structure to be packed within an XDC spec file? If not, is the only work around to declare straight ".h" files for the structures I want to define using this variable? I would prefer a RTSC oriented solution.

It is possible to define a packed data structure. In fact, this is done
by the xdc.runtime.Log module for Log_Event. It takes some effort,
however. You must:
1. define the type as an @Encoded type in the .xdc file (to tell
the tools that you'll take care of definig the structure
yourself)
2. create two C headers files named Mod__prologue.h and
Mod_epilogue.h, which contain the C definition of the
structure
3. define some functions in Mod.xs to tell the tools how the
structure is aligned, its size and a C expression used to
pack the structure when it is statically initialized.

I got around to trying this. A couple of notes for anyone else attempting to do this:

- Your .xdc file must be declared with the @CustomHeader attribute
- You must declare the structure as metaonly in the xdc file, then declare the @encoded typedef to whatever you want it to be in the C.
- There are two underscores in mod__epilogue.h and mod__prologue.h
- You only need to declare the structure in mod__prologue.h; mod__epilogue can remain empty.
- The desc argument passed into the eType$encode(desc) function is the metadomain representation of the structure. I am not exactly sure if this data can actually be used for static initialization of the structure.
- You must add the proper compiler option to your package.bld file to enable the GCC extensions (AKA packed). This will look something like:

//Helpful description from Assert.xs
/* The three functions below must exist for each encoded type defined in this
* module's spec. sizeof and alignof are invoked if the encoded type is used
* in a structure, while encode is used when a value of the encoded type
* needs to be represented on the target.
* In this case, the encoded type is 'Id', which is why the function names
* start with that prefix.
*/
function Foo_s$alignof()
{
return 1;
}
//TODO: We might be able to / need to do more complicated things here
function Foo_s$encode(desc)
{
return "{ (xdc_Bits8)" + desc.Bar + ", /* Bar */\n" +
" (xdc_Bits16)" + desc.Baz + ", /* Baz */\n" +
" }";
}
function Foo_s$sizeof()
{
return 3;
}

I have two more questions for Dave or anyone else who may know:

1) How can I use the sizeof() attribute in a client .cfg script? I want to be able to create a mailbox in the metadomain sized to the size of the packed structure I'm making. It seems like the both the meta and c-type is unknown in the cfg file. For example, just trying to print out the size of the Log Event type:

1) You can't really call $sizeof on an encoded type as you would do for a normal type. I am not really sure why $sizeof functions are not generated, but internally Foo_s$sizeof function would get called, if needed. The internal call looks like this: