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.

CLA MPU memory read conflict and incorrect read

Genius 5910 points

I got an incorrect memory read by the CLA.

With the following code:

    encoder_dir=1;
    Cla1ForceTask8 ();

__interrupt void Cla1Task8 ( void )
{
    dir=encoder_dir;
}

Somehow this gives a conflict. The result of this code is that when dir = 0.

If I change it to this:


    Cla1ForceTask8wait ();

    encoder_dir=1;

It works correctly.

So somehow when the 28035 and CLA try to write/read the same memory location the CLA got an incorrect value. So how do I solve this?

Thanks!

edit:

Can the memory alignment form 16 -> 32 bit be a problem?

This is the variable definition:

volatile int dir;
#pragma DATA_SECTION(encoder_dir,"CpuToCla1MsgRAM")
volatile  int  encoder_dir;

  • Hi,

    Don't use int for shared variables. int is 16-bits on the C28x and 32-bits on the CLA. It could be causing the code on the CLA side to look up the wrong address, especially if the linker has placed the 16-bit variable at an odd address.

    I would declare it as volatile short or volatile int16_t (include stdint.h)

  • Hi Vishal,

    Thanks for the reply. That seems to be the problem. I changed it to long.

    Can you please explain the difference between int and short or int16_t are they not all typedef int?

    Is not the only way to solve it  something like:

     #pragma align memory even

    And why  it isn't done automatically by the compiler with this command:

    #pragma DATA_SECTION(encoder_dir,"CpuToCla1MsgRAM")

  • Hi evs,

    evs said:
    Can you please explain the difference between int and short or int16_t are they not all typedef int?

    int and short are primitive C type. The C language sets short to be 16-bits and int to match the native bit-format of the machine. In the case of the c28 its 16-bits but the CLA is more geared toward 32-bit operations so it made sense to set int to 32-bits on the CLA. int16_t is typedef'd to 16-bits on both cores so it is always safer to use the explicit types defined in stdint.h

    evs said:

    Is not the only way to solve it  something like:

     #pragma align memory even

    And why  it isn't done automatically by the compiler with this command:

    #pragma DATA_SECTION(encoder_dir,"CpuToCla1MsgRAM")

    I guess you could have got away with even aligning the int, but consider if you had an array of ints - the c28 allocates 16 bits per entry, and when you access it on the CLA, say a[0], you end up reading a[0]:a[1] as the CLA will do a 32-bit read.