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.

TMS320F280049: Casting negative value between int16 and int32 for CLA

Part Number: TMS320F280049

Dear Champs,

I am asking this for our customers.

They are confused about some casting issues on CLA.

They wrote codes like below:

// In xxx.cla

int16_T  A;

// In xxx.c

A = -7U;

// Use CPU to CLA

#pragma DATA_SECTION(A, "CpuToClaMsgRAM");

// in xxx.cla, cast int16 to int32

int32_T U;

U = (int32_T)(A);

// In CCS window,

They found U = 65529 rather than -7.

However, if they use positive value for A, then it works correctly.

Would you please show me why it is?

Why is it viewed as unsigned rather than signed int?

Or is there any restriction when using negative integer value for CLA?

What is the correct way to cast them?

Wayne Huang

  • Wayne,

    Wayne Huang said:

    A = -7U;

    The 'u' suffix here tells the compiler to treat this literal as an unsigned int.  I suggest removing the U.  

    Having said that, I tried this case and I'm not able to reproduce it.  Even with the 'u" suffix. In CCS the variable, in the CLA debug context, is displayed as a int and not an unsigned int.  

    I think you are just seeing a display issue - the value is -7 but it has been displayed as if it was an unsigned number.

    Make sure the display hasn't been cast - i.e. telling CCS to display it in a different type.  If it has been cast, then it looks like this screenshot below. You can right click on the variable, and select "restore original type".

  • Dear Lori,

    The customer does not think this is related to CCS display because they used the variable in subsequent codes and found the result was wrong.

    You mentioned you did not reproduce this.

    Would you please send me or show us your test project?

    I think there should still be something wrong we've not yet found.

    I will also send you their test codes offline.

    Wayne Huang

  • Dear Lori,

    This is related to the type definition they use.

    They did not use TI's type definition for C28x and CLA.

    They are resolving this.

    Thank you for your support.

    Wayne Huang