diff --git a/src/main/drivers/bus_spi.c b/src/main/drivers/bus_spi.c index 615470aeb4..29255e5ef6 100644 --- a/src/main/drivers/bus_spi.c +++ b/src/main/drivers/bus_spi.c @@ -490,7 +490,7 @@ void spiSequence(const extDevice_t *dev, busSegment_t *segments) FAST_CODE void spiProcessSegmentsDMA(const extDevice_t *dev) { // Intialise the init structures for the first transfer - spiInternalInitStream(dev, false); + spiInternalInitStream(dev, dev->bus->curSegment); // Assert Chip Select IOLo(dev->busType_u.spi.csnPin); @@ -499,6 +499,16 @@ FAST_CODE void spiProcessSegmentsDMA(const extDevice_t *dev) spiInternalStartDMA(dev); } +static void spiPreInitStream(const extDevice_t *dev) +{ + // Prepare the init structure for the next segment to reduce inter-segment interval + // (if it's a "buffers" segment, not a "link" segment). + busSegment_t *segment = (busSegment_t *)dev->bus->curSegment + 1; + if (segment->len > 0) { + spiInternalInitStream(dev, segment); + } +} + // Interrupt handler common code for SPI receive DMA completion. // Proceed to next segment as required. FAST_IRQ_HANDLER void spiIrqHandler(const extDevice_t *dev) @@ -512,7 +522,7 @@ FAST_IRQ_HANDLER void spiIrqHandler(const extDevice_t *dev) // Repeat the last DMA segment bus->curSegment--; // Reinitialise the cached init values as segment is not progressing - spiInternalInitStream(dev, true); + spiPreInitStream(dev); break; case BUS_ABORT: @@ -557,7 +567,7 @@ FAST_IRQ_HANDLER void spiIrqHandler(const extDevice_t *dev) // After the completion of the first segment setup the init structure for the subsequent segment if (bus->initSegment) { - spiInternalInitStream(dev, false); + spiInternalInitStream(dev, bus->curSegment); bus->initSegment = false; } @@ -570,7 +580,7 @@ FAST_IRQ_HANDLER void spiIrqHandler(const extDevice_t *dev) spiInternalStartDMA(dev); // Prepare the init structures ready for the next segment to reduce inter-segment time - spiInternalInitStream(dev, true); + spiPreInitStream(dev); } } diff --git a/src/main/drivers/bus_spi_impl.h b/src/main/drivers/bus_spi_impl.h index 4b5106c8c4..abf925d447 100644 --- a/src/main/drivers/bus_spi_impl.h +++ b/src/main/drivers/bus_spi_impl.h @@ -87,7 +87,7 @@ typedef struct SPIDevice_s { extern spiDevice_t spiDevice[SPIDEV_COUNT]; void spiInitDevice(SPIDevice device); -void spiInternalInitStream(const extDevice_t *dev, bool preInit); +void spiInternalInitStream(const extDevice_t *dev, volatile busSegment_t *segment); void spiInternalStartDMA(const extDevice_t *dev); void spiInternalStopDMA (const extDevice_t *dev); void spiInternalResetStream(dmaChannelDescriptor_t *descriptor); diff --git a/src/platform/APM32/bus_spi_apm32.c b/src/platform/APM32/bus_spi_apm32.c index 6c58c5e8da..cf49043e58 100644 --- a/src/platform/APM32/bus_spi_apm32.c +++ b/src/platform/APM32/bus_spi_apm32.c @@ -156,23 +156,11 @@ FAST_CODE bool spiInternalReadWriteBufPolled(SPI_TypeDef *instance, const uint8_ return true; } -void spiInternalInitStream(const extDevice_t *dev, bool preInit) +void spiInternalInitStream(const extDevice_t *dev, volatile busSegment_t *segment) { STATIC_DMA_DATA_AUTO uint8_t dummyTxByte = 0xff; STATIC_DMA_DATA_AUTO uint8_t dummyRxByte; busDevice_t *bus = dev->bus; - - busSegment_t *segment = (busSegment_t *)bus->curSegment; - - if (preInit) { - // Prepare the init structure for the next segment to reduce inter-segment interval - segment++; - if(segment->len == 0) { - // There's no following segment - return; - } - } - int len = segment->len; uint8_t *txData = segment->u.buffers.txData; diff --git a/src/platform/AT32/bus_spi_at32bsp.c b/src/platform/AT32/bus_spi_at32bsp.c index fed36d685e..7a96e06139 100644 --- a/src/platform/AT32/bus_spi_at32bsp.c +++ b/src/platform/AT32/bus_spi_at32bsp.c @@ -156,23 +156,11 @@ bool spiInternalReadWriteBufPolled(spi_type *instance, const uint8_t *txData, ui return true; } -void spiInternalInitStream(const extDevice_t *dev, bool preInit) +void spiInternalInitStream(const extDevice_t *dev, volatile busSegment_t *segment) { STATIC_DMA_DATA_AUTO uint8_t dummyTxByte = 0xff; STATIC_DMA_DATA_AUTO uint8_t dummyRxByte; busDevice_t *bus = dev->bus; - - volatile busSegment_t *segment = bus->curSegment; - - if (preInit) { - // Prepare the init structure for the next segment to reduce inter-segment interval - segment++; - if(segment->len == 0) { - // There's no following segment - return; - } - } - int len = segment->len; uint8_t *txData = segment->u.buffers.txData; diff --git a/src/platform/STM32/bus_spi_ll.c b/src/platform/STM32/bus_spi_ll.c index 2a12575335..71857318a4 100644 --- a/src/platform/STM32/bus_spi_ll.c +++ b/src/platform/STM32/bus_spi_ll.c @@ -268,23 +268,11 @@ FAST_CODE bool spiInternalReadWriteBufPolled(SPI_TypeDef *instance, const uint8_ return true; } -void spiInternalInitStream(const extDevice_t *dev, bool preInit) +void spiInternalInitStream(const extDevice_t *dev, volatile busSegment_t *segment) { STATIC_DMA_DATA_AUTO uint8_t dummyTxByte = 0xff; STATIC_DMA_DATA_AUTO uint8_t dummyRxByte; busDevice_t *bus = dev->bus; - - busSegment_t *segment = (busSegment_t *)bus->curSegment; - - if (preInit) { - // Prepare the init structure for the next segment to reduce inter-segment interval - segment++; - if(segment->len == 0) { - // There's no following segment - return; - } - } - int len = segment->len; uint8_t *txData = segment->u.buffers.txData; diff --git a/src/platform/STM32/bus_spi_stdperiph.c b/src/platform/STM32/bus_spi_stdperiph.c index 9bb02fba80..5c37d8f5e6 100644 --- a/src/platform/STM32/bus_spi_stdperiph.c +++ b/src/platform/STM32/bus_spi_stdperiph.c @@ -162,23 +162,11 @@ bool spiInternalReadWriteBufPolled(SPI_TypeDef *instance, const uint8_t *txData, return true; } -void spiInternalInitStream(const extDevice_t *dev, bool preInit) +void spiInternalInitStream(const extDevice_t *dev, volatile busSegment_t *segment) { STATIC_DMA_DATA_AUTO uint8_t dummyTxByte = 0xff; STATIC_DMA_DATA_AUTO uint8_t dummyRxByte; busDevice_t *bus = dev->bus; - - volatile busSegment_t *segment = bus->curSegment; - - if (preInit) { - // Prepare the init structure for the next segment to reduce inter-segment interval - segment++; - if(segment->len == 0) { - // There's no following segment - return; - } - } - int len = segment->len; uint8_t *txData = segment->u.buffers.txData;