altos: Clean up radio APIs
authorKeith Packard <keithp@keithp.com>
Mon, 27 Aug 2012 20:47:16 +0000 (13:47 -0700)
committerKeith Packard <keithp@keithp.com>
Mon, 27 Aug 2012 20:47:16 +0000 (13:47 -0700)
Move api to ao_radio_cmac.h include file.
Expose ao_radio_test as standard API.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/cc1111/ao_launch.c
src/cc1111/ao_radio.c
src/core/ao.h
src/core/ao_aes.h
src/core/ao_radio_cmac.c
src/core/ao_radio_cmac.h [new file with mode: 0644]
src/drivers/ao_cc1120.c
src/drivers/ao_pad.c

index a593d0b2b624f94a16a98cab68a0a52e0f76d308..420f75683666c41125a19e259f11d491c6f7d284 100644 (file)
@@ -15,7 +15,8 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-#include "ao.h"
+#include <ao.h>
+#include <ao_radio_cmac.h>
 
 __xdata uint16_t ao_launch_ignite;
 
index 46b2362d8b19e5a5245ca8b680a744ced8625ea7..cb2c2fddba411fee29ea427bd11f44b402d96fd7 100644 (file)
@@ -470,8 +470,44 @@ ao_radio_rdf_abort(void)
 
 
 /* Output carrier */
+
+static __xdata ao_radio_test_on;
+
 void
-ao_radio_test(void)
+ao_radio_test(uint8_t on)
+{
+       if (on) {
+               if (!ao_radio_test_on) {
+#if HAS_MONITOR
+                       ao_monitor_disable();
+#endif
+#if PACKET_HAS_SLAVE
+                       ao_packet_slave_stop();
+#endif
+#if HAS_PAD
+                       ao_pad_disable();
+#endif
+                       ao_radio_get(0xff);
+                       RFST = RFST_STX;
+                       ao_radio_test_on = 1;
+               }
+       } else  {
+               if (ao_radio_test_on) {
+                       ao_radio_idle();
+                       ao_radio_put();
+                       ao_radio_test_on = 0;
+#if HAS_MONITOR
+                       ao_monitor_enable();
+#endif
+#if HAS_PAD
+                       ao_pad_enable();
+#endif
+               }
+       }
+}
+
+static void
+ao_radio_test_cmd(void)
 {
        uint8_t mode = 2;
        static __xdata radio_on;
@@ -481,40 +517,19 @@ ao_radio_test(void)
                mode = (uint8_t) ao_cmd_lex_u32;
        }
        mode++;
-       if ((mode & 2) && !radio_on) {
-#if HAS_MONITOR
-               ao_monitor_disable();
-#endif
-#if PACKET_HAS_SLAVE
-               ao_packet_slave_stop();
-#endif
-#if HAS_PAD
-               ao_pad_disable();
-#endif
-               ao_radio_get(0xff);
-               RFST = RFST_STX;
-               radio_on = 1;
-       }
+       if ((mode & 2))
+               ao_radio_test(1);
        if (mode == 3) {
                printf ("Hit a character to stop..."); flush();
                getchar();
                putchar('\n');
        }
-       if ((mode & 1) && radio_on) {
-               ao_radio_idle();
-               ao_radio_put();
-               radio_on = 0;
-#if HAS_MONITOR
-               ao_monitor_enable();
-#endif
-#if HAS_PAD
-               ao_pad_enable();
-#endif
-       }
+       if ((mode & 1))
+               ao_radio_test(0);
 }
 
 __code struct ao_cmds ao_radio_cmds[] = {
-       { ao_radio_test,        "C <1 start, 0 stop, none both>\0Radio carrier test" },
+       { ao_radio_test_cmd,    "C <1 start, 0 stop, none both>\0Radio carrier test" },
        { 0,    NULL },
 };
 
index 5e1fbb9d05d6a39ea91ec6ef368efa746ca0de2e..b8bedd85ee212b7749076d6b4239831a3e4dc00f 100644 (file)
@@ -543,9 +543,6 @@ ao_telemetry_tiny_init(void);
  */
 
 extern __xdata uint8_t ao_radio_dma;
