2020-02-26 16:55:35 +01:00
|
|
|
#ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
|
|
|
|
#define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
|
|
|
|
|
2020-05-01 16:47:53 +02:00
|
|
|
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
|
|
|
|
|
|
|
extern "C" {
|
2020-05-14 21:26:04 +02:00
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
#include <freertos/task.h>
|
2020-05-01 16:47:53 +02:00
|
|
|
}
|
|
|
|
#include <cstdint>
|
2020-05-18 17:46:04 +02:00
|
|
|
|
2020-04-23 17:54:41 +02:00
|
|
|
/**
|
|
|
|
* Architecture dependant portmacro.h function call.
|
|
|
|
* Should be implemented in bsp.
|
|
|
|
*/
|
|
|
|
extern "C" void requestContextSwitchFromISR();
|
|
|
|
|
2020-02-26 16:55:35 +01:00
|
|
|
/*!
|
|
|
|
* Used by functions to tell if they are being called from
|
2020-05-18 20:46:50 +02:00
|
|
|
* within an ISR or from a regular task. This is required because FreeRTOS
|
2020-05-18 17:46:04 +02:00
|
|
|
* has different functions for handling semaphores and messages from within
|
2020-05-18 20:46:50 +02:00
|
|
|
* an ISR and task.
|
2020-02-26 16:55:35 +01:00
|
|
|
*/
|
2020-05-29 13:02:13 +02:00
|
|
|
enum class CallContext {
|
|
|
|
TASK = 0x00,//!< task_context
|
|
|
|
ISR = 0xFF //!< isr_context
|
2020-02-28 22:55:25 +01:00
|
|
|
};
|
2020-02-26 16:55:35 +01:00
|
|
|
|
2020-04-23 17:54:41 +02:00
|
|
|
|
2020-02-28 22:55:25 +01:00
|
|
|
class TaskManagement {
|
|
|
|
public:
|
2020-05-18 20:46:50 +02:00
|
|
|
/**
|
2020-05-18 17:46:04 +02:00
|
|
|
* @brief In this function, a function dependant on the portmacro.h header
|
|
|
|
* function calls to request a context switch can be specified.
|
|
|
|
* This can be used if sending to the queue from an ISR caused a task
|
2020-05-18 20:46:50 +02:00
|
|
|
* to unblock and a context switch is required.
|
2020-02-28 22:55:25 +01:00
|
|
|
*/
|
2020-03-02 01:00:17 +01:00
|
|
|
static void requestContextSwitch(CallContext callContext);
|
2020-02-26 16:55:35 +01:00
|
|
|
|
2020-02-28 22:55:25 +01:00
|
|
|
/**
|
|
|
|
* If task preemption in FreeRTOS is disabled, a context switch
|
|
|
|
* can be requested manually by calling this function.
|
2020-05-18 20:46:50 +02:00
|
|
|
*/
|
2020-05-18 17:46:04 +02:00
|
|
|
static void requestContextSwitchFromTask(void);
|
2020-05-01 16:47:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The current task handle
|
|
|
|
*/
|
|
|
|
static TaskHandle_t getCurrentTaskHandle();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get returns the minimum amount of remaining stack space in words
|
|
|
|
* that was a available to the task since the task started executing.
|
|
|
|
* Please note that the actual value in bytes depends
|
|
|
|
* on the stack depth type.
|
|
|
|
* E.g. on a 32 bit machine, a value of 200 means 800 bytes.
|
|
|
|
* @return Smallest value of stack remaining since the task was started in
|
|
|
|
* words.
|
2020-05-18 20:46:50 +02:00
|
|
|
*/
|
2020-07-10 19:34:18 +02:00
|
|
|
static configSTACK_DEPTH_TYPE getTaskStackHighWatermark(
|
|
|
|
TaskHandle_t task = nullptr);
|
2020-02-28 22:55:25 +01:00
|
|
|
};
|
2020-02-26 16:55:35 +01:00
|
|
|
|
|
|
|
#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */
|