From eabee85ba9f1dd014abc66d13e212427dc328242 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 27 May 2020 19:56:02 +0200 Subject: [PATCH] tweaked factory to have configurability --- osal/FreeRTOS/CountingSemaphUsingTask.cpp | 13 ++++++++++ osal/FreeRTOS/CountingSemaphUsingTask.h | 5 ++-- osal/FreeRTOS/SemaphoreFactory.cpp | 30 +++++++++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/osal/FreeRTOS/CountingSemaphUsingTask.cpp b/osal/FreeRTOS/CountingSemaphUsingTask.cpp index 6c5d45c7..10365d7e 100644 --- a/osal/FreeRTOS/CountingSemaphUsingTask.cpp +++ b/osal/FreeRTOS/CountingSemaphUsingTask.cpp @@ -6,3 +6,16 @@ CountingSemaphoreUsingTask::CountingSemaphoreUsingTask(uint8_t count, count(count), initCount(initCount) { handle = TaskManagement::getCurrentTaskHandle(); } + +ReturnValue_t CountingSemaphoreUsingTask::acquire( + uint32_t timeoutMs) { + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t CountingSemaphoreUsingTask::release() { + return HasReturnvaluesIF::RETURN_OK; +} + +uint8_t CountingSemaphoreUsingTask::getSemaphoreCounter() { + return 0; +} diff --git a/osal/FreeRTOS/CountingSemaphUsingTask.h b/osal/FreeRTOS/CountingSemaphUsingTask.h index c4bfb61a..7fc98e93 100644 --- a/osal/FreeRTOS/CountingSemaphUsingTask.h +++ b/osal/FreeRTOS/CountingSemaphUsingTask.h @@ -13,8 +13,9 @@ class CountingSemaphoreUsingTask: public SemaphoreIF { public: CountingSemaphoreUsingTask(uint8_t count, uint8_t initCount); - ReturnValue_t acquire(uint32_t timeoutMs); - ReturnValue_t release(); + ReturnValue_t acquire(uint32_t timeoutMs) override; + ReturnValue_t release() override; + uint8_t getSemaphoreCounter() override; private: TaskHandle_t handle; diff --git a/osal/FreeRTOS/SemaphoreFactory.cpp b/osal/FreeRTOS/SemaphoreFactory.cpp index 1eee1bac..6acdc7b7 100644 --- a/osal/FreeRTOS/SemaphoreFactory.cpp +++ b/osal/FreeRTOS/SemaphoreFactory.cpp @@ -1,5 +1,7 @@ #include +#include #include +#include #include #include @@ -7,6 +9,9 @@ SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr; const uint32_t SemaphoreIF::NO_TIMEOUT = 0; const uint32_t SemaphoreIF::MAX_TIMEOUT = portMAX_DELAY; +static const uint32_t USE_REGULAR_SEMAPHORES = 0; +static const uint32_t USE_TASK_NOTIFICATIONS = 1; + SemaphoreFactory::SemaphoreFactory() { } @@ -22,12 +27,33 @@ SemaphoreFactory* SemaphoreFactory::instance() { } SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) { - return new BinarySemaphore(); + if(argument == USE_REGULAR_SEMAPHORES) { + return new BinarySemaphore(); + } + else if(argument == USE_TASK_NOTIFICATIONS) { + return new BinarySemaphoreUsingTask(); + } + else { + sif::warning << "SemaphoreFactory: Invalid argument, return regular" + "binary semaphore" << std::endl; + return new BinarySemaphore(); + } } SemaphoreIF* SemaphoreFactory::createCountingSemaphore(uint8_t count, uint8_t initCount, uint32_t argument) { - return new CountingSemaphore(count, initCount); + if(argument == USE_REGULAR_SEMAPHORES) { + return new CountingSemaphore(count, initCount); + } + else if(argument == USE_TASK_NOTIFICATIONS) { + return new CountingSemaphoreUsingTask(count, initCount); + } + else { + sif::warning << "SemaphoreFactory: Invalid argument, return regular" + "binary semaphore" << std::endl; + return new CountingSemaphore(count, initCount); + } + } void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {