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();
51 - for (uint8_t i = 0; i<50; i += 2) {
53 - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
56 + for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
57 cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
58 pgm_read_byte(&ASKSIN_CFG[i+1]) );
61 ccStrobe( CC1100_SCAL );
69 +// Workaround for CC1101 Errata 3
70 +static inline uint8_t read_cc1100_rxbytes()
72 + uint8_t rxbytes, rxbytes2;
74 + rxbytes = cc1100_readReg(CC1100_RXBYTES);
75 + while((rxbytes2 = cc1100_readReg(CC1100_RXBYTES)) != rxbytes)
85 uint8_t dec[MAX_ASKSIN_MSG];
93 - // see if a CRC OK pkt has been arrived
94 - if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
95 + // see if there is data to be read
96 + while (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
97 + rxfifo_cnt = read_cc1100_rxbytes();
99 + if (rxfifo_cnt & 0x80) // Overflow
102 + rxfifo_cnt &= 0x7f;
104 enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
106 + while ((enc[0] + 2) < (rxfifo_cnt - 1)) { // Wait for more data
108 + rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f) + 1;
111 if (enc[0]>=MAX_ASKSIN_MSG)
112 enc[0] = MAX_ASKSIN_MSG-1;
117 rssi = cc1100_sendbyte( 0 );
119 + l = cc1100_sendbyte( 0 );
123 - ccStrobe( CC1100_SFRX );
124 - ccStrobe( CC1100_SIDLE );
125 - ccStrobe( CC1100_SNOP );
126 - ccStrobe( CC1100_SRX );
127 + if (!(l & 0x80)) // CRC not ok
131 dec[1] = (~enc[1]) ^ 0x89;
134 dec[l] = enc[l] ^ dec[2];
137 if (tx_report & REP_BINTIME) {
140 @@ -131,26 +154,17 @@
148 + switch(cc1100_readReg( CC1100_MARCSTATE )) {
149 + case MARCSTATE_RXFIFO_OVERFLOW:
150 + ccStrobe( CC1100_SFRX );
151 + case MARCSTATE_IDLE:
152 + ccStrobe( CC1100_SIDLE );
153 + ccStrobe( CC1100_SNOP );
154 + ccStrobe( CC1100_SRX );
159 - switch (cc1100_readReg( CC1100_MARCSTATE )) {
165 - ccStrobe( CC1100_SFRX );
166 - ccStrobe( CC1100_SIDLE );
167 - ccStrobe( CC1100_SNOP );
168 - ccStrobe( CC1100_SRX );
177 my_delay_ms(3); // 3ms: Found by trial and error
180 - ccStrobe(CC1100_SIDLE);
181 - ccStrobe(CC1100_SFRX );
182 - ccStrobe(CC1100_SFTX );
184 - if (dec[2] & (1 << 4)) { //BURST-bit set?
185 - ccStrobe(CC1100_STX ); //We need to send a burst
187 - //According to ELV, devices get activated every 300ms, so send burst for 360ms
188 - for(l = 0; l < 3; l++)
189 - my_delay_ms(120); //arg is uint_8, so loop
195 enc[1] = (~dec[1]) ^ 0x89;
199 enc[l] = dec[l] ^ dec[2];
202 + if (dec[2] & (1 << 4)) { // BURST-bit set?
203 + // According to ELV, devices get activated every 300ms, so send burst for 360ms
204 + for(l = 0; l < 3; l++)
205 + my_delay_ms(120); // arg is uint_8, so loop
212 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
213 @@ -205,12 +215,17 @@
217 - ccStrobe( CC1100_SFRX );
218 - ccStrobe( CC1100_STX );
219 + // wait for TX to finish
220 + while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
223 + if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
224 + ccStrobe( CC1100_SFTX );
225 + ccStrobe( CC1100_SIDLE );
226 + ccStrobe( CC1100_SNOP );
227 + ccStrobe( CC1100_SRX );
230 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )