2018-07-13 15:56:37 +02:00
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
#include "FixedTimeslotTask.h"
|
|
|
|
|
|
|
|
uint32_t FixedTimeslotTask::deadlineMissedCount = 0;
|
2019-08-28 14:50:24 +02:00
|
|
|
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = configMINIMAL_STACK_SIZE;
|
2018-07-13 15:56:37 +02:00
|
|
|
|
|
|
|
FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority,
|
|
|
|
TaskStackSize setStack, TaskPeriod overallPeriod,
|
|
|
|
void (*setDeadlineMissedFunc)()) :
|
|
|
|
started(false), handle(NULL), pst(overallPeriod * 1000) {
|
|
|
|
xTaskCreate(taskEntryPoint, name, setStack, this, setPriority, &handle);
|
|
|
|
// All additional attributes are applied to the object.
|
|
|
|
this->deadlineMissedFunc = setDeadlineMissedFunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
FixedTimeslotTask::~FixedTimeslotTask() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void FixedTimeslotTask::taskEntryPoint(void* argument) {
|
|
|
|
|
|
|
|
//The argument is re-interpreted as FixedTimeslotTask. The Task object is global, so it is found from any place.
|
2020-01-20 22:03:13 +01:00
|
|
|
FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
|
2018-07-13 15:56:37 +02:00
|
|
|
// Task should not start until explicitly requested
|
|
|
|
// in FreeRTOS, tasks start as soon as they are created if the scheduler is running
|
|
|
|
// but not if the scheduler is not running.
|
|
|
|
// to be able to accommodate both cases we check a member which is set in #startTask()
|
|
|
|
// if it is not set and we get here, the scheduler was started before #startTask() was called and we need to suspend
|
|
|
|
// if it is set, the scheduler was not running before #startTask() was called and we can continue
|
|
|
|
|
|
|
|
if (!originalTask->started) {
|
|
|
|
vTaskSuspend(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
originalTask->taskFunctionality();
|
2020-04-23 19:13:18 +02:00
|
|
|
sif::debug << "Polling task " << originalTask->handle
|
2018-07-13 15:56:37 +02:00
|
|
|
<< " returned from taskFunctionality." << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FixedTimeslotTask::missedDeadlineCounter() {
|
|
|
|
FixedTimeslotTask::deadlineMissedCount++;
|
|
|
|
if (FixedTimeslotTask::deadlineMissedCount % 10 == 0) {
|
2020-04-23 19:13:18 +02:00
|
|
|
sif::error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
|
2018-07-13 15:56:37 +02:00
|
|
|
<< " deadlines." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t FixedTimeslotTask::startTask() {
|
|
|
|
started = true;
|
|
|
|
|
|
|
|
// We must not call resume if scheduler is not started yet
|
|
|
|
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
|
|
|
vTaskResume(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
|
|
|
|
uint32_t slotTimeMs, int8_t executionStep) {
|
2020-05-15 21:10:56 +02:00
|
|
|
<<<<<<< HEAD
|
|
|
|
=======
|
2020-05-07 20:06:17 +02:00
|
|
|
|
2020-05-15 21:10:56 +02:00
|
|
|
>>>>>>> mueller_framework
|
2020-05-05 18:28:50 +02:00
|
|
|
if (objectManager->get<ExecutableObjectIF>(componentId) != nullptr) {
|
2020-04-01 17:19:03 +02:00
|
|
|
if(slotTimeMs == 0) {
|
2020-05-05 19:03:00 +02:00
|
|
|
// FreeRTOS throws a sanity error for zero values, so we set
|
|
|
|
// the time to one millisecond.
|
2020-04-01 17:19:03 +02:00
|
|
|
slotTimeMs = 1;
|
|
|
|
}
|
2020-02-15 15:27:06 +01:00
|
|
|
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2020-01-20 22:03:13 +01:00
|
|
|
}
|
|
|
|
|
2020-05-07 19:41:42 +02:00
|
|
|
sif::error << "Component " << std::hex << componentId <<
|
2020-05-05 18:28:50 +02:00
|
|
|
" not found, not adding it to pst" << std::endl;
|
2020-02-15 15:27:06 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
2018-07-13 15:56:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t FixedTimeslotTask::getPeriodMs() const {
|
|
|
|
return pst.getLengthMs();
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t FixedTimeslotTask::checkSequence() const {
|
|
|
|
return pst.checkSequence();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FixedTimeslotTask::taskFunctionality() {
|
|
|
|
// A local iterator for the Polling Sequence Table is created to find the start time for the first entry.
|
2020-03-24 00:22:17 +01:00
|
|
|
SlotListIter slotListIter = pst.current;
|
2018-07-13 15:56:37 +02:00
|
|
|
|
|
|
|
//The start time for the first entry is read.
|
2020-03-24 00:22:17 +01:00
|
|
|
uint32_t intervalMs = slotListIter->pollingTimeMs;
|
2018-07-13 15:56:37 +02:00
|
|
|
TickType_t interval = pdMS_TO_TICKS(intervalMs);
|
|
|
|
|
|
|
|
TickType_t xLastWakeTime;
|
|
|
|
/* The xLastWakeTime variable needs to be initialized with the current tick
|
|
|
|
count. Note that this is the only time the variable is written to explicitly.
|
|
|
|
After this assignment, xLastWakeTime is updated automatically internally within
|
|
|
|
vTaskDelayUntil(). */
|
|
|
|
xLastWakeTime = xTaskGetTickCount();
|
|
|
|
|
|
|
|
// wait for first entry's start time
|
|
|
|
vTaskDelayUntil(&xLastWakeTime, interval);
|
|
|
|
|
|
|
|
/* Enter the loop that defines the task behavior. */
|
|
|
|
for (;;) {
|
|
|
|
//The component for this slot is executed and the next one is chosen.
|
|
|
|
this->pst.executeAndAdvance();
|
|
|
|
if (pst.slotFollowsImmediately()) {
|
|
|
|
//Do nothing
|
|
|
|
} else {
|
|
|
|
// we need to wait before executing the current slot
|
|
|
|
//this gives us the time to wait:
|
|
|
|
intervalMs = this->pst.getIntervalToPreviousSlotMs();
|
|
|
|
interval = pdMS_TO_TICKS(intervalMs);
|
|
|
|
vTaskDelayUntil(&xLastWakeTime, interval);
|
|
|
|
//TODO deadline missed check
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms) {
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(ms));
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|