ClearCore Library
Loading...
Searching...
No Matches
SysTimer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Teknic, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
28#ifndef __SYSTIMER_H__
29#define __SYSTIMER_H__
30
31#include "SysTiming.h"
32
33namespace ClearCore {
34
42class SysTimer {
43
44protected:
45 // Timer state variables
46 uint32_t m_timerStart = 0;
47 uint32_t m_timerDelay = 0;
48
52 SysTimer() {}
53
60 SysTimer(uint32_t delay) {
61 m_timerDelay = delay;
62 }
63
64public:
71 void SetDelay(uint32_t delay) {
72 m_timerDelay = delay;
73 }
74
81 void Start(uint32_t delay) {
82 m_timerDelay = delay;
83 m_timerStart = Now();
84 }
85
89 void Start() {
90 m_timerStart = Now();
91 }
92
103 bool Completed() {
104 return (Now() - m_timerStart) >= m_timerDelay;
105 }
106
117 uint32_t Elapsed() {
118 return Now() - m_timerStart;
119 }
120
121private:
132 virtual uint32_t Now() = 0;
133
134}; // SysTimer
135
140class SysTimerMs : public SysTimer {
141
142public:
147
153 SysTimerMs(uint32_t delay) : SysTimer(delay) {
154 m_timerStart = Now();
155 }
156
157private:
163 uint32_t Now() override {
164 return Milliseconds();
165 }
166
167}; // SysTimerMs
168
173class SysTimerUs : public SysTimer {
174
175public:
180
186 SysTimerUs(uint32_t delay) : SysTimer(delay) {
187 m_timerStart = Now();
188 }
189
190private:
196 uint32_t Now() override {
197 return Microseconds();
198 }
199
200}; // SysTimerUs
201
202} // ClearCore namespace
203
204#endif //__SYSTIMER_H__
ClearCore timing profiling utility functions.
uint32_t Microseconds(void)
Number of microseconds since the ClearCore was initialized.
uint32_t Milliseconds(void)
Number of milliseconds since the ClearCore was initialized.
ClearCore system timer/stopwatch class.
Definition SysTimer.h:42
uint32_t Elapsed()
Check how much time has elapsed since the start of the timer.
Definition SysTimer.h:117
bool Completed()
Check to see if the timer has completed.
Definition SysTimer.h:103
void Start(uint32_t delay)
Starts the timer with a delay argument.
Definition SysTimer.h:81
void Start()
Starts the timer with the default or configured delay.
Definition SysTimer.h:89
void SetDelay(uint32_t delay)
Set the delay of the timer.
Definition SysTimer.h:71
ClearCore system timer/stopwatch class using millisecond time base.
Definition SysTimer.h:140
SysTimerMs(uint32_t delay)
Construct and specify the timer's delay.
Definition SysTimer.h:153
SysTimerMs()
Default constructor.
Definition SysTimer.h:146
ClearCore system timer/stopwatch class using microsecond time base.
Definition SysTimer.h:173
SysTimerUs(uint32_t delay)
Construct and specify the timer's delay.
Definition SysTimer.h:186
SysTimerUs()
Default constructor.
Definition SysTimer.h:179
Namespace to encompass the ClearCore board API.
Definition AdcManager.h:36