]> git.zerfleddert.de Git - fhem-stuff/blob - culfw/culfw-asksin-fix.diff
5c8db334e05ae4c2c040584baacd09bdb67baa55
[fhem-stuff] / culfw / culfw-asksin-fix.diff
1 Index: 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,
14 @@ -26,16 +26,17 @@
15 0x11, 0x93,
16 0x12, 0x03,
17 0x15, 0x34,
18 - 0x17, 0x30, // always go into IDLE
19 + 0x17, 0x3F, // always go into RX after TX, CCA, ELV uses 0x03
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,
29 - 0x3e, 0xc3,
30 - 0xff
31 + 0x3e, 0xc3
32 };
33
34 void
35 @@ -56,18 +57,16 @@
36 my_delay_us(100);
37
38 // load configuration
39 - for (uint8_t i = 0; i<50; i += 2) {
40 -
41 - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
42 - break;
43 -
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]) );
47 }
48
49 ccStrobe( CC1100_SCAL );
50
51 - my_delay_ms(1);
52 + my_delay_ms(4);
53 +
54 + ccRX();
55 }
56
57 void
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;
78 -
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 );
101
102 - ccStrobe( CC1100_SFRX );
103 - ccStrobe( CC1100_SIDLE );
104 - ccStrobe( CC1100_SNOP );
105 - ccStrobe( CC1100_SRX );
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];
115 -
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;
123
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 + }
158 }
159 -
160 - return;
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
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 );
186 + break;
187 + }
188 }
189
190 void
191 @@ -173,20 +166,7 @@
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
212 @@ -195,6 +175,15 @@
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
221 + } else {
222 + my_delay_ms(10);
223 + }
224 +
225 // send
226 CC1100_ASSERT;
227 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
228 @@ -205,12 +194,17 @@
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 + ;
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 + }
244
245 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )
246 - my_delay_ms(5);
247 -
248 if(asksin_on) {
249 ccRX();
250 } else {
Impressum, Datenschutz