removed context switch request

(shall be done at end of ISR, so must be performed by caller)
This commit is contained in:
Robin Müller 2020-05-29 13:02:13 +02:00
parent da403c01d0
commit 78ae109a08
8 changed files with 17 additions and 25 deletions

View File

@ -75,7 +75,7 @@ uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter(
// Be careful with the stack size here. This is called from an ISR! // Be careful with the stack size here. This is called from an ISR!
ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR( ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR(
TaskHandle_t taskHandle, BaseType_t * higherPriorityTaskWoken) { TaskHandle_t taskHandle, BaseType_t * higherPriorityTaskWoken) {
if(getSemaphoreCounterFromISR(taskHandle) == 1) { if(getSemaphoreCounterFromISR(taskHandle, higherPriorityTaskWoken) == 1) {
return SemaphoreIF::SEMAPHORE_NOT_OWNED; return SemaphoreIF::SEMAPHORE_NOT_OWNED;
} }
vTaskNotifyGiveFromISR(taskHandle, higherPriorityTaskWoken); vTaskNotifyGiveFromISR(taskHandle, higherPriorityTaskWoken);
@ -83,10 +83,9 @@ ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR(
} }
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR( uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR(
TaskHandle_t taskHandle) { TaskHandle_t taskHandle, BaseType_t* higherPriorityTaskWoken) {
uint32_t notificationValue; uint32_t notificationValue = 0;
BaseType_t higherPriorityTaskWoken;
xTaskNotifyAndQueryFromISR(taskHandle, 0, eNoAction, &notificationValue, xTaskNotifyAndQueryFromISR(taskHandle, 0, eNoAction, &notificationValue,
&higherPriorityTaskWoken); higherPriorityTaskWoken);
return notificationValue; return notificationValue;
} }

View File

@ -32,7 +32,8 @@ public:
ReturnValue_t release() override; ReturnValue_t release() override;
uint8_t getSemaphoreCounter() const override; uint8_t getSemaphoreCounter() const override;
static uint8_t getSemaphoreCounter(TaskHandle_t taskHandle); 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. * Same as acquire() with timeout in FreeRTOS ticks.

View File

@ -36,9 +36,6 @@ BinarySemaphore& BinarySemaphore::operator =(
} }
ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) { ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) {
if(handle == nullptr) {
return SemaphoreIF::SEMAPHORE_INVALID;
}
TickType_t timeout = SemaphoreIF::NO_TIMEOUT; TickType_t timeout = SemaphoreIF::NO_TIMEOUT;
if(timeoutMs == SemaphoreIF::MAX_TIMEOUT) { if(timeoutMs == SemaphoreIF::MAX_TIMEOUT) {
timeout = SemaphoreIF::MAX_TIMEOUT; timeout = SemaphoreIF::MAX_TIMEOUT;
@ -97,12 +94,6 @@ ReturnValue_t BinarySemaphore::releaseFromISR(
} }
BaseType_t returncode = xSemaphoreGiveFromISR(semaphore, BaseType_t returncode = xSemaphoreGiveFromISR(semaphore,
higherPriorityTaskWoken); 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) { if (returncode == pdPASS) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }

View File

@ -92,8 +92,9 @@ public:
/** /**
* Wrapper function to give back semaphore from handle when called from an ISR * Wrapper function to give back semaphore from handle when called from an ISR
* @param semaphore * @param semaphore
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority * @param higherPriorityTaskWoken This will be set to pdPASS if a task with
* was unblocked * a higher priority was unblocked. A context switch from an ISR should
* then be requested (see TaskManagement functions)
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is * -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
* already available. * already available.

View File

@ -124,7 +124,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
bool ignoreFault, CallContext callContext) { bool ignoreFault, CallContext callContext) {
message->setSender(sentFrom); message->setSender(sentFrom);
BaseType_t result; BaseType_t result;
if(callContext == CallContext::task) { if(callContext == CallContext::TASK) {
result = xQueueSendToBack(reinterpret_cast<QueueHandle_t>(sendTo), result = xQueueSendToBack(reinterpret_cast<QueueHandle_t>(sendTo),
static_cast<const void*>(message->getBuffer()), 0); static_cast<const void*>(message->getBuffer()), 0);
} }

View File

@ -199,7 +199,7 @@ protected:
*/ */
static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo, static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo,
MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, 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); static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault);
@ -209,7 +209,7 @@ private:
MessageQueueId_t defaultDestination = 0; MessageQueueId_t defaultDestination = 0;
MessageQueueId_t lastPartner = 0; MessageQueueId_t lastPartner = 0;
//!< Stores the current system context //!< Stores the current system context
CallContext callContext = CallContext::task; CallContext callContext = CallContext::TASK;
}; };
#endif /* MESSAGEQUEUE_H_ */ #endif /* MESSAGEQUEUE_H_ */

View File

@ -5,8 +5,8 @@ void TaskManagement::requestContextSwitchFromTask() {
} }
void TaskManagement::requestContextSwitch( void TaskManagement::requestContextSwitch(
CallContext callContext = CallContext::task) { CallContext callContext = CallContext::TASK) {
if(callContext == CallContext::isr) { if(callContext == CallContext::ISR) {
// This function depends on the partmacro.h definition for the specific device // This function depends on the partmacro.h definition for the specific device
requestContextSwitchFromISR(); requestContextSwitchFromISR();
} else { } else {

View File

@ -21,9 +21,9 @@ extern "C" void requestContextSwitchFromISR();
* has different functions for handling semaphores and messages from within * has different functions for handling semaphores and messages from within
* an ISR and task. * an ISR and task.
*/ */
enum CallContext { enum class CallContext {
task = 0x00,//!< task_context TASK = 0x00,//!< task_context
isr = 0xFF //!< isr_context ISR = 0xFF //!< isr_context
}; };