-extern __xdata uint8_t ao_radio_dma_done;
-extern __xdata uint8_t ao_radio_done;
-extern __xdata uint8_t ao_radio_mutex;
 
 #ifdef PKT_APPEND_STATUS_1_CRC_OK
 #define AO_RADIO_STATUS_CRC_OK PKT_APPEND_STATUS_1_CRC_OK
@@ -566,6 +563,9 @@ ao_radio_recv(__xdata void *d, uint8_t size) __reentrant;
 void
 ao_radio_recv_abort(void);
 
+void
+ao_radio_test(uint8_t on);
+
 /*
  * Compute the packet length as follows:
  *
index ab3e367e6a653863c9480e181077b79029e18fdd..c47bc2db22f6921eeee524d46240e04951d89ac9 100644 (file)
@@ -51,21 +51,4 @@ ao_aes_run(__xdata uint8_t *in,
 void
 ao_aes_init(void);
 
-/* ao_radio_cmac.c */
-
-int8_t
-ao_radio_cmac_send(__xdata void *packet, uint8_t len) __reentrant;
-
-#define AO_RADIO_CMAC_OK       0
-#define AO_RADIO_CMAC_LEN_ERROR        -1
-#define AO_RADIO_CMAC_CRC_ERROR        -2
-#define AO_RADIO_CMAC_MAC_ERROR        -3
-#define AO_RADIO_CMAC_TIMEOUT  -4
-
-int8_t
-ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentrant;
-
-void
-ao_radio_cmac_init(void);
-
 #endif /* _AO_AES_H_ */
index 3e8dce53ac0a95ab43293860f7f97b343661ea48..fc0ca8b1310382912895f25d7f6e023525f1c0e2 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-#include "ao.h"
-
-#define AO_CMAC_KEY_LEN                AO_AES_LEN
-#define AO_CMAC_MAX_LEN                (128 - AO_CMAC_KEY_LEN)
+#include <ao.h>
+#include <ao_radio_cmac.h>
 
 static __xdata uint8_t ao_radio_cmac_mutex;
-__pdata int16_t ao_radio_cmac_rssi;
+__pdata int8_t ao_radio_cmac_rssi;
 static __xdata uint8_t cmac_data[AO_CMAC_MAX_LEN + AO_CMAC_KEY_LEN + 2 + AO_CMAC_KEY_LEN];
 static __pdata uint8_t ao_radio_cmac_len;
 
-static uint8_t
-getnibble(void)
-{
-       int8_t  b;
-
-       b = ao_cmd_hexchar(getchar());
-       if (b < 0) {
-               ao_cmd_status = ao_cmd_lex_error;
-               return 0;
-       }
-       return (uint8_t) b;
-}
-
-static uint8_t
-getbyte(void)
-{
-       uint8_t b;
-       b = getnibble() << 4;
-       b |= getnibble();
-       return b;
-}
-       
 static uint8_t
 round_len(uint8_t len)
 {
@@ -120,7 +96,7 @@ radio_cmac_recv(uint8_t len, uint16_t timeout) __reentrant
                return AO_RADIO_CMAC_TIMEOUT;
        }
 
-       ao_radio_cmac_rssi = (int16_t) (((int8_t) cmac_data[len + AO_CMAC_KEY_LEN]) >> 1) - 74;
+       ao_radio_cmac_rssi = (int8_t) (((int8_t) cmac_data[len + AO_CMAC_KEY_LEN]) >> 1) - 74;
        if (!(cmac_data[len + AO_CMAC_KEY_LEN +1] & AO_RADIO_STATUS_CRC_OK))
                return AO_RADIO_CMAC_CRC_ERROR;
 
@@ -191,55 +167,3 @@ ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentr
        return i;
 }
 
