fsfw/osal/FreeRTOS/FixedTimeslotTask.h

99 lines
3.1 KiB
C
Raw Normal View History

2020-06-19 14:47:01 +02:00
#ifndef FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
#define FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
2018-07-13 15:56:37 +02:00
#include <framework/devicehandlers/FixedSlotSequence.h>
#include <framework/tasks/FixedTimeslotTaskIF.h>
#include <framework/tasks/Typedef.h>
2020-06-19 14:47:01 +02:00
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
2018-07-13 15:56:37 +02:00
class FixedTimeslotTask: public FixedTimeslotTaskIF {
public:
2020-06-19 14:47:01 +02:00
2018-07-13 15:56:37 +02:00
/**
2020-06-22 23:49:31 +02:00
* Keep in mind that you need to call before vTaskStartScheduler()!
2020-06-19 14:47:01 +02:00
* A lot of task parameters are set in "FreeRTOSConfig.h".
* @param name Name of the task, lenght limited by configMAX_TASK_NAME_LEN
* @param setPriority Number of priorities specified by
* configMAX_PRIORITIES. High taskPriority_ number means high priority.
* @param setStack Stack size in words (not bytes!).
* Lower limit specified by configMINIMAL_STACK_SIZE
* @param overallPeriod Period in seconds.
* @param setDeadlineMissedFunc Callback if a deadline was missed.
* @return Pointer to the newly created task.
2018-07-13 15:56:37 +02:00
*/
FixedTimeslotTask(const char *name, TaskPriority setPriority,
TaskStackSize setStack, TaskPeriod overallPeriod,
void (*setDeadlineMissedFunc)());
/**
* @brief The destructor of the class.
2020-06-19 14:47:01 +02:00
* @details
* The destructor frees all heap memory that was allocated on thread
* initialization for the PST and the device handlers. This is done by
* calling the PST's destructor.
2018-07-13 15:56:37 +02:00
*/
virtual ~FixedTimeslotTask(void);
ReturnValue_t startTask(void);
/**
* This static function can be used as #deadlineMissedFunc.
2020-06-19 14:47:01 +02:00
* It counts missedDeadlines and prints the number of missed deadlines
* every 10th time.
2018-07-13 15:56:37 +02:00
*/
static void missedDeadlineCounter();
/**
* A helper variable to count missed deadlines.
*/
static uint32_t deadlineMissedCount;
ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs,
2020-06-22 23:49:31 +02:00
int8_t executionStep) override;
2018-07-13 15:56:37 +02:00
2020-06-22 23:49:31 +02:00
uint32_t getPeriodMs() const override;
2018-07-13 15:56:37 +02:00
2020-06-22 23:49:31 +02:00
ReturnValue_t checkSequence() const override;
2018-07-13 15:56:37 +02:00
2020-06-22 23:49:31 +02:00
ReturnValue_t sleepFor(uint32_t ms) override;
2020-06-19 14:47:01 +02:00
2018-07-13 15:56:37 +02:00
protected:
bool started;
TaskHandle_t handle;
FixedSlotSequence pst;
/**
2020-06-19 14:47:01 +02:00
* @brief This attribute holds a function pointer that is executed when
* a deadline was missed.
* @details
* Another function may be announced to determine the actions to perform
* when a deadline was missed. Currently, only one function for missing
* any deadline is allowed. If not used, it shall be declared NULL.
2018-07-13 15:56:37 +02:00
*/
void (*deadlineMissedFunc)(void);
/**
2020-06-19 14:47:01 +02:00
* @brief This is the entry point for a new task.
* @details
* This method starts the task by calling taskFunctionality(), as soon as
* all requirements (task scheduler has started and startTask()
* has been called) are met.
2018-07-13 15:56:37 +02:00
*/
static void taskEntryPoint(void* argument);
/**
* @brief This function holds the main functionality of the thread.
2020-06-19 14:47:01 +02:00
* @details
* Core function holding the main functionality of the task
* It links the functionalities provided by FixedSlotSequence with the
* OS's System Calls to keep the timing of the periods.
2018-07-13 15:56:37 +02:00
*/
void taskFunctionality(void);
2020-06-22 23:30:17 +02:00
void checkMissedDeadline(const TickType_t xLastWakeTime,
const TickType_t interval);
void handleMissedDeadline();
2018-07-13 15:56:37 +02:00
};
#endif /* POLLINGTASK_H_ */