From fa38a3760448e28109b6a73bb46e3ee50bb583a8 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 28 Feb 2020 22:55:25 +0100 Subject: [PATCH] all context switches calls to TaskManagement.h now --- osal/FreeRTOS/BinarySemaphore.cpp | 8 ++++--- osal/FreeRTOS/BinarySemaphore.h | 38 +++++++++++++++++-------------- osal/FreeRTOS/MessageQueue.cpp | 2 +- osal/FreeRTOS/MessageQueue.h | 5 ---- osal/FreeRTOS/TaskManagement.cpp | 6 +++-- osal/FreeRTOS/TaskManagement.h | 32 ++++++++++++++------------ 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index dd73c5b0..09e71f6d 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -4,6 +4,8 @@ * @date 25.02.2020 */ #include +#include + #include #include "portmacro.h" #include "task.h" @@ -65,7 +67,7 @@ SemaphoreHandle_t BinarySemaphore::getSemaphore() { return handle; } -ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore) { +ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) { if (semaphore == NULL) { return HasReturnvaluesIF::RETURN_FAILED; } @@ -77,7 +79,7 @@ ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore) { } } -ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, +ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) { if (semaphore == NULL) { return HasReturnvaluesIF::RETURN_FAILED; @@ -86,7 +88,7 @@ ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, if (returncode == pdPASS) { if(*higherPriorityTaskWoken == pdPASS) { // Request context switch - portYIELD_FROM_ISR(); + TaskManagement::requestContextSwitch(SystemContext::isr_context); } return HasReturnvaluesIF::RETURN_OK; } else { diff --git a/osal/FreeRTOS/BinarySemaphore.h b/osal/FreeRTOS/BinarySemaphore.h index afc01adf..7ead0d2f 100644 --- a/osal/FreeRTOS/BinarySemaphore.h +++ b/osal/FreeRTOS/BinarySemaphore.h @@ -68,27 +68,31 @@ public: * @return */ SemaphoreHandle_t getSemaphore(); + + /** + * Wrapper function to give back semaphore from handle + * @param semaphore + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ + static ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore); + + /** + * Wrapper function to give back semaphore from handle when called from an ISR + * @param semaphore + * @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority + * was unblocked + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ + static ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, + BaseType_t * higherPriorityTaskWoken); private: SemaphoreHandle_t handle; }; -/** - * Wrapper function to give back semaphore from handle - * @param semaphore - * @return -@c RETURN_OK on success - * -@c RETURN_FAILED on failure - */ -ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore); -/** - * Wrapper function to give back semaphore from handle when called from an ISR - * @param semaphore - * @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority - * was unblocked - * @return -@c RETURN_OK on success - * -@c RETURN_FAILED on failure - */ -ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, - BaseType_t * higherPriorityTaskWoken); + + #endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */ diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index 92c691ea..f23d9d9d 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -65,7 +65,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, result = xQueueSendFromISR(reinterpret_cast(sendTo), reinterpret_cast(message->getBuffer()), &xHigherPriorityTaskWoken); if(xHigherPriorityTaskWoken == pdTRUE) { - requestContextSwitch(callContext); + TaskManagement::requestContextSwitch(callContext); } } return handleSendResult(result, ignoreFault); diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index 9406fdef..d8e14961 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -58,11 +58,6 @@ public: */ virtual ~MessageQueue(); - /** - * 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. - * @param callContext - */ void switchSystemContext(SystemContext callContext); /** diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp index e9781769..573a7d7d 100644 --- a/osal/FreeRTOS/TaskManagement.cpp +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -9,11 +9,11 @@ #include "portmacro.h" #include "task.h" -void requestContextSwitchFromTask() { +void TaskManagement::requestContextSwitchFromTask() { vTaskDelay(0); } -void requestContextSwitch(SystemContext callContext) { +void TaskManagement::requestContextSwitch(SystemContext callContext = SystemContext::task_context) { if(callContext == SystemContext::isr_context) { // This function depends on the partmacro.h definition for the specific device portYIELD_FROM_ISR(); @@ -22,3 +22,5 @@ void requestContextSwitch(SystemContext callContext) { } } + + diff --git a/osal/FreeRTOS/TaskManagement.h b/osal/FreeRTOS/TaskManagement.h index 74e2316f..381e06f9 100644 --- a/osal/FreeRTOS/TaskManagement.h +++ b/osal/FreeRTOS/TaskManagement.h @@ -12,24 +12,26 @@ * 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 { +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); +class TaskManagement { +public: + /** + * 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); + /** + * If task preemption in FreeRTOS is disabled, a context switch + * can be requested manually by calling this function. + */ + static void requestContextSwitchFromTask(void); +}; #endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */