altos: Compute "real" RSSI value in radio code as needed
authorKeith Packard <keithp@keithp.com>
Tue, 30 Apr 2013 06:20:25 +0000 (23:20 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 8 May 2013 03:07:54 +0000 (20:07 -0700)
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>
src/cc1111/ao_radio.c
src/core/ao.h
src/core/ao_packet.h
src/core/ao_radio_cmac.c
src/drivers/ao_cc1120.c
src/drivers/ao_packet.c
src/drivers/ao_packet_master.c

index 07b0d1b5d3882c1f62826c7965e353ebf2a4ebf1..4842486b5e170c5625a5c5a9f3190e2381b32a6b 100644 (file)
@@ -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;
 }
index 2a8eb0423930d09a60457c94fcd64ec000db5306..6bcb3664925d5262871abaae9670ef6d397a0cd1 100644 (file)
@@ -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
index 6d121bb933d36431bf34453aa9b47e927cd7e8a3..b8426cf90d7d8cdd7397dfe406bbbdf344cdd626 100644 (file)
@@ -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);
index 4920b50ccb9bc954ba44dcc9aeb3ec54ac0025f4..3ca3c313fd7c1826a3c7a9f468adb0fb5677bc52 100644 (file)
@@ -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);
index 07ebf8356cf5f3e108d4eaa202fd64e19d840d03..b6b77a5a5249628a1f14773f747d93ec5fab70d0 100644 (file)
@@ -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;
index 802d4c9013f9bc1df21aee54dd4e4b44c2d3e9d9..8cdf85a94f9036648acf1332bfc94cb158567afd 100644 (file)
@@ -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
         */
index 4c0dc57303005e6132bfa961f88be5c3b6b86346..d6c99cbd89defb62b07a2def1b7964f8be2f9df9 100644 (file)
@@ -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[] = {