WIP: somethings wrong.. #19
@ -84,7 +84,7 @@ SemaphoreHandle_t BinarySemaphore::getSemaphore() {
|
|||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) {
|
ReturnValue_t BinarySemaphore::release(SemaphoreHandle_t semaphore) {
|
||||||
if (semaphore == nullptr) {
|
if (semaphore == nullptr) {
|
||||||
return SemaphoreIF::SEMAPHORE_NULLPOINTER;
|
return SemaphoreIF::SEMAPHORE_NULLPOINTER;
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Be careful with the stack size here. This is called from an ISR!
|
// Be careful with the stack size here. This is called from an ISR!
|
||||||
ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(
|
ReturnValue_t BinarySemaphore::releaseFromISR(
|
||||||
SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) {
|
SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) {
|
||||||
if (semaphore == nullptr) {
|
if (semaphore == nullptr) {
|
||||||
return SemaphoreIF::SEMAPHORE_NULLPOINTER;
|
return SemaphoreIF::SEMAPHORE_NULLPOINTER;
|
||||||
|
@ -52,7 +52,7 @@ public:
|
|||||||
* for example by an ISR or another task.
|
* for example by an ISR or another task.
|
||||||
* @param timeoutMs
|
* @param timeoutMs
|
||||||
* @return -@c RETURN_OK on success
|
* @return -@c RETURN_OK on success
|
||||||
* -@c RETURN_FAILED on failure
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||||
*/
|
*/
|
||||||
ReturnValue_t acquire(uint32_t timeoutMs =
|
ReturnValue_t acquire(uint32_t timeoutMs =
|
||||||
SemaphoreIF::NO_TIMEOUT) override;
|
SemaphoreIF::NO_TIMEOUT) override;
|
||||||
@ -60,16 +60,17 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Same as lockBinarySemaphore() with timeout in FreeRTOS ticks.
|
* Same as lockBinarySemaphore() with timeout in FreeRTOS ticks.
|
||||||
* @param timeoutTicks
|
* @param timeoutTicks
|
||||||
* @return - @c RETURN_OK on success
|
* @return -@c RETURN_OK on success
|
||||||
* - @c RETURN_FAILED on failure
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||||
*/
|
*/
|
||||||
ReturnValue_t acquireWithTickTimeout(TickType_t timeoutTicks =
|
ReturnValue_t acquireWithTickTimeout(TickType_t timeoutTicks =
|
||||||
BinarySemaphore::NO_TIMEOUT);
|
BinarySemaphore::NO_TIMEOUT);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Give back the binary semaphore
|
* Release the binary semaphore.
|
||||||
* @return - @c RETURN_OK on success
|
* @return -@c RETURN_OK on success
|
||||||
* - @c RETURN_FAILED on failure
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||||
|
* already available.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t release() override;
|
ReturnValue_t release() override;
|
||||||
|
|
||||||
@ -82,20 +83,22 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Wrapper function to give back semaphore from handle
|
* Wrapper function to give back semaphore from handle
|
||||||
* @param semaphore
|
* @param semaphore
|
||||||
* @return - @c RETURN_OK on success
|
* @return -@c RETURN_OK on success
|
||||||
* - @c RETURN_FAILED on failure
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||||
|
* already available.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore);
|
static ReturnValue_t release(SemaphoreHandle_t semaphore);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper function to give back semaphore from handle when called from an ISR
|
* Wrapper function to give back semaphore from handle when called from an ISR
|
||||||
* @param semaphore
|
* @param semaphore
|
||||||
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority
|
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority
|
||||||
* was unblocked
|
* was unblocked
|
||||||
* @return - @c RETURN_OK on success
|
* @return -@c RETURN_OK on success
|
||||||
* - @c RETURN_FAILED on failure
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||||
|
* already available.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
|
static ReturnValue_t releaseFromISR(SemaphoreHandle_t semaphore,
|
||||||
BaseType_t * higherPriorityTaskWoken);
|
BaseType_t * higherPriorityTaskWoken);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -12,7 +12,7 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* @brief Couting Semaphore implementation which uses the notification value
|
* @brief Couting Semaphore implementation which uses the notification value
|
||||||
* of the task. The notification value should therefore not be used
|
* of the task. The notification value should therefore not be used
|
||||||
* for other purposes
|
* for other purposes.
|
||||||
* @details
|
* @details
|
||||||
* Additional information: https://www.freertos.org/RTOS-task-notifications.html
|
* Additional information: https://www.freertos.org/RTOS-task-notifications.html
|
||||||
* and general semaphore documentation.
|
* and general semaphore documentation.
|
||||||
@ -22,17 +22,37 @@ public:
|
|||||||
CountingSemaphoreUsingTask(const uint8_t maxCount, uint8_t initCount);
|
CountingSemaphoreUsingTask(const uint8_t maxCount, uint8_t initCount);
|
||||||
virtual ~CountingSemaphoreUsingTask();
|
virtual ~CountingSemaphoreUsingTask();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
ReturnValue_t acquire(uint32_t timeoutMs = SemaphoreIF::NO_TIMEOUT) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
ReturnValue_t release() override;
|
||||||
|
|
||||||
uint8_t getSemaphoreCounter() const override;
|
uint8_t getSemaphoreCounter() const override;
|
||||||
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t task);
|
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t task);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Acquire, using a timeout value in ticks
|
* Acquire with a timeout value in ticks
|
||||||
* @param timeoutTicks
|
* @param timeoutTicks
|
||||||
* @return
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||||
*/
|
*/
|
||||||
ReturnValue_t acquireWithTickTimeout(
|
ReturnValue_t acquireWithTickTimeout(
|
||||||
TickType_t timeoutTicks= SemaphoreIF::NO_TIMEOUT);
|
TickType_t timeoutTicks = SemaphoreIF::NO_TIMEOUT);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get handle to the task related to the semaphore.
|
* Get handle to the task related to the semaphore.
|
||||||
@ -43,13 +63,17 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Release semaphore of task by supplying task handle
|
* Release semaphore of task by supplying task handle
|
||||||
* @param taskToNotify
|
* @param taskToNotify
|
||||||
* @return
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
||||||
|
* already available.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t release(TaskHandle_t taskToNotify);
|
static ReturnValue_t release(TaskHandle_t taskToNotify);
|
||||||
/**
|
/**
|
||||||
* Release seamphore of a task from an ISR.
|
* Release seamphore of a task from an ISR.
|
||||||
* @param taskToNotify
|
* @param taskToNotify
|
||||||
* @return
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
||||||
|
* already available.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t releaseFromISR(TaskHandle_t taskToNotify,
|
static ReturnValue_t releaseFromISR(TaskHandle_t taskToNotify,
|
||||||
BaseType_t* higherPriorityTaskWoken);
|
BaseType_t* higherPriorityTaskWoken);
|
||||||
|
@ -21,6 +21,10 @@ public:
|
|||||||
CountingSemaphore (CountingSemaphore &&);
|
CountingSemaphore (CountingSemaphore &&);
|
||||||
//! @brief Move assignment
|
//! @brief Move assignment
|
||||||
CountingSemaphore & operator=(CountingSemaphore &&);
|
CountingSemaphore & operator=(CountingSemaphore &&);
|
||||||
|
|
||||||
|
/* Same API as binary semaphore otherwise. acquire() can be called
|
||||||
|
* until there are not semaphores left and release() can be called
|
||||||
|
* until maxCount is reached. */
|
||||||
private:
|
private:
|
||||||
const uint8_t maxCount;
|
const uint8_t maxCount;
|
||||||
uint8_t initCount = 0;
|
uint8_t initCount = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user