From 4dd6594845deb381b80fcb2ba8e0ec27acec27e1 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 18 May 2020 19:38:02 +0200 Subject: [PATCH] integrated interface into bin semaphore --- osal/FreeRTOS/BinarySemaphore.cpp | 11 +++++++++++ osal/FreeRTOS/BinarySemaphore.h | 11 +++++++++-- tasks/SemaphoreIF.h | 14 +++++++------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index acfc53bd..c0300b81 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -132,6 +132,17 @@ void BinarySemaphore::resetSemaphore() { } } +ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) { + return takeBinarySemaphore(timeoutMs); +} + +ReturnValue_t BinarySemaphore::release() { + return giveBinarySemaphore(); +} + +uint8_t BinarySemaphore::getSemaphoreCounter() { + return uxSemaphoreGetCount(handle); +} // Be careful with the stack size here. This is called from an ISR! ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, diff --git a/osal/FreeRTOS/BinarySemaphore.h b/osal/FreeRTOS/BinarySemaphore.h index 865da8a6..8271d9d0 100644 --- a/osal/FreeRTOS/BinarySemaphore.h +++ b/osal/FreeRTOS/BinarySemaphore.h @@ -2,7 +2,7 @@ #define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ #include - +#include extern "C" { #include #include @@ -21,7 +21,8 @@ extern "C" { * @author R. Mueller * @ingroup osal */ -class BinarySemaphore: public HasReturnvaluesIF { +class BinarySemaphore: public SemaphoreIF, + public HasReturnvaluesIF { public: static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF; @@ -67,6 +68,12 @@ public: */ virtual ~BinarySemaphore(); + ReturnValue_t acquire(uint32_t timeoutMs = + BinarySemaphore::NO_BLOCK_TIMEOUT) override; + ReturnValue_t release() override; + + uint8_t getSemaphoreCounter() override; + /** * Take the binary semaphore. * If the semaphore has already been taken, the task will be blocked diff --git a/tasks/SemaphoreIF.h b/tasks/SemaphoreIF.h index cf56f6f9..616b992d 100644 --- a/tasks/SemaphoreIF.h +++ b/tasks/SemaphoreIF.h @@ -9,10 +9,11 @@ * task synchronization. */ class SemaphoreIF { +public: + virtual~ SemaphoreIF() {}; //!< Needs to be defined in implementation. static const uint32_t NO_TIMEOUT; static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF; - //! Semaphore timeout static constexpr ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(1); //! The current semaphore can not be given, because it is not owned @@ -26,24 +27,23 @@ class SemaphoreIF { * for a maximum of timeoutMs while trying to acquire the semaphore. * This can be used to achieve task synchrnization. * @param timeoutMs - * @return + * @return - c RETURN_OK for successfull acquisition */ - ReturnValue_t acquire(uint32_t timeoutMs) = 0; + virtual ReturnValue_t acquire(uint32_t timeoutMs) = 0; /** * Corrensponding call to release a semaphore. - * @return + * @return -@c RETURN_OK for successfull release */ - ReturnValue_t release() = 0; + virtual ReturnValue_t release() = 0; /** * If the semaphore is a counting semaphore then the semaphores current * count value is returned. If the semaphore is a binary semaphore then 1 * is returned if the semaphore is available, and 0 is returned if the * semaphore is not available. - * @return */ - uint8_t getSemaphoreCounter() = 0; + virtual uint8_t getSemaphoreCounter() = 0; }; #endif /* FRAMEWORK_TASKS_SEMAPHOREIF_H_ */