FreeRTOS Improvements #82

Closed
muellerr wants to merge 24 commits from KSat:mueller_FreeRTOS_improvements into master
2 changed files with 15 additions and 42 deletions
Showing only changes of commit e56bef7e00 - Show all commits

View File

@ -5,8 +5,8 @@
BinarySemaphore::BinarySemaphore() {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
sif::error << "Semaphore: Binary semaph creation failure" << std::endl;
if(handle == nullptr) {
sif::error << "Semaphore: Binary semaph creation failure" << std::endl;
}
xSemaphoreGive(handle);
}
@ -15,27 +15,6 @@ BinarySemaphore::~BinarySemaphore() {
vSemaphoreDelete(handle);
}
// This copy ctor is important as it prevents the assignment to a ressource
// (other.handle) variable which is later deleted!
BinarySemaphore::BinarySemaphore(const BinarySemaphore& other) {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
sif::error << "Binary semaphore creation failure" << std::endl;
}
xSemaphoreGive(handle);
}
BinarySemaphore& BinarySemaphore::operator =(const BinarySemaphore& s) {
if(this != &s) {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
sif::error << "Binary semaphore creation failure" << std::endl;
}
xSemaphoreGive(handle);
}
return *this;
}
BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
handle = xSemaphoreCreateBinary();
if(handle == nullptr) {
@ -126,7 +105,7 @@ void BinarySemaphore::resetSemaphore() {
xSemaphoreGive(handle);
}
}
ReturnValue_t BinarySemaphore::acquire(uint32_t timeoutMs) {
return takeBinarySemaphore(timeoutMs);
}
@ -137,7 +116,7 @@ ReturnValue_t BinarySemaphore::release() {
uint8_t BinarySemaphore::getSemaphoreCounter() {
return uxSemaphoreGetCount(handle);
}
}
// Be careful with the stack size here. This is called from an ISR!
ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
@ -156,5 +135,4 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t sema
} else {
return SEMAPHORE_NOT_OWNED;
}
}
}

View File

@ -1,7 +1,7 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
#define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/tasks/SemaphoreIF.h>
extern "C" {
#include <freertos/FreeRTOS.h>
@ -24,7 +24,7 @@ extern "C" {
* @ingroup osal
*/
class BinarySemaphore: public SemaphoreIF,
public HasReturnvaluesIF {
public HasReturnvaluesIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
@ -36,19 +36,13 @@ public:
//! Can be passed as tick type and ms value.
static constexpr TickType_t BLOCK_TIMEOUT_TICKS = portMAX_DELAY;
static constexpr uint32_t BLOCK_TIMEOUT = portMAX_DELAY;
//! Semaphore timeout
static constexpr ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(1);
/** The current semaphore can not be given, because it is not owned */
static constexpr ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(2);
static constexpr ReturnValue_t SEMAPHORE_NULLPOINTER = MAKE_RETURN_CODE(3);
//! @brief Default ctor
BinarySemaphore();
//! @brief Copy ctor
BinarySemaphore(const BinarySemaphore&);
//! @brief Copy assignment
BinarySemaphore& operator=(const BinarySemaphore&);
//! @brief Copy ctor, deleted explicitely.
BinarySemaphore(const BinarySemaphore&) = delete;
//! @brief Copy assignment, deleted explicitely.
BinarySemaphore& operator=(const BinarySemaphore&) = delete;
//! @brief Move ctor
BinarySemaphore (BinarySemaphore &&);
//! @brief Move assignment
@ -60,7 +54,7 @@ public:
BinarySemaphore::NO_BLOCK_TIMEOUT) override;
ReturnValue_t release() override;
uint8_t getSemaphoreCounter() override;
/**
* Take the binary semaphore.
* If the semaphore has already been taken, the task will be blocked
@ -118,7 +112,8 @@ public:
*/
static ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore,
BaseType_t * higherPriorityTaskWoken);
protected:
protected:
SemaphoreHandle_t handle;
};