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.

TMS320F28388S: how to do 16bit align for struct at c28 core

Part Number: TMS320F28388S
Other Parts Discussed in Thread: C2000WARE

...

Hi Expert,

my customer want to do word align for struct at C28 core, which can be easily used by #pragma PACK at arm core.

for example;

typedef struct

{

int test1;

long test2;

int test3;

int test4;

} TEST;

 

 test1 will take up 32bit as below showed, any way to align with 16bit size?  it seem #pragma PACK  does not work for C28. any other method?

  • Strong,

    C28x can't align a long(32-bits) across an odd base address, so the operation here is correct, forcing test2 to 0xAA92. 

    If you forced test2 to have an address of 0xAA91 it would write the 32-bits to 0xAA90 and 0xAA91, corrupting test1.

    Bottom line is that 32-bit data is forced to even alignment by the arch of the C28x.

    Only way I know to make this size efficient would be to group all the ints together, then the longs.  But if there is odd number if ints, there will always be 16-bits of empty space going to a long.

    Best,

    Matthew

  • Strong,

    Once the variables are grouped as Matthew advises, bit-packing (like that used in the header-files) can be used for easier logical access to smaller data variables. For example, in ~\C2000Ware_XXXX\device_support\f2838x\headers\include\f2838x_cputimer.h

    struct TIM_BITS {                       // bits description
        Uint16 LSW:16;                      // 15:0 CPU-Timer Counter Registers
        Uint16 MSW:16;                      // 31:16 CPU-Timer Counter Registers High
    };

    union TIM_REG {
        Uint32  all;
        struct  TIM_BITS  bit;
    };

    struct TPR_BITS {                       // bits description
        Uint16 TDDR:8;                      // 7:0 CPU-Timer Divide-Down.
        Uint16 PSC:8;                       // 15:8 CPU-Timer Prescale Counter.
    };

    union TPR_REG {
        Uint16  all;
        struct  TPR_BITS  bit;
    };

    struct CPUTIMER_REGS {
        union   TIM_REG                          TIM;                          // CPU-Timer, Counter Register
        union   PRD_REG                          PRD;                          // CPU-Timer, Period Register
        union   TCR_REG                          TCR;                          // CPU-Timer, Control Register
        Uint16                                   rsvd1;                        // Reserved
        union   TPR_REG                          TPR;                          // CPU-Timer, Prescale Register
        union   TPRH_REG                         TPRH;                         // CPU-Timer, Prescale Register High
    };

    -Tommy