mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-10 18:15:59 +00:00
Add semaphore based signal implementation
This commit is contained in:
parent
4b03e1d9f4
commit
47bad524ad
27
include/sta/os2/signal.hpp
Normal file
27
include/sta/os2/signal.hpp
Normal 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
29
src/os2/signal.cpp
Normal 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
|
Loading…
x
Reference in New Issue
Block a user