]> git.zerfleddert.de Git - fhem-stuff/blob - culfw/culfw-asksin-fix.diff
07a587f31afb0887c98906c901a196c1c0908822
[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,15 +90,27 @@
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 + 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 );
118 -
119 + l = cc1100_sendbyte( 0 );
120 +
121 CC1100_DEASSERT;
122
123 - ccStrobe( CC1100_SFRX );
124 - ccStrobe( CC1100_SIDLE );
125 - ccStrobe( CC1100_SNOP );
126 - ccStrobe( CC1100_SRX );
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
136 -
137 if (tx_report & REP_BINTIME) {
138
139 DC('a');
140 @@ -131,26 +154,17 @@
141
142 DNL();
143 }
144 + }
145
146 - return;
147 -
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;
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 - }
172 -
173 }
174
175 void
176 @@ -173,20 +187,7 @@
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
197 @@ -195,6 +196,15 @@
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
206 + } else {
207 + my_delay_ms(10);
208 + }
209 +
210 // send
211 CC1100_ASSERT;
212 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
213 @@ -205,12 +215,17 @@
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 + ;
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 + }
229
230 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )
231 - my_delay_ms(5);
232 -
233 if(asksin_on) {
234 ccRX();
235 } else {
Impressum, Datenschutz