interface adapted

This commit is contained in:
Robin Müller 2020-08-27 16:26:00 +02:00
parent a9c8bea857
commit aacda3afc2
10 changed files with 616 additions and 606 deletions

View File

@ -1,6 +1,6 @@
#include <framework/osal/FreeRTOS/BinSemaphUsingTask.h> #include "../../osal/FreeRTOS/BinSemaphUsingTask.h"
#include <framework/osal/FreeRTOS/TaskManagement.h> #include "../../osal/FreeRTOS/TaskManagement.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include "../../serviceinterface/ServiceInterfaceStream.h"
BinarySemaphoreUsingTask::BinarySemaphoreUsingTask() { BinarySemaphoreUsingTask::BinarySemaphoreUsingTask() {
handle = TaskManagement::getCurrentTaskHandle(); handle = TaskManagement::getCurrentTaskHandle();
@ -16,19 +16,23 @@ BinarySemaphoreUsingTask::~BinarySemaphoreUsingTask() {
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr); xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
} }
ReturnValue_t BinarySemaphoreUsingTask::acquire(uint32_t timeoutMs) { ReturnValue_t BinarySemaphoreUsingTask::acquire(TimeoutType timeoutType,
TickType_t timeout = SemaphoreIF::POLLING; uint32_t timeoutMs) {
if(timeoutMs == SemaphoreIF::BLOCKING) { TickType_t timeout = 0;
timeout = SemaphoreIF::BLOCKING; if(timeoutType == TimeoutType::POLLING) {
} timeout = 0;
else if(timeoutMs > SemaphoreIF::POLLING){ }
timeout = pdMS_TO_TICKS(timeoutMs); else if(timeoutType == TimeoutType::WAITING){
} timeout = pdMS_TO_TICKS(timeoutMs);
return acquireWithTickTimeout(timeout); }
else {
timeout = portMAX_DELAY;
}
return acquireWithTickTimeout(timeoutType, timeout);
} }
ReturnValue_t BinarySemaphoreUsingTask::acquireWithTickTimeout( ReturnValue_t BinarySemaphoreUsingTask::acquireWithTickTimeout(
TickType_t timeoutTicks) { TimeoutType timeoutType, TickType_t timeoutTicks) {
BaseType_t returncode = ulTaskNotifyTake(pdTRUE, timeoutTicks); BaseType_t returncode = ulTaskNotifyTake(pdTRUE, timeoutTicks);
if (returncode == pdPASS) { if (returncode == pdPASS) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;

View File

@ -1,8 +1,8 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_ #ifndef FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_
#define FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_ #define FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_
#include <framework/returnvalues/HasReturnvaluesIF.h> #include "../../returnvalues/HasReturnvaluesIF.h"
#include <framework/tasks/SemaphoreIF.h> #include "../../tasks/SemaphoreIF.h"
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/task.h> #include <freertos/task.h>
@ -25,8 +25,8 @@ public:
//! @brief Default dtor //! @brief Default dtor
virtual~ BinarySemaphoreUsingTask(); virtual~ BinarySemaphoreUsingTask();
ReturnValue_t acquire(uint32_t timeoutMs = ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
SemaphoreIF::BLOCKING) override; uint32_t timeoutMs = portMAX_DELAY) override;
ReturnValue_t release() override; ReturnValue_t release() override;
uint8_t getSemaphoreCounter() const override; uint8_t getSemaphoreCounter() const override;
static uint8_t getSemaphoreCounter(TaskHandle_t taskHandle); static uint8_t getSemaphoreCounter(TaskHandle_t taskHandle);
@ -39,8 +39,9 @@ public:
* @return - @c RETURN_OK on success * @return - @c RETURN_OK on success
* - @c RETURN_FAILED on failure * - @c RETURN_FAILED on failure
*/ */
ReturnValue_t acquireWithTickTimeout(TickType_t timeoutTicks = ReturnValue_t acquireWithTickTimeout(
SemaphoreIF::BLOCKING); TimeoutType timeoutType = TimeoutType::BLOCKING,
TickType_t timeoutTicks = portMAX_DELAY);
/** /**
* Get handle to the task related to the semaphore. * Get handle to the task related to the semaphore.

View File

@ -1,6 +1,6 @@
#include <framework/osal/FreeRTOS/BinarySemaphore.h> #include "../../osal/FreeRTOS/BinarySemaphore.h"
#include <framework/osal/FreeRTOS/TaskManagement.h> #include "../../osal/FreeRTOS/TaskManagement.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include "../../serviceinterface/ServiceInterfaceStream.h"
BinarySemaphore::BinarySemaphore() { BinarySemaphore::BinarySemaphore() {
handle = xSemaphoreCreateBinary(); handle = xSemaphoreCreateBinary();
@ -35,18 +35,23 @@ BinarySemaphore& BinarySemaphore::operator =(
return *this; return *this;
} }
ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) { ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType,
TickType_t timeout = SemaphoreIF::POLLING; uint32_t timeoutMs) {
if(timeoutMs == SemaphoreIF::BLOCKING) { TickType_t timeout = 0;
timeout = SemaphoreIF::BLOCKING; if(timeoutType == TimeoutType::POLLING) {
timeout = 0;
} }
else if(timeoutMs > SemaphoreIF::POLLING){ else if(timeoutType == TimeoutType::WAITING){
timeout = pdMS_TO_TICKS(timeoutMs); timeout = pdMS_TO_TICKS(timeoutMs);
} }
return acquireWithTickTimeout(timeout); else {
timeout = portMAX_DELAY;
}
return acquireWithTickTimeout(timeoutType, timeout);
} }
ReturnValue_t BinarySemaphore::acquireWithTickTimeout(TickType_t timeoutTicks) { ReturnValue_t BinarySemaphore::acquireWithTickTimeout(TimeoutType timeoutType,
TickType_t timeoutTicks) {
if(handle == nullptr) { if(handle == nullptr) {
return SemaphoreIF::SEMAPHORE_INVALID; return SemaphoreIF::SEMAPHORE_INVALID;
} }

View File

@ -1,8 +1,8 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ #ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
#define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ #define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
#include <framework/returnvalues/HasReturnvaluesIF.h> #include "../../returnvalues/HasReturnvaluesIF.h"
#include <framework/tasks/SemaphoreIF.h> #include "../../tasks/SemaphoreIF.h"
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
#include <freertos/semphr.h> #include <freertos/semphr.h>
@ -52,8 +52,8 @@ public:
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout * -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
*/ */
ReturnValue_t acquire(uint32_t timeoutMs = ReturnValue_t acquire(TimeoutType timeoutType =
SemaphoreIF::BLOCKING) override; TimeoutType::BLOCKING, uint32_t timeoutMs = portMAX_DELAY) override;
/** /**
* Same as lockBinarySemaphore() with timeout in FreeRTOS ticks. * Same as lockBinarySemaphore() with timeout in FreeRTOS ticks.
@ -61,8 +61,8 @@ public:
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout * -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
*/ */
ReturnValue_t acquireWithTickTimeout(TickType_t timeoutTicks = ReturnValue_t acquireWithTickTimeout(TimeoutType timeoutType =
SemaphoreIF::BLOCKING); TimeoutType::BLOCKING, TickType_t timeoutTicks = portMAX_DELAY);
/** /**
* Release the binary semaphore. * Release the binary semaphore.

View File

@ -1,6 +1,6 @@
#include <framework/osal/FreeRTOS/CountingSemaphUsingTask.h> #include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
#include <framework/osal/FreeRTOS/TaskManagement.h> #include "../../osal/FreeRTOS/TaskManagement.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include "../../serviceinterface/ServiceInterfaceStream.h"
CountingSemaphoreUsingTask::CountingSemaphoreUsingTask(const uint8_t maxCount, CountingSemaphoreUsingTask::CountingSemaphoreUsingTask(const uint8_t maxCount,
uint8_t initCount): maxCount(maxCount) { uint8_t initCount): maxCount(maxCount) {
@ -37,20 +37,24 @@ CountingSemaphoreUsingTask::~CountingSemaphoreUsingTask() {
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr); xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
} }
ReturnValue_t CountingSemaphoreUsingTask::acquire(uint32_t timeoutMs) { ReturnValue_t CountingSemaphoreUsingTask::acquire(TimeoutType timeoutType,
TickType_t timeout = SemaphoreIF::POLLING; uint32_t timeoutMs) {
if(timeoutMs == SemaphoreIF::BLOCKING) { TickType_t timeout = 0;
timeout = SemaphoreIF::BLOCKING; if(timeoutType == TimeoutType::POLLING) {
} timeout = 0;
else if(timeoutMs > SemaphoreIF::POLLING){ }
timeout = pdMS_TO_TICKS(timeoutMs); else if(timeoutType == TimeoutType::WAITING){
} timeout = pdMS_TO_TICKS(timeoutMs);
return acquireWithTickTimeout(timeout); }
else {
timeout = portMAX_DELAY;
}
return acquireWithTickTimeout(timeoutType, timeout);
} }
ReturnValue_t CountingSemaphoreUsingTask::acquireWithTickTimeout( ReturnValue_t CountingSemaphoreUsingTask::acquireWithTickTimeout(
TickType_t timeoutTicks) { TimeoutType timeoutType, TickType_t timeoutTicks) {
// Decrement notfication value without resetting it. // Decrement notfication value without resetting it.
BaseType_t oldCount = ulTaskNotifyTake(pdFALSE, timeoutTicks); BaseType_t oldCount = ulTaskNotifyTake(pdFALSE, timeoutTicks);
if (getSemaphoreCounter() == oldCount - 1) { if (getSemaphoreCounter() == oldCount - 1) {

View File

@ -1,8 +1,8 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_ #ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_
#define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_ #define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_
#include <framework/osal/FreeRTOS/CountingSemaphUsingTask.h> #include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
#include <framework/tasks/SemaphoreIF.h> #include "../../tasks/SemaphoreIF.h"
extern "C" { extern "C" {
#include <freertos/FreeRTOS.h> #include <freertos/FreeRTOS.h>
@ -31,7 +31,8 @@ public:
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout * -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
*/ */
ReturnValue_t acquire(uint32_t timeoutMs = SemaphoreIF::BLOCKING) override; ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
uint32_t timeoutMs = portMAX_DELAY) override;
/** /**
* Release a semaphore, increasing the number of available counting * Release a semaphore, increasing the number of available counting
@ -61,7 +62,8 @@ public:
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout * -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
*/ */
ReturnValue_t acquireWithTickTimeout( ReturnValue_t acquireWithTickTimeout(
TickType_t timeoutTicks = SemaphoreIF::BLOCKING); TimeoutType timeoutType = TimeoutType::BLOCKING,
TickType_t timeoutTicks = portMAX_DELAY);
/** /**
* Get handle to the task related to the semaphore. * Get handle to the task related to the semaphore.

View File

@ -1,6 +1,6 @@
#include <framework/osal/FreeRTOS/CountingSemaphore.h> #include "../../osal/FreeRTOS/CountingSemaphore.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include "../../serviceinterface/ServiceInterfaceStream.h"
#include <framework/osal/FreeRTOS/TaskManagement.h> #include "../../osal/FreeRTOS/TaskManagement.h"
#include <freertos/semphr.h> #include <freertos/semphr.h>

View File

@ -1,6 +1,6 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_ #ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_
#define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_ #define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_
#include <framework/osal/FreeRTOS/BinarySemaphore.h> #include "../../osal/FreeRTOS/BinarySemaphore.h"
/** /**
* @brief Counting semaphores, which can be acquire more than once. * @brief Counting semaphores, which can be acquire more than once.

View File

@ -1,13 +1,11 @@
#include <framework/osal/FreeRTOS/BinarySemaphore.h> #include "../../osal/FreeRTOS/BinarySemaphore.h"
#include <framework/osal/FreeRTOS/BinSemaphUsingTask.h> #include "../../osal/FreeRTOS/BinSemaphUsingTask.h"
#include <framework/osal/FreeRTOS/CountingSemaphore.h> #include "../../osal/FreeRTOS/CountingSemaphore.h"
#include <framework/osal/FreeRTOS/CountingSemaphUsingTask.h> #include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
#include <framework/tasks/SemaphoreFactory.h> #include "../../tasks/SemaphoreFactory.h"
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include "../../serviceinterface/ServiceInterfaceStream.h"
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr; SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
const uint32_t SemaphoreIF::POLLING = 0;
const uint32_t SemaphoreIF::BLOCKING = portMAX_DELAY;
static const uint32_t USE_REGULAR_SEMAPHORES = 0; static const uint32_t USE_REGULAR_SEMAPHORES = 0;
static const uint32_t USE_TASK_NOTIFICATIONS = 1; static const uint32_t USE_TASK_NOTIFICATIONS = 1;

View File

@ -1,7 +1,7 @@
#ifndef FRAMEWORK_TASKS_SEMAPHOREIF_H_ #ifndef FRAMEWORK_TASKS_SEMAPHOREIF_H_
#define FRAMEWORK_TASKS_SEMAPHOREIF_H_ #define FRAMEWORK_TASKS_SEMAPHOREIF_H_
#include <framework/returnvalues/FwClassIds.h> #include "../returnvalues/FwClassIds.h"
#include <framework/returnvalues/HasReturnvaluesIF.h> #include "../returnvalues/HasReturnvaluesIF.h"
#include <cstdint> #include <cstdint>
/** /**
@ -20,21 +20,16 @@
*/ */
class SemaphoreIF { class SemaphoreIF {
public: public:
/**
* Different types of timeout for the mutex lock.
*/
enum TimeoutType {
POLLING, //!< If mutex is not available, return immediately
WAITING, //!< Wait a specified time for the mutex to become available
BLOCKING //!< Block indefinitely until the mutex becomes available.
};
virtual~ SemaphoreIF() {}; virtual~ SemaphoreIF() {};
/**
* @brief Timeout value used for polling lock attempt.
* @details
* If the lock is not successfull, MUTEX_TIMEOUT will be returned
* immediately. Value needs to be defined in implementation.
*/
static const uint32_t POLLING;
/**
* @brief Timeout value used for permanent blocking lock attempt.
* @details
* The task will be blocked (indefinitely) until the mutex is unlocked.
* Value needs to be defined in implementation.
*/
static const uint32_t BLOCKING;
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF; static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
//! Semaphore timeout //! Semaphore timeout
@ -52,7 +47,8 @@ public:
* @param timeoutMs * @param timeoutMs
* @return - c RETURN_OK for successfull acquisition * @return - c RETURN_OK for successfull acquisition
*/ */
virtual ReturnValue_t acquire(uint32_t timeoutMs) = 0; virtual ReturnValue_t acquire(TimeoutType timeoutType =
TimeoutType::BLOCKING, uint32_t timeoutMs = 0) = 0;
/** /**
* Corrensponding call to release a semaphore. * Corrensponding call to release a semaphore.