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

Switched FPort to use RX frame deltas for refresh rate calculate.

This commit is contained in:
mikeller 2020-03-06 09:34:33 +13:00
parent dc5671f34c
commit ec5816eae0
2 changed files with 6 additions and 19 deletions

View file

@ -166,9 +166,12 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs)
return; return;
} }
timeDelta_t refreshRateUs; timeDelta_t frameAgeUs;
if (!rxTryGetFrameDeltaOrZero(&refreshRateUs)) { timeDelta_t refreshRateUs = rxGetFrameDelta(&frameAgeUs);
refreshRateUs = cmpTimeUs(currentTimeUs, lastRxTimeUs); // calculate a delta here if not supplied by the protocol if (!refreshRateUs || cmpTimeUs(currentTimeUs, lastRxTimeUs) <= frameAgeUs) {
if (!rxTryGetFrameDeltaOrZero(&refreshRateUs)) {
refreshRateUs = cmpTimeUs(currentTimeUs, lastRxTimeUs); // calculate a delta here if not supplied by the protocol
}
} }
lastRxTimeUs = currentTimeUs; lastRxTimeUs = currentTimeUs;
currentRxRefreshRate = constrain(refreshRateUs, 1000, 30000); currentRxRefreshRate = constrain(refreshRateUs, 1000, 30000);

View file

@ -130,7 +130,6 @@ static const smartPortPayload_t emptySmartPortFrame = { .frameId = 0, .valueId =
typedef struct fportBuffer_s { typedef struct fportBuffer_s {
uint8_t data[BUFFER_SIZE]; uint8_t data[BUFFER_SIZE];
uint8_t length; uint8_t length;
timeUs_t frameStartTimeUsOrZero;
timeUs_t frameStartTimeUs; timeUs_t frameStartTimeUs;
} fportBuffer_t; } fportBuffer_t;
@ -152,7 +151,6 @@ static serialPort_t *fportPort;
static bool telemetryEnabled = false; static bool telemetryEnabled = false;
#endif #endif
static timeUs_t lastRcFrameTimeUsOrZero = 0;
static timeUs_t lastRcFrameTimeUs = 0; static timeUs_t lastRcFrameTimeUs = 0;
static void reportFrameError(uint8_t errorReason) { static void reportFrameError(uint8_t errorReason) {
@ -182,7 +180,6 @@ static void fportDataReceive(uint16_t c, void *data)
reportFrameError(DEBUG_FPORT_ERROR_TIMEOUT); reportFrameError(DEBUG_FPORT_ERROR_TIMEOUT);
framePosition = 0; framePosition = 0;
rxBuffer[rxBufferWriteIndex].frameStartTimeUsOrZero = 0;
} }
uint8_t val = (uint8_t)c; uint8_t val = (uint8_t)c;
@ -210,14 +207,11 @@ static void fportDataReceive(uint16_t c, void *data)
frameStartAt = currentTimeUs; frameStartAt = currentTimeUs;
framePosition = 1; framePosition = 1;
rxBuffer[rxBufferWriteIndex].frameStartTimeUsOrZero = currentTimeUs;
rxBuffer[rxBufferWriteIndex].frameStartTimeUs = currentTimeUs; rxBuffer[rxBufferWriteIndex].frameStartTimeUs = currentTimeUs;
} else if (framePosition > 0) { } else if (framePosition > 0) {
if (framePosition >= BUFFER_SIZE + 1) { if (framePosition >= BUFFER_SIZE + 1) {
framePosition = 0; framePosition = 0;
rxBuffer[rxBufferWriteIndex].frameStartTimeUsOrZero = 0;
reportFrameError(DEBUG_FPORT_ERROR_OVERSIZE); reportFrameError(DEBUG_FPORT_ERROR_OVERSIZE);
} else { } else {
if (escapedCharacter) { if (escapedCharacter) {
@ -299,7 +293,6 @@ static uint8_t fportFrameStatus(rxRuntimeState_t *rxRuntimeState)
lastRcFrameReceivedMs = millis(); lastRcFrameReceivedMs = millis();
if (!(result & (RX_FRAME_FAILSAFE | RX_FRAME_DROPPED))) { if (!(result & (RX_FRAME_FAILSAFE | RX_FRAME_DROPPED))) {
lastRcFrameTimeUsOrZero = rxBuffer[rxBufferReadIndex].frameStartTimeUsOrZero;
lastRcFrameTimeUs = rxBuffer[rxBufferReadIndex].frameStartTimeUs; lastRcFrameTimeUs = rxBuffer[rxBufferReadIndex].frameStartTimeUs;
} }
} }
@ -406,14 +399,6 @@ static bool fportProcessFrame(const rxRuntimeState_t *rxRuntimeState)
return true; return true;
} }
static timeUs_t fportFrameTimeUsOrZero(void)
{
const timeUs_t result = lastRcFrameTimeUsOrZero;
lastRcFrameTimeUsOrZero = 0;
return result;
}
static timeUs_t fportFrameTimeUs(void) static timeUs_t fportFrameTimeUs(void)
{ {
return lastRcFrameTimeUs; return lastRcFrameTimeUs;
@ -430,7 +415,6 @@ bool fportRxInit(const rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState)
rxRuntimeState->rcFrameStatusFn = fportFrameStatus; rxRuntimeState->rcFrameStatusFn = fportFrameStatus;
rxRuntimeState->rcProcessFrameFn = fportProcessFrame; rxRuntimeState->rcProcessFrameFn = fportProcessFrame;
rxRuntimeState->rcFrameTimeUsOrZeroFn = fportFrameTimeUsOrZero;
rxRuntimeState->rcFrameTimeUsFn = fportFrameTimeUs; rxRuntimeState->rcFrameTimeUsFn = fportFrameTimeUs;
const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_RX_SERIAL); const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_RX_SERIAL);