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.

TMS320F28379D: Use of Volatile with Cla1ToCpuMsgRAM variables

Part Number: TMS320F28379D

Hi,

I'm writing code for Cpu1+CLA for our power application.  I'm storing some variables in Cla1ToCpuMsgRAM to read ADC results in CLA and do some floating point calculations.  I'm also using these same variables for some loops in the CPU main to change GPIOs accordingly.  I wanted to know if I should use volatile keyword with the variables that are stored in Cla1ToCpuMsgRAM?  

I measured the CLA execution time by toggling a GPIO for both cases with and without volatile keyword for Cla1ToCpuMsgRAM variables; the execution time without volatile keyword is almost half compared to when I use the volatile keyword.  I'm using optimization level 3 with speed vs size tradeoff=5.

Thanks in advance. 

  • Hi Farid,

    Yes, you will need to use volatile. However you can architect your code to make sure performance is not affected.

    volatile float g_Var1; // Volatile global

    Example:

    void func1()

    {

    float x = g_Var1;   // Assume this is the read from memory that you care about, others are expected to compute upon this read value.

    float y = g_Var1;   // However g_Var1 is read here again as it is volatile

    float z  = (x + y) * g_Var1;     // However g_Var1 is read here again as it is volatile

    }

    The above causes a a lot of redundant reads from memory for lines 2 and 3 resulting in more cycles.

    Here is an optimized version of the same function.

    void func1_opt()

    {

    float var1 = g_Var1; // Read from memory gets enforced here as g_Var1 is volatile. So the memory read has been captured in non-volatile variable var1.

    // Following code gets optimized as var1 is not a volatile

    float x = var1;   

    float y = var1;   

    float z  = (x + y) * var1;    

    }

    Hope this helps.

    Thanks,

    Ashwini