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 1753 | ||
|---|---|---|---|
| Line 392... | Line 392... | ||
| 392 | } |
392 | } |
| 393 | } |
393 | } |
| 394 | 394 | ||
| 395 | void IrTransceiver_Transmit(uint8_t channel, uint16_t *buffer, uint8_t length) |
395 | void IrTransceiver_Transmit(uint8_t channel, uint16_t *buffer, uint8_t length) |
| 396 | { |
396 | { |
| - | 397 | uint16_t diff; |
|
| - | 398 | uint8_t findchannel; |
|
| - | 399 | ||
| 397 | if (length > 0) |
400 | if (length > 0) |
| 398 | { |
401 | { |
| 399 | if (drvIrTxChannel[channel].timeoutEnable == FALSE) |
402 | if (drvIrTxChannel[channel].timeoutEnable == FALSE) |
| 400 | { |
403 | { |
| 401 | drvIrTxChannel[channel].timeoutEnable = TRUE; |
404 | drvIrTxChannel[channel].timeoutEnable = TRUE; |
| 402 | drvIrTxChannel[channel].txbuf = buffer; |
405 | drvIrTxChannel[channel].txbuf = buffer; |
| 403 | drvIrTxChannel[channel].txlen = length; |
406 | drvIrTxChannel[channel].txlen = length; |
| 404 | /* first value will be loaded directly to timer |
407 | /* first value will be loaded directly to timer below, therefore index is set to 1 here */ |
| 405 | drvIrTxChannel[channel].txindex = 1; |
408 | drvIrTxChannel[channel].txindex = 1; |
| 406 | - | ||
| 407 | drvIrTxChannel[channel].timeout = IR_COUNT_REG + drvIrTxChannel[channel].txbuf[0]; |
409 | drvIrTxChannel[channel].timeout = IR_COUNT_REG + drvIrTxChannel[channel].txbuf[0]; |
| 408 | /* TODO: only modify timer reg if this channel has the lowest time left */ |
- | |
| 409 | IR_COMPARE_REG = drvIrTxChannel[channel].timeout; |
- | |
| 410 | 410 | ||
| - | 411 | ||
| - | 412 | findchannel = 0; |
|
| - | 413 | diff = 0xffff; |
|
| - | 414 | uint16_t time = IR_COMPARE_REG; |
|
| - | 415 | /* go through all channels and find the one that have the next overflow */ |
|
| - | 416 | for (uint8_t i=0; i < IR_SUPPORTED_NUM_CHANNELS; i++) |
|
| - | 417 | { |
|
| - | 418 | /* if channel is waiting for an overflow */ |
|
| - | 419 | if (drvIrTxChannel[i].timeoutEnable==TRUE) |
|
| - | 420 | { |
|
| - | 421 | if (drvIrTxChannel[i].timeout - time < diff) // || (timeout - time > 0xffff-IR_MAX_PULSE_WIDTH) |
|
| - | 422 | { |
|
| - | 423 | diff = drvIrTxChannel[i].timeout - time; |
|
| - | 424 | findchannel = i; |
|
| - | 425 | } |
|
| - | 426 | } |
|
| - | 427 | } |
|
| - | 428 | ||
| - | 429 | /* set compare value to the channel that have the next overflow */ |
|
| - | 430 | IR_COMPARE_REG = drvIrTxChannel[findchannel].timeout; |
|
| - | 431 | ||
| - | 432 | /* Start send on pin */ |
|
| 411 | IR_OUTP_HIGH(); |
433 | IR_OUTP_HIGH(); |
| 412 | 434 | ||
| - | 435 | /* enable overflow interrupt */ |
|
| 413 | IR_UNMASK_COMPARE(); |
436 | IR_UNMASK_COMPARE(); |
| 414 | } |
437 | } |
| 415 | } |
438 | } |
| 416 | } |
439 | } |
| 417 | #endif |
440 | #endif |