]>
Commit | Line | Data |
---|---|---|
b2720844 MG |
1 | Index: clib/rf_asksin.c |
2 | =================================================================== | |
3 | --- clib/rf_asksin.c (revision 373) | |
4 | +++ clib/rf_asksin.c (working copy) | |
532a7bf0 | 5 | @@ -11,13 +11,13 @@ |
b2720844 MG |
6 | |
7 | uint8_t asksin_on = 0; | |
8 | ||
9 | -const uint8_t PROGMEM ASKSIN_CFG[50] = { | |
532a7bf0 | 10 | - 0x00, 0x07, |
b2720844 | 11 | +const uint8_t PROGMEM ASKSIN_CFG[] = { |
532a7bf0 | 12 | + 0x00, 0x01, |
b2720844 MG |
13 | 0x02, 0x2e, |
14 | 0x03, 0x0d, | |
532a7bf0 MG |
15 | 0x04, 0xE9, |
16 | 0x05, 0xCA, | |
17 | - 0x07, 0x0C, | |
18 | + 0x07, 0x04, | |
19 | 0x0B, 0x06, | |
20 | 0x0D, 0x21, | |
21 | 0x0E, 0x65, | |
22 | @@ -26,18 +26,21 @@ | |
b2720844 MG |
23 | 0x11, 0x93, |
24 | 0x12, 0x03, | |
25 | 0x15, 0x34, | |
26 | - 0x17, 0x30, // always go into IDLE | |
cf4474a9 | 27 | + 0x17, 0x3F, // always go into RX after TX, CCA, ELV uses 0x03 |
b2720844 MG |
28 | 0x18, 0x18, |
29 | 0x19, 0x16, | |
30 | 0x1B, 0x43, | |
31 | 0x21, 0x56, | |
32 | 0x25, 0x00, | |
33 | 0x26, 0x11, | |
34 | + 0x29, 0x59, | |
35 | + 0x2c, 0x81, | |
36 | 0x2D, 0x35, | |
777ef621 | 37 | - 0x3e, 0xc3, |
b2720844 | 38 | - 0xff |
777ef621 | 39 | + 0x3e, 0xc3 |
b2720844 MG |
40 | }; |
41 | ||
532a7bf0 MG |
42 | +static inline uint8_t read_cc1100_rxbytes(); |
43 | + | |
b2720844 | 44 | void |
532a7bf0 MG |
45 | rf_asksin_init(void) |
46 | { | |
47 | @@ -56,20 +59,30 @@ | |
b2720844 MG |
48 | my_delay_us(100); |
49 | ||
50 | // load configuration | |
51 | - for (uint8_t i = 0; i<50; i += 2) { | |
777ef621 MG |
52 | - |
53 | - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40) | |
54 | - break; | |
55 | - | |
b2720844 | 56 | + for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) { |
777ef621 MG |
57 | cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]), |
58 | pgm_read_byte(&ASKSIN_CFG[i+1]) ); | |
59 | } | |
b2720844 MG |
60 | |
61 | ccStrobe( CC1100_SCAL ); | |
62 | ||
63 | - my_delay_ms(1); | |
64 | + my_delay_ms(4); | |
65 | + | |
66 | + ccRX(); | |
67 | } | |
68 | ||
532a7bf0 MG |
69 | +// Workaround for CC1101 Errata 3 |
70 | +static inline uint8_t read_cc1100_rxbytes() | |
71 | +{ | |
72 | + uint8_t rxbytes, rxbytes2; | |
73 | + | |
74 | + rxbytes = cc1100_readReg(CC1100_RXBYTES); | |
75 | + while((rxbytes2 = cc1100_readReg(CC1100_RXBYTES)) != rxbytes) | |
76 | + rxbytes = rxbytes2; | |
77 | + | |
78 | + return rxbytes; | |
79 | +} | |
80 | + | |
b2720844 | 81 | void |
532a7bf0 MG |
82 | rf_asksin_task(void) |
83 | { | |
84 | @@ -77,15 +90,27 @@ | |
cf4474a9 MG |
85 | uint8_t dec[MAX_ASKSIN_MSG]; |
86 | uint8_t rssi; | |
87 | uint8_t l; | |
88 | + uint8_t rxfifo_cnt; | |
89 | ||
90 | if(!asksin_on) | |
91 | return; | |
92 | ||
532a7bf0 MG |
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(); | |
cf4474a9 | 98 | |
532a7bf0 MG |
99 | + if (rxfifo_cnt & 0x80) // Overflow |
100 | + break; | |
101 | + | |
102 | + rxfifo_cnt &= 0x7f; | |
103 | + | |
104 | enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len | |
cf4474a9 | 105 | |
532a7bf0 MG |
106 | + while ((enc[0] + 2) < (rxfifo_cnt - 1)) { // Wait for more data |
107 | + my_delay_ms(1); | |
108 | + rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f) + 1; | |
109 | + } | |
110 | + | |
111 | if (enc[0]>=MAX_ASKSIN_MSG) | |
112 | enc[0] = MAX_ASKSIN_MSG-1; | |
113 | ||
114 | @@ -97,13 +122,12 @@ | |
115 | } | |
116 | ||
117 | rssi = cc1100_sendbyte( 0 ); | |
cf4474a9 | 118 | - |
532a7bf0 MG |
119 | + l = cc1100_sendbyte( 0 ); |
120 | + | |
121 | CC1100_DEASSERT; | |
b2720844 MG |
122 | |
123 | - ccStrobe( CC1100_SFRX ); | |
124 | - ccStrobe( CC1100_SIDLE ); | |
125 | - ccStrobe( CC1100_SNOP ); | |
126 | - ccStrobe( CC1100_SRX ); | |
532a7bf0 MG |
127 | + if (!(l & 0x80)) // CRC not ok |
128 | + continue; | |
129 | ||
130 | dec[0] = enc[0]; | |
131 | dec[1] = (~enc[1]) ^ 0x89; | |
132 | @@ -113,7 +137,6 @@ | |
133 | ||
134 | dec[l] = enc[l] ^ dec[2]; | |
135 | ||
b2720844 | 136 | - |
532a7bf0 | 137 | if (tx_report & REP_BINTIME) { |
cf4474a9 | 138 | |
532a7bf0 MG |
139 | DC('a'); |
140 | @@ -131,26 +154,17 @@ | |
cf4474a9 | 141 | |
532a7bf0 | 142 | DNL(); |
b2720844 | 143 | } |
532a7bf0 MG |
144 | + } |
145 | ||
cf4474a9 | 146 | - return; |
b2720844 | 147 | - |
532a7bf0 MG |
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 ); | |
155 | + break; | |
b2720844 MG |
156 | } |
157 | - | |
158 | - | |
159 | - switch (cc1100_readReg( CC1100_MARCSTATE )) { | |
160 | - | |
161 | - // RX_OVERFLOW | |
162 | - case 17: | |
163 | - // IDLE | |
164 | - case 1: | |
165 | - ccStrobe( CC1100_SFRX ); | |
166 | - ccStrobe( CC1100_SIDLE ); | |
167 | - ccStrobe( CC1100_SNOP ); | |
168 | - ccStrobe( CC1100_SRX ); | |
169 | - break; | |
170 | - | |
171 | - } | |
532a7bf0 | 172 | - |
b2720844 MG |
173 | } |
174 | ||
175 | void | |
532a7bf0 | 176 | @@ -173,20 +187,7 @@ |
b2720844 MG |
177 | my_delay_ms(3); // 3ms: Found by trial and error |
178 | } | |
179 | ||
180 | - ccStrobe(CC1100_SIDLE); | |
181 | - ccStrobe(CC1100_SFRX ); | |
182 | - ccStrobe(CC1100_SFTX ); | |
183 | - | |
184 | - if (dec[2] & (1 << 4)) { //BURST-bit set? | |
185 | - ccStrobe(CC1100_STX ); //We need to send a burst | |
186 | - | |
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 | |
190 | - } | |
191 | - | |
192 | // "crypt" | |
193 | - | |
194 | enc[0] = dec[0]; | |
195 | enc[1] = (~dec[1]) ^ 0x89; | |
196 | ||
532a7bf0 | 197 | @@ -195,6 +196,15 @@ |
b2720844 MG |
198 | |
199 | enc[l] = dec[l] ^ dec[2]; | |
200 | ||
201 | + ccTX(); | |
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 | |
5f2228fc MG |
206 | + } else { |
207 | + my_delay_ms(10); | |
b2720844 MG |
208 | + } |
209 | + | |
210 | // send | |
211 | CC1100_ASSERT; | |
212 | cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO); | |
532a7bf0 | 213 | @@ -205,12 +215,17 @@ |
b2720844 MG |
214 | |
215 | CC1100_DEASSERT; | |
216 | ||
217 | - ccStrobe( CC1100_SFRX ); | |
218 | - ccStrobe( CC1100_STX ); | |
219 | + // wait for TX to finish | |
220 | + while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX) | |
221 | + ; | |
777ef621 MG |
222 | + |
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 ); | |
228 | + } | |
b2720844 MG |
229 | |
230 | - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 ) | |
231 | - my_delay_ms(5); | |
232 | - | |
233 | if(asksin_on) { | |
234 | ccRX(); | |
235 | } else { |