EIVE upstream #29
@ -22,12 +22,12 @@
|
|||||||
|
|
||||||
FixedTimeslotTask::FixedTimeslotTask(const char* name, TaskPriority setPriority,
|
FixedTimeslotTask::FixedTimeslotTask(const char* name, TaskPriority setPriority,
|
||||||
TaskStackSize setStack, TaskPeriod setPeriod,
|
TaskStackSize setStack, TaskPeriod setPeriod,
|
||||||
void (*setDeadlineMissedFunc)())
|
TaskDeadlineMissedFunction dlmFunc_)
|
||||||
: started(false),
|
: started(false),
|
||||||
pollingSeqTable(setPeriod * 1000),
|
pollingSeqTable(static_cast<uint32_t>(setPeriod * 1000)),
|
||||||
taskName(name),
|
taskName(name),
|
||||||
period(setPeriod),
|
period(setPeriod),
|
||||||
deadlineMissedFunc(setDeadlineMissedFunc) {
|
dlmFunc(dlmFunc_) {
|
||||||
// It is propably possible to set task priorities by using the native
|
// It is propably possible to set task priorities by using the native
|
||||||
// task handles for Windows / Linux
|
// task handles for Windows / Linux
|
||||||
mainThread = std::thread(&FixedTimeslotTask::taskEntryPoint, this, this);
|
mainThread = std::thread(&FixedTimeslotTask::taskEntryPoint, this, this);
|
||||||
@ -39,7 +39,7 @@ FixedTimeslotTask::FixedTimeslotTask(const char* name, TaskPriority setPriority,
|
|||||||
tasks::insertTaskName(mainThread.get_id(), taskName);
|
tasks::insertTaskName(mainThread.get_id(), taskName);
|
||||||
}
|
}
|
||||||
|
|
||||||
FixedTimeslotTask::~FixedTimeslotTask(void) {
|
FixedTimeslotTask::~FixedTimeslotTask() {
|
||||||
// Do not delete objects, we were responsible for ptrs only.
|
// Do not delete objects, we were responsible for ptrs only.
|
||||||
terminateThread = true;
|
terminateThread = true;
|
||||||
if (mainThread.joinable()) {
|
if (mainThread.joinable()) {
|
||||||
@ -48,7 +48,7 @@ FixedTimeslotTask::~FixedTimeslotTask(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FixedTimeslotTask::taskEntryPoint(void* argument) {
|
void FixedTimeslotTask::taskEntryPoint(void* argument) {
|
||||||
FixedTimeslotTask* originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
|
auto* originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
|
||||||
|
|
||||||
if (not originalTask->started) {
|
if (not originalTask->started) {
|
||||||
// we have to suspend/block here until the task is started.
|
// we have to suspend/block here until the task is started.
|
||||||
@ -114,8 +114,7 @@ void FixedTimeslotTask::taskFunctionality() {
|
|||||||
|
|
||||||
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
||||||
int8_t executionStep) {
|
int8_t executionStep) {
|
||||||
ExecutableObjectIF* executableObject =
|
auto* executableObject = ObjectManager::instance()->get<ExecutableObjectIF>(componentId);
|
||||||
ObjectManager::instance()->get<ExecutableObjectIF>(componentId);
|
|
||||||
if (executableObject != nullptr) {
|
if (executableObject != nullptr) {
|
||||||
pollingSeqTable.addSlot(componentId, slotTimeMs, executionStep, executableObject, this);
|
pollingSeqTable.addSlot(componentId, slotTimeMs, executionStep, executableObject, this);
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
@ -133,9 +132,9 @@ ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotT
|
|||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t FixedTimeslotTask::checkSequence() const { return pollingSeqTable.checkSequence(); }
|
ReturnValue_t FixedTimeslotTask::checkSequence() { return pollingSeqTable.checkSequence(); }
|
||||||
|
|
||||||
uint32_t FixedTimeslotTask::getPeriodMs() const { return period * 1000; }
|
uint32_t FixedTimeslotTask::getPeriodMs() const { return static_cast<uint32_t>(period * 1000); }
|
||||||
|
|
||||||
bool FixedTimeslotTask::delayForInterval(chron_ms* previousWakeTimeMs, const chron_ms interval) {
|
bool FixedTimeslotTask::delayForInterval(chron_ms* previousWakeTimeMs, const chron_ms interval) {
|
||||||
bool shouldDelay = false;
|
bool shouldDelay = false;
|
||||||
@ -176,3 +175,5 @@ bool FixedTimeslotTask::delayForInterval(chron_ms* previousWakeTimeMs, const chr
|
|||||||
(*previousWakeTimeMs) = currentStartTime;
|
(*previousWakeTimeMs) = currentStartTime;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FixedTimeslotTask::isEmpty() const { return pollingSeqTable.isEmpty() };
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../../objectmanager/ObjectManagerIF.h"
|
#include "fsfw/objectmanager/ObjectManagerIF.h"
|
||||||
#include "../../tasks/FixedSlotSequence.h"
|
#include "fsfw/tasks/FixedSlotSequence.h"
|
||||||
#include "../../tasks/FixedTimeslotTaskIF.h"
|
#include "fsfw/tasks/FixedTimeslotTaskIF.h"
|
||||||
#include "../../tasks/Typedef.h"
|
#include "fsfw/tasks/definitions.h"
|
||||||
|
|
||||||
class ExecutableObjectIF;
|
class ExecutableObjectIF;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class FixedTimeslotTask : public FixedTimeslotTaskIF {
|
|||||||
* @brief Currently, the executed object's lifetime is not coupled with
|
* @brief Currently, the executed object's lifetime is not coupled with
|
||||||
* the task object's lifetime, so the destructor is empty.
|
* the task object's lifetime, so the destructor is empty.
|
||||||
*/
|
*/
|
||||||
virtual ~FixedTimeslotTask(void);
|
~FixedTimeslotTask() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The method to start the task.
|
* @brief The method to start the task.
|
||||||
@ -48,7 +48,7 @@ class FixedTimeslotTask : public FixedTimeslotTaskIF {
|
|||||||
* The address of the task object is passed as an argument
|
* The address of the task object is passed as an argument
|
||||||
* to the system call.
|
* to the system call.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t startTask(void);
|
ReturnValue_t startTask() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add timeslot to the polling sequence table.
|
* Add timeslot to the polling sequence table.
|
||||||
@ -57,22 +57,23 @@ class FixedTimeslotTask : public FixedTimeslotTaskIF {
|
|||||||
* @param executionStep
|
* @param executionStep
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep);
|
ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) override;
|
||||||
|
|
||||||
ReturnValue_t checkSequence() const override;
|
ReturnValue_t checkSequence() override;
|
||||||
|
|
||||||
uint32_t getPeriodMs() const;
|
ReturnValue_t sleepFor(uint32_t ms) override;
|
||||||
|
uint32_t getPeriodMs() const override;
|
||||||
|
|
||||||
ReturnValue_t sleepFor(uint32_t ms);
|
bool isEmpty() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
using chron_ms = std::chrono::milliseconds;
|
using chron_ms = std::chrono::milliseconds;
|
||||||
|
|
||||||
bool started;
|
bool started;
|
||||||
//!< Typedef for the List of objects.
|
|
||||||
typedef std::vector<ExecutableObjectIF*> ObjectList;
|
|
||||||
std::thread mainThread;
|
std::thread mainThread;
|
||||||
std::atomic<bool> terminateThread{false};
|
std::atomic<bool> terminateThread{false};
|
||||||
|
TaskDeadlineMissedFunction dlmFunc = nullptr;
|
||||||
|
|
||||||
//! Polling sequence table which contains the object to execute
|
//! Polling sequence table which contains the object to execute
|
||||||
//! and information like the timeslots and the passed execution step.
|
//! and information like the timeslots and the passed execution step.
|
||||||
@ -89,15 +90,6 @@ class FixedTimeslotTask : public FixedTimeslotTaskIF {
|
|||||||
*/
|
*/
|
||||||
TaskPeriod period;
|
TaskPeriod period;
|
||||||
|
|
||||||
/**
|
|
||||||
* @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)(void);
|
|
||||||
/**
|
/**
|
||||||
* @brief This is the function executed in the new task's context.
|
* @brief This is the function executed in the new task's context.
|
||||||
* @details
|
* @details
|
||||||
@ -117,9 +109,9 @@ class FixedTimeslotTask : public FixedTimeslotTaskIF {
|
|||||||
* the checkAndRestartPeriod system call blocks the task until the next
|
* the checkAndRestartPeriod system call blocks the task until the next
|
||||||
* period. On missing the deadline, the deadlineMissedFunction is executed.
|
* period. On missing the deadline, the deadlineMissedFunction is executed.
|
||||||
*/
|
*/
|
||||||
void taskFunctionality(void);
|
void taskFunctionality();
|
||||||
|
|
||||||
bool delayForInterval(chron_ms* previousWakeTimeMs, const chron_ms interval);
|
bool delayForInterval(chron_ms* previousWakeTimeMs, chron_ms interval);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_ */
|
#endif /* FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user