Rev 1848 | Rev 1850 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1848 | Rev 1849 | ||
|---|---|---|---|
| Line 111... | Line 111... | ||
| 111 | volatile uint32_t sns_irTransceive_LastPronto=0; |
111 | volatile uint32_t sns_irTransceive_LastPronto=0; |
| 112 | static uint8_t activeChannel = 0; |
112 | static uint8_t activeChannel = 0; |
| 113 | #define sns_irTransceive_MAXTIMING (16*1000) |
113 | #define sns_irTransceive_MAXTIMING (16*1000) |
| 114 | 114 | ||
| 115 | static void send_pronto(uint16_t *buffer, uint8_t len, uint8_t channel, uint16_t modfreq) { |
115 | static void send_pronto(uint16_t *buffer, uint8_t len, uint8_t channel, uint16_t modfreq) { |
| 116 | return; |
- | |
| 117 | - | ||
| 118 | StdCan_Msg_t msg; |
116 | StdCan_Msg_t msg; |
| 119 | 117 | ||
| 120 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
118 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
| 121 | StdCan_Set_direction(msg.Header, DIRECTIONFLAG_FROM_OWNER); |
119 | StdCan_Set_direction(msg.Header, DIRECTIONFLAG_FROM_OWNER); |
| 122 | msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE; |
120 | msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE; |
| Line 133... | Line 131... | ||
| 133 | msg.Data[0] = ((channel<<4)|0xf); |
131 | msg.Data[0] = ((channel<<4)|0xf); |
| 134 | msg.Data[1] = 0x10; |
132 | msg.Data[1] = 0x10; |
| 135 | msg.Data[2] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>16)&0xff; |
133 | msg.Data[2] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>16)&0xff; |
| 136 | msg.Data[3] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>8)&0xff; |
134 | msg.Data[3] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>8)&0xff; |
| 137 | msg.Data[4] = ((currentTime-sns_irTransceive_LastPronto)*1000)&0xff; |
135 | msg.Data[4] = ((currentTime-sns_irTransceive_LastPronto)*1000)&0xff; |
| 138 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
136 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
| 139 | _delay_ms(1); |
137 | _delay_ms(1); |
| 140 | } |
138 | } |
| 141 | sns_irTransceive_LastPronto=currentTime; |
139 | sns_irTransceive_LastPronto=currentTime; |
| 142 | 140 | ||
| 143 | // calculate frequency divider |
141 | // calculate frequency divider |
| 144 | uint16_t divider = (uint16_t)(sns_irTransceive_BaseFrq / (1000*(uint32_t)modfreq)); |
142 | uint16_t divider = (uint16_t)(sns_irTransceive_BaseFrq / (1000*(uint32_t)modfreq)); |
| 145 | 143 | ||
| Line 170... | Line 168... | ||
| 170 | /* Remember byte if data does not fit 8 bit */ |
168 | /* Remember byte if data does not fit 8 bit */ |
| 171 | uint8_t mem = 0; |
169 | uint8_t mem = 0; |
| 172 | while (i < len) |
170 | while (i < len) |
| 173 | { |
171 | { |
| 174 | if (mem > 0) |
172 | if (mem > 0) |
| 175 | { |
173 | { |
| 176 | /* If byte was memorized then buffer it */ |
174 | /* If byte was memorized then buffer it */ |
| 177 | msg.Data[j] = mem; |
175 | msg.Data[j] = mem; |
| 178 | /* Clear memory */ |
176 | /* Clear memory */ |
| 179 | mem = 0; |
177 | mem = 0; |
| 180 | } |
178 | } |
| Line 205... | Line 203... | ||
| 205 | msg.Data[j] = 0; |
203 | msg.Data[j] = 0; |
| 206 | } |
204 | } |
| 207 | else |
205 | else |
| 208 | { |
206 | { |
| 209 | msg.Data[j] = data&0xff; |
207 | msg.Data[j] = data&0xff; |
| 210 | } |
208 | } |
| 211 | 209 | ||
| 212 | i++; |
210 | i++; |
| 213 | } |
211 | } |
| 214 | 212 | ||
| 215 | j++; |
213 | j++; |
| 216 | if (j==8) |
214 | if (j==8) |
| 217 | { |
215 | { |
| 218 | /* If send buffer is full, send frame */ |
216 | /* If send buffer is full, send frame */ |
| 219 | /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
217 | /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
| 220 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
218 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
| 221 | _delay_ms(1); |
219 | _delay_ms(1); |
| Line 410... | Line 408... | ||
| 410 | #if IR_RX_ENABLE==1 |
408 | #if IR_RX_ENABLE==1 |
| 411 | gpio_set_pin(sns_irTransceive_VCC_EN1_PIN); |
409 | gpio_set_pin(sns_irTransceive_VCC_EN1_PIN); |
| 412 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN); |
410 | IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN); |
| 413 | #endif |
411 | #endif |
| 414 | IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX1_PIN); |
412 | IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX1_PIN); |
| 415 | 413 | ||
| 416 | #if sns_irTransceive_ENABLE_PCA95xx==1 |
414 | #if sns_irTransceive_ENABLE_PCA95xx==1 |
| 417 | Pca95xx_set_out(sns_irTransceive_TX1_PWRl); |
415 | Pca95xx_set_out(sns_irTransceive_TX1_PWRl); |
| 418 | Pca95xx_set_out(sns_irTransceive_TX1_PWRh); |
416 | Pca95xx_set_out(sns_irTransceive_TX1_PWRh); |
| 419 | if (power&0x1) |
417 | if (power&0x1) |
| 420 | { |
418 | { |
| 421 | Pca95xx_set_in(sns_irTransceive_TX1_PWRl); |
419 | Pca95xx_set_in(sns_irTransceive_TX1_PWRl); |
| Line 698... | Line 696... | ||
| 698 | } |
696 | } |
| 699 | 697 | ||
| 700 | case sns_irTransceive_STATE_PRONTO_REPEAT: |
698 | case sns_irTransceive_STATE_PRONTO_REPEAT: |
| 701 | { |
699 | { |
| 702 | /* Check if done. */ |
700 | /* Check if done. */ |
| 703 | if ( |
701 | if ((irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats && irTxChannel[channel].proto.repeats != 0xFF) || irTxChannel[channel].stopSend) { |
| 704 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
702 | irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE; |
| 705 | break; |
703 | break; |
| 706 | } |
704 | } |
| 707 | 705 | ||
| 708 | if (irTxChannel[channel].repeatCount < 255) { |
706 | if (irTxChannel[channel].repeatCount < 255) { |
| Line 811... | Line 809... | ||
| 811 | 809 | ||
| 812 | default: |
810 | default: |
| 813 | break; |
811 | break; |
| 814 | } |
812 | } |
| 815 | #endif |
813 | #endif |
| 816 | 814 | ||
| 817 | } |
815 | } |
| 818 | } |
816 | } |
| 819 | 817 | ||
| 820 | 818 | ||
| 821 | /* Handle incoming CAN data */ |
819 | /* Handle incoming CAN data */ |
| 822 | void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
820 | void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg) |
| Line 908... | Line 906... | ||
| 908 | /* TODO: Send response frame */ |
906 | /* TODO: Send response frame */ |
| 909 | break; |
907 | break; |
| 910 | } |
908 | } |
| 911 | 909 | ||
| 912 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTOP: |
910 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTOP: |
| 913 | /* |
911 | /* Sanity check. */ |
| - | 912 | if (channel >= IR_SUPPORTED_NUM_CHANNELS) break; |
|
| - | 913 | ||
| - | 914 | irTxChannel[channel].stopSend = TRUE; |
|
| 914 | 915 | ||
| 915 | /* TODO: Send response frame */ |
916 | /* TODO: Send response frame */ |
| 916 | break; |
917 | break; |
| - | 918 | ||
| 917 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOCONTINUE: |
919 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOCONTINUE: |
| - | 920 | /* Sanity check. */ |
|
| - | 921 | if (channel >= IR_SUPPORTED_NUM_CHANNELS) break; |
|
| - | 922 | ||
| 918 | /* |
923 | /* Reset repeat counter, i.e. request additional repeats. */ |
| - | 924 | irTxChannel[channel].repeatCount = 0; |
|
| 919 | 925 | ||
| 920 | /* TODO: Send response frame */ |
926 | /* TODO: Send response frame */ |
| 921 | break; |
927 | break; |
| 922 | 928 | ||
| 923 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1: /* Fall through */ |
929 | case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1: /* Fall through */ |