converted files to cpp continued stubs

This commit is contained in:
Robin Müller 2021-06-04 16:34:38 +02:00
parent 39d2a49ca1
commit cb121b9faf
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
14 changed files with 93 additions and 70 deletions

View File

@ -2,6 +2,5 @@ add_subdirectory(spi)
add_subdirectory(devicetest)
target_sources(${TARGET_NAME} PRIVATE
interrupts.c
dma_interrupts.c
)

View File

@ -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

View File

@ -1,2 +0,0 @@
#include "interrupts.h"
#include <stddef.h>

View File

@ -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
)

View File

@ -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) {

View File

@ -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;
};

View File

@ -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) {
}

View File

@ -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;
};

View File

@ -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);
}

View File

@ -1,15 +1,15 @@
#include "spiCore.h"
#include <stdio.h>
#include <cstdio>
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);
}

View File

@ -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

View File

@ -8,6 +8,11 @@
namespace spi {
enum SpiBus {
SPI_1,
SPI_2
};
enum TransferModes {
POLLING,
INTERRUPT,

View File

@ -1,4 +1,4 @@
#include "interrupts.h"
#include "spiInterrupts.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_dma.h"
@ -7,41 +7,12 @@
#include <stddef.h>
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();
}

View File

@ -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