]>
Commit | Line | Data |
---|---|---|
b2720844 MG |
1 | Index: clib/rf_asksin.c |
2 | =================================================================== | |
3 | --- clib/rf_asksin.c (revision 373) | |
4 | +++ clib/rf_asksin.c (working copy) | |
222456d4 | 5 | @@ -11,8 +11,8 @@ |
b2720844 MG |
6 | |
7 | uint8_t asksin_on = 0; | |
8 | ||
9 | -const uint8_t PROGMEM ASKSIN_CFG[50] = { | |
532a7bf0 | 10 | - 0x00, 0x07, |
b2720844 | 11 | +const uint8_t PROGMEM ASKSIN_CFG[] = { |
532a7bf0 | 12 | + 0x00, 0x01, |
b2720844 MG |
13 | 0x02, 0x2e, |
14 | 0x03, 0x0d, | |
532a7bf0 | 15 | 0x04, 0xE9, |
222456d4 | 16 | @@ -26,18 +26,21 @@ |
b2720844 MG |
17 | 0x11, 0x93, |
18 | 0x12, 0x03, | |
19 | 0x15, 0x34, | |
20 | - 0x17, 0x30, // always go into IDLE | |
222456d4 | 21 | + 0x17, 0x33, // go into RX after TX, CCA; ELV uses 0x03 |
b2720844 MG |
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, | |
777ef621 | 31 | - 0x3e, 0xc3, |
b2720844 | 32 | - 0xff |
777ef621 | 33 | + 0x3e, 0xc3 |
b2720844 MG |
34 | }; |
35 | ||
ee6c84c4 | 36 | +static void rf_asksin_reset_rx(void); |
532a7bf0 | 37 | + |
b2720844 | 38 | void |
532a7bf0 MG |
39 | rf_asksin_init(void) |
40 | { | |
222456d4 | 41 | @@ -56,20 +59,27 @@ |
b2720844 MG |
42 | my_delay_us(100); |
43 | ||
44 | // load configuration | |
45 | - for (uint8_t i = 0; i<50; i += 2) { | |
777ef621 MG |
46 | - |
47 | - if (pgm_read_byte( &ASKSIN_CFG[i] )>0x40) | |
48 | - break; | |
49 | - | |
b2720844 | 50 | + for (uint8_t i = 0; i < sizeof(ASKSIN_CFG); i += 2) { |
777ef621 MG |
51 | cc1100_writeReg( pgm_read_byte(&ASKSIN_CFG[i]), |
52 | pgm_read_byte(&ASKSIN_CFG[i+1]) ); | |
53 | } | |
b2720844 MG |
54 | |
55 | ccStrobe( CC1100_SCAL ); | |
56 | ||
57 | - my_delay_ms(1); | |
58 | + my_delay_ms(4); | |
59 | + | |
60 | + ccRX(); | |
61 | } | |
62 | ||
ee6c84c4 | 63 | +static void |
b74270d7 MG |
64 | +rf_asksin_reset_rx(void) |
65 | +{ | |
66 | + ccStrobe( CC1100_SFRX ); | |
67 | + ccStrobe( CC1100_SIDLE ); | |
68 | + ccStrobe( CC1100_SNOP ); | |
b74270d7 MG |
69 | + ccStrobe( CC1100_SRX ); |
70 | +} | |
532a7bf0 | 71 | + |
b2720844 | 72 | void |
532a7bf0 MG |
73 | rf_asksin_task(void) |
74 | { | |
222456d4 | 75 | @@ -83,12 +93,14 @@ |
cf4474a9 | 76 | |
222456d4 MG |
77 | // see if a CRC OK pkt has been arrived |
78 | if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) { | |
79 | - | |
532a7bf0 | 80 | enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len |
cf4474a9 | 81 | |
b74270d7 MG |
82 | - if (enc[0]>=MAX_ASKSIN_MSG) |
83 | - enc[0] = MAX_ASKSIN_MSG-1; | |
db4f8119 | 84 | - |
b74270d7 MG |
85 | + if (enc[0] >= MAX_ASKSIN_MSG) { |
86 | + // Something went horribly wrong, out of sync? | |
87 | + rf_asksin_reset_rx(); | |
88 | + return; | |
89 | + } | |
532a7bf0 | 90 | + |
db4f8119 MG |
91 | CC1100_ASSERT; |
92 | cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO ); | |
532a7bf0 | 93 | |
222456d4 | 94 | @@ -97,12 +109,10 @@ |
532a7bf0 MG |
95 | } |
96 | ||
97 | rssi = cc1100_sendbyte( 0 ); | |
cf4474a9 | 98 | - |
222456d4 | 99 | + l = cc1100_sendbyte( 0 ); |
532a7bf0 MG |
100 | + |
101 | CC1100_DEASSERT; | |
b2720844 MG |
102 | |
103 | - ccStrobe( CC1100_SFRX ); | |
104 | - ccStrobe( CC1100_SIDLE ); | |
105 | - ccStrobe( CC1100_SNOP ); | |
222456d4 | 106 | ccStrobe( CC1100_SRX ); |
b74270d7 | 107 | |
532a7bf0 | 108 | dec[0] = enc[0]; |
222456d4 | 109 | @@ -113,7 +123,6 @@ |
532a7bf0 MG |
110 | |
111 | dec[l] = enc[l] ^ dec[2]; | |
112 | ||
b2720844 | 113 | - |
532a7bf0 | 114 | if (tx_report & REP_BINTIME) { |
cf4474a9 | 115 | |
532a7bf0 | 116 | DC('a'); |
222456d4 | 117 | @@ -131,26 +140,17 @@ |
cf4474a9 | 118 | |
532a7bf0 | 119 | DNL(); |
b2720844 | 120 | } |
532a7bf0 MG |
121 | + } |
122 | ||
cf4474a9 | 123 | - return; |
b2720844 | 124 | - |
532a7bf0 MG |
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; | |
b2720844 MG |
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 | - } | |
532a7bf0 | 149 | - |
b2720844 MG |
150 | } |
151 | ||
152 | void | |
222456d4 | 153 | @@ -173,20 +173,7 @@ |
b2720844 MG |
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 | ||
222456d4 | 174 | @@ -195,6 +182,15 @@ |
b2720844 MG |
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 | |
5f2228fc MG |
183 | + } else { |
184 | + my_delay_ms(10); | |
b2720844 MG |
185 | + } |
186 | + | |
187 | // send | |
188 | CC1100_ASSERT; | |
189 | cc1100_sendbyte(CC1100_WRITE_BURST | CC1100_TXFIFO); | |
222456d4 | 190 | @@ -205,12 +201,17 @@ |
b2720844 MG |
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 | + ; | |
777ef621 MG |
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 | + } | |
b2720844 MG |
206 | |
207 | - while( cc1100_readReg( CC1100_MARCSTATE ) != 1 ) | |
208 | - my_delay_ms(5); | |
209 | - | |
210 | if(asksin_on) { | |
211 | ccRX(); | |
212 | } else { |