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 if (enc[0]>=MAX_ASKSIN_MSG)
107 enc[0] = MAX_ASKSIN_MSG-1;
110 + while ((enc[0] + 2) < (rxfifo_cnt - 1)) { // Wait for more data
112 + rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f) + 1;
116 cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
121 rssi = cc1100_sendbyte( 0 );
123 + l = cc1100_sendbyte( 0 );
127 - ccStrobe( CC1100_SFRX );
128 - ccStrobe( CC1100_SIDLE );
129 - ccStrobe( CC1100_SNOP );
130 - ccStrobe( CC1100_SRX );
131 + if (!(l & 0x80)) // CRC not ok
135 dec[1] = (~enc[1]) ^ 0x89;
138 dec[l] = enc[l] ^ dec[2];
141 if (tx_report & REP_BINTIME) {
144 @@ -131,26 +154,17 @@
152 + switch(cc1100_readReg( CC1100_MARCSTATE )) {
153 + case MARCSTATE_RXFIFO_OVERFLOW:
154 + ccStrobe( CC1100_SFRX );
155 + case MARCSTATE_IDLE:
156 + ccStrobe( CC1100_SIDLE );
157 + ccStrobe( CC1100_SNOP );
158 + ccStrobe( CC1100_SRX );
163 - switch (cc1100_readReg( CC1100_MARCSTATE )) {
169 - ccStrobe( CC1100_SFRX );
170 - ccStrobe( CC1100_SIDLE );
171 - ccStrobe( CC1100_SNOP );
172 - ccStrobe( CC1100_SRX );
181 my_delay_ms(3); // 3ms: Found by trial and error
184 - ccStrobe(CC1100_SIDLE);
185 - ccStrobe(CC1100_SFRX );
186 - ccStrobe(CC1100_SFTX );
188 - if (dec[2] & (1 << 4)) { //BURST-bit set?
189 - ccStrobe(CC1100_STX ); //We need to send a burst
191 - //According to ELV, devices get activated every 300ms, so send burst for 360ms
192 - for(l = 0; l < 3; l++)
193 - my_delay_ms(120); //arg is uint_8, so loop
199 enc[1] = (~dec[1]) ^ 0x89;
203 enc[l] = dec[l] ^ dec[2];
206 + if (dec[2] & (1 << 4)) { // BURST-bit set?
207 + // According to ELV, devices get activated every 300ms, so send burst for 360ms
208 + for(l = 0; l < 3; l++)
209 + my_delay_ms(120); // arg is uint_8, so loop
216 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
217 @@ -205,12 +215,17 @@
221 - ccStrobe( CC1100_SFRX );
222 - ccStrobe( CC1100_STX );
223 + // wait for TX to finish
224 + while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
227 + if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
228 + ccStrobe( CC1100_SFTX );
229 + ccStrobe( CC1100_SIDLE );
230 + ccStrobe( CC1100_SNOP );
231 + ccStrobe( CC1100_SRX );
234 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )