Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Real-Time Software Components (RTSC) » Packed structures using XDC
Packed structures using XDC [message #667271] Wed, 27 April 2011 14:50 Go to next message
R Zuber is currently offline R Zuber
Messages: 5
Registered: April 2011
Junior Member
Hello,

According to this post:

http://e2e.ti.com/support/development_tools/compiler/f/343/p /38211/133442.aspx

and this wiki article:

http://processors.wiki.ti.com/index.php/GCC_Extensions_in_TI _Compilers#Type_Attributes

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.

I am aware that "packed" is a non-portable extension.

Thanks for your help.
Re: Packed structures using XDC [message #668422 is a reply to message #667271] Thu, 05 May 2011 11:37 Go to previous messageGo to next message
Dave Russo is currently offline Dave Russo
Messages: 172
Registered: July 2009
Senior Member
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.

We have documentation about encoded type on the RTSCpedia:
http://rtsc.eclipse.org/docs-tip/Using_Encoded_Types, and
http://rtsc.eclipse.org/docs-3.16/XDCspec_-_@Encoded

I hope this helps.

On 4/27/2011 11:50 AM, R Zuber wrote:
> Hello,
>
> According to this post:
>
> http://e2e.ti.com/support/development_tools/compiler/f/343/p /38211/133442.aspx
>
>
> and this wiki article:
>
> http://processors.wiki.ti.com/index.php/GCC_Extensions_in_TI _Compilers#Type_Attributes
>
>
> 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.
>
> I am aware that "packed" is a non-portable extension.
>
> Thanks for your help.
Re: Packed structures using XDC [message #693464 is a reply to message #668422] Wed, 06 July 2011 10:09 Go to previous messageGo to next message
R Zuber is currently offline R Zuber
Messages: 5
Registered: April 2011
Junior Member
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:

var Pkg = xdc.useModule('xdc.bld.PackageContents');
Pkg.attrs.copts = '--gcc'


This attribute is somewhat parasitic as all downstream package.blds must include it as well.

Here are some quick snippets for everyone's reference:

myModule.xdc
@CustomHeader
module myModule
{
   metaonly struct Foo
   {
      Bits8 Bar;
      Bits16 Baz;
   }

   @Encoded typedef Foo Foo_s;

   //The rest of your module here
}



myModule__prologue.h
typedef struct
{
   xdc_Bits8 Bar;
   xdc_Bits16 Baz;
}__attribute__((packed)) company_whatever_myModule_Foo_s;



myModule.xs

//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:

var Log = xdc.useModule('xdc.runtime.Log');
print('meta-type - ' + Log.EventDesc);
print('c-type - ' + Log.Event);
print('sizeof - ' + Log.EventDesc.$sizeof());
print('sizeof - ' + Log.Event.$sizeof());


returns an error because it doesn't know the type:

meta-type - <unknown>
c-type - <unknown>
js: "./Test.cfg", line 72: XDC runtime error: <unknown>: no property named '$sizeof'
    "./package/cfg/Test_x64P.cfg", line 747
    "./package/cfg/Test_x64P.cfg", line 802
    "./package/cfg/Test_x64P.cfg", line 734


I could just declare a constant for the size if need be, but it would be cleaner just to use $sizeof() directly.


2) Is my code above for the encode function correct?


[Updated on: Wed, 06 July 2011 10:53]

Report message to a moderator

Re: Packed structures using XDC [message #694611 is a reply to message #693464] Fri, 08 July 2011 21:05 Go to previous message
Sasha Slijepcevic is currently offline Sasha Slijepcevic
Messages: 86
Registered: July 2009
Member
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:

print("sizeof(myModule.Foo_s) = " + xdc.loadCapsule("company/whatever/myModule.xs").Foo_s$sizeof());


You can try using that. Now I am not sure what kind of object you are trying to create in metadomain, but why would you need to know the size? You can just declare
config Foo myFoo = {Bar:0, Baz:0};

and you will get the object of the right size. You can access it in C as myModule_Foo_s.

2) The code is correct in the sense that it will generate a valid C initializer. My compiler does not complain about the last comma in
{(xdc_Bits8)25, (xdc_bits16)100,}

but it does look wrong.

Previous Topic:Non-trivial package.bld examples?
Next Topic:nested packages
Goto Forum:
  


Current Time: Fri Aug 22 01:55:04 EDT 2014

Powered by FUDForum. Page generated in 0.01504 seconds