Implement BinarySemaphore freertos wrapper
This commit is contained in:
parent
e2a64ac231
commit
908a6becba
2 changed files with 46 additions and 0 deletions
26
modules/control/Firmware/src/FreeRTOS/BinarySemaphore.cpp
Normal file
26
modules/control/Firmware/src/FreeRTOS/BinarySemaphore.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <FreeRTOS/BinarySemaphore.h>
|
||||
#include <etl/utility.h>
|
||||
|
||||
freertos::BinarySemaphore::BinarySemaphore()
|
||||
: handle{xSemaphoreCreateBinary()} {}
|
||||
freertos::BinarySemaphore::BinarySemaphore(BinarySemaphore &&other) noexcept {
|
||||
handle = etl::move(other.handle);
|
||||
}
|
||||
freertos::BinarySemaphore::~BinarySemaphore() { vSemaphoreDelete(handle); }
|
||||
auto freertos::BinarySemaphore::operator=(
|
||||
const BinarySemaphore &&other) noexcept -> BinarySemaphore & {
|
||||
handle = etl::move(other.handle);
|
||||
return *this;
|
||||
}
|
||||
auto freertos::BinarySemaphore::take(TickType_t timeout) -> bool {
|
||||
BaseType_t success = xSemaphoreTake(handle, timeout);
|
||||
return success == pdTRUE ? true : false;
|
||||
}
|
||||
auto freertos::BinarySemaphore::give() -> bool {
|
||||
BaseType_t success = xSemaphoreGive(handle);
|
||||
return success == pdTRUE ? true : false;
|
||||
}
|
||||
|
||||
auto freertos::BinarySemaphore::getCount() -> size_t {
|
||||
return uxSemaphoreGetCount(handle);
|
||||
}
|
20
modules/control/Firmware/src/FreeRTOS/BinarySemaphore.h
Normal file
20
modules/control/Firmware/src/FreeRTOS/BinarySemaphore.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace freertos {
|
||||
class BinarySemaphore {
|
||||
public:
|
||||
BinarySemaphore();
|
||||
BinarySemaphore(const BinarySemaphore &other) = delete;
|
||||
BinarySemaphore(BinarySemaphore &&other) noexcept;
|
||||
~BinarySemaphore();
|
||||
BinarySemaphore &operator=(const BinarySemaphore &other) = delete;
|
||||
BinarySemaphore &operator=(const BinarySemaphore &&other) noexcept;
|
||||
bool take(TickType_t timeout = portMAX_DELAY);
|
||||
bool give();
|
||||
size_t getCount();
|
||||
|
||||
private:
|
||||
SemaphoreHandle_t handle;
|
||||
};
|
||||
} // namespace freertos
|
Reference in a new issue