Merge remote-tracking branch 'upstream/master' into mueller/feature/TmTcUnixBridge
This commit is contained in:
commit
6c0defed5e
@ -10,7 +10,7 @@ class ActionMessage {
|
|||||||
private:
|
private:
|
||||||
ActionMessage();
|
ActionMessage();
|
||||||
public:
|
public:
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::ACTION;
|
static const uint8_t MESSAGE_ID = messagetypes::ACTION;
|
||||||
static const Command_t EXECUTE_ACTION = MAKE_COMMAND_ID(1);
|
static const Command_t EXECUTE_ACTION = MAKE_COMMAND_ID(1);
|
||||||
static const Command_t STEP_SUCCESS = MAKE_COMMAND_ID(2);
|
static const Command_t STEP_SUCCESS = MAKE_COMMAND_ID(2);
|
||||||
static const Command_t STEP_FAILED = MAKE_COMMAND_ID(3);
|
static const Command_t STEP_FAILED = MAKE_COMMAND_ID(3);
|
||||||
|
@ -25,7 +25,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* These are the commands that can be sent to a DeviceHandlerBase
|
* These are the commands that can be sent to a DeviceHandlerBase
|
||||||
*/
|
*/
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::DEVICE_HANDLER_COMMAND;
|
static const uint8_t MESSAGE_ID = messagetypes::DEVICE_HANDLER_COMMAND;
|
||||||
static const Command_t CMD_RAW = MAKE_COMMAND_ID( 1 ); //!< Sends a raw command, setParameter is a ::store_id_t containing the raw packet to send
|
static const Command_t CMD_RAW = MAKE_COMMAND_ID( 1 ); //!< Sends a raw command, setParameter is a ::store_id_t containing the raw packet to send
|
||||||
// static const Command_t CMD_DIRECT = MAKE_COMMAND_ID( 2 ); //!< Sends a direct command, setParameter is a ::DeviceCommandId_t, setParameter2 is a ::store_id_t containing the data needed for the command
|
// static const Command_t CMD_DIRECT = MAKE_COMMAND_ID( 2 ); //!< Sends a direct command, setParameter is a ::DeviceCommandId_t, setParameter2 is a ::store_id_t containing the data needed for the command
|
||||||
static const Command_t CMD_SWITCH_IOBOARD = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier
|
static const Command_t CMD_SWITCH_IOBOARD = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class HealthMessage {
|
class HealthMessage {
|
||||||
public:
|
public:
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::HEALTH_COMMAND;
|
static const uint8_t MESSAGE_ID = messagetypes::HEALTH_COMMAND;
|
||||||
static const Command_t HEALTH_SET = MAKE_COMMAND_ID(1);//REPLY_COMMAND_OK/REPLY_REJECTED
|
static const Command_t HEALTH_SET = MAKE_COMMAND_ID(1);//REPLY_COMMAND_OK/REPLY_REJECTED
|
||||||
static const Command_t HEALTH_ANNOUNCE = MAKE_COMMAND_ID(3); //NO REPLY!
|
static const Command_t HEALTH_ANNOUNCE = MAKE_COMMAND_ID(3); //NO REPLY!
|
||||||
static const Command_t HEALTH_INFO = MAKE_COMMAND_ID(5);
|
static const Command_t HEALTH_INFO = MAKE_COMMAND_ID(5);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#include "../tmstorage/TmStoreMessage.h"
|
#include "../tmstorage/TmStoreMessage.h"
|
||||||
#include "../parameters/ParameterMessage.h"
|
#include "../parameters/ParameterMessage.h"
|
||||||
|
|
||||||
namespace MESSAGE_TYPE {
|
namespace messagetypes {
|
||||||
void clearMissionMessage(CommandMessage* message);
|
void clearMissionMessage(CommandMessage* message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,35 +67,35 @@ void CommandMessage::setParameter2(uint32_t parameter2) {
|
|||||||
|
|
||||||
void CommandMessage::clearCommandMessage() {
|
void CommandMessage::clearCommandMessage() {
|
||||||
switch((getCommand()>>8) & 0xff){
|
switch((getCommand()>>8) & 0xff){
|
||||||
case MESSAGE_TYPE::MODE_COMMAND:
|
case messagetypes::MODE_COMMAND:
|
||||||
ModeMessage::clear(this);
|
ModeMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
case MESSAGE_TYPE::HEALTH_COMMAND:
|
case messagetypes::HEALTH_COMMAND:
|
||||||
HealthMessage::clear(this);
|
HealthMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
case MESSAGE_TYPE::MODE_SEQUENCE:
|
case messagetypes::MODE_SEQUENCE:
|
||||||
ModeSequenceMessage::clear(this);
|
ModeSequenceMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
case MESSAGE_TYPE::ACTION:
|
case messagetypes::ACTION:
|
||||||
ActionMessage::clear(this);
|
ActionMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
case MESSAGE_TYPE::DEVICE_HANDLER_COMMAND:
|
case messagetypes::DEVICE_HANDLER_COMMAND:
|
||||||
DeviceHandlerMessage::clear(this);
|
DeviceHandlerMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
case MESSAGE_TYPE::MEMORY:
|
case messagetypes::MEMORY:
|
||||||
MemoryMessage::clear(this);
|
MemoryMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
case MESSAGE_TYPE::MONITORING:
|
case messagetypes::MONITORING:
|
||||||
MonitoringMessage::clear(this);
|
MonitoringMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
case MESSAGE_TYPE::TM_STORE:
|
case messagetypes::TM_STORE:
|
||||||
TmStoreMessage::clear(this);
|
TmStoreMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
case MESSAGE_TYPE::PARAMETER:
|
case messagetypes::PARAMETER:
|
||||||
ParameterMessage::clear(this);
|
ParameterMessage::clear(this);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
MESSAGE_TYPE::clearMissionMessage(this);
|
messagetypes::clearMissionMessage(this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
static const ReturnValue_t UNKNOWN_COMMAND = MAKE_RETURN_CODE(0x01);
|
static const ReturnValue_t UNKNOWN_COMMAND = MAKE_RETURN_CODE(0x01);
|
||||||
|
|
||||||
|
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::COMMAND;
|
static const uint8_t MESSAGE_ID = messagetypes::COMMAND;
|
||||||
static const Command_t CMD_NONE = MAKE_COMMAND_ID( 0 );//!< Used internally, will be ignored
|
static const Command_t CMD_NONE = MAKE_COMMAND_ID( 0 );//!< Used internally, will be ignored
|
||||||
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID( 3 );
|
static const Command_t REPLY_COMMAND_OK = MAKE_COMMAND_ID( 3 );
|
||||||
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 0xD1 );//!< Reply indicating that the current command was rejected, par1 should contain the error code
|
static const Command_t REPLY_REJECTED = MAKE_COMMAND_ID( 0xD1 );//!< Reply indicating that the current command was rejected, par1 should contain the error code
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef FRAMEWORK_IPC_FWMESSAGETYPES_H_
|
#ifndef FRAMEWORK_IPC_FWMESSAGETYPES_H_
|
||||||
#define FRAMEWORK_IPC_FWMESSAGETYPES_H_
|
#define FRAMEWORK_IPC_FWMESSAGETYPES_H_
|
||||||
|
|
||||||
namespace MESSAGE_TYPE {
|
namespace messagetypes {
|
||||||
//Remember to add new Message Types to the clearCommandMessage function!
|
//Remember to add new Message Types to the clearCommandMessage function!
|
||||||
enum FW_MESSAGE_TYPE {
|
enum FW_MESSAGE_TYPE {
|
||||||
COMMAND = 0,
|
COMMAND = 0,
|
||||||
|
@ -9,7 +9,7 @@ class MemoryMessage {
|
|||||||
private:
|
private:
|
||||||
MemoryMessage(); //A private ctor inhibits instantiation
|
MemoryMessage(); //A private ctor inhibits instantiation
|
||||||
public:
|
public:
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::MEMORY;
|
static const uint8_t MESSAGE_ID = messagetypes::MEMORY;
|
||||||
static const Command_t CMD_MEMORY_LOAD = MAKE_COMMAND_ID( 0x01 );
|
static const Command_t CMD_MEMORY_LOAD = MAKE_COMMAND_ID( 0x01 );
|
||||||
static const Command_t CMD_MEMORY_DUMP = MAKE_COMMAND_ID( 0x02 );
|
static const Command_t CMD_MEMORY_DUMP = MAKE_COMMAND_ID( 0x02 );
|
||||||
static const Command_t CMD_MEMORY_CHECK = MAKE_COMMAND_ID( 0x03 );
|
static const Command_t CMD_MEMORY_CHECK = MAKE_COMMAND_ID( 0x03 );
|
||||||
|
@ -17,7 +17,7 @@ class ModeMessage {
|
|||||||
private:
|
private:
|
||||||
ModeMessage();
|
ModeMessage();
|
||||||
public:
|
public:
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::MODE_COMMAND;
|
static const uint8_t MESSAGE_ID = messagetypes::MODE_COMMAND;
|
||||||
static const Command_t CMD_MODE_COMMAND = MAKE_COMMAND_ID(0x01);//!> Command to set the specified Mode, replies are: REPLY_MODE_REPLY, REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any replies, as this will break the subsystem mode machine!!
|
static const Command_t CMD_MODE_COMMAND = MAKE_COMMAND_ID(0x01);//!> Command to set the specified Mode, replies are: REPLY_MODE_REPLY, REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any replies, as this will break the subsystem mode machine!!
|
||||||
static const Command_t CMD_MODE_COMMAND_FORCED = MAKE_COMMAND_ID(0xF1);//!> Command to set the specified Mode, regardless of external control flag, replies are: REPLY_MODE_REPLY, REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any replies, as this will break the subsystem mode machine!!
|
static const Command_t CMD_MODE_COMMAND_FORCED = MAKE_COMMAND_ID(0xF1);//!> Command to set the specified Mode, regardless of external control flag, replies are: REPLY_MODE_REPLY, REPLY_WRONG_MODE_REPLY, and REPLY_REJECTED; don't add any replies, as this will break the subsystem mode machine!!
|
||||||
static const Command_t REPLY_MODE_REPLY = MAKE_COMMAND_ID(0x02);//!> Reply to a CMD_MODE_COMMAND or CMD_MODE_READ
|
static const Command_t REPLY_MODE_REPLY = MAKE_COMMAND_ID(0x02);//!> Reply to a CMD_MODE_COMMAND or CMD_MODE_READ
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
class MonitoringMessage: public CommandMessage {
|
class MonitoringMessage: public CommandMessage {
|
||||||
public:
|
public:
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::MONITORING;
|
static const uint8_t MESSAGE_ID = messagetypes::MONITORING;
|
||||||
//Object id could be useful, but we better manage that on service level (register potential reporters).
|
//Object id could be useful, but we better manage that on service level (register potential reporters).
|
||||||
static const Command_t LIMIT_VIOLATION_REPORT = MAKE_COMMAND_ID(10);
|
static const Command_t LIMIT_VIOLATION_REPORT = MAKE_COMMAND_ID(10);
|
||||||
virtual ~MonitoringMessage();
|
virtual ~MonitoringMessage();
|
||||||
|
@ -100,7 +100,6 @@ void ObjectManager::initialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ObjectManager::printList() {
|
void ObjectManager::printList() {
|
||||||
std::map<object_id_t, SystemObjectIF*>::iterator it;
|
|
||||||
sif::debug << "ObjectManager: Object List contains:" << std::endl;
|
sif::debug << "ObjectManager: Object List contains:" << std::endl;
|
||||||
for (auto const& it : objectList) {
|
for (auto const& it : objectList) {
|
||||||
sif::debug << std::hex << it.first << " | " << it.second << std::endl;
|
sif::debug << std::hex << it.first << " | " << it.second << std::endl;
|
||||||
|
95
osal/FreeRTOS/BinSemaphUsingTask.cpp
Normal file
95
osal/FreeRTOS/BinSemaphUsingTask.cpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#include "../../osal/FreeRTOS/BinSemaphUsingTask.h"
|
||||||
|
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
BinarySemaphoreUsingTask::BinarySemaphoreUsingTask() {
|
||||||
|
handle = TaskManagement::getCurrentTaskHandle();
|
||||||
|
if(handle == nullptr) {
|
||||||
|
sif::error << "Could not retrieve task handle. Please ensure the"
|
||||||
|
"constructor was called inside a task." << std::endl;
|
||||||
|
}
|
||||||
|
xTaskNotifyGive(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
BinarySemaphoreUsingTask::~BinarySemaphoreUsingTask() {
|
||||||
|
// Clear notification value on destruction.
|
||||||
|
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphoreUsingTask::acquire(TimeoutType timeoutType,
|
||||||
|
uint32_t timeoutMs) {
|
||||||
|
TickType_t timeout = 0;
|
||||||
|
if(timeoutType == TimeoutType::POLLING) {
|
||||||
|
timeout = 0;
|
||||||
|
}
|
||||||
|
else if(timeoutType == TimeoutType::WAITING){
|
||||||
|
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timeout = portMAX_DELAY;
|
||||||
|
}
|
||||||
|
return acquireWithTickTimeout(timeoutType, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphoreUsingTask::acquireWithTickTimeout(
|
||||||
|
TimeoutType timeoutType, TickType_t timeoutTicks) {
|
||||||
|
BaseType_t returncode = ulTaskNotifyTake(pdTRUE, timeoutTicks);
|
||||||
|
if (returncode == pdPASS) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphoreUsingTask::release() {
|
||||||
|
return release(this->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphoreUsingTask::release(
|
||||||
|
TaskHandle_t taskHandle) {
|
||||||
|
if(getSemaphoreCounter(taskHandle) == 1) {
|
||||||
|
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||||
|
}
|
||||||
|
BaseType_t returncode = xTaskNotifyGive(taskHandle);
|
||||||
|
if (returncode == pdPASS) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// This should never happen.
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskHandle_t BinarySemaphoreUsingTask::getTaskHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter() const {
|
||||||
|
return getSemaphoreCounter(this->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounter(
|
||||||
|
TaskHandle_t taskHandle) {
|
||||||
|
uint32_t notificationValue;
|
||||||
|
xTaskNotifyAndQuery(taskHandle, 0, eNoAction, ¬ificationValue);
|
||||||
|
return notificationValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Be careful with the stack size here. This is called from an ISR!
|
||||||
|
ReturnValue_t BinarySemaphoreUsingTask::releaseFromISR(
|
||||||
|
TaskHandle_t taskHandle, BaseType_t * higherPriorityTaskWoken) {
|
||||||
|
if(getSemaphoreCounterFromISR(taskHandle, higherPriorityTaskWoken) == 1) {
|
||||||
|
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||||
|
}
|
||||||
|
vTaskNotifyGiveFromISR(taskHandle, higherPriorityTaskWoken);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphoreUsingTask::getSemaphoreCounterFromISR(
|
||||||
|
TaskHandle_t taskHandle, BaseType_t* higherPriorityTaskWoken) {
|
||||||
|
uint32_t notificationValue = 0;
|
||||||
|
xTaskNotifyAndQueryFromISR(taskHandle, 0, eNoAction, ¬ificationValue,
|
||||||
|
higherPriorityTaskWoken);
|
||||||
|
return notificationValue;
|
||||||
|
}
|
76
osal/FreeRTOS/BinSemaphUsingTask.h
Normal file
76
osal/FreeRTOS/BinSemaphUsingTask.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#ifndef FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_
|
||||||
|
#define FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_
|
||||||
|
|
||||||
|
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include "../../tasks/SemaphoreIF.h"
|
||||||
|
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Binary Semaphore implementation using the task notification value.
|
||||||
|
* The notification value should therefore not be used
|
||||||
|
* for other purposes.
|
||||||
|
* @details
|
||||||
|
* Additional information: https://www.freertos.org/RTOS-task-notifications.html
|
||||||
|
* and general semaphore documentation.
|
||||||
|
*/
|
||||||
|
class BinarySemaphoreUsingTask: public SemaphoreIF,
|
||||||
|
public HasReturnvaluesIF {
|
||||||
|
public:
|
||||||
|
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||||
|
|
||||||
|
//! @brief Default ctor
|
||||||
|
BinarySemaphoreUsingTask();
|
||||||
|
//! @brief Default dtor
|
||||||
|
virtual~ BinarySemaphoreUsingTask();
|
||||||
|
|
||||||
|
ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||||
|
uint32_t timeoutMs = portMAX_DELAY) override;
|
||||||
|
ReturnValue_t release() override;
|
||||||
|
uint8_t getSemaphoreCounter() const override;
|
||||||
|
static uint8_t getSemaphoreCounter(TaskHandle_t taskHandle);
|
||||||
|
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t taskHandle,
|
||||||
|
BaseType_t* higherPriorityTaskWoken);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as acquire() with timeout in FreeRTOS ticks.
|
||||||
|
* @param timeoutTicks
|
||||||
|
* @return - @c RETURN_OK on success
|
||||||
|
* - @c RETURN_FAILED on failure
|
||||||
|
*/
|
||||||
|
ReturnValue_t acquireWithTickTimeout(
|
||||||
|
TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||||
|
TickType_t timeoutTicks = portMAX_DELAY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get handle to the task related to the semaphore.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
TaskHandle_t getTaskHandle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper function to give back semaphore from handle
|
||||||
|
* @param semaphore
|
||||||
|
* @return - @c RETURN_OK on success
|
||||||
|
* - @c RETURN_FAILED on failure
|
||||||
|
*/
|
||||||
|
static ReturnValue_t release(TaskHandle_t taskToNotify);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper function to give back semaphore from handle when called from an ISR
|
||||||
|
* @param semaphore
|
||||||
|
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||||
|
* a higher priority was unblocked. A context switch should be requested
|
||||||
|
* from an ISR if this is the case (see TaskManagement functions)
|
||||||
|
* @return - @c RETURN_OK on success
|
||||||
|
* - @c RETURN_FAILED on failure
|
||||||
|
*/
|
||||||
|
static ReturnValue_t releaseFromISR(TaskHandle_t taskToNotify,
|
||||||
|
BaseType_t * higherPriorityTaskWoken);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TaskHandle_t handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_OSAL_FREERTOS_BINSEMAPHUSINGTASK_H_ */
|
108
osal/FreeRTOS/BinarySemaphore.cpp
Normal file
108
osal/FreeRTOS/BinarySemaphore.cpp
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
#include "../../osal/FreeRTOS/BinarySemaphore.h"
|
||||||
|
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
BinarySemaphore::BinarySemaphore() {
|
||||||
|
handle = xSemaphoreCreateBinary();
|
||||||
|
if(handle == nullptr) {
|
||||||
|
sif::error << "Semaphore: Binary semaph creation failure" << std::endl;
|
||||||
|
}
|
||||||
|
// Initiated semaphore must be given before it can be taken.
|
||||||
|
xSemaphoreGive(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
BinarySemaphore::~BinarySemaphore() {
|
||||||
|
vSemaphoreDelete(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
|
||||||
|
handle = xSemaphoreCreateBinary();
|
||||||
|
if(handle == nullptr) {
|
||||||
|
sif::error << "Binary semaphore creation failure" << std::endl;
|
||||||
|
}
|
||||||
|
xSemaphoreGive(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
BinarySemaphore& BinarySemaphore::operator =(
|
||||||
|
BinarySemaphore&& s) {
|
||||||
|
if(&s != this) {
|
||||||
|
handle = xSemaphoreCreateBinary();
|
||||||
|
if(handle == nullptr) {
|
||||||
|
sif::error << "Binary semaphore creation failure" << std::endl;
|
||||||
|
}
|
||||||
|
xSemaphoreGive(handle);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType,
|
||||||
|
uint32_t timeoutMs) {
|
||||||
|
TickType_t timeout = 0;
|
||||||
|
if(timeoutType == TimeoutType::POLLING) {
|
||||||
|
timeout = 0;
|
||||||
|
}
|
||||||
|
else if(timeoutType == TimeoutType::WAITING){
|
||||||
|
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timeout = portMAX_DELAY;
|
||||||
|
}
|
||||||
|
return acquireWithTickTimeout(timeoutType, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::acquireWithTickTimeout(TimeoutType timeoutType,
|
||||||
|
TickType_t timeoutTicks) {
|
||||||
|
if(handle == nullptr) {
|
||||||
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseType_t returncode = xSemaphoreTake(handle, timeoutTicks);
|
||||||
|
if (returncode == pdPASS) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::release() {
|
||||||
|
return release(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::release(SemaphoreHandle_t semaphore) {
|
||||||
|
if (semaphore == nullptr) {
|
||||||
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
|
}
|
||||||
|
BaseType_t returncode = xSemaphoreGive(semaphore);
|
||||||
|
if (returncode == pdPASS) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphore::getSemaphoreCounter() const {
|
||||||
|
return uxSemaphoreGetCount(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreHandle_t BinarySemaphore::getSemaphore() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Be careful with the stack size here. This is called from an ISR!
|
||||||
|
ReturnValue_t BinarySemaphore::releaseFromISR(
|
||||||
|
SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) {
|
||||||
|
if (semaphore == nullptr) {
|
||||||
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
|
}
|
||||||
|
BaseType_t returncode = xSemaphoreGiveFromISR(semaphore,
|
||||||
|
higherPriorityTaskWoken);
|
||||||
|
if (returncode == pdPASS) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||||
|
}
|
||||||
|
}
|
107
osal/FreeRTOS/BinarySemaphore.h
Normal file
107
osal/FreeRTOS/BinarySemaphore.h
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
|
||||||
|
#define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_
|
||||||
|
|
||||||
|
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include "../../tasks/SemaphoreIF.h"
|
||||||
|
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/semphr.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OS Tool to achieve synchronization of between tasks or between
|
||||||
|
* task and ISR. The default semaphore implementation creates a
|
||||||
|
* binary semaphore, which can only be taken once.
|
||||||
|
* @details
|
||||||
|
* Documentation: https://www.freertos.org/Embedded-RTOS-Binary-Semaphores.html
|
||||||
|
*
|
||||||
|
* Please note that if the semaphore implementation is only related to
|
||||||
|
* the synchronization of one task, the new task notifications can be used,
|
||||||
|
* also see the BinSemaphUsingTask and CountingSemaphUsingTask classes.
|
||||||
|
* These use the task notification value instead of a queue and are
|
||||||
|
* faster and more efficient.
|
||||||
|
*
|
||||||
|
* @author R. Mueller
|
||||||
|
* @ingroup osal
|
||||||
|
*/
|
||||||
|
class BinarySemaphore: public SemaphoreIF,
|
||||||
|
public HasReturnvaluesIF {
|
||||||
|
public:
|
||||||
|
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||||
|
|
||||||
|
//! @brief Default ctor
|
||||||
|
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
|
||||||
|
BinarySemaphore & operator=(BinarySemaphore &&);
|
||||||
|
//! @brief Destructor
|
||||||
|
virtual ~BinarySemaphore();
|
||||||
|
|
||||||
|
uint8_t getSemaphoreCounter() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take the binary semaphore.
|
||||||
|
* If the semaphore has already been taken, the task will be blocked
|
||||||
|
* for a maximum of #timeoutMs or until the semaphore is given back,
|
||||||
|
* for example by an ISR or another task.
|
||||||
|
* @param timeoutMs
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||||
|
*/
|
||||||
|
ReturnValue_t acquire(TimeoutType timeoutType =
|
||||||
|
TimeoutType::BLOCKING, uint32_t timeoutMs = portMAX_DELAY) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as lockBinarySemaphore() with timeout in FreeRTOS ticks.
|
||||||
|
* @param timeoutTicks
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||||
|
*/
|
||||||
|
ReturnValue_t acquireWithTickTimeout(TimeoutType timeoutType =
|
||||||
|
TimeoutType::BLOCKING, TickType_t timeoutTicks = portMAX_DELAY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release the binary semaphore.
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||||
|
* already available.
|
||||||
|
*/
|
||||||
|
ReturnValue_t release() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Handle to the semaphore.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SemaphoreHandle_t getSemaphore();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper function to give back semaphore from handle
|
||||||
|
* @param semaphore
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||||
|
* already available.
|
||||||
|
*/
|
||||||
|
static ReturnValue_t release(SemaphoreHandle_t semaphore);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper function to give back semaphore from handle when called from an ISR
|
||||||
|
* @param semaphore
|
||||||
|
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||||
|
* a higher priority was unblocked. A context switch from an ISR should
|
||||||
|
* then be requested (see TaskManagement functions)
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||||
|
* already available.
|
||||||
|
*/
|
||||||
|
static ReturnValue_t releaseFromISR(SemaphoreHandle_t semaphore,
|
||||||
|
BaseType_t * higherPriorityTaskWoken);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
SemaphoreHandle_t handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */
|
114
osal/FreeRTOS/CountingSemaphUsingTask.cpp
Normal file
114
osal/FreeRTOS/CountingSemaphUsingTask.cpp
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
#include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
|
||||||
|
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
CountingSemaphoreUsingTask::CountingSemaphoreUsingTask(const uint8_t maxCount,
|
||||||
|
uint8_t initCount): maxCount(maxCount) {
|
||||||
|
if(initCount > maxCount) {
|
||||||
|
sif::error << "CountingSemaphoreUsingTask: Max count bigger than "
|
||||||
|
"intial cout. Setting initial count to max count." << std::endl;
|
||||||
|
initCount = maxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
handle = TaskManagement::getCurrentTaskHandle();
|
||||||
|
if(handle == nullptr) {
|
||||||
|
sif::error << "CountingSemaphoreUsingTask: Could not retrieve task "
|
||||||
|
"handle. Please ensure the constructor was called inside a "
|
||||||
|
"task." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t oldNotificationValue;
|
||||||
|
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite,
|
||||||
|
&oldNotificationValue);
|
||||||
|
if(oldNotificationValue != 0) {
|
||||||
|
sif::warning << "CountinSemaphoreUsingTask: Semaphore initiated but "
|
||||||
|
"current notification value is not 0. Please ensure the "
|
||||||
|
"notification value is not used for other purposes!" << std::endl;
|
||||||
|
}
|
||||||
|
for(int i = 0; i < initCount; i++) {
|
||||||
|
xTaskNotifyGive(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CountingSemaphoreUsingTask::~CountingSemaphoreUsingTask() {
|
||||||
|
// Clear notification value on destruction.
|
||||||
|
// If this is not desired, don't call the destructor
|
||||||
|
// (or implement a boolean which disables the reset)
|
||||||
|
xTaskNotifyAndQuery(handle, 0, eSetValueWithOverwrite, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphoreUsingTask::acquire(TimeoutType timeoutType,
|
||||||
|
uint32_t timeoutMs) {
|
||||||
|
TickType_t timeout = 0;
|
||||||
|
if(timeoutType == TimeoutType::POLLING) {
|
||||||
|
timeout = 0;
|
||||||
|
}
|
||||||
|
else if(timeoutType == TimeoutType::WAITING){
|
||||||
|
timeout = pdMS_TO_TICKS(timeoutMs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
timeout = portMAX_DELAY;
|
||||||
|
}
|
||||||
|
return acquireWithTickTimeout(timeoutType, timeout);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphoreUsingTask::acquireWithTickTimeout(
|
||||||
|
TimeoutType timeoutType, TickType_t timeoutTicks) {
|
||||||
|
// Decrement notfication value without resetting it.
|
||||||
|
BaseType_t oldCount = ulTaskNotifyTake(pdFALSE, timeoutTicks);
|
||||||
|
if (getSemaphoreCounter() == oldCount - 1) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphoreUsingTask::release() {
|
||||||
|
if(getSemaphoreCounter() == maxCount) {
|
||||||
|
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||||
|
}
|
||||||
|
return release(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphoreUsingTask::release(
|
||||||
|
TaskHandle_t taskToNotify) {
|
||||||
|
BaseType_t returncode = xTaskNotifyGive(taskToNotify);
|
||||||
|
if (returncode == pdPASS) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// This should never happen.
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounter() const {
|
||||||
|
uint32_t notificationValue = 0;
|
||||||
|
xTaskNotifyAndQuery(handle, 0, eNoAction, ¬ificationValue);
|
||||||
|
return notificationValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskHandle_t CountingSemaphoreUsingTask::getTaskHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphoreUsingTask::releaseFromISR(
|
||||||
|
TaskHandle_t taskToNotify, BaseType_t* higherPriorityTaskWoken) {
|
||||||
|
vTaskNotifyGiveFromISR(taskToNotify, higherPriorityTaskWoken);
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CountingSemaphoreUsingTask::getSemaphoreCounterFromISR(
|
||||||
|
TaskHandle_t task, BaseType_t* higherPriorityTaskWoken) {
|
||||||
|
uint32_t notificationValue;
|
||||||
|
xTaskNotifyAndQueryFromISR(task, 0, eNoAction, ¬ificationValue,
|
||||||
|
higherPriorityTaskWoken);
|
||||||
|
return notificationValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CountingSemaphoreUsingTask::getMaxCount() const {
|
||||||
|
return maxCount;
|
||||||
|
}
|
102
osal/FreeRTOS/CountingSemaphUsingTask.h
Normal file
102
osal/FreeRTOS/CountingSemaphUsingTask.h
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_
|
||||||
|
#define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_
|
||||||
|
|
||||||
|
#include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
|
||||||
|
#include "../../tasks/SemaphoreIF.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Couting Semaphore implementation which uses the notification value
|
||||||
|
* of the task. The notification value should therefore not be used
|
||||||
|
* for other purposes.
|
||||||
|
* @details
|
||||||
|
* Additional information: https://www.freertos.org/RTOS-task-notifications.html
|
||||||
|
* and general semaphore documentation.
|
||||||
|
*/
|
||||||
|
class CountingSemaphoreUsingTask: public SemaphoreIF {
|
||||||
|
public:
|
||||||
|
CountingSemaphoreUsingTask(const uint8_t maxCount, uint8_t initCount);
|
||||||
|
virtual ~CountingSemaphoreUsingTask();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Acquire the counting semaphore.
|
||||||
|
* If no semaphores are available, the task will be blocked
|
||||||
|
* for a maximum of #timeoutMs or until one is given back,
|
||||||
|
* for example by an ISR or another task.
|
||||||
|
* @param timeoutMs
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||||
|
*/
|
||||||
|
ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||||
|
uint32_t timeoutMs = portMAX_DELAY) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release a semaphore, increasing the number of available counting
|
||||||
|
* semaphores up to the #maxCount value.
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
||||||
|
* already available.
|
||||||
|
*/
|
||||||
|
ReturnValue_t release() override;
|
||||||
|
|
||||||
|
uint8_t getSemaphoreCounter() const override;
|
||||||
|
/**
|
||||||
|
* Get the semaphore counter from an ISR.
|
||||||
|
* @param task
|
||||||
|
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||||
|
* a higher priority was unblocked. A context switch should be requested
|
||||||
|
* from an ISR if this is the case (see TaskManagement functions)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static uint8_t getSemaphoreCounterFromISR(TaskHandle_t task,
|
||||||
|
BaseType_t* higherPriorityTaskWoken);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Acquire with a timeout value in ticks
|
||||||
|
* @param timeoutTicks
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||||
|
*/
|
||||||
|
ReturnValue_t acquireWithTickTimeout(
|
||||||
|
TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||||
|
TickType_t timeoutTicks = portMAX_DELAY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get handle to the task related to the semaphore.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
TaskHandle_t getTaskHandle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release semaphore of task by supplying task handle
|
||||||
|
* @param taskToNotify
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
||||||
|
* already available.
|
||||||
|
*/
|
||||||
|
static ReturnValue_t release(TaskHandle_t taskToNotify);
|
||||||
|
/**
|
||||||
|
* Release seamphore of a task from an ISR.
|
||||||
|
* @param taskToNotify
|
||||||
|
* @param higherPriorityTaskWoken This will be set to pdPASS if a task with
|
||||||
|
* a higher priority was unblocked. A context switch should be requested
|
||||||
|
* from an ISR if this is the case (see TaskManagement functions)
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if #maxCount semaphores are
|
||||||
|
* already available.
|
||||||
|
*/
|
||||||
|
static ReturnValue_t releaseFromISR(TaskHandle_t taskToNotify,
|
||||||
|
BaseType_t* higherPriorityTaskWoken);
|
||||||
|
|
||||||
|
uint8_t getMaxCount() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
TaskHandle_t handle;
|
||||||
|
const uint8_t maxCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHUSINGTASK_H_ */
|
43
osal/FreeRTOS/CountingSemaphore.cpp
Normal file
43
osal/FreeRTOS/CountingSemaphore.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include "../../osal/FreeRTOS/CountingSemaphore.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||||
|
|
||||||
|
#include <freertos/semphr.h>
|
||||||
|
|
||||||
|
// Make sure #define configUSE_COUNTING_SEMAPHORES 1 is set in
|
||||||
|
// free FreeRTOSConfig.h file.
|
||||||
|
CountingSemaphore::CountingSemaphore(const uint8_t maxCount, uint8_t initCount):
|
||||||
|
maxCount(maxCount), initCount(initCount) {
|
||||||
|
if(initCount > maxCount) {
|
||||||
|
sif::error << "CountingSemaphoreUsingTask: Max count bigger than "
|
||||||
|
"intial cout. Setting initial count to max count." << std::endl;
|
||||||
|
initCount = maxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
handle = xSemaphoreCreateCounting(maxCount, initCount);
|
||||||
|
if(handle == nullptr) {
|
||||||
|
sif::error << "CountingSemaphore: Creation failure" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CountingSemaphore::CountingSemaphore(CountingSemaphore&& other):
|
||||||
|
maxCount(other.maxCount), initCount(other.initCount) {
|
||||||
|
handle = xSemaphoreCreateCounting(other.maxCount, other.initCount);
|
||||||
|
if(handle == nullptr) {
|
||||||
|
sif::error << "CountingSemaphore: Creation failure" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CountingSemaphore& CountingSemaphore::operator =(
|
||||||
|
CountingSemaphore&& other) {
|
||||||
|
handle = xSemaphoreCreateCounting(other.maxCount, other.initCount);
|
||||||
|
if(handle == nullptr) {
|
||||||
|
sif::error << "CountingSemaphore: Creation failure" << std::endl;
|
||||||
|
}
|
||||||
|
return * this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t CountingSemaphore::getMaxCount() const {
|
||||||
|
return maxCount;
|
||||||
|
}
|
34
osal/FreeRTOS/CountingSemaphore.h
Normal file
34
osal/FreeRTOS/CountingSemaphore.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_
|
||||||
|
#define FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_
|
||||||
|
#include "../../osal/FreeRTOS/BinarySemaphore.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Counting semaphores, which can be acquire more than once.
|
||||||
|
* @details
|
||||||
|
* See: https://www.freertos.org/CreateCounting.html
|
||||||
|
* API of counting semaphores is almost identical to binary semaphores,
|
||||||
|
* so we just inherit from binary semaphore and provide the respective
|
||||||
|
* constructors.
|
||||||
|
*/
|
||||||
|
class CountingSemaphore: public BinarySemaphore {
|
||||||
|
public:
|
||||||
|
CountingSemaphore(const uint8_t maxCount, uint8_t initCount);
|
||||||
|
//! @brief Copy ctor, disabled
|
||||||
|
CountingSemaphore(const CountingSemaphore&) = delete;
|
||||||
|
//! @brief Copy assignment, disabled
|
||||||
|
CountingSemaphore& operator=(const CountingSemaphore&) = delete;
|
||||||
|
//! @brief Move ctor
|
||||||
|
CountingSemaphore (CountingSemaphore &&);
|
||||||
|
//! @brief Move assignment
|
||||||
|
CountingSemaphore & operator=(CountingSemaphore &&);
|
||||||
|
|
||||||
|
/* Same API as binary semaphore otherwise. acquire() can be called
|
||||||
|
* until there are not semaphores left and release() can be called
|
||||||
|
* until maxCount is reached. */
|
||||||
|
uint8_t getMaxCount() const;
|
||||||
|
private:
|
||||||
|
const uint8_t maxCount;
|
||||||
|
uint8_t initCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_ */
|
@ -5,11 +5,12 @@
|
|||||||
uint32_t FixedTimeslotTask::deadlineMissedCount = 0;
|
uint32_t FixedTimeslotTask::deadlineMissedCount = 0;
|
||||||
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = configMINIMAL_STACK_SIZE;
|
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = configMINIMAL_STACK_SIZE;
|
||||||
|
|
||||||
FixedTimeslotTask::FixedTimeslotTask(const char *name, TaskPriority setPriority,
|
FixedTimeslotTask::FixedTimeslotTask(TaskName name, TaskPriority setPriority,
|
||||||
TaskStackSize setStack, TaskPeriod overallPeriod,
|
TaskStackSize setStack, TaskPeriod overallPeriod,
|
||||||
void (*setDeadlineMissedFunc)()) :
|
void (*setDeadlineMissedFunc)()) :
|
||||||
started(false), handle(NULL), pst(overallPeriod * 1000) {
|
started(false), handle(NULL), pst(overallPeriod * 1000) {
|
||||||
xTaskCreate(taskEntryPoint, name, setStack, this, setPriority, &handle);
|
configSTACK_DEPTH_TYPE stackSize = setStack / sizeof(configSTACK_DEPTH_TYPE);
|
||||||
|
xTaskCreate(taskEntryPoint, name, stackSize, this, setPriority, &handle);
|
||||||
// All additional attributes are applied to the object.
|
// All additional attributes are applied to the object.
|
||||||
this->deadlineMissedFunc = setDeadlineMissedFunc;
|
this->deadlineMissedFunc = setDeadlineMissedFunc;
|
||||||
}
|
}
|
||||||
@ -82,7 +83,7 @@ ReturnValue_t FixedTimeslotTask::checkSequence() const {
|
|||||||
void FixedTimeslotTask::taskFunctionality() {
|
void FixedTimeslotTask::taskFunctionality() {
|
||||||
// A local iterator for the Polling Sequence Table is created to find the
|
// A local iterator for the Polling Sequence Table is created to find the
|
||||||
// start time for the first entry.
|
// start time for the first entry.
|
||||||
FixedSlotSequence::SlotListIter slotListIter = pst.current;
|
auto slotListIter = pst.current;
|
||||||
|
|
||||||
//The start time for the first entry is read.
|
//The start time for the first entry is read.
|
||||||
uint32_t intervalMs = slotListIter->pollingTimeMs;
|
uint32_t intervalMs = slotListIter->pollingTimeMs;
|
||||||
@ -155,3 +156,7 @@ ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms) {
|
|||||||
vTaskDelay(pdMS_TO_TICKS(ms));
|
vTaskDelay(pdMS_TO_TICKS(ms));
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TaskHandle_t FixedTimeslotTask::getTaskHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
#ifndef FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
#ifndef FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
||||||
#define FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
#define FRAMEWORK_OSAL_FREERTOS_FIXEDTIMESLOTTASK_H_
|
||||||
|
|
||||||
|
#include "FreeRTOSTaskIF.h"
|
||||||
#include "../../devicehandlers/FixedSlotSequence.h"
|
#include "../../devicehandlers/FixedSlotSequence.h"
|
||||||
#include "../../tasks/FixedTimeslotTaskIF.h"
|
#include "../../tasks/FixedTimeslotTaskIF.h"
|
||||||
#include "../../tasks/Typedef.h"
|
#include "../../tasks/Typedef.h"
|
||||||
|
|
||||||
|
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
|
|
||||||
class FixedTimeslotTask: public FixedTimeslotTaskIF {
|
class FixedTimeslotTask: public FixedTimeslotTaskIF, public FreeRTOSTaskIF {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,7 +25,7 @@ public:
|
|||||||
* @param setDeadlineMissedFunc Callback if a deadline was missed.
|
* @param setDeadlineMissedFunc Callback if a deadline was missed.
|
||||||
* @return Pointer to the newly created task.
|
* @return Pointer to the newly created task.
|
||||||
*/
|
*/
|
||||||
FixedTimeslotTask(const char *name, TaskPriority setPriority,
|
FixedTimeslotTask(TaskName name, TaskPriority setPriority,
|
||||||
TaskStackSize setStack, TaskPeriod overallPeriod,
|
TaskStackSize setStack, TaskPeriod overallPeriod,
|
||||||
void (*setDeadlineMissedFunc)());
|
void (*setDeadlineMissedFunc)());
|
||||||
|
|
||||||
@ -57,6 +59,8 @@ public:
|
|||||||
|
|
||||||
ReturnValue_t sleepFor(uint32_t ms) override;
|
ReturnValue_t sleepFor(uint32_t ms) override;
|
||||||
|
|
||||||
|
TaskHandle_t getTaskHandle() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool started;
|
bool started;
|
||||||
TaskHandle_t handle;
|
TaskHandle_t handle;
|
||||||
|
13
osal/FreeRTOS/FreeRTOSTaskIF.h
Normal file
13
osal/FreeRTOS/FreeRTOSTaskIF.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef FRAMEWORK_OSAL_FREERTOS_FREERTOSTASKIF_H_
|
||||||
|
#define FRAMEWORK_OSAL_FREERTOS_FREERTOSTASKIF_H_
|
||||||
|
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
|
||||||
|
class FreeRTOSTaskIF {
|
||||||
|
public:
|
||||||
|
virtual~ FreeRTOSTaskIF() {}
|
||||||
|
virtual TaskHandle_t getTaskHandle() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_OSAL_FREERTOS_FREERTOSTASKIF_H_ */
|
@ -1,4 +1,4 @@
|
|||||||
#include <framework/osal/FreeRTOS/Mutex.h>
|
#include "Mutex.h"
|
||||||
|
|
||||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
@ -5,12 +5,13 @@
|
|||||||
|
|
||||||
PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
|
PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
|
||||||
TaskStackSize setStack, TaskPeriod setPeriod,
|
TaskStackSize setStack, TaskPeriod setPeriod,
|
||||||
void (*setDeadlineMissedFunc)()) :
|
TaskDeadlineMissedFunction deadlineMissedFunc) :
|
||||||
started(false), handle(NULL), period(setPeriod), deadlineMissedFunc(
|
started(false), handle(NULL), period(setPeriod), deadlineMissedFunc(
|
||||||
setDeadlineMissedFunc)
|
deadlineMissedFunc)
|
||||||
{
|
{
|
||||||
|
configSTACK_DEPTH_TYPE stackSize = setStack / sizeof(configSTACK_DEPTH_TYPE);
|
||||||
BaseType_t status = xTaskCreate(taskEntryPoint, name,
|
BaseType_t status = xTaskCreate(taskEntryPoint, name,
|
||||||
setStack, this, setPriority, &handle);
|
stackSize, this, setPriority, &handle);
|
||||||
if(status != pdPASS){
|
if(status != pdPASS){
|
||||||
sif::debug << "PeriodicTask Insufficient heap memory remaining. "
|
sif::debug << "PeriodicTask Insufficient heap memory remaining. "
|
||||||
"Status: " << status << std::endl;
|
"Status: " << status << std::endl;
|
||||||
@ -86,12 +87,12 @@ ReturnValue_t PeriodicTask::addComponent(object_id_t object) {
|
|||||||
object);
|
object);
|
||||||
if (newObject == nullptr) {
|
if (newObject == nullptr) {
|
||||||
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
|
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
|
||||||
"it implements ExecutableObjectIF!" << std::endl;
|
"it implement ExecutableObjectIF" << std::endl;
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
objectList.push_back(newObject);
|
objectList.push_back(newObject);
|
||||||
|
|
||||||
newObject->setTaskIF(this);
|
newObject->setTaskIF(this);
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +123,10 @@ void PeriodicTask::checkMissedDeadline(const TickType_t xLastWakeTime,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TaskHandle_t PeriodicTask::getTaskHandle() {
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
void PeriodicTask::handleMissedDeadline() {
|
void PeriodicTask::handleMissedDeadline() {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
sif::warning << "PeriodicTask: " << pcTaskGetName(NULL) <<
|
sif::warning << "PeriodicTask: " << pcTaskGetName(NULL) <<
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "../../objectmanager/ObjectManagerIF.h"
|
#include "../../objectmanager/ObjectManagerIF.h"
|
||||||
#include "../../tasks/PeriodicTaskIF.h"
|
#include "../../tasks/PeriodicTaskIF.h"
|
||||||
#include "../../tasks/Typedef.h"
|
#include "../../tasks/Typedef.h"
|
||||||
|
#include "FreeRTOSTaskIF.h"
|
||||||
|
|
||||||
|
|
||||||
#include <freertos/FreeRTOS.h>
|
#include <freertos/FreeRTOS.h>
|
||||||
#include <freertos/task.h>
|
#include <freertos/task.h>
|
||||||
@ -17,7 +19,7 @@ class ExecutableObjectIF;
|
|||||||
* periodic activities of multiple objects.
|
* periodic activities of multiple objects.
|
||||||
* @ingroup task_handling
|
* @ingroup task_handling
|
||||||
*/
|
*/
|
||||||
class PeriodicTask: public PeriodicTaskIF {
|
class PeriodicTask: public PeriodicTaskIF, public FreeRTOSTaskIF {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Keep in Mind that you need to call before this vTaskStartScheduler()!
|
* Keep in Mind that you need to call before this vTaskStartScheduler()!
|
||||||
@ -38,9 +40,9 @@ public:
|
|||||||
* The function pointer to the deadline missed function that shall
|
* The function pointer to the deadline missed function that shall
|
||||||
* be assigned.
|
* be assigned.
|
||||||
*/
|
*/
|
||||||
PeriodicTask(const char *name, TaskPriority setPriority,
|
PeriodicTask(TaskName name, TaskPriority setPriority,
|
||||||
TaskStackSize setStack, TaskPeriod setPeriod,
|
TaskStackSize setStack, TaskPeriod setPeriod,
|
||||||
void (*setDeadlineMissedFunc)());
|
TaskDeadlineMissedFunction deadlineMissedFunc);
|
||||||
/**
|
/**
|
||||||
* @brief Currently, the executed object's lifetime is not coupled with
|
* @brief Currently, the executed object's lifetime is not coupled with
|
||||||
* the task object's lifetime, so the destructor is empty.
|
* the task object's lifetime, so the destructor is empty.
|
||||||
@ -68,6 +70,8 @@ public:
|
|||||||
uint32_t getPeriodMs() const override;
|
uint32_t getPeriodMs() const override;
|
||||||
|
|
||||||
ReturnValue_t sleepFor(uint32_t ms) override;
|
ReturnValue_t sleepFor(uint32_t ms) override;
|
||||||
|
|
||||||
|
TaskHandle_t getTaskHandle() override;
|
||||||
protected:
|
protected:
|
||||||
bool started;
|
bool started;
|
||||||
TaskHandle_t handle;
|
TaskHandle_t handle;
|
||||||
|
59
osal/FreeRTOS/SemaphoreFactory.cpp
Normal file
59
osal/FreeRTOS/SemaphoreFactory.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include "../../osal/FreeRTOS/BinarySemaphore.h"
|
||||||
|
#include "../../osal/FreeRTOS/BinSemaphUsingTask.h"
|
||||||
|
#include "../../osal/FreeRTOS/CountingSemaphore.h"
|
||||||
|
#include "../../osal/FreeRTOS/CountingSemaphUsingTask.h"
|
||||||
|
#include "../../tasks/SemaphoreFactory.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
|
||||||
|
|
||||||
|
static const uint32_t USE_REGULAR_SEMAPHORES = 0;
|
||||||
|
static const uint32_t USE_TASK_NOTIFICATIONS = 1;
|
||||||
|
|
||||||
|
SemaphoreFactory::SemaphoreFactory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreFactory::~SemaphoreFactory() {
|
||||||
|
delete factoryInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreFactory* SemaphoreFactory::instance() {
|
||||||
|
if (factoryInstance == nullptr){
|
||||||
|
factoryInstance = new SemaphoreFactory();
|
||||||
|
}
|
||||||
|
return SemaphoreFactory::factoryInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t argument) {
|
||||||
|
if(argument == USE_REGULAR_SEMAPHORES) {
|
||||||
|
return new BinarySemaphore();
|
||||||
|
}
|
||||||
|
else if(argument == USE_TASK_NOTIFICATIONS) {
|
||||||
|
return new BinarySemaphoreUsingTask();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
|
||||||
|
"binary semaphore" << std::endl;
|
||||||
|
return new BinarySemaphore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreIF* SemaphoreFactory::createCountingSemaphore(uint8_t maxCount,
|
||||||
|
uint8_t initCount, uint32_t argument) {
|
||||||
|
if(argument == USE_REGULAR_SEMAPHORES) {
|
||||||
|
return new CountingSemaphore(maxCount, initCount);
|
||||||
|
}
|
||||||
|
else if(argument == USE_TASK_NOTIFICATIONS) {
|
||||||
|
return new CountingSemaphoreUsingTask(maxCount, initCount);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sif::warning << "SemaphoreFactory: Invalid argument, return regular"
|
||||||
|
"binary semaphore" << std::endl;
|
||||||
|
return new CountingSemaphore(maxCount, initCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {
|
||||||
|
delete semaphore;
|
||||||
|
}
|
24
osal/FreeRTOS/TaskManagement.cpp
Normal file
24
osal/FreeRTOS/TaskManagement.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "../../osal/FreeRTOS/TaskManagement.h"
|
||||||
|
|
||||||
|
void TaskManagement::vRequestContextSwitchFromTask() {
|
||||||
|
vTaskDelay(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskManagement::requestContextSwitch(
|
||||||
|
CallContext callContext = CallContext::TASK) {
|
||||||
|
if(callContext == CallContext::ISR) {
|
||||||
|
// This function depends on the partmacro.h definition for the specific device
|
||||||
|
vRequestContextSwitchFromISR();
|
||||||
|
} else {
|
||||||
|
vRequestContextSwitchFromTask();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskHandle_t TaskManagement::getCurrentTaskHandle() {
|
||||||
|
return xTaskGetCurrentTaskHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t TaskManagement::getTaskStackHighWatermark(
|
||||||
|
TaskHandle_t task) {
|
||||||
|
return uxTaskGetStackHighWaterMark(task) * sizeof(StackType_t);
|
||||||
|
}
|
64
osal/FreeRTOS/TaskManagement.h
Normal file
64
osal/FreeRTOS/TaskManagement.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
|
||||||
|
#define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_
|
||||||
|
|
||||||
|
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <freertos/FreeRTOS.h>
|
||||||
|
#include <freertos/task.h>
|
||||||
|
}
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Architecture dependant portmacro.h function call.
|
||||||
|
* Should be implemented in bsp.
|
||||||
|
*/
|
||||||
|
extern void vRequestContextSwitchFromISR();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Used by functions to tell if they are being called from
|
||||||
|
* within an ISR or from a regular task. This is required because FreeRTOS
|
||||||
|
* has different functions for handling semaphores and messages from within
|
||||||
|
* an ISR and task.
|
||||||
|
*/
|
||||||
|
enum class CallContext {
|
||||||
|
TASK = 0x00,//!< task_context
|
||||||
|
ISR = 0xFF //!< isr_context
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class TaskManagement {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief In this function, a function dependant on the portmacro.h header
|
||||||
|
* function calls to request a context switch can be specified.
|
||||||
|
* This can be used if sending to the queue from an ISR caused a task
|
||||||
|
* to unblock and a context switch is required.
|
||||||
|
*/
|
||||||
|
static void requestContextSwitch(CallContext callContext);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If task preemption in FreeRTOS is disabled, a context switch
|
||||||
|
* can be requested manually by calling this function.
|
||||||
|
*/
|
||||||
|
static void vRequestContextSwitchFromTask(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The current task handle
|
||||||
|
*/
|
||||||
|
static TaskHandle_t getCurrentTaskHandle();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get returns the minimum amount of remaining stack space in words
|
||||||
|
* that was a available to the task since the task started executing.
|
||||||
|
* Please note that the actual value in bytes depends
|
||||||
|
* on the stack depth type.
|
||||||
|
* E.g. on a 32 bit machine, a value of 200 means 800 bytes.
|
||||||
|
* @return Smallest value of stack remaining since the task was started in
|
||||||
|
* words.
|
||||||
|
*/
|
||||||
|
static size_t getTaskStackHighWatermark(
|
||||||
|
TaskHandle_t task = nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */
|
149
osal/linux/BinarySemaphore.cpp
Normal file
149
osal/linux/BinarySemaphore.cpp
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
#include "../../osal/linux/BinarySemaphore.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
BinarySemaphore::BinarySemaphore() {
|
||||||
|
// Using unnamed semaphores for now
|
||||||
|
initSemaphore();
|
||||||
|
}
|
||||||
|
|
||||||
|
BinarySemaphore::~BinarySemaphore() {
|
||||||
|
sem_destroy(&handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) {
|
||||||
|
initSemaphore();
|
||||||
|
}
|
||||||
|
|
||||||
|
BinarySemaphore& BinarySemaphore::operator =(
|
||||||
|
BinarySemaphore&& s) {
|
||||||
|
initSemaphore();
|
||||||
|
return * this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType,
|
||||||
|
uint32_t timeoutMs) {
|
||||||
|
int result = 0;
|
||||||
|
if(timeoutType == TimeoutType::POLLING) {
|
||||||
|
result = sem_trywait(&handle);
|
||||||
|
}
|
||||||
|
else if(timeoutType == TimeoutType::BLOCKING) {
|
||||||
|
result = sem_wait(&handle);
|
||||||
|
}
|
||||||
|
else if(timeoutType == TimeoutType::WAITING){
|
||||||
|
timespec timeOut;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &timeOut);
|
||||||
|
uint64_t nseconds = timeOut.tv_sec * 1000000000 + timeOut.tv_nsec;
|
||||||
|
nseconds += timeoutMs * 1000000;
|
||||||
|
timeOut.tv_sec = nseconds / 1000000000;
|
||||||
|
timeOut.tv_nsec = nseconds - timeOut.tv_sec * 1000000000;
|
||||||
|
result = sem_timedwait(&handle, &timeOut);
|
||||||
|
if(result != 0 and errno == EINVAL) {
|
||||||
|
sif::debug << "BinarySemaphore::acquire: Invalid time value possible"
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(result == 0) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(errno) {
|
||||||
|
case(EAGAIN):
|
||||||
|
// Operation could not be performed without blocking (for sem_trywait)
|
||||||
|
case(ETIMEDOUT):
|
||||||
|
// Semaphore is 0
|
||||||
|
return SemaphoreIF::SEMAPHORE_TIMEOUT;
|
||||||
|
case(EINVAL):
|
||||||
|
// Semaphore invalid
|
||||||
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
|
case(EINTR):
|
||||||
|
// Call was interrupted by signal handler
|
||||||
|
sif::debug << "BinarySemaphore::acquire: Signal handler interrupted."
|
||||||
|
"Code " << strerror(errno) << std::endl;
|
||||||
|
/* No break */
|
||||||
|
default:
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::release() {
|
||||||
|
return BinarySemaphore::release(&this->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::release(sem_t *handle) {
|
||||||
|
ReturnValue_t countResult = checkCount(handle, 1);
|
||||||
|
if(countResult != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return countResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = sem_post(handle);
|
||||||
|
if(result == 0) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(errno) {
|
||||||
|
case(EINVAL):
|
||||||
|
// Semaphore invalid
|
||||||
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
|
case(EOVERFLOW):
|
||||||
|
// SEM_MAX_VALUE overflow. This should never happen
|
||||||
|
default:
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphore::getSemaphoreCounter() const {
|
||||||
|
// And another ugly cast :-D
|
||||||
|
return getSemaphoreCounter(const_cast<sem_t*>(&this->handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BinarySemaphore::getSemaphoreCounter(sem_t *handle) {
|
||||||
|
int value = 0;
|
||||||
|
int result = sem_getvalue(handle, &value);
|
||||||
|
if (result == 0) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
else if(result != 0 and errno == EINVAL) {
|
||||||
|
// Could be called from interrupt, use lightweight printf
|
||||||
|
printf("BinarySemaphore::getSemaphoreCounter: Invalid semaphore\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// This should never happen.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BinarySemaphore::initSemaphore(uint8_t initCount) {
|
||||||
|
auto result = sem_init(&handle, true, initCount);
|
||||||
|
if(result == -1) {
|
||||||
|
switch(errno) {
|
||||||
|
case(EINVAL):
|
||||||
|
// Value exceeds SEM_VALUE_MAX
|
||||||
|
case(ENOSYS):
|
||||||
|
// System does not support process-shared semaphores
|
||||||
|
sif::error << "BinarySemaphore: Init failed with" << strerror(errno)
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t BinarySemaphore::checkCount(sem_t* handle, uint8_t maxCount) {
|
||||||
|
int value = getSemaphoreCounter(handle);
|
||||||
|
if(value >= maxCount) {
|
||||||
|
if(maxCount == 1 and value > 1) {
|
||||||
|
// Binary Semaphore special case.
|
||||||
|
// This is a config error use lightweight printf is this is called
|
||||||
|
// from an interrupt
|
||||||
|
printf("BinarySemaphore::release: Value of binary semaphore greater"
|
||||||
|
" than 1!\n");
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
return SemaphoreIF::SEMAPHORE_NOT_OWNED;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
81
osal/linux/BinarySemaphore.h
Normal file
81
osal/linux/BinarySemaphore.h
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
#ifndef FRAMEWORK_OSAL_LINUX_BINARYSEMPAHORE_H_
|
||||||
|
#define FRAMEWORK_OSAL_LINUX_BINARYSEMPAHORE_H_
|
||||||
|
|
||||||
|
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include "../../tasks/SemaphoreIF.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <semaphore.h>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief OS Tool to achieve synchronization of between tasks or between
|
||||||
|
* task and ISR. The default semaphore implementation creates a
|
||||||
|
* binary semaphore, which can only be taken once.
|
||||||
|
* @details
|
||||||
|
* See: http://www.man7.org/linux/man-pages/man7/sem_overview.7.html
|
||||||
|
* @author R. Mueller
|
||||||
|
* @ingroup osal
|
||||||
|
*/
|
||||||
|
class BinarySemaphore: public SemaphoreIF,
|
||||||
|
public HasReturnvaluesIF {
|
||||||
|
public:
|
||||||
|
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||||
|
|
||||||
|
//! @brief Default ctor
|
||||||
|
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
|
||||||
|
BinarySemaphore & operator=(BinarySemaphore &&);
|
||||||
|
//! @brief Destructor
|
||||||
|
virtual ~BinarySemaphore();
|
||||||
|
|
||||||
|
void initSemaphore(uint8_t initCount = 1);
|
||||||
|
|
||||||
|
uint8_t getSemaphoreCounter() const override;
|
||||||
|
static uint8_t getSemaphoreCounter(sem_t* handle);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take the binary semaphore.
|
||||||
|
* If the semaphore has already been taken, the task will be blocked
|
||||||
|
* for a maximum of #timeoutMs or until the semaphore is given back,
|
||||||
|
* for example by an ISR or another task.
|
||||||
|
* @param timeoutMs
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_TIMEOUT on timeout
|
||||||
|
*/
|
||||||
|
ReturnValue_t acquire(TimeoutType timeoutType = TimeoutType::BLOCKING,
|
||||||
|
uint32_t timeoutMs = 0) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release the binary semaphore.
|
||||||
|
* @return -@c RETURN_OK on success
|
||||||
|
* -@c SemaphoreIF::SEMAPHORE_NOT_OWNED if the semaphores is
|
||||||
|
* already available.
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t release() override;
|
||||||
|
/**
|
||||||
|
* This static function can be used to release a semaphore by providing
|
||||||
|
* its handle.
|
||||||
|
* @param handle
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static ReturnValue_t release(sem_t* handle);
|
||||||
|
|
||||||
|
/** Checks the validity of the semaphore count against a specified
|
||||||
|
* known maxCount
|
||||||
|
* @param handle
|
||||||
|
* @param maxCount
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static ReturnValue_t checkCount(sem_t* handle, uint8_t maxCount);
|
||||||
|
protected:
|
||||||
|
sem_t handle;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */
|
54
osal/linux/CountingSemaphore.cpp
Normal file
54
osal/linux/CountingSemaphore.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include "../../osal/linux/CountingSemaphore.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
CountingSemaphore::CountingSemaphore(const uint8_t maxCount, uint8_t initCount):
|
||||||
|
maxCount(maxCount), initCount(initCount) {
|
||||||
|
if(initCount > maxCount) {
|
||||||
|
sif::error << "CountingSemaphoreUsingTask: Max count bigger than "
|
||||||
|
"intial cout. Setting initial count to max count." << std::endl;
|
||||||
|
initCount = maxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
initSemaphore(initCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
CountingSemaphore::CountingSemaphore(CountingSemaphore&& other):
|
||||||
|
maxCount(other.maxCount), initCount(other.initCount) {
|
||||||
|
initSemaphore(initCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
CountingSemaphore& CountingSemaphore::operator =(
|
||||||
|
CountingSemaphore&& other) {
|
||||||
|
initSemaphore(other.initCount);
|
||||||
|
return * this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphore::release() {
|
||||||
|
ReturnValue_t result = checkCount(&handle, maxCount);
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return CountingSemaphore::release(&this->handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t CountingSemaphore::release(sem_t* handle) {
|
||||||
|
int result = sem_post(handle);
|
||||||
|
if(result == 0) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(errno) {
|
||||||
|
case(EINVAL):
|
||||||
|
// Semaphore invalid
|
||||||
|
return SemaphoreIF::SEMAPHORE_INVALID;
|
||||||
|
case(EOVERFLOW):
|
||||||
|
// SEM_MAX_VALUE overflow. This should never happen
|
||||||
|
default:
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t CountingSemaphore::getMaxCount() const {
|
||||||
|
return maxCount;
|
||||||
|
}
|
||||||
|
|
37
osal/linux/CountingSemaphore.h
Normal file
37
osal/linux/CountingSemaphore.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef FRAMEWORK_OSAL_LINUX_COUNTINGSEMAPHORE_H_
|
||||||
|
#define FRAMEWORK_OSAL_LINUX_COUNTINGSEMAPHORE_H_
|
||||||
|
#include "../../osal/linux/BinarySemaphore.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Counting semaphores, which can be acquired more than once.
|
||||||
|
* @details
|
||||||
|
* See: https://www.freertos.org/CreateCounting.html
|
||||||
|
* API of counting semaphores is almost identical to binary semaphores,
|
||||||
|
* so we just inherit from binary semaphore and provide the respective
|
||||||
|
* constructors.
|
||||||
|
*/
|
||||||
|
class CountingSemaphore: public BinarySemaphore {
|
||||||
|
public:
|
||||||
|
CountingSemaphore(const uint8_t maxCount, uint8_t initCount);
|
||||||
|
//! @brief Copy ctor, disabled
|
||||||
|
CountingSemaphore(const CountingSemaphore&) = delete;
|
||||||
|
//! @brief Copy assignment, disabled
|
||||||
|
CountingSemaphore& operator=(const CountingSemaphore&) = delete;
|
||||||
|
//! @brief Move ctor
|
||||||
|
CountingSemaphore (CountingSemaphore &&);
|
||||||
|
//! @brief Move assignment
|
||||||
|
CountingSemaphore & operator=(CountingSemaphore &&);
|
||||||
|
|
||||||
|
ReturnValue_t release() override;
|
||||||
|
static ReturnValue_t release(sem_t* sem);
|
||||||
|
/* Same API as binary semaphore otherwise. acquire() can be called
|
||||||
|
* until there are not semaphores left and release() can be called
|
||||||
|
* until maxCount is reached. */
|
||||||
|
|
||||||
|
uint8_t getMaxCount() const;
|
||||||
|
private:
|
||||||
|
const uint8_t maxCount;
|
||||||
|
uint8_t initCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_OSAL_FREERTOS_COUNTINGSEMAPHORE_H_ */
|
33
osal/linux/SemaphoreFactory.cpp
Normal file
33
osal/linux/SemaphoreFactory.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "../../tasks/SemaphoreFactory.h"
|
||||||
|
#include "BinarySemaphore.h"
|
||||||
|
#include "CountingSemaphore.h"
|
||||||
|
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
|
||||||
|
SemaphoreFactory* SemaphoreFactory::factoryInstance = nullptr;
|
||||||
|
|
||||||
|
SemaphoreFactory::SemaphoreFactory() {
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreFactory::~SemaphoreFactory() {
|
||||||
|
delete factoryInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreFactory* SemaphoreFactory::instance() {
|
||||||
|
if (factoryInstance == nullptr){
|
||||||
|
factoryInstance = new SemaphoreFactory();
|
||||||
|
}
|
||||||
|
return SemaphoreFactory::factoryInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreIF* SemaphoreFactory::createBinarySemaphore(uint32_t arguments) {
|
||||||
|
return new BinarySemaphore();
|
||||||
|
}
|
||||||
|
|
||||||
|
SemaphoreIF* SemaphoreFactory::createCountingSemaphore(const uint8_t maxCount,
|
||||||
|
uint8_t initCount, uint32_t arguments) {
|
||||||
|
return new CountingSemaphore(maxCount, initCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SemaphoreFactory::deleteSemaphore(SemaphoreIF* semaphore) {
|
||||||
|
delete semaphore;
|
||||||
|
}
|
@ -9,7 +9,7 @@ class ParameterMessage {
|
|||||||
private:
|
private:
|
||||||
ParameterMessage();
|
ParameterMessage();
|
||||||
public:
|
public:
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::PARAMETER;
|
static const uint8_t MESSAGE_ID = messagetypes::PARAMETER;
|
||||||
static const Command_t CMD_PARAMETER_LOAD = MAKE_COMMAND_ID( 0x01 );
|
static const Command_t CMD_PARAMETER_LOAD = MAKE_COMMAND_ID( 0x01 );
|
||||||
static const Command_t CMD_PARAMETER_DUMP = MAKE_COMMAND_ID( 0x02 );
|
static const Command_t CMD_PARAMETER_DUMP = MAKE_COMMAND_ID( 0x02 );
|
||||||
static const Command_t REPLY_PARAMETER_DUMP = MAKE_COMMAND_ID( 0x03 );
|
static const Command_t REPLY_PARAMETER_DUMP = MAKE_COMMAND_ID( 0x03 );
|
||||||
|
@ -1,94 +1,129 @@
|
|||||||
#include "SerialBufferAdapter.h"
|
#include "../serialize/SerialBufferAdapter.h"
|
||||||
#include <cstring>
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
template<typename count_t>
|
||||||
template<typename T>
|
SerialBufferAdapter<count_t>::SerialBufferAdapter(const uint8_t* buffer,
|
||||||
SerialBufferAdapter<T>::SerialBufferAdapter(const uint8_t* buffer,
|
count_t bufferLength, bool serializeLength) :
|
||||||
T bufferLength, bool serializeLenght) :
|
serializeLength(serializeLength),
|
||||||
serializeLength(serializeLenght), constBuffer(buffer), buffer(NULL), bufferLength(
|
constBuffer(buffer), buffer(nullptr),
|
||||||
bufferLength) {
|
bufferLength(bufferLength) {}
|
||||||
}
|
|
||||||
|
template<typename count_t>
|
||||||
template<typename T>
|
SerialBufferAdapter<count_t>::SerialBufferAdapter(uint8_t* buffer,
|
||||||
SerialBufferAdapter<T>::SerialBufferAdapter(uint8_t* buffer, T bufferLength,
|
count_t bufferLength, bool serializeLength) :
|
||||||
bool serializeLenght) :
|
serializeLength(serializeLength), constBuffer(buffer), buffer(buffer),
|
||||||
serializeLength(serializeLenght), constBuffer(NULL), buffer(buffer), bufferLength(
|
bufferLength(bufferLength) {}
|
||||||
bufferLength) {
|
|
||||||
}
|
|
||||||
|
template<typename count_t>
|
||||||
template<typename T>
|
SerialBufferAdapter<count_t>::~SerialBufferAdapter() {
|
||||||
SerialBufferAdapter<T>::~SerialBufferAdapter() {
|
}
|
||||||
}
|
|
||||||
|
template<typename count_t>
|
||||||
template<typename T>
|
ReturnValue_t SerialBufferAdapter<count_t>::serialize(uint8_t** buffer,
|
||||||
ReturnValue_t SerialBufferAdapter<T>::serialize(uint8_t** buffer, size_t* size,
|
size_t* size, size_t maxSize, Endianness streamEndianness) const {
|
||||||
size_t maxSize, Endianness streamEndianness) const {
|
if (serializeLength) {
|
||||||
uint32_t serializedLength = bufferLength;
|
ReturnValue_t result = SerializeAdapter::serialize(&bufferLength,
|
||||||
if (serializeLength) {
|
buffer, size, maxSize, streamEndianness);
|
||||||
serializedLength += SerializeAdapter::getSerializedSize(
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
&bufferLength);
|
return result;
|
||||||
}
|
}
|
||||||
if (*size + serializedLength > maxSize) {
|
}
|
||||||
return BUFFER_TOO_SHORT;
|
|
||||||
} else {
|
if (*size + bufferLength > maxSize) {
|
||||||
if (serializeLength) {
|
return BUFFER_TOO_SHORT;
|
||||||
SerializeAdapter::serialize(&bufferLength, buffer, size,
|
}
|
||||||
maxSize, streamEndianness);
|
|
||||||
}
|
if (this->constBuffer != nullptr) {
|
||||||
if (this->constBuffer != NULL) {
|
std::memcpy(*buffer, this->constBuffer, bufferLength);
|
||||||
memcpy(*buffer, this->constBuffer, bufferLength);
|
}
|
||||||
} else if (this->buffer != NULL) {
|
else if (this->buffer != nullptr) {
|
||||||
memcpy(*buffer, this->buffer, bufferLength);
|
// This will propably be never reached, constBuffer should always be
|
||||||
} else {
|
// set if non-const buffer is set.
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
std::memcpy(*buffer, this->buffer, bufferLength);
|
||||||
}
|
}
|
||||||
*size += bufferLength;
|
else {
|
||||||
(*buffer) += bufferLength;
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
}
|
||||||
}
|
*size += bufferLength;
|
||||||
}
|
(*buffer) += bufferLength;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
template<typename T>
|
|
||||||
size_t SerialBufferAdapter<T>::getSerializedSize() const {
|
}
|
||||||
if (serializeLength) {
|
|
||||||
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
|
template<typename count_t>
|
||||||
} else {
|
size_t SerialBufferAdapter<count_t>::getSerializedSize() const {
|
||||||
return bufferLength;
|
if (serializeLength) {
|
||||||
}
|
return bufferLength + SerializeAdapter::getSerializedSize(&bufferLength);
|
||||||
}
|
} else {
|
||||||
template<typename T>
|
return bufferLength;
|
||||||
ReturnValue_t SerialBufferAdapter<T>::deSerialize(const uint8_t** buffer,
|
}
|
||||||
size_t* size, Endianness streamEndianness) {
|
}
|
||||||
//TODO Ignores Endian flag!
|
|
||||||
if (buffer != NULL) {
|
template<typename count_t>
|
||||||
if(serializeLength){
|
ReturnValue_t SerialBufferAdapter<count_t>::deSerialize(const uint8_t** buffer,
|
||||||
T serializedSize = SerializeAdapter::getSerializedSize(
|
size_t* size, Endianness streamEndianness) {
|
||||||
&bufferLength);
|
if (this->buffer == nullptr) {
|
||||||
if((*size - bufferLength - serializedSize) >= 0){
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
*buffer += serializedSize;
|
}
|
||||||
*size -= serializedSize;
|
|
||||||
}else{
|
if(serializeLength){
|
||||||
return STREAM_TOO_SHORT;
|
count_t lengthField = 0;
|
||||||
}
|
ReturnValue_t result = SerializeAdapter::deSerialize(&lengthField,
|
||||||
}
|
buffer, size, streamEndianness);
|
||||||
//No Else If, go on with buffer
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
if (*size - bufferLength >= 0) {
|
return result;
|
||||||
*size -= bufferLength;
|
}
|
||||||
memcpy(this->buffer, *buffer, bufferLength);
|
if(lengthField > bufferLength) {
|
||||||
(*buffer) += bufferLength;
|
return TOO_MANY_ELEMENTS;
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
}
|
||||||
} else {
|
bufferLength = lengthField;
|
||||||
return STREAM_TOO_SHORT;
|
}
|
||||||
}
|
|
||||||
} else {
|
if (bufferLength <= *size) {
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
*size -= bufferLength;
|
||||||
}
|
std::memcpy(this->buffer, *buffer, bufferLength);
|
||||||
}
|
(*buffer) += bufferLength;
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
//forward Template declaration for linker
|
else {
|
||||||
template class SerialBufferAdapter<uint8_t>;
|
return STREAM_TOO_SHORT;
|
||||||
template class SerialBufferAdapter<uint16_t>;
|
}
|
||||||
template class SerialBufferAdapter<uint32_t>;
|
}
|
||||||
|
|
||||||
|
template<typename count_t>
|
||||||
|
uint8_t * SerialBufferAdapter<count_t>::getBuffer() {
|
||||||
|
if(buffer == nullptr) {
|
||||||
|
sif::error << "Wrong access function for stored type !"
|
||||||
|
" Use getConstBuffer()." << std::endl;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename count_t>
|
||||||
|
const uint8_t * SerialBufferAdapter<count_t>::getConstBuffer() {
|
||||||
|
if(constBuffer == nullptr) {
|
||||||
|
sif::error << "SerialBufferAdapter::getConstBuffer:"
|
||||||
|
" Buffers are unitialized!" << std::endl;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return constBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename count_t>
|
||||||
|
void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer,
|
||||||
|
count_t bufferLength) {
|
||||||
|
this->buffer = buffer;
|
||||||
|
this->constBuffer = buffer;
|
||||||
|
this->bufferLength = bufferLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//forward Template declaration for linker
|
||||||
|
template class SerialBufferAdapter<uint8_t>;
|
||||||
|
template class SerialBufferAdapter<uint16_t>;
|
||||||
|
template class SerialBufferAdapter<uint32_t>;
|
||||||
|
template class SerialBufferAdapter<uint64_t>;
|
||||||
|
|
||||||
|
@ -1,35 +1,78 @@
|
|||||||
#ifndef SERIALBUFFERADAPTER_H_
|
#ifndef SERIALBUFFERADAPTER_H_
|
||||||
#define SERIALBUFFERADAPTER_H_
|
#define SERIALBUFFERADAPTER_H_
|
||||||
|
|
||||||
#include "SerializeIF.h"
|
#include "../serialize/SerializeIF.h"
|
||||||
#include "SerializeAdapter.h"
|
#include "../serialize/SerializeAdapter.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \ingroup serialize
|
* This adapter provides an interface for SerializeIF to serialize or deserialize
|
||||||
*/
|
* buffers with no length header but a known size.
|
||||||
template<typename T>
|
*
|
||||||
class SerialBufferAdapter: public SerializeIF {
|
* Additionally, the buffer length can be serialized too and will be put in
|
||||||
public:
|
* front of the serialized buffer.
|
||||||
SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLenght = false);
|
*
|
||||||
SerialBufferAdapter(uint8_t* buffer, T bufferLength,
|
* Can be used with SerialLinkedListAdapter by declaring a SerializeElement with
|
||||||
bool serializeLenght = false);
|
* SerialElement<SerialBufferAdapter<bufferLengthType(will be uint8_t mostly)>>.
|
||||||
|
* Right now, the SerialBufferAdapter must always
|
||||||
virtual ~SerialBufferAdapter();
|
* be initialized with the buffer and size !
|
||||||
|
*
|
||||||
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
* \ingroup serialize
|
||||||
size_t maxSize, Endianness streamEndianness) const override;
|
*/
|
||||||
|
template<typename count_t>
|
||||||
virtual size_t getSerializedSize() const override;
|
class SerialBufferAdapter: public SerializeIF {
|
||||||
|
public:
|
||||||
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
||||||
Endianness streamEndianness) override;
|
/**
|
||||||
private:
|
* Constructor for constant uint8_t buffer. Length field can be serialized optionally.
|
||||||
bool serializeLength;
|
* Type of length can be supplied as template type.
|
||||||
const uint8_t *constBuffer;
|
* @param buffer
|
||||||
uint8_t *buffer;
|
* @param bufferLength
|
||||||
T bufferLength;
|
* @param serializeLength
|
||||||
};
|
*/
|
||||||
|
SerialBufferAdapter(const uint8_t* buffer, count_t bufferLength,
|
||||||
|
bool serializeLength = false);
|
||||||
|
|
||||||
#endif /* SERIALBUFFERADAPTER_H_ */
|
/**
|
||||||
|
* Constructor for non-constant uint8_t buffer.
|
||||||
|
* Length field can be serialized optionally.
|
||||||
|
* Type of length can be supplied as template type.
|
||||||
|
* @param buffer
|
||||||
|
* @param bufferLength
|
||||||
|
* @param serializeLength Length field will be serialized with size count_t
|
||||||
|
*/
|
||||||
|
SerialBufferAdapter(uint8_t* buffer, count_t bufferLength,
|
||||||
|
bool serializeLength = false);
|
||||||
|
|
||||||
|
virtual ~SerialBufferAdapter();
|
||||||
|
|
||||||
|
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
||||||
|
size_t maxSize, Endianness streamEndianness) const override;
|
||||||
|
|
||||||
|
virtual size_t getSerializedSize() const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function deserializes a buffer into the member buffer.
|
||||||
|
* @details
|
||||||
|
* If a length field is present, it is ignored, as the size should have
|
||||||
|
* been set in the constructor. If the size is not known beforehand,
|
||||||
|
* consider using SerialFixedArrayListAdapter instead.
|
||||||
|
* @param buffer [out] Resulting buffer
|
||||||
|
* @param size remaining size to deserialize, should be larger than buffer
|
||||||
|
* + size field size
|
||||||
|
* @param bigEndian
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
||||||
|
Endianness streamEndianness) override;
|
||||||
|
|
||||||
|
uint8_t * getBuffer();
|
||||||
|
const uint8_t * getConstBuffer();
|
||||||
|
void setBuffer(uint8_t* buffer, count_t bufferLength);
|
||||||
|
private:
|
||||||
|
bool serializeLength = false;
|
||||||
|
const uint8_t *constBuffer = nullptr;
|
||||||
|
uint8_t *buffer = nullptr;
|
||||||
|
count_t bufferLength = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SERIALBUFFERADAPTER_H_ */
|
||||||
|
@ -151,7 +151,6 @@ HybridIterator<ModeListEntry> Subsystem::getTable(Mode_t id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t Subsystem::handleCommandMessage(CommandMessage *message) {
|
ReturnValue_t Subsystem::handleCommandMessage(CommandMessage *message) {
|
||||||
ReturnValue_t result;
|
|
||||||
switch (message->getCommand()) {
|
switch (message->getCommand()) {
|
||||||
case HealthMessage::HEALTH_INFO: {
|
case HealthMessage::HEALTH_INFO: {
|
||||||
HealthState health = HealthMessage::getHealth(message);
|
HealthState health = HealthMessage::getHealth(message);
|
||||||
@ -166,7 +165,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage *message) {
|
|||||||
FixedArrayList<ModeListEntry, MAX_LENGTH_OF_TABLE_OR_SEQUENCE> sequence;
|
FixedArrayList<ModeListEntry, MAX_LENGTH_OF_TABLE_OR_SEQUENCE> sequence;
|
||||||
const uint8_t *pointer;
|
const uint8_t *pointer;
|
||||||
size_t sizeRead;
|
size_t sizeRead;
|
||||||
result = IPCStore->getData(
|
ReturnValue_t result = IPCStore->getData(
|
||||||
ModeSequenceMessage::getStoreAddress(message), &pointer,
|
ModeSequenceMessage::getStoreAddress(message), &pointer,
|
||||||
&sizeRead);
|
&sizeRead);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
@ -193,7 +192,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage *message) {
|
|||||||
FixedArrayList<ModeListEntry, MAX_LENGTH_OF_TABLE_OR_SEQUENCE> table;
|
FixedArrayList<ModeListEntry, MAX_LENGTH_OF_TABLE_OR_SEQUENCE> table;
|
||||||
const uint8_t *pointer;
|
const uint8_t *pointer;
|
||||||
size_t sizeRead;
|
size_t sizeRead;
|
||||||
result = IPCStore->getData(
|
ReturnValue_t result = IPCStore->getData(
|
||||||
ModeSequenceMessage::getStoreAddress(message), &pointer,
|
ModeSequenceMessage::getStoreAddress(message), &pointer,
|
||||||
&sizeRead);
|
&sizeRead);
|
||||||
if (result == RETURN_OK) {
|
if (result == RETURN_OK) {
|
||||||
@ -210,21 +209,23 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage *message) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ModeSequenceMessage::DELETE_SEQUENCE:
|
case ModeSequenceMessage::DELETE_SEQUENCE:{
|
||||||
if (isInTransition) {
|
if (isInTransition) {
|
||||||
replyToCommand(IN_TRANSITION, 0);
|
replyToCommand(IN_TRANSITION, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = deleteSequence(ModeSequenceMessage::getSequenceId(message));
|
ReturnValue_t result = deleteSequence(ModeSequenceMessage::getSequenceId(message));
|
||||||
replyToCommand(result, 0);
|
replyToCommand(result, 0);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ModeSequenceMessage::DELETE_TABLE:
|
case ModeSequenceMessage::DELETE_TABLE:{
|
||||||
if (isInTransition) {
|
if (isInTransition) {
|
||||||
replyToCommand(IN_TRANSITION, 0);
|
replyToCommand(IN_TRANSITION, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result = deleteTable(ModeSequenceMessage::getTableId(message));
|
ReturnValue_t result = deleteTable(ModeSequenceMessage::getTableId(message));
|
||||||
replyToCommand(result, 0);
|
replyToCommand(result, 0);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ModeSequenceMessage::LIST_SEQUENCES: {
|
case ModeSequenceMessage::LIST_SEQUENCES: {
|
||||||
SerialFixedArrayListAdapter<Mode_t, MAX_NUMBER_OF_TABLES_OR_SEQUENCES> sequences;
|
SerialFixedArrayListAdapter<Mode_t, MAX_NUMBER_OF_TABLES_OR_SEQUENCES> sequences;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
class ModeSequenceMessage {
|
class ModeSequenceMessage {
|
||||||
public:
|
public:
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::MODE_SEQUENCE;
|
static const uint8_t MESSAGE_ID = messagetypes::MODE_SEQUENCE;
|
||||||
|
|
||||||
static const Command_t ADD_SEQUENCE = MAKE_COMMAND_ID(0x01);
|
static const Command_t ADD_SEQUENCE = MAKE_COMMAND_ID(0x01);
|
||||||
static const Command_t ADD_TABLE = MAKE_COMMAND_ID(0x02);
|
static const Command_t ADD_TABLE = MAKE_COMMAND_ID(0x02);
|
||||||
|
50
tasks/SemaphoreFactory.h
Normal file
50
tasks/SemaphoreFactory.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#ifndef FSFW_TASKS_SEMAPHOREFACTORY_H_
|
||||||
|
#define FSFW_TASKS_SEMAPHOREFACTORY_H_
|
||||||
|
|
||||||
|
#include "../tasks/SemaphoreIF.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates Semaphore.
|
||||||
|
* This class is a "singleton" interface, i.e. it provides an
|
||||||
|
* interface, but also is the base class for a singleton.
|
||||||
|
*/
|
||||||
|
class SemaphoreFactory {
|
||||||
|
public:
|
||||||
|
virtual ~SemaphoreFactory();
|
||||||
|
/**
|
||||||
|
* Returns the single instance of SemaphoreFactory.
|
||||||
|
* The implementation of #instance is found in its subclasses.
|
||||||
|
* Thus, we choose link-time variability of the instance.
|
||||||
|
*/
|
||||||
|
static SemaphoreFactory* instance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a binary semaphore.
|
||||||
|
* Creator function for a binary semaphore which may only be acquired once
|
||||||
|
* @param argument Can be used to pass implementation specific information.
|
||||||
|
* @return Pointer to newly created semaphore class instance.
|
||||||
|
*/
|
||||||
|
SemaphoreIF* createBinarySemaphore(uint32_t arguments = 0);
|
||||||
|
/**
|
||||||
|
* Create a counting semaphore.
|
||||||
|
* Creator functons for a counting semaphore which may be acquired multiple
|
||||||
|
* times.
|
||||||
|
* @param count Semaphore can be taken count times.
|
||||||
|
* @param initCount Initial count value.
|
||||||
|
* @param argument Can be used to pass implementation specific information.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SemaphoreIF* createCountingSemaphore(const uint8_t maxCount,
|
||||||
|
uint8_t initCount, uint32_t arguments = 0);
|
||||||
|
|
||||||
|
void deleteSemaphore(SemaphoreIF* semaphore);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* External instantiation is not allowed.
|
||||||
|
*/
|
||||||
|
SemaphoreFactory();
|
||||||
|
static SemaphoreFactory* factoryInstance;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FSFW_TASKS_SEMAPHOREFACTORY_H_ */
|
68
tasks/SemaphoreIF.h
Normal file
68
tasks/SemaphoreIF.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#ifndef FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||||
|
#define FRAMEWORK_TASKS_SEMAPHOREIF_H_
|
||||||
|
#include "../returnvalues/FwClassIds.h"
|
||||||
|
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generic interface for semaphores, which can be used to achieve
|
||||||
|
* task synchronization. This is a generic interface which can be
|
||||||
|
* used for both binary semaphores and counting semaphores.
|
||||||
|
* @details
|
||||||
|
* A semaphore is a synchronization primitive.
|
||||||
|
* See: https://en.wikipedia.org/wiki/Semaphore_(programming)
|
||||||
|
* A semaphore can be used to achieve task synchonization and track the
|
||||||
|
* availability of resources by using either the binary or the counting
|
||||||
|
* semaphore types.
|
||||||
|
*
|
||||||
|
* If mutual exlcusion of a resource is desired, a mutex should be used,
|
||||||
|
* which is a special form of a semaphore and has an own interface.
|
||||||
|
*/
|
||||||
|
class SemaphoreIF {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Different types of timeout for the mutex lock.
|
||||||
|
*/
|
||||||
|
enum TimeoutType {
|
||||||
|
POLLING, //!< If mutex is not available, return immediately
|
||||||
|
WAITING, //!< Wait a specified time for the mutex to become available
|
||||||
|
BLOCKING //!< Block indefinitely until the mutex becomes available.
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual~ SemaphoreIF() {};
|
||||||
|
|
||||||
|
static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF;
|
||||||
|
//! 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_INVALID = MAKE_RETURN_CODE(3);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic call to acquire a semaphore.
|
||||||
|
* If there are no more semaphores to be taken (for a counting semaphore,
|
||||||
|
* a semaphore may be taken more than once), the taks will block
|
||||||
|
* for a maximum of timeoutMs while trying to acquire the semaphore.
|
||||||
|
* This can be used to achieve task synchrnization.
|
||||||
|
* @param timeoutMs
|
||||||
|
* @return - c RETURN_OK for successfull acquisition
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t acquire(TimeoutType timeoutType =
|
||||||
|
TimeoutType::BLOCKING, uint32_t timeoutMs = 0) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Corrensponding call to release a semaphore.
|
||||||
|
* @return -@c RETURN_OK for successfull release
|
||||||
|
*/
|
||||||
|
virtual ReturnValue_t release() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the semaphore is a counting semaphore then the semaphores current
|
||||||
|
* count value is returned. If the semaphore is a binary semaphore then 1
|
||||||
|
* is returned if the semaphore is available, and 0 is returned if the
|
||||||
|
* semaphore is not available.
|
||||||
|
*/
|
||||||
|
virtual uint8_t getSemaphoreCounter() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* FRAMEWORK_TASKS_SEMAPHOREIF_H_ */
|
@ -1,7 +1,6 @@
|
|||||||
#ifndef FRAMEWORK_TASKS_TYPEDEF_H_
|
#ifndef FRAMEWORK_TASKS_TYPEDEF_H_
|
||||||
#define FRAMEWORK_TASKS_TYPEDEF_H_
|
#define FRAMEWORK_TASKS_TYPEDEF_H_
|
||||||
|
|
||||||
//TODO more generic?
|
|
||||||
typedef const char* TaskName;
|
typedef const char* TaskName;
|
||||||
typedef uint8_t TaskPriority;
|
typedef uint8_t TaskPriority;
|
||||||
typedef size_t TaskStackSize;
|
typedef size_t TaskStackSize;
|
||||||
|
@ -119,7 +119,7 @@ ReturnValue_t CCSDSTime::convertFromCCS(Clock::TimeOfDay_t* to, const uint8_t* f
|
|||||||
|
|
||||||
if (temp->pField & (1 << 3)) { //day of year variation
|
if (temp->pField & (1 << 3)) { //day of year variation
|
||||||
uint16_t tempDay = (temp->month << 8) + temp->day;
|
uint16_t tempDay = (temp->month << 8) + temp->day;
|
||||||
ReturnValue_t result = convertDaysOfYear(tempDay, to->year,
|
result = convertDaysOfYear(tempDay, to->year,
|
||||||
&(temp->month), &(temp->day));
|
&(temp->month), &(temp->day));
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
static store_address_t getStoreId(const CommandMessage* cmd);
|
static store_address_t getStoreId(const CommandMessage* cmd);
|
||||||
virtual ~TmStoreMessage();
|
virtual ~TmStoreMessage();
|
||||||
static const uint8_t MESSAGE_ID = MESSAGE_TYPE::TM_STORE;
|
static const uint8_t MESSAGE_ID = messagetypes::TM_STORE;
|
||||||
static const Command_t ENABLE_STORING = MAKE_COMMAND_ID(1);
|
static const Command_t ENABLE_STORING = MAKE_COMMAND_ID(1);
|
||||||
static const Command_t DELETE_STORE_CONTENT = MAKE_COMMAND_ID(2);
|
static const Command_t DELETE_STORE_CONTENT = MAKE_COMMAND_ID(2);
|
||||||
static const Command_t DOWNLINK_STORE_CONTENT = MAKE_COMMAND_ID(3);
|
static const Command_t DOWNLINK_STORE_CONTENT = MAKE_COMMAND_ID(3);
|
||||||
|
Loading…
Reference in New Issue
Block a user