all context switches calls to TaskManagement.h now

This commit is contained in:
Robin Müller 2020-02-28 22:55:25 +01:00
parent c93ee5c6cd
commit fa38a37604
6 changed files with 48 additions and 43 deletions

View File

@ -4,6 +4,8 @@
* @date 25.02.2020
*/
#include <framework/osal/FreeRTOS/BinarySemaphore.h>
#include <framework/osal/FreeRTOS/TaskManagement.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#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 {

View File

@ -68,19 +68,16 @@ public:
* @return
*/
SemaphoreHandle_t getSemaphore();
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);
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
@ -88,7 +85,14 @@ ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore);
* @return -@c RETURN_OK on success
* -@c RETURN_FAILED on failure
*/
ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
static ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
BaseType_t * higherPriorityTaskWoken);
private:
SemaphoreHandle_t handle;
};
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */

View File

@ -65,7 +65,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
result = xQueueSendFromISR(reinterpret_cast<void*>(sendTo),
reinterpret_cast<const void*>(message->getBuffer()), &xHigherPriorityTaskWoken);
if(xHigherPriorityTaskWoken == pdTRUE) {
requestContextSwitch(callContext);
TaskManagement::requestContextSwitch(callContext);
}
}
return handleSendResult(result, ignoreFault);

View File

@ -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);
/**

View File

@ -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) {
}
}

View File

@ -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;
};
/**
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.
*/
void requestContextSwitch(SystemContext callContext);
static 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);
static void requestContextSwitchFromTask(void);
};
#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */