From 281da25bf97f344fd7b7727530208879c9c7a153 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 1 May 2020 16:47:53 +0200 Subject: [PATCH] extended task management for freeRTOS --- osal/FreeRTOS/PeriodicTask.cpp | 7 ++++--- osal/FreeRTOS/PeriodicTask.h | 35 ++++++++++++++++---------------- osal/FreeRTOS/TaskFactory.cpp | 4 ---- osal/FreeRTOS/TaskManagement.cpp | 16 ++++++++++----- osal/FreeRTOS/TaskManagement.h | 32 ++++++++++++++++++++++++++++- tasks/TaskFactory.h | 7 ------- 6 files changed, 63 insertions(+), 38 deletions(-) diff --git a/osal/FreeRTOS/PeriodicTask.cpp b/osal/FreeRTOS/PeriodicTask.cpp index deab2dc1..3075be79 100644 --- a/osal/FreeRTOS/PeriodicTask.cpp +++ b/osal/FreeRTOS/PeriodicTask.cpp @@ -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; diff --git a/osal/FreeRTOS/PeriodicTask.h b/osal/FreeRTOS/PeriodicTask.h index 4cbffd5a..02ab7148 100644 --- a/osal/FreeRTOS/PeriodicTask.h +++ b/osal/FreeRTOS/PeriodicTask.h @@ -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. diff --git a/osal/FreeRTOS/TaskFactory.cpp b/osal/FreeRTOS/TaskFactory.cpp index 6b18d7a8..62015a4c 100644 --- a/osal/FreeRTOS/TaskFactory.cpp +++ b/osal/FreeRTOS/TaskFactory.cpp @@ -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() { } diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp index 3e22021a..bda43d8b 100644 --- a/osal/FreeRTOS/TaskManagement.cpp +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -1,10 +1,5 @@ #include -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; +} diff --git a/osal/FreeRTOS/TaskManagement.h b/osal/FreeRTOS/TaskManagement.h index 4c148ca5..11c4c9dc 100644 --- a/osal/FreeRTOS/TaskManagement.h +++ b/osal/FreeRTOS/TaskManagement.h @@ -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 + +extern "C" { +#include "FreeRTOS.h" +#include "task.h" +} +#include + /** * 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_ */ diff --git a/tasks/TaskFactory.h b/tasks/TaskFactory.h index 6716f7ff..31b8b135 100644 --- a/tasks/TaskFactory.h +++ b/tasks/TaskFactory.h @@ -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.