altos: Make sure we drop the SPI mutex when aborting cc1120 recv
authorKeith Packard <keithp@keithp.com>
Sat, 27 Sep 2014 05:53:39 +0000 (22:53 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 27 Sep 2014 06:01:18 +0000 (23:01 -0700)
The cc1120 receive code is 'twisty', in that it acquires the SPI mutex
in the middle of an interrupt handler so that it can quickly start the
radio when the signal comes in. This means we have to be careful to
drop that mutex in all paths which leave the receive code, including
when the packet receive is aborted mid-way through the process.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_cc1120.c

index 3ea8b7044b4cecb25f1880f5be5a3b1bbfb066cd..90d6cc75ab5f76eb5677a052203a44e85eb6b94d 100644 (file)
@@ -1125,12 +1125,12 @@ ao_radio_recv(__xdata void *d, uint8_t size, uint8_t timeout)
        ao_exti_set_mode(AO_CC1120_INT_PORT, AO_CC1120_INT_PIN,
                         AO_EXTI_MODE_FALLING|AO_EXTI_PRIORITY_HIGH);
 
-       ao_exti_set_callback(AO_CC1120_INT_PORT, AO_CC1120_INT_PIN, ao_radio_rx_isr);
-       ao_exti_enable(AO_CC1120_INT_PORT, AO_CC1120_INT_PIN);
-
        rx_starting = 1;
        rx_task_id = ao_cur_task->task_id;
 
+       ao_exti_set_callback(AO_CC1120_INT_PORT, AO_CC1120_INT_PIN, ao_radio_rx_isr);
+       ao_exti_enable(AO_CC1120_INT_PORT, AO_CC1120_INT_PIN);
+
        ao_radio_strobe(CC1120_SRX);
 
        if (timeout)
@@ -1148,8 +1148,9 @@ ao_radio_recv(__xdata void *d, uint8_t size, uint8_t timeout)
                ao_clear_alarm();
 
        if (ao_radio_abort) {
+               if (rx_task_id_save == 0)
+                       ao_radio_burst_read_stop();
                ret = 0;
-               rx_task_id = 0;
                goto abort;
        }