Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
timer_requirements.hpp
Go to the documentation of this file.
1/**
2 * @file timer_requirements.hpp
3 * @brief Timer driver requirements validator
4 * @ingroup validation
5 *
6 * Validates that Timer drivers provide required functionality using the
7 * method detection system.
8 *
9 * ## Timer Driver Contract
10 *
11 * Every Sound Byte Libs Timer driver MUST implement these methods:
12 * - `busy_wait_ms(uint32_t)` - Blocking millisecond delay
13 * - `millis() -> uint32_t` - Milliseconds since boot
14 * - `micros() -> uint32_t` - Microseconds since boot
15 *
16 * Optional methods (validated if present):
17 * - `init(uint32_t)` - Initialize timer (STM32 needs it, RP2xxx don't)
18 *
19 * ## Validation Usage
20 *
21 * Add validation at the bottom of driver timer.hpp:
22 * ```cpp
23 * #include <sbl/validation/timer_requirements.hpp>
24 * static_assert(sbl::validation::timer_driver_valid<sbl::driver::Timer>,
25 * "Timer driver missing required methods");
26 * ```
27 *
28 * @see method_detection.hpp
29 */
30
31#ifndef SBL_VALIDATION_TIMER_REQUIREMENTS_HPP_
32#define SBL_VALIDATION_TIMER_REQUIREMENTS_HPP_
33
34#include "method_detection.hpp"
35
36namespace sbl {
37namespace validation {
38
39/**
40 * @brief Timer driver requirements validator
41 *
42 * Validates that Timer drivers provide all required methods with correct
43 * signatures and return types.
44 */
45template<typename TimerDriver>
47public:
48 /**
49 * @brief Validate all required Timer methods
50 */
51 static constexpr bool validate() {
52 // --- Required methods (all platforms) ---
53
55 "SBL ERROR: Timer driver missing busy_wait_ms() method.\n"
56 "Required: static void busy_wait_ms(uint32_t)");
57
59 "SBL ERROR: Timer driver missing millis() method.\n"
60 "Required: static uint32_t millis()");
61
63 "SBL ERROR: Timer driver missing micros() method.\n"
64 "Required: static uint32_t micros()");
65
66 // --- Return type validation ---
67
69 "SBL ERROR: Timer micros() must return uint32_t.");
70
71 // --- Optional methods (validated if present) ---
72 // init(uint32_t) — STM32 needs it for SysTick setup, RP2xxx don't.
73 // No return type constraint (STM32 returns bool, others may return void).
74
75 return true;
76 }
77};
78
79/**
80 * @brief Helper to validate a Timer driver implementation
81 *
82 * Usage:
83 * ```cpp
84 * static_assert(sbl::validation::timer_driver_valid<MyTimerDriver>,
85 * "Timer driver incomplete");
86 * ```
87 */
88template<typename TimerDriver>
90
91} // namespace validation
92} // namespace sbl
93
94#endif // SBL_VALIDATION_TIMER_REQUIREMENTS_HPP_
Timer driver requirements validator.
static constexpr bool validate()
Validate all required Timer methods.
Method and interface detection for driver validation.
constexpr bool timer_driver_valid
Helper to validate a Timer driver implementation.
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24