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
timer_requirements.hpp
Go to the documentation of this file.
1
/**
2
* @file timer_requirements.hpp
3
* @brief The periodic-callback timer contract
4
* @ingroup validation
5
*
6
* Every MCU provides `sbl::driver::TimerCallback`, one periodic interrupt
7
* with one callback (the control tick's base period):
8
* - `start(uint32_t period_us, void (*cb)())` - start; a second start while running is an error
9
* - `set_period(uint32_t period_us)` - change the period
10
* - `stop()` - stop
11
*
12
* The free-running counter is the tick port, whose contract is
13
* <sbl/system/port/tick_requirements.hpp>.
14
*
15
* Usage, at the bottom of a driver's timer_callback.hpp:
16
* @code
17
* #include <sbl/hw/validation/timer_requirements.hpp>
18
* static_assert(sbl::validation::timer_callback_valid<sbl::driver::TimerCallback>,
19
* "TimerCallback driver incomplete");
20
* @endcode
21
*/
22
23
#ifndef SBL_HW_VALIDATION_TIMER_REQUIREMENTS_HPP_
24
#define SBL_HW_VALIDATION_TIMER_REQUIREMENTS_HPP_
25
26
#include <cstdint>
27
#include <type_traits>
28
29
namespace
sbl
{
30
namespace
validation {
31
32
template
<
typename
T,
typename
=
void
>
33
struct
has_timer_callback_start
: std::false_type {};
34
template
<
typename
T>
35
struct
has_timer_callback_start
<T,
36
std::void_t<decltype(T::start(std::declval<uint32_t>(), std::declval<void (*)()>()))>>
37
: std::true_type {};
38
39
template
<
typename
T,
typename
=
void
>
40
struct
has_timer_callback_set_period
: std::false_type {};
41
template
<
typename
T>
42
struct
has_timer_callback_set_period
<T, std::void_t<decltype(T::set_period(std::declval<uint32_t>()))>>
43
: std::true_type {};
44
45
template
<
typename
T,
typename
=
void
>
46
struct
has_timer_callback_stop
: std::false_type {};
47
template
<
typename
T>
48
struct
has_timer_callback_stop
<T, std::void_t<decltype(T::stop())>> : std::true_type {};
49
50
/** Validates a TimerCallback driver, with one message per missing method. */
51
template
<
typename
Driver>
52
class
TimerCallbackRequirements
{
53
public
:
54
static
constexpr
bool
validate() {
55
static_assert
(
has_timer_callback_start<Driver>::value
,
56
"SBL ERROR: TimerCallback driver missing start().\n"
57
"Required: static void start(uint32_t period_us, void (*cb)())"
);
58
static_assert
(
has_timer_callback_set_period<Driver>::value
,
59
"SBL ERROR: TimerCallback driver missing set_period().\n"
60
"Required: static void set_period(uint32_t period_us)"
);
61
static_assert
(
has_timer_callback_stop<Driver>::value
,
"SBL ERROR: TimerCallback driver missing stop().\n"
62
"Required: static void stop()"
);
63
return
true
;
64
}
65
};
66
67
template
<
typename
Driver>
68
constexpr
bool
timer_callback_valid =
TimerCallbackRequirements<Driver>::validate
();
69
70
}
// namespace validation
71
}
// namespace sbl
72
73
#endif
// SBL_HW_VALIDATION_TIMER_REQUIREMENTS_HPP_
sbl::validation::TimerCallbackRequirements
Definition
timer_requirements.hpp:52
sbl
Root namespace for all Sound Byte Libs code.
Definition
audio_capture.hpp:16
sbl::validation::has_timer_callback_set_period
Definition
timer_requirements.hpp:40
sbl::validation::has_timer_callback_start
Definition
timer_requirements.hpp:33
sbl::validation::has_timer_callback_stop
Definition
timer_requirements.hpp:46
src
sbl
hw
validation
timer_requirements.hpp
Generated by
1.9.8