Rev 1771 | Rev 1811 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1771 | Rev 1810 | ||
|---|---|---|---|
| Line 45... | Line 45... | ||
| 45 | #endif |
45 | #endif |
| 46 | 46 | ||
| 47 | uint16_t buf[IR_SUPPORTED_NUM_CHANNELS][MAX_NR_TIMES]; |
47 | uint16_t buf[IR_SUPPORTED_NUM_CHANNELS][MAX_NR_TIMES]; |
| 48 | 48 | ||
| 49 | StdCan_Msg_t irTxMsg; |
49 | StdCan_Msg_t irTxMsg; |
| - | 50 | ||
| - | 51 | #ifndef sns_irTransceive_PRONTO_SUPPORT |
|
| - | 52 | #define sns_irTransceive_PRONTO_SUPPORT 1 |
|
| - | 53 | #endif |
|
| 50 | 54 | ||
| 51 | #if (sns_irTransceive_SEND_DEBUG==1) |
55 | #if (sns_irTransceive_SEND_DEBUG==1) |
| 52 | void send_debug(uint16_t *buffer, uint8_t len) { |
56 | void send_debug(uint16_t *buffer, uint8_t len) { |
| 53 | StdCan_Msg_t dbgIrTxMsg; |
57 | StdCan_Msg_t dbgIrTxMsg; |
| 54 | /* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */ |
58 | /* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */ |
| Line 69... | Line 73... | ||
| 69 | dbgIrTxMsg.Data[4] = (buffer[index+2]>>8)&0xff; |
73 | dbgIrTxMsg.Data[4] = (buffer[index+2]>>8)&0xff; |
| 70 | dbgIrTxMsg.Data[5] = (buffer[index+2]>>0)&0xff; |
74 | dbgIrTxMsg.Data[5] = (buffer[index+2]>>0)&0xff; |
| 71 | dbgIrTxMsg.Data[6] = (buffer[index+3]>>8)&0xff; |
75 | dbgIrTxMsg.Data[6] = (buffer[index+3]>>8)&0xff; |
| 72 | dbgIrTxMsg.Data[7] = (buffer[index+3]>>0)&0xff; |
76 | dbgIrTxMsg.Data[7] = (buffer[index+3]>>0)&0xff; |
| 73 | 77 | ||
| 74 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
78 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
| 75 | while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {} |
79 | while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {} |
| 76 | _delay_ms(1); |
80 | _delay_ms(1); |
| 77 | } |
81 | } |
| 78 | 82 | ||
| 79 | uint8_t lastpacketcnt = len&0x03; |
83 | uint8_t lastpacketcnt = len&0x03; |
| 80 | if (lastpacketcnt > 0) { |
84 | if (lastpacketcnt > 0) { |
| 81 | dbgIrTxMsg.Length = lastpacketcnt<<1; |
85 | dbgIrTxMsg.Length = lastpacketcnt<<1; |
| 82 | for (uint8_t i = 0; i < lastpacketcnt; i++) { |
86 | for (uint8_t i = 0; i < lastpacketcnt; i++) { |
| 83 | dbgIrTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff; |
87 | dbgIrTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff; |
| 84 | dbgIrTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff; |
88 | dbgIrTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff; |
| 85 | } |
89 | } |
| 86 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
90 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
| 87 | while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {} |
91 | while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {} |
| 88 | _delay_ms(1); |
92 | _delay_ms(1); |
| 89 | } |
93 | } |
| 90 | 94 | ||
| 91 | } |
95 | } |
| - | 96 | #if sns_irTransceive_PRONTO_SUPPORT==1 |
|
| - | 97 | ||
| - | 98 | /* TODO configurable divider parameter */ |
|
| - | 99 | #define BaseFrq (4145146ULL) |
|
| - | 100 | #define wFrqDiv (0x6d) |
|
| - | 101 | #define divider (1000000ULL*wFrqDiv/BaseFrq) |
|
| - | 102 | ||
| - | 103 | void send_pronto(uint16_t *buffer, uint8_t len) { |
|
| - | 104 | StdCan_Msg_t msg; |
|
| - | 105 | ||
| - | 106 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
|
| - | 107 | StdCan_Set_direction(msg.Header, DIRECTIONFLAG_FROM_OWNER); |
|
| - | 108 | msg.Length = 8; |
|
| - | 109 | msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE; |
|
| - | 110 | msg.Header.ModuleId = sns_irTransceive_ID; |
|
| - | 111 | msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTART; |
|
| - | 112 | ||
| - | 113 | msg.Data[0] = 0x00; /* Prontoformat 0x0000 */ |
|
| - | 114 | msg.Data[1] = 0x00; |
|
| - | 115 | msg.Data[2] = 0x00; /* Freq divider, 38kHz => 0x006d TODO: configurable */ |
|
| - | 116 | msg.Data[3] = wFrqDiv; |
|
| - | 117 | msg.Data[4] = 0x00; /* Once seq length, first byte always 0 */ |
|
| - | 118 | msg.Data[5] = len/2; |
|
| - | 119 | msg.Data[6] = 0x00; /* Repeat seq length, always 0 for ir receive */ |
|
| - | 120 | msg.Data[7] = 0x00; |
|
| - | 121 | ||
| - | 122 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
|
| - | 123 | _delay_ms(1); |
|
| - | 124 | ||
| - | 125 | /* TODO Add more prontodata commands -> 32 */ |
|
| - | 126 | ||
| - | 127 | msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1; |
|
| - | 128 | for (uint8_t i = 0; i < len>>2; i++) { |
|
| - | 129 | uint8_t index = i<<2; |
|
| - | 130 | ||
| - | 131 | msg.Data[0] = ((buffer[index]/divider)>>8)&0xff; |
|
| - | 132 | msg.Data[1] = ((buffer[index]/divider)>>0)&0xff; |
|
| - | 133 | msg.Data[2] = ((buffer[index+1]/divider)>>8)&0xff; |
|
| - | 134 | msg.Data[3] = ((buffer[index+1]/divider)>>0)&0xff; |
|
| - | 135 | msg.Data[4] = ((buffer[index+2]/divider)>>8)&0xff; |
|
| - | 136 | msg.Data[5] = ((buffer[index+2]/divider)>>0)&0xff; |
|
| - | 137 | msg.Data[6] = ((buffer[index+3]/divider)>>8)&0xff; |
|
| - | 138 | msg.Data[7] = ((buffer[index+3]/divider)>>0)&0xff; |
|
| - | 139 | ||
| - | 140 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
|
| - | 141 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
|
| - | 142 | _delay_ms(1); |
|
| - | 143 | ||
| - | 144 | msg.Header.Command++; |
|
| - | 145 | } |
|
| - | 146 | ||
| - | 147 | uint8_t lastpacketcnt = len&0x03; |
|
| - | 148 | /* msg command kept from for loop, but increase 16 */ |
|
| - | 149 | msg.Header.Command+=32; |
|
| - | 150 | msg.Length = lastpacketcnt<<1; |
|
| - | 151 | for (uint8_t i = 0; i < lastpacketcnt; i++) { |
|
| - | 152 | msg.Data[i<<1] = ((buffer[(len&0xfc)|i]/divider)>>8)&0xff; |
|
| - | 153 | msg.Data[(i<<1)+1] = ((buffer[(len&0xfc)|i]/divider)>>0)&0xff; |
|
| - | 154 | } |
|
| - | 155 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
|
| - | 156 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
|
| - | 157 | _delay_ms(1); |
|
| - | 158 | } |
|
| - | 159 | #endif |
|
| 92 | #endif |
160 | #endif |
| 93 | 161 | ||
| 94 | 162 | ||
| 95 | #if IR_RX_ENABLE==1 |
163 | #if IR_RX_ENABLE==1 |
| 96 | void sns_irTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len) |
164 | void sns_irTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len) |
| 97 | { |
165 | { |
| Line 166... | Line 234... | ||
| 166 | Pca95xx_set_out(sns_irTransceive_TX0_PWRl); |
234 | Pca95xx_set_out(sns_irTransceive_TX0_PWRl); |
| 167 | Pca95xx_set_out(sns_irTransceive_TX0_PWRh); |
235 | Pca95xx_set_out(sns_irTransceive_TX0_PWRh); |
| 168 | if (power&0x1) |
236 | if (power&0x1) |
| 169 | { |
237 | { |
| 170 | Pca95xx_set_in(sns_irTransceive_TX0_PWRl); |
238 | Pca95xx_set_in(sns_irTransceive_TX0_PWRl); |
| 171 | } |
239 | } |
| 172 | if (power&0x2) |
240 | if (power&0x2) |
| 173 | { |
241 | { |
| 174 | Pca95xx_set_in(sns_irTransceive_TX0_PWRh); |
242 | Pca95xx_set_in(sns_irTransceive_TX0_PWRh); |
| 175 | } |
243 | } |
| 176 | #endif |
244 | #endif |
| 177 | break; |
245 | break; |
| 178 | case 1: |
246 | case 1: |
| 179 | #if IR_RX_ENABLE==1 |
247 | #if IR_RX_ENABLE==1 |
| 180 | gpio_set_pin(sns_irTransceive_VCC_EN1_PIN); |
248 | gpio_set_pin(sns_irTransceive_VCC_EN1_PIN); |
| Line 186... | Line 254... | ||
| 186 | Pca95xx_set_out(sns_irTransceive_TX1_PWRl); |
254 | Pca95xx_set_out(sns_irTransceive_TX1_PWRl); |
| 187 | Pca95xx_set_out(sns_irTransceive_TX1_PWRh); |
255 | Pca95xx_set_out(sns_irTransceive_TX1_PWRh); |
| 188 | if (power&0x1) |
256 | if (power&0x1) |
| 189 | { |
257 | { |
| 190 | Pca95xx_set_in(sns_irTransceive_TX1_PWRl); |
258 | Pca95xx_set_in(sns_irTransceive_TX1_PWRl); |
| 191 | } |
259 | } |
| 192 | if (power&0x2) |
260 | if (power&0x2) |
| 193 | { |
261 | { |
| 194 | Pca95xx_set_in(sns_irTransceive_TX1_PWRh); |
262 | Pca95xx_set_in(sns_irTransceive_TX1_PWRh); |
| 195 | } |
263 | } |
| 196 | #endif |
264 | #endif |
| 197 | break; |
265 | break; |
| 198 | case 2: |
266 | case 2: |
| 199 | #if IR_RX_ENABLE==1 |
267 | #if IR_RX_ENABLE==1 |
| 200 | gpio_set_pin(sns_irTransceive_VCC_EN2_PIN); |
268 | gpio_set_pin(sns_irTransceive_VCC_EN2_PIN); |
| 201 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN); |
269 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN); |
| Line 210... | Line 278... | ||
| 210 | Pca95xx_set_in(sns_irTransceive_TX2_PWRl); |
278 | Pca95xx_set_in(sns_irTransceive_TX2_PWRl); |
| 211 | } |
279 | } |
| 212 | if (power&0x2) |
280 | if (power&0x2) |
| 213 | { |
281 | { |
| 214 | Pca95xx_set_in(sns_irTransceive_TX2_PWRh); |
282 | Pca95xx_set_in(sns_irTransceive_TX2_PWRh); |
| 215 | } |
283 | } |
| 216 | #endif |
284 | #endif |
| 217 | break; |
285 | break; |
| 218 | } |
286 | } |
| 219 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
287 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
| 220 | } |
288 | } |
| 221 | #endif |
289 | #endif |
| 222 | } |
290 | } |
| 223 | } |
291 | } |
| 224 | 292 | ||
| 225 | 293 | ||
| 226 | void sns_irTransceive_Init(void) |
294 | void sns_irTransceive_Init(void) |
| 227 | { |
295 | { |
| 228 | StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS); |
296 | StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS); |
| 229 | StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
297 | StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 230 | irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE; |
298 | irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE; |
| 231 | irTxMsg.Header.ModuleId = sns_irTransceive_ID; |
299 | irTxMsg.Header.ModuleId = sns_irTransceive_ID; |
| 232 | irTxMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_IR; |
300 | irTxMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_IR; |
| Line 251... | Line 319... | ||
| 251 | irTxChannel[i].txlen = 0; |
319 | irTxChannel[i].txlen = 0; |
| 252 | irTxChannel[i].proto.data=0; |
320 | irTxChannel[i].proto.data=0; |
| 253 | irTxChannel[i].proto.repeats=0; |
321 | irTxChannel[i].proto.repeats=0; |
| 254 | irTxChannel[i].proto.framecnt=0; |
322 | irTxChannel[i].proto.framecnt=0; |
| 255 | irTxChannel[i].proto.protocol=0; |
323 | irTxChannel[i].proto.protocol=0; |
| 256 | #endif |
324 | #endif |
| 257 | } |
325 | } |
| 258 | 326 | ||
| 259 | #if IR_RX_ENABLE==1 |
327 | #if IR_RX_ENABLE==1 |
| 260 | // TODO: hardcoded to 3 channels?? /jm |
328 | // TODO: hardcoded to 3 channels?? /jm |
| 261 | irRxChannel[0].timerNum=sns_irTransceive_RX0_REPEATE_TIMER; |
329 | irRxChannel[0].timerNum=sns_irTransceive_RX0_REPEATE_TIMER; |
| 262 | irRxChannel[1].timerNum=sns_irTransceive_RX1_REPEATE_TIMER; |
330 | irRxChannel[1].timerNum=sns_irTransceive_RX1_REPEATE_TIMER; |
| Line 334... | Line 402... | ||
| 334 | } |
402 | } |
| 335 | 403 | ||
| 336 | void sns_irTransceive_Process(void) |
404 | void sns_irTransceive_Process(void) |
| 337 | { |
405 | { |
| 338 | for (uint8_t channel=0; channel < IR_SUPPORTED_NUM_CHANNELS; channel++) |
406 | for (uint8_t channel=0; channel < IR_SUPPORTED_NUM_CHANNELS; channel++) |
| 339 | { |
407 | { |
| 340 | 408 | ||
| 341 | #if IR_RX_ENABLE==1 |
409 | #if IR_RX_ENABLE==1 |
| 342 | switch (irRxChannel[channel].state) |
410 | switch (irRxChannel[channel].state) |
| 343 | { |
411 | { |
| 344 | case sns_irTransceive_STATE_IDLE: |
412 | case sns_irTransceive_STATE_IDLE: |
| 345 | irRxChannel[channel].state = sns_irTransceive_STATE_START_RECEIVE; |
413 | irRxChannel[channel].state = sns_irTransceive_STATE_START_RECEIVE; |
| 346 | break; |
414 | break; |
| 347 | 415 | ||
| 348 | case sns_irTransceive_STATE_START_RECEIVE: |
416 | case sns_irTransceive_STATE_START_RECEIVE: |
| 349 | IrTransceiver_ResetRx(channel); |
417 | IrTransceiver_ResetRx(channel); |
| 350 | cli(); |
418 | cli(); |
| 351 | irRxChannel[channel].newData = FALSE; |
419 | irRxChannel[channel].newData = FALSE; |
| 352 | sei(); |
420 | sei(); |
| 353 | irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING; |
421 | irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING; |
| 354 | break; |
422 | break; |
| 355 | 423 | ||
| 356 | case sns_irTransceive_STATE_RECEIVING: |
424 | case sns_irTransceive_STATE_RECEIVING: |
| Line 375... | Line 443... | ||
| 375 | StdCan_Put(&irTxMsg); |
443 | StdCan_Put(&irTxMsg); |
| 376 | } |
444 | } |
| 377 | else if (irRxChannel[channel].proto.protocol == IR_PROTO_UNKNOWN) |
445 | else if (irRxChannel[channel].proto.protocol == IR_PROTO_UNKNOWN) |
| 378 | { |
446 | { |
| 379 | #if (sns_irTransceive_SEND_DEBUG==1) |
447 | #if (sns_irTransceive_SEND_DEBUG==1) |
| - | 448 | #if sns_irTransceive_PRONTO_SUPPORT==0 |
|
| 380 | send_debug(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen); |
449 | send_debug(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen); |
| 381 | irRxChannel[channel].proto.timeout=300; |
450 | irRxChannel[channel].proto.timeout=300; |
| - | 451 | #endif |
|
| - | 452 | #if sns_irTransceive_PRONTO_SUPPORT==1 |
|
| - | 453 | send_pronto(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen); |
|
| - | 454 | irRxChannel[channel].proto.timeout=300; |
|
| - | 455 | #endif |
|
| - | 456 | ||
| 382 | #endif |
457 | #endif |
| 383 | } |
458 | } |
| 384 | 459 | ||
| 385 | /* Enable the receiver again */ |
460 | /* Enable the receiver again */ |
| 386 | IrTransceiver_EnableRx(channel); |
461 | IrTransceiver_EnableRx(channel); |