FreeRTOS Addons
Loading...
Searching...
No Matches
timer.hpp
1/****************************************************************************
2 *
3 * Copyright (c) 2017, Michael Becker (michael.f.becker@gmail.com)
4 *
5 * This file is part of the FreeRTOS Add-ons project.
6 *
7 * Source Code:
8 * https://github.com/michaelbecker/freertos-addons
9 *
10 * Project Page:
11 * http://michaelbecker.github.io/freertos-addons/
12 *
13 * On-line Documentation:
14 * http://michaelbecker.github.io/freertos-addons/docs/html/index.html
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files
18 * (the "Software"), to deal in the Software without restriction, including
19 * without limitation the rights to use, copy, modify, merge, publish,
20 * distribute, sublicense, and/or sell copies of the Software, and to
21 * permit persons to whom the Software is furnished to do so,subject to the
22 * following conditions:
23 *
24 * + The above copyright notice and this permission notice shall be included
25 * in all copies or substantial portions of the Software.
26 * + Credit is appreciated, but not required, if you find this project
27 * useful enough to include in your application, product, device, etc.
28 *
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
33 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
34 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
35 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 *
37 ***************************************************************************/
38
39
40#include "freertos-config.h"
41
42#ifndef TIMER_HPP_
43#define TIMER_HPP_
44
45
53#ifndef CPP_FREERTOS_NO_EXCEPTIONS
54#include <exception>
55#include <string>
56#include <cstdio>
57#ifdef CPP_FREERTOS_NO_CPP_STRINGS
58#error "FreeRTOS-Addons require C++ Strings if you are using exceptions"
59#endif
60#endif
61#include "FreeRTOS.h"
62#include "timers.h"
63
64
65namespace cpp_freertos {
66
67
68#ifndef CPP_FREERTOS_NO_EXCEPTIONS
72class TimerCreateException : public std::exception {
73
74 public:
79 {
80 sprintf(errorString, "Timer Constructor Failed");
81 }
82
87 virtual const char *what() const throw()
88 {
89 return errorString;
90 }
91
92 private:
96 char errorString[40];
97};
98#endif
99
100
109class Timer {
110
112 //
113 // Public API
114 //
116 public:
129 Timer( const char * const TimerName,
130 TickType_t PeriodInTicks,
131 bool Periodic = true
132 );
133
145 Timer( TickType_t PeriodInTicks,
146 bool Periodic = true
147 );
148
152 virtual ~Timer();
153
159 bool IsActive();
160
169 bool Start(TickType_t CmdTimeout = portMAX_DELAY);
170
179 bool StartFromISR(BaseType_t *pxHigherPriorityTaskWoken);
180
189 bool Stop(TickType_t CmdTimeout = portMAX_DELAY);
190
199 bool StopFromISR(BaseType_t *pxHigherPriorityTaskWoken);
200
209 bool Reset(TickType_t CmdTimeout = portMAX_DELAY);
210
219 bool ResetFromISR(BaseType_t *pxHigherPriorityTaskWoken);
220
230 bool SetPeriod( TickType_t NewPeriod,
231 TickType_t CmdTimeout = portMAX_DELAY);
232
242 bool SetPeriodFromISR( TickType_t NewPeriod,
243 BaseType_t *pxHigherPriorityTaskWoken);
244
245#if (INCLUDE_xTimerGetTimerDaemonTaskHandle == 1)
252 static TaskHandle_t GetTimerDaemonHandle();
253#endif
254
256 //
257 // Protected API
258 // Available from inside your Thread implementation.
259 // You should make sure that you are only calling these methods
260 // from within your Run() method, or that your Run() method is on the
261 // callstack.
262 //
264 protected:
269 virtual void Run() = 0;
270
272 //
273 // Private API
274 // The internals of this wrapper class.
275 //
277 private:
281 TimerHandle_t handle;
282
289 static void TimerCallbackFunctionAdapter(TimerHandle_t xTimer);
290};
291
292
293}
294#endif
Definition: timer.hpp:72
TimerCreateException()
Definition: timer.hpp:78
virtual const char * what() const
Definition: timer.hpp:87
Definition: timer.hpp:109
bool SetPeriodFromISR(TickType_t NewPeriod, BaseType_t *pxHigherPriorityTaskWoken)
Definition: ctimer.cpp:146
virtual ~Timer()
Definition: ctimer.cpp:87
bool Stop(TickType_t CmdTimeout=portMAX_DELAY)
Definition: ctimer.cpp:112
bool Start(TickType_t CmdTimeout=portMAX_DELAY)
Definition: ctimer.cpp:99
bool StopFromISR(BaseType_t *pxHigherPriorityTaskWoken)
Definition: ctimer.cpp:118
bool Reset(TickType_t CmdTimeout=portMAX_DELAY)
Definition: ctimer.cpp:125
bool IsActive()
Definition: ctimer.cpp:93
bool SetPeriod(TickType_t NewPeriod, TickType_t CmdTimeout=portMAX_DELAY)
Definition: ctimer.cpp:138
bool ResetFromISR(BaseType_t *pxHigherPriorityTaskWoken)
Definition: ctimer.cpp:131
virtual void Run()=0
bool StartFromISR(BaseType_t *pxHigherPriorityTaskWoken)
Definition: ctimer.cpp:105
static TaskHandle_t GetTimerDaemonHandle()
Definition: ctimer.cpp:157
Definition: condition_variable.hpp:57