Skip to content

Commit

Permalink
Merge pull request #3098 from hydra/bf-merges-20200603
Browse files Browse the repository at this point in the history
Bf merges 20200603
  • Loading branch information
hydra committed Jun 3, 2020
2 parents a361279 + 0b39296 commit 2663768
Show file tree
Hide file tree
Showing 19 changed files with 183 additions and 120 deletions.
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -690,6 +690,10 @@ test junittest test-all test-representative:
test_help:
$(V0) cd src/test && $(MAKE) help

## test_versions : print the compiler versions used for the test suite
test_versions:
$(V0) cd src/test && $(MAKE) versions

## test_% : run test 'test_%' from the test suite
test_%:
$(V0) cd src/test && $(MAKE) $@
Expand Down
28 changes: 19 additions & 9 deletions src/main/blackbox/blackbox.c
Expand Up @@ -42,17 +42,13 @@
#include "common/time.h"
#include "common/utils.h"

#include "config/config.h"
#include "config/feature.h"
#include "pg/pg.h"
#include "pg/pg_ids.h"
#include "pg/motor.h"
#include "pg/rx.h"

#include "drivers/compass/compass.h"
#include "drivers/sensor.h"
#include "drivers/time.h"

#include "config/config.h"
#include "fc/board_info.h"
#include "fc/controlrate_profile.h"
#include "fc/rc.h"
Expand All @@ -70,6 +66,11 @@
#include "io/gps.h"
#include "io/serial.h"

#include "pg/pg.h"
#include "pg/pg_ids.h"
#include "pg/motor.h"
#include "pg/rx.h"

#include "rx/rx.h"

