1
0
forked from fsfw/fsfw

counting semaph implementation finished

This commit is contained in:
2020-05-27 22:12:52 +02:00
parent 95bf5c1071
commit 63dbf99592
8 changed files with 154 additions and 87 deletions

View File

@ -1,7 +1,6 @@
#include <framework/osal/FreeRTOS/BinSemaphUsingTask.h>
#include <framework/osal/FreeRTOS/TaskManagement.h>
BinarySemaphoreUsingTask::BinarySemaphoreUsingTask() {
handle = TaskManagement::getCurrentTaskHandle();
xTaskNotifyGive(handle);
@ -9,44 +8,29 @@ BinarySemaphoreUsingTask::BinarySemaphoreUsingTask() {
}
ReturnValue_t BinarySemaphoreUsingTask::acquire(uint32_t timeoutMs) {
return takeBinarySemaphore(timeoutMs);
}
ReturnValue_t BinarySemaphoreUsingTask::release() {
return giveBinarySemaphore();
}
ReturnValue_t BinarySemaphoreUsingTask::takeBinarySemaphore(uint32_t timeoutMs) {
TickType_t timeout = SemaphoreIF::NO_TIMEOUT;
if(timeoutMs == SemaphoreIF::MAX_TIMEOUT) {
timeout = SemaphoreIF::MAX_TIMEOUT;
timeout = SemaphoreIF::MAX_TIMEOUT;
}
else if(timeoutMs > SemaphoreIF::NO_TIMEOUT){
timeout = pdMS_TO_TICKS(timeoutMs);
}
BaseType_t returncode = ulTaskNotifyTake(pdTRUE, timeout);
if (returncode == pdPASS) {
locked = true;
return HasReturnvaluesIF::RETURN_OK;
}
else {
return SemaphoreIF::SEMAPHORE_TIMEOUT;
timeout = pdMS_TO_TICKS(timeoutMs);
}
return acquireWithTickTimeout(timeout);
}
ReturnValue_t BinarySemaphoreUsingTask::takeBinarySemaphoreTickTimeout(
ReturnValue_t BinarySemaphoreUsingTask::acquireWithTickTimeout(
TickType_t timeoutTicks) {
BaseType_t returncode = ulTaskNotifyTake(pdTRUE, timeoutTicks);
if (returncode == pdPASS) {
locked = true;
return HasReturnvaluesIF::RETURN_OK;
} else {
return SEMAPHORE_TIMEOUT;
}
else {
return SemaphoreIF::SEMAPHORE_TIMEOUT;
}
}
ReturnValue_t BinarySemaphoreUsingTask::giveBinarySemaphore() {
ReturnValue_t BinarySemaphoreUsingTask::release() {
if(not locked) {
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
}
@ -69,7 +53,9 @@ uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter() const {
return notificationValue;
}
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR(TaskHandle_t taskHandle) {
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR(
TaskHandle_t taskHandle) {
uint32_t notificationValue;
BaseType_t higherPriorityTaskWoken;
xTaskNotifyAndQueryFromISR(taskHandle, 0, eNoAction, &notificationValue,
@ -80,8 +66,8 @@ uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR(TaskHandle_t taskHa
return notificationValue;
}
ReturnValue_t BinarySemaphoreUsingTask::giveBinarySemaphore(TaskHandle_t taskHandle) {
ReturnValue_t BinarySemaphoreUsingTask::release(
TaskHandle_t taskHandle) {
BaseType_t returncode = xTaskNotifyGive(taskHandle);
if (returncode == pdPASS) {
return HasReturnvaluesIF::RETURN_OK;
@ -93,7 +79,7 @@ ReturnValue_t BinarySemaphoreUsingTask::giveBinarySemaphore(TaskHandle_t taskHan
}
// Be careful with the stack size here. This is called from an ISR!
ReturnValue_t BinarySemaphoreUsingTask::giveBinarySemaphoreFromISR(
ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR(
TaskHandle_t taskHandle, BaseType_t * higherPriorityTaskWoken) {
vTaskNotifyGiveFromISR(taskHandle, higherPriorityTaskWoken);
if(*higherPriorityTaskWoken == pdPASS) {