1
0
forked from fsfw/fsfw

Merge remote-tracking branch 'upstream/master' into mueller/Linux-SetTaskIF-Fix

This commit is contained in:
2020-08-25 12:19:52 +02:00
17 changed files with 229 additions and 118 deletions

View File

@ -155,7 +155,7 @@ ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) {
if (checkOrCreateClockMutex() != HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t result = timeMutex->lockMutex(MutexIF::NO_TIMEOUT);
ReturnValue_t result = timeMutex->lockMutex(MutexIF::BLOCKING);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
@ -170,7 +170,7 @@ ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) {
if (timeMutex == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
ReturnValue_t result = timeMutex->lockMutex(MutexIF::NO_TIMEOUT);
ReturnValue_t result = timeMutex->lockMutex(MutexIF::BLOCKING);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}

View File

@ -1,28 +1,32 @@
#include "Mutex.h"
#include <framework/osal/FreeRTOS/Mutex.h>
#include "../../serviceinterface/ServiceInterfaceStream.h"
const uint32_t MutexIF::NO_TIMEOUT = 0;
Mutex::Mutex() {
handle = xSemaphoreCreateMutex();
//TODO print error
if(handle == nullptr) {
sif::error << "Mutex::Mutex(FreeRTOS): Creation failure" << std::endl;
}
}
Mutex::~Mutex() {
if (handle != 0) {
if (handle != nullptr) {
vSemaphoreDelete(handle);
}
}
ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) {
if (handle == 0) {
//TODO Does not exist
return HasReturnvaluesIF::RETURN_FAILED;
ReturnValue_t Mutex::lockMutex(TimeoutType timeoutType,
uint32_t timeoutMs) {
if (handle == nullptr) {
return MutexIF::MUTEX_NOT_FOUND;
}
TickType_t timeout = portMAX_DELAY;
if (timeoutMs != NO_TIMEOUT) {
// If the timeout type is BLOCKING, this will be the correct value.
uint32_t timeout = portMAX_DELAY;
if(timeoutType == TimeoutType::POLLING) {
timeout = 0;
}
else if(timeoutType == TimeoutType::WAITING){
timeout = pdMS_TO_TICKS(timeoutMs);
}
@ -30,21 +34,18 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) {
if (returncode == pdPASS) {
return HasReturnvaluesIF::RETURN_OK;
} else {
//TODO could not be acquired/timeout
return HasReturnvaluesIF::RETURN_FAILED;
return MutexIF::MUTEX_TIMEOUT;
}
}
ReturnValue_t Mutex::unlockMutex() {
if (handle == 0) {
//TODO Does not exist
return HasReturnvaluesIF::RETURN_FAILED;
if (handle == nullptr) {
return MutexIF::MUTEX_NOT_FOUND;
}
BaseType_t returncode = xSemaphoreGive(handle);
if (returncode == pdPASS) {
return HasReturnvaluesIF::RETURN_OK;
} else {
//TODO is not owner
return HasReturnvaluesIF::RETURN_FAILED;
return MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX;
}
}

View File

@ -1,22 +1,29 @@
#ifndef OS_RTEMS_MUTEX_H_
#define OS_RTEMS_MUTEX_H_
#ifndef FRAMEWORK_FREERTOS_MUTEX_H_
#define FRAMEWORK_FREERTOS_MUTEX_H_
#include "../../ipc/MutexIF.h"
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <FreeRTOS.h>
#include "semphr.h"
/**
* @brief OS component to implement MUTual EXclusion
*
* @details
* Mutexes are binary semaphores which include a priority inheritance mechanism.
* Documentation: https://www.freertos.org/Real-time-embedded-RTOS-mutexes.html
* @ingroup osal
*/
class Mutex : public MutexIF {
public:
Mutex();
~Mutex();
ReturnValue_t lockMutex(uint32_t timeoutMs);
ReturnValue_t unlockMutex();
ReturnValue_t lockMutex(TimeoutType timeoutType,
uint32_t timeoutMs) override;
ReturnValue_t unlockMutex() override;
private:
SemaphoreHandle_t handle;
};
#endif /* OS_RTEMS_MUTEX_H_ */
#endif /* FRAMEWORK_FREERTOS_MUTEX_H_ */