1
0
forked from fsfw/fsfw

retval fix, unittest running again

This commit is contained in:
2020-05-29 03:03:48 +02:00
parent 3d2935ac69
commit da403c01d0
5 changed files with 94 additions and 112 deletions

View File

@ -25,16 +25,15 @@ CountingSemaphoreUsingTask::CountingSemaphoreUsingTask(const uint8_t maxCount,
"current notification value is not 0. Please ensure the "
"notification value is not used for other purposes!" << std::endl;
}
while(currentCount != initCount) {
for(int i = 0; i < initCount; i++) {
xTaskNotifyGive(handle);
currentCount++;
}
}
CountingSemaphoreUsingTask::~CountingSemaphoreUsingTask() {
// Clear notification value on destruction.
// If this is not desired, don't call the destructor
// (or implement a boolea which disables the reset)
// (or implement a boolean which disables the reset)
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
}
@ -55,7 +54,6 @@ ReturnValue_t CountingSemaphoreUsingTask::acquireWithTickTimeout(
// Decrement notfication value without resetting it.
BaseType_t oldCount = ulTaskNotifyTake(pdFALSE, timeoutTicks);
if (getSemaphoreCounter() == oldCount - 1) {
currentCount --;
return HasReturnvaluesIF::RETURN_OK;
}
else {
@ -64,41 +62,10 @@ ReturnValue_t CountingSemaphoreUsingTask::acquireWithTickTimeout(
}
ReturnValue_t CountingSemaphoreUsingTask::release() {
if(currentCount == maxCount) {
if(getSemaphoreCounter() == maxCount) {
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
}
BaseType_t returncode = xTaskNotifyGive(handle);
if (returncode == pdPASS) {
currentCount++;
return HasReturnvaluesIF::RETURN_OK;
}
else {
// This should never happen
return HasReturnvaluesIF::RETURN_FAILED;
}
}
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounter() const {
uint32_t notificationValue = 0;
xTaskNotifyAndQuery(handle, 0, eNoAction, &notificationValue);
return notificationValue;
}
TaskHandle_t CountingSemaphoreUsingTask::getTaskHandle() {
return handle;
}
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounterFromISR(
TaskHandle_t task) {
uint32_t notificationValue;
BaseType_t higherPriorityTaskWoken = 0;
xTaskNotifyAndQueryFromISR(task, 0, eNoAction, &notificationValue,
&higherPriorityTaskWoken);
if(higherPriorityTaskWoken == pdTRUE) {
TaskManagement::requestContextSwitch(CallContext::isr);
}
return notificationValue;
return release(handle);
}
ReturnValue_t CountingSemaphoreUsingTask::release(
@ -113,13 +80,31 @@ ReturnValue_t CountingSemaphoreUsingTask::release(
}
}
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounter() const {
uint32_t notificationValue = 0;
xTaskNotifyAndQuery(handle, 0, eNoAction, &notificationValue);
return notificationValue;
}
TaskHandle_t CountingSemaphoreUsingTask::getTaskHandle() {
return handle;
}
ReturnValue_t CountingSemaphoreUsingTask::releaseFromISR(
TaskHandle_t taskToNotify, BaseType_t* higherPriorityTaskWoken) {
vTaskNotifyGiveFromISR(taskToNotify, 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;
}
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounterFromISR(
TaskHandle_t task, BaseType_t* higherPriorityTaskWoken) {
uint32_t notificationValue;
xTaskNotifyAndQueryFromISR(task, 0, eNoAction, &notificationValue,
higherPriorityTaskWoken);
return notificationValue;
}
uint8_t CountingSemaphoreUsingTask::getMaxCount() const {
return maxCount;
}