timeslot update for FreeRTOS
This commit is contained in:
parent
9465c8f2b2
commit
66cf2d3559
@ -1,20 +0,0 @@
|
||||
/**
|
||||
* @file PollingSlot.cpp
|
||||
* @brief This file defines the PollingSlot class.
|
||||
* @date 19.12.2012
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#include "FixedSequenceSlot.h"
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask) :
|
||||
handler(NULL), pollingTimeMs(setTime), opcode(setSequenceId) {
|
||||
handler = objectManager->get<ExecutableObjectIF>(handlerId);
|
||||
handler->setTaskIF(executingTask);
|
||||
}
|
||||
|
||||
FixedSequenceSlot::~FixedSequenceSlot() {}
|
||||
|
@ -8,7 +8,7 @@ const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = configMINIMAL_STACK_SIZE;
|
||||
FixedTimeslotTask::FixedTimeslotTask(TaskName name, TaskPriority setPriority,
|
||||
TaskStackSize setStack, TaskPeriod overallPeriod,
|
||||
void (*setDeadlineMissedFunc)()) :
|
||||
started(false), handle(NULL), pst(overallPeriod * 1000) {
|
||||
started(false), handle(nullptr), pst(overallPeriod * 1000) {
|
||||
configSTACK_DEPTH_TYPE stackSize = setStack / sizeof(configSTACK_DEPTH_TYPE);
|
||||
xTaskCreate(taskEntryPoint, name, stackSize, this, setPriority, &handle);
|
||||
// All additional attributes are applied to the object.
|
||||
@ -62,8 +62,10 @@ ReturnValue_t FixedTimeslotTask::startTask() {
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) {
|
||||
if (objectManager->get<ExecutableObjectIF>(componentId) != nullptr) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
ExecutableObjectIF* handler =
|
||||
objectManager->get<ExecutableObjectIF>(componentId);
|
||||
if (handler != nullptr) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, handler, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -85,6 +87,8 @@ void FixedTimeslotTask::taskFunctionality() {
|
||||
// start time for the first entry.
|
||||
auto slotListIter = pst.current;
|
||||
|
||||
pst.intializeSequenceAfterTaskCreation();
|
||||
|
||||
//The start time for the first entry is read.
|
||||
uint32_t intervalMs = slotListIter->pollingTimeMs;
|
||||
TickType_t interval = pdMS_TO_TICKS(intervalMs);
|
||||
|
@ -1,12 +1,11 @@
|
||||
#ifndef FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
||||
#define FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
||||
|
||||
#include "FreeRTOSTaskIF.h"
|
||||
#include "../../devicehandlers/FixedSlotSequence.h"
|
||||
#include "../../osal/FreeRTOS/FreeRTOSTaskIF.h"
|
||||
#include "../../tasks/FixedSlotSequence.h"
|
||||
#include "../../tasks/FixedTimeslotTaskIF.h"
|
||||
#include "../../tasks/Typedef.h"
|
||||
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
@ -99,4 +98,4 @@ protected:
|
||||
void handleMissedDeadline();
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_ */
|
||||
#endif /* POLLINGTASK_H_ */
|
||||
|
17
tasks/FixedSequenceSlot.cpp
Normal file
17
tasks/FixedSequenceSlot.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "FixedSequenceSlot.h"
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include <cstddef>
|
||||
|
||||
FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime,
|
||||
int8_t setSequenceId, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask) :
|
||||
pollingTimeMs(setTime), opcode(setSequenceId) {
|
||||
if(executableObject == nullptr) {
|
||||
return;
|
||||
}
|
||||
this->executableObject = executableObject;
|
||||
this->executableObject->setTaskIF(executingTask);
|
||||
}
|
||||
|
||||
FixedSequenceSlot::~FixedSequenceSlot() {}
|
||||
|
@ -1,39 +1,36 @@
|
||||
/**
|
||||
* @file FixedSequenceSlot.h
|
||||
* @brief This file defines the PollingSlot class.
|
||||
* @date 19.12.2012
|
||||
* @author baetz
|
||||
*/
|
||||
|
||||
#ifndef FIXEDSEQUENCESLOT_H_
|
||||
#define FIXEDSEQUENCESLOT_H_
|
||||
#ifndef FRAMEWORK_TASKS_FIXEDSEQUENCESLOT_H_
|
||||
#define FRAMEWORK_TASKS_FIXEDSEQUENCESLOT_H_
|
||||
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../tasks/ExecutableObjectIF.h"
|
||||
class PeriodicTaskIF;
|
||||
|
||||
/**
|
||||
* @brief This class is the representation of a single polling sequence table entry.
|
||||
*
|
||||
* @details The PollingSlot class is the representation of a single polling
|
||||
* @brief This class is the representation of a single polling sequence
|
||||
* table entry.
|
||||
* @details
|
||||
* The PollingSlot class is the representation of a single polling
|
||||
* sequence table entry.
|
||||
* @author baetz
|
||||
*/
|
||||
class FixedSequenceSlot {
|
||||
public:
|
||||
FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask );
|
||||
int8_t setSequenceId, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask);
|
||||
virtual ~FixedSequenceSlot();
|
||||
|
||||
/**
|
||||
* @brief Handler identifies which device handler object is executed in this slot.
|
||||
* @brief Handler identifies which object is executed in this slot.
|
||||
*/
|
||||
ExecutableObjectIF* handler;
|
||||
ExecutableObjectIF* executableObject = nullptr;
|
||||
|
||||
/**
|
||||
* @brief This attribute defines when a device handler object is executed.
|
||||
*
|
||||
* @details The pollingTime attribute identifies the time the handler is executed in ms.
|
||||
* It must be smaller than the period length of the polling sequence.
|
||||
* @details
|
||||
* The pollingTime attribute identifies the time the handler is
|
||||
* executed in ms. It must be smaller than the period length of the
|
||||
* polling sequence.
|
||||
*/
|
||||
uint32_t pollingTimeMs;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "FixedSlotSequence.h"
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include <cstdlib>
|
||||
|
||||
FixedSlotSequence::FixedSlotSequence(uint32_t setLengthMs) :
|
||||
lengthMs(setLengthMs) {
|
||||
@ -12,7 +13,7 @@ FixedSlotSequence::~FixedSlotSequence() {
|
||||
}
|
||||
|
||||
void FixedSlotSequence::executeAndAdvance() {
|
||||
current->handler->performOperation(current->opcode);
|
||||
current->executableObject->performOperation(current->opcode);
|
||||
// if (returnValue != RETURN_OK) {
|
||||
// this->sendErrorMessage( returnValue );
|
||||
// }
|
||||
@ -80,34 +81,41 @@ uint32_t FixedSlotSequence::getLengthMs() const {
|
||||
return this->lengthMs;
|
||||
}
|
||||
|
||||
void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
||||
int8_t executionStep, ExecutableObjectIF* executableObject,
|
||||
PeriodicTaskIF* executingTask) {
|
||||
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs,
|
||||
executionStep, executableObject, executingTask));
|
||||
this->current = slotList.begin();
|
||||
}
|
||||
|
||||
ReturnValue_t FixedSlotSequence::checkSequence() const {
|
||||
if(slotList.empty()) {
|
||||
sif::error << "Fixed Slot Sequence: Slot list is empty!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
auto slotIt = slotList.begin();
|
||||
uint32_t count = 0;
|
||||
uint32_t time = 0;
|
||||
while (slotIt != slotList.end()) {
|
||||
if (slotIt->handler == nullptr) {
|
||||
sif::error << "FixedSlotSequene::initialize: ObjectId does not exist!"
|
||||
<< std::endl;
|
||||
for(const auto& slot: slotList) {
|
||||
if (slot.executableObject == nullptr) {
|
||||
count++;
|
||||
} else if (slotIt->pollingTimeMs < time) {
|
||||
}
|
||||
else if (slot.pollingTimeMs < time) {
|
||||
sif::error << "FixedSlotSequence::initialize: Time: "
|
||||
<< slotIt->pollingTimeMs
|
||||
<< " is smaller than previous with " << time << std::endl;
|
||||
<< slot.pollingTimeMs << " is smaller than previous with "
|
||||
<< time << std::endl;
|
||||
count++;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// All ok, print slot.
|
||||
//info << "Current slot polling time: " << std::endl;
|
||||
//info << std::dec << slotIt->pollingTimeMs << std::endl;
|
||||
//sif::info << "Current slot polling time: " << std::endl;
|
||||
//sif::info << std::dec << slotIt->pollingTimeMs << std::endl;
|
||||
}
|
||||
time = slotIt->pollingTimeMs;
|
||||
slotIt++;
|
||||
time = slot.pollingTimeMs;
|
||||
|
||||
}
|
||||
//info << "Number of elements in slot list: "
|
||||
//sif::info << "Number of elements in slot list: "
|
||||
// << slotList.size() << std::endl;
|
||||
if (count > 0) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -115,9 +123,25 @@ ReturnValue_t FixedSlotSequence::checkSequence() const {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
||||
int8_t executionStep, PeriodicTaskIF* executingTask) {
|
||||
this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs, executionStep,
|
||||
executingTask));
|
||||
this->current = slotList.begin();
|
||||
|
||||
ReturnValue_t FixedSlotSequence::intializeSequenceAfterTaskCreation() const {
|
||||
std::set<ExecutableObjectIF*> uniqueObjects;
|
||||
uint32_t count = 0;
|
||||
for(const auto& slot: slotList) {
|
||||
// Ensure that each unique object is initialized once.
|
||||
if(uniqueObjects.find(slot.executableObject) == uniqueObjects.end()) {
|
||||
ReturnValue_t result =
|
||||
slot.executableObject->initializeAfterTaskCreation();
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
count++;
|
||||
}
|
||||
uniqueObjects.emplace(slot.executableObject);
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
sif::error << "FixedSlotSequence::intializeSequenceAfterTaskCreation:"
|
||||
"Counted " << count << " failed initializations!" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
#ifndef FRAMEWORK_DEVICEHANDLERS_FIXEDSLOTSEQUENCE_H_
|
||||
#define FRAMEWORK_DEVICEHANDLERS_FIXEDSLOTSEQUENCE_H_
|
||||
#ifndef FRAMEWORK_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||
#define FRAMEWORK_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||
|
||||
#include "FixedSequenceSlot.h"
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
/**
|
||||
* @brief This class is the representation of a Polling Sequence Table in software.
|
||||
*
|
||||
* @details
|
||||
* The FixedSlotSequence object maintains the dynamic execution of
|
||||
* device handler objects.
|
||||
@ -59,7 +59,7 @@ public:
|
||||
* @param
|
||||
*/
|
||||
void addSlot(object_id_t handlerId, uint32_t setTime, int8_t setSequenceId,
|
||||
PeriodicTaskIF* executingTask);
|
||||
ExecutableObjectIF* executableObject, PeriodicTaskIF* executingTask);
|
||||
|
||||
/**
|
||||
* Checks if the current slot shall be executed immediately after the one before.
|
||||
@ -125,12 +125,17 @@ public:
|
||||
SlotListIter current;
|
||||
|
||||
/**
|
||||
* Iterate through slotList and check successful creation.
|
||||
* @brief Check and initialize slot list.
|
||||
* @details
|
||||
* Checks if timing is ok (must be ascending) and if all handlers were found.
|
||||
* Also calls any initialization steps which are required after task
|
||||
* creation.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t checkSequence() const;
|
||||
|
||||
ReturnValue_t intializeSequenceAfterTaskCreation() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
@ -147,6 +152,8 @@ protected:
|
||||
SlotList slotList;
|
||||
|
||||
uint32_t lengthMs;
|
||||
|
||||
bool isEmpty = false;
|
||||
};
|
||||
|
||||
#endif /* FIXEDSLOTSEQUENCE_H_ */
|
Loading…
Reference in New Issue
Block a user