Tidied blackbox switch statements

This commit is contained in:
Martin Budden 2017-04-25 12:00:13 +01:00
parent 1ad0546af3
commit 68154a223b
1 changed files with 296 additions and 296 deletions

View File

@ -78,18 +78,18 @@ void blackboxWrite(uint8_t value)
{
switch (blackboxConfig()->device) {
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
flashfsWriteByte(value); // Write byte asynchronously
case BLACKBOX_DEVICE_FLASH:
flashfsWriteByte(value); // Write byte asynchronously
break;
#endif
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
afatfs_fputc(blackboxSDCard.logFile, value);
case BLACKBOX_DEVICE_SDCARD:
afatfs_fputc(blackboxSDCard.logFile, value);
break;
#endif
case BLACKBOX_DEVICE_SERIAL:
default:
serialWrite(blackboxPort, value);
case BLACKBOX_DEVICE_SERIAL:
default:
serialWrite(blackboxPort, value);
break;
}
}
@ -153,28 +153,28 @@ int blackboxPrint(const char *s)
switch (blackboxConfig()->device) {
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
length = strlen(s);
flashfsWrite((const uint8_t*) s, length, false); // Write asynchronously
case BLACKBOX_DEVICE_FLASH:
length = strlen(s);
flashfsWrite((const uint8_t*) s, length, false); // Write asynchronously
break;
#endif
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
length = strlen(s);
afatfs_fwrite(blackboxSDCard.logFile, (const uint8_t*) s, length); // Ignore failures due to buffers filling up
case BLACKBOX_DEVICE_SDCARD:
length = strlen(s);
afatfs_fwrite(blackboxSDCard.logFile, (const uint8_t*) s, length); // Ignore failures due to buffers filling up
break;
#endif
case BLACKBOX_DEVICE_SERIAL:
default:
pos = (uint8_t*) s;
while (*pos) {
serialWrite(blackboxPort, *pos);
pos++;
}
case BLACKBOX_DEVICE_SERIAL:
default:
pos = (uint8_t*) s;
while (*pos) {
serialWrite(blackboxPort, *pos);
pos++;
}
length = pos - (uint8_t*) s;
length = pos - (uint8_t*) s;
break;
}
@ -278,72 +278,72 @@ void blackboxWriteTag2_3S32(int32_t *values) {
}
switch (selector) {
case BITS_2:
blackboxWrite((selector << 6) | ((values[0] & 0x03) << 4) | ((values[1] & 0x03) << 2) | (values[2] & 0x03));
case BITS_2:
blackboxWrite((selector << 6) | ((values[0] & 0x03) << 4) | ((values[1] & 0x03) << 2) | (values[2] & 0x03));
break;
case BITS_4:
blackboxWrite((selector << 6) | (values[0] & 0x0F));
blackboxWrite((values[1] << 4) | (values[2] & 0x0F));
case BITS_4:
blackboxWrite((selector << 6) | (values[0] & 0x0F));
blackboxWrite((values[1] << 4) | (values[2] & 0x0F));
break;
case BITS_6:
blackboxWrite((selector << 6) | (values[0] & 0x3F));
blackboxWrite((uint8_t)values[1]);
blackboxWrite((uint8_t)values[2]);
case BITS_6:
blackboxWrite((selector << 6) | (values[0] & 0x3F));
blackboxWrite((uint8_t)values[1]);
blackboxWrite((uint8_t)values[2]);
break;
case BITS_32:
/*
* Do another round to compute a selector for each field, assuming that they are at least 8 bits each
*
* Selector2 field possibilities
* 0 - 8 bits
* 1 - 16 bits
* 2 - 24 bits
* 3 - 32 bits
*/
selector2 = 0;
case BITS_32:
/*
* Do another round to compute a selector for each field, assuming that they are at least 8 bits each
*
* Selector2 field possibilities
* 0 - 8 bits
* 1 - 16 bits
* 2 - 24 bits
* 3 - 32 bits
*/
selector2 = 0;
//Encode in reverse order so the first field is in the low bits:
for (x = NUM_FIELDS - 1; x >= 0; x--) {
selector2 <<= 2;
//Encode in reverse order so the first field is in the low bits:
for (x = NUM_FIELDS - 1; x >= 0; x--) {
selector2 <<= 2;
if (values[x] < 128 && values[x] >= -128) {
selector2 |= BYTES_1;
} else if (values[x] < 32768 && values[x] >= -32768) {
selector2 |= BYTES_2;
} else if (values[x] < 8388608 && values[x] >= -8388608) {
selector2 |= BYTES_3;
} else {
selector2 |= BYTES_4;
}
if (values[x] < 128 && values[x] >= -128) {
selector2 |= BYTES_1;
} else if (values[x] < 32768 && values[x] >= -32768) {
selector2 |= BYTES_2;
} else if (values[x] < 8388608 && values[x] >= -8388608) {
selector2 |= BYTES_3;
} else {
selector2 |= BYTES_4;
}
}
//Write the selectors
blackboxWrite((selector << 6) | selector2);
//Write the selectors
blackboxWrite((selector << 6) | selector2);
//And now the values according to the selectors we picked for them
for (x = 0; x < NUM_FIELDS; x++, selector2 >>= 2) {
switch (selector2 & 0x03) {
case BYTES_1:
blackboxWrite(values[x]);
break;
case BYTES_2:
blackboxWrite(values[x]);
blackboxWrite(values[x] >> 8);
break;
case BYTES_3:
blackboxWrite(values[x]);
blackboxWrite(values[x] >> 8);
blackboxWrite(values[x] >> 16);
break;
case BYTES_4:
blackboxWrite(values[x]);
blackboxWrite(values[x] >> 8);
blackboxWrite(values[x] >> 16);
blackboxWrite(values[x] >> 24);
break;
}
//And now the values according to the selectors we picked for them
for (x = 0; x < NUM_FIELDS; x++, selector2 >>= 2) {
switch (selector2 & 0x03) {
case BYTES_1:
blackboxWrite(values[x]);
break;
case BYTES_2:
blackboxWrite(values[x]);
blackboxWrite(values[x] >> 8);
break;
case BYTES_3:
blackboxWrite(values[x]);
blackboxWrite(values[x] >> 8);
blackboxWrite(values[x] >> 16);
break;
case BYTES_4:
blackboxWrite(values[x]);
blackboxWrite(values[x] >> 8);
blackboxWrite(values[x] >> 16);
blackboxWrite(values[x] >> 24);
break;
}
break;
}
break;
}
}
@ -386,42 +386,42 @@ void blackboxWriteTag8_4S16(int32_t *values) {
buffer = 0;
for (x = 0; x < 4; x++, selector >>= 2) {
switch (selector & 0x03) {
case FIELD_ZERO:
//No-op
case FIELD_ZERO:
//No-op
break;
case FIELD_4BIT:
if (nibbleIndex == 0) {
//We fill high-bits first
buffer = values[x] << 4;
nibbleIndex = 1;
} else {
blackboxWrite(buffer | (values[x] & 0x0F));
nibbleIndex = 0;
}
case FIELD_4BIT:
if (nibbleIndex == 0) {
//We fill high-bits first
buffer = values[x] << 4;
nibbleIndex = 1;
} else {
blackboxWrite(buffer | (values[x] & 0x0F));
nibbleIndex = 0;
}
break;
case FIELD_8BIT:
if (nibbleIndex == 0) {
blackboxWrite(values[x]);
} else {
//Write the high bits of the value first (mask to avoid sign extension)
blackboxWrite(buffer | ((values[x] >> 4) & 0x0F));
//Now put the leftover low bits into the top of the next buffer entry
buffer = values[x] << 4;
}
case FIELD_8BIT:
if (nibbleIndex == 0) {
blackboxWrite(values[x]);
} else {
//Write the high bits of the value first (mask to avoid sign extension)
blackboxWrite(buffer | ((values[x] >> 4) & 0x0F));
//Now put the leftover low bits into the top of the next buffer entry
buffer = values[x] << 4;
}
break;
case FIELD_16BIT:
if (nibbleIndex == 0) {
//Write high byte first
blackboxWrite(values[x] >> 8);
blackboxWrite(values[x]);
} else {
//First write the highest 4 bits
blackboxWrite(buffer | ((values[x] >> 12) & 0x0F));
// Then the middle 8
blackboxWrite(values[x] >> 4);
//Only the smallest 4 bits are still left to write
buffer = values[x] << 4;
}
case FIELD_16BIT:
if (nibbleIndex == 0) {
//Write high byte first
blackboxWrite(values[x] >> 8);
blackboxWrite(values[x]);
} else {
//First write the highest 4 bits
blackboxWrite(buffer | ((values[x] >> 12) & 0x0F));
// Then the middle 8
blackboxWrite(values[x] >> 4);
//Only the smallest 4 bits are still left to write
buffer = values[x] << 4;
}
break;
}
}
@ -498,13 +498,13 @@ void blackboxDeviceFlush(void)
* This is our only output device which requires us to call flush() in order for it to write anything. The other
* devices will progressively write in the background without Blackbox calling anything.
*/
case BLACKBOX_DEVICE_FLASH:
flashfsFlushAsync();
case BLACKBOX_DEVICE_FLASH:
flashfsFlushAsync();
break;
#endif
default:
;
default:
;
}
}
@ -516,25 +516,25 @@ void blackboxDeviceFlush(void)
bool blackboxDeviceFlushForce(void)
{
switch (blackboxConfig()->device) {
case BLACKBOX_DEVICE_SERIAL:
// Nothing to speed up flushing on serial, as serial is continuously being drained out of its buffer
return isSerialTransmitBufferEmpty(blackboxPort);
case BLACKBOX_DEVICE_SERIAL:
// Nothing to speed up flushing on serial, as serial is continuously being drained out of its buffer
return isSerialTransmitBufferEmpty(blackboxPort);
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
return flashfsFlushAsync();
case BLACKBOX_DEVICE_FLASH:
return flashfsFlushAsync();
#endif
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
/* SD card will flush itself without us calling it, but we need to call flush manually in order to check
* if it's done yet or not!
*/
return afatfs_flush();
case BLACKBOX_DEVICE_SDCARD:
/* SD card will flush itself without us calling it, but we need to call flush manually in order to check
* if it's done yet or not!
*/
return afatfs_flush();
#endif
default:
return false;
default:
return false;
}
}
@ -544,71 +544,71 @@ bool blackboxDeviceFlushForce(void)
bool blackboxDeviceOpen(void)
{
switch (blackboxConfig()->device) {
case BLACKBOX_DEVICE_SERIAL:
{
serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_BLACKBOX);
baudRate_e baudRateIndex;
portOptions_t portOptions = SERIAL_PARITY_NO | SERIAL_NOT_INVERTED;
case BLACKBOX_DEVICE_SERIAL:
{
serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_BLACKBOX);
baudRate_e baudRateIndex;
portOptions_t portOptions = SERIAL_PARITY_NO | SERIAL_NOT_INVERTED;
if (!portConfig) {
return false;
}
blackboxPortSharing = determinePortSharing(portConfig, FUNCTION_BLACKBOX);
baudRateIndex = portConfig->blackbox_baudrateIndex;
if (baudRates[baudRateIndex] == 230400) {
/*
* OpenLog's 230400 baud rate is very inaccurate, so it requires a larger inter-character gap in
* order to maintain synchronization.
*/
portOptions |= SERIAL_STOPBITS_2;
} else {
portOptions |= SERIAL_STOPBITS_1;
}
blackboxPort = openSerialPort(portConfig->identifier, FUNCTION_BLACKBOX, NULL, baudRates[baudRateIndex],
BLACKBOX_SERIAL_PORT_MODE, portOptions);
/*
* The slowest MicroSD cards have a write latency approaching 150ms. The OpenLog's buffer is about 900
* bytes. In order for its buffer to be able to absorb this latency we must write slower than 6000 B/s.
*
* So:
* Bytes per loop iteration = floor((looptime_ns / 1000000.0) * 6000)
* = floor((looptime_ns * 6000) / 1000000.0)
* = floor((looptime_ns * 3) / 500.0)
* = (looptime_ns * 3) / 500
*/
blackboxMaxHeaderBytesPerIteration = constrain((targetPidLooptime * 3) / 500, 1, BLACKBOX_TARGET_HEADER_BUDGET_PER_ITERATION);
return blackboxPort != NULL;
}
break;
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
if (flashfsGetSize() == 0 || isBlackboxDeviceFull()) {
if (!portConfig) {
return false;
}
blackboxMaxHeaderBytesPerIteration = BLACKBOX_TARGET_HEADER_BUDGET_PER_ITERATION;
blackboxPortSharing = determinePortSharing(portConfig, FUNCTION_BLACKBOX);
baudRateIndex = portConfig->blackbox_baudrateIndex;
return true;
if (baudRates[baudRateIndex] == 230400) {
/*
* OpenLog's 230400 baud rate is very inaccurate, so it requires a larger inter-character gap in
* order to maintain synchronization.
*/
portOptions |= SERIAL_STOPBITS_2;
} else {
portOptions |= SERIAL_STOPBITS_1;
}
blackboxPort = openSerialPort(portConfig->identifier, FUNCTION_BLACKBOX, NULL, baudRates[baudRateIndex],
BLACKBOX_SERIAL_PORT_MODE, portOptions);
/*
* The slowest MicroSD cards have a write latency approaching 150ms. The OpenLog's buffer is about 900
* bytes. In order for its buffer to be able to absorb this latency we must write slower than 6000 B/s.
*
* So:
* Bytes per loop iteration = floor((looptime_ns / 1000000.0) * 6000)
* = floor((looptime_ns * 6000) / 1000000.0)
* = floor((looptime_ns * 3) / 500.0)
* = (looptime_ns * 3) / 500
*/
blackboxMaxHeaderBytesPerIteration = constrain((targetPidLooptime * 3) / 500, 1, BLACKBOX_TARGET_HEADER_BUDGET_PER_ITERATION);
return blackboxPort != NULL;
}
break;
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
if (flashfsGetSize() == 0 || isBlackboxDeviceFull()) {
return false;
}
blackboxMaxHeaderBytesPerIteration = BLACKBOX_TARGET_HEADER_BUDGET_PER_ITERATION;
return true;
break;
#endif
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
if (afatfs_getFilesystemState() == AFATFS_FILESYSTEM_STATE_FATAL || afatfs_getFilesystemState() == AFATFS_FILESYSTEM_STATE_UNKNOWN || afatfs_isFull()) {
return false;
}
case BLACKBOX_DEVICE_SDCARD:
if (afatfs_getFilesystemState() == AFATFS_FILESYSTEM_STATE_FATAL || afatfs_getFilesystemState() == AFATFS_FILESYSTEM_STATE_UNKNOWN || afatfs_isFull()) {
return false;
}
blackboxMaxHeaderBytesPerIteration = BLACKBOX_TARGET_HEADER_BUDGET_PER_ITERATION;
blackboxMaxHeaderBytesPerIteration = BLACKBOX_TARGET_HEADER_BUDGET_PER_ITERATION;
return true;
return true;
break;
#endif
default:
return false;
default:
return false;
}
}
@ -653,21 +653,21 @@ bool isBlackboxErased(void)
void blackboxDeviceClose(void)
{
switch (blackboxConfig()->device) {
case BLACKBOX_DEVICE_SERIAL:
// Since the serial port could be shared with other processes, we have to give it back here
closeSerialPort(blackboxPort);
blackboxPort = NULL;
case BLACKBOX_DEVICE_SERIAL:
// Since the serial port could be shared with other processes, we have to give it back here
closeSerialPort(blackboxPort);
blackboxPort = NULL;
/*
* Normally this would be handled by mw.c, but since we take an unknown amount
* of time to shut down asynchronously, we're the only ones that know when to call it.
*/
if (blackboxPortSharing == PORTSHARING_SHARED) {
mspSerialAllocatePorts();
}
/*
* Normally this would be handled by mw.c, but since we take an unknown amount
* of time to shut down asynchronously, we're the only ones that know when to call it.
*/
if (blackboxPortSharing == PORTSHARING_SHARED) {
mspSerialAllocatePorts();
}
break;
default:
;
default:
;
}
}
@ -728,59 +728,59 @@ static bool blackboxSDCardBeginLog()
doMore:
switch (blackboxSDCard.state) {
case BLACKBOX_SDCARD_INITIAL:
if (afatfs_getFilesystemState() == AFATFS_FILESYSTEM_STATE_READY) {
blackboxSDCard.state = BLACKBOX_SDCARD_WAITING;
case BLACKBOX_SDCARD_INITIAL:
if (afatfs_getFilesystemState() == AFATFS_FILESYSTEM_STATE_READY) {
blackboxSDCard.state = BLACKBOX_SDCARD_WAITING;
afatfs_mkdir("logs", blackboxLogDirCreated);
}
break;
afatfs_mkdir("logs", blackboxLogDirCreated);
}
break;
case BLACKBOX_SDCARD_WAITING:
// Waiting for directory entry to be created
break;
case BLACKBOX_SDCARD_WAITING:
// Waiting for directory entry to be created
break;
case BLACKBOX_SDCARD_ENUMERATE_FILES:
while (afatfs_findNext(blackboxSDCard.logDirectory, &blackboxSDCard.logDirectoryFinder, &directoryEntry) == AFATFS_OPERATION_SUCCESS) {
if (directoryEntry && !fat_isDirectoryEntryTerminator(directoryEntry)) {
// If this is a log file, parse the log number from the filename
if (strncmp(directoryEntry->filename, LOGFILE_PREFIX, strlen(LOGFILE_PREFIX)) == 0
&& strncmp(directoryEntry->filename + 8, LOGFILE_SUFFIX, strlen(LOGFILE_SUFFIX)) == 0) {
char logSequenceNumberString[6];
case BLACKBOX_SDCARD_ENUMERATE_FILES:
while (afatfs_findNext(blackboxSDCard.logDirectory, &blackboxSDCard.logDirectoryFinder, &directoryEntry) == AFATFS_OPERATION_SUCCESS) {
if (directoryEntry && !fat_isDirectoryEntryTerminator(directoryEntry)) {
// If this is a log file, parse the log number from the filename
if (strncmp(directoryEntry->filename, LOGFILE_PREFIX, strlen(LOGFILE_PREFIX)) == 0
&& strncmp(directoryEntry->filename + 8, LOGFILE_SUFFIX, strlen(LOGFILE_SUFFIX)) == 0) {
char logSequenceNumberString[6];
memcpy(logSequenceNumberString, directoryEntry->filename + 3, 5);
logSequenceNumberString[5] = '\0';
memcpy(logSequenceNumberString, directoryEntry->filename + 3, 5);
logSequenceNumberString[5] = '\0';
blackboxSDCard.largestLogFileNumber = MAX((uint32_t) atoi(logSequenceNumberString), blackboxSDCard.largestLogFileNumber);
}
} else {
// We're done checking all the files on the card, now we can create a new log file
afatfs_findLast(blackboxSDCard.logDirectory);
blackboxSDCard.state = BLACKBOX_SDCARD_CHANGE_INTO_LOG_DIRECTORY;
goto doMore;
blackboxSDCard.largestLogFileNumber = MAX((uint32_t) atoi(logSequenceNumberString), blackboxSDCard.largestLogFileNumber);
}
}
break;
} else {
// We're done checking all the files on the card, now we can create a new log file
afatfs_findLast(blackboxSDCard.logDirectory);
case BLACKBOX_SDCARD_CHANGE_INTO_LOG_DIRECTORY:
// Change into the log directory:
if (afatfs_chdir(blackboxSDCard.logDirectory)) {
// We no longer need our open handle on the log directory
afatfs_fclose(blackboxSDCard.logDirectory, NULL);
blackboxSDCard.logDirectory = NULL;
blackboxSDCard.state = BLACKBOX_SDCARD_READY_TO_CREATE_LOG;
blackboxSDCard.state = BLACKBOX_SDCARD_CHANGE_INTO_LOG_DIRECTORY;
goto doMore;
}
break;
}
break;
case BLACKBOX_SDCARD_READY_TO_CREATE_LOG:
blackboxCreateLogFile();
break;
case BLACKBOX_SDCARD_CHANGE_INTO_LOG_DIRECTORY:
// Change into the log directory:
if (afatfs_chdir(blackboxSDCard.logDirectory)) {
// We no longer need our open handle on the log directory
afatfs_fclose(blackboxSDCard.logDirectory, NULL);
blackboxSDCard.logDirectory = NULL;
case BLACKBOX_SDCARD_READY_TO_LOG:
return true; // Log has been created!
blackboxSDCard.state = BLACKBOX_SDCARD_READY_TO_CREATE_LOG;
goto doMore;
}
break;
case BLACKBOX_SDCARD_READY_TO_CREATE_LOG:
blackboxCreateLogFile();
break;
case BLACKBOX_SDCARD_READY_TO_LOG:
return true; // Log has been created!
}
// Not finished init yet
@ -798,11 +798,11 @@ bool blackboxDeviceBeginLog(void)
{
switch (blackboxConfig()->device) {
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
return blackboxSDCardBeginLog();
case BLACKBOX_DEVICE_SDCARD:
return blackboxSDCardBeginLog();
#endif
default:
return true;
default:
return true;
}
}
@ -822,42 +822,42 @@ bool blackboxDeviceEndLog(bool retainLog)
switch (blackboxConfig()->device) {
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
// Keep retrying until the close operation queues
if (
(retainLog && afatfs_fclose(blackboxSDCard.logFile, NULL))
|| (!retainLog && afatfs_funlink(blackboxSDCard.logFile, NULL))
) {
// Don't bother waiting the for the close to complete, it's queued now and will complete eventually
blackboxSDCard.logFile = NULL;
blackboxSDCard.state = BLACKBOX_SDCARD_READY_TO_CREATE_LOG;
return true;
}
return false;
#endif
default:
case BLACKBOX_DEVICE_SDCARD:
// Keep retrying until the close operation queues
if (
(retainLog && afatfs_fclose(blackboxSDCard.logFile, NULL))
|| (!retainLog && afatfs_funlink(blackboxSDCard.logFile, NULL))
) {
// Don't bother waiting the for the close to complete, it's queued now and will complete eventually
blackboxSDCard.logFile = NULL;
blackboxSDCard.state = BLACKBOX_SDCARD_READY_TO_CREATE_LOG;
return true;
}
return false;
#endif
default:
return true;
}
}
bool isBlackboxDeviceFull(void)
{
switch (blackboxConfig()->device) {
case BLACKBOX_DEVICE_SERIAL:
return false;
case BLACKBOX_DEVICE_SERIAL:
return false;
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
return flashfsIsEOF();
case BLACKBOX_DEVICE_FLASH:
return flashfsIsEOF();
#endif
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
return afatfs_isFull();
case BLACKBOX_DEVICE_SDCARD:
return afatfs_isFull();
#endif
default:
return false;
default:
return false;
}
}
@ -870,21 +870,21 @@ void blackboxReplenishHeaderBudget()
int32_t freeSpace;
switch (blackboxConfig()->device) {
case BLACKBOX_DEVICE_SERIAL:
freeSpace = serialTxBytesFree(blackboxPort);
case BLACKBOX_DEVICE_SERIAL:
freeSpace = serialTxBytesFree(blackboxPort);
break;
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
freeSpace = flashfsGetWriteBufferFreeSpace();
case BLACKBOX_DEVICE_FLASH:
freeSpace = flashfsGetWriteBufferFreeSpace();
break;
#endif
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
freeSpace = afatfs_getFreeBufferSpace();
case BLACKBOX_DEVICE_SDCARD:
freeSpace = afatfs_getFreeBufferSpace();
break;
#endif
default:
freeSpace = 0;
default:
freeSpace = 0;
}
blackboxHeaderBudget = MIN(MIN(freeSpace, blackboxHeaderBudget + blackboxMaxHeaderBytesPerIteration), BLACKBOX_MAX_ACCUMULATED_HEADER_BUDGET);
@ -916,43 +916,43 @@ blackboxBufferReserveStatus_e blackboxDeviceReserveBufferSpace(int32_t bytes)
// Handle failure:
switch (blackboxConfig()->device) {
case BLACKBOX_DEVICE_SERIAL:
/*
* One byte of the tx buffer isn't available for user data (due to its circular list implementation),
* hence the -1. Note that the USB VCP implementation doesn't use a buffer and has txBufferSize set to zero.
*/
if (blackboxPort->txBufferSize && bytes > (int32_t) blackboxPort->txBufferSize - 1) {
return BLACKBOX_RESERVE_PERMANENT_FAILURE;
}
case BLACKBOX_DEVICE_SERIAL:
/*
* One byte of the tx buffer isn't available for user data (due to its circular list implementation),
* hence the -1. Note that the USB VCP implementation doesn't use a buffer and has txBufferSize set to zero.
*/
if (blackboxPort->txBufferSize && bytes > (int32_t) blackboxPort->txBufferSize - 1) {
return BLACKBOX_RESERVE_PERMANENT_FAILURE;
}
return BLACKBOX_RESERVE_TEMPORARY_FAILURE;
return BLACKBOX_RESERVE_TEMPORARY_FAILURE;
#ifdef USE_FLASHFS
case BLACKBOX_DEVICE_FLASH:
if (bytes > (int32_t) flashfsGetWriteBufferSize()) {
return BLACKBOX_RESERVE_PERMANENT_FAILURE;
}
case BLACKBOX_DEVICE_FLASH:
if (bytes > (int32_t) flashfsGetWriteBufferSize()) {
return BLACKBOX_RESERVE_PERMANENT_FAILURE;
}
if (bytes > (int32_t) flashfsGetWriteBufferFreeSpace()) {
/*
* The write doesn't currently fit in the buffer, so try to make room for it. Our flushing here means
* that the Blackbox header writing code doesn't have to guess about the best time to ask flashfs to
* flush, and doesn't stall waiting for a flush that would otherwise not automatically be called.
*/
flashfsFlushAsync();
}
if (bytes > (int32_t) flashfsGetWriteBufferFreeSpace()) {
/*
* The write doesn't currently fit in the buffer, so try to make room for it. Our flushing here means
* that the Blackbox header writing code doesn't have to guess about the best time to ask flashfs to
* flush, and doesn't stall waiting for a flush that would otherwise not automatically be called.
*/
flashfsFlushAsync();
}
return BLACKBOX_RESERVE_TEMPORARY_FAILURE;
return BLACKBOX_RESERVE_TEMPORARY_FAILURE;
#endif
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
// Assume that all writes will fit in the SDCard's buffers
return BLACKBOX_RESERVE_TEMPORARY_FAILURE;
case BLACKBOX_DEVICE_SDCARD:
// Assume that all writes will fit in the SDCard's buffers
return BLACKBOX_RESERVE_TEMPORARY_FAILURE;
#endif
default:
return BLACKBOX_RESERVE_PERMANENT_FAILURE;
default:
return BLACKBOX_RESERVE_PERMANENT_FAILURE;
}
}