mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 15:25:36 +03:00
Split rx processing into three states to eliminate cycle time jitter
Allow tasks with state machines to control which state determines task duration Fix unit tests
This commit is contained in:
parent
bc4372588b
commit
25fcacf4c5
11 changed files with 89 additions and 20 deletions
|
@ -158,23 +158,54 @@ static void taskUpdateAccelerometer(timeUs_t currentTimeUs)
|
|||
}
|
||||
#endif
|
||||
|
||||
static enum {
|
||||
CHECK, PROCESS, MODES, UPDATE
|
||||
} rxState = CHECK;
|
||||
|
||||
bool taskUpdateRxMainInProgress()
|
||||
{
|
||||
return (rxState != CHECK);
|
||||
}
|
||||
|
||||
static void taskUpdateRxMain(timeUs_t currentTimeUs)
|
||||
{
|
||||
if (!processRx(currentTimeUs)) {
|
||||
return;
|
||||
}
|
||||
switch (rxState) {
|
||||
default:
|
||||
case CHECK:
|
||||
ignoreTaskTime();
|
||||
rxState = PROCESS;
|
||||
break;
|
||||
|
||||
// updateRcCommands sets rcCommand, which is needed by updateAltHoldState and updateSonarAltHoldState
|
||||
updateRcCommands();
|
||||
updateArmingStatus();
|
||||
case PROCESS:
|
||||
ignoreTaskTime();
|
||||
if (!processRx(currentTimeUs)) {
|
||||
break;
|
||||
}
|
||||
rxState = MODES;
|
||||
break;
|
||||
|
||||
case MODES:
|
||||
processRxModes(currentTimeUs);
|
||||
rxState = UPDATE;
|
||||
break;
|
||||
|
||||
case UPDATE:
|
||||
ignoreTaskTime();
|
||||
// updateRcCommands sets rcCommand, which is needed by updateAltHoldState and updateSonarAltHoldState
|
||||
updateRcCommands();
|
||||
updateArmingStatus();
|
||||
|
||||
#ifdef USE_USB_CDC_HID
|
||||
if (!ARMING_FLAG(ARMED)) {
|
||||
sendRcDataToHid();
|
||||
}
|
||||
if (!ARMING_FLAG(ARMED)) {
|
||||
sendRcDataToHid();
|
||||
}
|
||||
#endif
|
||||
rxState = CHECK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_BARO
|
||||
static void taskUpdateBaro(timeUs_t currentTimeUs)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue