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[] = {
20 - 0x17, 0x30, // always go into IDLE
21 + 0x17, 0x33, // go into RX after TX, CCA; ELV uses 0x03
36 +static void rf_asksin_reset_rx(void);
45 - for (uint8_t i = 0; i<50; i += 2) {
47 - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
50 + for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
51 cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
52 pgm_read_byte(&ASKSIN_CFG[i+1]) );
55 ccStrobe( CC1100_SCAL );
64 +rf_asksin_reset_rx(void)
66 + ccStrobe( CC1100_SFRX );
67 + ccStrobe( CC1100_SIDLE );
68 + ccStrobe( CC1100_SNOP );
69 + ccStrobe( CC1100_SRX );
77 // see if a CRC OK pkt has been arrived
78 if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
80 enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
82 - if (enc[0]>=MAX_ASKSIN_MSG)
83 - enc[0] = MAX_ASKSIN_MSG-1;
85 + if (enc[0] >= MAX_ASKSIN_MSG) {
86 + // Something went horribly wrong, out of sync?
87 + rf_asksin_reset_rx();
92 cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
97 rssi = cc1100_sendbyte( 0 );
99 + l = cc1100_sendbyte( 0 );
103 - ccStrobe( CC1100_SFRX );
104 - ccStrobe( CC1100_SIDLE );
105 - ccStrobe( CC1100_SNOP );
106 ccStrobe( CC1100_SRX );
111 dec[l] = enc[l] ^ dec[2];
114 if (tx_report & REP_BINTIME) {
117 @@ -131,26 +140,17 @@
125 + switch(cc1100_readReg( CC1100_MARCSTATE )) {
126 + case MARCSTATE_RXFIFO_OVERFLOW:
127 + ccStrobe( CC1100_SFRX );
128 + case MARCSTATE_IDLE:
129 + ccStrobe( CC1100_SIDLE );
130 + ccStrobe( CC1100_SNOP );
131 + ccStrobe( CC1100_SRX );
136 - switch (cc1100_readReg( CC1100_MARCSTATE )) {
142 - ccStrobe( CC1100_SFRX );
143 - ccStrobe( CC1100_SIDLE );
144 - ccStrobe( CC1100_SNOP );
145 - ccStrobe( CC1100_SRX );
154 my_delay_ms(3); // 3ms: Found by trial and error
157 - ccStrobe(CC1100_SIDLE);
158 - ccStrobe(CC1100_SFRX );
159 - ccStrobe(CC1100_SFTX );
161 - if (dec[2] & (1 << 4)) { //BURST-bit set?
162 - ccStrobe(CC1100_STX ); //We need to send a burst
164 - //According to ELV, devices get activated every 300ms, so send burst for 360ms
165 - for(l = 0; l < 3; l++)
166 - my_delay_ms(120); //arg is uint_8, so loop
172 enc[1] = (~dec[1]) ^ 0x89;
176 enc[l] = dec[l] ^ dec[2];
179 + if (dec[2] & (1 << 4)) { // BURST-bit set?
180 + // According to ELV, devices get activated every 300ms, so send burst for 360ms
181 + for(l = 0; l < 3; l++)
182 + my_delay_ms(120); // arg is uint_8, so loop
189 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
190 @@ -205,12 +201,17 @@
194 - ccStrobe( CC1100_SFRX );
195 - ccStrobe( CC1100_STX );
196 + // wait for TX to finish
197 + while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
200 + if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
201 + ccStrobe( CC1100_SFTX );
202 + ccStrobe( CC1100_SIDLE );
203 + ccStrobe( CC1100_SNOP );
204 + ccStrobe( CC1100_SRX );
207 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )