diff --git a/osal/rtems/PollingTask.cpp b/osal/rtems/FixedTimeslotTask.cpp similarity index 73% rename from osal/rtems/PollingTask.cpp rename to osal/rtems/FixedTimeslotTask.cpp index 8cfec942..d3101162 100644 --- a/osal/rtems/PollingTask.cpp +++ b/osal/rtems/FixedTimeslotTask.cpp @@ -1,4 +1,4 @@ -#include "PollingTask.h" +#include #include "RtemsBasic.h" #include "../../tasks/FixedSequenceSlot.h" @@ -21,9 +21,9 @@ #include #include -uint32_t PollingTask::deadlineMissedCount = 0; +uint32_t FixedTimeslotTask::deadlineMissedCount = 0; -PollingTask::PollingTask(const char *name, rtems_task_priority setPriority, +FixedTimeslotTask::FixedTimeslotTask(const char *name, rtems_task_priority setPriority, size_t setStack, uint32_t setOverallPeriod, void (*setDeadlineMissedFunc)()) : RTEMSTaskBase(setPriority, setStack, name), periodId(0), pst( @@ -32,33 +32,34 @@ PollingTask::PollingTask(const char *name, rtems_task_priority setPriority, this->deadlineMissedFunc = setDeadlineMissedFunc; } -PollingTask::~PollingTask() { +FixedTimeslotTask::~FixedTimeslotTask() { } -rtems_task PollingTask::taskEntryPoint(rtems_task_argument argument) { +rtems_task FixedTimeslotTask::taskEntryPoint(rtems_task_argument argument) { //The argument is re-interpreted as PollingTask. - PollingTask *originalTask(reinterpret_cast(argument)); + FixedTimeslotTask *originalTask(reinterpret_cast(argument)); //The task's functionality is called. - originalTask->taskFunctionality(); + return originalTask->taskFunctionality(); + /* Should never be reached */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "Polling task " << originalTask->getId() - << " returned from taskFunctionality." << std::endl; + sif::error << "Polling task " << originalTask->getId() << " returned from taskFunctionality." << + std::endl; #endif } -void PollingTask::missedDeadlineCounter() { - PollingTask::deadlineMissedCount++; - if (PollingTask::deadlineMissedCount % 10 == 0) { +void FixedTimeslotTask::missedDeadlineCounter() { + FixedTimeslotTask::deadlineMissedCount++; + if (FixedTimeslotTask::deadlineMissedCount % 10 == 0) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "PST missed " << PollingTask::deadlineMissedCount + sif::error << "PST missed " << FixedTimeslotTask::deadlineMissedCount << " deadlines." << std::endl; #endif } } -ReturnValue_t PollingTask::startTask() { - rtems_status_code status = rtems_task_start(id, PollingTask::taskEntryPoint, +ReturnValue_t FixedTimeslotTask::startTask() { + rtems_status_code status = rtems_task_start(id, FixedTimeslotTask::taskEntryPoint, rtems_task_argument((void *) this)); if (status != RTEMS_SUCCESSFUL) { #if FSFW_CPP_OSTREAM_ENABLED == 1 @@ -79,7 +80,7 @@ ReturnValue_t PollingTask::startTask() { } } -ReturnValue_t PollingTask::addSlot(object_id_t componentId, +ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { ExecutableObjectIF* object = objectManager->get(componentId); if (object != nullptr) { @@ -94,17 +95,17 @@ ReturnValue_t PollingTask::addSlot(object_id_t componentId, return HasReturnvaluesIF::RETURN_FAILED; } -uint32_t PollingTask::getPeriodMs() const { +uint32_t FixedTimeslotTask::getPeriodMs() const { return pst.getLengthMs(); } -ReturnValue_t PollingTask::checkSequence() const { +ReturnValue_t FixedTimeslotTask::checkSequence() const { return pst.checkSequence(); } #include -void PollingTask::taskFunctionality() { +void FixedTimeslotTask::taskFunctionality() { // A local iterator for the Polling Sequence Table is created to find the start time for the first entry. FixedSlotSequence::SlotListIter it = pst.current; @@ -132,6 +133,6 @@ void PollingTask::taskFunctionality() { } } -ReturnValue_t PollingTask::sleepFor(uint32_t ms){ +ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms){ return RTEMSTaskBase::sleepFor(ms); }; diff --git a/osal/rtems/FixedTimeslotTask.h b/osal/rtems/FixedTimeslotTask.h new file mode 100644 index 00000000..55f78088 --- /dev/null +++ b/osal/rtems/FixedTimeslotTask.h @@ -0,0 +1,81 @@ +#ifndef FSFW_OSAL_RTEMS_FIXEDTIMESLOTTASK_H_ +#define FSFW_OSAL_RTEMS_FIXEDTIMESLOTTASK_H_ + +#include "RTEMSTaskBase.h" +#include "../../tasks/FixedSlotSequence.h" +#include "../../tasks/FixedTimeslotTaskIF.h" + +class FixedTimeslotTask: public RTEMSTaskBase, public FixedTimeslotTaskIF { +public: + /** + * @brief The standard constructor of the class. + * @details + * This is the general constructor of the class. In addition to the TaskBase parameters, + * the following variables are passed: + * @param setDeadlineMissedFunc The function pointer to the deadline missed function + * that shall be assigned. + * @param getPst The object id of the completely initialized polling sequence. + */ + FixedTimeslotTask( const char *name, rtems_task_priority setPriority, size_t setStackSize, + uint32_t overallPeriod, void (*setDeadlineMissedFunc)()); + + /** + * @brief The destructor of the class. + * @details + * The destructor frees all heap memory that was allocated on thread initialization + * for the PST andthe device handlers. This is done by calling the PST's destructor. + */ + virtual ~FixedTimeslotTask( void ); + + ReturnValue_t startTask( void ); + /** + * This static function can be used as #deadlineMissedFunc. + * It counts missedDeadlines and prints the number of missed deadlines every 10th time. + */ + static void missedDeadlineCounter(); + /** + * A helper variable to count missed deadlines. + */ + static uint32_t deadlineMissedCount; + + ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep); + + uint32_t getPeriodMs() const; + + ReturnValue_t checkSequence() const; + + ReturnValue_t sleepFor(uint32_t ms); +protected: + /** + * @brief id of the associated OS period + */ + rtems_id periodId; + + FixedSlotSequence pst; + + /** + * @brief This attribute holds a function pointer that is executed when a deadline was missed. + * + * @details + * Another function may be announced to determine the actions to perform when a deadline + * was missed. Currently, only one function for missing any deadline is allowed. + * If not used, it shall be declared NULL. + */ + void ( *deadlineMissedFunc )( void ) = nullptr; + /** + * @brief This is the entry point in a new polling thread. + * @details This method is the entry point in the new thread + */ + static rtems_task taskEntryPoint( rtems_task_argument argument ); + + /** + * @brief This function holds the main functionality of the thread. + * @details + * Holding the main functionality of the task, this method is most important. + * It links the functionalities provided by FixedSlotSequence with the OS's system calls to + * keep the timing of the periods. + */ + void taskFunctionality( void ); +}; + +#endif /* FSFW_OSAL_RTEMS_FIXEDTIMESLOTTASK_H_ */ diff --git a/osal/rtems/MutexFactory.cpp b/osal/rtems/MutexFactory.cpp index 24af5fa9..adc599e9 100644 --- a/osal/rtems/MutexFactory.cpp +++ b/osal/rtems/MutexFactory.cpp @@ -1,6 +1,7 @@ -#include "../../ipc/MutexFactory.h" #include "Mutex.h" -#include "RtemsBasic.h" + +#include "../../ipc/MutexFactory.h" + MutexFactory* MutexFactory::factoryInstance = new MutexFactory(); diff --git a/osal/rtems/PollingTask.h b/osal/rtems/PollingTask.h deleted file mode 100644 index 8646220d..00000000 --- a/osal/rtems/PollingTask.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef FSFW_OSAL_RTEMS_POLLINGTASK_H_ -#define FSFW_OSAL_RTEMS_POLLINGTASK_H_ - -#include -#include "../../tasks/FixedSlotSequence.h" -#include "../../tasks/FixedTimeslotTaskIF.h" - -class PollingTask: public RTEMSTaskBase, public FixedTimeslotTaskIF { - public: - /** - * @brief The standard constructor of the class. - * - * @details This is the general constructor of the class. In addition to the TaskBase parameters, - * the following variables are passed: - * - * @param (*setDeadlineMissedFunc)() The function pointer to the deadline missed function that shall be assigned. - * - * @param getPst The object id of the completely initialized polling sequence. - */ - PollingTask( const char *name, rtems_task_priority setPriority, size_t setStackSize, uint32_t overallPeriod, void (*setDeadlineMissedFunc)()); - - /** - * @brief The destructor of the class. - * - * @details The destructor frees all heap memory that was allocated on thread initialization for the PST and - * the device handlers. This is done by calling the PST's destructor. - */ - virtual ~PollingTask( void ); - - ReturnValue_t startTask( void ); - /** - * This static function can be used as #deadlineMissedFunc. - * It counts missedDeadlines and prints the number of missed deadlines every 10th time. - */ - static void missedDeadlineCounter(); - /** - * A helper variable to count missed deadlines. - */ - static uint32_t deadlineMissedCount; - - ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep); - - uint32_t getPeriodMs() const; - - ReturnValue_t checkSequence() const; - - ReturnValue_t sleepFor(uint32_t ms); -protected: - /** - * @brief id of the associated OS period - */ - rtems_id periodId; - - FixedSlotSequence pst; - - /** - * @brief This attribute holds a function pointer that is executed when a deadline was missed. - * - * @details Another function may be announced to determine the actions to perform when a deadline was missed. - * Currently, only one function for missing any deadline is allowed. - * If not used, it shall be declared NULL. - */ - void ( *deadlineMissedFunc )( void ); - /** - * @brief This is the entry point in a new polling thread. - * - * @details This method, that is the generalOSAL::checkAndRestartPeriod( this->periodId, interval ); entry point in the new thread, is here set to generate - * and link the Polling Sequence Table to the thread object and start taskFunctionality() - * on success. If operation of the task is ended for some reason, - * the destructor is called to free allocated memory. - */ - static rtems_task taskEntryPoint( rtems_task_argument argument ); - - /** - * @brief This function holds the main functionality of the thread. - * - * - * @details Holding the main functionality of the task, this method is most important. - * It links the functionalities provided by FixedSlotSequence with the OS's System Calls - * to keep the timing of the periods. - */ - void taskFunctionality( void ); -}; - -#endif /* FSFW_OSAL_RTEMS_POLLINGTASK_H_ */ diff --git a/osal/rtems/RTEMSTaskBase.cpp b/osal/rtems/RTEMSTaskBase.cpp index 25d6d498..d0cdc876 100644 --- a/osal/rtems/RTEMSTaskBase.cpp +++ b/osal/rtems/RTEMSTaskBase.cpp @@ -1,4 +1,4 @@ -#include +#include "RTEMSTaskBase.h" #include "../../serviceinterface/ServiceInterface.h" const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = RTEMS_MINIMUM_STACK_SIZE; diff --git a/osal/rtems/TaskFactory.cpp b/osal/rtems/TaskFactory.cpp index 702ef894..5dad69fe 100644 --- a/osal/rtems/TaskFactory.cpp +++ b/osal/rtems/TaskFactory.cpp @@ -1,8 +1,9 @@ -#include -#include "../../tasks/TaskFactory.h" -#include "PollingTask.h" +#include "FixedTimeslotTask.h" +#include "PeriodicTask.h" #include "InitTask.h" #include "RtemsBasic.h" + +#include "../../tasks/TaskFactory.h" #include "../../returnvalues/HasReturnvaluesIF.h" //TODO: Different variant than the lazy loading in QueueFactory. What's better and why? @@ -15,15 +16,21 @@ TaskFactory* TaskFactory::instance() { return TaskFactory::factoryInstance; } -PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_,TaskPriority taskPriority_,TaskStackSize stackSize_,TaskPeriod periodInSeconds_,TaskDeadlineMissedFunction deadLineMissedFunction_) { +PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_, TaskPriority taskPriority_, + TaskStackSize stackSize_,TaskPeriod periodInSeconds_, + TaskDeadlineMissedFunction deadLineMissedFunction_) { rtems_interval taskPeriod = periodInSeconds_ * Clock::getTicksPerSecond(); - return static_cast(new PeriodicTask(name_,taskPriority_,stackSize_,taskPeriod,deadLineMissedFunction_)); + return static_cast(new PeriodicTask(name_, taskPriority_, stackSize_, + taskPeriod,deadLineMissedFunction_)); } -FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(TaskName name_,TaskPriority taskPriority_,TaskStackSize stackSize_,TaskPeriod periodInSeconds_,TaskDeadlineMissedFunction deadLineMissedFunction_) { +FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(TaskName name_, + TaskPriority taskPriority_,TaskStackSize stackSize_,TaskPeriod periodInSeconds_, + TaskDeadlineMissedFunction deadLineMissedFunction_) { rtems_interval taskPeriod = periodInSeconds_ * Clock::getTicksPerSecond(); - return static_cast(new PollingTask(name_,taskPriority_,stackSize_,taskPeriod,deadLineMissedFunction_)); + return static_cast(new FixedTimeslotTask(name_, taskPriority_, + stackSize_, taskPeriod, deadLineMissedFunction_)); } ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {