FreeRTOS-Cpp
Kernel.hpp
1 /*
2  * FreeRTOS-Cpp
3  * Copyright (C) 2021 Jon Enz. All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  *
25  * https://github.com/jonenz/FreeRTOS-Cpp
26  */
27 
28 #ifndef FREERTOS_KERNEL_HPP
29 #define FREERTOS_KERNEL_HPP
30 
31 #include "FreeRTOS.h"
32 #include "task.h"
33 
34 namespace FreeRTOS {
35 
40 namespace Kernel {
41 enum class SchedulerState : BaseType_t {
42  Suspended = taskSCHEDULER_SUSPENDED,
43  NotStarted = taskSCHEDULER_NOT_STARTED,
44  Running = taskSCHEDULER_RUNNING,
45 };
46 
51 inline constexpr char versionNumber[] = tskKERNEL_VERSION_NUMBER;
52 inline constexpr BaseType_t versionMajor = tskKERNEL_VERSION_MAJOR;
53 inline constexpr BaseType_t versionMinor = tskKERNEL_VERSION_MINOR;
54 inline constexpr BaseType_t versionBuild = tskKERNEL_VERSION_BUILD;
55 
56 #if (INCLUDE_xTaskGetSchedulerState == 1)
67 inline SchedulerState getSchedulerState() {
68  return static_cast<SchedulerState>(xTaskGetSchedulerState());
69 }
70 #endif /* INCLUDE_xTaskGetSchedulerState */
71 
84 inline UBaseType_t getNumberOfTasks() { return uxTaskGetNumberOfTasks(); }
85 
86 #if (INCLUDE_xTaskGetIdleTaskHandle == 1 && configGENERATE_RUN_TIME_STATS == 1)
107 inline TickType_t getIdleRunTimeCounter() {
108  return xTaskGetIdleRunTimeCounter();
109 }
110 #endif /* INCLUDE_xTaskGetIdleTaskHandle && configGENERATE_RUN_TIME_STATS*/
111 
122 inline TickType_t getTickCount() { return xTaskGetTickCount(); }
123 
139 inline TickType_t getTickCountFromISR() { return xTaskGetTickCountFromISR(); }
140 
153 inline void yield() { taskYIELD(); }
154 
171 inline void enterCritical() { taskENTER_CRITICAL(); }
172 
195 inline uint32_t enterCriticalFromISR() { return taskENTER_CRITICAL_FROM_ISR(); }
196 
213 inline void exitCritical() { taskEXIT_CRITICAL(); }
214 
236 inline void exitCriticalFromISR(const uint32_t interruptStatus) {
237  taskEXIT_CRITICAL_FROM_ISR(interruptStatus);
238 }
239 
249 inline void disableInterrupts() { taskDISABLE_INTERRUPTS(); }
250 
260 inline void enableInterrupts() { taskENABLE_INTERRUPTS(); }
261 
275 inline void startScheduler() { vTaskStartScheduler(); }
276 
308 inline void endScheduler() { vTaskEndScheduler(); }
309 
331 inline void suspendAll() { vTaskSuspendAll(); }
332 
353 inline bool resumeAll() { return (xTaskResumeAll() == pdTRUE); }
354 
372 inline void stepTick(const TickType_t ticksToJump) {
373  vTaskStepTick(ticksToJump);
374 }
375 
402 inline bool catchUpTicks(const TickType_t ticksToCatchUp) {
403  return (xTaskCatchUpTicks(ticksToCatchUp) == pdTRUE);
404 }
405 } // namespace Kernel
406 
407 } // namespace FreeRTOS
408 
409 #endif // FREERTOS_KERNEL_HPP
void stepTick(const TickType_t ticksToJump)
Function that calls vTaskStepTick( const TickType_t xTicksToJump )
Definition: Kernel.hpp:372
bool catchUpTicks(const TickType_t ticksToCatchUp)
Function that calls xTaskCatchUpTicks( TickType_t xTicksToCatchUp )
Definition: Kernel.hpp:402
constexpr char versionNumber[]
If versionNumber ends with + it represents the version in development after the numbered release.
Definition: Kernel.hpp:51
bool resumeAll()
Function that calls xTaskResumeAll()
Definition: Kernel.hpp:353
void endScheduler()
Function that calls vTaskEndScheduler()
Definition: Kernel.hpp:308
void disableInterrupts()
Function that calls taskDISABLE_INTERRUPTS()
Definition: Kernel.hpp:249
void suspendAll()
Function that calls vTaskSuspendAll()
Definition: Kernel.hpp:331
void enterCritical()
Function that calls taskENTER_CRITICAL()
Definition: Kernel.hpp:171
TickType_t getTickCount()
Function that calls xTaskGetTickCount()
Definition: Kernel.hpp:122
TickType_t getIdleRunTimeCounter()
Function that calls xTaskGetIdleRunTimeCounter()
Definition: Kernel.hpp:107
void exitCritical()
Function that calls taskEXIT_CRITICAL()
Definition: Kernel.hpp:213
UBaseType_t getNumberOfTasks()
Function that calls uxTaskGetNumberOfTasks()
Definition: Kernel.hpp:84
void yield()
Function that calls taskYIELD()
Definition: Kernel.hpp:153
uint32_t enterCriticalFromISR()
Function that calls taskENTER_CRITICAL_FROM_ISR()
Definition: Kernel.hpp:195
SchedulerState getSchedulerState()
Function that calls xTaskGetSchedulerState()
Definition: Kernel.hpp:67
void startScheduler()
Function that calls vTaskStartScheduler()
Definition: Kernel.hpp:275
void enableInterrupts()
Function that calls taskENABLE_INTERRUPTS()
Definition: Kernel.hpp:260
void exitCriticalFromISR(const uint32_t interruptStatus)
Function that calls taskEXIT_CRITICAL_FROM_ISR()
Definition: Kernel.hpp:236
TickType_t getTickCountFromISR()
Function that calls xTaskGetTickCountFromISR()
Definition: Kernel.hpp:139