From d43cb26b8ee0a77db5283fa9fbeca84aa781231c Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Mon, 7 Mar 2022 15:28:53 +0100 Subject: [PATCH 1/4] ELRS/SX127x - Cleanup NVIC/atomic block usage. Since #11380 the sx127xISR will always be called from an ISR handler so no additional NVIC entry or ATOMIC_BLOCK is required. Also, since sx127xISR is always called from an ISR handler it means that there's no need to call rxSpiPollExti. --- src/main/drivers/rx/rx_sx127x.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/main/drivers/rx/rx_sx127x.c b/src/main/drivers/rx/rx_sx127x.c index 99172191f7..e85fc20986 100644 --- a/src/main/drivers/rx/rx_sx127x.c +++ b/src/main/drivers/rx/rx_sx127x.c @@ -76,27 +76,16 @@ static bool sx127xDetectChip(void) uint8_t sx127xISR(timeUs_t *timeStamp) { - bool extiTriggered = false; - timeUs_t extiTimestamp; + timeUs_t extiTimestamp = rxSpiGetLastExtiTimeUs(); - ATOMIC_BLOCK(NVIC_PRIO_RX_SPI_INT_EXTI) { - // prevent a data-race that can occur if a new EXTI ISR occurs during this block. - extiTriggered = rxSpiPollExti(); - extiTimestamp = rxSpiGetLastExtiTimeUs(); - if (extiTriggered) { - rxSpiResetExti(); - } + rxSpiResetExti(); + + uint8_t irqReason = sx127xGetIrqReason(); + if (extiTimestamp) { + *timeStamp = extiTimestamp; } - if (extiTriggered) { - uint8_t irqReason = sx127xGetIrqReason(); - if (extiTimestamp) { - *timeStamp = extiTimestamp; - } - - return irqReason; - } - return 0; + return irqReason; } bool sx127xInit(IO_t resetPin, IO_t busyPin) From d653dabebb37f550dcacc607e2c9f10c5f2268c9 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Mon, 7 Mar 2022 15:38:02 +0100 Subject: [PATCH 2/4] NIVC - Remove unused entries. --- src/main/drivers/nvic.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/drivers/nvic.h b/src/main/drivers/nvic.h index 216ed7ae05..1bfb5d5efc 100644 --- a/src/main/drivers/nvic.h +++ b/src/main/drivers/nvic.h @@ -75,10 +75,6 @@ #define NVIC_PRIO_I2C_EV NVIC_BUILD_PRIORITY(0, 0) #define NVIC_PRIO_USB NVIC_BUILD_PRIORITY(2, 0) #define NVIC_PRIO_USB_WUP NVIC_BUILD_PRIORITY(1, 0) -#define NVIC_PRIO_SONAR_ECHO NVIC_BUILD_PRIORITY(0x0f, 0x0f) -#define NVIC_PRIO_MPU_DATA_READY NVIC_BUILD_PRIORITY(0, 1) -#define NVIC_PRIO_MAG_DATA_READY NVIC_BUILD_PRIORITY(0x0f, 0x0f) -#define NVIC_PRIO_CALLBACK NVIC_BUILD_PRIORITY(0x0f, 0x0f) #define NVIC_PRIO_SPI_DMA NVIC_BUILD_PRIORITY(0, 0) #define NVIC_PRIO_SDIO_DMA NVIC_BUILD_PRIORITY(0, 0) From 9ea45b7c37901c4c4ef943f2335b85262bf60c1d Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Mon, 7 Mar 2022 15:41:20 +0100 Subject: [PATCH 3/4] NVIC - Remove outdated comment. Yes, there is a reason to use DMAIRQHandler, so that the WS2811 dma transfer complete handler can update the ws2811LedDataTransferInProgress flag. Potentially though the timer could be left running and restarted when the next led strip update occurs and the dma transfer 'numbers of bytes to transfer' field could be read instead of the ws2811LedDataTransferInProgress flag... --- src/main/drivers/nvic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/drivers/nvic.h b/src/main/drivers/nvic.h index 1bfb5d5efc..d65e4a9600 100644 --- a/src/main/drivers/nvic.h +++ b/src/main/drivers/nvic.h @@ -36,7 +36,7 @@ #define NVIC_PRIO_MPU_INT_EXTI NVIC_BUILD_PRIORITY(0x0f, 0x0f) #define NVIC_PRIO_MAG_INT_EXTI NVIC_BUILD_PRIORITY(0x0f, 0x0f) -#define NVIC_PRIO_WS2811_DMA NVIC_BUILD_PRIORITY(1, 2) // TODO - is there some reason to use high priority? (or to use DMA IRQ at all?) +#define NVIC_PRIO_WS2811_DMA NVIC_BUILD_PRIORITY(1, 2) // TODO - is there some reason to use high priority? #define NVIC_PRIO_SERIALUART_TXDMA NVIC_BUILD_PRIORITY(1, 1) // Highest of all SERIALUARTx_TXDMA #define NVIC_PRIO_SERIALUART1_TXDMA NVIC_BUILD_PRIORITY(1, 1) #define NVIC_PRIO_SERIALUART1_RXDMA NVIC_BUILD_PRIORITY(1, 1) From b79e3bb741dbcdf22f27454a1c00707f4237da14 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Wed, 16 Mar 2022 13:50:36 +0100 Subject: [PATCH 4/4] ELRS - Delete now-unused NVIC_PRIO_RX_SPI_INT_EXTI. --- src/main/drivers/nvic.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/drivers/nvic.h b/src/main/drivers/nvic.h index d65e4a9600..ed3c65629b 100644 --- a/src/main/drivers/nvic.h +++ b/src/main/drivers/nvic.h @@ -30,7 +30,6 @@ #define NVIC_PRIO_TRANSPONDER_DMA NVIC_BUILD_PRIORITY(3, 0) // RX_SPI must be lower priority than SPI DMA so EXTI ISRs don't interfere with SPI transfers and transfer complete callbacks -#define NVIC_PRIO_RX_SPI_INT_EXTI NVIC_BUILD_PRIORITY(3, 0x0f) #define NVIC_PRIO_RX_INT_EXTI NVIC_BUILD_PRIORITY(3, 0x0f) #define NVIC_PRIO_RX_BUSY_EXTI NVIC_BUILD_PRIORITY(3, 0x0f)