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] = {
10 +const uint8_t PROGMEM ASKSIN_CFG[] = {
18 - 0x17, 0x30, // always go into IDLE
19 + 0x17, 0x3F, // always go into RX after TX, CCA, ELV uses 0x03
39 - for (uint8_t i = 0; i<50; i += 2) {
41 - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
44 + for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
45 cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
46 pgm_read_byte(&ASKSIN_CFG[i+1]) );
49 ccStrobe( CC1100_SCAL );
59 uint8_t dec[MAX_ASKSIN_MSG];
67 // see if a CRC OK pkt has been arrived
68 if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
69 + while((rxfifo_cnt = cc1100_readReg(CC1100_RXBYTES)) != 0x00) {
70 + if (rxfifo_cnt & 0x80) // Overflow
73 - enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
74 + enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
76 - if (enc[0]>=MAX_ASKSIN_MSG)
77 - enc[0] = MAX_ASKSIN_MSG-1;
80 - cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
82 - for (uint8_t i=0; i<enc[0]; i++) {
83 - enc[i+1] = cc1100_sendbyte( 0 );
86 - rssi = cc1100_sendbyte( 0 );
89 + if (enc[0]>=MAX_ASKSIN_MSG)
90 + enc[0] = MAX_ASKSIN_MSG-1;
93 + cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
95 + for (uint8_t i=0; i<enc[0]; i++) {
96 + enc[i+1] = cc1100_sendbyte( 0 );
99 + rssi = cc1100_sendbyte( 0 );
100 + /* LQI = */ cc1100_sendbyte( 0 );
102 - ccStrobe( CC1100_SFRX );
103 - ccStrobe( CC1100_SIDLE );
104 - ccStrobe( CC1100_SNOP );
105 - ccStrobe( CC1100_SRX );
109 - dec[1] = (~enc[1]) ^ 0x89;
111 - for (l = 2; l < dec[0]; l++)
112 - dec[l] = (enc[l-1] + 0xdc) ^ enc[l];
114 - dec[l] = enc[l] ^ dec[2];
117 - if (tx_report & REP_BINTIME) {
118 + while(cc1100_readReg(CC1100_RXBYTES) & 0x7f)
119 + cc1100_readReg( CC1100_RXFIFO );
122 + dec[1] = (~enc[1]) ^ 0x89;
125 - for (uint8_t i=0; i<=dec[0]; i++)
130 + for (l = 2; l < dec[0]; l++)
131 + dec[l] = (enc[l-1] + 0xdc) ^ enc[l];
133 - for (uint8_t i=0; i<=dec[0]; i++)
135 + dec[l] = enc[l] ^ dec[2];
137 - if (tx_report & REP_RSSI)
141 + if (tx_report & REP_BINTIME) {
144 + for (uint8_t i=0; i<=dec[0]; i++)
150 + for (uint8_t i=0; i<=dec[0]; i++)
153 + if (tx_report & REP_RSSI)
165 - switch (cc1100_readReg( CC1100_MARCSTATE )) {
171 - ccStrobe( CC1100_SFRX );
172 - ccStrobe( CC1100_SIDLE );
173 - ccStrobe( CC1100_SNOP );
174 - ccStrobe( CC1100_SRX );
179 + switch(cc1100_readReg( CC1100_MARCSTATE )) {
180 + case MARCSTATE_RXFIFO_OVERFLOW:
181 + ccStrobe( CC1100_SFRX );
182 + case MARCSTATE_IDLE:
183 + ccStrobe( CC1100_SIDLE );
184 + ccStrobe( CC1100_SNOP );
185 + ccStrobe( CC1100_SRX );
192 my_delay_ms(3); // 3ms: Found by trial and error
195 - ccStrobe(CC1100_SIDLE);
196 - ccStrobe(CC1100_SFRX );
197 - ccStrobe(CC1100_SFTX );
199 - if (dec[2] & (1 << 4)) { //BURST-bit set?
200 - ccStrobe(CC1100_STX ); //We need to send a burst
202 - //According to ELV, devices get activated every 300ms, so send burst for 360ms
203 - for(l = 0; l < 3; l++)
204 - my_delay_ms(120); //arg is uint_8, so loop
210 enc[1] = (~dec[1]) ^ 0x89;
214 enc[l] = dec[l] ^ dec[2];
217 + if (dec[2] & (1 << 4)) { // BURST-bit set?
218 + // According to ELV, devices get activated every 300ms, so send burst for 360ms
219 + for(l = 0; l < 3; l++)
220 + my_delay_ms(120); // arg is uint_8, so loop
227 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
228 @@ -205,12 +194,17 @@
232 - ccStrobe( CC1100_SFRX );
233 - ccStrobe( CC1100_STX );
234 + // wait for TX to finish
235 + while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
238 + if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
239 + ccStrobe( CC1100_SFTX );
240 + ccStrobe( CC1100_SIDLE );
241 + ccStrobe( CC1100_SNOP );
242 + ccStrobe( CC1100_SRX );
245 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )