FreeRTOS Addons
Loading...
Searching...
No Matches
tasklet.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 TASKLET_HPP_
43#define TASKLET_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#include "semphr.h"
64
65
66namespace cpp_freertos {
67
68
69#ifndef CPP_FREERTOS_NO_EXCEPTIONS
73class TaskletCreateException : public std::exception {
74
75 public:
80 {
81 sprintf(errorString, "Tasklet Constructor Failed");
82 }
83
87 explicit TaskletCreateException(const char *info)
88 {
89 snprintf(errorString, sizeof(errorString),
90 "Tasklet Constructor Failed %s", info);
91 }
92
97 virtual const char *what() const throw()
98 {
99 return errorString;
100 }
101
102 private:
106 char errorString[80];
107};
108#endif
109
110
121class Tasklet {
122
124 //
125 // Public API
126 //
128 public:
134 Tasklet();
135
141 virtual ~Tasklet();
142
152 bool Schedule( uint32_t parameter,
153 TickType_t CmdTimeout = portMAX_DELAY);
154
166 bool ScheduleFromISR( uint32_t parameter,
167 BaseType_t *pxHigherPriorityTaskWoken);
168
170 //
171 // Protected API
172 // Available from inside your Tasklet implementation.
173 // You should make sure that you are only calling these methods
174 // from within your Run() method, or that your Run() method is on the
175 // callstack.
176 //
178 protected:
185 virtual void Run(uint32_t parameter) = 0;
186
191 void CheckForSafeDelete();
192
194 //
195 // Private API
196 // The internals of this wrapper class.
197 //
199 private:
206 static void TaskletAdapterFunction(void *ref, uint32_t parameter);
207
211 SemaphoreHandle_t DtorLock;
212};
213
214}
215#endif
216
Definition: tasklet.hpp:73
TaskletCreateException()
Definition: tasklet.hpp:79
virtual const char * what() const
Definition: tasklet.hpp:97
TaskletCreateException(const char *info)
Definition: tasklet.hpp:87
Definition: tasklet.hpp:121
virtual ~Tasklet()
Definition: ctasklet.cpp:62
bool ScheduleFromISR(uint32_t parameter, BaseType_t *pxHigherPriorityTaskWoken)
Definition: ctasklet.cpp:104
virtual void Run(uint32_t parameter)=0
bool Schedule(uint32_t parameter, TickType_t CmdTimeout=portMAX_DELAY)
Definition: ctasklet.cpp:82
void CheckForSafeDelete()
Definition: ctasklet.cpp:67
Tasklet()
Definition: ctasklet.cpp:46
Definition: condition_variable.hpp:57