refactored irq code

This commit is contained in:
2021-06-03 16:11:49 +02:00
parent 78a66e1b67
commit abe62d807a
8 changed files with 203 additions and 83 deletions

View File

@ -2,11 +2,38 @@
#include <stddef.h>
void SPI1_IRQHandler() {
void (*spi1_user_handler) (void* args) = NULL;
void * spi1_user_args = NULL;
void (*spi2_user_handler) (void* args) = NULL;
void * spi2_user_args = NULL;
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();
}

View File

@ -1,8 +1,27 @@
#ifndef FSFW_HAL_STM32H7_INTERRUPTS_H_
#define FSFW_HAL_STM32H7_INTERRUPTS_H_
#ifndef FSFW_HAL_STM32H7_SPI_INTERRUPTS_H_
#define FSFW_HAL_STM32H7_SPI_INTERRUPTS_H_
#include "../interrupts.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);
#endif /* FSFW_HAL_STM32H7_INTERRUPTS_H_ */
#ifdef __cplusplus
}
#endif
#endif /* FSFW_HAL_STM32H7_SPI_INTERRUPTS_H_ */

View File

@ -25,44 +25,30 @@ SPI_HandleTypeDef* getSpiHandle() {
return spiHandle;
}
///**
// * @brief This function handles DMA Rx interrupt request.
// * @param None
// * @retval None
// */
//void SPIx_DMA_RX_IRQHandler(void)
//{
// HAL_DMA_IRQHandler(spiHandle->hdmarx);
//}
//
///**
// * @brief This function handles DMA Tx interrupt request.
// * @param None
// * @retval None
// */
//void SPIx_DMA_TX_IRQHandler(void)
//{
// HAL_DMA_IRQHandler(spiHandle->hdmatx);
//}
//
//void DMA2_Stream3_IRQHandler() {
// SPIx_DMA_TX_IRQHandler();
//}
//
//void DMA2_Stream2_IRQHandler() {
// SPIx_DMA_RX_IRQHandler();
//}
//
///**
// * @brief This function handles SPIx interrupt request.
// * @param None
// * @retval None
// */
//void SPIx_IRQHandler(void)
//{
// HAL_SPI_IRQHandler(spiHandle);
//}
//
//void SPI1_IRQHandler(void) {
// SPIx_IRQHandler();
//}
/**
* @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);
}