X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fdrivers%2Fao_cc1120.c;h=772014ee175f0087be15537b91f81e7ef15c1348;hb=3876b5bfad383119339aea51e2cf301012a1f991;hp=07ebf8356cf5f3e108d4eaa202fd64e19d840d03;hpb=f09b2fc7fcfb1b3dcb1a46a8b9856092dd59866b;p=fw%2Faltos diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index 07ebf835..772014ee 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 @@ -390,16 +392,15 @@ static const uint16_t rdf_setup[] = { }; /* - * APRS deviation is 5kHz + * APRS deviation is 3kHz * * fdev = fosc >> 24 * (256 + dev_m) << dev_e * - * 32e6Hz / (2 ** 24) * (256 + 71) * (2 ** 3) = 4989 + * 32e6Hz / (2 ** 24) * (256 + 137) * (2 ** 2) = 2998Hz */ -#define APRS_DEV_E 3 -#define APRS_DEV_M 71 -#define APRS_PACKET_LEN 50 +#define APRS_DEV_E 2 +#define APRS_DEV_M 137 /* * For our APRS beacon, set the symbol rate to 9.6kBaud (8x oversampling for 1200 baud data rate) @@ -552,6 +553,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 +911,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; @@ -960,8 +963,10 @@ ao_radio_recv(__xdata void *d, uint8_t size, uint8_t timeout) /* Wait for the preamble to appear */ ao_radio_wait_isr(timeout); - if (ao_radio_abort) + if (ao_radio_abort) { + ret = 0; goto abort; + } ao_radio_reg_write(AO_CC1120_INT_GPIO_IOCFG, CC1120_IOCFG_GPIO_CFG_CLKEN_SOFT); ao_exti_set_mode(AO_CC1120_INT_PORT, AO_CC1120_INT_PIN, @@ -977,17 +982,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;