WIP: somethings wrong.. #19
@ -2,7 +2,7 @@
|
|||||||
#include <framework/osal/FreeRTOS/TaskManagement.h>
|
#include <framework/osal/FreeRTOS/TaskManagement.h>
|
||||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
|
|
||||||
#if ( configUSE_OLD_SEMAPHORES == 1 )
|
#if ( configUSE_TASK_NOTIFICATIONS == 0 )
|
||||||
|
|
||||||
BinarySemaphore::BinarySemaphore() {
|
BinarySemaphore::BinarySemaphore() {
|
||||||
handle = xSemaphoreCreateBinary();
|
handle = xSemaphoreCreateBinary();
|
||||||
@ -174,9 +174,6 @@ ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t BinarySemaphore::giveBinarySemaphore() {
|
ReturnValue_t BinarySemaphore::giveBinarySemaphore() {
|
||||||
if (handle == nullptr) {
|
|
||||||
return SEMAPHORE_NULLPOINTER;
|
|
||||||
}
|
|
||||||
BaseType_t returncode = xTaskNotifyGive(handle);
|
BaseType_t returncode = xTaskNotifyGive(handle);
|
||||||
if (returncode == pdPASS) {
|
if (returncode == pdPASS) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
@ -185,4 +182,47 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TaskHandle_t BinarySemaphore::getTaskHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphore::getSemaphoreCounter() {
|
||||||
|
uint32_t notificationValue;
|
||||||
|
xTaskNotifyAndQuery(handle, 0, eNoAction, ¬ificationValue);
|
||||||
|
return notificationValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphore::getSemaphoreCounterFromISR(TaskHandle_t taskHandle) {
|
||||||
|
uint32_t notificationValue;
|
||||||
|
BaseType_t higherPriorityTaskWoken;
|
||||||
|
xTaskNotifyAndQueryFromISR(taskHandle, 0, eNoAction, ¬ificationValue,
|
||||||
|
&higherPriorityTaskWoken);
|
||||||
|
if(higherPriorityTaskWoken) {
|
||||||
|
TaskManagement::requestContextSwitch(CallContext::isr);
|
||||||
|
}
|
||||||
|
return notificationValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::giveBinarySemaphore(TaskHandle_t taskHandle) {
|
||||||
|
BaseType_t returncode = xTaskNotifyGive(taskHandle);
|
||||||
|
if (returncode == pdPASS) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
} else {
|
||||||
|
return SEMAPHORE_NOT_OWNED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Be careful with the stack size here. This is called from an ISR!
|
||||||
|
ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(
|
||||||
|
TaskHandle_t taskHandle, BaseType_t * higherPriorityTaskWoken) {
|
||||||
|
vTaskNotifyGiveFromISR(taskHandle, higherPriorityTaskWoken);
|
||||||
|
if(*higherPriorityTaskWoken == pdPASS) {
|
||||||
|
// Request context switch because unblocking the semaphore
|
||||||
|
// caused a high priority task unblock.
|
||||||
|
TaskManagement::requestContextSwitch(CallContext::isr);
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#if ( configUSE_OLD_SEMAPHORES == 1 )
|
#if ( configUSE_TASK_NOTIFICATIONS == 0 )
|
||||||
#include <freertos/semphr.h>
|
#include <freertos/semphr.h>
|
||||||
#else
|
#else
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
@ -28,7 +28,7 @@ extern "C" {
|
|||||||
* @author R. Mueller
|
* @author R. Mueller
|
||||||
* @ingroup osal
|
* @ingroup osal
|
||||||
*/
|
*/
|
||||||
#if ( configUSE_OLD_SEMAPHORES == 1 )
|
#if ( configUSE_TASK_NOTIFICATIONS == 0 )
|
||||||
|
|
||||||
class BinarySemaphore: public SemaphoreIF,
|
class BinarySemaphore: public SemaphoreIF,
|
||||||
public HasReturnvaluesIF {
|
public HasReturnvaluesIF {
|
||||||
@ -155,7 +155,7 @@ public:
|
|||||||
ReturnValue_t giveBinarySemaphore();
|
ReturnValue_t giveBinarySemaphore();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Handle to the semaphore.
|
* Get handle to the task related to the semaphore.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
TaskHandle_t getTaskHandle();
|
TaskHandle_t getTaskHandle();
|
||||||
@ -179,6 +179,8 @@ public:
|
|||||||
static ReturnValue_t giveBinarySemaphoreFromISR(TaskHandle_t taskToNotify,
|
static ReturnValue_t giveBinarySemaphoreFromISR(TaskHandle_t taskToNotify,
|
||||||
BaseType_t * higherPriorityTaskWoken);
|
BaseType_t * higherPriorityTaskWoken);
|
||||||
|
|
||||||
|
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t taskHandle);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TaskHandle_t handle;
|
TaskHandle_t handle;
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
#include <framework/osal/FreeRTOS/CountingSemaphore.h>
|
#include <framework/osal/FreeRTOS/CountingSemaphore.h>
|
||||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <freertos/semphr.h>
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure #define configUSE_COUNTING_SEMAPHORES 1 is set in
|
// Make sure #define configUSE_COUNTING_SEMAPHORES 1 is set in
|
||||||
// free FreeRTOSConfig.h file.
|
// free FreeRTOSConfig.h file.
|
||||||
CountingSemaphore::CountingSemaphore(uint8_t count, uint8_t initCount):
|
CountingSemaphore::CountingSemaphore(uint8_t count, uint8_t initCount):
|
||||||
|
Loading…
Reference in New Issue
Block a user