2020-05-27 19:46:56 +02:00
|
|
|
#ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_
|
|
|
|
#define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_
|
|
|
|
|
|
|
|
#include <framework/osal/FreeRTOS/CountingSemaphUsingTask.h>
|
|
|
|
#include <framework/tasks/SemaphoreIF.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
#include <freertos/task.h>
|
|
|
|
}
|
|
|
|
|
2020-05-27 23:29:06 +02:00
|
|
|
/**
|
|
|
|
* @brief Couting Semaphore implementation which uses the notification value
|
|
|
|
* of the task. The notification value should therefore not be used
|
2020-05-27 23:41:59 +02:00
|
|
|
* for other purposes.
|
2020-05-27 23:29:06 +02:00
|
|
|
* @details
|
|
|
|
* Additional information: https://www.freertos.org/RTOS-task-notifications.html
|
|
|
|
* and general semaphore documentation.
|
|
|
|
*/
|
2020-05-27 19:46:56 +02:00
|
|
|
class CountingSemaphoreUsingTask: public SemaphoreIF {
|
|
|
|
public:
|
2020-05-27 22:12:52 +02:00
|
|
|
CountingSemaphoreUsingTask(const uint8_t maxCount, uint8_t initCount);
|
2020-05-27 23:29:06 +02:00
|
|
|
virtual ~CountingSemaphoreUsingTask();
|
2020-05-27 19:46:56 +02:00
|
|
|
|
2020-05-27 23:41:59 +02:00
|
|
|
/**
|
|
|
|
* Acquire the counting semaphore.
|
|
|
|
* If no semaphores are available, the task will be blocked
|
|
|
|
* for a maximum of #timeoutMs or until one is given back,
|
|
|
|
* for example by an ISR or another task.
|
|
|
|
* @param timeoutMs
|
|
|
|
* @return -@c RETURN_OK on success
|
|
|
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
|
|
|
*/
|
2020-06-02 22:19:48 +02:00
|
|
|
ReturnValue_t acquire(uint32_t timeoutMs = SemaphoreIF::BLOCKING) override;
|
2020-05-27 23:41:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Release a semaphore, increasing the number of available counting
|
|
|
|
* semaphores up to the #maxCount value.
|
|
|
|
* @return -@c RETURN_OK on success
|
|
|
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
|
|
|
* already available.
|
|
|
|
*/
|
2020-05-27 19:56:02 +02:00
|
|
|
ReturnValue_t release() override;
|
2020-05-27 23:41:59 +02:00
|
|
|
|
2020-05-27 21:33:34 +02:00
|
|
|
uint8_t getSemaphoreCounter() const override;
|
2020-05-29 03:03:48 +02:00
|
|
|
/**
|
|
|
|
* Get the semaphore counter from an ISR.
|
|
|
|
* @param task
|
|
|
|
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
|
|
|
* a higher priority was unblocked. A context switch should be requested
|
|
|
|
* from an ISR if this is the case (see TaskManagement functions)
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t task,
|
|
|
|
BaseType_t* higherPriorityTaskWoken);
|
2020-05-27 23:41:59 +02:00
|
|
|
|
2020-05-27 22:12:52 +02:00
|
|
|
/**
|
2020-05-27 23:41:59 +02:00
|
|
|
* Acquire with a timeout value in ticks
|
2020-05-27 22:12:52 +02:00
|
|
|
* @param timeoutTicks
|
2020-05-27 23:41:59 +02:00
|
|
|
* @return -@c RETURN_OK on success
|
|
|
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
2020-05-27 22:12:52 +02:00
|
|
|
*/
|
|
|
|
ReturnValue_t acquireWithTickTimeout(
|
2020-06-02 22:19:48 +02:00
|
|
|
TickType_t timeoutTicks = SemaphoreIF::BLOCKING);
|
2020-05-27 22:12:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get handle to the task related to the semaphore.
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
TaskHandle_t getTaskHandle();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release semaphore of task by supplying task handle
|
|
|
|
* @param taskToNotify
|
2020-05-27 23:41:59 +02:00
|
|
|
* @return -@c RETURN_OK on success
|
|
|
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
|
|
|
* already available.
|
2020-05-27 22:12:52 +02:00
|
|
|
*/
|
|
|
|
static ReturnValue_t release(TaskHandle_t taskToNotify);
|
|
|
|
/**
|
|
|
|
* Release seamphore of a task from an ISR.
|
|
|
|
* @param taskToNotify
|
2020-05-29 03:03:48 +02:00
|
|
|
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
|
|
|
* a higher priority was unblocked. A context switch should be requested
|
|
|
|
* from an ISR if this is the case (see TaskManagement functions)
|
2020-05-27 23:41:59 +02:00
|
|
|
* @return -@c RETURN_OK on success
|
|
|
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
|
|
|
* already available.
|
2020-05-27 22:12:52 +02:00
|
|
|
*/
|
|
|
|
static ReturnValue_t releaseFromISR(TaskHandle_t taskToNotify,
|
|
|
|
BaseType_t* higherPriorityTaskWoken);
|
2020-05-27 19:46:56 +02:00
|
|
|
|
2020-05-29 03:03:48 +02:00
|
|
|
uint8_t getMaxCount() const;
|
|
|
|
|
2020-05-27 19:46:56 +02:00
|
|
|
private:
|
|
|
|
TaskHandle_t handle;
|
2020-05-27 21:27:31 +02:00
|
|
|
const uint8_t maxCount;
|
2020-05-27 19:46:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_ */
|