altos: Make radio test command careful with the radio mutex.
authorKeith Packard <keithp@keithp.com>
Wed, 24 Nov 2010 03:02:54 +0000 (19:02 -0800)
committerKeith Packard <keithp@keithp.com>
Wed, 24 Nov 2010 03:10:27 +0000 (19:10 -0800)
Remember whether the radio test mode is on or off and don't try to do
either of them twice to prevent the mutex from being acquired or
released twice.

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

index b2105ff89c41e3add1f5a86aade8d650952ed953..67d5f6bad7e7272190cb2b967c311c69efeb7af4 100644 (file)
@@ -452,26 +452,29 @@ void
 ao_radio_test(void)
 {
        uint8_t mode = 2;
 ao_radio_test(void)
 {
        uint8_t mode = 2;
+       static __xdata radio_on;
        ao_cmd_white();
        if (ao_cmd_lex_c != '\n') {
                ao_cmd_decimal();
                mode = (uint8_t) ao_cmd_lex_u32;
        }
        mode++;
        ao_cmd_white();
        if (ao_cmd_lex_c != '\n') {
                ao_cmd_decimal();
                mode = (uint8_t) ao_cmd_lex_u32;
        }
        mode++;
-       if (mode & 2) {
+       if ((mode & 2) && !radio_on) {
                ao_set_monitor(0);
                ao_packet_slave_stop();
                ao_radio_get();
                RFST = RFST_STX;
                ao_set_monitor(0);
                ao_packet_slave_stop();
                ao_radio_get();
                RFST = RFST_STX;
+               radio_on = 1;
        }
        if (mode == 3) {
                printf ("Hit a character to stop..."); flush();
                getchar();
                putchar('\n');
        }
        }
        if (mode == 3) {
                printf ("Hit a character to stop..."); flush();
                getchar();
                putchar('\n');
        }
-       if (mode & 1) {
+       if ((mode & 1) && radio_on) {
                ao_radio_idle();
                ao_radio_put();
                ao_radio_idle();
                ao_radio_put();
+               radio_on = 0;
        }
 }
 
        }
 }