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.

TMS320F28035: Atomic operations

Part Number: TMS320F28035

Hello.

I need to assign one variable to another in atomic way.

    Uint16 T, X;

    Uint16 val = __disable_interrupts();

    T = X;

    if (0U == (val & 0x1)) __enable_interrupts();

Is this the right way?

  • Hello,

    I believe this is one way to do this on the device, I will forward this to the compiler experts in case there is other syntax that is usable; I do not believe the device has anything inherent in the program memory for marking atomic code sequences.

    Best regards,

    Omer Amir

  • HI. OK, I will wait for compiler expertsadvice. I would like to add that I not only need atomic way when assigning variables but also when comparing them.

  • There are a few compiler intrinsics that might be helpful.  Please search the C28x compiler manual for the sub-chapter titled Using Intrinsics to Access Assembly Language Statements.  Then search the table in that sub-chapter for the word atomic.  You'll see you can perform an operation directly on a memory location, in an atomic way.  There is no atomic intrinsic which simply copies a value or expression to a memory location.  But I suspect these intrinsics will be useful anyway.

    In practice the __enable_interrupts intrinsic is rarely used.  Because it forces interrupts to be enabled, without regard for whether the interrupts were previously disabled.  Use __restore_interrupts instead.  Here is a typical example ...

        uint16_t state = __disable_interrupts();
        /* interrupts disabled here */
        __restore_interrupts(state);

    Thanks and regards,

    -George