It appears that I am having a race condition in acknowledging IPC interrupt flags on the Concerto F28M35H52C1. I am using the CtoM IPC1 and IPC2 interrupts, and occasionally IPC1 will fail to acknowledge and the flag will be left set. Both interrupt handlers are already bare-minimum functions that simply acknowledge the interrupt and set a flag for later handling in the main thread.
Example code follows:
void IPCHandler1() { IPCCtoMFlagAcknowledge(IPC_CTOMIPCACK_IPC1); IPCFlag1 = true; } void IPCHandler2() { IPCCtoMFlagAcknowledge(IPC_CTOMIPCACK_IPC2); IPCFlag2 = true; }
I believe the race condition is caused by a read-modify-write race condition on acknowledging the flags, since they both access the same register with an |= operation.
As I understand it, I have a few options:
1. Disable interrupts in the IPC handler.
2. Structure the code on the C28 so that IPC1 and IPC2 flags are set with some time separation. (This is an option for my code, but in general might not be).
3. Use bit-banding to set the acknowledge registers. This last one seems compelling as a good solution, but I can't seem to get it to work. The normal register access is given by:
void IPCCtoMFlagAcknowledge (unsigned long ulFlags) { HWREG(MTOCIPC_BASE + IPC_O_CTOMIPCACK) |= ulFlags; }
// elsewhere IPCCtoMFlagAcknowledge(IPC_CTOMIPCACK_IPC2);
Would the correct usage of the HWREGBITW macro to use the bit-band alias be the following?
HWREGBITW(MTOCIPC_BASE, IPC_CTOMIPCACK_IPC1) = 1;
This doesn't seem to work for me, however. Any help is appreciated on usage of the bit bands or the race condition in general.