all context switches calls to TaskManagement.h now
This commit is contained in:
parent
c93ee5c6cd
commit
fa38a37604
@ -4,6 +4,8 @@
|
|||||||
* @date 25.02.2020
|
* @date 25.02.2020
|
||||||
*/
|
*/
|
||||||
#include <framework/osal/FreeRTOS/BinarySemaphore.h>
|
#include <framework/osal/FreeRTOS/BinarySemaphore.h>
|
||||||
|
#include <framework/osal/FreeRTOS/TaskManagement.h>
|
||||||
|
|
||||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
#include "portmacro.h"
|
#include "portmacro.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
@ -65,7 +67,7 @@ SemaphoreHandle_t BinarySemaphore::getSemaphore() {
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore) {
|
ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) {
|
||||||
if (semaphore == NULL) {
|
if (semaphore == NULL) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
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) {
|
BaseType_t * higherPriorityTaskWoken) {
|
||||||
if (semaphore == NULL) {
|
if (semaphore == NULL) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
@ -86,7 +88,7 @@ ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
|
|||||||
if (returncode == pdPASS) {
|
if (returncode == pdPASS) {
|
||||||
if(*higherPriorityTaskWoken == pdPASS) {
|
if(*higherPriorityTaskWoken == pdPASS) {
|
||||||
// Request context switch
|
// Request context switch
|
||||||
portYIELD_FROM_ISR();
|
TaskManagement::requestContextSwitch(SystemContext::isr_context);
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,9 +68,6 @@ public:
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
SemaphoreHandle_t getSemaphore();
|
SemaphoreHandle_t getSemaphore();
|
||||||
private:
|
|
||||||
SemaphoreHandle_t handle;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper function to give back semaphore from handle
|
* Wrapper function to give back semaphore from handle
|
||||||
@ -78,7 +75,7 @@ private:
|
|||||||
* @return -@c RETURN_OK on success
|
* @return -@c RETURN_OK on success
|
||||||
* -@c RETURN_FAILED on failure
|
* -@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
|
* Wrapper function to give back semaphore from handle when called from an ISR
|
||||||
@ -88,7 +85,14 @@ ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore);
|
|||||||
* @return -@c RETURN_OK on success
|
* @return -@c RETURN_OK on success
|
||||||
* -@c RETURN_FAILED on failure
|
* -@c RETURN_FAILED on failure
|
||||||
*/
|
*/
|
||||||
ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
|
static ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
|
||||||
BaseType_t * higherPriorityTaskWoken);
|
BaseType_t * higherPriorityTaskWoken);
|
||||||
|
private:
|
||||||
|
SemaphoreHandle_t handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */
|
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */
|
||||||
|
@ -65,7 +65,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
|||||||
result = xQueueSendFromISR(reinterpret_cast<void*>(sendTo),
|
result = xQueueSendFromISR(reinterpret_cast<void*>(sendTo),
|
||||||
reinterpret_cast<const void*>(message->getBuffer()), &xHigherPriorityTaskWoken);
|
reinterpret_cast<const void*>(message->getBuffer()), &xHigherPriorityTaskWoken);
|
||||||
if(xHigherPriorityTaskWoken == pdTRUE) {
|
if(xHigherPriorityTaskWoken == pdTRUE) {
|
||||||
requestContextSwitch(callContext);
|
TaskManagement::requestContextSwitch(callContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return handleSendResult(result, ignoreFault);
|
return handleSendResult(result, ignoreFault);
|
||||||
|
@ -58,11 +58,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual ~MessageQueue();
|
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);
|
void switchSystemContext(SystemContext callContext);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
#include "portmacro.h"
|
#include "portmacro.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
void requestContextSwitchFromTask() {
|
void TaskManagement::requestContextSwitchFromTask() {
|
||||||
vTaskDelay(0);
|
vTaskDelay(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestContextSwitch(SystemContext callContext) {
|
void TaskManagement::requestContextSwitch(SystemContext callContext = SystemContext::task_context) {
|
||||||
if(callContext == SystemContext::isr_context) {
|
if(callContext == SystemContext::isr_context) {
|
||||||
// This function depends on the partmacro.h definition for the specific device
|
// This function depends on the partmacro.h definition for the specific device
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
@ -22,3 +22,5 @@ void requestContextSwitch(SystemContext callContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,24 +12,26 @@
|
|||||||
* within an ISR or from a regular task. This is required because FreeRTOS
|
* 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.
|
* has different functions for handling semaphores and messages from within an ISR and task.
|
||||||
*/
|
*/
|
||||||
typedef enum _SystemContext {
|
enum SystemContext {
|
||||||
task_context = 0x00,//!< task_context
|
task_context = 0x00,//!< task_context
|
||||||
isr_context = 0xFF //!< isr_context
|
isr_context = 0xFF //!< isr_context
|
||||||
} SystemContext;
|
};
|
||||||
|
|
||||||
|
class TaskManagement {
|
||||||
|
public:
|
||||||
/**
|
/**
|
||||||
* In this function, a function dependant on the portmacro.h header function calls
|
* In this function, a function dependant on the portmacro.h header function calls
|
||||||
* to request a context switch can be specified.
|
* 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
|
* This can be used if sending to the queue from an ISR caused a task to unblock
|
||||||
* and a context switch is required.
|
* 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
|
* If task preemption in FreeRTOS is disabled, a context switch
|
||||||
* can be requested manually by calling this function.
|
* can be requested manually by calling this function.
|
||||||
*/
|
*/
|
||||||
void requestContextSwitch(void);
|
static void requestContextSwitchFromTask(void);
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */
|
#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user