#include "sensors/acceleration.h"
Expand Down Expand Up @@ -281,6 +282,7 @@ typedef enum BlackboxState {
BLACKBOX_STATE_SEND_GPS_G_HEADER,
BLACKBOX_STATE_SEND_SLOW_HEADER,
BLACKBOX_STATE_SEND_SYSINFO,
BLACKBOX_STATE_CACHE_FLUSH,
BLACKBOX_STATE_PAUSED,
BLACKBOX_STATE_RUNNING,
BLACKBOX_STATE_SHUTTING_DOWN,
Expand Down Expand Up @@ -1608,6 +1610,8 @@ STATIC_UNIT_TESTED void blackboxLogIteration(timeUs_t currentTimeUs)
*/
void blackboxUpdate(timeUs_t currentTimeUs)
{
static BlackboxState cacheFlushNextState;

switch (blackboxState) {
case BLACKBOX_STATE_STOPPED:
if (ARMING_FLAG(ARMED)) {
Expand Down Expand Up @@ -1681,7 +1685,8 @@ void blackboxUpdate(timeUs_t currentTimeUs)
//On entry of this state, xmitState.headerIndex is 0 and xmitState.u.fieldIndex is -1
if (!sendFieldDefinition('S', 0, blackboxSlowFields, blackboxSlowFields + 1, ARRAYLEN(blackboxSlowFields),
NULL, NULL)) {
blackboxSetState(BLACKBOX_STATE_SEND_SYSINFO);
cacheFlushNextState = BLACKBOX_STATE_SEND_SYSINFO;
blackboxSetState(BLACKBOX_STATE_CACHE_FLUSH);
}
break;
case BLACKBOX_STATE_SEND_SYSINFO:
Expand All @@ -1695,9 +1700,14 @@ void blackboxUpdate(timeUs_t currentTimeUs)
* (overflowing circular buffers causes all data to be discarded, so the first few logged iterations
* could wipe out the end of the header if we weren't careful)
*/
if (blackboxDeviceFlushForce()) {
blackboxSetState(BLACKBOX_STATE_RUNNING);
}
cacheFlushNextState = BLACKBOX_STATE_RUNNING;
blackboxSetState(BLACKBOX_STATE_CACHE_FLUSH);
}
break;
case BLACKBOX_STATE_CACHE_FLUSH:
// Flush the cache and wait until all possible entries have been written to the media
if (blackboxDeviceFlushForceComplete()) {
blackboxSetState(cacheFlushNextState);
}
break;
case BLACKBOX_STATE_PAUSED:
Expand Down
28 changes: 25 additions & 3 deletions src/main/blackbox/blackbox_io.c
Expand Up @@ -242,9 +242,11 @@ bool blackboxDeviceFlushForce(void)

#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!
*/
// 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!
// However the "flush" only queues one dirty sector each time and the process is asynchronous. So after
// the last dirty sector is queued the flush returns true even though the sector may not actually have
// been physically written to the SD card yet.
return afatfs_flush();
#endif // USE_SDCARD

Expand All @@ -253,6 +255,26 @@ bool blackboxDeviceFlushForce(void)
}
}

// Flush the blackbox device and only return true if sync is actually complete.
// Primarily to ensure the async operations of SD card sector writes complete thus freeing the cache entries.
bool blackboxDeviceFlushForceComplete(void)
{
switch (blackboxConfig()->device) {
#ifdef USE_SDCARD
case BLACKBOX_DEVICE_SDCARD:
if (afatfs_sectorCacheInSync()) {
return true;
} else {
blackboxDeviceFlushForce();
return false;
}
#endif // USE_SDCARD

default:
return blackboxDeviceFlushForce();
}
}

/**
* Attempt to open the logging device. Returns true if successful.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/blackbox/blackbox_io.h
Expand Up @@ -46,6 +46,8 @@ int blackboxWriteString(const char *s);

void blackboxDeviceFlush(void);
bool blackboxDeviceFlushForce(void);
bool blackboxDeviceFlushForceComplete(void);

bool blackboxDeviceOpen(void);
void blackboxDeviceClose(void);

Expand Down
38 changes: 22 additions & 16 deletions src/main/cli/cli.c
Expand Up @@ -228,12 +228,15 @@ static char cliBufferTemp[CLI_IN_BUFFER_SIZE];
#define CUSTOM_DEFAULTS_CHANGESET_ID_PREFIX ", version: "
#define CUSTOM_DEFAULTS_DATE_PREFIX ", date: "

#define MAX_CHANGESET_ID_LENGTH 8
#define MAX_DATE_LENGTH 20

static bool customDefaultsHeaderParsed = false;
static bool customDefaultsFound = false;
static char customDefaultsManufacturerId[MAX_MANUFACTURER_ID_LENGTH + 1] = { 0 };
static char customDefaultsBoardName[MAX_BOARD_NAME_LENGTH + 1] = { 0 };
static char customDefaultsChangesetId[9] = { 0 };
static char customDefaultsDate[21] = { 0 };
static char customDefaultsChangesetId[MAX_CHANGESET_ID_LENGTH + 1] = { 0 };
static char customDefaultsDate[MAX_DATE_LENGTH + 1] = { 0 };
#endif

#if defined(USE_CUSTOM_DEFAULTS_ADDRESS)
Expand Down Expand Up @@ -4252,7 +4255,7 @@ static bool customDefaultsHasNext(const char *customDefaultsPtr)
return *customDefaultsPtr && *customDefaultsPtr != 0xFF && customDefaultsPtr < customDefaultsEnd;
}

static const char *parseCustomDefaultsHeaderElement(char *dest, const char *customDefaultsPtr, const char *prefix, char terminator)
static const char *parseCustomDefaultsHeaderElement(char *dest, const char *customDefaultsPtr, const char *prefix, const char terminator, const unsigned maxLength)
{
char *endPtr = NULL;
unsigned len = strlen(prefix);
Expand All @@ -4263,7 +4266,7 @@ static const char *parseCustomDefaultsHeaderElement(char *dest, const char *cust

if (endPtr && customDefaultsHasNext(endPtr)) {
len = endPtr - customDefaultsPtr;
memcpy(dest, customDefaultsPtr, len);
memcpy(dest, customDefaultsPtr, MIN(len, maxLength));

customDefaultsPtr += len;

Expand All @@ -4284,13 +4287,13 @@ static void parseCustomDefaultsHeader(void)
customDefaultsPtr++;
}

customDefaultsPtr = parseCustomDefaultsHeaderElement(customDefaultsManufacturerId, customDefaultsPtr, CUSTOM_DEFAULTS_MANUFACTURER_ID_PREFIX, CUSTOM_DEFAULTS_BOARD_NAME_PREFIX[0]);
customDefaultsPtr = parseCustomDefaultsHeaderElement(customDefaultsManufacturerId, customDefaultsPtr, CUSTOM_DEFAULTS_MANUFACTURER_ID_PREFIX, CUSTOM_DEFAULTS_BOARD_NAME_PREFIX[0], MAX_MANUFACTURER_ID_LENGTH);

customDefaultsPtr = parseCustomDefaultsHeaderElement(customDefaultsBoardName, customDefaultsPtr, CUSTOM_DEFAULTS_BOARD_NAME_PREFIX, CUSTOM_DEFAULTS_CHANGESET_ID_PREFIX[0]);
customDefaultsPtr = parseCustomDefaultsHeaderElement(customDefaultsBoardName, customDefaultsPtr, CUSTOM_DEFAULTS_BOARD_NAME_PREFIX, CUSTOM_DEFAULTS_CHANGESET_ID_PREFIX[0], MAX_BOARD_NAME_LENGTH);

customDefaultsPtr = parseCustomDefaultsHeaderElement(customDefaultsChangesetId, customDefaultsPtr, CUSTOM_DEFAULTS_CHANGESET_ID_PREFIX, CUSTOM_DEFAULTS_DATE_PREFIX[0]);
customDefaultsPtr = parseCustomDefaultsHeaderElement(customDefaultsChangesetId, customDefaultsPtr, CUSTOM_DEFAULTS_CHANGESET_ID_PREFIX, CUSTOM_DEFAULTS_DATE_PREFIX[0], MAX_CHANGESET_ID_LENGTH);

customDefaultsPtr = parseCustomDefaultsHeaderElement(customDefaultsDate, customDefaultsPtr, CUSTOM_DEFAULTS_DATE_PREFIX, '\n');
customDefaultsPtr = parseCustomDefaultsHeaderElement(customDefaultsDate, customDefaultsPtr, CUSTOM_DEFAULTS_DATE_PREFIX, '\n', MAX_DATE_LENGTH);
}

customDefaultsHeaderParsed = true;
Expand Down Expand Up @@ -5201,24 +5204,27 @@ static void resourceCheck(uint8_t resourceIndex, uint8_t index, ioTag_t newTag)
}
}

static bool strToPin(char *pch, ioTag_t *tag)
static bool strToPin(char *ptr, ioTag_t *tag)
{
if (strcasecmp(pch, "NONE") == 0) {
if (strcasecmp(ptr, "NONE") == 0) {
*tag = IO_TAG_NONE;

return true;
} else {
unsigned pin = 0;
unsigned port = (*pch >= 'a') ? *pch - 'a' : *pch - 'A';

const unsigned port = (*ptr >= 'a') ? *ptr - 'a' : *ptr - 'A';
if (port < 8) {
pch++;
pin = atoi(pch);
if (pin < 16) {
ptr++;

char *end;
const long pin = strtol(ptr, &end, 10);
if (end != ptr && pin >= 0 && pin < 16) {
*tag = DEFIO_TAG_MAKE(port, pin);

return true;
}
}
}

return false;
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/config/config.c
Expand Up @@ -60,6 +60,8 @@
#include "io/serial.h"
#include "io/vtx.h"

#include "msp/msp_box.h"

#include "osd/osd.h"

#include "pg/adc.h"
Expand Down Expand Up @@ -181,6 +183,8 @@ static void activateConfig(void)
#if defined(USE_LED_STRIP_STATUS_MODE)
reevaluateLedConfig();
#endif

initActiveBoxIds();
}

static void adjustFilterLimit(uint16_t *parm, uint16_t resetValue)
Expand Down

0 comments on commit 2663768

Please sign in to comment.