Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
interrupts_requirements.hpp
Go to the documentation of this file.
1/**
2 * @file interrupts_requirements.hpp
3 * @brief Interrupts driver requirements validator
4 * @ingroup validation
5 *
6 * ## Interrupts Driver Contract
7 *
8 * Every MCU provides `sbl::driver::Interrupts` with these static methods:
9 * - `save_ceiling() -> uint32_t` - The current mask, opaque, for restore_ceiling()
10 * - `raise_ceiling(Level)` - Mask `level` and everything less urgent; never lowers the mask
11 * - `restore_ceiling(uint32_t)` - Put back a mask from save_ceiling()
12 * - `disable_all() -> uint32_t` - Mask every configurable exception; returns the previous state
13 * - `restore_all(uint32_t)` - Put back the state from disable_all()
14 *
15 * Levels are sbl::system::interrupts::Level; the encoding to a hardware
16 * priority is the driver's. disable_all() blocks audio and is for death
17 * paths only (assert, fault); critical sections use ScopedControlCritical.
18 *
19 * ## Validation Usage
20 *
21 * At the bottom of the driver's interrupts.hpp:
22 * ```cpp
23 * #include <sbl/hw/validation/interrupts_requirements.hpp>
24 * static_assert(sbl::validation::interrupts_driver_valid<sbl::driver::Interrupts>,
25 * "Interrupts driver incomplete");
26 * ```
27 */
28
29#ifndef SBL_HW_VALIDATION_INTERRUPTS_REQUIREMENTS_HPP_
30#define SBL_HW_VALIDATION_INTERRUPTS_REQUIREMENTS_HPP_
31
32#include <cstdint>
33#include <type_traits>
34#include <utility>
35
37
38namespace sbl {
39namespace validation {
40
41namespace detail {
42
44
45template<typename T, typename = void>
46struct has_save_ceiling : std::false_type {};
47template<typename T>
48struct has_save_ceiling<T, std::void_t<decltype(T::save_ceiling())>>
49 : std::is_same<decltype(T::save_ceiling()), uint32_t> {};
50
51template<typename T, typename = void>
52struct has_raise_ceiling : std::false_type {};
53template<typename T>
54struct has_raise_ceiling<T, std::void_t<decltype(T::raise_ceiling(std::declval<Level>()))>> : std::true_type {};
55
56template<typename T, typename = void>
57struct has_restore_ceiling : std::false_type {};
58template<typename T>
59struct has_restore_ceiling<T, std::void_t<decltype(T::restore_ceiling(std::declval<uint32_t>()))>> : std::true_type {};
60
61template<typename T, typename = void>
62struct has_disable_all : std::false_type {};
63template<typename T>
64struct has_disable_all<T, std::void_t<decltype(T::disable_all())>>
65 : std::is_same<decltype(T::disable_all()), uint32_t> {};
66
67template<typename T, typename = void>
68struct has_restore_all : std::false_type {};
69template<typename T>
70struct has_restore_all<T, std::void_t<decltype(T::restore_all(std::declval<uint32_t>()))>> : std::true_type {};
71
72} // namespace detail
73
74/**
75 * @brief Interrupts driver requirements validator
76 */
77template<typename InterruptsDriver>
79public:
80 static constexpr bool validate() {
81 static_assert(detail::has_save_ceiling<InterruptsDriver>::value,
82 "SBL ERROR: Interrupts driver missing save_ceiling().\n"
83 "Required: static uint32_t save_ceiling()");
84
85 static_assert(detail::has_raise_ceiling<InterruptsDriver>::value,
86 "SBL ERROR: Interrupts driver missing raise_ceiling().\n"
87 "Required: static void raise_ceiling(sbl::system::interrupts::Level)");
88
89 static_assert(detail::has_restore_ceiling<InterruptsDriver>::value,
90 "SBL ERROR: Interrupts driver missing restore_ceiling().\n"
91 "Required: static void restore_ceiling(uint32_t)");
92
93 static_assert(detail::has_disable_all<InterruptsDriver>::value,
94 "SBL ERROR: Interrupts driver missing disable_all().\n"
95 "Required: static uint32_t disable_all()");
96
97 static_assert(detail::has_restore_all<InterruptsDriver>::value,
98 "SBL ERROR: Interrupts driver missing restore_all().\n"
99 "Required: static void restore_all(uint32_t)");
100
101 return true;
102 }
103};
104
105/**
106 * @brief Helper to validate an interrupts driver implementation
107 */
108template<typename InterruptsDriver>
110
111} // namespace validation
112} // namespace sbl
113
114#endif // SBL_HW_VALIDATION_INTERRUPTS_REQUIREMENTS_HPP_
Interrupts driver requirements validator.
Interrupt execution levels and the control critical section.
Level
Execution levels, most urgent first.
constexpr bool interrupts_driver_valid
Helper to validate an interrupts driver implementation.
Root namespace for all Sound Byte Libs code.