diff options
| author | Keith Packard <keithp@keithp.com> | 2013-04-29 23:20:25 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2013-05-07 20:07:54 -0700 | 
| commit | eb0e1720be2aa4fb6729ceada09c18947bfee2bc (patch) | |
| tree | 77bfbad77fa2d2f653c9bf6814b7d63607672a77 /src | |
| parent | 949700f276b80b4eb28f15b5559714f430f227f1 (diff) | |
altos: Compute "real" RSSI value in radio code as needed
Instead of dragging around the weird CC1111 RSSI values, just compute
a dBm value in a signed 8-bit integer, ao_radio_rssi. Use that
everywhere we need RSSI internally. We leave the weird CC1111 value in
the packet reply as that's what the host expects.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cc1111/ao_radio.c | 19 | ||||
| -rw-r--r-- | src/core/ao.h | 2 | ||||
| -rw-r--r-- | src/core/ao_packet.h | 2 | ||||
| -rw-r--r-- | src/core/ao_radio_cmac.c | 4 | ||||
| -rw-r--r-- | src/drivers/ao_cc1120.c | 23 | ||||
| -rw-r--r-- | src/drivers/ao_packet.c | 4 | ||||
| -rw-r--r-- | src/drivers/ao_packet_master.c | 2 | 
7 files changed, 43 insertions, 13 deletions
| diff --git a/src/cc1111/ao_radio.c b/src/cc1111/ao_radio.c index 07b0d1b5..4842486b 100644 --- a/src/cc1111/ao_radio.c +++ b/src/cc1111/ao_radio.c @@ -249,6 +249,18 @@ __xdata uint8_t ao_radio_done;  __xdata uint8_t ao_radio_abort;  __xdata uint8_t ao_radio_mutex; +#if PACKET_HAS_MASTER || HAS_AES +#define NEED_RADIO_RSSI 1 +#endif + +#ifndef NEED_RADIO_RSSI +#define NEED_RADIO_RSSI 0 +#endif + +#if NEED_RADIO_RSSI +__xdata int8_t ao_radio_rssi; +#endif +  void  ao_radio_general_isr(void) __interrupt 16  { @@ -356,7 +368,14 @@ ao_radio_recv(__xdata void *packet, uint8_t size, uint8_t timeout) __reentrant  	if (!ao_radio_dma_done) {  		ao_dma_abort(ao_radio_dma);  		ao_radio_idle(); +#if NEED_RADIO_RSSI +		ao_radio_rssi = 0; +#endif  	} +#if NEED_RADIO_RSSI +	else +		ao_radio_rssi = AO_RSSI_FROM_RADIO(((uint8_t *)packet)[size - 1]); +#endif  	ao_radio_put();  	return ao_radio_dma_done;  } diff --git a/src/core/ao.h b/src/core/ao.h index 2a8eb042..6bcb3664 100644 --- a/src/core/ao.h +++ b/src/core/ao.h @@ -511,6 +511,8 @@ ao_telemetry_tiny_init(void);  extern __xdata uint8_t	ao_radio_dma; +extern __xdata int8_t	ao_radio_rssi; +  #ifdef PKT_APPEND_STATUS_1_CRC_OK  #define AO_RADIO_STATUS_CRC_OK	PKT_APPEND_STATUS_1_CRC_OK  #else diff --git a/src/core/ao_packet.h b/src/core/ao_packet.h index 6d121bb9..b8426cf9 100644 --- a/src/core/ao_packet.h +++ b/src/core/ao_packet.h @@ -68,7 +68,7 @@ _ao_packet_pollchar(void);  #if PACKET_HAS_MASTER  /* ao_packet_master.c */ -extern __xdata uint8_t ao_packet_last_rssi; +extern __xdata int8_t ao_packet_last_rssi;  void  ao_packet_master_init(void); diff --git a/src/core/ao_radio_cmac.c b/src/core/ao_radio_cmac.c index 4920b50c..3ca3c313 100644 --- a/src/core/ao_radio_cmac.c +++ b/src/core/ao_radio_cmac.c @@ -92,7 +92,7 @@ radio_cmac_recv(uint8_t len, uint16_t timeout) __reentrant  		return AO_RADIO_CMAC_TIMEOUT;  	} -	ao_radio_cmac_rssi = (int8_t) (((int8_t) cmac_data[len + AO_CMAC_KEY_LEN]) >> 1) - 74; +	ao_radio_cmac_rssi = ao_radio_rssi;  	if (!(cmac_data[len + AO_CMAC_KEY_LEN +1] & AO_RADIO_STATUS_CRC_OK))  		return AO_RADIO_CMAC_CRC_ERROR; @@ -146,7 +146,7 @@ ao_radio_cmac_send(__xdata void *packet, uint8_t len) __reentrant  int8_t  ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentrant  { -	uint8_t	i; +	int8_t	i;  	if (len > AO_CMAC_MAX_LEN)  		return AO_RADIO_CMAC_LEN_ERROR;  	ao_mutex_get(&ao_radio_cmac_mutex); diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index 07ebf835..b6b77a5a 100644 --- a/src/drivers/ao_cc1120.c +++ b/src/drivers/ao_cc1120.c @@ -32,6 +32,8 @@ static uint8_t ao_radio_mcu_wake;	/* MARC status change */  static uint8_t ao_radio_marc_status;	/* Last read MARC status value */  static uint8_t ao_radio_tx_finished;	/* MARC status indicates TX finished */ +int8_t	ao_radio_rssi;			/* Last received RSSI value */ +  #define CC1120_DEBUG	AO_FEC_DEBUG  #define CC1120_TRACE	0 @@ -552,6 +554,7 @@ ao_radio_get(uint8_t len)  	static uint32_t	last_radio_setting;  	ao_mutex_get(&ao_radio_mutex); +  	if (!ao_radio_configured)  		ao_radio_setup();  	if (ao_config.radio_setting != last_radio_setting) { @@ -909,7 +912,8 @@ ao_radio_recv(__xdata void *d, uint8_t size, uint8_t timeout)  {  	uint8_t		len;  	uint16_t	i; -	uint8_t		rssi; +	uint8_t		radio_rssi = 0; +	uint8_t		rssi0;  	uint8_t		ret;  	static int been_here = 0; @@ -977,17 +981,26 @@ ao_radio_recv(__xdata void *d, uint8_t size, uint8_t timeout)  	ao_radio_burst_read_stop();  abort: -	ao_radio_strobe(CC1120_SIDLE); -  	/* Convert from 'real' rssi to cc1111-style values */ -	rssi = AO_RADIO_FROM_RSSI(ao_radio_reg_read(CC1120_RSSI1)); +	rssi0 = ao_radio_reg_read(CC1120_RSSI0); +	if (rssi0 & 1) { +		int8_t rssi = ao_radio_reg_read(CC1120_RSSI1); +		ao_radio_rssi = rssi; + +		/* Bound it to the representable range */ +		if (rssi > -11) +			rssi = -11; +		radio_rssi = AO_RADIO_FROM_RSSI (rssi); +	} + +	ao_radio_strobe(CC1120_SIDLE);  	ao_radio_put();  	/* Store the received RSSI value; the crc-OK byte is already done */ -	((uint8_t *) d)[size] = (uint8_t) rssi; +	((uint8_t *) d)[size] = radio_rssi;  #if AO_PROFILE  	rx_last_done_tick = rx_done_tick; diff --git a/src/drivers/ao_packet.c b/src/drivers/ao_packet.c index 802d4c90..8cdf85a9 100644 --- a/src/drivers/ao_packet.c +++ b/src/drivers/ao_packet.c @@ -31,7 +31,6 @@ __xdata uint8_t ao_packet_restart;  #if PACKET_HAS_MASTER  __xdata uint8_t ao_packet_master_sleeping; -__xdata uint8_t ao_packet_last_rssi;  #endif  void @@ -85,9 +84,6 @@ ao_packet_recv(void)  	if (!(ao_rx_packet.status & AO_RADIO_STATUS_CRC_OK))  		return 0; -#if PACKET_HAS_MASTER -	ao_packet_last_rssi = ao_rx_packet.rssi; -#endif  	/* Accept packets with matching call signs, or any packet if  	 * our callsign hasn't been configured  	 */ diff --git a/src/drivers/ao_packet_master.c b/src/drivers/ao_packet_master.c index 4c0dc573..d6c99cbd 100644 --- a/src/drivers/ao_packet_master.c +++ b/src/drivers/ao_packet_master.c @@ -145,7 +145,7 @@ ao_packet_forward(void) __reentrant  static void  ao_packet_signal(void)  { -	printf ("RSSI: %d\n", AO_RSSI_FROM_RADIO(ao_packet_last_rssi)); +	printf ("RSSI: %d\n", ao_radio_rssi);  }  __code struct ao_cmds ao_packet_master_cmds[] = { | 
