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.

Word alignment issues

Other Parts Discussed in Thread: TMS320F28335

We are using TMS320F28335 and CCS 3.3 with latest code genration tools.

I just wanted to work around this word alignment issue.

I have a structure say

typedef struct _x_x

{

unsigned char a;

unsigned char b;

unsigned short c;

unsigned short d;

}

The size of this structure returns 4. I think this is due to word alignment on this controller. But is it possible to set some compiler options to behave as a byte aligned and return a size of 6 and do the back ground operations to work as if its a byte aligned controller.

I could not able to port code which is written and work on byte alignment.

for example, lets say i'm receiving data on a parellel port (8bit), i would like to typecast the structure pointer to a char pointer and stream in the data and then back typecast to structure and use it. This is not working out as the otherside device streams in data on byte aligned format.

Any suggestioins pls.

 

  • I have heard that "the greatest advantage of C is its portability, while the greatest disadvantage of C is its lack of portability." Similarly, the good news is that you can do what you need to do with the F28335, while the bad news is that you cannot do what you want to do with the F28335.

    You will need to refer to the TMS320C28x Optimizing C/C++ Compiler User's Guide (I have rev C). Section  6.3 discusses data types and there is a Note at the bottom of page 82 that explains some [probably unexpected and surprising] facts about the sizeof() function and bytes & words on the C28x family. This may lead you to believe that you cannot do what you want to do since you are moving from a byte-addressable machine to the C28x 16-bit word-addressable machine.

    However, section 7.1.7 discusses bit fields, which can be used to more closely implement the data-parsing structure that you need. I would recommend looking through some of the peripheral header files to see examples of using fields and unions and structs to implement flexible and powerful size-mapping structures.

  • Some of the compiler options are intended to overcome portability issues.

    There is a pragma STRUCT_ALIGN in c6000 compiler. Is the same available in c2000 compiler?

    Is it possible to get the byte alignment using DATA_ALIGN with 1 or STRUCT_ALIGN with 1?

  • The C6000 is an 8-bit byte-addressable machine while the C28x is a 16-bit word-addressable machine. They will have different behaviors.

    You will need to refer to the C Compiler User's Guide for the answer to the use of the DATA_ALIGN and STRUCT_ALIGN pragmas. I do not believe you will get the results you want that easily. There are byte-operation intrinsics listed in the C Compiler User's Guide, and those might help with what you want, but I still think the bit-fields and the interpretation of sizeof() will be your best solution.

  • For byte addressing, see also this topic:

    http://e2e.ti.com/forums/t/11201.aspx

     

  • Hi,

    what about doing it this way?

    typedef struct _x_x
    {
    unsigned short a_b;
    unsigned short c;
    unsigned short d;
    }

    // some macro definitions for byte access
    #define BYTE1(var) *((unsigned char *) &var+1)
    #define BYTE0(var) *((unsigned char *) &var)

    Use it like:

    unsigned char a,b;

    a = BYTE1(a_b);

    b = BYTE0(a_b);

    I think you will have to test it with your compiler to see if it works as expected.

    Rgds
    aBUGSworstnightmare