1 Index: clib/rf_asksin.c
2 ===================================================================
3 --- clib/rf_asksin.c (revision 373)
4 +++ clib/rf_asksin.c (working copy)
9 -const uint8_t PROGMEM ASKSIN_CFG[50] = {
11 +const uint8_t PROGMEM ASKSIN_CFG[] = {
26 - 0x17, 0x30, // always go into IDLE
27 + 0x17, 0x3F, // always go into RX after TX, CCA, ELV uses 0x03
42 +static inline uint8_t read_cc1100_rxbytes(void);
43 +static inline void rf_asksin_reset_rx(void);
52 - for (uint8_t i = 0; i<50; i += 2) {
54 - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
57 + for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
58 cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
59 pgm_read_byte(&ASKSIN_CFG[i+1]) );
62 ccStrobe( CC1100_SCAL );
70 +// Workaround for CC1101 Errata 3
71 +static inline uint8_t
72 +read_cc1100_rxbytes(void)
74 + uint8_t rxbytes, rxbytes2;
76 + rxbytes = cc1100_readReg(CC1100_RXBYTES);
77 + while((rxbytes2 = cc1100_readReg(CC1100_RXBYTES)) != rxbytes)
84 +rf_asksin_reset_rx(void)
86 + ccStrobe( CC1100_SFRX );
87 + ccStrobe( CC1100_SIDLE );
88 + ccStrobe( CC1100_SNOP );
90 + while (read_cc1100_rxbytes() & 0x7f)
91 + cc1100_readReg(CC1100_RXFIFO);
93 + ccStrobe( CC1100_SRX );
100 uint8_t dec[MAX_ASKSIN_MSG];
103 + uint8_t rxfifo_cnt;
108 - // see if a CRC OK pkt has been arrived
109 - if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
110 + // see if there is data to be read
111 + while (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
112 + rxfifo_cnt = read_cc1100_rxbytes();
114 + if (rxfifo_cnt & 0x80) // Overflow
117 + rxfifo_cnt &= 0x7f;
119 enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
122 - if (enc[0]>=MAX_ASKSIN_MSG)
123 - enc[0] = MAX_ASKSIN_MSG-1;
125 + if (enc[0] >= MAX_ASKSIN_MSG) {
126 + // Something went horribly wrong, out of sync?
127 + rf_asksin_reset_rx();
132 + while (l-- && ((enc[0] + 2) < rxfifo_cnt)) { // Wait for more data
134 + rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f);
138 + // Not enough data received, out of sync?
139 + rf_asksin_reset_rx();
144 cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
149 rssi = cc1100_sendbyte( 0 );
154 - ccStrobe( CC1100_SFRX );
155 - ccStrobe( CC1100_SIDLE );
156 - ccStrobe( CC1100_SNOP );
157 - ccStrobe( CC1100_SRX );
158 + // We must not read the last byte from the RX fifo while RX is in progress (Errata 1)
159 + while (((read_cc1100_rxbytes() & 0x7f) == 1) && (cc1100_readReg(CC1100_PKTSTATUS) & (1 << 3))) {
163 + l = cc1100_readReg(CC1100_RXFIFO);
165 + if (!(l & 0x80)) // CRC not ok
169 dec[1] = (~enc[1]) ^ 0x89;
173 dec[l] = enc[l] ^ dec[2];
176 if (tx_report & REP_BINTIME) {
179 @@ -131,26 +186,17 @@
187 + switch(cc1100_readReg( CC1100_MARCSTATE )) {
188 + case MARCSTATE_RXFIFO_OVERFLOW:
189 + ccStrobe( CC1100_SFRX );
190 + case MARCSTATE_IDLE:
191 + ccStrobe( CC1100_SIDLE );
192 + ccStrobe( CC1100_SNOP );
193 + ccStrobe( CC1100_SRX );
198 - switch (cc1100_readReg( CC1100_MARCSTATE )) {
204 - ccStrobe( CC1100_SFRX );
205 - ccStrobe( CC1100_SIDLE );
206 - ccStrobe( CC1100_SNOP );
207 - ccStrobe( CC1100_SRX );
216 my_delay_ms(3); // 3ms: Found by trial and error
219 - ccStrobe(CC1100_SIDLE);
220 - ccStrobe(CC1100_SFRX );
221 - ccStrobe(CC1100_SFTX );
223 - if (dec[2] & (1 << 4)) { //BURST-bit set?
224 - ccStrobe(CC1100_STX ); //We need to send a burst
226 - //According to ELV, devices get activated every 300ms, so send burst for 360ms
227 - for(l = 0; l < 3; l++)
228 - my_delay_ms(120); //arg is uint_8, so loop
234 enc[1] = (~dec[1]) ^ 0x89;
238 enc[l] = dec[l] ^ dec[2];
241 + if (dec[2] & (1 << 4)) { // BURST-bit set?
242 + // According to ELV, devices get activated every 300ms, so send burst for 360ms
243 + for(l = 0; l < 3; l++)
244 + my_delay_ms(120); // arg is uint_8, so loop
251 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
252 @@ -205,12 +247,17 @@
256 - ccStrobe( CC1100_SFRX );
257 - ccStrobe( CC1100_STX );
258 + // wait for TX to finish
259 + while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
262 + if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
263 + ccStrobe( CC1100_SFTX );
264 + ccStrobe( CC1100_SIDLE );
265 + ccStrobe( CC1100_SNOP );
266 + ccStrobe( CC1100_SRX );
269 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )