rtos2-utils/src/signal.cpp
2024-02-07 18:50:13 +01:00

40 lines
691 B
C++

#include <sta/rtos/signal.hpp>
#include <sta/debug/assert.hpp>
namespace sta
{
RtosSignal::RtosSignal(osSemaphoreId_t semaphore)
: semaphore_{semaphore}
{
STA_ASSERT(semaphore != NULL);
}
RtosSignal::RtosSignal(uint32_t max, uint32_t initial /* = 0 */)
: semaphore_{osSemaphoreNew(max, initial, NULL)}
{
STA_ASSERT(semaphore_ != NULL);
}
void RtosSignal::notify()
{
osSemaphoreRelease(semaphore_);
}
bool RtosSignal::peek()
{
return (osSemaphoreGetCount(semaphore_) != 0);
}
bool RtosSignal::test()
{
return (osSemaphoreAcquire(semaphore_, 0) == osOK);
}
void RtosSignal::wait()
{
osSemaphoreAcquire(semaphore_, osWaitForever);
}
} // namespace sta