]> git.zerfleddert.de Git - fhem-stuff/blame - culfw/culfw-asksin-fix.diff
better fix for receiving multiple packets, read them all from the fifo!
[fhem-stuff] / culfw / culfw-asksin-fix.diff
CommitLineData
b2720844
MG
1Index: clib/rf_asksin.c
2===================================================================
3--- clib/rf_asksin.c (revision 373)
4+++ clib/rf_asksin.c (working copy)
5@@ -11,7 +11,7 @@
6
7 uint8_t asksin_on = 0;
8
9-const uint8_t PROGMEM ASKSIN_CFG[50] = {
10+const uint8_t PROGMEM ASKSIN_CFG[] = {
11 0x00, 0x07,
12 0x02, 0x2e,
13 0x03, 0x0d,
777ef621 14@@ -26,16 +26,17 @@
b2720844
MG
15 0x11, 0x93,
16 0x12, 0x03,
17 0x15, 0x34,
18- 0x17, 0x30, // always go into IDLE
cf4474a9 19+ 0x17, 0x3F, // always go into RX after TX, CCA, ELV uses 0x03
b2720844
MG
20 0x18, 0x18,
21 0x19, 0x16,
22 0x1B, 0x43,
23 0x21, 0x56,
24 0x25, 0x00,
25 0x26, 0x11,
26+ 0x29, 0x59,
27+ 0x2c, 0x81,
28 0x2D, 0x35,
777ef621 29- 0x3e, 0xc3,
b2720844 30- 0xff
777ef621 31+ 0x3e, 0xc3
b2720844
MG
32 };
33
34 void
777ef621 35@@ -56,18 +57,16 @@
b2720844
MG
36 my_delay_us(100);
37
38 // load configuration
39- for (uint8_t i = 0; i<50; i += 2) {
777ef621
MG
40-
41- if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
42- break;
43-
b2720844 44+ for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
777ef621
MG
45 cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
46 pgm_read_byte(&ASKSIN_CFG[i+1]) );
47 }
b2720844
MG
48
49 ccStrobe( CC1100_SCAL );
50
51- my_delay_ms(1);
52+ my_delay_ms(4);
53+
54+ ccRX();
55 }
56
57 void
cf4474a9
MG
58@@ -77,80 +76,74 @@
59 uint8_t dec[MAX_ASKSIN_MSG];
60 uint8_t rssi;
61 uint8_t l;
62+ uint8_t rxfifo_cnt;
63
64 if(!asksin_on)
65 return;
66
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
71+ break;
72
73- enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
74+ enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
75
76- if (enc[0]>=MAX_ASKSIN_MSG)
77- enc[0] = MAX_ASKSIN_MSG-1;
65862dac 78-
cf4474a9
MG
79- CC1100_ASSERT;
80- cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
81-
82- for (uint8_t i=0; i<enc[0]; i++) {
83- enc[i+1] = cc1100_sendbyte( 0 );
84- }
85-
86- rssi = cc1100_sendbyte( 0 );
87-
88- CC1100_DEASSERT;
89+ if (enc[0]>=MAX_ASKSIN_MSG)
90+ enc[0] = MAX_ASKSIN_MSG-1;
91+
92+ CC1100_ASSERT;
93+ cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
94+
95+ for (uint8_t i=0; i<enc[0]; i++) {
96+ enc[i+1] = cc1100_sendbyte( 0 );
97+ }
98+
99+ rssi = cc1100_sendbyte( 0 );
100+ /* LQI = */ cc1100_sendbyte( 0 );
b2720844
MG
101
102- ccStrobe( CC1100_SFRX );
103- ccStrobe( CC1100_SIDLE );
104- ccStrobe( CC1100_SNOP );
105- ccStrobe( CC1100_SRX );
cf4474a9
MG
106+ CC1100_DEASSERT;
107
108- dec[0] = enc[0];
109- dec[1] = (~enc[1]) ^ 0x89;
110-
111- for (l = 2; l < dec[0]; l++)
112- dec[l] = (enc[l-1] + 0xdc) ^ enc[l];
113-
114- dec[l] = enc[l] ^ dec[2];
b2720844 115-
cf4474a9
MG
116-
117- if (tx_report & REP_BINTIME) {
118+ while(cc1100_readReg(CC1100_RXBYTES) & 0x7f)
119+ cc1100_readReg( CC1100_RXFIFO );
120+
121+ dec[0] = enc[0];
122+ dec[1] = (~enc[1]) ^ 0x89;
b2720844 123
cf4474a9
MG
124- DC('a');
125- for (uint8_t i=0; i<=dec[0]; i++)
126- DC( dec[i] );
127-
128- } else {
129- DC('A');
130+ for (l = 2; l < dec[0]; l++)
131+ dec[l] = (enc[l-1] + 0xdc) ^ enc[l];
132
133- for (uint8_t i=0; i<=dec[0]; i++)
134- DH2( dec[i] );
135+ dec[l] = enc[l] ^ dec[2];
136
137- if (tx_report & REP_RSSI)
138- DH2(rssi);
139-
140- DNL();
141+ if (tx_report & REP_BINTIME) {
142+
143+ DC('a');
144+ for (uint8_t i=0; i<=dec[0]; i++)
145+ DC( dec[i] );
146+
147+ } else {
148+ DC('A');
149+
150+ for (uint8_t i=0; i<=dec[0]; i++)
151+ DH2( dec[i] );
152+
153+ if (tx_report & REP_RSSI)
154+ DH2(rssi);
155+
156+ DNL();
157+ }
b2720844 158 }
cf4474a9
MG
159-
160- return;
b2720844
MG
161-
162 }
163-
164-
165- switch (cc1100_readReg( CC1100_MARCSTATE )) {
166-
167- // RX_OVERFLOW
168- case 17:
169- // IDLE
170- case 1:
171- ccStrobe( CC1100_SFRX );
172- ccStrobe( CC1100_SIDLE );
173- ccStrobe( CC1100_SNOP );
174- ccStrobe( CC1100_SRX );
175- break;
176-
177- }
178
65862dac
MG
179+ switch(cc1100_readReg( CC1100_MARCSTATE )) {
180+ case MARCSTATE_RXFIFO_OVERFLOW:
b2720844 181+ ccStrobe( CC1100_SFRX );
65862dac 182+ case MARCSTATE_IDLE:
b2720844
MG
183+ ccStrobe( CC1100_SIDLE );
184+ ccStrobe( CC1100_SNOP );
185+ ccStrobe( CC1100_SRX );
65862dac 186+ break;
b2720844
MG
187+ }
188 }
189
190 void
cf4474a9 191@@ -173,20 +166,7 @@
b2720844
MG
192 my_delay_ms(3); // 3ms: Found by trial and error
193 }
194
195- ccStrobe(CC1100_SIDLE);
196- ccStrobe(CC1100_SFRX );
197- ccStrobe(CC1100_SFTX );
198-
199- if (dec[2] & (1 << 4)) { //BURST-bit set?
200- ccStrobe(CC1100_STX ); //We need to send a burst
201-
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
205- }
206-
207 // "crypt"
208-
209 enc[0] = dec[0];
210 enc[1] = (~dec[1]) ^ 0x89;
211
cf4474a9 212@@ -195,6 +175,15 @@
b2720844
MG
213
214 enc[l] = dec[l] ^ dec[2];
215
216+ ccTX();
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
5f2228fc
MG
221+ } else {
222+ my_delay_ms(10);
b2720844
MG
223+ }
224+
225 // send
226 CC1100_ASSERT;
227 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
cf4474a9 228@@ -205,12 +194,17 @@
b2720844
MG
229
230 CC1100_DEASSERT;
231
232- ccStrobe( CC1100_SFRX );
233- ccStrobe( CC1100_STX );
234+ // wait for TX to finish
235+ while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
236+ ;
777ef621
MG
237+
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 );
243+ }
b2720844
MG
244
245- while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )
246- my_delay_ms(5);
247-
248 if(asksin_on) {
249 ccRX();
250 } else {
Impressum, Datenschutz