MATLAB: How to ensure data store integrity for C2000 Target with Embedded Coder

Embedded Coder

I have a Simulink model configured for Ti Piccolo F2806x target.
It has several function-call subsystem driven by a C28x Hardware Interupt block.
This function-call subsystems need to access (read or write) a data store memory that contains an array of three int variables.
I want to ensure that the data is fully written and not corrupted when accessed by the different subsystems.

Best Answer

A very similar issue is handled in the shipping example "c28069pmsmfoc".
In this example, we have four data store memory blocks that are updated in high priority interrupts.
While reading the variables in a lower priority task, we need to guarantee that they do not update while we read them and all four of them are coming from the same update interrupt.
To do this, we block interrupts for the time of the read and unblock interrupts right after the read.
This can be done with an atomic subsystem + custom code block.
Look at:
c28069pmsmfoc/FOC Alogrithm/Torque Control Algorithm/Atomic Hall Reading
In that atomic subsystem, we placed a "System Outputs" Custom Code block in which we write "DINT;" on entry to disable interrupts, and "EINT;" on exit to re-enable interrupts at the end of the execution of the atomic subsystem.
Keep in mind that the subsystem has to be atomic otherwise the custom code will go to the beginning and the end of the entire rate group.