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
cycles_requirements.hpp
Go to the documentation of this file.
1/**
2 * @file cycles_requirements.hpp
3 * @brief The cycle port: what the profiling tools need from a target
4 *
5 * Each MCU directory provides `sbl::driver::Cycles` in `system/port/cycles.hpp`,
6 * mounted on the include path as <sbl/system/port/cycles.hpp>:
7 * - `init()` - start the counter; boot-time only
8 * - `read() -> uint32_t` - the count, one load, wrapping at 2^32
9 * - `rate() -> uint32_t` (constexpr) - counts per second
10 *
11 * Checked at compile time the way hw/validation checks the driver contracts.
12 * The detection lives here because system/ does not include hw/.
13 *
14 * Usage:
15 * @code
16 * static_assert(sbl::system::port::cycles_port_valid<sbl::driver::Cycles>,
17 * "the cycle port does not meet its contract");
18 * @endcode
19 */
20
21#ifndef SBL_SYSTEM_PORT_CYCLES_REQUIREMENTS_HPP_
22#define SBL_SYSTEM_PORT_CYCLES_REQUIREMENTS_HPP_
23
24#include <cstdint>
25#include <type_traits>
26
28
29namespace detail {
30
31template<typename T, typename = void>
32struct has_cycles_init : std::false_type {};
33template<typename T>
34struct has_cycles_init<T, std::void_t<decltype(T::init())>> : std::true_type {};
35
36template<typename T, typename = void>
37struct has_cycles_read : std::false_type {};
38template<typename T>
39struct has_cycles_read<T, std::void_t<decltype(T::read())>> : std::is_same<decltype(T::read()), uint32_t> {};
40
41template<typename T, typename = void>
42struct has_cycles_rate : std::false_type {};
43template<typename T>
44struct has_cycles_rate<T, std::void_t<decltype(T::rate())>> : std::is_same<decltype(T::rate()), uint32_t> {};
45
46} // namespace detail
47
48/** Validates a cycle port, with one message per missing method. */
49template<typename Port>
51 static_assert(detail::has_cycles_init<Port>::value, "SBL ERROR: cycle port missing init().\n"
52 "Required: static void init()");
53 static_assert(detail::has_cycles_read<Port>::value, "SBL ERROR: cycle port missing read().\n"
54 "Required: static uint32_t read()");
55 static_assert(detail::has_cycles_rate<Port>::value, "SBL ERROR: cycle port missing rate().\n"
56 "Required: static constexpr uint32_t rate()");
57 static constexpr bool value = detail::has_cycles_init<Port>::value && detail::has_cycles_read<Port>::value &&
58 detail::has_cycles_rate<Port>::value;
59};
60
61template<typename Port>
62inline constexpr bool cycles_port_valid = CyclesPortValidator<Port>::value;
63
64} // namespace sbl::system::port
65
66#endif // SBL_SYSTEM_PORT_CYCLES_REQUIREMENTS_HPP_