fsfw/osal/FreeRTOS/PeriodicTask.h

126 lines
4.2 KiB
C
Raw Normal View History

2020-06-19 14:45:29 +02:00
#ifndef FRAMEWORK_OSAL_FREERTOS_PERIODICTASK_H_
#define FRAMEWORK_OSAL_FREERTOS_PERIODICTASK_H_
2018-07-13 15:56:37 +02:00
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/tasks/PeriodicTaskIF.h>
#include <framework/tasks/Typedef.h>
2020-06-19 14:45:29 +02:00
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
2018-07-13 15:56:37 +02:00
#include <vector>
class ExecutableObjectIF;
/**
2020-06-19 14:45:29 +02:00
* @brief This class represents a specialized task for
* periodic activities of multiple objects.
2018-07-13 15:56:37 +02:00
* @ingroup task_handling
*/
class PeriodicTask: public PeriodicTaskIF {
public:
/**
2020-06-19 14:45:29 +02:00
* Keep in Mind that you need to call before this vTaskStartScheduler()!
* A lot of task parameters are set in "FreeRTOSConfig.h".
* TODO: why does this need to be called before vTaskStartScheduler?
* @details
* The class is initialized without allocated objects.
* These need to be added with #addComponent.
* @param priority
* Sets the priority of a task. Values depend on freeRTOS configuration,
* high number means high priority.
* @param stack_size
* The stack size reserved by the operating system for the task.
* @param setPeriod
* The length of the period with which the task's
* functionality will be executed. It is expressed in clock ticks.
* @param setDeadlineMissedFunc
* The function pointer to the deadline missed function that shall
* be assigned.
2018-07-13 15:56:37 +02:00
*/
2020-06-19 14:45:29 +02:00
PeriodicTask(const char *name, TaskPriority setPriority,
TaskStackSize setStack, TaskPeriod setPeriod,
void (*setDeadlineMissedFunc)());
2018-07-13 15:56:37 +02:00
/**
2020-06-19 14:45:29 +02:00
* @brief Currently, the executed object's lifetime is not coupled with
* the task object's lifetime, so the destructor is empty.
2018-07-13 15:56:37 +02:00
*/
virtual ~PeriodicTask(void);
/**
* @brief The method to start the task.
* @details The method starts the task with the respective system call.
* Entry point is the taskEntryPoint method described below.
* The address of the task object is passed as an argument
* to the system call.
*/
2020-06-23 01:14:28 +02:00
ReturnValue_t startTask() override;
2018-07-13 15:56:37 +02:00
/**
* Adds an object to the list of objects to be executed.
* The objects are executed in the order added.
* @param object Id of the object to add.
2020-06-19 14:45:29 +02:00
* @return
* -@c RETURN_OK on success
* -@c RETURN_FAILED if the object could not be added.
2018-07-13 15:56:37 +02:00
*/
2020-06-23 01:14:28 +02:00
ReturnValue_t addComponent(object_id_t object,
bool setTaskIF = true) override;
2018-07-13 15:56:37 +02:00
2020-06-23 01:14:28 +02:00
uint32_t getPeriodMs() const override;
2018-07-13 15:56:37 +02:00
2020-06-23 01:14:28 +02:00
ReturnValue_t sleepFor(uint32_t ms) override;
2018-07-13 15:56:37 +02:00
protected:
bool started;
TaskHandle_t handle;
2020-06-19 14:45:29 +02:00
//! Typedef for the List of objects.
typedef std::vector<ExecutableObjectIF*> ObjectList;
2018-07-13 15:56:37 +02:00
/**
* @brief This attribute holds a list of objects to be executed.
*/
ObjectList objectList;
/**
* @brief The period of the task.
2020-06-19 14:45:29 +02:00
* @details
* The period determines the frequency of the task's execution.
* It is expressed in clock ticks.
2018-07-13 15:56:37 +02:00
*/
TaskPeriod period;
/**
* @brief The pointer to the deadline-missed function.
2020-06-19 14:45:29 +02:00
* @details
* This pointer stores the function that is executed if the task's deadline
* is missed so each may react individually on a timing failure.
* The pointer may be NULL, then nothing happens on missing the deadline.
* The deadline is equal to the next execution of the periodic task.
2018-07-13 15:56:37 +02:00
*/
void (*deadlineMissedFunc)(void);
/**
* @brief This is the function executed in the new task's context.
2020-06-19 14:45:29 +02:00
* @details
* It converts the argument back to the thread object type and copies the
* class instance to the task context. The taskFunctionality method is
* called afterwards.
2018-07-13 15:56:37 +02:00
* @param A pointer to the task object itself is passed as argument.
*/
static void taskEntryPoint(void* argument);
/**
* @brief The function containing the actual functionality of the task.
2020-06-19 14:45:29 +02:00
* @details
* The method sets and starts the task's period, then enters a loop that is
* repeated as long as the isRunning attribute is true. Within the loop,
* all performOperation methods of the added objects are called.
* Afterwards the checkAndRestartPeriod system call blocks the task until
* the next period.
* On missing the deadline, the deadlineMissedFunction is executed.
2018-07-13 15:56:37 +02:00
*/
void taskFunctionality(void);
2020-06-23 01:14:28 +02:00
void checkMissedDeadline(const TickType_t xLastWakeTime,
const TickType_t interval);
void handleMissedDeadline();
2018-07-13 15:56:37 +02:00
};
2020-06-19 14:45:29 +02:00
#endif /* PERIODICTASK_H_ */