From a65a1840838435f8ce3cfed8bc7a2adf74eac2ac Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 16 Jul 2021 12:22:14 +0200 Subject: [PATCH] not an ideal solution but works for now --- hal/inc/fsfw/hal/linux/spi/SpiComIF.h | 6 +++--- hal/inc/fsfw/hal/stm32h7/spi/SpiComIF.h | 2 +- hal/src/stm32h7/devicetest/GyroL3GD20H.cpp | 1 - hal/src/stm32h7/spi/SpiComIF.cpp | 17 ++++++++++++++- inc/fsfw/osal/freertos/BinarySemaphore.h | 2 +- inc/fsfw/osal/rtems/BinarySemaphore.h | 21 +++++++++++++++++++ inc/fsfw/osal/rtems/MessageQueue.h | 6 +++--- src/osal/rtems/BinarySemaphore.cpp | 24 ++++++++++++++++++++++ src/osal/rtems/CMakeLists.txt | 1 + 9 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 inc/fsfw/osal/rtems/BinarySemaphore.h create mode 100644 src/osal/rtems/BinarySemaphore.cpp diff --git a/hal/inc/fsfw/hal/linux/spi/SpiComIF.h b/hal/inc/fsfw/hal/linux/spi/SpiComIF.h index 676c7cba..7f66b8e5 100644 --- a/hal/inc/fsfw/hal/linux/spi/SpiComIF.h +++ b/hal/inc/fsfw/hal/linux/spi/SpiComIF.h @@ -3,10 +3,10 @@ #include "spiDefinitions.h" #include "returnvalues/classIds.h" -#include "../../common/gpio/GpioIF.h" +#include "fsfw/hal/common/gpio/GpioIF.h" -#include -#include +#include "fsfw/devicehandlers/DeviceCommunicationIF.h" +#include "fsfw/objectmanager/SystemObject.h" #include #include diff --git a/hal/inc/fsfw/hal/stm32h7/spi/SpiComIF.h b/hal/inc/fsfw/hal/stm32h7/spi/SpiComIF.h index c2554544..00625b34 100644 --- a/hal/inc/fsfw/hal/stm32h7/spi/SpiComIF.h +++ b/hal/inc/fsfw/hal/stm32h7/spi/SpiComIF.h @@ -5,7 +5,6 @@ #include "fsfw/devicehandlers/DeviceCommunicationIF.h" #include "fsfw/objectmanager/SystemObject.h" -#include "fsfw/osal/freertos/BinarySemaphore.h" #include "fsfw/hal/stm32h7/spi/spiDefinitions.h" #include "stm32h7xx_hal_spi.h" #include "stm32h743xx.h" @@ -14,6 +13,7 @@ #include class SpiCookie; +class BinarySemaphore; /** * @brief This communication interface allows using generic device handlers with using diff --git a/hal/src/stm32h7/devicetest/GyroL3GD20H.cpp b/hal/src/stm32h7/devicetest/GyroL3GD20H.cpp index 6765f540..04b1de3b 100644 --- a/hal/src/stm32h7/devicetest/GyroL3GD20H.cpp +++ b/hal/src/stm32h7/devicetest/GyroL3GD20H.cpp @@ -9,7 +9,6 @@ #include "fsfw/tasks/TaskFactory.h" #include "fsfw/serviceinterface/ServiceInterface.h" -#include "stm32h7xx_nucleo.h" #include "stm32h7xx_hal_spi.h" #include "stm32h7xx_hal_rcc.h" diff --git a/hal/src/stm32h7/spi/SpiComIF.cpp b/hal/src/stm32h7/spi/SpiComIF.cpp index d1484de0..da34c4c0 100644 --- a/hal/src/stm32h7/spi/SpiComIF.cpp +++ b/hal/src/stm32h7/spi/SpiComIF.cpp @@ -2,12 +2,21 @@ #include "fsfw/hal/stm32h7/spi/SpiCookie.h" #include "fsfw/tasks/SemaphoreFactory.h" -#include "fsfw/osal/freertos/TaskManagement.h" #include "fsfw/hal/stm32h7/spi/spiCore.h" #include "fsfw/hal/stm32h7/spi/spiInterrupts.h" #include "fsfw/hal/stm32h7/spi/mspInit.h" #include "fsfw/hal/stm32h7/gpio/gpio.h" +// FreeRTOS required special Semaphore handling from an ISR. Therefore, we use the concrete +// instance here, because RTEMS and FreeRTOS are the only relevant OSALs currently +// and it is not trivial to add a releaseFromISR to the SemaphoreIF +#if defined FSFW_OSAL_RTEMS +#include "fsfw/osal/rtems/BinarySemaphore.h" +#elif defined FSFW_OSAL_FREERTOS +#include "fsfw/osal/freertos/TaskManagement.h" +#include "fsfw/osal/freertos/BinarySemaphore.h" +#endif + #include "stm32h7xx_hal_gpio.h" SpiComIF::SpiComIF(object_id_t objectId): SystemObject(objectId) { @@ -421,10 +430,14 @@ void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetSt HAL_GPIO_WritePin(spiCookie->getChipSelectGpioPort(), spiCookie->getChipSelectGpioPin(), GPIO_PIN_SET); +#if defined FSFW_OSAL_FREERTOS // Release the task semaphore BaseType_t taskWoken = pdFALSE; ReturnValue_t result = BinarySemaphore::releaseFromISR(comIF->spiSemaphore->getSemaphore(), &taskWoken); +#elif defined FSFW_OSAL_RTEMS + ReturnValue_t result = comIF->spiSemaphore->release(); +#endif if(result != HasReturnvaluesIF::RETURN_OK) { // Configuration error printf("SpiComIF::genericIrqHandler: Failure releasing Semaphore!\n"); @@ -436,11 +449,13 @@ void SpiComIF::genericIrqHandler(void *irqArgsVoid, spi::TransferStates targetSt SCB_InvalidateDCache_by_Addr ((uint32_t *) comIF->currentRecvPtr, comIF->currentRecvBuffSize); } +#if defined FSFW_OSAL_FREERTOS /* Request a context switch if the SPI ComIF task was woken up and has a higher priority than the currently running task */ if(taskWoken == pdTRUE) { TaskManagement::requestContextSwitch(CallContext::ISR); } +#endif } void SpiComIF::printCfgError(const char *const type) { diff --git a/inc/fsfw/osal/freertos/BinarySemaphore.h b/inc/fsfw/osal/freertos/BinarySemaphore.h index 1ae56ff6..6e70bf70 100644 --- a/inc/fsfw/osal/freertos/BinarySemaphore.h +++ b/inc/fsfw/osal/freertos/BinarySemaphore.h @@ -98,7 +98,7 @@ public: * already available. */ static ReturnValue_t releaseFromISR(SemaphoreHandle_t semaphore, - BaseType_t * higherPriorityTaskWoken); + BaseType_t * higherPriorityTaskWoken) override; protected: SemaphoreHandle_t handle; diff --git a/inc/fsfw/osal/rtems/BinarySemaphore.h b/inc/fsfw/osal/rtems/BinarySemaphore.h new file mode 100644 index 00000000..3b3a5aba --- /dev/null +++ b/inc/fsfw/osal/rtems/BinarySemaphore.h @@ -0,0 +1,21 @@ +#ifndef FSFW_INC_FSFW_OSAL_RTEMS_BINARYSEMAPHORE_H_ +#define FSFW_INC_FSFW_OSAL_RTEMS_BINARYSEMAPHORE_H_ + +#include "fsfw/tasks/SemaphoreIF.h" + +class BinarySemaphore: public SemaphoreIF { +public: + BinarySemaphore(); + virtual ~BinarySemaphore(); + + // Interface implementation + ReturnValue_t acquire(TimeoutType timeoutType = + TimeoutType::BLOCKING, uint32_t timeoutMs = 0) override; + ReturnValue_t release() override; + uint8_t getSemaphoreCounter() const override; +private: +}; + + + +#endif /* FSFW_INC_FSFW_OSAL_RTEMS_BINARYSEMAPHORE_H_ */ diff --git a/inc/fsfw/osal/rtems/MessageQueue.h b/inc/fsfw/osal/rtems/MessageQueue.h index 342f1e30..fa143ebe 100644 --- a/inc/fsfw/osal/rtems/MessageQueue.h +++ b/inc/fsfw/osal/rtems/MessageQueue.h @@ -1,9 +1,9 @@ #ifndef FSFW_OSAL_RTEMS_MESSAGEQUEUE_H_ #define FSFW_OSAL_RTEMS_MESSAGEQUEUE_H_ -#include "../../internalError/InternalErrorReporterIF.h" -#include "../../ipc/MessageQueueIF.h" -#include "../../ipc/MessageQueueMessage.h" +#include "fsfw/internalerror/InternalErrorReporterIF.h" +#include "fsfw/ipc/MessageQueueIF.h" +#include "fsfw/ipc/MessageQueueMessage.h" #include "RtemsBasic.h" /** diff --git a/src/osal/rtems/BinarySemaphore.cpp b/src/osal/rtems/BinarySemaphore.cpp new file mode 100644 index 00000000..f9db1009 --- /dev/null +++ b/src/osal/rtems/BinarySemaphore.cpp @@ -0,0 +1,24 @@ +#include "fsfw/osal/rtems/BinarySemaphore.h" + +#include + +BinarySemaphore::BinarySemaphore() { +} + +BinarySemaphore::~BinarySemaphore() { + +} + +// Interface implementation +ReturnValue_t BinarySemaphore::acquire(TimeoutType timeoutType, uint32_t timeoutMs) { + return HasReturnvaluesIF::RETURN_OK; +} + + +ReturnValue_t BinarySemaphore::release() { + return HasReturnvaluesIF::RETURN_OK; +} + +uint8_t BinarySemaphore::getSemaphoreCounter() const { + return 0; +} diff --git a/src/osal/rtems/CMakeLists.txt b/src/osal/rtems/CMakeLists.txt index cd266125..ac728b2f 100644 --- a/src/osal/rtems/CMakeLists.txt +++ b/src/osal/rtems/CMakeLists.txt @@ -13,6 +13,7 @@ target_sources(${LIB_FSFW_NAME} RtemsBasic.cpp RTEMSTaskBase.cpp TaskFactory.cpp + BinarySemaphore.cpp )