From 12bb43cdb8c420fc94e5a6afb845a6b9182b4e87 Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Sun, 17 Apr 2022 15:13:57 +0100 Subject: [PATCH 1/3] Define state case rather than relying on default --- src/main/rx/cc2500_frsky_shared.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/rx/cc2500_frsky_shared.c b/src/main/rx/cc2500_frsky_shared.c index 14a02c665d..2ff2d5b5d0 100644 --- a/src/main/rx/cc2500_frsky_shared.c +++ b/src/main/rx/cc2500_frsky_shared.c @@ -435,6 +435,8 @@ rx_spi_received_e frSkySpiDataReceived(uint8_t *packet) protocolState = STATE_STARTING; break; + + case STATE_STARTING: default: ret = handlePacket(packet, &protocolState); From 1368b221b7ecde2dc34000ae990c1aa0dc8b3f4e Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Sun, 17 Apr 2022 15:14:23 +0100 Subject: [PATCH 2/3] Remove rxFrameReady() --- src/main/fc/core.c | 8 -------- src/main/fc/core.h | 1 - src/main/scheduler/scheduler.c | 14 +++++++------- src/test/unit/scheduler_unittest.cc | 1 - 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/main/fc/core.c b/src/main/fc/core.c index 4eb9957ced..c6b36d749b 100644 --- a/src/main/fc/core.c +++ b/src/main/fc/core.c @@ -1262,14 +1262,6 @@ FAST_CODE bool pidLoopReady(void) return false; } -FAST_CODE bool rxFrameReady(void) -{ - if ((activePidLoopDenom == 1) || (pidUpdateCounter % activePidLoopDenom == 0)) { - return true; - } - return false; -} - FAST_CODE void taskFiltering(timeUs_t currentTimeUs) { gyroFiltering(currentTimeUs); diff --git a/src/main/fc/core.h b/src/main/fc/core.h index 32ca92c674..d955dfbe28 100644 --- a/src/main/fc/core.h +++ b/src/main/fc/core.h @@ -82,7 +82,6 @@ void updateArmingStatus(void); void taskGyroSample(timeUs_t currentTimeUs); bool gyroFilterReady(void); bool pidLoopReady(void); -bool rxFrameReady(void); void taskFiltering(timeUs_t currentTimeUs); void taskMainPidLoop(timeUs_t currentTimeUs); diff --git a/src/main/scheduler/scheduler.c b/src/main/scheduler/scheduler.c index 01c68f54a9..fba208b605 100644 --- a/src/main/scheduler/scheduler.c +++ b/src/main/scheduler/scheduler.c @@ -503,13 +503,13 @@ FAST_CODE void scheduler(void) if (pidLoopReady()) { taskExecutionTimeUs += schedulerExecuteTask(getTask(TASK_PID), currentTimeUs); } - if (rxFrameReady()) { - // Check for incoming RX data. Don't do this in the checker as that is called repeatedly within - // a given gyro loop, and ELRS takes a long time to process this and so can only be safely processed - // before the checkers - rxFrameCheck(currentTimeUs, cmpTimeUs(currentTimeUs, getTask(TASK_RX)->lastExecutedAtUs)); - } - // Check for failsafe conditions every 10ms, independently of the Rx Task, which runs at 33hz. + + // Check for incoming RX data. Don't do this in the checker as that is called repeatedly within + // a given gyro loop, and ELRS takes a long time to process this and so can only be safely processed + // before the checkers + rxFrameCheck(currentTimeUs, cmpTimeUs(currentTimeUs, getTask(TASK_RX)->lastExecutedAtUs)); + + // Check for failsafe conditions without reliance on the RX task being well behaved if (cmp32(millis(), lastFailsafeCheckMs) > PERIOD_RXDATA_FAILURE) { // This is very low cost taking less that 4us every 10ms failsafeCheckDataFailurePeriod(); diff --git a/src/test/unit/scheduler_unittest.cc b/src/test/unit/scheduler_unittest.cc index aea553e027..f820132d66 100644 --- a/src/test/unit/scheduler_unittest.cc +++ b/src/test/unit/scheduler_unittest.cc @@ -67,7 +67,6 @@ extern "C" { int16_t debug[1]; uint8_t debugMode = 0; - bool rxFrameReady(void) { return 0; } void rxFrameCheck(timeUs_t, timeDelta_t) {} // set up micros() to simulate time From 8bc7548dbbeab38c9c31aa95f15a61a90f589660 Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Mon, 18 Apr 2022 23:08:58 +0100 Subject: [PATCH 3/3] Disable SPI DMA for CC2500 --- src/main/drivers/rx/rx_cc2500.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/drivers/rx/rx_cc2500.c b/src/main/drivers/rx/rx_cc2500.c index 5f8e6a20a9..487b2eb780 100644 --- a/src/main/drivers/rx/rx_cc2500.c +++ b/src/main/drivers/rx/rx_cc2500.c @@ -50,20 +50,12 @@ void cc2500ReadFifo(uint8_t *dpbuffer, uint8_t len) void cc2500WriteCommand(uint8_t command, uint8_t data) { - // Burst writes require an interbyte gap, see fig. 7, pg. 22 in https://www.ti.com/lit/ds/symlink/cc2500.pdf - // As such gaps can't be inserted if DMA is being used, inhibit DMA on this bus for the duration of this call - rxSpiDmaEnable(false); rxSpiWriteCommand(command, data); - rxSpiDmaEnable(true); } void cc2500WriteCommandMulti(uint8_t command, const uint8_t *data, uint8_t length) { - // Burst writes require an interbyte gap, see fig. 7, pg. 22 in https://www.ti.com/lit/ds/symlink/cc2500.pdf - // As such gaps can't be inserted if DMA is being used, inhibit DMA on this bus for the duration of this call - rxSpiDmaEnable(false); rxSpiWriteCommandMulti(command, data, length); - rxSpiDmaEnable(true); } void cc2500WriteFifo(uint8_t *dpbuffer, uint8_t len) @@ -116,6 +108,10 @@ void cc2500SetPower(uint8_t power) uint8_t cc2500Reset(void) { + // Writes require an interbyte gap, see fig. 7, pg. 22 in https://www.ti.com/lit/ds/symlink/cc2500.pdf + // As such gaps can't be inserted if DMA is being used, inhibit DMA for this device + rxSpiDmaEnable(false); + cc2500Strobe(CC2500_SRES); delayMicroseconds(1000); // 1000us // CC2500_SetTxRxMode(TXRX_OFF);