moved timeslot files to task folder

implmented setting task IF for regular periodic tasks
This commit is contained in:
Robin Müller 2020-06-19 20:14:56 +02:00
parent eb4ce980fe
commit 2de811e0af
13 changed files with 82 additions and 58 deletions

View File

@ -62,11 +62,6 @@ ReturnValue_t FixedTimeslotTask::startTask() {
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
uint32_t slotTimeMs, int8_t executionStep) {
if (objectManager->get<ExecutableObjectIF>(componentId) != nullptr) {
if(slotTimeMs == 0) {
// FreeRTOS throws a sanity error for zero values, so we set
// the time to one millisecond.
slotTimeMs = 1;
}
pst.addSlot(componentId, slotTimeMs, executionStep, this);
return HasReturnvaluesIF::RETURN_OK;
}
@ -101,7 +96,9 @@ void FixedTimeslotTask::taskFunctionality() {
xLastWakeTime = xTaskGetTickCount();
// wait for first entry's start time
vTaskDelayUntil(&xLastWakeTime, interval);
if(interval > 0) {
vTaskDelayUntil(&xLastWakeTime, interval);
}
/* Enter the loop that defines the task behavior. */
for (;;) {
@ -137,3 +134,4 @@ ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms) {
vTaskDelay(pdMS_TO_TICKS(ms));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,7 +1,7 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
#define FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
#include <framework/devicehandlers/FixedSlotSequence.h>
#include <framework/tasks/FixedSlotSequence.h>
#include <framework/tasks/FixedTimeslotTaskIF.h>
#include <framework/tasks/Typedef.h>
@ -49,13 +49,13 @@ public:
static uint32_t deadlineMissedCount;
ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs,
int8_t executionStep);
int8_t executionStep) override;
uint32_t getPeriodMs() const;
uint32_t getPeriodMs() const override;
ReturnValue_t checkSequence() const;
ReturnValue_t checkSequence() const override;
ReturnValue_t sleepFor(uint32_t ms);
ReturnValue_t sleepFor(uint32_t ms) override;
protected:
bool started;

View File

@ -70,9 +70,8 @@ void PeriodicTask::taskFunctionality() {
xLastWakeTime = xTaskGetTickCount();
/* Enter the loop that defines the task behavior. */
for (;;) {
for (ObjectList::iterator it = objectList.begin();
it != objectList.end(); ++it) {
(*it)->performOperation();
for (auto const& object: objectList) {
object->performOperation();
}
/* If all operations are finished and the difference of the
@ -93,12 +92,17 @@ void PeriodicTask::taskFunctionality() {
}
}
ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
ReturnValue_t PeriodicTask::addComponent(object_id_t object, bool setTaskIF) {
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(
object);
if (newObject == NULL) {
if (newObject == nullptr) {
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
"it implement ExecutableObjectIF" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
if(setTaskIF) {
newObject->setTaskIF(this);
}
objectList.push_back(newObject);
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -54,7 +54,7 @@ public:
* The address of the task object is passed as an argument
* to the system call.
*/
ReturnValue_t startTask(void);
ReturnValue_t startTask() override;
/**
* Adds an object to the list of objects to be executed.
* The objects are executed in the order added.
@ -63,11 +63,12 @@ public:
* -@c RETURN_OK on success
* -@c RETURN_FAILED if the object could not be added.
*/
ReturnValue_t addComponent(object_id_t object);
ReturnValue_t addComponent(object_id_t object,
bool setTaskIF = true) override;
uint32_t getPeriodMs() const;
uint32_t getPeriodMs() const override;
ReturnValue_t sleepFor(uint32_t ms);
ReturnValue_t sleepFor(uint32_t ms) override;
protected:
bool started;
TaskHandle_t handle;

View File

@ -2,7 +2,7 @@
#define FRAMEWORK_OSAL_HOST_FIXEDTIMESLOTTASK_H_
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/devicehandlers/FixedSlotSequence.h>
#include <framework/tasks/FixedSlotSequence.h>
#include <framework/tasks/FixedTimeslotTaskIF.h>
#include <framework/tasks/Typedef.h>

View File

@ -24,9 +24,14 @@ void* PeriodicPosixTask::taskEntryPoint(void* arg) {
ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) {
ExecutableObjectIF* newObject = objectManager->get<ExecutableObjectIF>(
object);
if (newObject == NULL) {
if (newObject == nullptr) {
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
"it implements ExecutableObjectIF" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
if(setTaskIF) {
newObject->setTaskIF(this);
}
objectList.push_back(newObject);
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -39,7 +39,8 @@ public:
* @param object Id of the object to add.
* @return RETURN_OK on success, RETURN_FAILED if the object could not be added.
*/
ReturnValue_t addComponent(object_id_t object);
ReturnValue_t addComponent(object_id_t object,
bool setTaskIF = true) override;
uint32_t getPeriodMs() const;

View File

@ -1,19 +1,14 @@
/**
* @file PollingSlot.cpp
* @brief This file defines the PollingSlot class.
* @date 19.12.2012
* @author baetz
*/
#include <framework/devicehandlers/FixedSequenceSlot.h>
#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) :
handler(NULL), pollingTimeMs(setTime), opcode(setSequenceId) {
pollingTimeMs(setTime), opcode(setSequenceId) {
handler = objectManager->get<ExecutableObjectIF>(handlerId);
handler->setTaskIF(executingTask);
if(executingTask != nullptr) {
handler->setTaskIF(executingTask);
}
}
FixedSequenceSlot::~FixedSequenceSlot() {}

View File

@ -1,22 +1,17 @@
/**
* @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 <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.
* @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:
@ -27,7 +22,7 @@ public:
/**
* @brief Handler identifies which device handler object is executed in this slot.
*/
ExecutableObjectIF* handler;
ExecutableObjectIF* handler = nullptr;
/**
* @brief This attribute defines when a device handler object is executed.
@ -43,7 +38,7 @@ public:
* @details The state of this value decides what communication routine is
* called in the PST executable or the device handler object.
*/
uint8_t opcode;
uint8_t opcode;
/**
* @brief Operator overload for the comparison operator to

View File

@ -1,5 +1,5 @@
#include <framework/devicehandlers/FixedSlotSequence.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/tasks/FixedSlotSequence.h>
#include <cstdlib>
FixedSlotSequence::FixedSlotSequence(uint32_t setLengthMs) :

View File

@ -1,8 +1,8 @@
#ifndef FIXEDSLOTSEQUENCE_H_
#define FIXEDSLOTSEQUENCE_H_
#ifndef FRAMEWORK_TASKS_FIXEDSLOTSEQUENCE_H_
#define FRAMEWORK_TASKS_FIXEDSLOTSEQUENCE_H_
#include <framework/devicehandlers/FixedSequenceSlot.h>
#include <framework/objectmanager/SystemObject.h>
#include <framework/tasks/FixedSequenceSlot.h>
#include <set>

View File

@ -12,11 +12,18 @@ 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_ */

View File

@ -1,9 +1,11 @@
#ifndef PERIODICTASKIF_H_
#define PERIODICTASKIF_H_
#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.
@ -17,11 +19,27 @@ public:
*/
virtual ~PeriodicTaskIF() { }
/**
* @brief With the startTask method, a created task can be started for the first time.
* @brief With the startTask method, a created task can be started
* for the first time.
*/
virtual ReturnValue_t startTask() = 0;
virtual ReturnValue_t addComponent(object_id_t object) {return HasReturnvaluesIF::RETURN_FAILED;};
/**
* 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,
bool setTaskIF = true) {
return HasReturnvaluesIF::RETURN_FAILED;
};
virtual ReturnValue_t sleepFor(uint32_t ms) = 0;