extended task management for freeRTOS

This commit is contained in:
Robin Müller 2020-05-01 16:47:53 +02:00
parent 15c03863c0
commit 281da25bf9
6 changed files with 63 additions and 38 deletions

View File

@ -6,9 +6,10 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
TaskStackSize setStack, TaskPeriod setPeriod,
void (*setDeadlineMissedFunc)()) :
started(false), handle(NULL), period(setPeriod), deadlineMissedFunc(
setDeadlineMissedFunc) {
BaseType_t status = xTaskCreate(taskEntryPoint, name, setStack, this, setPriority, &handle);
setDeadlineMissedFunc)
{
BaseType_t status = xTaskCreate(taskEntryPoint, name,
setStack, this, setPriority, &handle);
if(status != pdPASS){
sif::debug << "PeriodicTask Insufficient heap memory remaining. Status: "
<< status << std::endl;

View File

@ -13,11 +13,9 @@
class ExecutableObjectIF;
/**
* @brief This class represents a specialized task for periodic activities of multiple objects.
*
* @details MultiObjectTask is an extension to ObjectTask in the way that it is able to execute
* multiple objects that implement the ExecutableObjectIF interface. The objects must be
* added prior to starting the task.
* @brief This class represents a specialized task for
* periodic activities of multiple objects.
* @details
*
* @ingroup task_handling
*/
@ -25,21 +23,22 @@ class PeriodicTask: public PeriodicTaskIF {
public:
/**
* @brief Standard constructor of the class.
* @details The class is initialized without allocated objects. These need to be added
* with #addObject.
* In the underlying TaskBase class, a new operating system task is created.
* In addition to the TaskBase parameters, the period, the pointer to the
* aforementioned initialization function and an optional "deadline-missed"
* function pointer is passed.
* @param priority Sets the priority of a task. Values range from a low 0 to a high 99.
* @details
* The class is initialized without allocated objects. These need to be added
* with #addComponent. In the underlying TaskBase class, a new operating
* system task is created. In addition to the TaskBase parameters,
* the period, the pointer to the aforementioned initialization function and
* an optional "deadline-missed" function pointer is passed.
* @param priority Sets the priority of a task. Values depend on
* freeRTOS configuration, high number means high priority.
* @param stack_size The stack size reserved by the operating system for the task.
* @param setPeriod The length of the period with which the task's functionality will be
* executed. It is expressed in clock ticks.
* @param setDeadlineMissedFunc The function pointer to the deadline missed function
* that shall be assigned.
* @param setPeriod The length of the period with which the task's
* functionality will be executed. It is expressed in clock ticks.
* @param setDeadlineMissedFunc
* The function pointer to the deadline missed function that shall be assigned.
*/
PeriodicTask(const char *name, TaskPriority setPriority, TaskStackSize setStack, TaskPeriod setPeriod,
void (*setDeadlineMissedFunc)());
PeriodicTask(const char *name, TaskPriority setPriority, TaskStackSize setStack,
TaskPeriod setPeriod,void (*setDeadlineMissedFunc)());
/**
* @brief Currently, the executed object's lifetime is not coupled with the task object's
* lifetime, so the destructor is empty.

View File

@ -44,10 +44,6 @@ ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {
}
}
ReturnValue_t TaskFactory::delayTask(uint32_t delayMs) {
vTaskDelay(pdMS_TO_TICKS(delayMs));
return HasReturnvaluesIF::RETURN_OK;
}
TaskFactory::TaskFactory() {
}

View File

@ -1,10 +1,5 @@
#include <framework/osal/FreeRTOS/TaskManagement.h>
extern "C" {
#include "FreeRTOS.h"
#include "task.h"
}
void TaskManagement::requestContextSwitchFromTask() {
vTaskDelay(0);
}
@ -18,5 +13,16 @@ void TaskManagement::requestContextSwitch(CallContext callContext = CallContext:
}
}
TaskHandle_t TaskManagement::getCurrentTaskHandle() {
return xTaskGetCurrentTaskHandle();
}
configSTACK_DEPTH_TYPE TaskManagement::getTaskStackHighWatermark() {
return uxTaskGetStackHighWaterMark(TaskManagement::getCurrentTaskHandle());
}
ReturnValue_t TaskManagement::delayTask(uint32_t delayMs) {
vTaskDelay(pdMS_TO_TICKS(delayMs));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,7 +1,14 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
#define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
// maybe this can be part of the TaskFactory.cpp
#include <framework/returnvalues/HasReturnvaluesIF.h>
extern "C" {
#include "FreeRTOS.h"
#include "task.h"
}
#include <cstdint>
/**
* Architecture dependant portmacro.h function call.
* Should be implemented in bsp.
@ -35,6 +42,29 @@ public:
* can be requested manually by calling this function.
*/
static void requestContextSwitchFromTask(void);
/**
* @return The current task handle
*/
static TaskHandle_t getCurrentTaskHandle();
/**
* Get returns the minimum amount of remaining stack space in words
* that was a available to the task since the task started executing.
* Please note that the actual value in bytes depends
* on the stack depth type.
* E.g. on a 32 bit machine, a value of 200 means 800 bytes.
* @return Smallest value of stack remaining since the task was started in
* words.
*/
static configSTACK_DEPTH_TYPE getTaskStackHighWatermark();
/**
* 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);
};
#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */

View File

@ -60,13 +60,6 @@ public:
*/
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.