fsfw/src/fsfw_hal/stm32h7/spi/spiInterrupts.cpp

104 lines
2.4 KiB
C++
Raw Normal View History

2021-08-02 20:58:56 +02:00
#include "fsfw_hal/stm32h7/spi/spiInterrupts.h"
2021-07-13 19:19:25 +02:00
2022-02-02 10:29:30 +01:00
#include <stddef.h>
#include "fsfw_hal/stm32h7/spi/spiCore.h"
2021-07-13 19:19:25 +02:00
#include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_dma.h"
#include "stm32h7xx_hal_spi.h"
user_handler_t spi1UserHandler = &spi::spiIrqHandler;
user_args_t spi1UserArgs = nullptr;
user_handler_t spi2UserHandler = &spi::spiIrqHandler;
user_args_t spi2UserArgs = nullptr;
/**
* @brief This function handles DMA Rx interrupt request.
* @param None
* @retval None
*/
2022-02-02 10:29:30 +01:00
void spi::dmaRxIrqHandler(void *dmaHandle) {
if (dmaHandle == nullptr) {
return;
}
HAL_DMA_IRQHandler((DMA_HandleTypeDef *)dmaHandle);
2021-07-13 19:19:25 +02:00
}
/**
* @brief This function handles DMA Rx interrupt request.
* @param None
* @retval None
*/
2022-02-02 10:29:30 +01:00
void spi::dmaTxIrqHandler(void *dmaHandle) {
if (dmaHandle == nullptr) {
return;
}
HAL_DMA_IRQHandler((DMA_HandleTypeDef *)dmaHandle);
2021-07-13 19:19:25 +02:00
}
/**
* @brief This function handles SPIx interrupt request.
* @param None
* @retval None
*/
2022-02-02 10:29:30 +01:00
void spi::spiIrqHandler(void *spiHandle) {
if (spiHandle == nullptr) {
return;
}
// auto currentSpiHandle = spi::getSpiHandle();
HAL_SPI_IRQHandler((SPI_HandleTypeDef *)spiHandle);
2021-07-13 19:19:25 +02:00
}
void spi::assignSpiUserHandler(spi::SpiBus spiIdx, user_handler_t userHandler,
2022-02-02 10:29:30 +01:00
user_args_t userArgs) {
if (spiIdx == spi::SpiBus::SPI_1) {
spi1UserHandler = userHandler;
spi1UserArgs = userArgs;
} else {
spi2UserHandler = userHandler;
spi2UserArgs = userArgs;
}
2021-07-13 19:19:25 +02:00
}
void spi::getSpiUserHandler(spi::SpiBus spiBus, user_handler_t *userHandler,
2022-02-02 10:29:30 +01:00
user_args_t *userArgs) {
if (userHandler == nullptr or userArgs == nullptr) {
return;
}
if (spiBus == spi::SpiBus::SPI_1) {
*userArgs = spi1UserArgs;
*userHandler = spi1UserHandler;
} else {
*userArgs = spi2UserArgs;
*userHandler = spi2UserHandler;
}
2021-07-13 19:19:25 +02:00
}
void spi::assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs) {
2022-02-02 10:29:30 +01:00
if (spiBus == spi::SpiBus::SPI_1) {
spi1UserArgs = userArgs;
} else {
spi2UserArgs = userArgs;
}
2021-07-13 19:19:25 +02:00
}
/* 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() {
2022-02-02 10:29:30 +01:00
if (spi1UserHandler != NULL) {
spi1UserHandler(spi1UserArgs);
return;
}
Default_Handler();
2021-07-13 19:19:25 +02:00
}
2022-02-02 10:29:30 +01:00
extern "C" void SPI2_IRQHandler() {
if (spi2UserHandler != nullptr) {
spi2UserHandler(spi2UserArgs);
return;
}
Default_Handler();
2021-07-13 19:19:25 +02:00
}