fsfw-hal/stm32h7/spi/spiInterrupts.cpp

77 lines
1.7 KiB
C++

#include "spiInterrupts.h"
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_dma.h"
#include "stm32h7xx_hal_spi.h"
#include <stddef.h>
void (*spi1_user_handler) (void* args) = nullptr;
void * spi1_user_args = nullptr;
void (*spi2_user_handler) (void* args) = nullptr;
void * spi2_user_args = nullptr;
/**
* @brief This function handles DMA Rx interrupt request.
* @param None
* @retval None
*/
void dma_rx_irq_handler(void* dma_handle) {
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dma_handle);
}
/**
* @brief This function handles DMA Rx interrupt request.
* @param None
* @retval None
*/
void dma_tx_irq_handler(void* dma_handle) {
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dma_handle);
}
/**
* @brief This function handles SPIx interrupt request.
* @param None
* @retval None
*/
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();
}