Rev 1865 | Rev 1875 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1865 | Rev 1871 | ||
|---|---|---|---|
| Line 14... | Line 14... | ||
| 14 | #include <drivers/mcu/pcint.h> |
14 | #include <drivers/mcu/pcint.h> |
| 15 | #include <drivers/ir/transceiver/irtransceiverMulti.h> |
15 | #include <drivers/ir/transceiver/irtransceiverMulti.h> |
| 16 | #include <drivers/ir/protocols.h> |
16 | #include <drivers/ir/protocols.h> |
| 17 | #include <avr/io.h> |
17 | #include <avr/io.h> |
| 18 | #include <avr/interrupt.h> |
18 | #include <avr/interrupt.h> |
| - | 19 | ||
| - | 20 | ||
| - | 21 | #include <drivers/mcu/gpio.h> |
|
| 19 | 22 | ||
| 20 | /*----------------------------------------------------------------------------- |
23 | /*----------------------------------------------------------------------------- |
| 21 | * Prerequisites |
24 | * Prerequisites |
| 22 | *---------------------------------------------------------------------------*/ |
25 | *---------------------------------------------------------------------------*/ |
| 23 | #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) |
26 | #if defined(__AVR_ATmega8__) || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) |
| Line 124... | Line 127... | ||
| 124 | /* is there more to send */ |
127 | /* is there more to send */ |
| 125 | if (drvIrTxChannel[channel].txindex < drvIrTxChannel[channel].txlen) |
128 | if (drvIrTxChannel[channel].txindex < drvIrTxChannel[channel].txlen) |
| 126 | { |
129 | { |
| 127 | /* load next timeout value */ |
130 | /* load next timeout value */ |
| 128 | drvIrTxChannel[channel].timeout = IR_COMPARE_REG + drvIrTxChannel[channel].txbuf[drvIrTxChannel[channel].txindex++]; |
131 | drvIrTxChannel[channel].timeout = IR_COMPARE_REG + drvIrTxChannel[channel].txbuf[drvIrTxChannel[channel].txindex++]; |
| 129 | } |
132 | } |
| 130 | else |
133 | else |
| 131 | { |
134 | { |
| 132 | /* disable this channel */ |
135 | /* disable this channel */ |
| 133 | drvIrTxChannel[channel].timeoutEnable = FALSE; |
136 | drvIrTxChannel[channel].timeoutEnable = FALSE; |
| 134 | 137 | ||
| 135 | /* disable the overflow interrupt */ |
138 | /* disable the overflow interrupt */ |
| Line 182... | Line 185... | ||
| 182 | drvIrRxChannel[i].storeEnable = FALSE; |
185 | drvIrRxChannel[i].storeEnable = FALSE; |
| 183 | } |
186 | } |
| 184 | 187 | ||
| 185 | /* Disable ISR */ |
188 | /* Disable ISR */ |
| 186 | IR_MASK_TIMEOUT(); |
189 | IR_MASK_TIMEOUT(); |
| - | 190 | ||
| - | 191 | // gpio_toggle_pin(EXP_J); |
|
| 187 | } |
192 | } |
| 188 | #endif |
193 | #endif |
| 189 | 194 | ||
| 190 | 195 | ||
| 191 | /*----------------------------------------------------------------------------- |
196 | /*----------------------------------------------------------------------------- |
| Line 202... | Line 207... | ||
| 202 | void IrTransceiver_Store_ch1(uint8_t id, uint8_t status) |
207 | void IrTransceiver_Store_ch1(uint8_t id, uint8_t status) |
| 203 | { |
208 | { |
| 204 | IrTransceiver_Store(1); |
209 | IrTransceiver_Store(1); |
| 205 | } |
210 | } |
| 206 | void IrTransceiver_Store_ch2(uint8_t id, uint8_t status) |
211 | void IrTransceiver_Store_ch2(uint8_t id, uint8_t status) |
| 207 | { |
212 | { |
| 208 | IrTransceiver_Store(2); |
213 | IrTransceiver_Store(2); |
| 209 | } |
214 | } |
| 210 | 215 | ||
| 211 | void IrTransceiver_Store(uint8_t channel) |
216 | void IrTransceiver_Store(uint8_t channel) |
| 212 | { |
217 | { |
| Line 217... | Line 222... | ||
| 217 | uint16_t time = IR_COUNT_REG; |
222 | uint16_t time = IR_COUNT_REG; |
| 218 | 223 | ||
| 219 | /* Subtract the current measurement from the previous to get the pulse width. */ |
224 | /* Subtract the current measurement from the previous to get the pulse width. */ |
| 220 | pulsewidth = time - prev_time[channel]; |
225 | pulsewidth = time - prev_time[channel]; |
| 221 | prev_time[channel] = time; |
226 | prev_time[channel] = time; |
| - | 227 | ||
| - | 228 | #if IR_MIN_STARTPULSE_WIDTH>0 |
|
| - | 229 | if ((pulsewidth <= IR_MIN_STARTPULSE_WIDTH) && (drvIrRxChannel[channel].storeEnable == TRUE) && (drvIrRxChannel[channel].rxlen == 0)) |
|
| - | 230 | { |
|
| - | 231 | IR_MASK_TIMEOUT(); |
|
| - | 232 | return; |
|
| - | 233 | } |
|
| - | 234 | else |
|
| - | 235 | { |
|
| - | 236 | IR_UNMASK_TIMEOUT(); |
|
| - | 237 | } |
|
| - | 238 | #endif |
|
| - | 239 | //gpio_toggle_pin(EXP_K); |
|
| 222 | 240 | ||
| 223 | if (drvIrRxChannel[channel].storeEnable) |
241 | if (drvIrRxChannel[channel].storeEnable) |
| 224 | { |
242 | { |
| 225 | /* Store the measurement. */ |
243 | /* Store the measurement. */ |
| 226 | drvIrRxChannel[channel].rxbuf[drvIrRxChannel[channel].rxlen++] = pulsewidth; |
244 | drvIrRxChannel[channel].rxbuf[drvIrRxChannel[channel].rxlen++] = pulsewidth; |
| Line 234... | Line 252... | ||
| 234 | else |
252 | else |
| 235 | { |
253 | { |
| 236 | /* Set the timeout for detection of the end of the pulse train. */ |
254 | /* Set the timeout for detection of the end of the pulse train. */ |
| 237 | drvIrRxChannel[channel].timeout = time + IR_MAX_PULSE_WIDTH; |
255 | drvIrRxChannel[channel].timeout = time + IR_MAX_PULSE_WIDTH; |
| 238 | IR_TIMEOUT_REG = drvIrRxChannel[channel].timeout; |
256 | IR_TIMEOUT_REG = drvIrRxChannel[channel].timeout; |
| 239 | } |
257 | } |
| 240 | } |
258 | } |
| 241 | else if (drvIrRxChannel[channel].enable == TRUE) |
259 | else if (drvIrRxChannel[channel].enable == TRUE) |
| 242 | { |
260 | { |
| 243 | /* The first edge of the pulse train has been detected. Enable the storage of the following pulsewidths. */ |
261 | /* The first edge of the pulse train has been detected. Enable the storage of the following pulsewidths. */ |
| 244 | drvIrRxChannel[channel].storeEnable = TRUE; |
262 | drvIrRxChannel[channel].storeEnable = TRUE; |
| 245 | drvIrRxChannel[channel].rxlen = 0; |
263 | drvIrRxChannel[channel].rxlen = 0; |
| Line 456... | Line 474... | ||
| 456 | /* Start send on pin */ |
474 | /* Start send on pin */ |
| 457 | IR_OUTP_HIGH(); |
475 | IR_OUTP_HIGH(); |
| 458 | 476 | ||
| 459 | /* enable overflow interrupt */ |
477 | /* enable overflow interrupt */ |
| 460 | IR_UNMASK_COMPARE(); |
478 | IR_UNMASK_COMPARE(); |
| - | 479 | ||
| - | 480 | return 1; |
|
| 461 | } |
481 | } |
| 462 | #endif |
482 | #endif |
| 463 | 483 | ||