various changes, stopwatch
Semaphore: Some bugfixes, some constructors added Stopwatch: First implementation, can measure in ms(double) and ms(normal)
This commit is contained in:
@ -21,26 +21,68 @@ BinarySemaphore::~BinarySemaphore() {
|
||||
vSemaphoreDelete(handle);
|
||||
}
|
||||
|
||||
// This copy ctor is important as it prevents the assignment to a ressource
|
||||
// (other.handle) variable which is later deleted!
|
||||
BinarySemaphore::BinarySemaphore(const BinarySemaphore& other) {
|
||||
xSemaphoreCreateBinary(handle);
|
||||
if(handle == nullptr) {
|
||||
error << "Binary semaphore creation failure" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
BinarySemaphore& BinarySemaphore::operator =(const BinarySemaphore& s) {
|
||||
if(this != &s) {
|
||||
xSemaphoreCreateBinary(handle);
|
||||
if(handle == nullptr) {
|
||||
error << "Binary semaphore creation failure" << std::endl;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
|
||||
xSemaphoreCreateBinary(handle);
|
||||
if(handle == nullptr) {
|
||||
error << "Binary semaphore creation failure" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
BinarySemaphore& BinarySemaphore::operator =(
|
||||
BinarySemaphore&& s) {
|
||||
if(&s != this) {
|
||||
xSemaphoreCreateBinary(handle);
|
||||
if(handle == nullptr) {
|
||||
error << "Binary semaphore creation failure" << std::endl;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::takeBinarySemaphore(uint32_t timeoutMs) {
|
||||
if(handle == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
return SEMAPHORE_NULLPOINTER;
|
||||
}
|
||||
TickType_t timeout = portMAX_DELAY;
|
||||
if(timeoutMs != 0) {
|
||||
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||
TickType_t timeout = BinarySemaphore::NO_BLOCK_TICKS;
|
||||
if(timeoutMs == BinarySemaphore::BLOCK_TIMEOUT) {
|
||||
timeout = BinarySemaphore::BLOCK_TIMEOUT_TICKS;
|
||||
}
|
||||
else if(timeoutMs > BinarySemaphore::NO_BLOCK_TIMEOUT){
|
||||
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||
}
|
||||
|
||||
BaseType_t returncode = xSemaphoreTake(handle, timeout);
|
||||
if (returncode == pdPASS) {
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return SEMAPHORE_NOT_FOUND;
|
||||
}
|
||||
else {
|
||||
return SEMAPHORE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(TickType_t timeoutTicks) {
|
||||
ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(
|
||||
TickType_t timeoutTicks) {
|
||||
if(handle == nullptr) {
|
||||
return SEMAPHORE_NOT_FOUND;
|
||||
return SEMAPHORE_NULLPOINTER;
|
||||
}
|
||||
|
||||
BaseType_t returncode = xSemaphoreTake(handle, timeoutTicks);
|
||||
@ -53,7 +95,7 @@ ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(TickType_t timeout
|
||||
|
||||
ReturnValue_t BinarySemaphore::giveBinarySemaphore() {
|
||||
if (handle == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
return SEMAPHORE_NULLPOINTER;
|
||||
}
|
||||
BaseType_t returncode = xSemaphoreGive(handle);
|
||||
if (returncode == pdPASS) {
|
||||
@ -69,7 +111,7 @@ SemaphoreHandle_t BinarySemaphore::getSemaphore() {
|
||||
|
||||
ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) {
|
||||
if (semaphore == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
return SEMAPHORE_NULLPOINTER;
|
||||
}
|
||||
BaseType_t returncode = xSemaphoreGive(semaphore);
|
||||
if (returncode == pdPASS) {
|
||||
@ -86,11 +128,12 @@ void BinarySemaphore::resetSemaphore() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Be careful with the stack size here. This is called from an ISR!
|
||||
ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
|
||||
BaseType_t * higherPriorityTaskWoken) {
|
||||
if (semaphore == nullptr) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
return SEMAPHORE_NULLPOINTER;
|
||||
}
|
||||
BaseType_t returncode = xSemaphoreGiveFromISR(semaphore, higherPriorityTaskWoken);
|
||||
if (returncode == pdPASS) {
|
||||
@ -99,11 +142,10 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t sema
|
||||
// TODO: I don't know if this will ever happen but if it does,
|
||||
// I want to to know in case this causes issues. If it doesn't
|
||||
// we should remove this.
|
||||
TRACE_INFO("Binary Semaphore: Higher priority task unblocked!");
|
||||
TaskManagement::requestContextSwitch(CallContext::isr);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
} else {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
return SEMAPHORE_NOT_OWNED;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user