indentation

This commit is contained in:
Robin Müller 2021-01-28 00:15:13 +01:00
parent 5b0758638b
commit dcb569a7c8
2 changed files with 128 additions and 130 deletions

View File

@ -25,118 +25,116 @@
uint32_t FixedTimeslotTask::deadlineMissedCount = 0; uint32_t FixedTimeslotTask::deadlineMissedCount = 0;
FixedTimeslotTask::FixedTimeslotTask(const char *name, rtems_task_priority setPriority, FixedTimeslotTask::FixedTimeslotTask(const char *name, rtems_task_priority setPriority,
size_t setStack, uint32_t setOverallPeriod, size_t setStack, uint32_t setOverallPeriod, void (*setDeadlineMissedFunc)(void)):
void (*setDeadlineMissedFunc)()) : RTEMSTaskBase(setPriority, setStack, name), periodId(0), pst(setOverallPeriod) {
RTEMSTaskBase(setPriority, setStack, name), periodId(0), pst( // All additional attributes are applied to the object.
setOverallPeriod) { this->deadlineMissedFunc = setDeadlineMissedFunc;
// All additional attributes are applied to the object.
this->deadlineMissedFunc = setDeadlineMissedFunc;
} }
FixedTimeslotTask::~FixedTimeslotTask() { FixedTimeslotTask::~FixedTimeslotTask() {
} }
rtems_task FixedTimeslotTask::taskEntryPoint(rtems_task_argument argument) { rtems_task FixedTimeslotTask::taskEntryPoint(rtems_task_argument argument) {
/* The argument is re-interpreted as a FixedTimeslotTask */
//The argument is re-interpreted as PollingTask. FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(argument)); /* The task's functionality is called. */
//The task's functionality is called. return originalTask->taskFunctionality();
return originalTask->taskFunctionality(); /* Should never be reached */
/* Should never be reached */
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Polling task " << originalTask->getId() << " returned from taskFunctionality." << sif::error << "Polling task " << originalTask->getId() << " returned from taskFunctionality." <<
std::endl; std::endl;
#endif #endif
} }
void FixedTimeslotTask::missedDeadlineCounter() { void FixedTimeslotTask::missedDeadlineCounter() {
FixedTimeslotTask::deadlineMissedCount++; FixedTimeslotTask::deadlineMissedCount++;
if (FixedTimeslotTask::deadlineMissedCount % 10 == 0) { if (FixedTimeslotTask::deadlineMissedCount % 10 == 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PST missed " << FixedTimeslotTask::deadlineMissedCount sif::error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
<< " deadlines." << std::endl; << " deadlines." << std::endl;
#endif #endif
} }
} }
ReturnValue_t FixedTimeslotTask::startTask() { ReturnValue_t FixedTimeslotTask::startTask() {
rtems_status_code status = rtems_task_start(id, FixedTimeslotTask::taskEntryPoint, rtems_status_code status = rtems_task_start(id, FixedTimeslotTask::taskEntryPoint,
rtems_task_argument((void *) this)); rtems_task_argument((void *) this));
if (status != RTEMS_SUCCESSFUL) { if (status != RTEMS_SUCCESSFUL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PollingTask::startTask for " << std::hex << this->getId() sif::error << "PollingTask::startTask for " << std::hex << this->getId()
<< std::dec << " failed." << std::endl; << std::dec << " failed." << std::endl;
#endif #endif
} }
switch(status){ switch(status){
case RTEMS_SUCCESSFUL: case RTEMS_SUCCESSFUL:
//ask started successfully //ask started successfully
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
default: default:
/* RTEMS_INVALID_ADDRESS - invalid task entry point /*
RTEMS_INVALID_ADDRESS - invalid task entry point
RTEMS_INVALID_ID - invalid task id RTEMS_INVALID_ID - invalid task id
RTEMS_INCORRECT_STATE - task not in the dormant state RTEMS_INCORRECT_STATE - task not in the dormant state
RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task */ RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task */
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
uint32_t slotTimeMs, int8_t executionStep) { uint32_t slotTimeMs, int8_t executionStep) {
ExecutableObjectIF* object = objectManager->get<ExecutableObjectIF>(componentId); ExecutableObjectIF* object = objectManager->get<ExecutableObjectIF>(componentId);
if (object != nullptr) { if (object != nullptr) {
pst.addSlot(componentId, slotTimeMs, executionStep, object, this); pst.addSlot(componentId, slotTimeMs, executionStep, object, this);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "Component " << std::hex << componentId << sif::error << "Component " << std::hex << componentId <<
" not found, not adding it to pst" << std::endl; " not found, not adding it to pst" << std::endl;
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
uint32_t FixedTimeslotTask::getPeriodMs() const { uint32_t FixedTimeslotTask::getPeriodMs() const {
return pst.getLengthMs(); return pst.getLengthMs();
} }
ReturnValue_t FixedTimeslotTask::checkSequence() const { ReturnValue_t FixedTimeslotTask::checkSequence() const {
return pst.checkSequence(); return pst.checkSequence();
} }
void FixedTimeslotTask::taskFunctionality() { void FixedTimeslotTask::taskFunctionality() {
/* A local iterator for the Polling Sequence Table is created to find the start time for /* A local iterator for the Polling Sequence Table is created to find the start time for
the first entry. */ the first entry. */
FixedSlotSequence::SlotListIter it = pst.current; FixedSlotSequence::SlotListIter it = pst.current;
/* Initialize the PST with the correct calling task */ /* Initialize the PST with the correct calling task */
pst.intializeSequenceAfterTaskCreation(); pst.intializeSequenceAfterTaskCreation();
/* The start time for the first entry is read. */ /* The start time for the first entry is read. */
rtems_interval interval = RtemsBasic::convertMsToTicks(it->pollingTimeMs); rtems_interval interval = RtemsBasic::convertMsToTicks(it->pollingTimeMs);
RTEMSTaskBase::setAndStartPeriod(interval,&periodId); RTEMSTaskBase::setAndStartPeriod(interval,&periodId);
//The task's "infinite" inner loop is entered. //The task's "infinite" inner loop is entered.
while (1) { while (1) {
if (pst.slotFollowsImmediately()) { if (pst.slotFollowsImmediately()) {
//Do nothing /* Do nothing */
} }
else { else {
//The interval for the next polling slot is selected. /* The interval for the next polling slot is selected. */
interval = RtemsBasic::convertMsToTicks(this->pst.getIntervalToNextSlotMs()); interval = RtemsBasic::convertMsToTicks(this->pst.getIntervalToNextSlotMs());
//The period is checked and restarted with the new interval. /* The period is checked and restarted with the new interval.
//If the deadline was missed, the deadlineMissedFunc is called. If the deadline was missed, the deadlineMissedFunc is called. */
rtems_status_code status = RTEMSTaskBase::restartPeriod(interval,periodId); rtems_status_code status = RTEMSTaskBase::restartPeriod(interval,periodId);
if (status == RTEMS_TIMEOUT) { if (status == RTEMS_TIMEOUT) {
if (this->deadlineMissedFunc != nullptr) { if (this->deadlineMissedFunc != nullptr) {
this->deadlineMissedFunc(); this->deadlineMissedFunc();
} }
} }
} }
//The device handler for this slot is executed and the next one is chosen. /* The device handler for this slot is executed and the next one is chosen. */
this->pst.executeAndAdvance(); this->pst.executeAndAdvance();
} }
} }
ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms){ ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms){
return RTEMSTaskBase::sleepFor(ms); return RTEMSTaskBase::sleepFor(ms);
}; };

View File

@ -8,74 +8,74 @@
class FixedTimeslotTask: public RTEMSTaskBase, public FixedTimeslotTaskIF { class FixedTimeslotTask: public RTEMSTaskBase, public FixedTimeslotTaskIF {
public: public:
/** /**
* @brief The standard constructor of the class. * @brief The standard constructor of the class.
* @details * @details
* This is the general constructor of the class. In addition to the TaskBase parameters, * This is the general constructor of the class. In addition to the TaskBase parameters,
* the following variables are passed: * the following variables are passed:
* @param setDeadlineMissedFunc The function pointer to the deadline missed function * @param setDeadlineMissedFunc The function pointer to the deadline missed function
* that shall be assigned. * that shall be assigned.
* @param getPst The object id of the completely initialized polling sequence. * @param getPst The object id of the completely initialized polling sequence.
*/ */
FixedTimeslotTask( const char *name, rtems_task_priority setPriority, size_t setStackSize, FixedTimeslotTask( const char *name, rtems_task_priority setPriority, size_t setStackSize,
uint32_t overallPeriod, void (*setDeadlineMissedFunc)()); uint32_t overallPeriod, void (*setDeadlineMissedFunc)());
/** /**
* @brief The destructor of the class. * @brief The destructor of the class.
* @details * @details
* The destructor frees all heap memory that was allocated on thread initialization * 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. * for the PST andthe device handlers. This is done by calling the PST's destructor.
*/ */
virtual ~FixedTimeslotTask( void ); virtual ~FixedTimeslotTask( void );
ReturnValue_t startTask( void ); ReturnValue_t startTask( void );
/** /**
* This static function can be used as #deadlineMissedFunc. * This static function can be used as #deadlineMissedFunc.
* It counts missedDeadlines and prints the number of missed deadlines every 10th time. * It counts missedDeadlines and prints the number of missed deadlines every 10th time.
*/ */
static void missedDeadlineCounter(); static void missedDeadlineCounter();
/** /**
* A helper variable to count missed deadlines. * A helper variable to count missed deadlines.
*/ */
static uint32_t deadlineMissedCount; static uint32_t deadlineMissedCount;
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);
uint32_t getPeriodMs() const; uint32_t getPeriodMs() const;
ReturnValue_t checkSequence() const; ReturnValue_t checkSequence() const;
ReturnValue_t sleepFor(uint32_t ms); ReturnValue_t sleepFor(uint32_t ms);
protected: protected:
/** /**
* @brief id of the associated OS period * @brief id of the associated OS period
*/ */
rtems_id periodId; rtems_id periodId;
FixedSlotSequence pst; FixedSlotSequence pst;
/** /**
* @brief This attribute holds a function pointer that is executed when a deadline was missed. * @brief This attribute holds a function pointer that is executed when a deadline was missed.
* *
* @details * @details
* Another function may be announced to determine the actions to perform when a deadline * 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. * was missed. Currently, only one function for missing any deadline is allowed.
* If not used, it shall be declared NULL. * If not used, it shall be declared NULL.
*/ */
void ( *deadlineMissedFunc )( void ) = nullptr; void ( *deadlineMissedFunc )( void ) = nullptr;
/** /**
* @brief This is the entry point in a new polling thread. * @brief This is the entry point in a new polling thread.
* @details This method is the entry point in the new thread * @details This method is the entry point in the new thread
*/ */
static rtems_task taskEntryPoint( rtems_task_argument argument ); static rtems_task taskEntryPoint( rtems_task_argument argument );
/** /**
* @brief This function holds the main functionality of the thread. * @brief This function holds the main functionality of the thread.
* @details * @details
* Holding the main functionality of the task, this method is most important. * 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 * It links the functionalities provided by FixedSlotSequence with the OS's system calls to
* keep the timing of the periods. * keep the timing of the periods.
*/ */
void taskFunctionality( void ); void taskFunctionality( void );
}; };
#endif /* FSFW_OSAL_RTEMS_FIXEDTIMESLOTTASK_H_ */ #endif /* FSFW_OSAL_RTEMS_FIXEDTIMESLOTTASK_H_ */