1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

Implement queuing of SPI request segments

Use union in busSegment_t as per ledvinap feedback
This commit is contained in:
Steve Evans 2022-01-01 02:31:18 +00:00
parent ea53e32db4
commit 4aab87539f
11 changed files with 190 additions and 185 deletions

View file

@ -257,7 +257,7 @@ busStatus_e m25p16_callbackReady(uint32_t arg)
flashDevice_t *fdevice = (flashDevice_t *)arg;
extDevice_t *dev = fdevice->io.handle.dev;
uint8_t readyPoll = dev->bus->curSegment->rxData[1];
uint8_t readyPoll = dev->bus->curSegment->u.buffers.rxData[1];
if (readyPoll & M25P16_STATUS_FLAG_WRITE_IN_PROGRESS) {
return BUS_BUSY;
@ -281,10 +281,10 @@ static void m25p16_eraseSector(flashDevice_t *fdevice, uint32_t address)
STATIC_DMA_DATA_AUTO uint8_t writeEnable[] = { M25P16_INSTRUCTION_WRITE_ENABLE };
busSegment_t segments[] = {
{readStatus, readyStatus, sizeof(readStatus), true, m25p16_callbackReady},
{writeEnable, NULL, sizeof(writeEnable), true, m25p16_callbackWriteEnable},
{sectorErase, NULL, fdevice->isLargeFlash ? 5 : 4, true, NULL},
{NULL, NULL, 0, true, NULL},
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, m25p16_callbackReady},
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, m25p16_callbackWriteEnable},
{.u.buffers = {sectorErase, NULL}, fdevice->isLargeFlash ? 5 : 4, true, NULL},
{.u.buffers = {NULL, NULL}, 0, true, NULL},
};
// Ensure any prior DMA has completed before continuing
@ -306,10 +306,10 @@ static void m25p16_eraseCompletely(flashDevice_t *fdevice)
STATIC_DMA_DATA_AUTO uint8_t bulkErase[] = { M25P16_INSTRUCTION_BULK_ERASE };
busSegment_t segments[] = {
{readStatus, readyStatus, sizeof(readStatus), true, m25p16_callbackReady},
{writeEnable, NULL, sizeof(writeEnable), true, m25p16_callbackWriteEnable},
{bulkErase, NULL, sizeof(bulkErase), true, NULL},
{NULL, NULL, 0, true, NULL},
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, m25p16_callbackReady},
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, m25p16_callbackWriteEnable},
{.u.buffers = {bulkErase, NULL}, sizeof(bulkErase), true, NULL},
{.u.buffers = {NULL, NULL}, 0, true, NULL},
};
spiSequence(fdevice->io.handle.dev, segments);
@ -334,12 +334,12 @@ static uint32_t m25p16_pageProgramContinue(flashDevice_t *fdevice, uint8_t const
STATIC_DMA_DATA_AUTO uint8_t pageProgram[5] = { M25P16_INSTRUCTION_PAGE_PROGRAM };
static busSegment_t segments[] = {
{readStatus, readyStatus, sizeof(readStatus), true, m25p16_callbackReady},
{writeEnable, NULL, sizeof(writeEnable), true, m25p16_callbackWriteEnable},
{pageProgram, NULL, 0, false, NULL},
{NULL, NULL, 0, true, NULL},
{NULL, NULL, 0, true, NULL},
{NULL, NULL, 0, true, NULL},
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, m25p16_callbackReady},
{.u.buffers = {writeEnable, NULL}, sizeof(writeEnable), true, m25p16_callbackWriteEnable},
{.u.buffers = {pageProgram, NULL}, 0, false, NULL},
{.u.buffers = {NULL, NULL}, 0, true, NULL},
{.u.buffers = {NULL, NULL}, 0, true, NULL},
{.u.buffers = {NULL, NULL}, 0, true, NULL},
};
// Ensure any prior DMA has completed before continuing
@ -350,7 +350,7 @@ static uint32_t m25p16_pageProgramContinue(flashDevice_t *fdevice, uint8_t const
m25p16_setCommandAddress(&pageProgram[1], fdevice->currentWriteAddress, fdevice->isLargeFlash);
// Patch the data segments
segments[DATA1].txData = (uint8_t *)buffers[0];
segments[DATA1].u.buffers.txData = (uint8_t *)buffers[0];
segments[DATA1].len = bufferSizes[0];
fdevice->callbackArg = bufferSizes[0];
@ -358,12 +358,12 @@ static uint32_t m25p16_pageProgramContinue(flashDevice_t *fdevice, uint8_t const
segments[DATA1].negateCS = true;
segments[DATA1].callback = m25p16_callbackWriteComplete;
// Mark segment following data as being of zero length
segments[DATA2].txData = (uint8_t *)NULL;
segments[DATA2].u.buffers.txData = (uint8_t *)NULL;
segments[DATA2].len = 0;
} else if (bufferCount == 2) {
segments[DATA1].negateCS = false;
segments[DATA1].callback = NULL;
segments[DATA2].txData = (uint8_t *)buffers[1];
segments[DATA2].u.buffers.txData = (uint8_t *)buffers[1];
segments[DATA2].len = bufferSizes[1];
fdevice->callbackArg += bufferSizes[1];
segments[DATA2].negateCS = true;
@ -427,10 +427,10 @@ static int m25p16_readBytes(flashDevice_t *fdevice, uint32_t address, uint8_t *b
spiWait(fdevice->io.handle.dev);
busSegment_t segments[] = {
{readStatus, readyStatus, sizeof(readStatus), true, m25p16_callbackReady},
{readBytes, NULL, fdevice->isLargeFlash ? 5 : 4, false, NULL},
{NULL, buffer, length, true, NULL},
{NULL, NULL, 0, true, NULL},
{.u.buffers = {readStatus, readyStatus}, sizeof(readStatus), true, m25p16_callbackReady},
{.u.buffers = {readBytes, NULL}, fdevice->isLargeFlash ? 5 : 4, false, NULL},
{.u.buffers = {NULL, buffer}, length, true, NULL},
{.u.buffers = {NULL, NULL}, 0, true, NULL},
};
// Patch the readBytes command