2020-09-05 20:18:52 +02:00
|
|
|
#ifndef FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_
|
|
|
|
#define FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include <atomic>
|
|
|
|
#include <condition_variable>
|
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-05-18 18:15:31 +02:00
|
|
|
#include "fsfw/objectmanager/ObjectManagerIF.h"
|
|
|
|
#include "fsfw/tasks/FixedSlotSequence.h"
|
2022-05-19 00:44:34 +02:00
|
|
|
#include "fsfw/tasks/FixedTimeslotTaskBase.h"
|
2022-05-18 18:15:31 +02:00
|
|
|
#include "fsfw/tasks/definitions.h"
|
2020-09-05 20:18:52 +02:00
|
|
|
|
|
|
|
class ExecutableObjectIF;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This class represents a task for periodic activities with multiple
|
|
|
|
* steps and strict timeslot requirements for these steps.
|
|
|
|
* @details
|
|
|
|
* @ingroup task_handling
|
|
|
|
*/
|
2022-05-19 00:44:34 +02:00
|
|
|
class FixedTimeslotTask : public FixedTimeslotTaskBase {
|
2022-02-02 10:29:30 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Standard constructor of the class.
|
|
|
|
* @details
|
|
|
|
* The class is initialized without allocated objects. These need to be
|
|
|
|
* added with #addComponent.
|
|
|
|
* @param priority
|
|
|
|
* @param stack_size
|
|
|
|
* @param setPeriod
|
|
|
|
* @param setDeadlineMissedFunc
|
|
|
|
* The function pointer to the deadline missed function that shall be
|
|
|
|
* assigned.
|
|
|
|
*/
|
|
|
|
FixedTimeslotTask(const char* name, TaskPriority setPriority, TaskStackSize setStack,
|
|
|
|
TaskPeriod setPeriod, void (*setDeadlineMissedFunc)());
|
|
|
|
/**
|
|
|
|
* @brief Currently, the executed object's lifetime is not coupled with
|
|
|
|
* the task object's lifetime, so the destructor is empty.
|
|
|
|
*/
|
2022-05-18 18:15:31 +02:00
|
|
|
~FixedTimeslotTask() override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
*/
|
2022-05-18 18:15:31 +02:00
|
|
|
ReturnValue_t startTask() override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add timeslot to the polling sequence table.
|
|
|
|
* @param componentId
|
|
|
|
* @param slotTimeMs
|
|
|
|
* @param executionStep
|
|
|
|
* @return
|
|
|
|
*/
|
2022-05-19 00:44:34 +02:00
|
|
|
ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
|
|
|
int8_t executionStep) override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-05-18 18:15:31 +02:00
|
|
|
ReturnValue_t sleepFor(uint32_t ms) override;
|
2022-02-02 10:29:30 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
using chron_ms = std::chrono::milliseconds;
|
|
|
|
|
|
|
|
bool started;
|
2022-05-18 18:15:31 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
std::thread mainThread;
|
|
|
|
std::atomic<bool> terminateThread{false};
|
|
|
|
|
|
|
|
std::condition_variable initCondition;
|
|
|
|
std::mutex initMutex;
|
|
|
|
std::string taskName;
|
2022-05-19 00:44:34 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* @brief This is the function executed in the new task's context.
|
|
|
|
* @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.
|
|
|
|
* @param A pointer to the task object itself is passed as argument.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void taskEntryPoint(void* argument);
|
|
|
|
/**
|
|
|
|
* @brief The function containing the actual functionality of the task.
|
|
|
|
* @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.
|
|
|
|
*/
|
2022-05-19 00:44:34 +02:00
|
|
|
[[noreturn]] void taskFunctionality();
|
2022-02-02 10:29:30 +01:00
|
|
|
|
2022-05-18 23:45:38 +02:00
|
|
|
static bool delayForInterval(chron_ms* previousWakeTimeMs, chron_ms interval);
|
2020-09-05 20:18:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_ */
|