Rev 1744 | Rev 1755 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1744 | Rev 1754 | ||
|---|---|---|---|
| Line 163... | Line 163... | ||
| 163 | #if IR_TX_ACTIVE_LOW==1 |
163 | #if IR_TX_ACTIVE_LOW==1 |
| 164 | gpio_set_pin(sns_irTransceive_TX0_PIN); |
164 | gpio_set_pin(sns_irTransceive_TX0_PIN); |
| 165 | gpio_set_pin(sns_irTransceive_TX1_PIN); |
165 | gpio_set_pin(sns_irTransceive_TX1_PIN); |
| 166 | gpio_set_pin(sns_irTransceive_TX2_PIN); |
166 | gpio_set_pin(sns_irTransceive_TX2_PIN); |
| 167 | #endif |
167 | #endif |
| - | 168 | #endif |
|
| - | 169 | ||
| - | 170 | /* IR tx power pins on PCA95xx */ |
|
| - | 171 | #if sns_irTransceive_ENABLE_PCA95xx==1 |
|
| - | 172 | Pca95xx_Init(0); |
|
| - | 173 | Pca95xx_clr_pin(sns_irTransceive_TX0_PWRl); |
|
| - | 174 | Pca95xx_set_out(sns_irTransceive_TX0_PWRl); |
|
| - | 175 | Pca95xx_clr_pin(sns_irTransceive_TX0_PWRh); |
|
| - | 176 | Pca95xx_set_out(sns_irTransceive_TX0_PWRh); |
|
| - | 177 | ||
| - | 178 | Pca95xx_clr_pin(sns_irTransceive_TX1_PWRl); |
|
| - | 179 | Pca95xx_set_out(sns_irTransceive_TX1_PWRl); |
|
| - | 180 | Pca95xx_clr_pin(sns_irTransceive_TX1_PWRh); |
|
| - | 181 | Pca95xx_set_out(sns_irTransceive_TX1_PWRh); |
|
| - | 182 | ||
| - | 183 | Pca95xx_clr_pin(sns_irTransceive_TX2_PWRl); |
|
| - | 184 | Pca95xx_set_out(sns_irTransceive_TX2_PWRl); |
|
| - | 185 | Pca95xx_clr_pin(sns_irTransceive_TX2_PWRh); |
|
| - | 186 | Pca95xx_set_out(sns_irTransceive_TX2_PWRh); |
|
| 168 | #endif |
187 | #endif |
| 169 | 188 | ||
| 170 | } |
189 | } |
| 171 | 190 | ||
| 172 | void sns_irTransceive_Process(void) |
191 | void sns_irTransceive_Process(void) |
| Line 177... | Line 196... | ||
| 177 | #if IR_RX_ENABLE==1 |
196 | #if IR_RX_ENABLE==1 |
| 178 | switch (irRxChannel[channel].state) |
197 | switch (irRxChannel[channel].state) |
| 179 | { |
198 | { |
| 180 | case sns_irTransceive_STATE_IDLE: |
199 | case sns_irTransceive_STATE_IDLE: |
| 181 | irRxChannel[channel].state = sns_irTransceive_STATE_START_RECEIVE; |
200 | irRxChannel[channel].state = sns_irTransceive_STATE_START_RECEIVE; |
| 182 | break; |
201 | break; |
| 183 | 202 | ||
| 184 | case sns_irTransceive_STATE_START_RECEIVE: |
203 | case sns_irTransceive_STATE_START_RECEIVE: |
| 185 | IrTransceiver_ResetRx(channel); |
204 | IrTransceiver_ResetRx(channel); |
| 186 | cli(); |
205 | cli(); |
| 187 | irRxChannel[channel].newData = FALSE; |
206 | irRxChannel[channel].newData = FALSE; |
| 188 | sei(); |
207 | sei(); |
| 189 | irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING; |
208 | irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING; |
| 190 | break; |
209 | break; |
| 191 | 210 | ||
| 192 | case sns_irTransceive_STATE_RECEIVING: |
211 | case sns_irTransceive_STATE_RECEIVING: |
| 193 | if (irRxChannel[channel].newData == TRUE) { |
212 | if (irRxChannel[channel].newData == TRUE) { |
| 194 | //TODO: move this line to the RX callback |
213 | //TODO: move this line to the RX callback |
| 195 | IrTransceiver_DisableRx(channel); |
214 | IrTransceiver_DisableRx(channel); |
| 196 | cli(); |
215 | cli(); |
| Line 199... | Line 218... | ||
| 199 | 218 | ||
| 200 | /* Let protocol driver parse and then send on CAN */ |
219 | /* Let protocol driver parse and then send on CAN */ |
| 201 | uint8_t res2 = parseProtocol(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen, &irRxChannel[channel].proto); |
220 | uint8_t res2 = parseProtocol(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen, &irRxChannel[channel].proto); |
| 202 | if (res2 == IR_OK && irRxChannel[channel].proto.protocol != IR_PROTO_UNKNOWN) { |
221 | if (res2 == IR_OK && irRxChannel[channel].proto.protocol != IR_PROTO_UNKNOWN) { |
| 203 | irTxMsg.Data[0] = 0xf&CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED; |
222 | irTxMsg.Data[0] = 0xf&CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED; |
| 204 | irTxMsg.Data[0] |= channel<<4; |
223 | irTxMsg.Data[0] |= channel<<4; |
| 205 | irTxMsg.Data[1] = irRxChannel[channel].proto.protocol; |
224 | irTxMsg.Data[1] = irRxChannel[channel].proto.protocol; |
| 206 | irTxMsg.Data[2] = (irRxChannel[channel].proto.data>>24)&0xff; |
225 | irTxMsg.Data[2] = (irRxChannel[channel].proto.data>>24)&0xff; |
| 207 | irTxMsg.Data[3] = (irRxChannel[channel].proto.data>>16)&0xff; |
226 | irTxMsg.Data[3] = (irRxChannel[channel].proto.data>>16)&0xff; |
| 208 | irTxMsg.Data[4] = (irRxChannel[channel].proto.data>>8)&0xff; |
227 | irTxMsg.Data[4] = (irRxChannel[channel].proto.data>>8)&0xff; |
| 209 | irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff; |
228 | irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff; |
| Line 302... | Line 321... | ||
| 302 | } |
321 | } |
| 303 | 322 | ||
| 304 | Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0); |
323 | Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0); |
| 305 | 324 | ||
| 306 | if (irTxChannel[channel].proto.framecnt != 255) |
325 | if (irTxChannel[channel].proto.framecnt != 255) |
| 307 | { |
326 | { |
| 308 | irTxChannel[channel].proto.framecnt++; |
327 | irTxChannel[channel].proto.framecnt++; |
| 309 | } |
328 | } |
| 310 | 329 | ||
| 311 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
330 | irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING; |
| 312 | break; |
331 | break; |
| 313 | 332 | ||
| 314 | case sns_irTransceive_STATE_PAUSING: |
333 | case sns_irTransceive_STATE_PAUSING: |
| 315 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
334 | if (Timer_Expired(irTxChannel[channel].timerNum)) |
| 316 | { |
335 | { |
| 317 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
336 | irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT; |
| 318 | } |
337 | } |
| 319 | 338 | ||
| 320 | /* transmission is stopped when such command is recevied on can */ |
339 | /* transmission is stopped when such command is recevied on can */ |
| 321 | if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats) |
340 | if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats) |
| 322 | { |
341 | { |
| 323 | //TODO maybe send message on can for status? to confirm stopped sending, ready for new command |
342 | //TODO maybe send message on can for status? to confirm stopped sending, ready for new command |
| 324 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
343 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
| 325 | } |
344 | } |
| 326 | break; |
345 | break; |
| 327 | 346 | ||
| 328 | case sns_irTransceive_STATE_START_IDLE: |
347 | case sns_irTransceive_STATE_START_IDLE: |
| 329 | irTxChannel[channel].stopSend = FALSE; |
348 | irTxChannel[channel].stopSend = FALSE; |
| 330 | irTxChannel[channel].repeatCount = 0; |
349 | irTxChannel[channel].repeatCount = 0; |
| Line 332... | Line 351... | ||
| 332 | 351 | ||
| 333 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
352 | irTxChannel[channel].state = sns_irTransceive_STATE_IDLE; |
| 334 | break; |
353 | break; |
| 335 | 354 | ||
| 336 | default: |
355 | default: |
| 337 | break; |
356 | break; |
| 338 | } |
357 | } |
| 339 | #endif |
358 | #endif |
| 340 | 359 | ||
| 341 | } |
360 | } |
| 342 | } |
361 | } |
| 343 | 362 | ||
| 344 | /* Handle incoming CAN data */ |
363 | /* Handle incoming CAN data */ |
| 345 | void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
364 | void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
| 346 | { |
365 | { |
| Line 405... | Line 424... | ||
| 405 | IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN); |
424 | IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN); |
| 406 | break; |
425 | break; |
| 407 | case 2: |
426 | case 2: |
| 408 | gpio_clr_pin(sns_irTransceive_VCC_EN2_PIN); |
427 | gpio_clr_pin(sns_irTransceive_VCC_EN2_PIN); |
| 409 | IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN); |
428 | IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN); |
| 410 | break; |
429 | break; |
| 411 | } |
430 | } |
| 412 | irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING; |
431 | irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING; |
| 413 | } |
432 | } |
| 414 | #endif |
433 | #endif |
| - | 434 | ||
| - | 435 | ||
| - | 436 | ||
| - | 437 | // Pca95xx_set_out(sns_irTransceive_TX1_PWRl); |
|
| - | 438 | // Pca95xx_set_out(sns_irTransceive_TX1_PWRh); |
|
| - | 439 | ||
| - | 440 | // Pca95xx_set_out(sns_irTransceive_TX2_PWRl); |
|
| - | 441 | // Pca95xx_set_out(sns_irTransceive_TX2_PWRh); |
|
| - | 442 | ||
| - | 443 | ||
| 415 | 444 | ||
| 416 | #if IR_TX_ENABLE==1 |
445 | #if IR_TX_ENABLE==1 |
| 417 | if (config == CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_TRANSMIT) |
446 | if (config == CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_TRANSMIT) |
| 418 | { |
447 | { |
| 419 | #if IR_RX_ENABLE==1 |
448 | #if IR_RX_ENABLE==1 |
| 420 | irRxChannel[channel].state = sns_irTransceive_STATE_DISABLED; |
449 | irRxChannel[channel].state = sns_irTransceive_STATE_DISABLED; |
| 421 | #endif |
450 | #endif |
| - | 451 | ||
| 422 | irTxChannel[channel].txbuf = buf[channel]; |
452 | irTxChannel[channel].txbuf = buf[channel]; |
| 423 | switch (channel) |
453 | switch (channel) |
| 424 | { |
454 | { |
| 425 | case 0: |
455 | case 0: |
| 426 | #if IR_RX_ENABLE==1 |
456 | #if IR_RX_ENABLE==1 |
| 427 | gpio_set_pin(sns_irTransceive_VCC_EN0_PIN); |
457 | gpio_set_pin(sns_irTransceive_VCC_EN0_PIN); |
| 428 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN); |
458 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN); |
| 429 | #endif |
459 | #endif |
| 430 | IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN); |
460 | IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN); |
| - | 461 | ||
| - | 462 | #if sns_irTransceive_ENABLE_PCA95xx==1 |
|
| - | 463 | Pca95xx_set_out(sns_irTransceive_TX0_PWRl); |
|
| - | 464 | Pca95xx_set_out(sns_irTransceive_TX0_PWRh); |
|
| - | 465 | if (power&0x1) |
|
| - | 466 | { |
|
| - | 467 | Pca95xx_set_in(sns_irTransceive_TX0_PWRl); |
|
| - | 468 | } |
|
| - | 469 | if (power&0x2) |
|
| - | 470 | { |
|
| - | 471 | Pca95xx_set_in(sns_irTransceive_TX0_PWRh); |
|
| - | 472 | } |
|
| - | 473 | #endif |
|
| 431 | break; |
474 | break; |
| 432 | case 1: |
475 | case 1: |
| 433 | #if IR_RX_ENABLE==1 |
476 | #if IR_RX_ENABLE==1 |
| 434 | gpio_set_pin(sns_irTransceive_VCC_EN1_PIN); |
477 | gpio_set_pin(sns_irTransceive_VCC_EN1_PIN); |
| 435 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN); |
478 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN); |
| 436 | #endif |
479 | #endif |
| 437 | IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX1_PIN); |
480 | IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX1_PIN); |
| - | 481 | ||
| - | 482 | #if sns_irTransceive_ENABLE_PCA95xx==1 |
|
| - | 483 | Pca95xx_set_out(sns_irTransceive_TX1_PWRl); |
|
| - | 484 | Pca95xx_set_out(sns_irTransceive_TX1_PWRh); |
|
| - | 485 | if (power&0x1) |
|
| - | 486 | { |
|
| - | 487 | Pca95xx_set_in(sns_irTransceive_TX1_PWRl); |
|
| - | 488 | } |
|
| - | 489 | if (power&0x2) |
|
| - | 490 | { |
|
| - | 491 | Pca95xx_set_in(sns_irTransceive_TX1_PWRh); |
|
| - | 492 | } |
|
| - | 493 | #endif |
|
| 438 | break; |
494 | break; |
| 439 | case 2: |
495 | case 2: |
| 440 | #if IR_RX_ENABLE==1 |
496 | #if IR_RX_ENABLE==1 |
| 441 | gpio_set_pin(sns_irTransceive_VCC_EN2_PIN); |
497 | gpio_set_pin(sns_irTransceive_VCC_EN2_PIN); |
| 442 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN); |
498 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN); |
| 443 | #endif |
499 | #endif |
| 444 | IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX2_PIN); |
500 | IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX2_PIN); |
| - | 501 | ||
| - | 502 | #if sns_irTransceive_ENABLE_PCA95xx==1 |
|
| - | 503 | Pca95xx_set_out(sns_irTransceive_TX2_PWRl); |
|
| - | 504 | Pca95xx_set_out(sns_irTransceive_TX2_PWRh); |
|
| - | 505 | if (power&0x1) |
|
| - | 506 | { |
|
| - | 507 | Pca95xx_set_in(sns_irTransceive_TX2_PWRl); |
|
| - | 508 | } |
|
| - | 509 | if (power&0x2) |
|
| - | 510 | { |
|
| - | 511 | Pca95xx_set_in(sns_irTransceive_TX2_PWRh); |
|
| - | 512 | } |
|
| - | 513 | #endif |
|
| 445 | break; |
514 | break; |
| 446 | } |
515 | } |
| 447 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
516 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
| 448 | } |
517 | } |
| 449 | #endif |
518 | #endif |