I'm writing a C program to program a microcontroller. In practice, when an interrupt handler occurs I go to execute the following code:
uint8_t call_irq_handler = 0; // variable that is modified by the irq handler
uint8_t call_irq_handler_previous = 0;
static __attribute__((interrupt)) void __irq_handler()
{
call_irq_handler_previous = call_irq_handler;
call_irq_handler = call_irq_handler + 1;
}
In main, instead, to wait for the interrupt handler to be executed, I put the following while loop:
while (call_irq_handler == call_irq_handler_previous)
{
count_cmd_write++;
#if DEBUG
printf("...i didn't get interrupt handler for cmd_write...\n");
#else
continue;
#endif
}
If I set DEBUG 1, I have no problem, the code is executed and after a while I exit the while loop. However, if DEBUG 0 then I remain in the while, and therefore the interrupt handler is not taken. Anyone know why this happens?
call_irq_handler_previousvolatile?