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.

TMS320F28075: C28x <-> CLA: Volatile Keyword on shared structures

Part Number: TMS320F28075
Other Parts Discussed in Thread: C2000WARE

Hi,

I have been doing some work with the C28x and CLA based on the FCL codebase.  None of the data shared between the two processors is declared volatile in the example projects.  Is that intentional?  When I look at other examples (c2000ware_motorcontrol_sdk_3_02_00_00/c2000ware/driverlib/f2807x/examples/cpu1/cla) they also don't use the volatile keyword.

I would guess that declaring it volatile should be necessary since the underlying contents can be changed by either processor.  But am I missing something with the way that the CLA compiler is implemented?

Thanks,

-Colin

  • We try to use volatile only when we find it's necessary since there can be a performance impact from using it. In my experience it doesn't seem to be necessary with variables shared between CLA and C28x, but I'll loop in someone from our compiler team for an explanation.

    Whitney

  • I just took another look at some of the FCL code, and I think the answer is that there's no point at which the variables are expected to be changed by the other processor mid-function. For example, pangle is calculated on the CLA, but the C28x code doesn't read pangle until it has already confirmed that the CLA task as completed, so there's no need for additional memory accesses beyond the first one of the function call.

    So there are still scenarios where shared variables do need to be made volatile, but we've apparently avoided them in these examples

    Whitney

  • Thanks Whitney.

    Will the CLA optimizer ever remove a variable read entirely if it doesn't see that the variable set in the .cla code?  Or is there a guarantee that it always read it once at the start of the task?

  • I'm going to do what I mentioned I'd do yesterday, and loop in someone from the compiler team to give you a more precise answer. Slight smile

    Whitney

  • Will the CLA optimizer ever remove a variable read entirely

    It is possible.  Consider this example ...

    extern int global;
    
    int fxn(int arg1, int arg2)
    {
       /* All of this statement is optimized away */
       int never_used = global;
    
       return arg1 + arg2;
    }

    However, that example is probably not typical of actual code.  If a variable read is part of a computation that leads to a write to a global, or a value passed to a function call, or a value returned, etc., then it is not optimized away.  

    For more on volatile, please see this sub-chapter on volatile from the C28x Optimization Guide.

    Thanks and regards,

    -George

  • Thanks George.  The following line is the validation that I was hoping to see.

    " If a variable read is part of a computation that leads to a write to a global, or a value passed to a function call, or a value returned, etc., then it is not optimized away. "