fsfw/osal/FreeRTOS/CountingSemaphUsingTask.h

88 lines
2.7 KiB
C
Raw Normal View History

#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.
*/
class CountingSemaphoreUsingTask: public SemaphoreIF {
public:
CountingSemaphoreUsingTask(const uint8_t maxCount, uint8_t initCount);
2020-05-27 23:29:06 +02:00
virtual ~CountingSemaphoreUsingTask();
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
*/
ReturnValue_t acquire(uint32_t timeoutMs = SemaphoreIF::NO_TIMEOUT) 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.
*/
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;
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t task);
2020-05-27 23:41:59 +02:00
/**
2020-05-27 23:41:59 +02:00
* Acquire with a timeout value in ticks
* @param timeoutTicks
2020-05-27 23:41:59 +02:00
* @return -@c RETURN_OK on success
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
*/
ReturnValue_t acquireWithTickTimeout(
2020-05-27 23:41:59 +02:00
TickType_t timeoutTicks = SemaphoreIF::NO_TIMEOUT);
/**
* 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.
*/
static ReturnValue_t release(TaskHandle_t taskToNotify);
/**
* Release seamphore of a task from an ISR.
* @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.
*/
static ReturnValue_t releaseFromISR(TaskHandle_t taskToNotify,
BaseType_t* higherPriorityTaskWoken);
private:
TaskHandle_t handle;
2020-05-27 21:27:31 +02:00
const uint8_t maxCount;
uint8_t currentCount = 0;
};
#endif /* FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_ */