Rev 25 | Rev 27 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 25 | Rev 26 | ||
---|---|---|---|
Line 66... | Line 66... | ||
66 | 66 | ||
67 | volatile uint8_t I2C_RxBufferSize = 0, I2C_TxBufferSize = 0; |
67 | volatile uint8_t I2C_RxBufferSize = 0, I2C_TxBufferSize = 0; |
68 | volatile uint8_t *I2C_TxBuffer = 0, *I2C_RxBuffer = 0; |
68 | volatile uint8_t *I2C_TxBuffer = 0, *I2C_RxBuffer = 0; |
Line 69... | Line -... | ||
69 | volatile uint8_t Tx_Idx = 0, Rx_Idx = 0; |
- | |
- | 69 | volatile uint8_t Tx_Idx = 0, Rx_Idx = 0; |
|
Line 70... | Line 70... | ||
70 | 70 | ||
71 | 71 | volatile uint8_t I2C_PrimRxBuffer[10]; |
|
72 | 72 | ||
73 | struct I2C_Heading_t I2C_Heading; |
73 | struct I2C_Heading_t I2C_Heading; |
Line 183... | Line 183... | ||
183 | case I2C_CMD_READ_HEADING: |
183 | case I2C_CMD_READ_HEADING: |
184 | I2C_TxBuffer = (uint8_t *)&I2C_Heading; |
184 | I2C_TxBuffer = (uint8_t *)&I2C_Heading; |
185 | I2C_TxBufferSize = sizeof(I2C_Heading); |
185 | I2C_TxBufferSize = sizeof(I2C_Heading); |
186 | I2C_RxBuffer = (uint8_t *)&I2C_WriteAttitude; |
186 | I2C_RxBuffer = (uint8_t *)&I2C_WriteAttitude; |
187 | I2C_RxBufferSize = sizeof(I2C_WriteAttitude); |
187 | I2C_RxBufferSize = sizeof(I2C_WriteAttitude); |
188 | // update heading from global variable |
- | |
189 | I2C_Heading.Heading = Heading; |
188 | I2C_Heading.Heading = Heading; |
190 | // copy current attitude from I2C rx buffer to uart rx buffer (this is used for the calulation of the heading) |
- | |
191 | ExternData.Attitude[NICK] = I2C_WriteAttitude.Nick; |
189 | ExternData.Attitude[NICK] = I2C_WriteAttitude.Nick; |
192 | ExternData.Attitude[ROLL] = I2C_WriteAttitude.Roll; |
190 | ExternData.Attitude[ROLL] = I2C_WriteAttitude.Roll; |
193 | break; |
191 | break; |
194 | default: // unknown command id |
192 | default: // unknown command id |
195 | I2C_RxBuffer = 0; |
193 | I2C_RxBuffer = 0; |
Line 203... | Line 201... | ||
203 | } |
201 | } |
204 | else // Rx_Idx != 0xFF |
202 | else // Rx_Idx != 0xFF |
205 | { |
203 | { |
206 | // fill receiver buffer with the byte that has been received |
204 | // fill receiver buffer with the byte that has been received |
207 | // if buffer exist and there is still some free space |
205 | // if buffer exist and there is still some free space |
208 | if((I2C_RxBuffer != 0) && (Rx_Idx < I2C_RxBufferSize)) |
206 | if(Rx_Idx < I2C_RxBufferSize) |
209 | { |
207 | { |
210 | I2C_RxBuffer[Rx_Idx] = data; |
208 | I2C_PrimRxBuffer[Rx_Idx] = data; |
211 | crc += data; |
209 | crc += data; |
212 | } |
210 | } |
213 | else if (Rx_Idx == I2C_RxBufferSize) // crc byte was transferred |
211 | else if (Rx_Idx == I2C_RxBufferSize) // crc byte was transfered |
214 | { |
212 | { // if checksum matched |
215 | if(crc == data) |
213 | if(crc == data) |
- | 214 | { // and RxBuffer exist |
|
- | 215 | if(I2C_RxBuffer != 0) |
|
- | 216 | { // copy data to rx buffer |
|
- | 217 | for(data = 0; data < I2C_RxBufferSize; data++) |
|
- | 218 | { |
|
- | 219 | I2C_RxBuffer[data] = I2C_PrimRxBuffer[data]; |
|
- | 220 | } |
|
- | 221 | } |
|
- | 222 | DebugOut.Analog[31]++; |
|
- | 223 | } |
|
- | 224 | else |
|
216 | { |
225 | { |
217 | // copy primary rx buffer to target |
226 | DebugOut.Analog[30]++; |
218 | } |
227 | } |
219 | } |
228 | } |
220 | // else ignore data |
229 | // else ignore data |
221 | Rx_Idx++; |
230 | Rx_Idx++; |
222 | } |
231 | } |