1 Index: clib/rf_asksin.c
2 ===================================================================
3 --- clib/rf_asksin.c (revision 377)
4 +++ clib/rf_asksin.c (working copy)
9 +//we receive a new byte approximately every 8 ms...
10 +#define RX_TIMEOUT_MS 10
12 uint8_t asksin_on = 0;
14 const uint8_t PROGMEM ASKSIN_CFG[] = {
30 - 0x17, 0x33, // go into RX after TX, CCA; EQ3 uses 0x03
31 + 0x17, 0x3F, // always go into RX, CCA; EQ3 uses 0x03
39 +static inline uint8_t read_cc1100_rxbytes(void);
40 static void rf_asksin_reset_rx(void);
47 +// Workaround for CC1101 Errata 3
48 +static inline uint8_t
49 +read_cc1100_rxbytes(void)
51 + uint8_t rxbytes, rxbytes2;
53 + rxbytes = cc1100_readReg(CC1100_RXBYTES);
54 + while((rxbytes2 = cc1100_readReg(CC1100_RXBYTES)) != rxbytes)
61 rf_asksin_reset_rx(void)
63 ccStrobe( CC1100_SFRX );
64 ccStrobe( CC1100_SIDLE );
65 ccStrobe( CC1100_SNOP );
67 + while (read_cc1100_rxbytes() & 0x7f)
68 + cc1100_readReg(CC1100_RXFIFO);
70 ccStrobe( CC1100_SRX );
74 uint8_t dec[MAX_ASKSIN_MSG];
83 - // see if a CRC OK pkt has been arrived
84 - if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
85 + // see if there is data to be read
86 + while (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
87 + rxfifo_cnt = read_cc1100_rxbytes();
89 + if (rxfifo_cnt & 0x80) // Overflow
94 + // We must not read the last byte from the RX fifo while RX is in progress (Errata 1)
95 + while ((rxfifo_cnt < 2) && (cc1100_readReg(CC1100_PKTSTATUS) & (1 << 3))) {
97 + rxfifo_cnt = read_cc1100_rxbytes() & 0x7f;
100 enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
103 if (enc[0] >= MAX_ASKSIN_MSG) {
104 // Something went horribly wrong, out of sync?
109 + if ((enc[0] + 2) > rxfifo_cnt) {
110 + timeout = RX_TIMEOUT_MS * ((enc[0] + 2) - rxfifo_cnt);
111 + while (timeout-- && ((enc[0] + 2) > rxfifo_cnt)) { // Wait for more data
113 + rxfifo_cnt = read_cc1100_rxbytes();
115 + if (rxfifo_cnt & 0x80) { // Overflow
116 + rf_asksin_reset_rx();
120 + rxfifo_cnt &= 0x7f;
124 + // Not enough data received, out of sync?
125 + rf_asksin_reset_rx();
131 cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
133 @@ -109,12 +167,19 @@
136 rssi = cc1100_sendbyte( 0 );
137 - /* LQI = */ cc1100_sendbyte( 0 );
141 - ccStrobe( CC1100_SRX );
142 + // We must not read the last byte from the RX fifo while RX is in progress (Errata 1)
143 + while (((read_cc1100_rxbytes() & 0x7f) < 2) && (cc1100_readReg(CC1100_PKTSTATUS) & (1 << 3))) {
147 + l = cc1100_readReg(CC1100_RXFIFO);
149 + if (!(l & 0x80)) // CRC not ok
153 dec[1] = (~enc[1]) ^ 0x89;