diff --git a/devicehandlers/CommunicationMessage.cpp b/devicehandlers/CommunicationMessage.cpp new file mode 100644 index 00000000..6dddc5be --- /dev/null +++ b/devicehandlers/CommunicationMessage.cpp @@ -0,0 +1,9 @@ +/** + * @file CommunicationMessage.cpp + * + * @date 28.02.2020 + */ + + + + diff --git a/devicehandlers/CommunicationMessage.h b/devicehandlers/CommunicationMessage.h new file mode 100644 index 00000000..70c1052a --- /dev/null +++ b/devicehandlers/CommunicationMessage.h @@ -0,0 +1,82 @@ +/** + * @file CommunicationMessage.h + * + * @date 28.02.2020 + */ + +#ifndef FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ +#define FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ +#include +#include + +/** + * @brief Used to pass communication information between tasks + * + * @details + * Can be used to pass information like data pointers and + * data sizes between communication tasks + * like the Device Handler Comm Interfaces and Polling Tasks. + * + * Can also be used to exchange actual data if its not too large + * (e.g. Sensor values). + * + */ +class CommunicationMessage: public MessageQueueMessage { +public: + enum communicationStatus { + SEND_DATA, + PROCESS_DATA, + FAULTY, + }; + + //Add other messageIDs here if necessary. + static const uint8_t COMMUNICATION_MESSAGE_SIZE = HEADER_SIZE + 4 * sizeof(uint32_t); + + CommunicationMessage(); + + /** + * Send requests with pointer to the data to be sent and send data length + * @param address Target Address + * @param sendData + * @param length + */ + void setSendRequest(uint32_t address, const uint8_t * sendData, uint32_t length); + + /** + * Data message with data stored in IPC store + * @param address + * @param length + * @param storeId + */ + void setDataMessage(uint32_t address, uint32_t length, store_address_t * storeId); + + /** + * Data message with data stored in actual message. + * 4 byte datafield is intialized with 0. + * Set data with specific setter functions. + */ + void setDataMessage(uint32_t address, uint32_t length); + +private: + void setCommunicationStatus(communicationStatus status); + void setAddress(uint32_t address); + void setSendData(const uint8_t * sendData); + void setDataLen(uint32_t length); + + /** For low size data, maximum of 4 bytes can be sent */ + void setDataByte1(uint8_t byte1); + void setDataByte2(uint8_t byte2); + void setDataByte3(uint8_t byte3); + void setDataByte4(uint8_t byte4); + + void setDataUINT16_1(uint16_t data1); + void setDataUINT16_2(uint16_t data2); + + void setData(uint32_t data); + + virtual ~CommunicationMessage(); +}; + + + +#endif /* FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ */ diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index 09e71f6d..c3d57387 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -88,7 +88,7 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t sema if (returncode == pdPASS) { if(*higherPriorityTaskWoken == pdPASS) { // Request context switch - TaskManagement::requestContextSwitch(SystemContext::isr_context); + TaskManagement::requestContextSwitch(CallContext::isr); } return HasReturnvaluesIF::RETURN_OK; } else { diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index f23d9d9d..cc38e77d 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -6,7 +6,7 @@ // As a first step towards this, introduces system context variable which needs to be switched manually // Haven't found function to find system context. MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) : -defaultDestination(0),lastPartner(0), callContext(SystemContext::task_context) { +defaultDestination(0),lastPartner(0), callContext(CallContext::task) { handle = xQueueCreate(message_depth, max_message_size); if (handle == NULL) { error << "MessageQueue creation failed" << std::endl; @@ -19,7 +19,7 @@ MessageQueue::~MessageQueue() { } } -void MessageQueue::switchSystemContext(SystemContext callContext) { +void MessageQueue::switchSystemContext(CallContext callContext) { this->callContext = callContext; } @@ -53,10 +53,10 @@ ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, MessageQueueMessage *message, MessageQueueId_t sentFrom, - bool ignoreFault, SystemContext callContext) { + bool ignoreFault, CallContext callContext) { message->setSender(sentFrom); BaseType_t result; - if(callContext == SystemContext::task_context) { + if(callContext == CallContext::task) { result = xQueueSendToBack(reinterpret_cast(sendTo), reinterpret_cast(message->getBuffer()), 0); } diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index d8e14961..8edfed10 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -58,7 +58,7 @@ public: */ virtual ~MessageQueue(); - void switchSystemContext(SystemContext callContext); + void switchSystemContext(CallContext callContext); /** * @brief This operation sends a message to the given destination. @@ -168,7 +168,7 @@ protected: */ static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, - bool ignoreFault=false, SystemContext callContex = SystemContext::task_context); + bool ignoreFault=false, CallContext callContex = CallContext::task); static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); @@ -177,7 +177,7 @@ private: QueueHandle_t handle; MessageQueueId_t defaultDestination; MessageQueueId_t lastPartner; - SystemContext callContext; //!< Stores the current system context + CallContext callContext; //!< Stores the current system context }; #endif /* MESSAGEQUEUE_H_ */ diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp index 573a7d7d..40a0f395 100644 --- a/osal/FreeRTOS/TaskManagement.cpp +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -13,8 +13,8 @@ void TaskManagement::requestContextSwitchFromTask() { vTaskDelay(0); } -void TaskManagement::requestContextSwitch(SystemContext callContext = SystemContext::task_context) { - if(callContext == SystemContext::isr_context) { +void TaskManagement::requestContextSwitch(CallContext callContext = CallContext::task) { + if(callContext == CallContext::isr) { // This function depends on the partmacro.h definition for the specific device portYIELD_FROM_ISR(); } else { diff --git a/osal/FreeRTOS/TaskManagement.h b/osal/FreeRTOS/TaskManagement.h index 381e06f9..fd2bfc0b 100644 --- a/osal/FreeRTOS/TaskManagement.h +++ b/osal/FreeRTOS/TaskManagement.h @@ -12,9 +12,10 @@ * 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 SystemContext { - task_context = 0x00,//!< task_context - isr_context = 0xFF //!< isr_context + +enum CallContext { + task = 0x00,//!< task_context + isr = 0xFF //!< isr_context }; class TaskManagement { @@ -25,7 +26,7 @@ public: * 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(SystemContext callContext); + static void requestContextSwitch(CallContext callContext); /** * If task preemption in FreeRTOS is disabled, a context switch