packed structure in xc

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
genap
Experienced Member
Posts: 99
Joined: Sat Aug 31, 2013 11:23 pm

packed structure in xc

Post by genap »

Hello,
how do I pack a structure in xc?
I am trying to use __attribute__((packed)) , but compiler complains about unrecognized attribute.

Gennady


User avatar
Ross
XCore Expert
Posts: 962
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Sadly this is not currently support in XC (though I am campaigning for it ;) )

It is supported in C if that helps.
User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am
Contact:

Post by segher »

I have a hard time coming up with an example where "packed"
would be really useful on xcore chips: the memory is too
small for easy memory savings to matter, the cost of unaligned
accesses is much too big.

There is of course legacy code that uses "packed" (or struct
layout in general) to interface to something external. Bad plan.

Do you have an example where it is really useful?
genap
Experienced Member
Posts: 99
Joined: Sat Aug 31, 2013 11:23 pm

Post by genap »

I have a profile (structure of application properties), which is loaded externally though HID.
This profile structure is generated externally, on a PC.
On upload profile is stored on a flash (secondary, not boot flash).
On power-up the application loads profile from a flash and operates on it.

From my point of view the easiest way to make sure that alignment is the same in both loaded and internal structures is to have them packed.
teachop
Active Member
Posts: 47
Joined: Wed Feb 05, 2014 1:25 am

Post by teachop »

It is helpful in serial communications.
babazaroni
Experienced Member
Posts: 94
Joined: Sun Feb 10, 2013 4:47 am

Post by babazaroni »

Hopefully, XMOS will fix this and allow packed structures.

When one receives a serial stream from outside the system, one can't expect the elements are grouped nicely for xmos.

I don't want to be a human compiler piecing bytes together to form the values, when the compiler should be doing it.

And I don't want to write C helper functions either, which are ugly and tedious.
User avatar
Ross
XCore Expert
Posts: 962
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

babazaroni wrote:Hopefully, XMOS will fix this and allow packed structures.

When one receives a serial stream from outside the system, one can't expect the elements are grouped nicely for xmos.

I don't want to be a human compiler piecing bytes together to form the values, when the compiler should be doing it.

And I don't want to write C helper functions either, which are ugly and tedious.
Fair comments..
gcore
Member
Posts: 11
Joined: Thu Oct 06, 2016 4:58 am

Post by gcore »

Packed structures would be helpful for me too, for the same reason: being able to represent data coming from outside the system.
Post Reply