From cb121b9faf9f96818739e14bf79b48470c9f3290 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 4 Jun 2021 16:34:38 +0200 Subject: [PATCH] converted files to cpp continued stubs --- stm32h7/CMakeLists.txt | 1 - stm32h7/dma_interrupts.h | 4 +- stm32h7/interrupts.c | 2 - stm32h7/spi/CMakeLists.txt | 6 +- stm32h7/spi/SpiComIF.cpp | 3 +- stm32h7/spi/SpiComIF.h | 9 ++- stm32h7/spi/SpiCookie.cpp | 7 +- stm32h7/spi/SpiCookie.h | 14 +++- stm32h7/spi/{mspInit.c => mspInit.cpp} | 10 +-- stm32h7/spi/{spiCore.c => spiCore.cpp} | 20 +++--- stm32h7/spi/spiCore.h | 2 +- stm32h7/spi/spiDefinitions.h | 5 ++ .../spi/{interrupts.c => spiInterrupts.cpp} | 71 ++++++++++--------- stm32h7/spi/{interrupts.h => spiInterrupts.h} | 9 +-- 14 files changed, 93 insertions(+), 70 deletions(-) delete mode 100644 stm32h7/interrupts.c rename stm32h7/spi/{mspInit.c => mspInit.cpp} (95%) rename stm32h7/spi/{spiCore.c => spiCore.cpp} (84%) rename stm32h7/spi/{interrupts.c => spiInterrupts.cpp} (75%) rename stm32h7/spi/{interrupts.h => spiInterrupts.h} (84%) diff --git a/stm32h7/CMakeLists.txt b/stm32h7/CMakeLists.txt index ed74b99..58b50fe 100644 --- a/stm32h7/CMakeLists.txt +++ b/stm32h7/CMakeLists.txt @@ -2,6 +2,5 @@ add_subdirectory(spi) add_subdirectory(devicetest) target_sources(${TARGET_NAME} PRIVATE - interrupts.c dma_interrupts.c ) diff --git a/stm32h7/dma_interrupts.h b/stm32h7/dma_interrupts.h index b28310f..b24c235 100644 --- a/stm32h7/dma_interrupts.h +++ b/stm32h7/dma_interrupts.h @@ -1,12 +1,12 @@ #ifndef FSFW_HAL_STM32H7_DMA_INTERRUPTS_H_ #define FSFW_HAL_STM32H7_DMA_INTERRUPTS_H_ -#include "interrupts.h" - #ifdef __cplusplus extern "C" { #endif +#include "interrupts.h" + typedef enum { DMA_1 = 0, DMA_2 = 1 diff --git a/stm32h7/interrupts.c b/stm32h7/interrupts.c deleted file mode 100644 index 4987edd..0000000 --- a/stm32h7/interrupts.c +++ /dev/null @@ -1,2 +0,0 @@ -#include "interrupts.h" -#include diff --git a/stm32h7/spi/CMakeLists.txt b/stm32h7/spi/CMakeLists.txt index 1e8feb5..c566f53 100644 --- a/stm32h7/spi/CMakeLists.txt +++ b/stm32h7/spi/CMakeLists.txt @@ -1,8 +1,8 @@ target_sources(${TARGET_NAME} PRIVATE - spiCore.c + spiCore.cpp spiDefinitions.cpp - interrupts.c - mspInit.c + spiInterrupts.cpp + mspInit.cpp SpiCookie.cpp SpiComIF.cpp ) diff --git a/stm32h7/spi/SpiComIF.cpp b/stm32h7/spi/SpiComIF.cpp index c3e6021..913c647 100644 --- a/stm32h7/spi/SpiComIF.cpp +++ b/stm32h7/spi/SpiComIF.cpp @@ -1,6 +1,7 @@ #include "SpiComIF.h" -SpiComIF::SpiComIF(object_id_t objectId): SystemObject(objectId) { +SpiComIF::SpiComIF(object_id_t objectId, SPI_TypeDef* spiInstance, + spi::TransferModes transferMode): SystemObject(objectId) { } ReturnValue_t SpiComIF::initializeInterface(CookieIF *cookie) { diff --git a/stm32h7/spi/SpiComIF.h b/stm32h7/spi/SpiComIF.h index 9205b61..bd79e0c 100644 --- a/stm32h7/spi/SpiComIF.h +++ b/stm32h7/spi/SpiComIF.h @@ -1,14 +1,19 @@ #ifndef FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ #define FSFW_HAL_STM32H7_SPI_SPICOMIF_H_ + #include "fsfw/devicehandlers/DeviceCommunicationIF.h" #include "fsfw/objectmanager/SystemObject.h" +#include "fsfw_hal/stm32h7/spi/spiDefinitions.h" +#include "stm32h7xx_hal_spi.h" +#include "stm32h743xx.h" + class SpiComIF: public SystemObject, public DeviceCommunicationIF { public: - SpiComIF(object_id_t objectId); + SpiComIF(object_id_t objectId, SPI_TypeDef* spiInstance, spi::TransferModes transferMode); protected: // DeviceCommunicationIF overrides @@ -21,7 +26,7 @@ protected: virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override; private: - + SPI_HandleTypeDef spiHandle; }; diff --git a/stm32h7/spi/SpiCookie.cpp b/stm32h7/spi/SpiCookie.cpp index d7824fd..97e5bee 100644 --- a/stm32h7/spi/SpiCookie.cpp +++ b/stm32h7/spi/SpiCookie.cpp @@ -1,4 +1,9 @@ #include "SpiCookie.h" -SpiCookie::SpiCookie() { + + +SpiCookie::SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, uint32_t spiSpeed, + spi::SpiModes spiMode, uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort): + deviceAddress(deviceAddress), spiIdx(spiIdx), spiSpeed(spiSpeed), spiMode(spiMode), + chipSelectGpioPin(chipSelectGpioPin), chipSelectGpioPort(chipSelectGpioPort) { } diff --git a/stm32h7/spi/SpiCookie.h b/stm32h7/spi/SpiCookie.h index 7a12d91..1bee9ba 100644 --- a/stm32h7/spi/SpiCookie.h +++ b/stm32h7/spi/SpiCookie.h @@ -1,13 +1,23 @@ #ifndef FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ #define FSFW_HAL_STM32H7_SPI_SPICOOKIE_H_ +#include "spiDefinitions.h" + #include "fsfw/devicehandlers/CookieIF.h" +#include "stm32h743xx.h" + class SpiCookie: public CookieIF { public: - SpiCookie(); + SpiCookie(address_t deviceAddress, spi::SpiBus spiIdx, uint32_t spiSpeed, spi::SpiModes spiMode, + uint16_t chipSelectGpioPin, GPIO_TypeDef* chipSelectGpioPort); private: - + address_t deviceAddress; + spi::SpiBus spiIdx; + uint32_t spiSpeed; + spi::SpiModes spiMode; + uint16_t chipSelectGpioPin; + GPIO_TypeDef* chipSelectGpioPort; }; diff --git a/stm32h7/spi/mspInit.c b/stm32h7/spi/mspInit.cpp similarity index 95% rename from stm32h7/spi/mspInit.c rename to stm32h7/spi/mspInit.cpp index 9025780..05f9522 100644 --- a/stm32h7/spi/mspInit.c +++ b/stm32h7/spi/mspInit.cpp @@ -1,8 +1,8 @@ #include "mspInit.h" #include "spiConf.h" #include "spiCore.h" +#include "spiInterrupts.h" #include "../dma_interrupts.h" -#include "interrupts.h" #include "stm32h743xx.h" #include "stm32h7xx_hal_spi.h" @@ -90,20 +90,20 @@ void hal_spi_msp_init_dma(void *spi_handle) { /*##-4- Configure the NVIC for DMA #########################################*/ /* NVIC configuration for DMA transfer complete interrupt (SPI1_RX) */ // Assign the interrupt handler - assign_dma_user_handler(DMA_2, 2, &dma_rx_irq_handler, hdma_rx); + assign_dma_user_handler(DMA_2, DMAStreams::STREAM_2, &dma_rx_irq_handler, hdma_rx); HAL_NVIC_SetPriority(SPIx_DMA_RX_IRQn, 1, 0); HAL_NVIC_EnableIRQ(SPIx_DMA_RX_IRQn); /* NVIC configuration for DMA transfer complete interrupt (SPI1_TX) */ // Assign the interrupt handler - assign_dma_user_handler(DMA_2, 3, &dma_tx_irq_handler, hdma_tx); + assign_dma_user_handler(DMA_2, DMAStreams::STREAM_3, &dma_tx_irq_handler, hdma_tx); HAL_NVIC_SetPriority(SPIx_DMA_TX_IRQn, 1, 1); HAL_NVIC_EnableIRQ(SPIx_DMA_TX_IRQn); /*##-5- Configure the NVIC for SPI #########################################*/ /* NVIC configuration for SPI transfer complete interrupt (SPI1) */ // Assign the interrupt handler - assign_spi_user_handler(SPI_1, &spi1_irq_handler, hspi); + assign_spi_user_handler(spi::SPI_1, &spi1_irq_handler, hspi); HAL_NVIC_SetPriority(SPIx_IRQn, 1, 0); HAL_NVIC_EnableIRQ(SPIx_IRQn); } @@ -195,7 +195,7 @@ void hal_spi_msp_deinit_polling(void *hspi) { void hal_spi_msp_init_interrupt(void *hspi) { hal_spi_msp_init_polling(hspi); // Configure the NVIC for SPI - assign_spi_user_handler(SPI_1, &spi1_irq_handler, hspi); + assign_spi_user_handler(spi::SPI_1, &spi1_irq_handler, hspi); HAL_NVIC_SetPriority(SPIx_IRQn, 1, 0); HAL_NVIC_EnableIRQ(SPIx_IRQn); } diff --git a/stm32h7/spi/spiCore.c b/stm32h7/spi/spiCore.cpp similarity index 84% rename from stm32h7/spi/spiCore.c rename to stm32h7/spi/spiCore.cpp index f0152d2..ad57f5d 100644 --- a/stm32h7/spi/spiCore.c +++ b/stm32h7/spi/spiCore.cpp @@ -1,15 +1,15 @@ #include "spiCore.h" -#include +#include -SPI_HandleTypeDef* spiHandle = NULL; -DMA_HandleTypeDef* hdma_tx = NULL; -DMA_HandleTypeDef* hdma_rx = NULL; +SPI_HandleTypeDef* spiHandle = nullptr; +DMA_HandleTypeDef* hdma_tx = nullptr; +DMA_HandleTypeDef* hdma_rx = nullptr; -msp_func_t msp_init_func = NULL; -void* msp_init_args = NULL; +msp_func_t msp_init_func = nullptr; +void* msp_init_args = nullptr; -msp_func_t msp_deinit_func = NULL; -void* msp_deinit_args = NULL; +msp_func_t msp_deinit_func = nullptr; +void* msp_deinit_args = nullptr; void set_dma_handles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle) { hdma_tx = txHandle; @@ -64,7 +64,7 @@ void get_msp_deinit_function(msp_func_t* deinit_func, void **args) { * @param hspi: SPI handle pointer * @retval None */ -void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) { +extern "C" void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) { if(msp_init_func != NULL) { msp_init_func(msp_init_args); } @@ -81,7 +81,7 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) { * @param hspi: SPI handle pointer * @retval None */ -void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) { +extern "C" void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) { if(msp_deinit_func != NULL) { msp_deinit_func(msp_deinit_args); } diff --git a/stm32h7/spi/spiCore.h b/stm32h7/spi/spiCore.h index 75d4eca..fb947be 100644 --- a/stm32h7/spi/spiCore.h +++ b/stm32h7/spi/spiCore.h @@ -8,7 +8,7 @@ extern "C" { #endif -typedef void (*msp_func_t) (void* args); +using msp_func_t = void (*) (void* args); /** * Assign MSP init functions. Important for SPI configuration diff --git a/stm32h7/spi/spiDefinitions.h b/stm32h7/spi/spiDefinitions.h index e23ea2e..b812c15 100644 --- a/stm32h7/spi/spiDefinitions.h +++ b/stm32h7/spi/spiDefinitions.h @@ -8,6 +8,11 @@ namespace spi { +enum SpiBus { + SPI_1, + SPI_2 +}; + enum TransferModes { POLLING, INTERRUPT, diff --git a/stm32h7/spi/interrupts.c b/stm32h7/spi/spiInterrupts.cpp similarity index 75% rename from stm32h7/spi/interrupts.c rename to stm32h7/spi/spiInterrupts.cpp index 5137f40..51a58eb 100644 --- a/stm32h7/spi/interrupts.c +++ b/stm32h7/spi/spiInterrupts.cpp @@ -1,4 +1,4 @@ -#include "interrupts.h" +#include "spiInterrupts.h" #include "stm32h7xx_hal.h" #include "stm32h7xx_hal_dma.h" @@ -7,41 +7,12 @@ #include -void (*spi1_user_handler) (void* args) = NULL; -void * spi1_user_args = NULL; +void (*spi1_user_handler) (void* args) = nullptr; +void * spi1_user_args = nullptr; -void (*spi2_user_handler) (void* args) = NULL; -void * spi2_user_args = NULL; +void (*spi2_user_handler) (void* args) = nullptr; +void * spi2_user_args = nullptr; -void assign_spi_user_handler(SpiBus spi_idx, user_handler_t user_handler, user_args_t user_args) { - if(spi_idx == SPI_1) { - spi1_user_handler = user_handler; - spi1_user_args = user_args; - } - else { - spi2_user_handler = user_handler; - spi2_user_args = user_args; - } -} - -/* Do not change these function names! They need to be exactly equal to the name of the functions -defined in the startup_stm32h743xx.s files! */ - -void SPI1_IRQHandler() { - if(spi1_user_handler != NULL) { - spi1_user_handler(spi1_user_args); - return; - } - Default_Handler(); -} - -void SPI2_IRQHandler() { - if(spi2_user_handler != NULL) { - spi2_user_handler(spi2_user_args); - return; - } - Default_Handler(); -} /** * @brief This function handles DMA Rx interrupt request. @@ -71,3 +42,35 @@ void spi1_irq_handler(void* spi_handle) HAL_SPI_IRQHandler((SPI_HandleTypeDef *) spi_handle); } +void assign_spi_user_handler(spi::SpiBus spi_idx, user_handler_t user_handler, + user_args_t user_args) { + if(spi_idx == spi::SpiBus::SPI_1) { + spi1_user_handler = user_handler; + spi1_user_args = user_args; + } + else { + spi2_user_handler = user_handler; + spi2_user_args = user_args; + } +} + +/* Do not change these function names! They need to be exactly equal to the name of the functions +defined in the startup_stm32h743xx.s files! */ + +extern "C" void SPI1_IRQHandler() { + if(spi1_user_handler != NULL) { + spi1_user_handler(spi1_user_args); + return; + } + Default_Handler(); +} + +extern "C" void SPI2_IRQHandler() { + if(spi2_user_handler != NULL) { + spi2_user_handler(spi2_user_args); + return; + } + Default_Handler(); +} + + diff --git a/stm32h7/spi/interrupts.h b/stm32h7/spi/spiInterrupts.h similarity index 84% rename from stm32h7/spi/interrupts.h rename to stm32h7/spi/spiInterrupts.h index 060eaa1..49be029 100644 --- a/stm32h7/spi/interrupts.h +++ b/stm32h7/spi/spiInterrupts.h @@ -2,23 +2,20 @@ #define FSFW_HAL_STM32H7_SPI_INTERRUPTS_H_ #include "../interrupts.h" +#include "spiDefinitions.h" #ifdef __cplusplus extern "C" { #endif -typedef enum { - SPI_1, - SPI_2 -} SpiBus; - /** * Assign a user interrupt handler for SPI bus 1, allowing to pass an arbitrary argument as well. * Generally, this argument will be the related SPI handle. * @param user_handler * @param user_args */ -void assign_spi_user_handler(SpiBus spiBus, user_handler_t user_handler, user_args_t user_args); +void assign_spi_user_handler(spi::SpiBus spiBus, user_handler_t user_handler, + user_args_t user_args); /** * Generic interrupt handlers supplied for convenience. Do not call these directly! Set them