-static void
-radio_cmac_send_cmd(void) __reentrant
-{
-       uint8_t i;
-       uint8_t len;
-
-       ao_cmd_decimal();
-       if (ao_cmd_status != ao_cmd_success)
-               return;
-       len = ao_cmd_lex_i;
-       if (len > AO_CMAC_MAX_LEN) {
-               ao_cmd_status = ao_cmd_syntax_error;
-               return;
-       }
-       flush();
-       ao_mutex_get(&ao_radio_cmac_mutex);
-       len = ao_cmd_lex_i;
-       for (i = 0; i < len; i++) {
-               cmac_data[i] = getbyte();
-               if (ao_cmd_status != ao_cmd_success)
-                       return;
-       }
-       radio_cmac_send(len);
-       ao_mutex_put(&ao_radio_cmac_mutex);
-}
-
-static void
-radio_cmac_recv_cmd(void) __reentrant
-{
-       uint8_t         len, i;
-       uint16_t        timeout;
-
-       ao_cmd_decimal();
-       if (ao_cmd_status != ao_cmd_success)
-               return;
-       len = ao_cmd_lex_i;
-       ao_cmd_decimal();
-       if (ao_cmd_status != ao_cmd_success)
-               return;
-       timeout = AO_MS_TO_TICKS(ao_cmd_lex_i);
-       ao_mutex_get(&ao_radio_cmac_mutex);
-       i = radio_cmac_recv(len, timeout);
-       if (i == AO_RADIO_CMAC_OK) {
-               printf ("PACKET ");
-               for (i = 0; i < len; i++)
-                       printf("%02x", cmac_data[i]);
-               printf (" %d\n", ao_radio_cmac_rssi);
-       } else
-               printf ("ERROR %d %d\n", i, ao_radio_cmac_rssi);
-       ao_mutex_put(&ao_radio_cmac_mutex);
-}
-
diff --git a/src/core/ao_radio_cmac.h b/src/core/ao_radio_cmac.h
new file mode 100644 (file)
index 0000000..e86f31e
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2012 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_RADIO_CMAC_H_
+#define _AO_RADIO_CMAC_H_
+
+#include <ao_aes.h>
+
+#define AO_CMAC_KEY_LEN                AO_AES_LEN
+#define AO_CMAC_MAX_LEN                (128 - AO_CMAC_KEY_LEN)
+
+extern __pdata int8_t ao_radio_cmac_rssi;
+
+int8_t
+ao_radio_cmac_send(__xdata void *packet, uint8_t len) __reentrant;
+
+#define AO_RADIO_CMAC_OK       0
+#define AO_RADIO_CMAC_LEN_ERROR        -1
+#define AO_RADIO_CMAC_CRC_ERROR        -2
+#define AO_RADIO_CMAC_MAC_ERROR        -3
+#define AO_RADIO_CMAC_TIMEOUT  -4
+
+int8_t
+ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentrant;
+
+void
+ao_radio_cmac_init(void);
+
+#endif /* _AO_RADIO_CMAC_H_ */
index 97a434d8975131338034ad1783c1e0e61bae5c7a..4df931b5094b0349b9c903f768170dc21553f89f 100644 (file)
@@ -515,7 +515,7 @@ ao_radio_rdf_abort(void)
 }
 
 static void
-ao_radio_test(void)
+ao_radio_test_cmd(void)
 {
        uint8_t mode = 2;
        uint8_t radio_on;
@@ -1008,7 +1008,7 @@ ao_radio_test_recv()
 #endif
 
 static const struct ao_cmds ao_radio_cmds[] = {
-       { ao_radio_test,        "C <1 start, 0 stop, none both>\0Radio carrier test" },
+       { ao_radio_test_cmd,    "C <1 start, 0 stop, none both>\0Radio carrier test" },
 #if CC1120_DEBUG
        { ao_radio_show,        "R\0Show CC1120 status" },
        { ao_radio_beep,        "b\0Emit an RDF beacon" },
index 791c9a475fe3f0697ccd300f18af8c2d285da63f..b33a5ffdaeaf7a74abe94446def2c95089f9d025 100644 (file)
@@ -18,6 +18,7 @@
 #include <ao.h>
 #include <ao_pad.h>
 #include <ao_74hc497.h>
+#include <ao_radio_cmac.h>
 
 static __xdata uint8_t ao_pad_ignite;
 static __xdata struct ao_pad_command   command;