diff options
| -rw-r--r-- | src/cc1111/ao_launch.c | 3 | ||||
| -rw-r--r-- | src/cc1111/ao_radio.c | 69 | ||||
| -rw-r--r-- | src/core/ao.h | 6 | ||||
| -rw-r--r-- | src/core/ao_aes.h | 17 | ||||
| -rw-r--r-- | src/core/ao_radio_cmac.c | 84 | ||||
| -rw-r--r-- | src/core/ao_radio_cmac.h | 43 | ||||
| -rw-r--r-- | src/drivers/ao_cc1120.c | 4 | ||||
| -rw-r--r-- | src/drivers/ao_pad.c | 1 | 
8 files changed, 97 insertions, 130 deletions
| diff --git a/src/cc1111/ao_launch.c b/src/cc1111/ao_launch.c index a593d0b2..420f7568 100644 --- a/src/cc1111/ao_launch.c +++ b/src/cc1111/ao_launch.c @@ -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; diff --git a/src/cc1111/ao_radio.c b/src/cc1111/ao_radio.c index 46b2362d..cb2c2fdd 100644 --- a/src/cc1111/ao_radio.c +++ b/src/cc1111/ao_radio.c @@ -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 },  }; diff --git a/src/core/ao.h b/src/core/ao.h index 5e1fbb9d..b8bedd85 100644 --- a/src/core/ao.h +++ b/src/core/ao.h @@ -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:   * diff --git a/src/core/ao_aes.h b/src/core/ao_aes.h index ab3e367e..c47bc2db 100644 --- a/src/core/ao_aes.h +++ b/src/core/ao_aes.h @@ -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_ */ diff --git a/src/core/ao_radio_cmac.c b/src/core/ao_radio_cmac.c index 3e8dce53..fc0ca8b1 100644 --- a/src/core/ao_radio_cmac.c +++ b/src/core/ao_radio_cmac.c @@ -15,39 +15,15 @@   * 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)  {  	uint8_t	rem; @@ -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 index 00000000..e86f31e9 --- /dev/null +++ b/src/core/ao_radio_cmac.h @@ -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_ */ diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index 97a434d8..4df931b5 100644 --- a/src/drivers/ao_cc1120.c +++ b/src/drivers/ao_cc1120.c @@ -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" }, diff --git a/src/drivers/ao_pad.c b/src/drivers/ao_pad.c index 791c9a47..b33a5ffd 100644 --- a/src/drivers/ao_pad.c +++ b/src/drivers/ao_pad.c @@ -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; | 
