Implement BinarySemaphore freertos wrapper

This commit is contained in:
GHOSCHT 2023-03-30 17:48:53 +02:00
parent e2a64ac231
commit 908a6becba
No known key found for this signature in database
2 changed files with 46 additions and 0 deletions

View 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);
}

View 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