FreeRTOScpp
Loading...
Searching...
No Matches
FreeRTOScpp.h
Go to the documentation of this file.
1/**
2 * @file FreeRTOScpp.h
3 * @brief FreeRTOS Wrapper
4 *
5 * This file contains a set of lightweight wrappers for tasks using FreeRTOS
6 *
7 * @copyright (c) 2007-2024 Richard Damon
8 * @author Richard Damon <richard.damon@gmail.com>
9 * @parblock
10 * MIT License:
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this software and associated documentation files (the "Software"), to deal
14 * in the Software without restriction, including without limitation the rights
15 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 * copies of the Software, and to permit persons to whom the Software is
17 * furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 * THE SOFTWARE.
29 *
30 * It is requested (but not required by license) that any bugs found or
31 * improvements made be shared, preferably to the author.
32 * @endparblock
33 *
34 * @ingroup FreeRTOSCpp
35 */
36
37#ifndef FREERTOSPP_FREERTOSCPP_H_
38#define FREERTOSPP_FREERTOSCPP_H_
39
40#include "FreeRTOS.h"
41#include "task.h" // For Version Numbers
42
43/**
44 * @def FREERTOSCPP_USE_CHRONO
45 * Enable the use of C++ chrono time values.
46 *
47 * @ingroup FreeRTOSCpp
48 *
49 * @def FREERTOS_USE_NAMESPACE
50 * If non-zero, put FreeRTOScpp library into namespace FreeRTOScpp.
51 * If 2, adds a using namespace FreeRTOScpp, so code doesn't need to use that namespace unless conflicts arise.
52 * @ingroup FreeRTOSCpp
53 */
54
55#if DOXYGEN
56#define FREERTOSCPP_USE_CHRONO 1
57#define FREERTOS_USE_NAMESPACE 2
58#endif
59
60#define FREERTOS_VERSION_ALL (tskKERNEL_VERSION_MAJOR * 1'000'000 + tskKERNEL_VERSION_MINOR * 1000 + tskKERNEL_VERSION_BUILD)
61
62#ifndef FREERTOSCPP_USE_CHRONO
63#define FREERTOSCPP_USE_CHRONO 1 // Define to 1 to add C++ chrono time versions
64#endif
65
66#ifndef FREERTOSCPP_USE_NAMESPACE
67#define FREERTOSCPP_USE_NAMESPACE 2 // 0 = No Namespace, 1 = In namespace FreeRTOScpp, 2 = In namespace FreeRTOScpp and then use the namespace
68#endif
69
70#if FREERTOSCPP_USE_CHRONO
71#include <chrono>
72#endif
73
74namespace FreeRTOScpp {
75
76#if FREERTOSCPP_USE_CHRONO
77// Code to use std::chrono::durations optionally for times
78
79typedef std::chrono::milliseconds Time_ms;
80
81inline constexpr TickType_t ms2ticks(Time_ms ms) {
82 return pdMS_TO_TICKS(ms.count());
83}
84#endif
85
86} // namespace FreeRTOScpp
87#if FREERTOSCPP_USE_NAMESPACE == 2
88using namespace FreeRTOScpp;
89#endif
90
91#endif /* FREERTOSPP_FREERTOSCPP_H_ */
Definition FreeRTOScpp.h:74