From 78ae109a08ec58c17b1b966944992da0b74da011 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 May 2020 13:02:13 +0200 Subject: [PATCH] removed context switch request (shall be done at end of ISR, so must be performed by caller) --- osal/FreeRTOS/BinSemaphUsingTask.cpp | 9 ++++----- osal/FreeRTOS/BinSemaphUsingTask.h | 3 ++- osal/FreeRTOS/BinarySemaphore.cpp | 9 --------- osal/FreeRTOS/BinarySemaphore.h | 5 +++-- osal/FreeRTOS/MessageQueue.cpp | 2 +- osal/FreeRTOS/MessageQueue.h | 4 ++-- osal/FreeRTOS/TaskManagement.cpp | 4 ++-- osal/FreeRTOS/TaskManagement.h | 6 +++--- 8 files changed, 17 insertions(+), 25 deletions(-) diff --git a/osal/FreeRTOS/BinSemaphUsingTask.cpp b/osal/FreeRTOS/BinSemaphUsingTask.cpp index 51a3c5636..8f5fd4d8a 100644 --- a/osal/FreeRTOS/BinSemaphUsingTask.cpp +++ b/osal/FreeRTOS/BinSemaphUsingTask.cpp @@ -75,7 +75,7 @@ uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter( // Be careful with the stack size here. This is called from an ISR! ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR( TaskHandle_t taskHandle, BaseType_t * higherPriorityTaskWoken) { - if(getSemaphoreCounterFromISR(taskHandle) == 1) { + if(getSemaphoreCounterFromISR(taskHandle, higherPriorityTaskWoken) == 1) { return SemaphoreIF::SEMAPHORE_NOT_OWNED; } vTaskNotifyGiveFromISR(taskHandle, higherPriorityTaskWoken); @@ -83,10 +83,9 @@ ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR( } uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR( - TaskHandle_t taskHandle) { - uint32_t notificationValue; - BaseType_t higherPriorityTaskWoken; + TaskHandle_t taskHandle, BaseType_t* higherPriorityTaskWoken) { + uint32_t notificationValue = 0; xTaskNotifyAndQueryFromISR(taskHandle, 0, eNoAction, ¬ificationValue, - &higherPriorityTaskWoken); + higherPriorityTaskWoken); return notificationValue; } diff --git a/osal/FreeRTOS/BinSemaphUsingTask.h b/osal/FreeRTOS/BinSemaphUsingTask.h index 316208801..e6cb2a074 100644 --- a/osal/FreeRTOS/BinSemaphUsingTask.h +++ b/osal/FreeRTOS/BinSemaphUsingTask.h @@ -32,7 +32,8 @@ public: ReturnValue_t release() override; uint8_t getSemaphoreCounter() const override; static uint8_t getSemaphoreCounter(TaskHandle_t taskHandle); - static uint8_t getSemaphoreCounterFromISR(TaskHandle_t taskHandle); + static uint8_t getSemaphoreCounterFromISR(TaskHandle_t taskHandle, + BaseType_t* higherPriorityTaskWoken); /** * Same as acquire() with timeout in FreeRTOS ticks. diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index 7b695dee1..b6687bb75 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -36,9 +36,6 @@ BinarySemaphore& BinarySemaphore::operator =( } ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) { - if(handle == nullptr) { - return SemaphoreIF::SEMAPHORE_INVALID; - } TickType_t timeout = SemaphoreIF::NO_TIMEOUT; if(timeoutMs == SemaphoreIF::MAX_TIMEOUT) { timeout = SemaphoreIF::MAX_TIMEOUT; @@ -97,12 +94,6 @@ ReturnValue_t BinarySemaphore::releaseFromISR( } BaseType_t returncode = xSemaphoreGiveFromISR(semaphore, higherPriorityTaskWoken); - // This should propably be called at the end of the (calling) ISR - //if(*higherPriorityTaskWoken == pdPASS) { - // Request context switch because unblocking the semaphore - // caused a high priority task unblock. - //TaskManagement::requestContextSwitch(CallContext::isr); - //} if (returncode == pdPASS) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/osal/FreeRTOS/BinarySemaphore.h b/osal/FreeRTOS/BinarySemaphore.h index f3839151d..de6092afd 100644 --- a/osal/FreeRTOS/BinarySemaphore.h +++ b/osal/FreeRTOS/BinarySemaphore.h @@ -92,8 +92,9 @@ public: /** * 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 + * @param higherPriorityTaskWoken This will be set to pdPASS if a task with + * a higher priority was unblocked. A context switch from an ISR should + * then be requested (see TaskManagement functions) * @return -@c RETURN_OK on success * -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is * already available. diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index 9e4b581be..b56a62521 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -124,7 +124,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, bool ignoreFault, CallContext callContext) { message->setSender(sentFrom); BaseType_t result; - if(callContext == CallContext::task) { + if(callContext == CallContext::TASK) { result = xQueueSendToBack(reinterpret_cast(sendTo), static_cast(message->getBuffer()), 0); } diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index 988733f6b..8daab8f66 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -199,7 +199,7 @@ protected: */ static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, - bool ignoreFault=false, CallContext callContext = CallContext::task); + bool ignoreFault=false, CallContext callContext = CallContext::TASK); static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); @@ -209,7 +209,7 @@ private: MessageQueueId_t defaultDestination = 0; MessageQueueId_t lastPartner = 0; //!< Stores the current system context - CallContext callContext = CallContext::task; + CallContext callContext = CallContext::TASK; }; #endif /* MESSAGEQUEUE_H_ */ diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp index 4529b3710..7871ab2ec 100644 --- a/osal/FreeRTOS/TaskManagement.cpp +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -5,8 +5,8 @@ void TaskManagement::requestContextSwitchFromTask() { } void TaskManagement::requestContextSwitch( - CallContext callContext = CallContext::task) { - if(callContext == CallContext::isr) { + CallContext callContext = CallContext::TASK) { + if(callContext == CallContext::ISR) { // This function depends on the partmacro.h definition for the specific device requestContextSwitchFromISR(); } else { diff --git a/osal/FreeRTOS/TaskManagement.h b/osal/FreeRTOS/TaskManagement.h index b9874db0c..39c24377b 100644 --- a/osal/FreeRTOS/TaskManagement.h +++ b/osal/FreeRTOS/TaskManagement.h @@ -21,9 +21,9 @@ extern "C" void requestContextSwitchFromISR(); * has different functions for handling semaphores and messages from within * an ISR and task. */ -enum CallContext { - task = 0x00,//!< task_context - isr = 0xFF //!< isr_context +enum class CallContext { + TASK = 0x00,//!< task_context + ISR = 0xFF //!< isr_context };