-
Notifications
You must be signed in to change notification settings - Fork 9
/
system_clock.hpp
106 lines (89 loc) · 2.45 KB
/
system_clock.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2020 Embedded Artistry LLC
// SPDX-License-Identifier: GPL-3.0-only OR Embedded Virtual Machine Commercial License
#ifndef SYSTEM_CLOCK_HPP_
#define SYSTEM_CLOCK_HPP_
#include "clock.hpp"
#include "driver.hpp"
namespace embvm
{
/// @addtogroup FrameworkDriver
/// @{
namespace clk
{
/** This class defines common system clock interfaces.
*
* # Define a system clock driver
*
* To create a system clock driver, derive from the SystemClock object:
*
* @code
* class SimulatorSystemClock final : public SystemClock
* { ... };
* @endcode
*
* Derived classes must implement the following interfaces:
* - frequency()
* - tips()
* - spin()
*
* Derived classes must also implement pure virtual embvm::DriverBase functions:
* - start_()
* - stop_()
*/
class SystemClock : public embvm::DriverBase
{
public:
/// Default spin increment is microseconds
using spin_duration_t = std::chrono::duration<uint32_t, std::micro>;
// std::chrono::duration type for the tick return
using tick_duration_t = std::chrono::duration<uint64_t, std::micro>;
protected:
/** Default constructor.
*
* Initializes the base class with the proper typeid.
*/
SystemClock() noexcept : embvm::DriverBase(embvm::DriverType::SYSTEM_CLOCK)
{
// empty constructor
}
/// Default destructor
~SystemClock() noexcept;
public:
/** SystemClock Driver Type ID
*
* @returns SystemClock type ID.
*/
static constexpr auto type() noexcept -> embvm::DriverType
{
return embvm::DriverType::SYSTEM_CLOCK;
}
/** Get the frequency of the system clock.
*
* @returns the frequency of the system clock, in Hz.
*/
[[nodiscard]] virtual freq_hz_t::rep frequency() const noexcept = 0;
/** Check the ticks elapsed since boot.
*
* Derived classes must implement the ticks() function.
*
* @returns ticks elapsed since boot.
*/
[[nodiscard]] virtual tick_duration_t::rep ticks() const noexcept = 0;
/** Spin the processor for the specified number of ticks.
*
* Derived classes must implement the spin() function.
*
* @param count The number of ticks to spin the processor for.
*/
virtual void spin(spin_duration_t::rep count) noexcept = 0;
protected:
// embvm::DriverBase function that derived classes must implement.
void start_() noexcept override = 0;
// embvm::DriverBase function that derived classes must implement.
void stop_() noexcept override = 0;
};
} // namespace clk
/// @}
// End group
} // namespace embvm
#endif // SYSTEM_CLOCK_HPP_