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
types.hpp
Go to the documentation of this file.
1/**
2 * @file types.hpp
3 * @brief Interrupt system types: execution levels and trigger kinds
4 * @ingroup hal
5 *
6 * One execution-level scheme for the whole library. Every platform's vector
7 * table maps onto these names (see `<mcu>/driver/priorities.hpp` in
8 * sbl-hardware); application code never writes a numeric priority.
9 *
10 * Numbers are ARM NVIC levels: lower is more urgent. The STM32H750
11 * implements four priority bits, so the encoded byte is `level << 4` and
12 * the sixteen levels below are the whole space. Rationale per row:
13 * docs/research/interrupt-priority-and-real-time-scheduling.md §4.3.
14 */
15
16#ifndef SBL_HW_HAL_INTERRUPTS_TYPES_HPP_
17#define SBL_HW_HAL_INTERRUPTS_TYPES_HPP_
18
19#include <cstdint>
20
21namespace sbl {
22namespace hal {
23namespace interrupts {
24
25/**
26 * @brief Execution levels, most urgent first.
27 *
28 * The invariants the scheme guarantees:
29 * - Level 0 stays empty, so nothing can ever tie with audio and nothing
30 * escapes BASEPRI.
31 * - Audio has its own level. Any handler that shares it would delay audio
32 * by its full length (equal priority cannot preempt).
33 * - ControlTick is the BASEPRI ceiling: a ScopedControlCritical masks this
34 * level and everything below it, and nothing above it may touch state
35 * that main or the tick protect. Audio's blocking term is therefore zero.
36 * - SysTick, PendSV and SVCall are assigned explicitly; unassigned system
37 * handlers reset to level 0, above audio.
38 */
39enum class Level : uint8_t {
40 Reserved = 0, ///< Empty by design (unmaskable by BASEPRI)
41 ShortDeadline = 1, ///< Reserved for microsecond handlers that touch only SPSC queues
42 Audio = 2, ///< Audio DMA half/complete — the SAI streams only
43 UsbMidi = 4, ///< USB OTG interrupt, MIDI UART RX (both FIFO-elastic)
44 Dma = 5, ///< Every other DMA stream (ADC, SDMMC)
45 Bus = 6, ///< I2C / SPI event handlers, if interrupt-driven
46 ControlTick = 8, ///< Control-rate timer tick — the BASEPRI ceiling
47 SoftPwm = 9, ///< Software PWM / BCM timer (tolerates tick preemption)
48 Exti = 10, ///< External pin interrupts (encoders, buttons)
49 SoftPend = 11, ///< Software-pended work: tud_task(), USB-MIDI parse
50 Debug = 12, ///< Debug UART, diagnostics drain
51 SysTick = 14, ///< Millisecond tick; busy_wait_ms works from any level below
52 PendSv = 15, ///< PendSV and SVCall (left free for an RTOS later)
53};
54
55/// The level a ScopedControlCritical raises BASEPRI to.
57
58/// Priority bits the target implements (STM32H750: 4 of 8).
59inline constexpr uint8_t kPriorityBits = 4;
60
61/// Encode a level as the byte written to NVIC->IP[] / SCB->SHP[] / BASEPRI.
62constexpr uint8_t encode(Level level) {
63 return static_cast<uint8_t>(static_cast<uint8_t>(level) << (8u - kPriorityBits));
64}
65
66/// True if a handler at `level` is masked while BASEPRI sits at the ceiling.
67constexpr bool masked_by_ceiling(Level level) {
68 return static_cast<uint8_t>(level) >= static_cast<uint8_t>(kBasepriCeiling);
69}
70
71/**
72 * @brief External interrupt trigger types
73 */
74enum class Trigger : uint8_t {
75 Rising, ///< Rising edge trigger
76 Falling, ///< Falling edge trigger
77 Change, ///< Any edge (rising or falling)
78 Low, ///< Low level trigger
79 High ///< High level trigger
80};
81
82} // namespace interrupts
83} // namespace hal
84} // namespace sbl
85
86#endif // SBL_HW_HAL_INTERRUPTS_TYPES_HPP_
constexpr uint8_t kPriorityBits
Priority bits the target implements (STM32H750: 4 of 8).
Definition types.hpp:59
Level
Execution levels, most urgent first.
Definition types.hpp:39
@ Dma
Every other DMA stream (ADC, SDMMC)
@ SysTick
Millisecond tick; busy_wait_ms works from any level below.
@ ShortDeadline
Reserved for microsecond handlers that touch only SPSC queues.
@ PendSv
PendSV and SVCall (left free for an RTOS later)
@ Bus
I2C / SPI event handlers, if interrupt-driven.
@ ControlTick
Control-rate timer tick — the BASEPRI ceiling.
@ Reserved
Empty by design (unmaskable by BASEPRI)
@ Debug
Debug UART, diagnostics drain.
@ Audio
Audio DMA half/complete — the SAI streams only.
@ Exti
External pin interrupts (encoders, buttons)
@ SoftPwm
Software PWM / BCM timer (tolerates tick preemption)
@ SoftPend
Software-pended work: tud_task(), USB-MIDI parse.
@ UsbMidi
USB OTG interrupt, MIDI UART RX (both FIFO-elastic)
constexpr uint8_t encode(Level level)
Encode a level as the byte written to NVIC->IP[] / SCB->SHP[] / BASEPRI.
Definition types.hpp:62
Trigger
External interrupt trigger types.
Definition types.hpp:74
@ Falling
Falling edge trigger.
@ Low
Low level trigger.
@ Rising
Rising edge trigger.
@ High
High level trigger.
@ Change
Any edge (rising or falling)
constexpr Level kBasepriCeiling
The level a ScopedControlCritical raises BASEPRI to.
Definition types.hpp:56
constexpr bool masked_by_ceiling(Level level)
True if a handler at level is masked while BASEPRI sits at the ceiling.
Definition types.hpp:67
Root namespace for all Sound Byte Libs code.
Definition assert.hpp:51