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
tick_requirements.hpp
Go to the documentation of this file.
1/**
2 * @file tick_requirements.hpp
3 * @brief The tick port: the hardware timer under the system timer
4 *
5 * Each MCU directory provides `sbl::driver::Tick` in `system/port/tick.hpp`,
6 * mounted on the include path as <sbl/system/port/tick.hpp>. It is a
7 * free-running counter with an overflow interrupt, shaped like CMSIS-RTOS2's
8 * OS Tick API:
9 * - `init()` - start counting; boot-time only, on every boot path
10 * - `setup(void (*handler)())` - register the overflow handler
11 * - `enable()`, `disable()` - the overflow interrupt on and off
12 * - `acknowledge()` - clear the overflow flag
13 * - `overflow() -> bool` - the overflow flag is pending
14 * - `count() -> uint32_t` - the count, one load, wrapping at 2^32
15 * - `rate() -> uint32_t` (constexpr) - counts per second
16 *
17 * The system timer (system/timer.hpp) composes the 64-bit count, the waits
18 * and millis() on top; the port carries no units beyond its rate.
19 */
20
21#ifndef SBL_SYSTEM_PORT_TICK_REQUIREMENTS_HPP_
22#define SBL_SYSTEM_PORT_TICK_REQUIREMENTS_HPP_
23
24#include <cstdint>
25#include <type_traits>
26
27namespace sbl::system::port {
28
29namespace detail {
30
31template<typename T, typename = void>
32struct has_tick_init : std::false_type {};
33template<typename T>
34struct has_tick_init<T, std::void_t<decltype(T::init())>> : std::true_type {};
35
36template<typename T, typename = void>
37struct has_tick_setup : std::false_type {};
38template<typename T>
39struct has_tick_setup<T, std::void_t<decltype(T::setup(std::declval<void (*)()>()))>> : std::true_type {};
40
41template<typename T, typename = void>
42struct has_tick_enable : std::false_type {};
43template<typename T>
44struct has_tick_enable<T, std::void_t<decltype(T::enable()), decltype(T::disable())>> : std::true_type {};
45
46template<typename T, typename = void>
47struct has_tick_overflow : std::false_type {};
48template<typename T>
49struct has_tick_overflow<T, std::void_t<decltype(T::acknowledge()), decltype(T::overflow())>>
50 : std::is_same<decltype(T::overflow()), bool> {};
51
52template<typename T, typename = void>
53struct has_tick_count : std::false_type {};
54template<typename T>
55struct has_tick_count<T, std::void_t<decltype(T::count())>> : std::is_same<decltype(T::count()), uint32_t> {};
56
57template<typename T, typename = void>
58struct has_tick_rate : std::false_type {};
59template<typename T>
60struct has_tick_rate<T, std::void_t<decltype(T::rate())>> : std::is_same<decltype(T::rate()), uint32_t> {};
61
62} // namespace detail
63
64/** Validates a tick port, with one message per missing method. */
65template<typename Port>
67 static_assert(detail::has_tick_init<Port>::value, "SBL ERROR: tick port missing init().\n"
68 "Required: static void init()");
69 static_assert(detail::has_tick_setup<Port>::value, "SBL ERROR: tick port missing setup(handler).\n"
70 "Required: static void setup(void (*handler)())");
71 static_assert(detail::has_tick_enable<Port>::value, "SBL ERROR: tick port missing enable()/disable().\n"
72 "Required: static void enable(), static void disable()");
73 static_assert(detail::has_tick_overflow<Port>::value,
74 "SBL ERROR: tick port missing acknowledge()/overflow().\n"
75 "Required: static void acknowledge(), static bool overflow()");
76 static_assert(detail::has_tick_count<Port>::value, "SBL ERROR: tick port missing count().\n"
77 "Required: static uint32_t count()");
78 static_assert(detail::has_tick_rate<Port>::value, "SBL ERROR: tick port missing rate().\n"
79 "Required: static constexpr uint32_t rate()");
80 static constexpr bool value = detail::has_tick_init<Port>::value && detail::has_tick_setup<Port>::value &&
81 detail::has_tick_enable<Port>::value && detail::has_tick_overflow<Port>::value &&
82 detail::has_tick_count<Port>::value && detail::has_tick_rate<Port>::value;
83};
84
85template<typename Port>
86inline constexpr bool tick_port_valid = TickPortValidator<Port>::value;
87
88} // namespace sbl::system::port
89
90#endif // SBL_SYSTEM_PORT_TICK_REQUIREMENTS_HPP_