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.

CCS/TMS320F28335: Array forced to structure

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Dear team,

On 28335, whether the structure can be aligned with one byte. If it doesn't work, how do you force the array into a structure? There are single-byte, double-byte, and multi-bytes in the structure.

Please help.

  • I want to be clear on what you mean by the term byte.  On the C28x CPU, the smallest addressable unit of memory is a 16-bit word, and not an 8-bit byte.  For more background on this topic, please see the Variable Types part of the larger article C28x Code Generation Tips and Tricks.

    With that in mind, if the term byte means an 8-bit wide unit of memory, then a structure cannot be aligned on a byte.  If the term byte means a 16-bit wide unit of memory, then a structure can be aligned on a byte.

    Thanks and regards,

    -George

  • Thanks for your reply.


    If I need to force an array into a structure on 28335, is it allowed?

  • I'm not sure what you mean when you say ...

    Susan Yang said:
    force an array into a structure

    Just for now, pretend that you can do it.  Please show an example of C code which does that.  The more details this example has, the better.

    Thanks and regards,

    -George

  • Suppose there is such a structure:

    typedef struct FRAME
    
    {
    
    unsigned long int head;
    
    unsigned int len;
    
    unsigned int data;
    
    unsigned long int tail
    
    }FRAME;

    The following is a buffer array, the data is as follows,

    unsigned char buf[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0x0a, 0x0b, 0x0c};


    I hope to map this value to the structure,like

    head = 0x04030201,len = 0x0605,data = 0x0807, tail - 0x0c0b0a09

    How to realize this function?

    BR,

    SUSAN

  • The transformation from ...

    Susan Yang said:
    unsigned char buf[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0x0a, 0x0b, 0x0c};

    ... to ...

    Susan Yang said:
    head = 0x04030201,len = 0x0605,data = 0x0807, tail - 0x0c0b0a09

    ... presumes that the type char is 8-bits wide.  That is not the case on the C28x CPU.  The smallest type on C28x is 16-bits side.  Thus, the most you can pack into a 32-bit long is 2 16-bit words.  Are you OK with this limitation?

    If you are not OK with this limitation, then you need to consider using the __byte intrinsic.  Please search for __byte in the C28x compiler manual.

    Thanks and regards,

    -George