improved bin semaph implementation
This commit is contained in:
parent
88e3dc15b2
commit
c4e60946d3
@ -37,7 +37,7 @@ BinarySemaphore& BinarySemaphore::operator =(
|
|||||||
|
|
||||||
ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) {
|
ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) {
|
||||||
if(handle == nullptr) {
|
if(handle == nullptr) {
|
||||||
return SEMAPHORE_NULLPOINTER;
|
return SemaphoreIF::SEMAPHORE_NULLPOINTER;
|
||||||
}
|
}
|
||||||
TickType_t timeout = SemaphoreIF::NO_TIMEOUT;
|
TickType_t timeout = SemaphoreIF::NO_TIMEOUT;
|
||||||
if(timeoutMs == SemaphoreIF::MAX_TIMEOUT) {
|
if(timeoutMs == SemaphoreIF::MAX_TIMEOUT) {
|
||||||
@ -59,14 +59,14 @@ ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) {
|
|||||||
ReturnValue_t BinarySemaphore::acquireWithTickTimeout(
|
ReturnValue_t BinarySemaphore::acquireWithTickTimeout(
|
||||||
TickType_t timeoutTicks) {
|
TickType_t timeoutTicks) {
|
||||||
if(handle == nullptr) {
|
if(handle == nullptr) {
|
||||||
return SEMAPHORE_NULLPOINTER;
|
return SemaphoreIF::SEMAPHORE_NULLPOINTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseType_t returncode = xSemaphoreTake(handle, timeoutTicks);
|
BaseType_t returncode = xSemaphoreTake(handle, timeoutTicks);
|
||||||
if (returncode == pdPASS) {
|
if (returncode == pdPASS) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
} else {
|
} else {
|
||||||
return SEMAPHORE_TIMEOUT;
|
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,13 +82,17 @@ ReturnValue_t BinarySemaphore::release() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphore::getSemaphoreCounter() {
|
||||||
|
return uxSemaphoreGetCount(handle);
|
||||||
|
}
|
||||||
|
|
||||||
SemaphoreHandle_t BinarySemaphore::getSemaphore() {
|
SemaphoreHandle_t BinarySemaphore::getSemaphore() {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) {
|
ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) {
|
||||||
if (semaphore == nullptr) {
|
if (semaphore == nullptr) {
|
||||||
return SEMAPHORE_NULLPOINTER;
|
return SemaphoreIF::SEMAPHORE_NULLPOINTER;
|
||||||
}
|
}
|
||||||
BaseType_t returncode = xSemaphoreGive(semaphore);
|
BaseType_t returncode = xSemaphoreGive(semaphore);
|
||||||
if (returncode == pdPASS) {
|
if (returncode == pdPASS) {
|
||||||
@ -96,17 +100,13 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore)
|
|||||||
} else {
|
} else {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t BinarySemaphore::getSemaphoreCounter() {
|
|
||||||
return uxSemaphoreGetCount(handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Be careful with the stack size here. This is called from an ISR!
|
// Be careful with the stack size here. This is called from an ISR!
|
||||||
ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(
|
ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(
|
||||||
SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) {
|
SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) {
|
||||||
if (semaphore == nullptr) {
|
if (semaphore == nullptr) {
|
||||||
return SEMAPHORE_NULLPOINTER;
|
return SemaphoreIF::SEMAPHORE_NULLPOINTER;
|
||||||
}
|
}
|
||||||
BaseType_t returncode = xSemaphoreGiveFromISR(semaphore,
|
BaseType_t returncode = xSemaphoreGiveFromISR(semaphore,
|
||||||
higherPriorityTaskWoken);
|
higherPriorityTaskWoken);
|
||||||
@ -117,7 +117,8 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(
|
|||||||
TaskManagement::requestContextSwitch(CallContext::isr);
|
TaskManagement::requestContextSwitch(CallContext::isr);
|
||||||
}
|
}
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
} else {
|
}
|
||||||
return SEMAPHORE_NOT_OWNED;
|
else {
|
||||||
|
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user