updating code from Flying Laptop
This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
35
osal/rtems/Mutex.cpp
Normal file
35
osal/rtems/Mutex.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "Mutex.h"
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
const uint32_t MutexIF::NO_TIMEOUT = RTEMS_NO_TIMEOUT;
|
||||
uint8_t Mutex::count = 0;
|
||||
|
||||
Mutex::Mutex() :
|
||||
mutexId(0) {
|
||||
rtems_name mutexName = ('M' << 24) + ('T' << 16) + ('X' << 8) + count++;
|
||||
rtems_status_code status = rtems_semaphore_create(mutexName, 1,
|
||||
RTEMS_BINARY_SEMAPHORE | RTEMS_PRIORITY | RTEMS_INHERIT_PRIORITY, 0,
|
||||
&mutexId);
|
||||
if (status != RTEMS_SUCCESSFUL) {
|
||||
error << "Mutex: creation with name, id " << mutexName << ", " << mutexId
|
||||
<< " failed with " << status << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Mutex::~Mutex() {
|
||||
rtems_status_code status = rtems_semaphore_delete(mutexId);
|
||||
if (status != RTEMS_SUCCESSFUL) {
|
||||
error << "Mutex: deletion for id " << mutexId
|
||||
<< " failed with " << status << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) {
|
||||
rtems_status_code status = rtems_semaphore_obtain(mutexId, RTEMS_WAIT, timeoutMs);
|
||||
return RtemsBasic::convertReturnCode(status);
|
||||
}
|
||||
|
||||
ReturnValue_t Mutex::unlockMutex() {
|
||||
rtems_status_code status = rtems_semaphore_release(mutexId);
|
||||
return RtemsBasic::convertReturnCode(status);
|
||||
}
|
Reference in New Issue
Block a user