From f4c812bef76a2cd95f675cb27ea89059561ceec7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 13 Feb 2015 23:51:10 -0800 Subject: altos: Replace ao_alarm/ao_clear_alarm with ao_sleep_for Having arbitrary alarms firing in the middle of complicated device logic makes no sense at all. Therefore only correct use of ao_alarm and ao_clear_alarm was around a specific ao_sleep call, with correct recovery in case the alarm fires. This patch replaces all uses of ao_alarm/ao_sleep/ao_clear_alarm with ao_sleep_for, a new function which takes the alarm timeout directly. A few cases which weren't simply calling ao_sleep have been reworked to pass the timeout value down to the place where sleep *is* being called, and having that code deal with the return correctly. Signed-off-by: Keith Packard --- src/drivers/ao_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/drivers/ao_packet.c') diff --git a/src/drivers/ao_packet.c b/src/drivers/ao_packet.c index 8cdf85a9..18330ead 100644 --- a/src/drivers/ao_packet.c +++ b/src/drivers/ao_packet.c @@ -54,14 +54,14 @@ ao_packet_send(void) } uint8_t -ao_packet_recv(void) +ao_packet_recv(uint16_t timeout) { uint8_t dma_done; #ifdef AO_LED_GREEN ao_led_on(AO_LED_GREEN); #endif - dma_done = ao_radio_recv(&ao_rx_packet, sizeof (struct ao_packet_recv), 0); + dma_done = ao_radio_recv(&ao_rx_packet, sizeof (struct ao_packet_recv), timeout); #ifdef AO_LED_GREEN ao_led_off(AO_LED_GREEN); #endif -- cgit v1.2.3 From 135abf0e7c5ceb5738a0b5f68fe2be4b7abdae5e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 14 Feb 2015 23:18:38 -0800 Subject: altos/cc1200: Adjust bit-sync configuration The default bit timing adjustment mechanism allows for only a 0.2% deviation from the programmed bit timing. I found one TeleMini device which is beyond that tolerance as it was built with an older crystal with more error. Switch to the more expensive synchronization mechanism which allows up to 2% timing error, but requires a multi-byte preamble (which we have). This fixes packet mode nicely. Signed-off-by: Keith Packard --- src/drivers/ao_cc1200.h | 32 ++++++++++++++++++++++++++++++++ src/drivers/ao_cc1200_CC1200.h | 9 +++++++++ src/drivers/ao_packet.c | 14 ++++++++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) (limited to 'src/drivers/ao_packet.c') diff --git a/src/drivers/ao_cc1200.h b/src/drivers/ao_cc1200.h index b04775fd..b2b63cde 100644 --- a/src/drivers/ao_cc1200.h +++ b/src/drivers/ao_cc1200.h @@ -438,6 +438,38 @@ #define CC1200_IF_MIX_CFG (CC1200_EXTENDED_BIT | 0x00) #define CC1200_FREQOFF_CFG (CC1200_EXTENDED_BIT | 0x01) #define CC1200_TOC_CFG (CC1200_EXTENDED_BIT | 0x02) + +#define CC1200_TOC_CFG_TOC_LIMIT 6 +#define CC1200_TOC_CFG_TOC_LIMIT_0_2 0 +#define CC1200_TOC_CFG_TOC_LIMIT_2 1 +#define CC1200_TOC_CFG_TOC_LIMIT_12 3 + +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN 3 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_8 0 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_16 1 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_32 2 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_64 3 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_128 4 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_256 5 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_8_16 0 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_6_16 1 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_2_16 2 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_1_16 3 +#define CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_1_16_SYNC 4 + +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN 0 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_8 0 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_16 1 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_32 2 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_64 3 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_128 4 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_256 5 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_FREEZE 0 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_6_32 1 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_2_32 2 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_1_32 3 +#define CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_1_32_SYNC 4 + #define CC1200_MARC_SPARE (CC1200_EXTENDED_BIT | 0x03) #define CC1200_ECG_CFG (CC1200_EXTENDED_BIT | 0x04) #define CC1200_MDMCFG2 (CC1200_EXTENDED_BIT | 0x05) diff --git a/src/drivers/ao_cc1200_CC1200.h b/src/drivers/ao_cc1200_CC1200.h index 35673123..f0214c2a 100644 --- a/src/drivers/ao_cc1200_CC1200.h +++ b/src/drivers/ao_cc1200_CC1200.h @@ -101,6 +101,15 @@ (CC1200_MDMCFG2_SYMBOL_MAP_CFG_MODE_0 << CC1200_MDMCFG2_SYMBOL_MAP_CFG) | (CC1200_MDMCFG2_UPSAMPLER_P_8 << CC1200_MDMCFG2_UPSAMPLER_P) | (0 << CC1200_MDMCFG2_CFM_DATA_EN)), + CC1200_MDMCFG0, /* General Modem Parameter Configuration Reg. 0 */ + ((0 << CC1200_MDMCFG0_TRANSPARENT_MODE_EN) | + (0 << CC1200_MDMCFG0_TRANSPARENT_INTFACT) | + (0 << CC1200_MDMCFG0_DATA_FILTER_EN) | + (1 << CC1200_MDMCFG0_VITERBI_EN)), + CC1200_TOC_CFG, /* Timing Offset Correction Configuration */ + ((CC1200_TOC_CFG_TOC_LIMIT_2 << CC1200_TOC_CFG_TOC_LIMIT) | + (CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN_6_16 << CC1200_TOC_CFG_TOC_PRE_SYNC_BLOCKLEN)| + (CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN_2_32 << CC1200_TOC_CFG_TOC_POST_SYNC_BLOCKLEN)), CC1200_FREQ2, 0x6c, /* Frequency Configuration [23:16] */ CC1200_FREQ1, 0xa3, /* Frequency Configuration [15:8] */ CC1200_FREQ0, 0x33, /* Frequency Configuration [7:0] */ diff --git a/src/drivers/ao_packet.c b/src/drivers/ao_packet.c index 18330ead..8c2db275 100644 --- a/src/drivers/ao_packet.c +++ b/src/drivers/ao_packet.c @@ -81,8 +81,16 @@ ao_packet_recv(uint16_t timeout) /* Check to see if we got a valid packet */ if (!dma_done) return 0; - if (!(ao_rx_packet.status & AO_RADIO_STATUS_CRC_OK)) + if (!(ao_rx_packet.status & AO_RADIO_STATUS_CRC_OK)) { + printf("bad crc addr %d len %d seq %d ack %d callsign %8.8s\n", + ao_rx_packet.packet.addr, + ao_rx_packet.packet.len, + ao_rx_packet.packet.seq, + ao_rx_packet.packet.ack, + ao_rx_packet.packet.callsign); + flush(); return 0; + } /* Accept packets with matching call signs, or any packet if * our callsign hasn't been configured @@ -90,8 +98,10 @@ ao_packet_recv(uint16_t timeout) if (ao_xmemcmp(ao_rx_packet.packet.callsign, ao_config.callsign, AO_MAX_CALLSIGN) != 0 && - ao_xmemcmp(ao_config.callsign, CODE_TO_XDATA("N0CALL"), 7) != 0) + ao_xmemcmp(ao_config.callsign, CODE_TO_XDATA("N0CALL"), 7) != 0) { + printf ("bad call\n"); flush(); return 0; + } /* SYN packets carry no data */ if (ao_rx_packet.packet.len == AO_PACKET_SYN) { -- cgit v1.2.3 From 2ebb4dff758058ae9512cf36518416eb69b928f0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 15 Feb 2015 08:57:55 -0800 Subject: altos: Remove some accidental debug printfs from ao_packet.c While fixing the cc1200 configuration, I added some debug printfs to this code. They were accidentally committed with the fix... Signed-off-by: Keith Packard --- src/drivers/ao_packet.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/drivers/ao_packet.c') diff --git a/src/drivers/ao_packet.c b/src/drivers/ao_packet.c index 8c2db275..18330ead 100644 --- a/src/drivers/ao_packet.c +++ b/src/drivers/ao_packet.c @@ -81,16 +81,8 @@ ao_packet_recv(uint16_t timeout) /* Check to see if we got a valid packet */ if (!dma_done) return 0; - if (!(ao_rx_packet.status & AO_RADIO_STATUS_CRC_OK)) { - printf("bad crc addr %d len %d seq %d ack %d callsign %8.8s\n", - ao_rx_packet.packet.addr, - ao_rx_packet.packet.len, - ao_rx_packet.packet.seq, - ao_rx_packet.packet.ack, - ao_rx_packet.packet.callsign); - flush(); + if (!(ao_rx_packet.status & AO_RADIO_STATUS_CRC_OK)) return 0; - } /* Accept packets with matching call signs, or any packet if * our callsign hasn't been configured @@ -98,10 +90,8 @@ ao_packet_recv(uint16_t timeout) if (ao_xmemcmp(ao_rx_packet.packet.callsign, ao_config.callsign, AO_MAX_CALLSIGN) != 0 && - ao_xmemcmp(ao_config.callsign, CODE_TO_XDATA("N0CALL"), 7) != 0) { - printf ("bad call\n"); flush(); + ao_xmemcmp(ao_config.callsign, CODE_TO_XDATA("N0CALL"), 7) != 0) return 0; - } /* SYN packets carry no data */ if (ao_rx_packet.packet.len == AO_PACKET_SYN) { -- cgit v1.2.3