FreeRTOS-Cpp
Loading...
Searching...
No Matches
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
34namespace FreeRTOS {
35
40namespace Kernel {
41enum class SchedulerState : BaseType_t {
42 Suspended = taskSCHEDULER_SUSPENDED,
43 NotStarted = taskSCHEDULER_NOT_STARTED,
44 Running = taskSCHEDULER_RUNNING,
45};
46
51inline constexpr char versionNumber[] = tskKERNEL_VERSION_NUMBER;
52inline constexpr BaseType_t versionMajor = tskKERNEL_VERSION_MAJOR;
53inline constexpr BaseType_t versionMinor = tskKERNEL_VERSION_MINOR;
54inline constexpr BaseType_t versionBuild = tskKERNEL_VERSION_BUILD;
55
56#if (INCLUDE_xTaskGetSchedulerState == 1)
67inline SchedulerState getSchedulerState() {
68 return static_cast<SchedulerState>(xTaskGetSchedulerState());
69}
70#endif /* INCLUDE_xTaskGetSchedulerState */
71
84inline UBaseType_t getNumberOfTasks() {
85 return uxTaskGetNumberOfTasks();
86}
87
88#if (INCLUDE_xTaskGetIdleTaskHandle == 1 && configGENERATE_RUN_TIME_STATS == 1)
109inline TickType_t getIdleRunTimeCounter() {
110 return xTaskGetIdleRunTimeCounter();
111}
112#endif /* INCLUDE_xTaskGetIdleTaskHandle && configGENERATE_RUN_TIME_STATS*/
113
124inline TickType_t getTickCount() {
125 return xTaskGetTickCount();
126}
127
143inline TickType_t getTickCountFromISR() {
144 return xTaskGetTickCountFromISR();
145}
146
159inline void yield() {
160 taskYIELD();
161}
162
179inline void enterCritical() {
180 taskENTER_CRITICAL();
181}
182
205inline uint32_t enterCriticalFromISR() {
206 return taskENTER_CRITICAL_FROM_ISR();
207}
208
225inline void exitCritical() {
226 taskEXIT_CRITICAL();
227}
228
250inline void exitCriticalFromISR(const uint32_t interruptStatus) {
251 taskEXIT_CRITICAL_FROM_ISR(interruptStatus);
252}
253
263inline void disableInterrupts() {
264 taskDISABLE_INTERRUPTS();
265}
266
276inline void enableInterrupts() {
277 taskENABLE_INTERRUPTS();
278}
279
293inline void startScheduler() {
294 vTaskStartScheduler();
295}
296
328inline void endScheduler() {
329 vTaskEndScheduler();
330}
331
353inline void suspendAll() {
354 vTaskSuspendAll();
355}
356
377inline bool resumeAll() {
378 return (xTaskResumeAll() == pdTRUE);
379}
380
381#if (configUSE_TICKLESS_IDLE != 0)
399inline void stepTick(const TickType_t ticksToJump) {
400 vTaskStepTick(ticksToJump);
401}
402#endif /* configUSE_TICKLESS_IDLE */
403
430inline bool catchUpTicks(const TickType_t ticksToCatchUp) {
431 return (xTaskCatchUpTicks(ticksToCatchUp) == pdTRUE);
432}
433} // namespace Kernel
434
435} // namespace FreeRTOS
436
437#endif // FREERTOS_KERNEL_HPP
void stepTick(const TickType_t ticksToJump)
Function that calls vTaskStepTick( const TickType_t xTicksToJump )
Definition Kernel.hpp:399
bool catchUpTicks(const TickType_t ticksToCatchUp)
Function that calls xTaskCatchUpTicks( TickType_t xTicksToCatchUp )
Definition Kernel.hpp:430
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:377
void endScheduler()
Function that calls vTaskEndScheduler()
Definition Kernel.hpp:328
void disableInterrupts()
Function that calls taskDISABLE_INTERRUPTS()
Definition Kernel.hpp:263
void suspendAll()
Function that calls vTaskSuspendAll()
Definition Kernel.hpp:353
void enterCritical()
Function that calls taskENTER_CRITICAL()
Definition Kernel.hpp:179
TickType_t getTickCount()
Function that calls xTaskGetTickCount()
Definition Kernel.hpp:124
TickType_t getIdleRunTimeCounter()
Function that calls xTaskGetIdleRunTimeCounter()
Definition Kernel.hpp:109
void exitCritical()
Function that calls taskEXIT_CRITICAL()
Definition Kernel.hpp:225
UBaseType_t getNumberOfTasks()
Function that calls uxTaskGetNumberOfTasks()
Definition Kernel.hpp:84
void yield()
Function that calls taskYIELD()
Definition Kernel.hpp:159
uint32_t enterCriticalFromISR()
Function that calls taskENTER_CRITICAL_FROM_ISR()
Definition Kernel.hpp:205
SchedulerState getSchedulerState()
Function that calls xTaskGetSchedulerState()
Definition Kernel.hpp:67
void startScheduler()
Function that calls vTaskStartScheduler()
Definition Kernel.hpp:293
void enableInterrupts()
Function that calls taskENABLE_INTERRUPTS()
Definition Kernel.hpp:276
void exitCriticalFromISR(const uint32_t interruptStatus)
Function that calls taskEXIT_CRITICAL_FROM_ISR()
Definition Kernel.hpp:250
TickType_t getTickCountFromISR()
Function that calls xTaskGetTickCountFromISR()
Definition Kernel.hpp:143