Open FFBoard
Open source force feedback firmware
ctimer.cpp
Go to the documentation of this file.
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#include "FreeRTOS.h"
40#include "timer.hpp"
41
42
43using namespace cpp_freertos;
44
45
46Timer::Timer( const char * const TimerName,
47 TickType_t PeriodInTicks,
48 bool Periodic
49 )
50{
51 handle = xTimerCreate( TimerName,
52 PeriodInTicks,
53 Periodic ? pdTRUE : pdFALSE,
54 this,
56
57 if (handle == NULL) {
58#ifndef CPP_FREERTOS_NO_EXCEPTIONS
60#else
61 configASSERT(!"Timer Constructor Failed");
62#endif
63 }
64}
65
66
67Timer::Timer( TickType_t PeriodInTicks,
68 bool Periodic
69 )
70{
71 handle = xTimerCreate( "Default",
72 PeriodInTicks,
73 Periodic ? pdTRUE : pdFALSE,
74 this,
76
77 if (handle == NULL) {
78#ifndef CPP_FREERTOS_NO_EXCEPTIONS
80#else
81 configASSERT(!"Timer Constructor Failed");
82#endif
83 }
84}
85
86
88{
89 xTimerDelete(handle, portMAX_DELAY);
90}
91
92
94{
95 return xTimerIsTimerActive(handle) == pdFALSE ? false : true;
96}
97
98
99bool Timer::Start(TickType_t CmdTimeout)
100{
101 return xTimerStart(handle, CmdTimeout) == pdFALSE ? false : true;
102}
103
104
105bool Timer::StartFromISR(BaseType_t *pxHigherPriorityTaskWoken)
106{
107 return xTimerStartFromISR(handle, pxHigherPriorityTaskWoken) == pdFALSE
108 ? false : true;
109}
110
111
112bool Timer::Stop(TickType_t CmdTimeout)
113{
114 return xTimerStop(handle, CmdTimeout) == pdFALSE ? false : true;
115}
116
117
118bool Timer::StopFromISR(BaseType_t *pxHigherPriorityTaskWoken)
119{
120 return xTimerStopFromISR(handle, pxHigherPriorityTaskWoken) == pdFALSE
121 ? false : true;
122}
123
124
125bool Timer::Reset(TickType_t CmdTimeout)
126{
127 return xTimerReset(handle, CmdTimeout) == pdFALSE ? false : true;
128}
129
130
131bool Timer::ResetFromISR(BaseType_t *pxHigherPriorityTaskWoken)
132{
133 return xTimerResetFromISR(handle, pxHigherPriorityTaskWoken) == pdFALSE
134 ? false : true;
135}
136
137
138bool Timer::SetPeriod( TickType_t NewPeriod,
139 TickType_t CmdTimeout)
140{
141 return xTimerChangePeriod(handle, NewPeriod, CmdTimeout) == pdFALSE
142 ? false : true;
143}
144
145
146bool Timer::SetPeriodFromISR( TickType_t NewPeriod,
147 BaseType_t *pxHigherPriorityTaskWoken)
148{
149 return xTimerChangePeriodFromISR( handle, NewPeriod,
150 pxHigherPriorityTaskWoken) == pdFALSE
151 ? false : true;
152}
153
154
155#if (INCLUDE_xTimerGetTimerDaemonTaskHandle == 1)
156
158{
159 return xTimerGetTimerDaemonTaskHandle();
160}
161
162#endif
163
164
165void Timer::TimerCallbackFunctionAdapter(TimerHandle_t xTimer)
166{
167 Timer *timer = static_cast<Timer *>(pvTimerGetTimerID(xTimer));
168 timer->Run();
169}
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
TimerHandle_t handle
Definition: timer.hpp:279
static void TimerCallbackFunctionAdapter(TimerHandle_t xTimer)
Definition: ctimer.cpp:165
bool Reset(TickType_t CmdTimeout=portMAX_DELAY)
Definition: ctimer.cpp:125
bool SetPeriod(TickType_t NewPeriod, TickType_t CmdTimeout=portMAX_DELAY)
Definition: ctimer.cpp:138
Timer(const char *const TimerName, TickType_t PeriodInTicks, bool Periodic=true)
Definition: ctimer.cpp:46
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