Page 1 of 1

[NO REPLY] Critical Sections (rev #2, 2018-1-15)

Posted: Sun Dec 10, 2017 7:54 pm
by Giovanni
In order to address the problem posed by asynchronous events, ISRs in this example, an ad-hoc compound statement can be used:

Example:

Code: Select all

worddef exclusive async <isr> critical {
enter:
  Disable_IRQ();
leave:
  enable_IRQ();
async_enter:
  disable_IRQ_fromISR();
async_leave:
  enable_IRQ_fromISR();
}

critical int i = 0;

critical void signal(void) {
  ...
}

async <isr> void my_isr_function(void) {
  critical {
    i++;
    signal();
  }
}

void signal_handler(void) {
  int local_i;

  critical {
   local_i = i--;
  }
  use(local_i);
}


Critical functions

  • Functions that can only be called from within a critical section.
  • Critical functions can only call critical or pure/const functions.

Critical variables

  • Critical variables can only be accessed from within a critical block or by critical functions.

Giovanni