]> git.zerfleddert.de Git - fhem-stuff/blob - culfw/culfw-asksin-fix.diff
795ff4107d6f6ac13c7e4ae7afe868d45aab6d8c
[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,13 +11,13 @@
6
7 uint8_t asksin_on = 0;
8
9 -const uint8_t PROGMEM ASKSIN_CFG[50] = {
10 - 0x00, 0x07,
11 +const uint8_t PROGMEM ASKSIN_CFG[] = {
12 + 0x00, 0x01,
13 0x02, 0x2e,
14 0x03, 0x0d,
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 @@
23 0x11, 0x93,
24 0x12, 0x03,
25 0x15, 0x34,
26 - 0x17, 0x30, // always go into IDLE
27 + 0x17, 0x3F, // always go into RX after TX, CCA, ELV uses 0x03
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,
37 - 0x3e, 0xc3,
38 - 0xff
39 + 0x3e, 0xc3
40 };
41
42 +static inline uint8_t read_cc1100_rxbytes();
43 +
44 void
45 rf_asksin_init(void)
46 {
47 @@ -56,20 +59,30 @@
48 my_delay_us(100);
49
50 // load configuration
51 - for (uint8_t i = 0; i<50; i += 2) {
52 -
53 - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
54 - break;
55 -
56 + for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
57 cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
58 pgm_read_byte(&ASKSIN_CFG[i+1]) );
59 }
60
61 ccStrobe( CC1100_SCAL );
62
63 - my_delay_ms(1);
64 + my_delay_ms(4);
65 +
66 + ccRX();
67 }
68
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 +
81 void
82 rf_asksin_task(void)
83 {
84 @@ -77,18 +90,30 @@
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
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();
98
99 + if (rxfifo_cnt & 0x80) // Overflow
100 + break;
101 +
102 + rxfifo_cnt &= 0x7f;
103 +
104 enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
105
106 if (enc[0]>=MAX_ASKSIN_MSG)
107 enc[0] = MAX_ASKSIN_MSG-1;
108 -
109 +
110 + while ((enc[0] + 2) < (rxfifo_cnt - 1)) { // Wait for more data
111 + my_delay_ms(1);
112 + rxfifo_cnt = (read_cc1100_rxbytes() & 0x7f) + 1;
113 + }
114 +
115 CC1100_ASSERT;
116 cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
117
118 @@ -97,13 +122,12 @@
119 }
120
121 rssi = cc1100_sendbyte( 0 );
122 -
123 + l = cc1100_sendbyte( 0 );
124 +
125 CC1100_DEASSERT;
126
127 - ccStrobe( CC1100_SFRX );
128 - ccStrobe( CC1100_SIDLE );
129 - ccStrobe( CC1100_SNOP );
130 - ccStrobe( CC1100_SRX );
131 + if (!(l & 0x80)) // CRC not ok
132 + continue;
133
134 dec[0] = enc[0];
135 dec[1] = (~enc[1]) ^ 0x89;
136 @@ -113,7 +137,6 @@
137
138 dec[l] = enc[l] ^ dec[2];
139
140 -
141 if (tx_report & REP_BINTIME) {
142
143 DC('a');
144 @@ -131,26 +154,17 @@
145
146 DNL();
147 }
148 + }
149
150 - return;
151 -
152 + switch(cc1100_readReg( CC1100_MARCSTATE )) {
153 + case MARCSTATE_RXFIFO_OVERFLOW:
154 + ccStrobe( CC1100_SFRX );
155 + case MARCSTATE_IDLE:
156 + ccStrobe( CC1100_SIDLE );
157 + ccStrobe( CC1100_SNOP );
158 + ccStrobe( CC1100_SRX );
159 + break;
160 }
161 -
162 -
163 - switch (cc1100_readReg( CC1100_MARCSTATE )) {
164 -
165 - // RX_OVERFLOW
166 - case 17:
167 - // IDLE
168 - case 1:
169 - ccStrobe( CC1100_SFRX );
170 - ccStrobe( CC1100_SIDLE );
171 - ccStrobe( CC1100_SNOP );
172 - ccStrobe( CC1100_SRX );
173 - break;
174 -
175 - }
176 -
177 }
178
179 void
180 @@ -173,20 +187,7 @@
181 my_delay_ms(3); // 3ms: Found by trial and error
182 }
183
184 - ccStrobe(CC1100_SIDLE);
185 - ccStrobe(CC1100_SFRX );
186 - ccStrobe(CC1100_SFTX );
187 -
188 - if (dec[2] & (1 << 4)) { //BURST-bit set?
189 - ccStrobe(CC1100_STX ); //We need to send a burst
190 -
191 - //According to ELV, devices get activated every 300ms, so send burst for 360ms
192 - for(l = 0; l < 3; l++)
193 - my_delay_ms(120); //arg is uint_8, so loop
194 - }
195 -
196 // "crypt"
197 -
198 enc[0] = dec[0];
199 enc[1] = (~dec[1]) ^ 0x89;
200
201 @@ -195,6 +196,15 @@
202
203 enc[l] = dec[l] ^ dec[2];
204
205 + ccTX();
206 + if (dec[2] & (1 << 4)) { // BURST-bit set?
207 + // According to ELV, devices get activated every 300ms, so send burst for 360ms
208 + for(l = 0; l < 3; l++)
209 + my_delay_ms(120); // arg is uint_8, so loop
210 + } else {
211 + my_delay_ms(10);
212 + }
213 +
214 // send
215 CC1100_ASSERT;
216 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
217 @@ -205,12 +215,17 @@
218
219 CC1100_DEASSERT;
220
221 - ccStrobe( CC1100_SFRX );
222 - ccStrobe( CC1100_STX );
223 + // wait for TX to finish
224 + while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
225 + ;
226 +
227 + if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
228 + ccStrobe( CC1100_SFTX );
229 + ccStrobe( CC1100_SIDLE );
230 + ccStrobe( CC1100_SNOP );
231 + ccStrobe( CC1100_SRX );
232 + }
233
234 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )
235 - my_delay_ms(5);
236 -
237 if(asksin_on) {
238 ccRX();
239 } else {
Impressum, Datenschutz