Add semaphore based signal implementation

This commit is contained in:
Henrik Stickann 2022-04-10 15:27:16 +02:00
parent 4b03e1d9f4
commit 47bad524ad
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#ifndef STA_OS2_SIGNAL_HPP
#define STA_OS2_SIGNAL_HPP
#include <sta/signal.hpp>
#include <cmsis_os2.h>
namespace sta
{
class Os2Signal : public Signal
{
public:
Os2Signal(osSemaphoreId_t * semaphore);
void notify() override;
bool peek() override;
bool test() override;
void wait() override;
private:
osSemaphoreId_t * semaphore_;
};
} // namespace sta
#endif // STA_OS2_SIGNAL_HPP

29
src/os2/signal.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <sta/os2/signal.hpp>
namespace sta
{
Os2Signal::Os2Signal(osSemaphoreId_t * semaphore)
: semaphore_{semaphore}
{}
void Os2Signal::notify()
{
osSemaphoreRelease(*semaphore_);
}
bool Os2Signal::peek()
{
return (osSemaphoreGetCount(*semaphore_) != 0);
}
bool Os2Signal::test()
{
return (osSemaphoreAcquire(*semaphore_, 0) == osOK);
}
void Os2Signal::wait()
{
osSemaphoreAcquire(*semaphore_, osWaitForever);
}
} // namespace sta