1
0
forked from fsfw/fsfw

implemented semaph factory

This commit is contained in:
2020-05-18 20:35:13 +02:00
parent 067cd95731
commit 7227c3a866
8 changed files with 177 additions and 62 deletions

View File

@ -3,21 +3,21 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h>
BinarySemaphore::BinarySemaphore() {
Semaphore::Semaphore() {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
sif::error << "Binary semaphore creation failure" << std::endl;
sif::error << "Semaphore: Binary semaph creation failure" << std::endl;
}
xSemaphoreGive(handle);
}
BinarySemaphore::~BinarySemaphore() {
Semaphore::~Semaphore() {
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) {
Semaphore::Semaphore(const Semaphore& other) {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
sif::error << "Binary semaphore creation failure" << std::endl;
@ -25,7 +25,7 @@ BinarySemaphore::BinarySemaphore(const BinarySemaphore& other) {
xSemaphoreGive(handle);
}
BinarySemaphore& BinarySemaphore::operator =(const BinarySemaphore& s) {
Semaphore& Semaphore::operator =(const Semaphore& s) {
if(this != &s) {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
@ -36,7 +36,7 @@ BinarySemaphore& BinarySemaphore::operator =(const BinarySemaphore& s) {
return *this;
}
BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
Semaphore::Semaphore(Semaphore&& s) {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
sif::error << "Binary semaphore creation failure" << std::endl;
@ -44,8 +44,8 @@ BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
xSemaphoreGive(handle);
}
BinarySemaphore& BinarySemaphore::operator =(
BinarySemaphore&& s) {
Semaphore& Semaphore::operator =(
Semaphore&& s) {
if(&s != this) {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
@ -56,15 +56,15 @@ BinarySemaphore& BinarySemaphore::operator =(
return *this;
}
ReturnValue_t BinarySemaphore::takeBinarySemaphore(uint32_t timeoutMs) {
ReturnValue_t Semaphore::takeBinarySemaphore(uint32_t timeoutMs) {
if(handle == nullptr) {
return SEMAPHORE_NULLPOINTER;
}
TickType_t timeout = BinarySemaphore::NO_BLOCK_TICKS;
if(timeoutMs == BinarySemaphore::BLOCK_TIMEOUT) {
timeout = BinarySemaphore::BLOCK_TIMEOUT_TICKS;
TickType_t timeout = Semaphore::NO_BLOCK_TICKS;
if(timeoutMs == Semaphore::BLOCK_TIMEOUT) {
timeout = Semaphore::BLOCK_TIMEOUT_TICKS;
}
else if(timeoutMs > BinarySemaphore::NO_BLOCK_TIMEOUT){
else if(timeoutMs > Semaphore::NO_BLOCK_TIMEOUT){
timeout = pdMS_TO_TICKS(timeoutMs);
}
@ -77,7 +77,7 @@ ReturnValue_t BinarySemaphore::takeBinarySemaphore(uint32_t timeoutMs) {
}
}
ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(
ReturnValue_t Semaphore::takeBinarySemaphoreTickTimeout(
TickType_t timeoutTicks) {
if(handle == nullptr) {
return SEMAPHORE_NULLPOINTER;
@ -91,7 +91,7 @@ ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(
}
}
ReturnValue_t BinarySemaphore::giveBinarySemaphore() {
ReturnValue_t Semaphore::giveBinarySemaphore() {
if (handle == nullptr) {
return SEMAPHORE_NULLPOINTER;
}
@ -103,11 +103,11 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore() {
}
}
SemaphoreHandle_t BinarySemaphore::getSemaphore() {
SemaphoreHandle_t Semaphore::getSemaphore() {
return handle;
}
ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) {
ReturnValue_t Semaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) {
if (semaphore == nullptr) {
return SEMAPHORE_NULLPOINTER;
}
@ -119,7 +119,7 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore)
}
}
void BinarySemaphore::resetSemaphore() {
void Semaphore::resetSemaphore() {
if(handle != nullptr) {
vSemaphoreDelete(handle);
handle = xSemaphoreCreateBinary();
@ -127,20 +127,20 @@ void BinarySemaphore::resetSemaphore() {
}
}
ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) {
ReturnValue_t Semaphore::acquire(uint32_t timeoutMs) {
return takeBinarySemaphore(timeoutMs);
}
ReturnValue_t BinarySemaphore::release() {
ReturnValue_t Semaphore::release() {
return giveBinarySemaphore();
}
uint8_t BinarySemaphore::getSemaphoreCounter() {
uint8_t Semaphore::getSemaphoreCounter() {
return uxSemaphoreGetCount(handle);
}
// Be careful with the stack size here. This is called from an ISR!
ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
ReturnValue_t Semaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
BaseType_t * higherPriorityTaskWoken) {
if (semaphore == nullptr) {
return SEMAPHORE_NULLPOINTER;
@ -157,3 +157,4 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t sema
return SEMAPHORE_NOT_OWNED;
}
}