Rev 1811 | Rev 1813 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1811 | Rev 1812 | ||
|---|---|---|---|
| Line 92... | Line 92... | ||
| 92 | #endif |
92 | #endif |
| 93 | 93 | ||
| 94 | #ifndef sns_irTransceive_PRONTO_SUPPORT |
94 | #ifndef sns_irTransceive_PRONTO_SUPPORT |
| 95 | #define sns_irTransceive_PRONTO_SUPPORT 0 |
95 | #define sns_irTransceive_PRONTO_SUPPORT 0 |
| 96 | #endif |
96 | #endif |
| 97 | - | ||
| 98 | #if sns_irTransceive_PRONTO_SUPPORT==1 |
97 | #if sns_irTransceive_PRONTO_SUPPORT==1 |
| 99 | #define BaseFrq (4145146ULL) |
98 | #define BaseFrq (4145146ULL) |
| 100 | /* TODO configurable divider parameter */ |
99 | /* TODO configurable divider parameter */ |
| 101 | #define wFrqDiv (0x6d) |
100 | #define wFrqDiv (0x6d) |
| 102 | #define divider (1000000ULL*wFrqDiv/BaseFrq) |
101 | #define divider (1000000ULL*wFrqDiv/BaseFrq) |
| - | 102 | ||
| 103 | 103 | ||
| 104 | void send_pronto(uint16_t *buffer, uint8_t len) { |
104 | void send_pronto(uint16_t *buffer, uint8_t len) { |
| 105 | StdCan_Msg_t msg; |
105 | StdCan_Msg_t msg; |
| 106 | 106 | ||
| 107 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
107 | StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS); |
| Line 114... | Line 114... | ||
| 114 | msg.Data[0] = 0x00; /* Prontoformat 0x0000 */ |
114 | msg.Data[0] = 0x00; /* Prontoformat 0x0000 */ |
| 115 | msg.Data[1] = 0x00; |
115 | msg.Data[1] = 0x00; |
| 116 | msg.Data[2] = 0x00; /* Freq divider, 38kHz => 0x006d TODO: configurable */ |
116 | msg.Data[2] = 0x00; /* Freq divider, 38kHz => 0x006d TODO: configurable */ |
| 117 | msg.Data[3] = wFrqDiv; |
117 | msg.Data[3] = wFrqDiv; |
| 118 | msg.Data[4] = 0x00; /* Once seq length, first byte always 0 */ |
118 | msg.Data[4] = 0x00; /* Once seq length, first byte always 0 */ |
| 119 | msg.Data[5] = |
119 | msg.Data[5] = 0x00; //len/2; /* not correct if any byte overflows */ |
| 120 | msg.Data[6] = 0x00; /* Repeat seq length, always 0 for ir receive */ |
120 | msg.Data[6] = 0x00; /* Repeat seq length, always 0 for ir receive */ |
| 121 | msg.Data[7] = 0x00; |
121 | msg.Data[7] = 0x00; |
| 122 | 122 | ||
| 123 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
123 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
| - | 124 | _delay_ms(1); |
|
| - | 125 | ||
| - | 126 | msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1; |
|
| - | 127 | uint8_t i = 0; |
|
| - | 128 | uint8_t j = 0; |
|
| - | 129 | uint8_t mem = 0; |
|
| - | 130 | while (i < len) |
|
| - | 131 | { |
|
| - | 132 | if (mem > 0) |
|
| - | 133 | { |
|
| - | 134 | /* If byte was memorized then buffer it */ |
|
| - | 135 | msg.Data[j] = mem; |
|
| - | 136 | /* Clear memory */ |
|
| - | 137 | mem = 0; |
|
| - | 138 | } |
|
| - | 139 | else |
|
| - | 140 | { |
|
| - | 141 | if (buffer[i] >= (2^8)) |
|
| - | 142 | { |
|
| - | 143 | /* If data does not fit into 8 bit, then split, memorize low byte */ |
|
| - | 144 | mem = buffer[i]&0xff; |
|
| - | 145 | /* Buffer high byte */ |
|
| - | 146 | msg.Data[j] = (buffer[i]>>8)&0xff; |
|
| - | 147 | j++; |
|
| - | 148 | if (j==8) |
|
| - | 149 | { |
|
| - | 150 | /* If send buffer is full, send frame */ |
|
| - | 151 | /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
|
| - | 152 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
|
| 124 | _delay_ms(1); |
153 | _delay_ms(1); |
| - | 154 | j=0; |
|
| - | 155 | msg.Header.Command++; |
|
| - | 156 | } |
|
| - | 157 | /* Set complementary burst pair to 0 to indicate 16bit transmission */ |
|
| - | 158 | msg.Data[j] = 0; |
|
| - | 159 | } |
|
| - | 160 | else |
|
| - | 161 | { |
|
| - | 162 | msg.Data[j] = buffer[i]&0xff; |
|
| - | 163 | } |
|
| 125 | 164 | ||
| 126 | msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1; |
- | |
| 127 | for (uint8_t i = 0; i < len>>3; i++) { |
- | |
| 128 |
|
165 | i++; |
| - | 166 | } |
|
| 129 | 167 | ||
| - | 168 | j++; |
|
| 130 |
|
169 | if (j==8) |
| 131 | { |
170 | { |
| 132 |
|
171 | /* If send buffer is full, send frame */ |
| 133 | msg.Data[j+1] = (buffer[index+j+1]/divider)&0xff; |
- | |
| 134 | } |
- | |
| 135 | - | ||
| 136 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
172 | /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
| 137 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
173 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
| 138 | _delay_ms(1); |
174 | _delay_ms(1); |
| 139 | 175 | j=0; |
|
| 140 | msg.Header.Command++; |
176 | msg.Header.Command++; |
| 141 | } |
177 | } |
| 142 | 178 | ||
| 143 | uint8_t lastpacketcnt = len&0x03; |
- | |
| - | 179 | } |
|
| - | 180 | ||
| 144 | /* msg command kept from for loop, but increase 16 */ |
181 | /* msg command kept from for loop, but increase 16 to send ProntoEnd */ |
| 145 | msg.Header.Command+=16; |
182 | msg.Header.Command+=16; |
| 146 | msg.Length = |
183 | msg.Length = j; |
| 147 |
|
184 | /* data kept from loop */ |
| 148 | msg.Data[i<<1] = ((buffer[(len&0xfc)|i]/divider)>>8)&0xff; |
- | |
| 149 | msg.Data[(i<<1)+1] = ((buffer[(len&0xfc)|i]/divider)>>0)&0xff; |
- | |
| 150 | } |
- | |
| 151 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
185 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
| 152 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
186 | while (StdCan_Put(&msg) != StdCan_Ret_OK) {} |
| 153 | _delay_ms(1); |
187 | _delay_ms(1); |
| 154 | } |
188 | } |
| 155 | #endif |
189 | #endif |