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