picolibrary

Interrupt Facilities

Interrupt facilities are defined in the include/picolibrary/interrupt.h/source/picolibrary/interrupt.cc header/source file pair.

Table of Contents

  1. Controller
  2. Critical Section Guard

Controller

The ::picolibrary::Interrupt::Controller_Concept concept class defines the expected interface of an interrupt controller.

The ::picolibrary::Testing::Automated::Interrupt::Mock_Controller mock interrupt controller class is available if the PICOLIBRARY_ENABLE_AUTOMATED_TESTING project configuration option is ON. The mock is defined in the include/picolibrary/testing/automated/interrupt.h/source/picolibrary/testing/automated/interrupt.cc header/source file pair.

Critical Section Guard

To create a critical section, use the ::picolibrary::Interrupt::Critical_Section_Guard RAII critical section guard template class. Exit actions are selected using the ::picolibrary::Interrupt::Restore_Interrupt_Enable_State/::picolibrary::Interrupt::RESTORE_INTERRUPT_ENABLE_STATE and ::picolibrary::Interrupt::Enable_Interrupt/::picolibrary::Interrupt::ENABLE_INTERRUPT types/constants. ::picolibrary::Interrupt::Critical_Section_Guard automated tests are defined in the test/automated/picolibrary/interrupt/critical_section_guard/main.cc source file.

#include "picolibrary/interrupt.h"

template<typename Controller>
void foo( Controller & controller ) noexcept
{
    {
        // save interrupt enable state and disable interrupt
        auto const guard = ::picolibrary::Interrupt::Critical_Section_Guard{
            controller,
            ::picolibrary::Interrupt::RESTORE_INTERRUPT_ENABLE_STATE };
    }
    // interrupt enable state restored
}

template<typename Controller>
void foo( Controller & controller ) noexcept
{
    {
        // disable interrupt
        auto const guard = ::picolibrary::Interrupt::Critical_Section_Guard{
            controller,
            ::picolibrary::Interrupt::ENABLE_INTERRUPT };
    }
    // interrupt enabled
}