2018-07-13 18:28:26 +02:00
|
|
|
#ifndef FRAMEWORK_OSAL_LINUX_PERIODICPOSIXTASK_H_
|
|
|
|
#define FRAMEWORK_OSAL_LINUX_PERIODICPOSIXTASK_H_
|
|
|
|
|
2022-05-14 09:40:31 +02:00
|
|
|
#include <set>
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "../../objectmanager/ObjectManagerIF.h"
|
|
|
|
#include "../../tasks/ExecutableObjectIF.h"
|
|
|
|
#include "../../tasks/PeriodicTaskIF.h"
|
|
|
|
#include "PosixThread.h"
|
2020-06-06 15:47:33 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
class PeriodicPosixTask : public PosixThread, public PeriodicTaskIF {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a generic periodic task.
|
|
|
|
* @param name_
|
|
|
|
* Name, maximum allowed size of linux is 16 chars, everything else will
|
|
|
|
* be truncated.
|
|
|
|
* @param priority_
|
|
|
|
* Real-time priority, ranges from 1 to 99 for Linux.
|
|
|
|
* See: https://man7.org/linux/man-pages/man7/sched.7.html
|
|
|
|
* @param stackSize_
|
|
|
|
* @param period_
|
|
|
|
* @param deadlineMissedFunc_
|
|
|
|
*/
|
|
|
|
PeriodicPosixTask(const char* name_, int priority_, size_t stackSize_, uint32_t period_,
|
|
|
|
void (*deadlineMissedFunc_)());
|
|
|
|
virtual ~PeriodicPosixTask();
|
2018-07-13 18:28:26 +02:00
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
ReturnValue_t startTask() override;
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @return RETURN_OK on success, RETURN_FAILED if the object could not be added.
|
|
|
|
*/
|
2022-05-14 09:40:31 +02:00
|
|
|
ReturnValue_t addComponent(object_id_t object, uint8_t opCode) override;
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-03-28 13:50:42 +02:00
|
|
|
/**
|
|
|
|
* Adds an object to the list of objects to be executed.
|
|
|
|
* The objects are executed in the order added.
|
|
|
|
* @param object pointer to the object to add.
|
|
|
|
* @return RETURN_OK on success, RETURN_FAILED if the object could not be added.
|
|
|
|
*/
|
2022-05-14 09:40:31 +02:00
|
|
|
ReturnValue_t addComponent(ExecutableObjectIF* object, uint8_t opCode) override;
|
2022-03-28 13:50:42 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
uint32_t getPeriodMs() const override;
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t sleepFor(uint32_t ms) override;
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-05-14 09:40:31 +02:00
|
|
|
ReturnValue_t initObjsAfterTaskCreation();
|
|
|
|
|
|
|
|
bool isEmpty() const override;
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
private:
|
2022-05-14 09:40:31 +02:00
|
|
|
//! Typedef for the List of objects. Will contain the objects to execute and their respective
|
|
|
|
//! op codes
|
|
|
|
using ObjectList = std::multiset<std::pair<ExecutableObjectIF*, uint8_t>>;
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* @brief This attribute holds a list of objects to be executed.
|
|
|
|
*/
|
|
|
|
ObjectList objectList;
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Flag to indicate that the task was started and is allowed to run
|
|
|
|
*/
|
|
|
|
bool started;
|
2018-07-13 18:28:26 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
/**
|
|
|
|
* @brief Period of the task in milliseconds
|
|
|
|
*/
|
|
|
|
uint32_t periodMs;
|
|
|
|
/**
|
|
|
|
* @brief The function containing the actual functionality of the task.
|
|
|
|
* @details The method sets and starts
|
2022-02-22 11:16:33 +01:00
|
|
|
* the task's period, then enters a loop that is repeated indefinitely. Within
|
|
|
|
* the loop, all performOperation methods of the added objects are called. Afterwards the task
|
|
|
|
* will be blocked until the next period. On missing the deadline, the deadlineMissedFunction is
|
|
|
|
* executed.
|
2022-02-02 10:29:30 +01:00
|
|
|
*/
|
|
|
|
virtual void taskFunctionality(void);
|
|
|
|
/**
|
|
|
|
* @brief This is the entry point in a new thread.
|
|
|
|
*
|
|
|
|
* @details This method, that is the entry point in the new thread and calls taskFunctionality
|
|
|
|
* of the child class. Needs a valid pointer to the derived class.
|
|
|
|
*/
|
|
|
|
static void* taskEntryPoint(void* arg);
|
|
|
|
/**
|
|
|
|
* @brief The pointer to the deadline-missed function.
|
|
|
|
* @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.
|
|
|
|
*/
|
|
|
|
void (*deadlineMissedFunc)();
|
2018-07-13 18:28:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FRAMEWORK_OSAL_LINUX_PERIODICPOSIXTASK_H_ */
|