Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12690 Discussions

using packet data types on nios

Altera_Forum
Honored Contributor II
1,232 Views

I am creating a large embedded file system on my board. Memory constraints may require that I use packed data types. I realize there are issues with data alignment and code efficiency, but maybe there are smarter ways to do it. I also need to xfer the file system data to/from a windows machine, and expect to have a translation module on the PC side.  

 

There is a short discussion about this for the ARM processor here, and I wonder if the same basic rules apply to the Nios: 

http://www.arm.com/support/faqdev/1228.html (http://www.arm.com/support/faqdev/1228.html

 

By using __alignof__() and sizeof(), I can see the Nios compiler behavior is to pad in the same way as the ARM.  

 

So has anyone gone down this path before on the Nios and could give recommendations? 

 

Is it just a matter of declaring __packed structures and pointers, or is there more pain involved? 

 

thanks
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
489 Views

"PACKED", not packet. I need an edit header function.

0 Kudos
Altera_Forum
Honored Contributor II
489 Views
0 Kudos
Altera_Forum
Honored Contributor II
489 Views

Thanks, this gives a good example. The problem you ran into is just one of several alignment issues. I don't think your structure was packed, so you only had to deal with the basic alignment between the buffer and the struct. You probably know that if you printed the address of each struct member, there would be some obvious padding.  

 

In my filesystem, every field of every record will need to be packed for size efficiency, and there are lots of different types of records with different field sizes. Because of this I suspect half the non-byte types will end up unaligned, and so require unaligned access methods. I'd sure like to find out I am wrong.  

 

I am trying to determine if it is better to operate on a non-packed record and only pack/unpack on the actual write/read, or operate on the data directly.
0 Kudos
Altera_Forum
Honored Contributor II
489 Views

I usually try to lump my odd-sized structure members together so the majority of the members are aligned. 

 

It's really hard to know what the compiler will do, though, since it may well load your packed structure member into a register once and then not access the struct again. Probably best to start out packed, turn on full optimization and then fix performance problems. 

 

Andrew
0 Kudos
Reply