include replacements
This commit is contained in:
@ -1,53 +1,53 @@
|
||||
#ifndef FRAMEWORK_TASKS_EXECUTABLEOBJECTIF_H_
|
||||
#define FRAMEWORK_TASKS_EXECUTABLEOBJECTIF_H_
|
||||
|
||||
class PeriodicTaskIF;
|
||||
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
|
||||
#include <cstring>
|
||||
/**
|
||||
* @brief The interface provides a method to execute objects within a task.
|
||||
* @details The performOperation method, that is required by the interface is
|
||||
* executed cyclically within a task context.
|
||||
* @author Bastian Baetz
|
||||
*/
|
||||
class ExecutableObjectIF {
|
||||
public:
|
||||
/**
|
||||
* @brief This is the empty virtual destructor as required for C++ interfaces.
|
||||
*/
|
||||
virtual ~ExecutableObjectIF() { }
|
||||
/**
|
||||
* @brief The performOperation method is executed in a task.
|
||||
* @details There are no restrictions for calls within this method, so any
|
||||
* other member of the class can be used.
|
||||
* @return Currently, the return value is ignored.
|
||||
*/
|
||||
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) = 0;
|
||||
|
||||
/**
|
||||
* @brief Function called during setup assignment of object to task
|
||||
* @details
|
||||
* Has to be called from the function that assigns the object to a task and
|
||||
* enables the object implementation to overwrite this function and get
|
||||
* a reference to the executing task
|
||||
* @param task_ Pointer to the taskIF of this task
|
||||
*/
|
||||
virtual void setTaskIF(PeriodicTaskIF* task_) {};
|
||||
|
||||
/**
|
||||
* This function should be called after the object was assigned to a
|
||||
* specific task.
|
||||
*
|
||||
* Example: Can be used to get task execution frequency.
|
||||
* The task is created after initialize() and the object ctors have been
|
||||
* called so the execution frequency can't be cached in initialize()
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t initializeAfterTaskCreation() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_EXECUTABLEOBJECTIF_H_ */
|
||||
#ifndef FRAMEWORK_TASKS_EXECUTABLEOBJECTIF_H_
|
||||
#define FRAMEWORK_TASKS_EXECUTABLEOBJECTIF_H_
|
||||
|
||||
class PeriodicTaskIF;
|
||||
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
#include <cstring>
|
||||
/**
|
||||
* @brief The interface provides a method to execute objects within a task.
|
||||
* @details The performOperation method, that is required by the interface is
|
||||
* executed cyclically within a task context.
|
||||
* @author Bastian Baetz
|
||||
*/
|
||||
class ExecutableObjectIF {
|
||||
public:
|
||||
/**
|
||||
* @brief This is the empty virtual destructor as required for C++ interfaces.
|
||||
*/
|
||||
virtual ~ExecutableObjectIF() { }
|
||||
/**
|
||||
* @brief The performOperation method is executed in a task.
|
||||
* @details There are no restrictions for calls within this method, so any
|
||||
* other member of the class can be used.
|
||||
* @return Currently, the return value is ignored.
|
||||
*/
|
||||
virtual ReturnValue_t performOperation(uint8_t operationCode = 0) = 0;
|
||||
|
||||
/**
|
||||
* @brief Function called during setup assignment of object to task
|
||||
* @details
|
||||
* Has to be called from the function that assigns the object to a task and
|
||||
* enables the object implementation to overwrite this function and get
|
||||
* a reference to the executing task
|
||||
* @param task_ Pointer to the taskIF of this task
|
||||
*/
|
||||
virtual void setTaskIF(PeriodicTaskIF* task_) {};
|
||||
|
||||
/**
|
||||
* This function should be called after the object was assigned to a
|
||||
* specific task.
|
||||
*
|
||||
* Example: Can be used to get task execution frequency.
|
||||
* The task is created after initialize() and the object ctors have been
|
||||
* called so the execution frequency can't be cached in initialize()
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t initializeAfterTaskCreation() {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_EXECUTABLEOBJECTIF_H_ */
|
||||
|
@ -1,16 +1,16 @@
|
||||
#include <framework/objectmanager/SystemObjectIF.h>
|
||||
#include <framework/tasks/FixedSequenceSlot.h>
|
||||
#include <cstddef>
|
||||
|
||||
FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask) :
|
||||
pollingTimeMs(setTime), opcode(setSequenceId) {
|
||||
handler = objectManager->get<ExecutableObjectIF>(handlerId);
|
||||
if(executingTask != nullptr) {
|
||||
handler->setTaskIF(executingTask);
|
||||
}
|
||||
handler->initializeAfterTaskCreation();
|
||||
}
|
||||
|
||||
FixedSequenceSlot::~FixedSequenceSlot() {}
|
||||
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include "../tasks/FixedSequenceSlot.h"
|
||||
#include <cstddef>
|
||||
|
||||
FixedSequenceSlot::FixedSequenceSlot(object_id_t handlerId, uint32_t setTime,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask) :
|
||||
pollingTimeMs(setTime), opcode(setSequenceId) {
|
||||
handler = objectManager->get<ExecutableObjectIF>(handlerId);
|
||||
if(executingTask != nullptr) {
|
||||
handler->setTaskIF(executingTask);
|
||||
}
|
||||
handler->initializeAfterTaskCreation();
|
||||
}
|
||||
|
||||
FixedSequenceSlot::~FixedSequenceSlot() {}
|
||||
|
||||
|
@ -1,55 +1,55 @@
|
||||
#ifndef FRAMEWORK_TASKS_FIXEDSEQUENCESLOT_H_
|
||||
#define FRAMEWORK_TASKS_FIXEDSEQUENCESLOT_H_
|
||||
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/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
|
||||
* sequence table entry.
|
||||
* @author baetz
|
||||
*/
|
||||
class FixedSequenceSlot {
|
||||
public:
|
||||
FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask );
|
||||
virtual ~FixedSequenceSlot();
|
||||
|
||||
/**
|
||||
* @brief Handler identifies which device handler object is executed in this slot.
|
||||
*/
|
||||
ExecutableObjectIF* handler = 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.
|
||||
*/
|
||||
uint32_t pollingTimeMs;
|
||||
|
||||
/**
|
||||
* @brief This value defines the type of device communication.
|
||||
*
|
||||
* @details The state of this value decides what communication routine is
|
||||
* called in the PST executable or the device handler object.
|
||||
*/
|
||||
uint8_t opcode;
|
||||
|
||||
/**
|
||||
* @brief Operator overload for the comparison operator to
|
||||
* allow sorting by polling time.
|
||||
* @param fixedSequenceSlot
|
||||
* @return
|
||||
*/
|
||||
bool operator <(const FixedSequenceSlot & fixedSequenceSlot) const {
|
||||
return pollingTimeMs < fixedSequenceSlot.pollingTimeMs;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* 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
|
||||
* sequence table entry.
|
||||
* @author baetz
|
||||
*/
|
||||
class FixedSequenceSlot {
|
||||
public:
|
||||
FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs,
|
||||
int8_t setSequenceId, PeriodicTaskIF* executingTask );
|
||||
virtual ~FixedSequenceSlot();
|
||||
|
||||
/**
|
||||
* @brief Handler identifies which device handler object is executed in this slot.
|
||||
*/
|
||||
ExecutableObjectIF* handler = 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.
|
||||
*/
|
||||
uint32_t pollingTimeMs;
|
||||
|
||||
/**
|
||||
* @brief This value defines the type of device communication.
|
||||
*
|
||||
* @details The state of this value decides what communication routine is
|
||||
* called in the PST executable or the device handler object.
|
||||
*/
|
||||
uint8_t opcode;
|
||||
|
||||
/**
|
||||
* @brief Operator overload for the comparison operator to
|
||||
* allow sorting by polling time.
|
||||
* @param fixedSequenceSlot
|
||||
* @return
|
||||
*/
|
||||
bool operator <(const FixedSequenceSlot & fixedSequenceSlot) const {
|
||||
return pollingTimeMs < fixedSequenceSlot.pollingTimeMs;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FIXEDSEQUENCESLOT_H_ */
|
||||
|
@ -1,124 +1,124 @@
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <framework/tasks/FixedSlotSequence.h>
|
||||
#include <cstdlib>
|
||||
|
||||
FixedSlotSequence::FixedSlotSequence(uint32_t setLengthMs) :
|
||||
lengthMs(setLengthMs) {
|
||||
current = slotList.begin();
|
||||
}
|
||||
|
||||
FixedSlotSequence::~FixedSlotSequence() {
|
||||
// Call the destructor on each list entry.
|
||||
slotList.clear();
|
||||
}
|
||||
|
||||
void FixedSlotSequence::executeAndAdvance() {
|
||||
current->handler->performOperation(current->opcode);
|
||||
// if (returnValue != RETURN_OK) {
|
||||
// this->sendErrorMessage( returnValue );
|
||||
// }
|
||||
//Increment the polling Sequence iterator
|
||||
this->current++;
|
||||
//Set it to the beginning, if the list's end is reached.
|
||||
if (this->current == this->slotList.end()) {
|
||||
this->current = this->slotList.begin();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t FixedSlotSequence::getIntervalToNextSlotMs() {
|
||||
uint32_t oldTime;
|
||||
SlotListIter slotListIter = current;
|
||||
// Get the pollingTimeMs of the current slot object.
|
||||
oldTime = slotListIter->pollingTimeMs;
|
||||
// Advance to the next object.
|
||||
slotListIter++;
|
||||
// Find the next interval which is not 0.
|
||||
while (slotListIter != slotList.end()) {
|
||||
if (oldTime != slotListIter->pollingTimeMs) {
|
||||
return slotListIter->pollingTimeMs - oldTime;
|
||||
} else {
|
||||
slotListIter++;
|
||||
}
|
||||
}
|
||||
// If the list end is reached (this is definitely an interval != 0),
|
||||
// the interval is calculated by subtracting the remaining time of the PST
|
||||
// and adding the start time of the first handler in the list.
|
||||
slotListIter = slotList.begin();
|
||||
return lengthMs - oldTime + slotListIter->pollingTimeMs;
|
||||
}
|
||||
|
||||
uint32_t FixedSlotSequence::getIntervalToPreviousSlotMs() {
|
||||
uint32_t currentTime;
|
||||
SlotListIter slotListIter = current;
|
||||
// Get the pollingTimeMs of the current slot object.
|
||||
currentTime = slotListIter->pollingTimeMs;
|
||||
|
||||
//if it is the first slot, calculate difference to last slot
|
||||
if (slotListIter == slotList.begin()){
|
||||
return lengthMs - (--slotList.end())->pollingTimeMs + currentTime;
|
||||
}
|
||||
// get previous slot
|
||||
slotListIter--;
|
||||
|
||||
return currentTime - slotListIter->pollingTimeMs;
|
||||
}
|
||||
|
||||
bool FixedSlotSequence::slotFollowsImmediately() {
|
||||
uint32_t currentTime = current->pollingTimeMs;
|
||||
SlotListIter fixedSequenceIter = this->current;
|
||||
// Get the pollingTimeMs of the current slot object.
|
||||
if (fixedSequenceIter == slotList.begin())
|
||||
return false;
|
||||
fixedSequenceIter--;
|
||||
if (fixedSequenceIter->pollingTimeMs == currentTime) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t FixedSlotSequence::getLengthMs() const {
|
||||
return this->lengthMs;
|
||||
}
|
||||
|
||||
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;
|
||||
count++;
|
||||
} else if (slotIt->pollingTimeMs < time) {
|
||||
sif::error << "FixedSlotSequence::initialize: Time: "
|
||||
<< slotIt->pollingTimeMs
|
||||
<< " is smaller than previous with " << time << std::endl;
|
||||
count++;
|
||||
} else {
|
||||
// All ok, print slot.
|
||||
//info << "Current slot polling time: " << std::endl;
|
||||
//info << std::dec << slotIt->pollingTimeMs << std::endl;
|
||||
}
|
||||
time = slotIt->pollingTimeMs;
|
||||
slotIt++;
|
||||
}
|
||||
//info << "Number of elements in slot list: "
|
||||
// << slotList.size() << std::endl;
|
||||
if (count > 0) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
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();
|
||||
}
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../tasks/FixedSlotSequence.h"
|
||||
#include <cstdlib>
|
||||
|
||||
FixedSlotSequence::FixedSlotSequence(uint32_t setLengthMs) :
|
||||
lengthMs(setLengthMs) {
|
||||
current = slotList.begin();
|
||||
}
|
||||
|
||||
FixedSlotSequence::~FixedSlotSequence() {
|
||||
// Call the destructor on each list entry.
|
||||
slotList.clear();
|
||||
}
|
||||
|
||||
void FixedSlotSequence::executeAndAdvance() {
|
||||
current->handler->performOperation(current->opcode);
|
||||
// if (returnValue != RETURN_OK) {
|
||||
// this->sendErrorMessage( returnValue );
|
||||
// }
|
||||
//Increment the polling Sequence iterator
|
||||
this->current++;
|
||||
//Set it to the beginning, if the list's end is reached.
|
||||
if (this->current == this->slotList.end()) {
|
||||
this->current = this->slotList.begin();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t FixedSlotSequence::getIntervalToNextSlotMs() {
|
||||
uint32_t oldTime;
|
||||
SlotListIter slotListIter = current;
|
||||
// Get the pollingTimeMs of the current slot object.
|
||||
oldTime = slotListIter->pollingTimeMs;
|
||||
// Advance to the next object.
|
||||
slotListIter++;
|
||||
// Find the next interval which is not 0.
|
||||
while (slotListIter != slotList.end()) {
|
||||
if (oldTime != slotListIter->pollingTimeMs) {
|
||||
return slotListIter->pollingTimeMs - oldTime;
|
||||
} else {
|
||||
slotListIter++;
|
||||
}
|
||||
}
|
||||
// If the list end is reached (this is definitely an interval != 0),
|
||||
// the interval is calculated by subtracting the remaining time of the PST
|
||||
// and adding the start time of the first handler in the list.
|
||||
slotListIter = slotList.begin();
|
||||
return lengthMs - oldTime + slotListIter->pollingTimeMs;
|
||||
}
|
||||
|
||||
uint32_t FixedSlotSequence::getIntervalToPreviousSlotMs() {
|
||||
uint32_t currentTime;
|
||||
SlotListIter slotListIter = current;
|
||||
// Get the pollingTimeMs of the current slot object.
|
||||
currentTime = slotListIter->pollingTimeMs;
|
||||
|
||||
//if it is the first slot, calculate difference to last slot
|
||||
if (slotListIter == slotList.begin()){
|
||||
return lengthMs - (--slotList.end())->pollingTimeMs + currentTime;
|
||||
}
|
||||
// get previous slot
|
||||
slotListIter--;
|
||||
|
||||
return currentTime - slotListIter->pollingTimeMs;
|
||||
}
|
||||
|
||||
bool FixedSlotSequence::slotFollowsImmediately() {
|
||||
uint32_t currentTime = current->pollingTimeMs;
|
||||
SlotListIter fixedSequenceIter = this->current;
|
||||
// Get the pollingTimeMs of the current slot object.
|
||||
if (fixedSequenceIter == slotList.begin())
|
||||
return false;
|
||||
fixedSequenceIter--;
|
||||
if (fixedSequenceIter->pollingTimeMs == currentTime) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t FixedSlotSequence::getLengthMs() const {
|
||||
return this->lengthMs;
|
||||
}
|
||||
|
||||
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;
|
||||
count++;
|
||||
} else if (slotIt->pollingTimeMs < time) {
|
||||
sif::error << "FixedSlotSequence::initialize: Time: "
|
||||
<< slotIt->pollingTimeMs
|
||||
<< " is smaller than previous with " << time << std::endl;
|
||||
count++;
|
||||
} else {
|
||||
// All ok, print slot.
|
||||
//info << "Current slot polling time: " << std::endl;
|
||||
//info << std::dec << slotIt->pollingTimeMs << std::endl;
|
||||
}
|
||||
time = slotIt->pollingTimeMs;
|
||||
slotIt++;
|
||||
}
|
||||
//info << "Number of elements in slot list: "
|
||||
// << slotList.size() << std::endl;
|
||||
if (count > 0) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
@ -1,154 +1,154 @@
|
||||
#ifndef FRAMEWORK_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||
#define FRAMEWORK_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/tasks/FixedSequenceSlot.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.
|
||||
*
|
||||
* The main idea is to create a list of device handlers, to announce all
|
||||
* handlers to thepolling sequence and to maintain a list of
|
||||
* polling slot objects. This slot list represents the Polling Sequence Table
|
||||
* in software.
|
||||
*
|
||||
* Each polling slot contains information to indicate when and
|
||||
* which device handler shall be executed within a given polling period.
|
||||
* The sequence is then executed by iterating through this slot list.
|
||||
* Handlers are invoking by calling a certain function stored in the handler list.
|
||||
*/
|
||||
class FixedSlotSequence {
|
||||
public:
|
||||
using SlotList = std::multiset<FixedSequenceSlot>;
|
||||
using SlotListIter = std::multiset<FixedSequenceSlot>::iterator;
|
||||
|
||||
/**
|
||||
* @brief The constructor of the FixedSlotSequence object.
|
||||
*
|
||||
* @details The constructor takes two arguments, the period length and the init function.
|
||||
*
|
||||
* @param setLength The period length, expressed in ms.
|
||||
*/
|
||||
FixedSlotSequence(uint32_t setLengthMs);
|
||||
|
||||
/**
|
||||
* @brief The destructor of the FixedSlotSequence object.
|
||||
*
|
||||
* @details The destructor frees all allocated memory by iterating through the slotList
|
||||
* and deleting all allocated resources.
|
||||
*/
|
||||
virtual ~FixedSlotSequence();
|
||||
|
||||
/**
|
||||
* @brief This is a method to add an PollingSlot object to slotList.
|
||||
*
|
||||
* @details Here, a polling slot object is added to the slot list. It is appended
|
||||
* to the end of the list. The list is currently NOT reordered.
|
||||
* Afterwards, the iterator current is set to the beginning of the list.
|
||||
* @param Object ID of the object to add
|
||||
* @param setTime Value between (0 to 1) * slotLengthMs, when a FixedTimeslotTask
|
||||
* will be called inside the slot period.
|
||||
* @param setSequenceId ID which can be used to distinguish
|
||||
* different task operations
|
||||
* @param
|
||||
* @param
|
||||
*/
|
||||
void addSlot(object_id_t handlerId, uint32_t setTime, int8_t setSequenceId,
|
||||
PeriodicTaskIF* executingTask);
|
||||
|
||||
/**
|
||||
* Checks if the current slot shall be executed immediately after the one before.
|
||||
* This allows to distinguish between grouped and not grouped handlers.
|
||||
* @return - @c true if the slot has the same polling time as the previous
|
||||
* - @c false else
|
||||
*/
|
||||
bool slotFollowsImmediately();
|
||||
|
||||
/**
|
||||
* @brief This method returns the time until the next software
|
||||
* component is invoked.
|
||||
*
|
||||
* @details
|
||||
* This method is vitally important for the operation of the PST.
|
||||
* By fetching the polling time of the current slot and that of the
|
||||
* next one (or the first one, if the list end is reached)
|
||||
* it calculates and returns the interval in milliseconds within
|
||||
* which the handler execution shall take place.
|
||||
* If the next slot has the same time as the current one, it is ignored
|
||||
* until a slot with different time or the end of the PST is found.
|
||||
*/
|
||||
uint32_t getIntervalToNextSlotMs();
|
||||
|
||||
/**
|
||||
* @brief This method returns the time difference between the current
|
||||
* slot and the previous slot
|
||||
*
|
||||
* @details
|
||||
* This method is vitally important for the operation of the PST.
|
||||
* By fetching the polling time of the current slot and that of the previous
|
||||
* one (or the last one, if the slot is the first one) it calculates and
|
||||
* returns the interval in milliseconds that the handler execution shall
|
||||
* be delayed.
|
||||
*/
|
||||
uint32_t getIntervalToPreviousSlotMs();
|
||||
|
||||
/**
|
||||
* @brief This method returns the length of this FixedSlotSequence instance.
|
||||
*/
|
||||
uint32_t getLengthMs() const;
|
||||
|
||||
/**
|
||||
* @brief The method to execute the device handler entered in the current
|
||||
* PollingSlot object.
|
||||
*
|
||||
* @details
|
||||
* Within this method the device handler object to be executed is chosen by
|
||||
* looking up the handler address of the current slot in the handlerMap.
|
||||
* Either the device handler's talkToInterface or its listenToInterface
|
||||
* method is invoked, depending on the isTalking flag of the polling slot.
|
||||
* After execution the iterator current is increased or, by reaching the
|
||||
* end of slotList, reset to the beginning.
|
||||
*/
|
||||
void executeAndAdvance();
|
||||
|
||||
/**
|
||||
* @brief An iterator that indicates the current polling slot to execute.
|
||||
*
|
||||
* @details This is an iterator for slotList and always points to the
|
||||
* polling slot which is executed next.
|
||||
*/
|
||||
SlotListIter current;
|
||||
|
||||
/**
|
||||
* Iterate through slotList and check successful creation.
|
||||
* Checks if timing is ok (must be ascending) and if all handlers were found.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t checkSequence() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief This list contains all PollingSlot objects, defining order and
|
||||
* execution time of the device handler objects.
|
||||
*
|
||||
* @details
|
||||
* The slot list is a std:list object that contains all created
|
||||
* PollingSlot instances. They are NOT ordered automatically, so by
|
||||
* adding entries, the correct order needs to be ensured. By iterating
|
||||
* through this list the polling sequence is executed. Two entries with
|
||||
* identical polling times are executed immediately one after another.
|
||||
*/
|
||||
SlotList slotList;
|
||||
|
||||
uint32_t lengthMs;
|
||||
|
||||
bool isEmpty = false;
|
||||
};
|
||||
|
||||
#endif /* FIXEDSLOTSEQUENCE_H_ */
|
||||
#ifndef FRAMEWORK_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||
#define FRAMEWORK_TASKS_FIXEDSLOTSEQUENCE_H_
|
||||
|
||||
#include "../objectmanager/SystemObject.h"
|
||||
#include "../tasks/FixedSequenceSlot.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.
|
||||
*
|
||||
* The main idea is to create a list of device handlers, to announce all
|
||||
* handlers to thepolling sequence and to maintain a list of
|
||||
* polling slot objects. This slot list represents the Polling Sequence Table
|
||||
* in software.
|
||||
*
|
||||
* Each polling slot contains information to indicate when and
|
||||
* which device handler shall be executed within a given polling period.
|
||||
* The sequence is then executed by iterating through this slot list.
|
||||
* Handlers are invoking by calling a certain function stored in the handler list.
|
||||
*/
|
||||
class FixedSlotSequence {
|
||||
public:
|
||||
using SlotList = std::multiset<FixedSequenceSlot>;
|
||||
using SlotListIter = std::multiset<FixedSequenceSlot>::iterator;
|
||||
|
||||
/**
|
||||
* @brief The constructor of the FixedSlotSequence object.
|
||||
*
|
||||
* @details The constructor takes two arguments, the period length and the init function.
|
||||
*
|
||||
* @param setLength The period length, expressed in ms.
|
||||
*/
|
||||
FixedSlotSequence(uint32_t setLengthMs);
|
||||
|
||||
/**
|
||||
* @brief The destructor of the FixedSlotSequence object.
|
||||
*
|
||||
* @details The destructor frees all allocated memory by iterating through the slotList
|
||||
* and deleting all allocated resources.
|
||||
*/
|
||||
virtual ~FixedSlotSequence();
|
||||
|
||||
/**
|
||||
* @brief This is a method to add an PollingSlot object to slotList.
|
||||
*
|
||||
* @details Here, a polling slot object is added to the slot list. It is appended
|
||||
* to the end of the list. The list is currently NOT reordered.
|
||||
* Afterwards, the iterator current is set to the beginning of the list.
|
||||
* @param Object ID of the object to add
|
||||
* @param setTime Value between (0 to 1) * slotLengthMs, when a FixedTimeslotTask
|
||||
* will be called inside the slot period.
|
||||
* @param setSequenceId ID which can be used to distinguish
|
||||
* different task operations
|
||||
* @param
|
||||
* @param
|
||||
*/
|
||||
void addSlot(object_id_t handlerId, uint32_t setTime, int8_t setSequenceId,
|
||||
PeriodicTaskIF* executingTask);
|
||||
|
||||
/**
|
||||
* Checks if the current slot shall be executed immediately after the one before.
|
||||
* This allows to distinguish between grouped and not grouped handlers.
|
||||
* @return - @c true if the slot has the same polling time as the previous
|
||||
* - @c false else
|
||||
*/
|
||||
bool slotFollowsImmediately();
|
||||
|
||||
/**
|
||||
* @brief This method returns the time until the next software
|
||||
* component is invoked.
|
||||
*
|
||||
* @details
|
||||
* This method is vitally important for the operation of the PST.
|
||||
* By fetching the polling time of the current slot and that of the
|
||||
* next one (or the first one, if the list end is reached)
|
||||
* it calculates and returns the interval in milliseconds within
|
||||
* which the handler execution shall take place.
|
||||
* If the next slot has the same time as the current one, it is ignored
|
||||
* until a slot with different time or the end of the PST is found.
|
||||
*/
|
||||
uint32_t getIntervalToNextSlotMs();
|
||||
|
||||
/**
|
||||
* @brief This method returns the time difference between the current
|
||||
* slot and the previous slot
|
||||
*
|
||||
* @details
|
||||
* This method is vitally important for the operation of the PST.
|
||||
* By fetching the polling time of the current slot and that of the previous
|
||||
* one (or the last one, if the slot is the first one) it calculates and
|
||||
* returns the interval in milliseconds that the handler execution shall
|
||||
* be delayed.
|
||||
*/
|
||||
uint32_t getIntervalToPreviousSlotMs();
|
||||
|
||||
/**
|
||||
* @brief This method returns the length of this FixedSlotSequence instance.
|
||||
*/
|
||||
uint32_t getLengthMs() const;
|
||||
|
||||
/**
|
||||
* @brief The method to execute the device handler entered in the current
|
||||
* PollingSlot object.
|
||||
*
|
||||
* @details
|
||||
* Within this method the device handler object to be executed is chosen by
|
||||
* looking up the handler address of the current slot in the handlerMap.
|
||||
* Either the device handler's talkToInterface or its listenToInterface
|
||||
* method is invoked, depending on the isTalking flag of the polling slot.
|
||||
* After execution the iterator current is increased or, by reaching the
|
||||
* end of slotList, reset to the beginning.
|
||||
*/
|
||||
void executeAndAdvance();
|
||||
|
||||
/**
|
||||
* @brief An iterator that indicates the current polling slot to execute.
|
||||
*
|
||||
* @details This is an iterator for slotList and always points to the
|
||||
* polling slot which is executed next.
|
||||
*/
|
||||
SlotListIter current;
|
||||
|
||||
/**
|
||||
* Iterate through slotList and check successful creation.
|
||||
* Checks if timing is ok (must be ascending) and if all handlers were found.
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t checkSequence() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief This list contains all PollingSlot objects, defining order and
|
||||
* execution time of the device handler objects.
|
||||
*
|
||||
* @details
|
||||
* The slot list is a std:list object that contains all created
|
||||
* PollingSlot instances. They are NOT ordered automatically, so by
|
||||
* adding entries, the correct order needs to be ensured. By iterating
|
||||
* through this list the polling sequence is executed. Two entries with
|
||||
* identical polling times are executed immediately one after another.
|
||||
*/
|
||||
SlotList slotList;
|
||||
|
||||
uint32_t lengthMs;
|
||||
|
||||
bool isEmpty = false;
|
||||
};
|
||||
|
||||
#endif /* FIXEDSLOTSEQUENCE_H_ */
|
||||
|
@ -1,29 +1,29 @@
|
||||
#ifndef FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_
|
||||
#define FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_
|
||||
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
#include <framework/tasks/PeriodicTaskIF.h>
|
||||
|
||||
/**
|
||||
* @brief Following the same principle as the base class IF.
|
||||
* This is the interface for a Fixed timeslot task
|
||||
*/
|
||||
class FixedTimeslotTaskIF : public PeriodicTaskIF {
|
||||
public:
|
||||
virtual ~FixedTimeslotTaskIF() {}
|
||||
|
||||
/**
|
||||
* Add an object with a slot time and the execution step to the task.
|
||||
* The execution step shall be passed to the object.
|
||||
* @param componentId
|
||||
* @param slotTimeMs
|
||||
* @param executionStep
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) = 0;
|
||||
/** Check whether the sequence is valid */
|
||||
virtual ReturnValue_t checkSequence() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_ */
|
||||
#ifndef FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_
|
||||
#define FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_
|
||||
|
||||
#include "../objectmanager/ObjectManagerIF.h"
|
||||
#include "../tasks/PeriodicTaskIF.h"
|
||||
|
||||
/**
|
||||
* @brief Following the same principle as the base class IF.
|
||||
* This is the interface for a Fixed timeslot task
|
||||
*/
|
||||
class FixedTimeslotTaskIF : public PeriodicTaskIF {
|
||||
public:
|
||||
virtual ~FixedTimeslotTaskIF() {}
|
||||
|
||||
/**
|
||||
* Add an object with a slot time and the execution step to the task.
|
||||
* The execution step shall be passed to the object.
|
||||
* @param componentId
|
||||
* @param slotTimeMs
|
||||
* @param executionStep
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) = 0;
|
||||
/** Check whether the sequence is valid */
|
||||
virtual ReturnValue_t checkSequence() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_FIXEDTIMESLOTTASKIF_H_ */
|
||||
|
@ -1,49 +1,49 @@
|
||||
#ifndef FRAMEWORK_TASK_PERIODICTASKIF_H_
|
||||
#define FRAMEWORK_TASK_PERIODICTASKIF_H_
|
||||
|
||||
#include <framework/objectmanager/SystemObjectIF.h>
|
||||
#include <framework/timemanager/Clock.h>
|
||||
#include <cstddef>
|
||||
class ExecutableObjectIF;
|
||||
|
||||
/**
|
||||
* New version of TaskIF
|
||||
* Follows RAII principles, i.e. there's no create or delete method.
|
||||
* Minimalistic.
|
||||
*/
|
||||
class PeriodicTaskIF {
|
||||
public:
|
||||
static const size_t MINIMUM_STACK_SIZE;
|
||||
/**
|
||||
* @brief A virtual destructor as it is mandatory for interfaces.
|
||||
*/
|
||||
virtual ~PeriodicTaskIF() { }
|
||||
/**
|
||||
* @brief With the startTask method, a created task can be started
|
||||
* for the first time.
|
||||
*/
|
||||
virtual ReturnValue_t startTask() = 0;
|
||||
|
||||
/**
|
||||
* Add a component (object) to a periodic task. The pointer to the
|
||||
* task can be set optionally
|
||||
* @param object
|
||||
* Add an object to the task. The most important case is to add an
|
||||
* executable object with a function which will be called regularly
|
||||
* (see ExecutableObjectIF)
|
||||
* @param setTaskIF
|
||||
* Can be used to specify whether the task object pointer is passed
|
||||
* to the component.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t addComponent(object_id_t object) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
|
||||
virtual ReturnValue_t sleepFor(uint32_t ms) = 0;
|
||||
|
||||
virtual uint32_t getPeriodMs() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* PERIODICTASKIF_H_ */
|
||||
#ifndef FRAMEWORK_TASK_PERIODICTASKIF_H_
|
||||
#define FRAMEWORK_TASK_PERIODICTASKIF_H_
|
||||
|
||||
#include "../objectmanager/SystemObjectIF.h"
|
||||
#include "../timemanager/Clock.h"
|
||||
#include <cstddef>
|
||||
class ExecutableObjectIF;
|
||||
|
||||
/**
|
||||
* New version of TaskIF
|
||||
* Follows RAII principles, i.e. there's no create or delete method.
|
||||
* Minimalistic.
|
||||
*/
|
||||
class PeriodicTaskIF {
|
||||
public:
|
||||
static const size_t MINIMUM_STACK_SIZE;
|
||||
/**
|
||||
* @brief A virtual destructor as it is mandatory for interfaces.
|
||||
*/
|
||||
virtual ~PeriodicTaskIF() { }
|
||||
/**
|
||||
* @brief With the startTask method, a created task can be started
|
||||
* for the first time.
|
||||
*/
|
||||
virtual ReturnValue_t startTask() = 0;
|
||||
|
||||
/**
|
||||
* Add a component (object) to a periodic task. The pointer to the
|
||||
* task can be set optionally
|
||||
* @param object
|
||||
* Add an object to the task. The most important case is to add an
|
||||
* executable object with a function which will be called regularly
|
||||
* (see ExecutableObjectIF)
|
||||
* @param setTaskIF
|
||||
* Can be used to specify whether the task object pointer is passed
|
||||
* to the component.
|
||||
* @return
|
||||
*/
|
||||
virtual ReturnValue_t addComponent(object_id_t object) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
};
|
||||
|
||||
virtual ReturnValue_t sleepFor(uint32_t ms) = 0;
|
||||
|
||||
virtual uint32_t getPeriodMs() const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* PERIODICTASKIF_H_ */
|
||||
|
@ -1,49 +1,49 @@
|
||||
#ifndef FRAMEWORK_TASKS_SEMAPHOREFACTORY_H_
|
||||
#define FRAMEWORK_TASKS_SEMAPHOREFACTORY_H_
|
||||
#include <framework/tasks/SemaphoreIF.h>
|
||||
|
||||
/**
|
||||
* Creates Semaphore.
|
||||
* This class is a "singleton" interface, i.e. it provides an
|
||||
* interface, but also is the base class for a singleton.
|
||||
*/
|
||||
class SemaphoreFactory {
|
||||
public:
|
||||
virtual ~SemaphoreFactory();
|
||||
/**
|
||||
* Returns the single instance of SemaphoreFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static SemaphoreFactory* instance();
|
||||
|
||||
/**
|
||||
* Create a binary semaphore.
|
||||
* Creator function for a binary semaphore which may only be acquired once
|
||||
* @param argument Can be used to pass implementation specific information.
|
||||
* @return Pointer to newly created semaphore class instance.
|
||||
*/
|
||||
SemaphoreIF* createBinarySemaphore(uint32_t arguments = 0);
|
||||
/**
|
||||
* Create a counting semaphore.
|
||||
* Creator functons for a counting semaphore which may be acquired multiple
|
||||
* times.
|
||||
* @param count Semaphore can be taken count times.
|
||||
* @param initCount Initial count value.
|
||||
* @param argument Can be used to pass implementation specific information.
|
||||
* @return
|
||||
*/
|
||||
SemaphoreIF* createCountingSemaphore(const uint8_t maxCount,
|
||||
uint8_t initCount, uint32_t arguments = 0);
|
||||
|
||||
void deleteSemaphore(SemaphoreIF* semaphore);
|
||||
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
SemaphoreFactory();
|
||||
static SemaphoreFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_SEMAPHOREFACTORY_H_ */
|
||||
#ifndef FRAMEWORK_TASKS_SEMAPHOREFACTORY_H_
|
||||
#define FRAMEWORK_TASKS_SEMAPHOREFACTORY_H_
|
||||
#include "../tasks/SemaphoreIF.h"
|
||||
|
||||
/**
|
||||
* Creates Semaphore.
|
||||
* This class is a "singleton" interface, i.e. it provides an
|
||||
* interface, but also is the base class for a singleton.
|
||||
*/
|
||||
class SemaphoreFactory {
|
||||
public:
|
||||
virtual ~SemaphoreFactory();
|
||||
/**
|
||||
* Returns the single instance of SemaphoreFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static SemaphoreFactory* instance();
|
||||
|
||||
/**
|
||||
* Create a binary semaphore.
|
||||
* Creator function for a binary semaphore which may only be acquired once
|
||||
* @param argument Can be used to pass implementation specific information.
|
||||
* @return Pointer to newly created semaphore class instance.
|
||||
*/
|
||||
SemaphoreIF* createBinarySemaphore(uint32_t arguments = 0);
|
||||
/**
|
||||
* Create a counting semaphore.
|
||||
* Creator functons for a counting semaphore which may be acquired multiple
|
||||
* times.
|
||||
* @param count Semaphore can be taken count times.
|
||||
* @param initCount Initial count value.
|
||||
* @param argument Can be used to pass implementation specific information.
|
||||
* @return
|
||||
*/
|
||||
SemaphoreIF* createCountingSemaphore(const uint8_t maxCount,
|
||||
uint8_t initCount, uint32_t arguments = 0);
|
||||
|
||||
void deleteSemaphore(SemaphoreIF* semaphore);
|
||||
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
SemaphoreFactory();
|
||||
static SemaphoreFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_SEMAPHOREFACTORY_H_ */
|
||||
|
@ -1,72 +1,72 @@
|
||||
#ifndef FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||
#define FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||
#include <framework/returnvalues/FwClassIds.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Generic interface for semaphores, which can be used to achieve
|
||||
* task synchronization. This is a generic interface which can be
|
||||
* used for both binary semaphores and counting semaphores.
|
||||
* @details
|
||||
* A semaphore is a synchronization primitive.
|
||||
* See: https://en.wikipedia.org/wiki/Semaphore_(programming)
|
||||
* A semaphore can be used to achieve task synchonization and track the
|
||||
* availability of resources by using either the binary or the counting
|
||||
* semaphore types.
|
||||
*
|
||||
* If mutual exlcusion of a resource is desired, a mutex should be used,
|
||||
* which is a special form of a semaphore and has an own interface.
|
||||
*/
|
||||
class SemaphoreIF {
|
||||
public:
|
||||
virtual~ SemaphoreIF() {};
|
||||
/**
|
||||
* @brief Timeout value used for polling lock attempt.
|
||||
* @details
|
||||
* If the lock is not successfull, MUTEX_TIMEOUT will be returned
|
||||
* immediately. Value needs to be defined in implementation.
|
||||
*/
|
||||
static const uint32_t POLLING;
|
||||
/**
|
||||
* @brief Timeout value used for permanent blocking lock attempt.
|
||||
* @details
|
||||
* The task will be blocked (indefinitely) until the mutex is unlocked.
|
||||
* Value needs to be defined in implementation.
|
||||
*/
|
||||
static const uint32_t BLOCKING;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||
//! Semaphore timeout
|
||||
static constexpr ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(1);
|
||||
//! The current semaphore can not be given, because it is not owned
|
||||
static constexpr ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(2);
|
||||
static constexpr ReturnValue_t SEMAPHORE_INVALID = MAKE_RETURN_CODE(3);
|
||||
|
||||
/**
|
||||
* Generic call to acquire a semaphore.
|
||||
* If there are no more semaphores to be taken (for a counting semaphore,
|
||||
* a semaphore may be taken more than once), the taks will block
|
||||
* for a maximum of timeoutMs while trying to acquire the semaphore.
|
||||
* This can be used to achieve task synchrnization.
|
||||
* @param timeoutMs
|
||||
* @return - c RETURN_OK for successfull acquisition
|
||||
*/
|
||||
virtual ReturnValue_t acquire(uint32_t timeoutMs) = 0;
|
||||
|
||||
/**
|
||||
* Corrensponding call to release a semaphore.
|
||||
* @return -@c RETURN_OK for successfull release
|
||||
*/
|
||||
virtual ReturnValue_t release() = 0;
|
||||
|
||||
/**
|
||||
* If the semaphore is a counting semaphore then the semaphores current
|
||||
* count value is returned. If the semaphore is a binary semaphore then 1
|
||||
* is returned if the semaphore is available, and 0 is returned if the
|
||||
* semaphore is not available.
|
||||
*/
|
||||
virtual uint8_t getSemaphoreCounter() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_SEMAPHOREIF_H_ */
|
||||
#ifndef FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||
#define FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||
#include "../returnvalues/FwClassIds.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Generic interface for semaphores, which can be used to achieve
|
||||
* task synchronization. This is a generic interface which can be
|
||||
* used for both binary semaphores and counting semaphores.
|
||||
* @details
|
||||
* A semaphore is a synchronization primitive.
|
||||
* See: https://en.wikipedia.org/wiki/Semaphore_(programming)
|
||||
* A semaphore can be used to achieve task synchonization and track the
|
||||
* availability of resources by using either the binary or the counting
|
||||
* semaphore types.
|
||||
*
|
||||
* If mutual exlcusion of a resource is desired, a mutex should be used,
|
||||
* which is a special form of a semaphore and has an own interface.
|
||||
*/
|
||||
class SemaphoreIF {
|
||||
public:
|
||||
virtual~ SemaphoreIF() {};
|
||||
/**
|
||||
* @brief Timeout value used for polling lock attempt.
|
||||
* @details
|
||||
* If the lock is not successfull, MUTEX_TIMEOUT will be returned
|
||||
* immediately. Value needs to be defined in implementation.
|
||||
*/
|
||||
static const uint32_t POLLING;
|
||||
/**
|
||||
* @brief Timeout value used for permanent blocking lock attempt.
|
||||
* @details
|
||||
* The task will be blocked (indefinitely) until the mutex is unlocked.
|
||||
* Value needs to be defined in implementation.
|
||||
*/
|
||||
static const uint32_t BLOCKING;
|
||||
|
||||
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||
//! Semaphore timeout
|
||||
static constexpr ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(1);
|
||||
//! The current semaphore can not be given, because it is not owned
|
||||
static constexpr ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(2);
|
||||
static constexpr ReturnValue_t SEMAPHORE_INVALID = MAKE_RETURN_CODE(3);
|
||||
|
||||
/**
|
||||
* Generic call to acquire a semaphore.
|
||||
* If there are no more semaphores to be taken (for a counting semaphore,
|
||||
* a semaphore may be taken more than once), the taks will block
|
||||
* for a maximum of timeoutMs while trying to acquire the semaphore.
|
||||
* This can be used to achieve task synchrnization.
|
||||
* @param timeoutMs
|
||||
* @return - c RETURN_OK for successfull acquisition
|
||||
*/
|
||||
virtual ReturnValue_t acquire(uint32_t timeoutMs) = 0;
|
||||
|
||||
/**
|
||||
* Corrensponding call to release a semaphore.
|
||||
* @return -@c RETURN_OK for successfull release
|
||||
*/
|
||||
virtual ReturnValue_t release() = 0;
|
||||
|
||||
/**
|
||||
* If the semaphore is a counting semaphore then the semaphores current
|
||||
* count value is returned. If the semaphore is a binary semaphore then 1
|
||||
* is returned if the semaphore is available, and 0 is returned if the
|
||||
* semaphore is not available.
|
||||
*/
|
||||
virtual uint8_t getSemaphoreCounter() const = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_SEMAPHOREIF_H_ */
|
||||
|
@ -1,73 +1,73 @@
|
||||
#ifndef FRAMEWORK_TASKS_TASKFACTORY_H_
|
||||
#define FRAMEWORK_TASKS_TASKFACTORY_H_
|
||||
|
||||
#include <cstdlib>
|
||||
#include <framework/tasks/FixedTimeslotTaskIF.h>
|
||||
#include <framework/tasks/Typedef.h>
|
||||
|
||||
/**
|
||||
* Singleton Class that produces Tasks.
|
||||
*/
|
||||
class TaskFactory {
|
||||
public:
|
||||
virtual ~TaskFactory();
|
||||
/**
|
||||
* Returns the single instance of TaskFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static TaskFactory* instance();
|
||||
|
||||
/**
|
||||
* Generic interface to create a periodic task
|
||||
* @param name_ Name of the task
|
||||
* @param taskPriority_ Priority of the task
|
||||
* @param stackSize_ Stack size if the task
|
||||
* @param periodInSeconds_ Period in seconds
|
||||
* @param deadLineMissedFunction_ This function is called if a deadline was
|
||||
* missed
|
||||
* @return Pointer to the created periodic task class
|
||||
*/
|
||||
PeriodicTaskIF* createPeriodicTask(TaskName name_,
|
||||
TaskPriority taskPriority_, TaskStackSize stackSize_,
|
||||
TaskPeriod periodInSeconds_,
|
||||
TaskDeadlineMissedFunction deadLineMissedFunction_);
|
||||
|
||||
/**
|
||||
* Generic interface to create a fixed timeslot task
|
||||
* @param name_ Name of the task
|
||||
* @param taskPriority_ Priority of the task
|
||||
* @param stackSize_ Stack size if the task
|
||||
* @param periodInSeconds_ Period in seconds
|
||||
* @param deadLineMissedFunction_ This function is called if a deadline was
|
||||
* missed
|
||||
* @return Pointer to the created periodic task class
|
||||
*/
|
||||
FixedTimeslotTaskIF* createFixedTimeslotTask(TaskName name_,
|
||||
TaskPriority taskPriority_, TaskStackSize stackSize_,
|
||||
TaskPeriod periodInSeconds_,
|
||||
TaskDeadlineMissedFunction deadLineMissedFunction_);
|
||||
|
||||
/**
|
||||
* Function to be called to delete a task
|
||||
* @param task The pointer to the task that shall be deleted,
|
||||
* NULL specifies current Task
|
||||
* @return Success of deletion
|
||||
*/
|
||||
static ReturnValue_t deleteTask(PeriodicTaskIF* task = NULL);
|
||||
|
||||
/**
|
||||
* Function to be called to delay current task
|
||||
* @param delay The delay in milliseconds
|
||||
* @return Success of deletion
|
||||
*/
|
||||
static ReturnValue_t delayTask(uint32_t delayMs);
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
TaskFactory();
|
||||
static TaskFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_TASKFACTORY_H_ */
|
||||
#ifndef FRAMEWORK_TASKS_TASKFACTORY_H_
|
||||
#define FRAMEWORK_TASKS_TASKFACTORY_H_
|
||||
|
||||
#include <cstdlib>
|
||||
#include "../tasks/FixedTimeslotTaskIF.h"
|
||||
#include "../tasks/Typedef.h"
|
||||
|
||||
/**
|
||||
* Singleton Class that produces Tasks.
|
||||
*/
|
||||
class TaskFactory {
|
||||
public:
|
||||
virtual ~TaskFactory();
|
||||
/**
|
||||
* Returns the single instance of TaskFactory.
|
||||
* The implementation of #instance is found in its subclasses.
|
||||
* Thus, we choose link-time variability of the instance.
|
||||
*/
|
||||
static TaskFactory* instance();
|
||||
|
||||
/**
|
||||
* Generic interface to create a periodic task
|
||||
* @param name_ Name of the task
|
||||
* @param taskPriority_ Priority of the task
|
||||
* @param stackSize_ Stack size if the task
|
||||
* @param periodInSeconds_ Period in seconds
|
||||
* @param deadLineMissedFunction_ This function is called if a deadline was
|
||||
* missed
|
||||
* @return Pointer to the created periodic task class
|
||||
*/
|
||||
PeriodicTaskIF* createPeriodicTask(TaskName name_,
|
||||
TaskPriority taskPriority_, TaskStackSize stackSize_,
|
||||
TaskPeriod periodInSeconds_,
|
||||
TaskDeadlineMissedFunction deadLineMissedFunction_);
|
||||
|
||||
/**
|
||||
* Generic interface to create a fixed timeslot task
|
||||
* @param name_ Name of the task
|
||||
* @param taskPriority_ Priority of the task
|
||||
* @param stackSize_ Stack size if the task
|
||||
* @param periodInSeconds_ Period in seconds
|
||||
* @param deadLineMissedFunction_ This function is called if a deadline was
|
||||
* missed
|
||||
* @return Pointer to the created periodic task class
|
||||
*/
|
||||
FixedTimeslotTaskIF* createFixedTimeslotTask(TaskName name_,
|
||||
TaskPriority taskPriority_, TaskStackSize stackSize_,
|
||||
TaskPeriod periodInSeconds_,
|
||||
TaskDeadlineMissedFunction deadLineMissedFunction_);
|
||||
|
||||
/**
|
||||
* Function to be called to delete a task
|
||||
* @param task The pointer to the task that shall be deleted,
|
||||
* NULL specifies current Task
|
||||
* @return Success of deletion
|
||||
*/
|
||||
static ReturnValue_t deleteTask(PeriodicTaskIF* task = NULL);
|
||||
|
||||
/**
|
||||
* Function to be called to delay current task
|
||||
* @param delay The delay in milliseconds
|
||||
* @return Success of deletion
|
||||
*/
|
||||
static ReturnValue_t delayTask(uint32_t delayMs);
|
||||
private:
|
||||
/**
|
||||
* External instantiation is not allowed.
|
||||
*/
|
||||
TaskFactory();
|
||||
static TaskFactory* factoryInstance;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_TASKS_TASKFACTORY_H_ */
|
||||
|
Reference in New Issue
Block a user