2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/tasks/TaskFactory.h"
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
2021-07-14 10:50:44 +02:00
|
|
|
#include "fsfw/osal/host/FixedTimeslotTask.h"
|
|
|
|
#include "fsfw/osal/host/PeriodicTask.h"
|
|
|
|
#include "fsfw/osal/host/taskHelpers.h"
|
2022-08-16 12:48:22 +02:00
|
|
|
#include "fsfw/returnvalues/returnvalue.h"
|
2021-07-14 10:50:44 +02:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
2022-02-02 10:29:30 +01:00
|
|
|
#include "fsfw/tasks/PeriodicTaskIF.h"
|
2020-09-05 20:18:52 +02:00
|
|
|
|
|
|
|
TaskFactory* TaskFactory::factoryInstance = new TaskFactory();
|
|
|
|
|
2021-03-21 16:20:13 +01:00
|
|
|
// Not used for the host implementation for now because C++ thread abstraction is used
|
2020-09-05 20:18:52 +02:00
|
|
|
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = 0;
|
|
|
|
|
2022-05-19 00:44:34 +02:00
|
|
|
TaskFactory::TaskFactory() = default;
|
2020-09-05 20:18:52 +02:00
|
|
|
|
2022-05-19 00:44:34 +02:00
|
|
|
TaskFactory::~TaskFactory() = default;
|
2020-09-05 20:18:52 +02:00
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
TaskFactory* TaskFactory::instance() { return TaskFactory::factoryInstance; }
|
2020-09-05 20:18:52 +02:00
|
|
|
|
2023-03-24 13:25:34 +01:00
|
|
|
PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_, TaskPriority taskPriority_,
|
|
|
|
TaskStackSize stackSize_,
|
|
|
|
TaskPeriod periodInSeconds_,
|
|
|
|
TaskDeadlineMissedFunction deadLineMissedFunction_,
|
|
|
|
void* args) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return new PeriodicTask(name_, taskPriority_, stackSize_, periodInSeconds_,
|
|
|
|
deadLineMissedFunction_);
|
2020-09-05 20:18:52 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(
|
|
|
|
TaskName name_, TaskPriority taskPriority_, TaskStackSize stackSize_,
|
2023-03-24 13:25:34 +01:00
|
|
|
TaskPeriod periodInSeconds_, TaskDeadlineMissedFunction deadLineMissedFunction_, void* args) {
|
2022-02-02 10:29:30 +01:00
|
|
|
return new FixedTimeslotTask(name_, taskPriority_, stackSize_, periodInSeconds_,
|
|
|
|
deadLineMissedFunction_);
|
2020-09-05 20:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {
|
2022-02-02 10:29:30 +01:00
|
|
|
// This might block for some time!
|
|
|
|
delete task;
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::FAILED;
|
2020-09-05 20:18:52 +02:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
ReturnValue_t TaskFactory::delayTask(uint32_t delayMs) {
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(delayMs));
|
2022-08-15 20:28:16 +02:00
|
|
|
return returnvalue::OK;
|
2020-09-05 20:18:52 +02:00
|
|
|
}
|
|
|
|
|
2021-02-22 18:43:09 +01:00
|
|
|
void TaskFactory::printMissedDeadline() {
|
2022-02-02 10:29:30 +01:00
|
|
|
std::string name = tasks::getTaskName(std::this_thread::get_id());
|
2021-03-21 16:20:13 +01:00
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::warning << "TaskFactory::printMissedDeadline: " << name << std::endl;
|
2021-03-21 16:20:13 +01:00
|
|
|
#else
|
2022-02-02 10:29:30 +01:00
|
|
|
sif::printWarning("TaskFactory::printMissedDeadline: %s\n", name);
|
2021-03-21 16:20:13 +01:00
|
|
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
2021-02-22 18:43:09 +01:00
|
|
|
}
|