Microchip® Advanced Software Framework

Quick Start Guide for SYSTEM INTERRUPT - Critical Section Use Case

In this case we perform a critical piece of code, disabling all interrupts while a global shared flag is read.

During the critical section, no interrupts may occur.

Setup

Prerequisites

There are no special setup requirements for this use-case.

Use Case

Code

Copy-paste the following code to your user application:

if (is_ready == true) {
/* Do something in response to the global shared flag */
is_ready = false;
}

Workflow

  1. Enter a critical section to disable global interrupts.
    Note
    Critical sections may be nested if desired; if nested, global interrupts will only be re-enabled once the outer-most critical section has completed.
  2. Check a global shared flag and perform a response. This code may be any critical code that requires exclusive access to all resources without the possibility of interruption.
    if (is_ready == true) {
    /* Do something in response to the global shared flag */
    is_ready = false;
    }
  3. Exit the critical section to re-enable global interrupts.