Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::hal::interrupts Namespace Reference

Interrupt priorities and critical sections. More...

Detailed Description

Interrupt priorities and critical sections.

Classes

class  ScopedControlCritical
 RAII critical section against the control tick and everything below. More...
 

Enumerations

enum class  Level : uint8_t {
  Reserved = 0 , ShortDeadline = 1 , Audio = 2 , UsbMidi = 4 ,
  Dma = 5 , Bus = 6 , ControlTick = 8 , SoftPwm = 9 ,
  Exti = 10 , SoftPend = 11 , Debug = 12 , SysTick = 14 ,
  PendSv = 15
}
 Execution levels, most urgent first. More...
 
enum class  Trigger : uint8_t {
  Rising , Falling , Change , Low ,
  High
}
 External interrupt trigger types. More...
 

Functions

uint32_t get_basepri ()
 Read BASEPRI (0 = no ceiling).
 
void set_basepri (uint32_t encoded)
 Write BASEPRI unconditionally (used to restore a saved value).
 
void raise_basepri (uint32_t encoded)
 
uint32_t disable_and_save ()
 Disable all configurable exceptions and return the previous PRIMASK.
 
void restore (uint32_t saved_state)
 Restore PRIMASK from disable_and_save().
 
uint32_t get_state ()
 Current PRIMASK (0 = enabled, 1 = disabled).
 
bool are_enabled ()
 True if configurable exceptions are enabled (PRIMASK clear).
 
constexpr uint8_t encode (Level level)
 Encode a level as the byte written to NVIC->IP[] / SCB->SHP[] / BASEPRI.
 
constexpr bool masked_by_ceiling (Level level)
 True if a handler at level is masked while BASEPRI sits at the ceiling.
 

Variables

constexpr Level kBasepriCeiling = Level::ControlTick
 The level a ScopedControlCritical raises BASEPRI to.
 
constexpr uint8_t kPriorityBits = 4
 Priority bits the target implements (STM32H750: 4 of 8).
 

Enumeration Type Documentation

◆ Level

enum class sbl::hal::interrupts::Level : uint8_t
strong

Execution levels, most urgent first.

The invariants the scheme guarantees:

  • Level 0 stays empty, so nothing can ever tie with audio and nothing escapes BASEPRI.
  • Audio has its own level. Any handler that shares it would delay audio by its full length (equal priority cannot preempt).
  • ControlTick is the BASEPRI ceiling: a ScopedControlCritical masks this level and everything below it, and nothing above it may touch state that main or the tick protect. Audio's blocking term is therefore zero.
  • SysTick, PendSV and SVCall are assigned explicitly; unassigned system handlers reset to level 0, above audio.
Enumerator
Reserved 

Empty by design (unmaskable by BASEPRI)

ShortDeadline 

Reserved for microsecond handlers that touch only SPSC queues.

Audio 

Audio DMA half/complete — the SAI streams only.

UsbMidi 

USB OTG interrupt, MIDI UART RX (both FIFO-elastic)

Dma 

Every other DMA stream (ADC, SDMMC)

Bus 

I2C / SPI event handlers, if interrupt-driven.

ControlTick 

Control-rate timer tick — the BASEPRI ceiling.

SoftPwm 

Software PWM / BCM timer (tolerates tick preemption)

Exti 

External pin interrupts (encoders, buttons)

SoftPend 

Software-pended work: tud_task(), USB-MIDI parse.

Debug 

Debug UART, diagnostics drain.

SysTick 

Millisecond tick; busy_wait_ms works from any level below.

PendSv 

PendSV and SVCall (left free for an RTOS later)

Definition at line 39 of file types.hpp.

◆ Trigger

enum class sbl::hal::interrupts::Trigger : uint8_t
strong

External interrupt trigger types.

Enumerator
Rising 

Rising edge trigger.

Falling 

Falling edge trigger.

Change 

Any edge (rising or falling)

Low 

Low level trigger.

High 

High level trigger.

Definition at line 74 of file types.hpp.

Function Documentation

◆ get_basepri()

uint32_t sbl::hal::interrupts::get_basepri ( )
inline

Read BASEPRI (0 = no ceiling).

Definition at line 48 of file control.hpp.

◆ set_basepri()

void sbl::hal::interrupts::set_basepri ( uint32_t  encoded)
inline

Write BASEPRI unconditionally (used to restore a saved value).

Definition at line 59 of file control.hpp.

Referenced by sbl::hal::interrupts::ScopedControlCritical::~ScopedControlCritical().

◆ raise_basepri()

void sbl::hal::interrupts::raise_basepri ( uint32_t  encoded)
inline

Raise BASEPRI to encoded only if that is a higher priority than the current value — never lowers it, so nested sections compose.

Definition at line 69 of file control.hpp.

Referenced by sbl::hal::interrupts::ScopedControlCritical::ScopedControlCritical().

◆ disable_and_save()

uint32_t sbl::hal::interrupts::disable_and_save ( )
inline

Disable all configurable exceptions and return the previous PRIMASK.

This blocks the audio ISR. It exists for assert/fault handling, where the system is already lost; a critical section wants ScopedControlCritical.

Definition at line 111 of file control.hpp.

◆ restore()

void sbl::hal::interrupts::restore ( uint32_t  saved_state)
inline

Restore PRIMASK from disable_and_save().

Definition at line 123 of file control.hpp.

◆ get_state()

uint32_t sbl::hal::interrupts::get_state ( )
inline

Current PRIMASK (0 = enabled, 1 = disabled).

Definition at line 132 of file control.hpp.

Referenced by are_enabled().

◆ are_enabled()

bool sbl::hal::interrupts::are_enabled ( )
inline

True if configurable exceptions are enabled (PRIMASK clear).

Definition at line 143 of file control.hpp.

References get_state().

◆ encode()

constexpr uint8_t sbl::hal::interrupts::encode ( Level  level)
constexpr

Encode a level as the byte written to NVIC->IP[] / SCB->SHP[] / BASEPRI.

Definition at line 62 of file types.hpp.

References kPriorityBits.

Referenced by sbl::hal::interrupts::ScopedControlCritical::ScopedControlCritical().

◆ masked_by_ceiling()

constexpr bool sbl::hal::interrupts::masked_by_ceiling ( Level  level)
constexpr

True if a handler at level is masked while BASEPRI sits at the ceiling.

Definition at line 67 of file types.hpp.

References kBasepriCeiling.

Variable Documentation

◆ kBasepriCeiling

constexpr Level sbl::hal::interrupts::kBasepriCeiling = Level::ControlTick
inlineconstexpr

The level a ScopedControlCritical raises BASEPRI to.

Definition at line 56 of file types.hpp.

Referenced by masked_by_ceiling(), and sbl::hal::interrupts::ScopedControlCritical::ScopedControlCritical().

◆ kPriorityBits

constexpr uint8_t sbl::hal::interrupts::kPriorityBits = 4
inlineconstexpr

Priority bits the target implements (STM32H750: 4 of 8).

Definition at line 59 of file types.hpp.

Referenced by encode().