From abccd81fdfddb1fc065af32bf6c603c4c3722430 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 26 Feb 2020 16:55:35 +0100 Subject: [PATCH] new file for freeRTOS task management functions --- osal/FreeRTOS/FixedTimeslotTask.cpp | 1 - osal/FreeRTOS/FixedTimeslotTask.h | 1 + osal/FreeRTOS/MessageQueue.cpp | 6 ----- osal/FreeRTOS/MessageQueue.h | 22 +++--------------- osal/FreeRTOS/PeriodicTask.h | 6 ++--- osal/FreeRTOS/TaskManagement.cpp | 24 ++++++++++++++++++++ osal/FreeRTOS/TaskManagement.h | 35 +++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 osal/FreeRTOS/TaskManagement.cpp create mode 100644 osal/FreeRTOS/TaskManagement.h diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index 413d7596..a2c2e5c6 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -114,4 +114,3 @@ ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms) { vTaskDelay(pdMS_TO_TICKS(ms)); return HasReturnvaluesIF::RETURN_OK; } - diff --git a/osal/FreeRTOS/FixedTimeslotTask.h b/osal/FreeRTOS/FixedTimeslotTask.h index bed13051..1ab8724f 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.h +++ b/osal/FreeRTOS/FixedTimeslotTask.h @@ -51,6 +51,7 @@ public: ReturnValue_t checkSequence() const; ReturnValue_t sleepFor(uint32_t ms); + protected: bool started; TaskHandle_t handle; diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index fdca80c7..92c691ea 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -23,12 +23,6 @@ void MessageQueue::switchSystemContext(SystemContext callContext) { this->callContext = callContext; } -void MessageQueue::requestContextSwitch(SystemContext callContext) { - if(callContext == SystemContext::isr_context) { - portYIELD_FROM_ISR(); - } -} - ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo, MessageQueueMessage* message, bool ignoreFault) { return sendMessageFrom(sendTo, message, this->getId(), ignoreFault); diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index cdb2a798..9406fdef 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -4,11 +4,11 @@ #include #include #include +#include #include #include "queue.h" -#include "portmacro.h" -#include "task.h" + //TODO this class assumes that MessageQueueId_t is the same size as void* (the FreeRTOS handle type), compiler will catch this but it might be nice to have something checking or even an always working solution // https://scaryreasoner.wordpress.com/2009/02/28/checking-sizeof-at-compile-time/ @@ -58,16 +58,6 @@ public: */ virtual ~MessageQueue(); - /*! - * Used by calling function to tell the callbacks if they are being called from - * within an ISR or from a regular task. This is required because FreeRTOS - * has different functions for handling semaphores from within an ISR and task. - */ - typedef enum _SystemContext { - task_context = 0x00,//!< task_context - isr_context = 0xFF //!< isr_context - } SystemContext; - /** * This function is used to specify whether a message queue operation is called * from within an ISR or a task. FreeRTOS offers different functions for this task. @@ -187,13 +177,7 @@ protected: static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); - /** - * In this function, a function dependant on the portmacro.h header function calls - * to request a context switch can be specified. - * This can be used if sending to the queue from an ISR caused a task to unblock - * and a context switch is required. - */ - static void requestContextSwitch(SystemContext callContext); + private: QueueHandle_t handle; MessageQueueId_t defaultDestination; diff --git a/osal/FreeRTOS/PeriodicTask.h b/osal/FreeRTOS/PeriodicTask.h index e7ba8dd2..4cbffd5a 100644 --- a/osal/FreeRTOS/PeriodicTask.h +++ b/osal/FreeRTOS/PeriodicTask.h @@ -1,5 +1,5 @@ -#ifndef MULTIOBJECTTASK_H_ -#define MULTIOBJECTTASK_H_ +#ifndef PERIODICTASK_H_ +#define PERIODICTASK_H_ #include #include @@ -107,4 +107,4 @@ protected: void taskFunctionality(void); }; -#endif /* MULTIOBJECTTASK_H_ */ +#endif /* PERIODICTASK_H_ */ diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp new file mode 100644 index 00000000..e9781769 --- /dev/null +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -0,0 +1,24 @@ +/** + * @file TaskManagement.cpp + * + * @date 26.02.2020 + * + */ +#include +#include +#include "portmacro.h" +#include "task.h" + +void requestContextSwitchFromTask() { + vTaskDelay(0); +} + +void requestContextSwitch(SystemContext callContext) { + if(callContext == SystemContext::isr_context) { + // This function depends on the partmacro.h definition for the specific device + portYIELD_FROM_ISR(); + } else { + requestContextSwitchFromTask(); + } +} + diff --git a/osal/FreeRTOS/TaskManagement.h b/osal/FreeRTOS/TaskManagement.h new file mode 100644 index 00000000..74e2316f --- /dev/null +++ b/osal/FreeRTOS/TaskManagement.h @@ -0,0 +1,35 @@ +/** + * @file TaskManagement.h + * + * @date 26.02.2020 + */ + +#ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ +#define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ + +/*! + * Used by functions to tell if they are being called from + * within an ISR or from a regular task. This is required because FreeRTOS + * has different functions for handling semaphores and messages from within an ISR and task. + */ +typedef enum _SystemContext { + task_context = 0x00,//!< task_context + isr_context = 0xFF //!< isr_context +} SystemContext; + +/** + * In this function, a function dependant on the portmacro.h header function calls + * to request a context switch can be specified. + * This can be used if sending to the queue from an ISR caused a task to unblock + * and a context switch is required. + */ +void requestContextSwitch(SystemContext callContext); + +/** + * If task preemption in FreeRTOS is disabled, a context switch + * can be requested manually by calling this function. + */ +void requestContextSwitch(void); + + +#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */