rtems multi object is now periodicTask
This commit is contained in:
parent
47698418fc
commit
de45e9b8a9
@ -5,13 +5,13 @@ target_sources(${LIB_FSFW_NAME}
|
||||
InitTask.cpp
|
||||
InternalErrorCodes.cpp
|
||||
MessageQueue.cpp
|
||||
MultiObjectTask.cpp
|
||||
PeriodicTask.cpp
|
||||
Mutex.cpp
|
||||
MutexFactory.cpp
|
||||
PollingTask.cpp
|
||||
QueueFactory.cpp
|
||||
RtemsBasic.cpp
|
||||
TaskBase.cpp
|
||||
RTEMSTaskBase.cpp
|
||||
TaskFactory.cpp
|
||||
)
|
||||
|
||||
|
@ -1,86 +0,0 @@
|
||||
/**
|
||||
* @file MultiObjectTask.cpp
|
||||
* @brief This file defines the MultiObjectTask class.
|
||||
* @date 30.01.2014
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
#include "MultiObjectTask.h"
|
||||
|
||||
MultiObjectTask::MultiObjectTask(const char *name, rtems_task_priority setPriority,
|
||||
size_t setStack, rtems_interval setPeriod, void (*setDeadlineMissedFunc)()) :
|
||||
TaskBase(setPriority, setStack, name), periodTicks(
|
||||
RtemsBasic::convertMsToTicks(setPeriod)), periodId(0), deadlineMissedFunc(
|
||||
setDeadlineMissedFunc) {
|
||||
}
|
||||
|
||||
MultiObjectTask::~MultiObjectTask(void) {
|
||||
//Do not delete objects, we were responsible for ptrs only.
|
||||
rtems_rate_monotonic_delete(periodId);
|
||||
}
|
||||
rtems_task MultiObjectTask::taskEntryPoint(rtems_task_argument argument) {
|
||||
//The argument is re-interpreted as MultiObjectTask. The Task object is global, so it is found from any place.
|
||||
MultiObjectTask *originalTask(reinterpret_cast<MultiObjectTask*>(argument));
|
||||
originalTask->taskFunctionality();
|
||||
}
|
||||
|
||||
ReturnValue_t MultiObjectTask::startTask() {
|
||||
rtems_status_code status = rtems_task_start(id, MultiObjectTask::taskEntryPoint,
|
||||
rtems_task_argument((void *) this));
|
||||
if (status != RTEMS_SUCCESSFUL) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "ObjectTask::startTask for " << std::hex << this->getId()
|
||||
<< std::dec << " failed." << std::endl;
|
||||
#endif
|
||||
}
|
||||
switch(status){
|
||||
case RTEMS_SUCCESSFUL:
|
||||
//ask started successfully
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
default:
|
||||
/* RTEMS_INVALID_ADDRESS - invalid task entry point
|
||||
RTEMS_INVALID_ID - invalid task id
|
||||
RTEMS_INCORRECT_STATE - task not in the dormant state
|
||||
RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t MultiObjectTask::sleepFor(uint32_t ms) {
|
||||
return TaskBase::sleepFor(ms);
|
||||
}
|
||||
|
||||
void MultiObjectTask::taskFunctionality() {
|
||||
TaskBase::setAndStartPeriod(periodTicks,&periodId);
|
||||
//The task's "infinite" inner loop is entered.
|
||||
while (1) {
|
||||
for (ObjectList::iterator it = objectList.begin();
|
||||
it != objectList.end(); ++it) {
|
||||
(*it)->performOperation();
|
||||
}
|
||||
rtems_status_code status = TaskBase::restartPeriod(periodTicks,periodId);
|
||||
if (status == RTEMS_TIMEOUT) {
|
||||
if (this->deadlineMissedFunc != nullptr) {
|
||||
this->deadlineMissedFunc();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t MultiObjectTask::addComponent(object_id_t object) {
|
||||
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(
|
||||
object);
|
||||
if (newObject == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
objectList.push_back(newObject);
|
||||
newObject->setTaskIF(this);
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t MultiObjectTask::getPeriodMs() const {
|
||||
return RtemsBasic::convertTicksToMs(periodTicks);
|
||||
}
|
80
osal/rtems/PeriodicTask.cpp
Normal file
80
osal/rtems/PeriodicTask.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
#include "PeriodicTask.h"
|
||||
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
#include "../../tasks/ExecutableObjectIF.h"
|
||||
|
||||
PeriodicTask::PeriodicTask(const char *name, rtems_task_priority setPriority,
|
||||
size_t setStack, rtems_interval setPeriod, void (*setDeadlineMissedFunc)()) :
|
||||
RTEMSTaskBase(setPriority, setStack, name),
|
||||
periodTicks(RtemsBasic::convertMsToTicks(setPeriod)),
|
||||
deadlineMissedFunc(setDeadlineMissedFunc) {
|
||||
}
|
||||
|
||||
PeriodicTask::~PeriodicTask(void) {
|
||||
/* Do not delete objects, we were responsible for pointers only. */
|
||||
rtems_rate_monotonic_delete(periodId);
|
||||
}
|
||||
|
||||
rtems_task PeriodicTask::taskEntryPoint(rtems_task_argument argument) {
|
||||
/* The argument is re-interpreted as MultiObjectTask. The Task object is global,
|
||||
so it is found from any place. */
|
||||
PeriodicTask *originalTask(reinterpret_cast<PeriodicTask*>(argument));
|
||||
return originalTask->taskFunctionality();;
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTask::startTask() {
|
||||
rtems_status_code status = rtems_task_start(id, PeriodicTask::taskEntryPoint,
|
||||
rtems_task_argument((void *) this));
|
||||
if (status != RTEMS_SUCCESSFUL) {
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
sif::error << "ObjectTask::startTask for " << std::hex << this->getId()
|
||||
<< std::dec << " failed." << std::endl;
|
||||
#endif
|
||||
}
|
||||
switch(status){
|
||||
case RTEMS_SUCCESSFUL:
|
||||
/* Task started successfully */
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
default:
|
||||
/* RTEMS_INVALID_ADDRESS - invalid task entry point
|
||||
RTEMS_INVALID_ID - invalid task id
|
||||
RTEMS_INCORRECT_STATE - task not in the dormant state
|
||||
RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task */
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTask::sleepFor(uint32_t ms) {
|
||||
return RTEMSTaskBase::sleepFor(ms);
|
||||
}
|
||||
|
||||
void PeriodicTask::taskFunctionality() {
|
||||
RTEMSTaskBase::setAndStartPeriod(periodTicks,&periodId);
|
||||
/* The task's "infinite" inner loop is entered. */
|
||||
while (1) {
|
||||
for (const auto& object: objectList) {
|
||||
object->performOperation();
|
||||
}
|
||||
rtems_status_code status = RTEMSTaskBase::restartPeriod(periodTicks,periodId);
|
||||
if (status == RTEMS_TIMEOUT) {
|
||||
if (this->deadlineMissedFunc != nullptr) {
|
||||
this->deadlineMissedFunc();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
|
||||
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(object);
|
||||
if (newObject == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
objectList.push_back(newObject);
|
||||
newObject->setTaskIF(this);
|
||||
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
uint32_t PeriodicTask::getPeriodMs() const {
|
||||
return RtemsBasic::convertTicksToMs(periodTicks);
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
#ifndef FSFW_OSAL_RTEMS_MULTIOBJECTTASK_H_
|
||||
#define FSFW_OSAL_RTEMS_MULTIOBJECTTASK_H_
|
||||
#ifndef FSFW_OSAL_RTEMS_PERIODICTASK_H_
|
||||
#define FSFW_OSAL_RTEMS_PERIODICTASK_H_
|
||||
|
||||
#include "RTEMSTaskBase.h"
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../tasks/PeriodicTaskIF.h"
|
||||
|
||||
#include "TaskBase.h"
|
||||
#include <vector>
|
||||
|
||||
class ExecutableObjectIF;
|
||||
@ -18,7 +18,7 @@ class ExecutableObjectIF;
|
||||
* @author baetz
|
||||
* @ingroup task_handling
|
||||
*/
|
||||
class MultiObjectTask: public TaskBase, public PeriodicTaskIF {
|
||||
class PeriodicTask: public RTEMSTaskBase, public PeriodicTaskIF {
|
||||
public:
|
||||
/**
|
||||
* @brief Standard constructor of the class.
|
||||
@ -35,13 +35,13 @@ public:
|
||||
* @param setDeadlineMissedFunc The function pointer to the deadline missed function
|
||||
* that shall be assigned.
|
||||
*/
|
||||
MultiObjectTask(const char *name, rtems_task_priority setPriority, size_t setStack, rtems_interval setPeriod,
|
||||
void (*setDeadlineMissedFunc)());
|
||||
PeriodicTask(const char *name, rtems_task_priority setPriority, size_t setStack,
|
||||
rtems_interval setPeriod, void (*setDeadlineMissedFunc)());
|
||||
/**
|
||||
* @brief Currently, the executed object's lifetime is not coupled with the task object's
|
||||
* lifetime, so the destructor is empty.
|
||||
*/
|
||||
virtual ~MultiObjectTask(void);
|
||||
virtual ~PeriodicTask(void);
|
||||
|
||||
/**
|
||||
* @brief The method to start the task.
|
||||
@ -76,7 +76,7 @@ protected:
|
||||
/**
|
||||
* @brief id of the associated OS period
|
||||
*/
|
||||
rtems_id periodId;
|
||||
rtems_id periodId = 0;
|
||||
/**
|
||||
* @brief The pointer to the deadline-missed function.
|
||||
* @details This pointer stores the function that is executed if the task's deadline is missed.
|
||||
@ -104,4 +104,4 @@ protected:
|
||||
void taskFunctionality(void);
|
||||
};
|
||||
|
||||
#endif /* FSFW_OSAL_RTEMS_MULTIOBJECTTASK_H_ */
|
||||
#endif /* FSFW_OSAL_RTEMS_PERIODICTASK_H_ */
|
@ -20,7 +20,7 @@ uint32_t PollingTask::deadlineMissedCount = 0;
|
||||
PollingTask::PollingTask(const char *name, rtems_task_priority setPriority,
|
||||
size_t setStack, uint32_t setOverallPeriod,
|
||||
void (*setDeadlineMissedFunc)()) :
|
||||
TaskBase(setPriority, setStack, name), periodId(0), pst(
|
||||
RTEMSTaskBase(setPriority, setStack, name), periodId(0), pst(
|
||||
setOverallPeriod) {
|
||||
// All additional attributes are applied to the object.
|
||||
this->deadlineMissedFunc = setDeadlineMissedFunc;
|
||||
@ -104,7 +104,7 @@ void PollingTask::taskFunctionality() {
|
||||
|
||||
//The start time for the first entry is read.
|
||||
rtems_interval interval = RtemsBasic::convertMsToTicks(it->pollingTimeMs);
|
||||
TaskBase::setAndStartPeriod(interval,&periodId);
|
||||
RTEMSTaskBase::setAndStartPeriod(interval,&periodId);
|
||||
//The task's "infinite" inner loop is entered.
|
||||
while (1) {
|
||||
if (pst.slotFollowsImmediately()) {
|
||||
@ -114,7 +114,7 @@ void PollingTask::taskFunctionality() {
|
||||
interval = RtemsBasic::convertMsToTicks(this->pst.getIntervalToNextSlotMs());
|
||||
//The period is checked and restarted with the new interval.
|
||||
//If the deadline was missed, the deadlineMissedFunc is called.
|
||||
rtems_status_code status = TaskBase::restartPeriod(interval,periodId);
|
||||
rtems_status_code status = RTEMSTaskBase::restartPeriod(interval,periodId);
|
||||
if (status == RTEMS_TIMEOUT) {
|
||||
if (this->deadlineMissedFunc != nullptr) {
|
||||
this->deadlineMissedFunc();
|
||||
@ -127,5 +127,5 @@ void PollingTask::taskFunctionality() {
|
||||
}
|
||||
|
||||
ReturnValue_t PollingTask::sleepFor(uint32_t ms){
|
||||
return TaskBase::sleepFor(ms);
|
||||
return RTEMSTaskBase::sleepFor(ms);
|
||||
};
|
||||
|
@ -1,11 +1,11 @@
|
||||
#ifndef FSFW_OSAL_RTEMS_POLLINGTASK_H_
|
||||
#define FSFW_OSAL_RTEMS_POLLINGTASK_H_
|
||||
|
||||
#include <fsfw/osal/rtems/RTEMSTaskBase.h>
|
||||
#include "../../tasks/FixedSlotSequence.h"
|
||||
#include "../../tasks/FixedTimeslotTaskIF.h"
|
||||
#include "TaskBase.h"
|
||||
|
||||
class PollingTask: public TaskBase, public FixedTimeslotTaskIF {
|
||||
class PollingTask: public RTEMSTaskBase, public FixedTimeslotTaskIF {
|
||||
public:
|
||||
/**
|
||||
* @brief The standard constructor of the class.
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "TaskBase.h"
|
||||
#include <fsfw/osal/rtems/RTEMSTaskBase.h>
|
||||
#include "../../serviceinterface/ServiceInterface.h"
|
||||
|
||||
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = RTEMS_MINIMUM_STACK_SIZE;
|
||||
|
||||
TaskBase::TaskBase(rtems_task_priority set_priority, size_t stack_size,
|
||||
RTEMSTaskBase::RTEMSTaskBase(rtems_task_priority set_priority, size_t stack_size,
|
||||
const char *name) {
|
||||
rtems_name osalName = 0;
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
@ -31,21 +31,21 @@ TaskBase::TaskBase(rtems_task_priority set_priority, size_t stack_size,
|
||||
}
|
||||
}
|
||||
|
||||
TaskBase::~TaskBase() {
|
||||
RTEMSTaskBase::~RTEMSTaskBase() {
|
||||
rtems_task_delete(id);
|
||||
}
|
||||
|
||||
rtems_id TaskBase::getId() {
|
||||
rtems_id RTEMSTaskBase::getId() {
|
||||
return this->id;
|
||||
}
|
||||
|
||||
ReturnValue_t TaskBase::sleepFor(uint32_t ms) {
|
||||
ReturnValue_t RTEMSTaskBase::sleepFor(uint32_t ms) {
|
||||
rtems_status_code status = rtems_task_wake_after(RtemsBasic::convertMsToTicks(ms));
|
||||
return convertReturnCode(status);
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TaskBase::convertReturnCode(rtems_status_code inValue) {
|
||||
ReturnValue_t RTEMSTaskBase::convertReturnCode(rtems_status_code inValue) {
|
||||
switch (inValue) {
|
||||
case RTEMS_SUCCESSFUL:
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
@ -68,7 +68,7 @@ ReturnValue_t TaskBase::convertReturnCode(rtems_status_code inValue) {
|
||||
}
|
||||
|
||||
|
||||
ReturnValue_t TaskBase::setAndStartPeriod(rtems_interval period, rtems_id *periodId) {
|
||||
ReturnValue_t RTEMSTaskBase::setAndStartPeriod(rtems_interval period, rtems_id *periodId) {
|
||||
rtems_name periodName = (('P' << 24) + ('e' << 16) + ('r' << 8) + 'd');
|
||||
rtems_status_code status = rtems_rate_monotonic_create(periodName, periodId);
|
||||
if (status == RTEMS_SUCCESSFUL) {
|
||||
@ -77,7 +77,7 @@ ReturnValue_t TaskBase::setAndStartPeriod(rtems_interval period, rtems_id *perio
|
||||
return convertReturnCode(status);
|
||||
}
|
||||
|
||||
rtems_status_code TaskBase::restartPeriod(rtems_interval period, rtems_id periodId){
|
||||
rtems_status_code RTEMSTaskBase::restartPeriod(rtems_interval period, rtems_id periodId){
|
||||
//This is necessary to avoid a call with period = 0, which does not start the period.
|
||||
rtems_status_code status = rtems_rate_monotonic_period(periodId, period + 1);
|
||||
return status;
|
@ -1,5 +1,5 @@
|
||||
#ifndef FSFW_OSAL_RTEMS_TASKBASE_H_
|
||||
#define FSFW_OSAL_RTEMS_TASKBASE_H_
|
||||
#ifndef FSFW_OSAL_RTEMS_RTEMSTASKBASE_H_
|
||||
#define FSFW_OSAL_RTEMS_RTEMSTASKBASE_H_
|
||||
|
||||
#include "RtemsBasic.h"
|
||||
#include "../../tasks/PeriodicTaskIF.h"
|
||||
@ -9,7 +9,7 @@
|
||||
*
|
||||
* @details Task creation base class for rtems.
|
||||
*/
|
||||
class TaskBase {
|
||||
class RTEMSTaskBase {
|
||||
protected:
|
||||
/**
|
||||
* @brief The class stores the task id it got assigned from the operating system in this attribute.
|
||||
@ -26,11 +26,11 @@ public:
|
||||
* @param stack_size The stack size reserved by the operating system for the task.
|
||||
* @param nam The name of the Task, as a null-terminated String. Currently max 4 chars supported (excluding Null-terminator), rest will be truncated
|
||||
*/
|
||||
TaskBase( rtems_task_priority priority, size_t stack_size, const char *name);
|
||||
RTEMSTaskBase( rtems_task_priority priority, size_t stack_size, const char *name);
|
||||
/**
|
||||
* @brief In the destructor, the created task is deleted.
|
||||
*/
|
||||
virtual ~TaskBase();
|
||||
virtual ~RTEMSTaskBase();
|
||||
/**
|
||||
* @brief This method returns the task id of this class.
|
||||
*/
|
||||
@ -44,4 +44,4 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* FSFW_OSAL_RTEMS_TASKBASE_H_ */
|
||||
#endif /* FSFW_OSAL_RTEMS_RTEMSTASKBASE_H_ */
|
@ -1,5 +1,6 @@
|
||||
#include "RtemsBasic.h"
|
||||
|
||||
// TODO: Can this be removed?
|
||||
|
||||
//ReturnValue_t RtemsBasic::convertReturnCode(rtems_status_code inValue) {
|
||||
// if (inValue == RTEMS_SUCCESSFUL) {
|
||||
|
@ -2,12 +2,13 @@
|
||||
#define FSFW_OSAL_RTEMS_RTEMSBASIC_H_
|
||||
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/libio.h>
|
||||
#include <rtems/error.h>
|
||||
#include <rtems/stackchk.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class RtemsBasic {
|
||||
public:
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <fsfw/osal/rtems/PeriodicTask.h>
|
||||
#include "../../tasks/TaskFactory.h"
|
||||
#include "MultiObjectTask.h"
|
||||
#include "PollingTask.h"
|
||||
#include "InitTask.h"
|
||||
#include "RtemsBasic.h"
|
||||
@ -18,7 +18,7 @@ TaskFactory* TaskFactory::instance() {
|
||||
PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_,TaskPriority taskPriority_,TaskStackSize stackSize_,TaskPeriod periodInSeconds_,TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
||||
rtems_interval taskPeriod = periodInSeconds_ * Clock::getTicksPerSecond();
|
||||
|
||||
return static_cast<PeriodicTaskIF*>(new MultiObjectTask(name_,taskPriority_,stackSize_,taskPeriod,deadLineMissedFunction_));
|
||||
return static_cast<PeriodicTaskIF*>(new PeriodicTask(name_,taskPriority_,stackSize_,taskPeriod,deadLineMissedFunction_));
|
||||
}
|
||||
|
||||
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(TaskName name_,TaskPriority taskPriority_,TaskStackSize stackSize_,TaskPeriod periodInSeconds_,TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
||||
|
Loading…
Reference in New Issue
Block a user