1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-12 19:10:32 +03:00

spiInternalInitStream extract common preInit code.

Clarify logic for init / preinit of spi DMA channels by extracting
the code for when spiInternalInitStream was called with preInit = true.

NB PICO updates to follow
This commit is contained in:
Matthew Selby 2025-07-04 10:55:21 +01:00
parent b6d37008f5
commit 16283c4e14
6 changed files with 19 additions and 57 deletions

View file

@ -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);
}
}

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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;