]> git.zerfleddert.de Git - fhem-stuff/blob - culfw/culfw-asksin-fix.diff
168ad477b42dfdda427084da0dcdcbcf1be4ce5f
[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,8 +11,8 @@
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 @@ -26,18 +26,21 @@
17 0x11, 0x93,
18 0x12, 0x03,
19 0x15, 0x34,
20 - 0x17, 0x30, // always go into IDLE
21 + 0x17, 0x33, // go into RX after TX, CCA; ELV uses 0x03
22 0x18, 0x18,
23 0x19, 0x16,
24 0x1B, 0x43,
25 0x21, 0x56,
26 0x25, 0x00,
27 0x26, 0x11,
28 + 0x29, 0x59,
29 + 0x2c, 0x81,
30 0x2D, 0x35,
31 - 0x3e, 0xc3,
32 - 0xff
33 + 0x3e, 0xc3
34 };
35
36 +static void rf_asksin_reset_rx(void);
37 +
38 void
39 rf_asksin_init(void)
40 {
41 @@ -56,20 +59,27 @@
42 my_delay_us(100);
43
44 // load configuration
45 - for (uint8_t i = 0; i<50; i += 2) {
46 -
47 - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40)
48 - break;
49 -
50 + for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) {
51 cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]),
52 pgm_read_byte(&ASKSIN_CFG[i+1]) );
53 }
54
55 ccStrobe( CC1100_SCAL );
56
57 - my_delay_ms(1);
58 + my_delay_ms(4);
59 +
60 + ccRX();
61 }
62
63 +static void
64 +rf_asksin_reset_rx(void)
65 +{
66 + ccStrobe( CC1100_SFRX );
67 + ccStrobe( CC1100_SIDLE );
68 + ccStrobe( CC1100_SNOP );
69 + ccStrobe( CC1100_SRX );
70 +}
71 +
72 void
73 rf_asksin_task(void)
74 {
75 @@ -83,12 +93,14 @@
76
77 // see if a CRC OK pkt has been arrived
78 if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
79 -
80 enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
81
82 - if (enc[0]>=MAX_ASKSIN_MSG)
83 - enc[0] = MAX_ASKSIN_MSG-1;
84 -
85 + if (enc[0] >= MAX_ASKSIN_MSG) {
86 + // Something went horribly wrong, out of sync?
87 + rf_asksin_reset_rx();
88 + return;
89 + }
90 +
91 CC1100_ASSERT;
92 cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
93
94 @@ -97,12 +109,10 @@
95 }
96
97 rssi = cc1100_sendbyte( 0 );
98 -
99 + l = cc1100_sendbyte( 0 );
100 +
101 CC1100_DEASSERT;
102
103 - ccStrobe( CC1100_SFRX );
104 - ccStrobe( CC1100_SIDLE );
105 - ccStrobe( CC1100_SNOP );
106 ccStrobe( CC1100_SRX );
107
108 dec[0] = enc[0];
109 @@ -113,7 +123,6 @@
110
111 dec[l] = enc[l] ^ dec[2];
112
113 -
114 if (tx_report & REP_BINTIME) {
115
116 DC('a');
117 @@ -131,26 +140,17 @@
118
119 DNL();
120 }
121 + }
122
123 - return;
124 -
125 + switch(cc1100_readReg( CC1100_MARCSTATE )) {
126 + case MARCSTATE_RXFIFO_OVERFLOW:
127 + ccStrobe( CC1100_SFRX );
128 + case MARCSTATE_IDLE:
129 + ccStrobe( CC1100_SIDLE );
130 + ccStrobe( CC1100_SNOP );
131 + ccStrobe( CC1100_SRX );
132 + break;
133 }
134 -
135 -
136 - switch (cc1100_readReg( CC1100_MARCSTATE )) {
137 -
138 - // RX_OVERFLOW
139 - case 17:
140 - // IDLE
141 - case 1:
142 - ccStrobe( CC1100_SFRX );
143 - ccStrobe( CC1100_SIDLE );
144 - ccStrobe( CC1100_SNOP );
145 - ccStrobe( CC1100_SRX );
146 - break;
147 -
148 - }
149 -
150 }
151
152 void
153 @@ -173,20 +173,7 @@
154 my_delay_ms(3); // 3ms: Found by trial and error
155 }
156
157 - ccStrobe(CC1100_SIDLE);
158 - ccStrobe(CC1100_SFRX );
159 - ccStrobe(CC1100_SFTX );
160 -
161 - if (dec[2] & (1 << 4)) { //BURST-bit set?
162 - ccStrobe(CC1100_STX ); //We need to send a burst
163 -
164 - //According to ELV, devices get activated every 300ms, so send burst for 360ms
165 - for(l = 0; l < 3; l++)
166 - my_delay_ms(120); //arg is uint_8, so loop
167 - }
168 -
169 // "crypt"
170 -
171 enc[0] = dec[0];
172 enc[1] = (~dec[1]) ^ 0x89;
173
174 @@ -195,6 +182,15 @@
175
176 enc[l] = dec[l] ^ dec[2];
177
178 + ccTX();
179 + if (dec[2] & (1 << 4)) { // BURST-bit set?
180 + // According to ELV, devices get activated every 300ms, so send burst for 360ms
181 + for(l = 0; l < 3; l++)
182 + my_delay_ms(120); // arg is uint_8, so loop
183 + } else {
184 + my_delay_ms(10);
185 + }
186 +
187 // send
188 CC1100_ASSERT;
189 cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO);
190 @@ -205,12 +201,17 @@
191
192 CC1100_DEASSERT;
193
194 - ccStrobe( CC1100_SFRX );
195 - ccStrobe( CC1100_STX );
196 + // wait for TX to finish
197 + while(cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TX)
198 + ;
199 +
200 + if (cc1100_readReg( CC1100_MARCSTATE ) == MARCSTATE_TXFIFO_UNDERFLOW) {
201 + ccStrobe( CC1100_SFTX );
202 + ccStrobe( CC1100_SIDLE );
203 + ccStrobe( CC1100_SNOP );
204 + ccStrobe( CC1100_SRX );
205 + }
206
207 - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 )
208 - my_delay_ms(5);
209 -
210 if(asksin_on) {
211 ccRX();
212 } else {
Impressum, Datenschutz