Fixed hanging on 'defaults nosave' when RX_SERIAL is enabled. (#8946)

Fixed hanging on 'defaults nosave' when RX_SERIAL is enabled.
This commit is contained in:
Michael Keller 2019-09-26 00:29:15 +12:00 committed by GitHub
commit be4db4cfa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 128 additions and 58 deletions

View File

@ -3335,8 +3335,13 @@ static void cliBeeper(char *cmdline)
#if defined(USE_RX_SPI) || defined (USE_SERIALRX_SRXL2) #if defined(USE_RX_SPI) || defined (USE_SERIALRX_SRXL2)
void cliRxBind(char *cmdline){ void cliRxBind(char *cmdline){
UNUSED(cmdline); UNUSED(cmdline);
if (featureIsEnabled(FEATURE_RX_SERIAL)) { switch (rxRuntimeConfig.rxProvider) {
switch (rxConfig()->serialrx_provider) { default:
cliPrint("Not supported.");
break;
case RX_PROVIDER_SERIAL:
switch (rxRuntimeConfig.serialrxProvider) {
default: default:
cliPrint("Not supported."); cliPrint("Not supported.");
break; break;
@ -3347,9 +3352,10 @@ void cliRxBind(char *cmdline){
break; break;
#endif #endif
} }
}
break;
#if defined(USE_RX_SPI) #if defined(USE_RX_SPI)
else if (featureIsEnabled(FEATURE_RX_SPI)) { case RX_PROVIDER_SPI:
switch (rxSpiConfig()->rx_spi_protocol) { switch (rxSpiConfig()->rx_spi_protocol) {
default: default:
cliPrint("Not supported."); cliPrint("Not supported.");
@ -3380,8 +3386,9 @@ void cliRxBind(char *cmdline){
#endif #endif
} }
} break;
#endif #endif
}
} }
#endif #endif

View File

@ -293,10 +293,10 @@ void fcTasksInit(void)
#ifdef USE_TELEMETRY #ifdef USE_TELEMETRY
if (featureIsEnabled(FEATURE_TELEMETRY)) { if (featureIsEnabled(FEATURE_TELEMETRY)) {
setTaskEnabled(TASK_TELEMETRY, true); setTaskEnabled(TASK_TELEMETRY, true);
if (rxConfig()->serialrx_provider == SERIALRX_JETIEXBUS) { if (rxRuntimeConfig.serialrxProvider == SERIALRX_JETIEXBUS) {
// Reschedule telemetry to 500hz for Jeti Exbus // Reschedule telemetry to 500hz for Jeti Exbus
rescheduleTask(TASK_TELEMETRY, TASK_PERIOD_HZ(500)); rescheduleTask(TASK_TELEMETRY, TASK_PERIOD_HZ(500));
} else if (rxConfig()->serialrx_provider == SERIALRX_CRSF) { } else if (rxRuntimeConfig.serialrxProvider == SERIALRX_CRSF) {
// Reschedule telemetry to 500hz, 2ms for CRSF // Reschedule telemetry to 500hz, 2ms for CRSF
rescheduleTask(TASK_TELEMETRY, TASK_PERIOD_HZ(500)); rescheduleTask(TASK_TELEMETRY, TASK_PERIOD_HZ(500));
} }

View File

@ -60,12 +60,20 @@ void rxPwmInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
rxRuntimeConfig->rxRefreshRate = 20000; rxRuntimeConfig->rxRefreshRate = 20000;
// configure PWM/CPPM read function and max number of channels. serial rx below will override both of these, if enabled // configure PWM/CPPM read function and max number of channels. serial rx below will override both of these, if enabled
if (featureIsEnabled(FEATURE_RX_PARALLEL_PWM)) { switch (rxRuntimeConfig->rxProvider) {
default:
break;
case RX_PROVIDER_PARALLEL_PWM:
rxRuntimeConfig->channelCount = MAX_SUPPORTED_RC_PARALLEL_PWM_CHANNEL_COUNT; rxRuntimeConfig->channelCount = MAX_SUPPORTED_RC_PARALLEL_PWM_CHANNEL_COUNT;
rxRuntimeConfig->rcReadRawFn = pwmReadRawRC; rxRuntimeConfig->rcReadRawFn = pwmReadRawRC;
} else if (featureIsEnabled(FEATURE_RX_PPM)) {
break;
case RX_PROVIDER_PPM:
rxRuntimeConfig->channelCount = MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT; rxRuntimeConfig->channelCount = MAX_SUPPORTED_RC_PPM_CHANNEL_COUNT;
rxRuntimeConfig->rcReadRawFn = ppmReadRawRC; rxRuntimeConfig->rcReadRawFn = ppmReadRawRC;
break;
} }
} }
#endif #endif

View File

@ -180,10 +180,10 @@ STATIC_UNIT_TESTED bool isPulseValid(uint16_t pulseDuration)
} }
#ifdef USE_SERIAL_RX #ifdef USE_SERIAL_RX
bool serialRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig) static bool serialRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
{ {
bool enabled = false; bool enabled = false;
switch (rxConfig->serialrx_provider) { switch (rxRuntimeConfig->serialrxProvider) {
#ifdef USE_SERIALRX_SRXL2 #ifdef USE_SERIALRX_SRXL2
case SERIALRX_SRXL2: case SERIALRX_SRXL2:
enabled = srxl2RxInit(rxConfig, rxRuntimeConfig); enabled = srxl2RxInit(rxConfig, rxRuntimeConfig);
@ -252,6 +252,20 @@ bool serialRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
void rxInit(void) void rxInit(void)
{ {
if (featureIsEnabled(FEATURE_RX_PARALLEL_PWM)) {
rxRuntimeConfig.rxProvider = RX_PROVIDER_PARALLEL_PWM;
} else if (featureIsEnabled(FEATURE_RX_PPM)) {
rxRuntimeConfig.rxProvider = RX_PROVIDER_PPM;
} else if (featureIsEnabled(FEATURE_RX_SERIAL)) {
rxRuntimeConfig.rxProvider = RX_PROVIDER_SERIAL;
} else if (featureIsEnabled(FEATURE_RX_MSP)) {
rxRuntimeConfig.rxProvider = RX_PROVIDER_MSP;
} else if (featureIsEnabled(FEATURE_RX_SPI)) {
rxRuntimeConfig.rxProvider = RX_PROVIDER_SPI;
} else {
rxRuntimeConfig.rxProvider = RX_PROVIDER_NONE;
}
rxRuntimeConfig.serialrxProvider = rxConfig()->serialrx_provider;
rxRuntimeConfig.rcReadRawFn = nullReadRawRC; rxRuntimeConfig.rcReadRawFn = nullReadRawRC;
rxRuntimeConfig.rcFrameStatusFn = nullFrameStatus; rxRuntimeConfig.rcFrameStatusFn = nullFrameStatus;
rxRuntimeConfig.rcProcessFrameFn = nullProcessFrame; rxRuntimeConfig.rcProcessFrameFn = nullProcessFrame;
@ -282,38 +296,52 @@ void rxInit(void)
} }
} }
switch (rxRuntimeConfig.rxProvider) {
default:
break;
#ifdef USE_SERIAL_RX #ifdef USE_SERIAL_RX
if (featureIsEnabled(FEATURE_RX_SERIAL)) { case RX_PROVIDER_SERIAL:
{
const bool enabled = serialRxInit(rxConfig(), &rxRuntimeConfig); const bool enabled = serialRxInit(rxConfig(), &rxRuntimeConfig);
if (!enabled) { if (!enabled) {
rxRuntimeConfig.rcReadRawFn = nullReadRawRC; rxRuntimeConfig.rcReadRawFn = nullReadRawRC;
rxRuntimeConfig.rcFrameStatusFn = nullFrameStatus; rxRuntimeConfig.rcFrameStatusFn = nullFrameStatus;
} }
} }
break;
#endif #endif
#ifdef USE_RX_MSP #ifdef USE_RX_MSP
if (featureIsEnabled(FEATURE_RX_MSP)) { case RX_PROVIDER_MSP:
rxMspInit(rxConfig(), &rxRuntimeConfig); rxMspInit(rxConfig(), &rxRuntimeConfig);
needRxSignalMaxDelayUs = DELAY_5_HZ; needRxSignalMaxDelayUs = DELAY_5_HZ;
}
break;
#endif #endif
#ifdef USE_RX_SPI #ifdef USE_RX_SPI
if (featureIsEnabled(FEATURE_RX_SPI)) { case RX_PROVIDER_SPI:
{
const bool enabled = rxSpiInit(rxSpiConfig(), &rxRuntimeConfig); const bool enabled = rxSpiInit(rxSpiConfig(), &rxRuntimeConfig);
if (!enabled) { if (!enabled) {
rxRuntimeConfig.rcReadRawFn = nullReadRawRC; rxRuntimeConfig.rcReadRawFn = nullReadRawRC;
rxRuntimeConfig.rcFrameStatusFn = nullFrameStatus; rxRuntimeConfig.rcFrameStatusFn = nullFrameStatus;
} }
} }
break;
#endif #endif
#if defined(USE_PWM) || defined(USE_PPM) #if defined(USE_PWM) || defined(USE_PPM)
if (featureIsEnabled(FEATURE_RX_PPM | FEATURE_RX_PARALLEL_PWM)) { case RX_PROVIDER_PPM:
case RX_PROVIDER_PARALLEL_PWM:
rxPwmInit(rxConfig(), &rxRuntimeConfig); rxPwmInit(rxConfig(), &rxRuntimeConfig);
}
break;
#endif #endif
}
#if defined(USE_ADC) #if defined(USE_ADC)
if (featureIsEnabled(FEATURE_RSSI_ADC)) { if (featureIsEnabled(FEATURE_RSSI_ADC)) {
@ -343,7 +371,7 @@ bool rxAreFlightChannelsValid(void)
void suspendRxPwmPpmSignal(void) void suspendRxPwmPpmSignal(void)
{ {
#if defined(USE_PWM) || defined(USE_PPM) #if defined(USE_PWM) || defined(USE_PPM)
if (featureIsEnabled(FEATURE_RX_PARALLEL_PWM | FEATURE_RX_PPM)) { if (rxRuntimeConfig.rxProvider == RX_PROVIDER_PARALLEL_PWM || rxRuntimeConfig.rxProvider == RX_PROVIDER_PPM) {
suspendRxSignalUntil = micros() + SKIP_RC_ON_SUSPEND_PERIOD; suspendRxSignalUntil = micros() + SKIP_RC_ON_SUSPEND_PERIOD;
skipRxSamples = SKIP_RC_SAMPLES_ON_RESUME; skipRxSamples = SKIP_RC_SAMPLES_ON_RESUME;
failsafeOnRxSuspend(SKIP_RC_ON_SUSPEND_PERIOD); failsafeOnRxSuspend(SKIP_RC_ON_SUSPEND_PERIOD);
@ -354,7 +382,7 @@ void suspendRxPwmPpmSignal(void)
void resumeRxPwmPpmSignal(void) void resumeRxPwmPpmSignal(void)
{ {
#if defined(USE_PWM) || defined(USE_PPM) #if defined(USE_PWM) || defined(USE_PPM)
if (featureIsEnabled(FEATURE_RX_PARALLEL_PWM | FEATURE_RX_PPM)) { if (rxRuntimeConfig.rxProvider == RX_PROVIDER_PARALLEL_PWM || rxRuntimeConfig.rxProvider == RX_PROVIDER_PPM) {
suspendRxSignalUntil = micros(); suspendRxSignalUntil = micros();
skipRxSamples = SKIP_RC_SAMPLES_ON_RESUME; skipRxSamples = SKIP_RC_SAMPLES_ON_RESUME;
failsafeOnRxResume(); failsafeOnRxResume();
@ -419,23 +447,33 @@ bool rxUpdateCheck(timeUs_t currentTimeUs, timeDelta_t currentDeltaTime)
bool signalReceived = false; bool signalReceived = false;
bool useDataDrivenProcessing = true; bool useDataDrivenProcessing = true;
switch (rxRuntimeConfig.rxProvider) {
default:
break;
#if defined(USE_PWM) || defined(USE_PPM) #if defined(USE_PWM) || defined(USE_PPM)
if (featureIsEnabled(FEATURE_RX_PPM)) { case RX_PROVIDER_PPM:
if (isPPMDataBeingReceived()) { if (isPPMDataBeingReceived()) {
signalReceived = true; signalReceived = true;
rxIsInFailsafeMode = false; rxIsInFailsafeMode = false;
needRxSignalBefore = currentTimeUs + needRxSignalMaxDelayUs; needRxSignalBefore = currentTimeUs + needRxSignalMaxDelayUs;
resetPPMDataReceivedState(); resetPPMDataReceivedState();
} }
} else if (featureIsEnabled(FEATURE_RX_PARALLEL_PWM)) {
break;
case RX_PROVIDER_PARALLEL_PWM:
if (isPWMDataBeingReceived()) { if (isPWMDataBeingReceived()) {
signalReceived = true; signalReceived = true;
rxIsInFailsafeMode = false; rxIsInFailsafeMode = false;
needRxSignalBefore = currentTimeUs + needRxSignalMaxDelayUs; needRxSignalBefore = currentTimeUs + needRxSignalMaxDelayUs;
useDataDrivenProcessing = false; useDataDrivenProcessing = false;
} }
} else
break;
#endif #endif
case RX_PROVIDER_SERIAL:
case RX_PROVIDER_MSP:
case RX_PROVIDER_SPI:
{ {
const uint8_t frameStatus = rxRuntimeConfig.rcFrameStatusFn(&rxRuntimeConfig); const uint8_t frameStatus = rxRuntimeConfig.rcFrameStatusFn(&rxRuntimeConfig);
if (frameStatus & RX_FRAME_COMPLETE) { if (frameStatus & RX_FRAME_COMPLETE) {
@ -454,6 +492,9 @@ bool rxUpdateCheck(timeUs_t currentTimeUs, timeDelta_t currentDeltaTime)
} }
} }
break;
}
if (signalReceived) { if (signalReceived) {
rxSignalReceived = true; rxSignalReceived = true;
} else if (currentTimeUs >= needRxSignalBefore) { } else if (currentTimeUs >= needRxSignalBefore) {
@ -584,7 +625,7 @@ static void detectAndApplySignalLossBehaviour(void)
} }
} }
#if defined(USE_PWM) || defined(USE_PPM) #if defined(USE_PWM) || defined(USE_PPM)
if (featureIsEnabled(FEATURE_RX_PARALLEL_PWM | FEATURE_RX_PPM)) { if (rxRuntimeConfig.rxProvider == RX_PROVIDER_PARALLEL_PWM || rxRuntimeConfig.rxProvider == RX_PROVIDER_PPM) {
// smooth output for PWM and PPM // smooth output for PWM and PPM
rcData[channel] = calculateChannelMovingAverage(channel, sample); rcData[channel] = calculateChannelMovingAverage(channel, sample);
} else } else

View File

@ -126,7 +126,18 @@ typedef uint16_t (*rcReadRawDataFnPtr)(const struct rxRuntimeConfig_s *rxRuntime
typedef uint8_t (*rcFrameStatusFnPtr)(struct rxRuntimeConfig_s *rxRuntimeConfig); typedef uint8_t (*rcFrameStatusFnPtr)(struct rxRuntimeConfig_s *rxRuntimeConfig);
typedef bool (*rcProcessFrameFnPtr)(const struct rxRuntimeConfig_s *rxRuntimeConfig); typedef bool (*rcProcessFrameFnPtr)(const struct rxRuntimeConfig_s *rxRuntimeConfig);
typedef enum {
RX_PROVIDER_NONE = 0,
RX_PROVIDER_PARALLEL_PWM,
RX_PROVIDER_PPM,
RX_PROVIDER_SERIAL,
RX_PROVIDER_MSP,
RX_PROVIDER_SPI,
} rxProvider_t;
typedef struct rxRuntimeConfig_s { typedef struct rxRuntimeConfig_s {
rxProvider_t rxProvider;
SerialRXType serialrxProvider;
uint8_t channelCount; // number of RC channels as reported by current input driver uint8_t channelCount; // number of RC channels as reported by current input driver
uint16_t rxRefreshRate; uint16_t rxRefreshRate;
rcReadRawDataFnPtr rcReadRawFn; rcReadRawDataFnPtr rcReadRawFn;

View File

@ -242,7 +242,7 @@ void spektrumBind(rxConfig_t *rxConfig)
ioTag_t rxPin = serialPinConfig()->ioTagRx[index]; ioTag_t rxPin = serialPinConfig()->ioTagRx[index];
// Take care half-duplex case // Take care half-duplex case
switch (rxConfig->serialrx_provider) { switch (rxRuntimeConfig.serialrxProvider) {
case SERIALRX_SRXL: case SERIALRX_SRXL:
#if defined(USE_TELEMETRY_SRXL) #if defined(USE_TELEMETRY_SRXL)
if (featureIsEnabled(FEATURE_TELEMETRY) && !telemetryCheckRxPortShared(portConfig)) { if (featureIsEnabled(FEATURE_TELEMETRY) && !telemetryCheckRxPortShared(portConfig)) {
@ -357,7 +357,10 @@ bool spektrumInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig
bool portShared = false; bool portShared = false;
#endif #endif
switch (rxConfig->serialrx_provider) { switch (rxRuntimeConfig->serialrxProvider) {
default:
break;
case SERIALRX_SRXL: case SERIALRX_SRXL:
#if defined(USE_TELEMETRY_SRXL) #if defined(USE_TELEMETRY_SRXL)
srxlEnabled = (featureIsEnabled(FEATURE_TELEMETRY) && !portShared); srxlEnabled = (featureIsEnabled(FEATURE_TELEMETRY) && !portShared);

View File

@ -266,7 +266,7 @@ bool xBusInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
{ {
uint32_t baudRate; uint32_t baudRate;
switch (rxConfig->serialrx_provider) { switch (rxRuntimeConfig->serialrxProvider) {
case SERIALRX_XBUS_MODE_B: case SERIALRX_XBUS_MODE_B:
rxRuntimeConfig->channelCount = XBUS_CHANNEL_COUNT; rxRuntimeConfig->channelCount = XBUS_CHANNEL_COUNT;
xBusFrameReceived = false; xBusFrameReceived = false;

View File

@ -136,21 +136,21 @@ bool telemetryDetermineEnabledState(portSharing_e portSharing)
bool telemetryCheckRxPortShared(const serialPortConfig_t *portConfig) bool telemetryCheckRxPortShared(const serialPortConfig_t *portConfig)
{ {
if (portConfig->functionMask & FUNCTION_RX_SERIAL && portConfig->functionMask & TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK && if (portConfig->functionMask & FUNCTION_RX_SERIAL && portConfig->functionMask & TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK &&
(rxConfig()->serialrx_provider == SERIALRX_SPEKTRUM1024 || (rxRuntimeConfig.serialrxProvider == SERIALRX_SPEKTRUM1024 ||
rxConfig()->serialrx_provider == SERIALRX_SPEKTRUM2048 || rxRuntimeConfig.serialrxProvider == SERIALRX_SPEKTRUM2048 ||
rxConfig()->serialrx_provider == SERIALRX_SBUS || rxRuntimeConfig.serialrxProvider == SERIALRX_SBUS ||
rxConfig()->serialrx_provider == SERIALRX_SUMD || rxRuntimeConfig.serialrxProvider == SERIALRX_SUMD ||
rxConfig()->serialrx_provider == SERIALRX_SUMH || rxRuntimeConfig.serialrxProvider == SERIALRX_SUMH ||
rxConfig()->serialrx_provider == SERIALRX_XBUS_MODE_B || rxRuntimeConfig.serialrxProvider == SERIALRX_XBUS_MODE_B ||
rxConfig()->serialrx_provider == SERIALRX_XBUS_MODE_B_RJ01 || rxRuntimeConfig.serialrxProvider == SERIALRX_XBUS_MODE_B_RJ01 ||
rxConfig()->serialrx_provider == SERIALRX_IBUS)) { rxRuntimeConfig.serialrxProvider == SERIALRX_IBUS)) {
return true; return true;
} }
#ifdef USE_TELEMETRY_IBUS #ifdef USE_TELEMETRY_IBUS
if ( portConfig->functionMask & FUNCTION_TELEMETRY_IBUS if ( portConfig->functionMask & FUNCTION_TELEMETRY_IBUS
&& portConfig->functionMask & FUNCTION_RX_SERIAL && portConfig->functionMask & FUNCTION_RX_SERIAL
&& rxConfig()->serialrx_provider == SERIALRX_IBUS) { && rxRuntimeConfig.serialrxProvider == SERIALRX_IBUS) {
// IBUS serial RX & telemetry // IBUS serial RX & telemetry
return true; return true;
} }