From fa966924e40a125805deb10e607637c5d3cab51d Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 20 Aug 2022 16:28:14 +0100 Subject: [PATCH] usbuart: Moved the aux UART DMA RX interrupt handling into aux_serial.c --- src/platforms/common/aux_serial.c | 41 ++++++++++++++++++++++++++++++ src/platforms/stm32/usbuart.c | 42 ------------------------------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/platforms/common/aux_serial.c b/src/platforms/common/aux_serial.c index 3d9708f..a970bd5 100644 --- a/src/platforms/common/aux_serial.c +++ b/src/platforms/common/aux_serial.c @@ -309,6 +309,17 @@ static void aux_serial_dma_transmit_isr(const uint8_t dma_tx_channel) nvic_enable_irq(USB_IRQ); } +static void aux_serial_dma_receive_isr(const uint8_t usart_irq, const uint8_t dma_rx_channel) +{ + nvic_disable_irq(usart_irq); + + /* Clear flags and transmit a packet*/ + dma_clear_interrupt_flags(USBUSART_DMA_BUS, dma_rx_channel, DMA_CGIF); + debug_uart_run(); + + nvic_enable_irq(usart_irq); +} + #if defined(USBUSART_ISR) void USBUSART_ISR(void) { @@ -363,6 +374,36 @@ void USBUSART2_DMA_TX_ISR(void) } #endif +#if defined(USBUSART_DMA_RX_ISR) +void USBUSART_DMA_RX_ISR(void) +{ + aux_serial_dma_receive_isr(USBUSART_IRQ, USBUSART_DMA_RX_CHAN); +} +#endif + +#if defined(USBUSART1_DMA_RX_ISR) +void USBUSART1_DMA_RX_ISR(void) +{ + aux_serial_dma_receive_isr(USBUSART1_IRQ, USBUSART1_DMA_RX_CHAN); +} +#endif + +#if defined(USBUSART2_DMA_RX_ISR) +void USBUSART2_DMA_RX_ISR(void) +{ + aux_serial_dma_receive_isr(USBUSART2_IRQ, USBUSART2_DMA_RX_CHAN); +} +#endif + +#if defined(USBUSART_DMA_RXTX_ISR) +void USBUSART_DMA_RXTX_ISR(void) +{ + if (dma_get_interrupt_flag(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN, DMA_CGIF)) + USBUSART_DMA_RX_ISR(); + if (dma_get_interrupt_flag(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN, DMA_CGIF)) + USBUSART_DMA_TX_ISR(); +} +#endif #elif defined(LM4F) char *aux_serial_current_transmit_buffer(void) { diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index a971f6c..496d9cc 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -75,45 +75,3 @@ void usbuart_set_led_state(uint8_t ledn, bool state) gpio_clear(LED_PORT_UART, LED_UART); } } - -#define USBUSART_DMA_RX_ISR_TEMPLATE(USART_IRQ, DMA_RX_CHAN) do { \ - nvic_disable_irq(USART_IRQ); \ - \ - /* Clear flags */ \ - dma_clear_interrupt_flags(USBUSART_DMA_BUS, DMA_RX_CHAN, DMA_CGIF); \ - /* Transmit a packet */ \ - debug_uart_run(); \ - \ - nvic_enable_irq(USART_IRQ); \ -} while(0) - -#if defined(USBUSART_DMA_RX_ISR) -void USBUSART_DMA_RX_ISR(void) -{ - USBUSART_DMA_RX_ISR_TEMPLATE(USBUSART_IRQ, USBUSART_DMA_RX_CHAN); -} -#endif - -#if defined(USBUSART1_DMA_RX_ISR) -void USBUSART1_DMA_RX_ISR(void) -{ - USBUSART_DMA_RX_ISR_TEMPLATE(USBUSART1_IRQ, USBUSART1_DMA_RX_CHAN); -} -#endif - -#if defined(USBUSART2_DMA_RX_ISR) -void USBUSART2_DMA_RX_ISR(void) -{ - USBUSART_DMA_RX_ISR_TEMPLATE(USBUSART2_IRQ, USBUSART2_DMA_RX_CHAN); -} -#endif - -#if defined(USBUSART_DMA_RXTX_ISR) -void USBUSART_DMA_RXTX_ISR(void) -{ - if (dma_get_interrupt_flag(USBUSART_DMA_BUS, USBUSART_DMA_RX_CHAN, DMA_CGIF)) - USBUSART_DMA_RX_ISR(); - if (dma_get_interrupt_flag(USBUSART_DMA_BUS, USBUSART_DMA_TX_CHAN, DMA_CGIF)) - USBUSART_DMA_TX_ISR(); -} -#endif