C166: EXTS PROBLEMS USING THE _ATOMIC_ FUNCTION
Information in this article applies to:
I have written the following code:
_atomic_(4); Event = *ISREventPointer; _atomic_(4); *ISREventPointer = 0;
expecting interrupts to be disabled for the duration of the execution of both lines of C code. However, the assembly code generated was:
150E D130 ATOMIC #04H ; SOURCE LINE # 1347 1510 DC0F EXTS R15,#01H 1512 A9AE MOVB RL5,[R14] ;---- Variable 'Event' assigned to Register 'RL5' ---- ; SOURCE LINE # 1348 1514 D130 ATOMIC #04H ; SOURCE LINE # 1349 1516 E10C MOVB RL6,#00H 1518 DC0F EXTS R15,#01H 151A B9CE MOVB [R14],RL6
If I am reading this correctly, the EXTS instruction will reset the internal counter being used for the ATOMIC instruction back to 1, causing only the following instruction (MOVB) to be non-interruptable.
Is there a workaround for this problem?
This happens because the EXTS instruction is required to execute the two lines of C code you have written. The result is that you run into a limitation of the microcontroller which cannot properly handle situations where EXTS instructions follow ATOMIC instructions.
There are two other methods to disable interrupts.
Last Reviewed: Friday, July 15, 2005
of your data.