Add mutex implementation

This commit is contained in:
Henrik Stickann 2022-04-09 21:16:11 +02:00
parent 2a2a13a2d1
commit 4b03e1d9f4
2 changed files with 50 additions and 0 deletions

31
include/sta/os2/mutex.hpp Normal file
View File

@ -0,0 +1,31 @@
#ifndef STA_OS2_MUTEX_HPP
#define STA_OS2_MUTEX_HPP
#include <sta/mutex.hpp>
#include <cmsis_os2.h>
namespace sta
{
/**
* @brief Implementation of Mutex for CMSIS V2.
*/
class Os2Mutex : public Mutex
{
public:
/**
* @param handle CMSIS V2 mutex
*/
Os2Mutex(osMutexId_t * handle);
void acquire() override;
void release() override;
private:
osMutexId_t * handle_; /**< CMSIS V2 mutex */
};
} // namespace sta
#endif // STA_OS2_MUTEX_HPP

19
src/os2/mutex.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <sta/os2/mutex.hpp>
namespace sta
{
Os2Mutex::Os2Mutex(osMutexId_t * handle)
: handle_{handle}
{}
void Os2Mutex::acquire()
{
osMutexAcquire(*handle_, osWaitForever);
}
void Os2Mutex::release()
{
osMutexRelease(*handle_);
}
}