using newer bin semaph create call.

architecture dependant function call is external now and shall
be implemented by developer
This commit is contained in:
Robin Müller 2020-04-23 17:54:41 +02:00
parent 44d4678089
commit 1415cd2339
4 changed files with 32 additions and 23 deletions

View File

@ -8,16 +8,13 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
extern "C" {
#include "portmacro.h"
#include "task.h"
}
BinarySemaphore::BinarySemaphore() { BinarySemaphore::BinarySemaphore() {
xSemaphoreCreateBinary(handle); handle = xSemaphoreCreateBinary();
if(handle == nullptr) { if(handle == nullptr) {
error << "Binary semaphore creation failure" << std::endl; error << "Binary semaphore creation failure" << std::endl;
} }
xSemaphoreGive(handle);
} }
BinarySemaphore::~BinarySemaphore() { BinarySemaphore::~BinarySemaphore() {
@ -27,36 +24,40 @@ BinarySemaphore::~BinarySemaphore() {
// This copy ctor is important as it prevents the assignment to a ressource // This copy ctor is important as it prevents the assignment to a ressource
// (other.handle) variable which is later deleted! // (other.handle) variable which is later deleted!
BinarySemaphore::BinarySemaphore(const BinarySemaphore& other) { BinarySemaphore::BinarySemaphore(const BinarySemaphore& other) {
xSemaphoreCreateBinary(handle); handle = xSemaphoreCreateBinary();
if(handle == nullptr) { if(handle == nullptr) {
error << "Binary semaphore creation failure" << std::endl; error << "Binary semaphore creation failure" << std::endl;
} }
xSemaphoreGive(handle);
} }
BinarySemaphore& BinarySemaphore::operator =(const BinarySemaphore& s) { BinarySemaphore& BinarySemaphore::operator =(const BinarySemaphore& s) {
if(this != &s) { if(this != &s) {
xSemaphoreCreateBinary(handle); handle = xSemaphoreCreateBinary();
if(handle == nullptr) { if(handle == nullptr) {
error << "Binary semaphore creation failure" << std::endl; error << "Binary semaphore creation failure" << std::endl;
} }
xSemaphoreGive(handle);
} }
return *this; return *this;
} }
BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) { BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
xSemaphoreCreateBinary(handle); handle = xSemaphoreCreateBinary();
if(handle == nullptr) { if(handle == nullptr) {
error << "Binary semaphore creation failure" << std::endl; error << "Binary semaphore creation failure" << std::endl;
} }
xSemaphoreGive(handle);
} }
BinarySemaphore& BinarySemaphore::operator =( BinarySemaphore& BinarySemaphore::operator =(
BinarySemaphore&& s) { BinarySemaphore&& s) {
if(&s != this) { if(&s != this) {
xSemaphoreCreateBinary(handle); handle = xSemaphoreCreateBinary();
if(handle == nullptr) { if(handle == nullptr) {
error << "Binary semaphore creation failure" << std::endl; error << "Binary semaphore creation failure" << std::endl;
} }
xSemaphoreGive(handle);
} }
return *this; return *this;
} }
@ -127,7 +128,8 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore)
void BinarySemaphore::resetSemaphore() { void BinarySemaphore::resetSemaphore() {
if(handle != nullptr) { if(handle != nullptr) {
vSemaphoreDelete(handle); vSemaphoreDelete(handle);
xSemaphoreCreateBinary(handle); handle = xSemaphoreCreateBinary();
xSemaphoreGive(handle);
} }
} }

View File

@ -18,6 +18,10 @@ extern "C" {
* @brief OS Tool to achieve synchronization of between tasks or between task and ISR * @brief OS Tool to achieve synchronization of between tasks or between task and ISR
* @details * @details
* Documentation: https://www.freertos.org/Embedded-RTOS-Binary-Semaphores.html * Documentation: https://www.freertos.org/Embedded-RTOS-Binary-Semaphores.html
*
* SHOULDDO: check freeRTOS version and use new task notifications,
* if non-ancient freeRTOS version is used.
*
* @ingroup osal * @ingroup osal
*/ */
class BinarySemaphore: public HasReturnvaluesIF { class BinarySemaphore: public HasReturnvaluesIF {
@ -68,8 +72,8 @@ public:
/** /**
* Take the binary semaphore. * Take the binary semaphore.
* If the semaphore has already been taken, the task will be blocked for a maximum * If the semaphore has already been taken, the task will be blocked
* of #timeoutMs or until the semaphore is given back, * for a maximum of #timeoutMs or until the semaphore is given back,
* for example by an ISR or another task. * for example by an ISR or another task.
* @param timeoutMs * @param timeoutMs
* @return -@c RETURN_OK on success * @return -@c RETURN_OK on success

View File

@ -5,16 +5,12 @@
* *
*/ */
#include <framework/osal/FreeRTOS/TaskManagement.h> #include <framework/osal/FreeRTOS/TaskManagement.h>
#include <FreeRTOS.h>
#include "portmacro.h"
#include "task.h"
/** extern "C" {
* TODO: This stuff is hardware and architecture and mission dependant... #include "FreeRTOS.h"
* Some FreeRTOS implementations might be able to determine their own task context for example. #include "task.h"
* If not ISRs are used, or task preemption is enabled, some of this stuff might }
* not be necessary anyway. Maybe there is a better solution?
*/
void TaskManagement::requestContextSwitchFromTask() { void TaskManagement::requestContextSwitchFromTask() {
vTaskDelay(0); vTaskDelay(0);
} }
@ -22,7 +18,7 @@ void TaskManagement::requestContextSwitchFromTask() {
void TaskManagement::requestContextSwitch(CallContext callContext = CallContext::task) { void TaskManagement::requestContextSwitch(CallContext callContext = CallContext::task) {
if(callContext == CallContext::isr) { if(callContext == CallContext::isr) {
// This function depends on the partmacro.h definition for the specific device // This function depends on the partmacro.h definition for the specific device
portYIELD_FROM_ISR(); requestContextSwitchFromISR();
} else { } else {
requestContextSwitchFromTask(); requestContextSwitchFromTask();
} }

View File

@ -7,6 +7,12 @@
#ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ #ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
#define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ #define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
/**
* Architecture dependant portmacro.h function call.
* Should be implemented in bsp.
*/
extern "C" void requestContextSwitchFromISR();
/*! /*!
* Used by functions to tell if they are being called from * Used by functions to tell if they are being called from
* within an ISR or from a regular task. This is required because FreeRTOS * within an ISR or from a regular task. This is required because FreeRTOS
@ -18,6 +24,7 @@ enum CallContext {
isr = 0xFF //!< isr_context isr = 0xFF //!< isr_context
}; };
class TaskManagement { class TaskManagement {
public: public:
/** /**