Hi,
Semaphores are needed only when both cores (S12X and XGATE) access the same shared resource, typically a variable in RAM. The are needed to avoid simultaneous R/W from both cores. For example, CPU writes some data in one or two steps and XGATE reads them at the same moment. Data consistency is not guaranteed.
Use semaphores when:
- A variable is modified by both XGATE and S12X ISRs.
Example: A status flag or counter updated by both cores. Or writing to a port.
- A variable is modified by one core and read by the other, and the read must be consistent.
Example: A buffer index updated by XGATE and read by S12X in a loop.
You do not need semaphores when:
- A variable is only modified by XGATE, and only read by S12X, and consistency is not critical (e.g., occasional stale reads are acceptable).
- A variable is only accessed by one core (either read or write).
Note, I found in my old code following. It is probably not important for some mask sets but better to implement to be sure it works everywhere.
.... *.cxgate module
interrupt void PIT0isr(void)
{
//--- Protected software region starts // AN2685.pdf
//-----------------------------------------
// use this
asm LOOP1:
asm SSEM #0 // try to lock semaphore 0
asm SSEM #0 // try to lock semaphore 0 // once more due to internal silicon bug
asm BCC LOOP1 // retry if locked
//-----------------------------------------
//or this
//asm SSEM #0 // try to lock semaphore 0
//asm SSEM #0 // try to lock semaphore 0 // once more due to internal silicon bug
//asm BCC PIT0isr_RTI // return without flag clearing to enable service of an interrupt with higher priority
//-----------------------------------------
....
.....
....
//-----------------------------------------
asm CSEM #0 // release semaphore
//-----------------------------------------
asm PIT0isr_RTI:
//-----------------------------------------
PITTF = 0x01; // clear interrupt flag of PIT0isr
}
Best regards,
Ladislav