Add protocol level receiver frame rate measurement for Spektrum

This commit is contained in:
Bruce Luckcuck 2019-11-21 15:59:10 -05:00
parent 05418297b2
commit cad5bdd9f1
1 changed files with 14 additions and 4 deletions

View File

@ -76,17 +76,19 @@ static uint8_t telemetryBuf[SRXL_FRAME_SIZE_MAX];
static uint8_t telemetryBufLen = 0;
#endif
static timeDelta_t lastFrameDelta = 0;
// Receive ISR callback
static void spektrumDataReceive(uint16_t c, void *data)
{
UNUSED(data);
uint32_t spekTime, spekTimeInterval;
static uint32_t spekTimeLast = 0;
static timeUs_t spekTimeLast = 0;
static uint8_t spekFramePosition = 0;
static timeUs_t lastFrameCompleteTimeUs = 0;
spekTime = micros();
spekTimeInterval = spekTime - spekTimeLast;
const timeUs_t spekTime = microsISR();
const timeUs_t spekTimeInterval = cmpTimeUs(spekTime, spekTimeLast);
spekTimeLast = spekTime;
if (spekTimeInterval > SPEKTRUM_NEEDED_FRAME_INTERVAL) {
@ -98,6 +100,8 @@ static void spektrumDataReceive(uint16_t c, void *data)
if (spekFramePosition < SPEK_FRAME_SIZE) {
rcFrameComplete = false;
} else {
lastFrameDelta = cmpTimeUs(spekTime, lastFrameCompleteTimeUs);
lastFrameCompleteTimeUs = spekTime;
rcFrameComplete = true;
}
}
@ -341,6 +345,11 @@ void srxlRxWriteTelemetryData(const void *data, int len)
}
#endif
static timeDelta_t spektrumFrameDelta(void)
{
return lastFrameDelta;
}
bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState)
{
rxRuntimeStatePtr = rxRuntimeState;
@ -388,6 +397,7 @@ bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeState_t *rxRuntimeState)
rxRuntimeState->rcReadRawFn = spektrumReadRawRC;
rxRuntimeState->rcFrameStatusFn = spektrumFrameStatus;
rxRuntimeState->rcFrameDeltaFn = spektrumFrameDelta;
#if defined(USE_TELEMETRY_SRXL)
rxRuntimeState->rcProcessFrameFn = spektrumProcessFrame;
#endif