Does anyone know of a C construct that will generate code similar to that produced with the #pragma DISABLE directive? Specifically I'm looking to get the JBC instruction. I'm trying to emulate the #pragma DISABLE directive for small sections of code within a function. Inline assembly is out since you lose C source level debugging capablility when you compile via the SRC directive. Here's the best I have so far, but I'm (overly) paranoid that the interrupt state could change between the jump and the clear due to a task switch... I'm using Rtx51Tiny:
data BYTE easav; if (EA==0) { easav=0; } else { EA=0; easav=1; }
JB EA,?C0018 CLR A MOV easav?341,A SJMP ?C0019 ?C0018: CLR EA MOV easav?341,#01H ?C0019:
why the feniggle to avoid clearing EA if it is already cleared, who gives a ... easav - EA; EA = 0;
The main concern is testing and clearing EA at the same time. Consider the following:
void(foo) { // At this point interrupts are enabled easav = EA; // easav = 1 /* ISR gets called. ISR clears EA for some reason (expect that it will be re-enabled at some point in the main application code) */ EA = 0; do_stuff(); EA = easav; // EA = 1, oops! }
Try #pragma DISABLE in front of the function