Rev 2198 | Rev 2200 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2198 | Rev 2199 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | #include "sns_rfTransceive.h" |
2 | #include "sns_rfTransceive.h" |
| 3 | 3 | ||
| 4 | #if IR_RX_ENABLE==1 |
4 | #if IR_RX_ENABLE==1 |
| 5 | StdCan_Msg_t rfTxMsg; |
5 | StdCan_Msg_t rfTxMsg; |
| 6 | #endif |
- | |
| 7 | - | ||
| 8 | #if IR_RX_ENABLE==1 |
- | |
| 9 | uint8_t rfRxChannel_newData; |
6 | uint8_t rfRxChannel_newData; |
| 10 | uint8_t |
7 | uint8_t rfRxChannel_len; |
| - | 8 | uint8_t rfRxChannel_index; |
|
| 11 | uint8_t rfRxChannel_state; |
9 | uint8_t rfRxChannel_state; |
| 12 | Ir_Protocol_Data_t rfRxChannel_proto; |
10 | Ir_Protocol_Data_t rfRxChannel_proto; |
| 13 | uint16_t rfRxChannel_buf[MAX_NR_TIMES]; |
11 | uint16_t rfRxChannel_buf[MAX_NR_TIMES]; |
| 14 | 12 | ||
| 15 | uint16_t debugCnt1 = 0; |
- | |
| 16 | uint16_t debugCnt2 = 0; |
- | |
| 17 | uint16_t debugCnt3 = 5; |
- | |
| 18 | - | ||
| 19 | void sns_rfTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len, uint8_t index) |
13 | void sns_rfTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len, uint8_t index) |
| 20 | { |
14 | { |
| 21 | #if IR_RX_CONTINUOUS_MODE==0 |
15 | #if IR_RX_CONTINUOUS_MODE==0 |
| 22 | rfRxChannel_newData = TRUE; |
16 | rfRxChannel_newData = TRUE; |
| 23 |
|
17 | rfRxChannel_len = len; |
| 24 | #else |
18 | #else |
| 25 | //gpio_toggle_pin(EXP_B); |
- | |
| 26 | if (len > sns_rfTransceive_MIN_NUM_PULSES) |
19 | if (len > sns_rfTransceive_MIN_NUM_PULSES) |
| 27 | { |
20 | { |
| 28 | rfRxChannel_newData = TRUE; |
21 | rfRxChannel_newData = TRUE; |
| 29 |
|
22 | rfRxChannel_len = len; |
| 30 | - | ||
| 31 | ///////////// DEBUG!!!! |
- | |
| 32 |
|
23 | rfRxChannel_index = index; |
| 33 | - | ||
| 34 | //debugCnt1 +=1; |
- | |
| 35 | } |
24 | } |
| 36 | //debugCnt2 +=1; |
- | |
| 37 | //check if len is > something reasonable |
- | |
| 38 | //let process function parse protocols |
- | |
| 39 | #endif |
25 | #endif |
| 40 | } |
26 | } |
| 41 | #endif |
27 | #endif |
| 42 | 28 | ||
| 43 | 29 | ||
| 44 | #if IR_TX_ENABLE==1 |
30 | #if IR_TX_ENABLE==1 |
| 45 | uint8_t rfTxChannel_sendComplete; |
31 | uint8_t rfTxChannel_sendComplete; |
| 46 | uint8_t rfTxChannel_state; |
32 | uint8_t rfTxChannel_state; |
| 47 | uint8_t |
33 | uint8_t rfTxChannel_len; |
| 48 | Ir_Protocol_Data_t rfTxChannel_proto; |
34 | Ir_Protocol_Data_t rfTxChannel_proto; |
| 49 | uint16_t rfTxChannel_buf[MAX_NR_TIMES]; |
35 | uint16_t rfTxChannel_buf[MAX_NR_TIMES]; |
| 50 | uint8_t rfTxChannel_repeatCount; |
36 | uint8_t rfTxChannel_repeatCount; |
| 51 | uint8_t rfTxChannel_stopSend; |
37 | uint8_t rfTxChannel_stopSend; |
| 52 | 38 | ||
| Line 65... | Line 51... | ||
| 65 | rfTxMsg.Header.ModuleId = sns_rfTransceive_ID; |
51 | rfTxMsg.Header.ModuleId = sns_rfTransceive_ID; |
| 66 | rfTxMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_IR; |
52 | rfTxMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_IR; |
| 67 | rfTxMsg.Length = 8; |
53 | rfTxMsg.Length = 8; |
| 68 | 54 | ||
| 69 | rfRxChannel_newData = FALSE; |
55 | rfRxChannel_newData = FALSE; |
| 70 |
|
56 | rfRxChannel_len = 0; |
| 71 | rfRxChannel_proto.timeout=0; |
57 | rfRxChannel_proto.timeout=0; |
| 72 | rfRxChannel_proto.data=0; |
58 | rfRxChannel_proto.data=0; |
| 73 | rfRxChannel_proto.repeats=0; |
59 | rfRxChannel_proto.repeats=0; |
| 74 | rfRxChannel_proto.protocol=0; |
60 | rfRxChannel_proto.protocol=0; |
| 75 | #endif |
61 | #endif |
| 76 | 62 | ||
| 77 | #if IR_TX_ENABLE==1 |
63 | #if IR_TX_ENABLE==1 |
| 78 | rfTxChannel_sendComplete = FALSE; |
64 | rfTxChannel_sendComplete = FALSE; |
| 79 |
|
65 | rfTxChannel_len = 0; |
| 80 | rfTxChannel_proto.data=0; |
66 | rfTxChannel_proto.data=0; |
| 81 | rfTxChannel_proto.repeats=0; |
67 | rfTxChannel_proto.repeats=0; |
| 82 | rfTxChannel_proto.framecnt=0; |
68 | rfTxChannel_proto.framecnt=0; |
| 83 | rfTxChannel_proto.protocol=0; |
69 | rfTxChannel_proto.protocol=0; |
| 84 | rfTxChannel_repeatCount = 0; |
70 | rfTxChannel_repeatCount = 0; |
| Line 99... | Line 85... | ||
| 99 | #endif |
85 | #endif |
| 100 | 86 | ||
| 101 | #if IR_TX_ENABLE==1 |
87 | #if IR_TX_ENABLE==1 |
| 102 | IrTransceiver_InitTxChannel(0, sns_rfTransceive_TX_done_callback, sns_rfTransceive_TX_PIN); |
88 | IrTransceiver_InitTxChannel(0, sns_rfTransceive_TX_done_callback, sns_rfTransceive_TX_PIN); |
| 103 | rfTxChannel_state = sns_rfTransceive_STATE_IDLE; |
89 | rfTxChannel_state = sns_rfTransceive_STATE_IDLE; |
| 104 | #endif |
90 | #endif |
| 105 | - | ||
| 106 | ///////////// DEBUG!!!! |
- | |
| 107 | gpio_set_out(EXP_A); |
- | |
| 108 | } |
91 | } |
| 109 | 92 | ||
| 110 | 93 | ||
| 111 | ///////////// DEBUG!!!! |
94 | ///////////// DEBUG!!!! |
| 112 | #if 0 |
95 | #if 0 |
| 113 | StdCan_Msg_t irTxMsg; |
96 | StdCan_Msg_t irTxMsg; |
| 114 | void send_debug(uint16_t *buffer, uint8_t len) { |
97 | void send_debug(uint16_t *buffer, uint8_t len) { |
| Line 164... | Line 147... | ||
| 164 | if (rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN && rfRxChannel_proto.timeout != 0) { |
147 | if (rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN && rfRxChannel_proto.timeout != 0) { |
| 165 | /* Send button release command on CAN */ |
148 | /* Send button release command on CAN */ |
| 166 | rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED; |
149 | rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED; |
| 167 | rfTxMsg.Data[1] = rfRxChannel_proto.protocol; |
150 | rfTxMsg.Data[1] = rfRxChannel_proto.protocol; |
| 168 | /* Data content is kept from last transmit (pressed) */ |
151 | /* Data content is kept from last transmit (pressed) */ |
| 169 | 152 | ||
| 170 | StdCan_Put(&rfTxMsg); |
153 | StdCan_Put(&rfTxMsg); |
| 171 | } |
154 | } |
| 172 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
155 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
| 173 | break; |
156 | break; |
| 174 | } |
157 | } |
| 175 | 158 | ||
| 176 | case sns_rfTransceive_STATE_START_RECEIVE: |
159 | case sns_rfTransceive_STATE_START_RECEIVE: |
| 177 | cli(); |
160 | cli(); |
| 178 | rfRxChannel_newData = FALSE; |
161 | rfRxChannel_newData = FALSE; |
| 179 | sei(); |
162 | sei(); |
| 180 | rfRxChannel_state = sns_rfTransceive_STATE_RECEIVING; |
163 | rfRxChannel_state = sns_rfTransceive_STATE_RECEIVING; |
| 181 | 164 | ||
| 182 | break; |
165 | break; |
| 183 | 166 | ||
| 184 | case sns_rfTransceive_STATE_RECEIVING: |
167 | case sns_rfTransceive_STATE_RECEIVING: |
| 185 | if (rfRxChannel_newData == TRUE) { |
168 | if (rfRxChannel_newData == TRUE) { |
| 186 | cli(); |
169 | cli(); |
| 187 | rfRxChannel_newData = FALSE; |
170 | rfRxChannel_newData = FALSE; |
| 188 | sei(); |
171 | sei(); |
| 189 | /* |
- | |
| 190 | debugCnt3 +=1; |
- | |
| 191 | if (debugCnt3>5) |
- | |
| 192 | { |
- | |
| 193 | printf("1\n"); |
- | |
| 194 | debugCnt3=0; |
- | |
| 195 | } |
- | |
| 196 | */ |
- | |
| 197 | /* Let protocol driver parse and then send on CAN */ |
172 | /* Let protocol driver parse and then send on CAN */ |
| 198 | uint8_t res2 = parseProtocol(rfRxChannel_buf, |
173 | uint8_t res2 = parseProtocol(rfRxChannel_buf, rfRxChannel_len, rfRxChannel_index, &rfRxChannel_proto); |
| 199 | if (res2 == IR_OK && rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN) { |
174 | if (res2 == IR_OK && rfRxChannel_proto.protocol != IR_PROTO_UNKNOWN) { |
| 200 | gpio_clr_pin(EXP_B); |
- | |
| 201 | //send_debug(rfRxChannel_buf, |
175 | //send_debug(rfRxChannel_buf, rfRxChannel_len); |
| 202 | /* If timeout is 0, protocol is burst protocol */ |
176 | /* If timeout is 0, protocol is burst protocol */ |
| 203 | if (rfRxChannel_proto.timeout > 0) |
177 | if (rfRxChannel_proto.timeout > 0) |
| 204 | { |
178 | { |
| 205 | rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED; |
179 | rfTxMsg.Data[0] = CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED; |
| 206 | rfRxChannel_state = sns_rfTransceive_STATE_START_PAUSE; |
180 | rfRxChannel_state = sns_rfTransceive_STATE_START_PAUSE; |
| Line 221... | Line 195... | ||
| 221 | StdCan_Put(&rfTxMsg); |
195 | StdCan_Put(&rfTxMsg); |
| 222 | } |
196 | } |
| 223 | else if (rfRxChannel_proto.protocol == IR_PROTO_UNKNOWN) |
197 | else if (rfRxChannel_proto.protocol == IR_PROTO_UNKNOWN) |
| 224 | { |
198 | { |
| 225 | #if (sns_rfTransceive_SEND_DEBUG==1) |
199 | #if (sns_rfTransceive_SEND_DEBUG==1) |
| 226 | //send_debug(rfRxChannel_buf, |
200 | //send_debug(rfRxChannel_buf, rfRxChannel_len); |
| 227 | //rfRxChannel_proto.timeout=300; |
201 | //rfRxChannel_proto.timeout=300; |
| 228 | #endif |
202 | #endif |
| 229 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
203 | rfRxChannel_state = sns_rfTransceive_STATE_START_RECEIVE; |
| 230 | } |
204 | } |
| 231 | } |
205 | } |
| Line 239... | Line 213... | ||
| 239 | 213 | ||
| 240 | case sns_rfTransceive_STATE_PAUSING: |
214 | case sns_rfTransceive_STATE_PAUSING: |
| 241 | /* reset timer if new IR arrived */ |
215 | /* reset timer if new IR arrived */ |
| 242 | if (rfRxChannel_newData == TRUE) { |
216 | if (rfRxChannel_newData == TRUE) { |
| 243 | cli(); |
217 | cli(); |
| 244 | IrTransceiver_ResetRx(0); //TODO?? |
- | |
| 245 | rfRxChannel_newData = FALSE; |
218 | rfRxChannel_newData = FALSE; |
| 246 | sei(); |
219 | sei(); |
| 247 | 220 | ||
| 248 | Ir_Protocol_Data_t protoDummy; |
221 | Ir_Protocol_Data_t protoDummy; |
| 249 | if (parseProtocol(rfRxChannel_buf, |
222 | if (parseProtocol(rfRxChannel_buf, rfRxChannel_len, rfRxChannel_index, &protoDummy) == IR_OK) { |
| 250 | if (protoDummy.protocol == rfRxChannel_proto.protocol) { |
223 | if (protoDummy.protocol == rfRxChannel_proto.protocol) { |
| 251 | /* re-set timer so we can send release button event when no new RF is arriving */ |
224 | /* re-set timer so we can send release button event when no new RF is arriving */ |
| 252 | Timer_SetTimeout(sns_rfTransceive_RX_REPEATE_TIMER, rfRxChannel_proto.timeout, TimerTypeOneShot, 0); |
225 | Timer_SetTimeout(sns_rfTransceive_RX_REPEATE_TIMER, rfRxChannel_proto.timeout, TimerTypeOneShot, 0); |
| 253 | } |
226 | } |
| 254 | } |
227 | } |
| Line 277... | Line 250... | ||
| 277 | } |
250 | } |
| 278 | 251 | ||
| 279 | case sns_rfTransceive_STATE_START_TRANSMIT: |
252 | case sns_rfTransceive_STATE_START_TRANSMIT: |
| 280 | { |
253 | { |
| 281 | /* Expand protocol. */ |
254 | /* Expand protocol. */ |
| 282 | if (expandProtocol(rfTxChannel_buf, & |
255 | if (expandProtocol(rfTxChannel_buf, &rfTxChannel_len, &rfTxChannel_proto) != IR_OK) { |
| 283 | /* Failed to expand protocol -> enter idle state. */ |
256 | /* Failed to expand protocol -> enter idle state. */ |
| 284 | rfTxChannel_state = sns_rfTransceive_STATE_IDLE; |
257 | rfTxChannel_state = sns_rfTransceive_STATE_IDLE; |
| 285 | break; |
258 | break; |
| 286 | } |
259 | } |
| 287 | 260 | ||
| 288 | /* Start RF transmission. */ |
261 | /* Start RF transmission. */ |
| 289 | IrTransceiver_Transmit(0, rfTxChannel_buf, 0, |
262 | IrTransceiver_Transmit(0, rfTxChannel_buf, 0, rfTxChannel_len, rfTxChannel_proto.modfreq); |
| 290 | 263 | ||
| 291 | /* Enter transmitting state. */ |
264 | /* Enter transmitting state. */ |
| 292 | rfTxChannel_state = sns_rfTransceive_STATE_TRANSMITTING; |
265 | rfTxChannel_state = sns_rfTransceive_STATE_TRANSMITTING; |
| 293 | break; |
266 | break; |
| 294 | } |
267 | } |