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:
parent
dc5671f34c
commit
ec5816eae0
2 changed files with 6 additions and 19 deletions
|
@ -166,10 +166,13 @@ static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
|||
return;
|
||||
}
|
||||
|
||||
timeDelta_t refreshRateUs;
|
||||
timeDelta_t frameAgeUs;
|
||||
timeDelta_t refreshRateUs = rxGetFrameDelta(&frameAgeUs);
|
||||
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;
|
||||
currentRxRefreshRate = constrain(refreshRateUs, 1000, 30000);
|
||||
isRXDataNew = true;
|
||||
|
|
|
@ -130,7 +130,6 @@ static const smartPortPayload_t emptySmartPortFrame = { .frameId = 0, .valueId =
|
|||
typedef struct fportBuffer_s {
|
||||
uint8_t data[BUFFER_SIZE];
|
||||
uint8_t length;
|
||||
timeUs_t frameStartTimeUsOrZero;
|
||||
timeUs_t frameStartTimeUs;
|
||||
} fportBuffer_t;
|
||||
|
||||
|
@ -152,7 +151,6 @@ static serialPort_t *fportPort;
|
|||
static bool telemetryEnabled = false;
|
||||
#endif
|
||||
|
||||
static timeUs_t lastRcFrameTimeUsOrZero = 0;
|
||||
static timeUs_t lastRcFrameTimeUs = 0;
|
||||
|
||||
static void reportFrameError(uint8_t errorReason) {
|
||||
|
@ -182,7 +180,6 @@ static void fportDataReceive(uint16_t c, void *data)
|
|||
reportFrameError(DEBUG_FPORT_ERROR_TIMEOUT);
|
||||
|
||||
framePosition = 0;
|
||||
rxBuffer[rxBufferWriteIndex].frameStartTimeUsOrZero = 0;
|
||||
}
|
||||
|
||||
uint8_t val = (uint8_t)c;
|
||||
|
@ -210,14 +207,11 @@ static void fportDataReceive(uint16_t c, void *data)
|
|||
frameStartAt = currentTimeUs;
|
||||
framePosition = 1;
|
||||
|
||||
rxBuffer[rxBufferWriteIndex].frameStartTimeUsOrZero = currentTimeUs;
|
||||
rxBuffer[rxBufferWriteIndex].frameStartTimeUs = currentTimeUs;
|
||||
} else if (framePosition > 0) {
|
||||
if (framePosition >= BUFFER_SIZE + 1) {
|
||||
framePosition = 0;
|
||||
|
||||
rxBuffer[rxBufferWriteIndex].frameStartTimeUsOrZero = 0;
|
||||
|
||||
reportFrameError(DEBUG_FPORT_ERROR_OVERSIZE);
|
||||
} else {
|
||||
if (escapedCharacter) {
|
||||
|
@ -299,7 +293,6 @@ static uint8_t fportFrameStatus(rxRuntimeState_t *rxRuntimeState)
|
|||
lastRcFrameReceivedMs = millis();
|
||||
|
||||
if (!(result & (RX_FRAME_FAILSAFE | RX_FRAME_DROPPED))) {
|
||||
lastRcFrameTimeUsOrZero = rxBuffer[rxBufferReadIndex].frameStartTimeUsOrZero;
|
||||
lastRcFrameTimeUs = rxBuffer[rxBufferReadIndex].frameStartTimeUs;
|
||||
}
|
||||
}
|
||||
|
@ -406,14 +399,6 @@ static bool fportProcessFrame(const rxRuntimeState_t *rxRuntimeState)
|
|||
return true;
|
||||
}
|
||||
|
||||
static timeUs_t fportFrameTimeUsOrZero(void)
|
||||
{
|
||||
const timeUs_t result = lastRcFrameTimeUsOrZero;
|
||||
lastRcFrameTimeUsOrZero = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static timeUs_t fportFrameTimeUs(void)
|
||||
{
|
||||
return lastRcFrameTimeUs;
|
||||
|
@ -430,7 +415,6 @@ bool fportRxInit(const rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState)
|
|||
|
||||
rxRuntimeState->rcFrameStatusFn = fportFrameStatus;
|
||||
rxRuntimeState->rcProcessFrameFn = fportProcessFrame;
|
||||
rxRuntimeState->rcFrameTimeUsOrZeroFn = fportFrameTimeUsOrZero;
|
||||
rxRuntimeState->rcFrameTimeUsFn = fportFrameTimeUs;
|
||||
|
||||
const serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_RX_SERIAL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue