From 3fd3c7786e881fcc07d2fd18b5466cf8afb2a03b Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Fri, 24 Dec 2021 08:32:07 +0000 Subject: [PATCH] Set M0 mode to IDLE when transceiver mode is OFF. At this point, streaming has been stopped, so there will be no further SGPIO interrupts. However, the M0 will still be spinning on the interrupt flag, waiting to proceed. To ensure that the M0 actually reaches its idle loop, we set the SGPIO interrupt flag once. The M0 will then finish spinning on the flag, clear the flag, see the new mode setting, and jump to the idle loop. --- firmware/hackrf_usb/usb_api_transceiver.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/firmware/hackrf_usb/usb_api_transceiver.c b/firmware/hackrf_usb/usb_api_transceiver.c index c3584219..624fd4aa 100644 --- a/firmware/hackrf_usb/usb_api_transceiver.c +++ b/firmware/hackrf_usb/usb_api_transceiver.c @@ -269,7 +269,12 @@ void transceiver_shutdown(void) led_off(LED2); led_off(LED3); rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_OFF); - m0_state.mode = M0_MODE_RX; + m0_state.mode = M0_MODE_IDLE; + // The M0 may already be waiting for the next SGPIO + // exchange interrupt. In order to ensure that the M0 + // switches over to its idle loop, we need to set the + // SGPIO exchange interrupt flag here. + SGPIO_SET_STATUS_1 = (1 << SGPIO_SLICE_A); } void transceiver_startup(const transceiver_mode_t mode) {