X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fdrivers%2Fao_cc1120.c;h=1d28148ba2b4a74366a87c345cad72e6f9ebb02d;hb=bd21c050fd8b96b33ab6859c942bf55cf2b91868;hp=501b937004c1cd0264409f6a61a7ff9775f48d2b;hpb=f1ae622eff60e05c1f5d8f822a3cf6a85750c6cc;p=fw%2Faltos diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index 501b9370..1d28148b 100644 --- a/src/drivers/ao_cc1120.c +++ b/src/drivers/ao_cc1120.c @@ -29,17 +29,11 @@ uint8_t ao_radio_in_recv; #define CC1120_DEBUG AO_FEC_DEBUG #define CC1120_TRACE 0 -#if CC1120_TRACE -#define fec_dump_bytes(b,l,n) ao_fec_dump_bytes(b,l,n) -#else -#define fec_dump_bytes(b,l,n) -#endif - const uint32_t ao_radio_cal = 0x6ca333; #define FOSC 32000000 -#define ao_radio_select() ao_spi_get_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS) +#define ao_radio_select() ao_spi_get_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS,AO_SPI_SPEED_1MHz) #define ao_radio_deselect() ao_spi_put_mask(AO_CC1120_SPI_CS_PORT,(1 << AO_CC1120_SPI_CS_PIN),AO_CC1120_SPI_BUS) #define ao_radio_spi_send(d,l) ao_spi_send((d), (l), AO_CC1120_SPI_BUS) #define ao_radio_spi_send_fixed(d,l) ao_spi_send_fixed((d), (l), AO_CC1120_SPI_BUS) @@ -582,12 +576,12 @@ ao_radio_send(const void *d, uint8_t size) #define AO_RADIO_MAX_RECV 90 -uint8_t rx_data[(AO_RADIO_MAX_RECV + 4) * 2 * 8]; -uint16_t rx_data_count; -uint16_t rx_data_consumed; -uint16_t rx_data_cur; -uint8_t rx_ignore; -uint8_t rx_waiting; +static uint8_t rx_data[(AO_RADIO_MAX_RECV + 4) * 2 * 8]; +static uint16_t rx_data_count; +static uint16_t rx_data_consumed; +static uint16_t rx_data_cur; +static uint8_t rx_ignore; +static uint8_t rx_waiting; #if AO_PROFILE static uint32_t rx_start_tick, rx_packet_tick, rx_done_tick, rx_last_done_tick; @@ -611,8 +605,10 @@ ao_radio_rx_isr(void) rx_data[rx_data_cur++] = d; if (rx_waiting && rx_data_cur - rx_data_consumed >= AO_FEC_DECODE_BLOCK) { #if AO_PROFILE - if (rx_data_consumed == 0) + if (!rx_packet_tick) rx_packet_tick = ao_profile_tick(); + if (rx_data_cur < rx_data_count) + return; #endif rx_waiting = 0; ao_wakeup(&ao_radio_wake); @@ -636,6 +632,9 @@ ao_radio_rx_wait(void) if (ao_radio_abort) return 0; rx_data_consumed += AO_FEC_DECODE_BLOCK; +#if AO_PROFILE + return rx_data_cur - rx_data_consumed; +#endif return AO_FEC_DECODE_BLOCK; } @@ -655,6 +654,7 @@ ao_radio_recv(__xdata void *d, uint8_t size) } #if AO_PROFILE rx_start_tick = ao_profile_tick(); + rx_packet_tick = 0; #endif len = size + 2; /* CRC bytes */ len += 1 + ~(len & 1); /* 1 or two pad bytes */ @@ -696,12 +696,7 @@ ao_radio_recv(__xdata void *d, uint8_t size) ao_radio_put(); - /* Construct final packet */ - - if (ret && ((uint8_t *) d)[size] == 0 && ((uint8_t *)d)[size+1] == 0) - ((uint8_t *) d)[size + 1] = 0x80; - else - ((uint8_t *) d)[size + 1] = 0x00; + /* Store the received RSSI value; the crc-OK byte is already done */ ((uint8_t *) d)[size] = (uint8_t) rssi;