Move api to ao_radio_cmac.h include file.
Expose ao_radio_test as standard API.
Signed-off-by: Keith Packard <keithp@keithp.com>
* 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;
/* 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;
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 },
};
*/
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
void
ao_radio_recv_abort(void);
+void
+ao_radio_test(uint8_t on);
+
/*
* Compute the packet length as follows:
*
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_ */
* 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)
{
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;
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);
-}
-
--- /dev/null
+/*
+ * 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_ */
}
static void
-ao_radio_test(void)
+ao_radio_test_cmd(void)
{
uint8_t mode = 2;
uint8_t radio_on;
#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" },
#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;