922
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file uart_Internal.c
|
|
4 * @author heinrichs weikamp gmbh
|
|
5 * @version V0.0.1
|
|
6 * @date 03-November-2044
|
|
7 * @brief Control functions for devices connected to the internal UART
|
|
8 *
|
|
9 @verbatim
|
|
10 ==============================================================================
|
|
11 ##### How to use #####
|
|
12 ==============================================================================
|
|
13 @endverbatim
|
|
14 ******************************************************************************
|
|
15 * @attention
|
|
16 *
|
|
17 * <h2><center>© COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
|
|
18 *
|
|
19 ******************************************************************************
|
|
20 */
|
|
21 /* Includes ------------------------------------------------------------------*/
|
|
22 #include "uart.h"
|
|
23 #include "uart_Internal.h"
|
|
24 #include "uartProtocol_GNSS.h"
|
|
25 #include "GNSS.h"
|
|
26 #include "externalInterface.h"
|
|
27 #include "data_exchange.h"
|
|
28 #include <string.h> /* memset */
|
|
29
|
|
30
|
|
31 static uint8_t isEndIndication6(uint8_t index);
|
|
32 static uint8_t gnssState = UART_GNSS_INIT;
|
|
33
|
|
34 /* Private variables ---------------------------------------------------------*/
|
|
35
|
|
36
|
|
37 #define TX_BUF_SIZE (40u) /* max length for commands */
|
|
38 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */
|
|
39 #define CHUNKS_PER_BUFFER (6u)
|
|
40
|
|
41 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor (UART mux) */
|
|
42 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */
|
|
43 #define TIMEOUT_SENSOR_ANSWER (300) /* Time till a request is repeated if no answer was received */
|
|
44
|
|
45
|
|
46 static receiveStateGnss_t rxState = GNSSRX_READY;
|
|
47 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */
|
|
48
|
|
49 static uint8_t writeIndex = 0;
|
|
50
|
|
51 static uint8_t dataToRead = 0;
|
|
52
|
|
53 DMA_HandleTypeDef hdma_usart6_rx, hdma_usart6_tx;
|
|
54
|
|
55 uint8_t tx6Buffer[CHUNK_SIZE]; /* tx uses less bytes */
|
|
56 uint8_t tx6BufferQue[TX_BUF_SIZE]; /* In MUX mode command may be send shortly after each other => allow q 1 entry que */
|
|
57 uint8_t tx6BufferQueLen;
|
|
58
|
|
59 uint8_t rxBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow variations in buffer read time */
|
|
60 uint8_t txBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow variations in buffer read time */
|
|
61
|
|
62 static uint8_t rx6WriteIndex; /* Index of the data item which is analysed */
|
|
63 static uint8_t rx6ReadIndex; /* Index at which new data is stared */
|
|
64
|
|
65 static uint8_t dmaRx6Active; /* Indicator if DMA reception needs to be started */
|
|
66 static uint8_t dmaTx6Active; /* Indicator if DMA reception needs to be started */
|
|
67
|
|
68
|
|
69 /* Exported functions --------------------------------------------------------*/
|
|
70
|
|
71 void UART_clearRx6Buffer(void)
|
|
72 {
|
|
73 uint16_t index = 0;
|
|
74 do
|
|
75 {
|
|
76 rxBufferUart6[index++] = BUFFER_NODATA_LOW;
|
|
77 rxBufferUart6[index++] = BUFFER_NODATA_HIGH;
|
|
78 } while (index < sizeof(rxBufferUart6));
|
|
79
|
|
80 rx6ReadIndex = 0;
|
|
81 rx6WriteIndex = 0;
|
|
82 }
|
|
83
|
|
84 void GNSS_IO_init() {
|
|
85
|
|
86 GPIO_InitTypeDef GPIO_InitStruct = { 0 };
|
|
87 /* Peripheral clock enable */
|
|
88 __HAL_RCC_USART6_CLK_ENABLE()
|
|
89 ;
|
|
90
|
|
91 __HAL_RCC_GPIOA_CLK_ENABLE()
|
|
92 ;
|
|
93 /**USART6 GPIO Configuration
|
|
94 PA11 ------> USART6_TX
|
|
95 PA12 ------> USART6_RX
|
|
96 */
|
|
97 GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
|
|
98 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
99 GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
100 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
|
|
101 GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
|
|
102 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
103
|
|
104 /* USART6 DMA Init */
|
|
105 /* USART6_RX Init */
|
923
|
106 hdma_usart6_rx.Instance = DMA2_Stream2;
|
922
|
107 hdma_usart6_rx.Init.Channel = DMA_CHANNEL_5;
|
|
108 hdma_usart6_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
|
109 hdma_usart6_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
|
110 hdma_usart6_rx.Init.MemInc = DMA_MINC_ENABLE;
|
|
111 hdma_usart6_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
|
|
112 hdma_usart6_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
|
113 hdma_usart6_rx.Init.Mode = DMA_NORMAL;
|
|
114 hdma_usart6_rx.Init.Priority = DMA_PRIORITY_LOW;
|
|
115 hdma_usart6_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
|
116 HAL_DMA_Init(&hdma_usart6_rx);
|
|
117
|
|
118 __HAL_LINKDMA(&huart6, hdmarx, hdma_usart6_rx);
|
|
119
|
|
120 /* USART6_TX Init */
|
|
121 hdma_usart6_tx.Instance = DMA2_Stream6;
|
|
122 hdma_usart6_tx.Init.Channel = DMA_CHANNEL_5;
|
|
123 hdma_usart6_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
|
124 hdma_usart6_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
|
125 hdma_usart6_tx.Init.MemInc = DMA_MINC_ENABLE;
|
|
126 hdma_usart6_tx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
|
|
127 hdma_usart6_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
|
|
128 hdma_usart6_tx.Init.Mode = DMA_NORMAL;
|
|
129 hdma_usart6_tx.Init.Priority = DMA_PRIORITY_LOW;
|
|
130 hdma_usart6_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
|
|
131 HAL_DMA_Init(&hdma_usart6_tx);
|
|
132
|
|
133 __HAL_LINKDMA(&huart6, hdmatx, hdma_usart6_tx);
|
|
134
|
|
135 /* USART6 interrupt Init */
|
|
136 HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);
|
|
137 HAL_NVIC_EnableIRQ(USART6_IRQn);
|
|
138
|
|
139 MX_USART6_DMA_Init();
|
|
140
|
|
141 }
|
|
142
|
|
143 void MX_USART6_DMA_Init() {
|
|
144 /* DMA controller clock enable */
|
|
145 __HAL_RCC_DMA2_CLK_ENABLE();
|
|
146
|
|
147 /* DMA interrupt init */
|
|
148 /* DMA2_Stream2_IRQn interrupt configuration */
|
|
149 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
|
|
150 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
|
|
151 /* DMA2_Stream6_IRQn interrupt configuration */
|
|
152 HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0);
|
|
153 HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
|
|
154 }
|
|
155
|
|
156
|
|
157 void MX_USART6_UART_DeInit(void)
|
|
158 {
|
|
159 HAL_DMA_Abort(&hdma_usart6_rx);
|
|
160 HAL_DMA_DeInit(&hdma_usart6_rx);
|
|
161 HAL_DMA_Abort(&hdma_usart6_tx);
|
|
162 HAL_DMA_DeInit(&hdma_usart6_tx);
|
|
163 HAL_UART_DeInit(&huart6);
|
|
164 HAL_UART_DeInit(&huart6);
|
|
165 }
|
|
166
|
|
167 void MX_USART6_UART_Init(void) {
|
|
168 huart6.Instance = USART6;
|
|
169 huart6.Init.BaudRate = 9600;
|
|
170 huart6.Init.WordLength = UART_WORDLENGTH_8B;
|
|
171 huart6.Init.StopBits = UART_STOPBITS_1;
|
|
172 huart6.Init.Parity = UART_PARITY_NONE;
|
|
173 huart6.Init.Mode = UART_MODE_TX_RX;
|
|
174 huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
175 huart6.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
176 HAL_UART_Init(&huart6);
|
923
|
177
|
|
178 UART_clearRx6Buffer();
|
|
179 dmaRx6Active = 0;
|
|
180 dmaTx6Active = 0;
|
|
181 tx6BufferQueLen = 0;
|
922
|
182 }
|
|
183
|
|
184
|
|
185
|
|
186 void UART6_SendCmdUbx(const uint8_t *cmd, uint8_t len)
|
|
187 {
|
|
188 if(len < TX_BUF_SIZE) /* A longer string is an indication for a missing 0 termination */
|
|
189 {
|
|
190 if(dmaRx6Active == 0)
|
|
191 {
|
927
|
192 UART6_StartDMA_Receiption();
|
922
|
193 }
|
|
194 memcpy(tx6Buffer, cmd, len);
|
|
195 if(HAL_OK == HAL_UART_Transmit_DMA(&huart6,tx6Buffer,len))
|
|
196 {
|
|
197 dmaTx6Active = 1;
|
|
198 }
|
|
199 }
|
|
200 }
|
|
201
|
|
202 uint8_t isEndIndication6(uint8_t index)
|
|
203 {
|
|
204 uint8_t ret = 0;
|
|
205 if(index % 2)
|
|
206 {
|
|
207 if(rxBufferUart6[index] == BUFFER_NODATA_HIGH)
|
|
208 {
|
|
209 ret = 1;
|
|
210 }
|
|
211 }
|
|
212 else
|
|
213 {
|
|
214 if(rxBufferUart6[index] == BUFFER_NODATA_LOW)
|
|
215 {
|
|
216 ret = 1;
|
|
217 }
|
|
218 }
|
|
219
|
|
220 return ret;
|
|
221 }
|
|
222
|
|
223 void UART6_StartDMA_Receiption()
|
|
224 {
|
|
225 if(dmaRx6Active == 0)
|
|
226 {
|
|
227 if(((rx6WriteIndex / CHUNK_SIZE) != (rx6ReadIndex / CHUNK_SIZE)) || ((isEndIndication6(rx6WriteIndex)) && (isEndIndication6(rx6WriteIndex + 1)))) /* start next transfer if we did not catch up with read index */
|
|
228 {
|
|
229 if(HAL_OK == HAL_UART_Receive_DMA (&huart6, &rxBufferUart6[rx6WriteIndex], CHUNK_SIZE))
|
|
230 {
|
|
231 dmaRx6Active = 1;
|
|
232 }
|
|
233 }
|
|
234 }
|
|
235 }
|
|
236
|
|
237
|
|
238
|
|
239 void UART6_RxCpltCallback(UART_HandleTypeDef *huart)
|
|
240 {
|
|
241 if(huart == &huart6)
|
|
242 {
|
|
243 dmaRx6Active = 0;
|
|
244 rx6WriteIndex+=CHUNK_SIZE;
|
|
245 if(rx6WriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
|
|
246 {
|
|
247 rx6WriteIndex = 0;
|
|
248 }
|
|
249 UART6_StartDMA_Receiption();
|
|
250 }
|
|
251 }
|
|
252 void UART6_TxCpltCallback(UART_HandleTypeDef *huart)
|
|
253 {
|
|
254 if(huart == &huart6)
|
|
255 {
|
|
256 dmaTx6Active = 0;
|
|
257 UART6_WriteData();
|
|
258 if(tx6BufferQueLen)
|
|
259 {
|
|
260 memcpy(tx6Buffer, tx6BufferQue, tx6BufferQueLen);
|
|
261 HAL_UART_Transmit_DMA(&huart6,tx6Buffer,tx6BufferQueLen);
|
|
262 dmaTx6Active = 1;
|
|
263 tx6BufferQueLen = 0;
|
|
264 }
|
|
265 }
|
|
266 }
|
|
267
|
|
268 void UART6_ReadData()
|
|
269 {
|
|
270 uint8_t localRX = rx6ReadIndex;
|
|
271 uint8_t futureIndex = rx6ReadIndex + 1;
|
|
272 uint8_t moreData = 0;
|
|
273
|
|
274 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
|
|
275 {
|
|
276 futureIndex = 0;
|
|
277 }
|
|
278
|
|
279 if((!isEndIndication6(localRX)) || (!isEndIndication6(futureIndex))) do
|
|
280 {
|
|
281 while((!isEndIndication6(localRX)) || (moreData))
|
|
282 {
|
|
283 moreData = 0;
|
|
284 UART6_Gnss_ProcessData(rxBufferUart6[localRX]);
|
|
285
|
|
286 if(localRX % 2)
|
|
287 {
|
|
288 rxBufferUart6[localRX] = BUFFER_NODATA_HIGH;
|
|
289 }
|
|
290 else
|
|
291 {
|
|
292 rxBufferUart6[localRX] = BUFFER_NODATA_LOW;
|
|
293 }
|
|
294
|
|
295 localRX++;
|
|
296 rx6ReadIndex++;
|
|
297 if(rx6ReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
|
|
298 {
|
|
299 localRX = 0;
|
|
300 rx6ReadIndex = 0;
|
|
301 }
|
|
302 futureIndex++;
|
|
303 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
|
|
304 {
|
|
305 futureIndex = 0;
|
|
306 }
|
|
307 }
|
|
308 if(!isEndIndication6(futureIndex))
|
|
309 {
|
|
310 moreData = 1;
|
|
311 }
|
|
312 } while(moreData);
|
|
313 }
|
|
314
|
|
315 void UART6_WriteData(void)
|
|
316 {
|
|
317 if(huart6.hdmatx->State == HAL_DMA_STATE_READY)
|
|
318 {
|
|
319 huart6.gState = HAL_UART_STATE_READY;
|
|
320 dmaTx6Active = 0;
|
|
321 }
|
|
322 if(huart6.hdmarx->State == HAL_DMA_STATE_READY)
|
|
323 {
|
|
324 huart6.RxState = HAL_UART_STATE_READY;
|
|
325 dmaRx6Active = 0;
|
|
326 }
|
|
327 }
|
|
328
|
|
329 void UART6_Gnss_SendCmd(uint8_t GnssCmd)
|
|
330 {
|
|
331 const uint8_t* pData;
|
|
332 uint8_t txLength = 0;
|
|
333
|
|
334 switch (GnssCmd)
|
|
335 {
|
|
336 case GNSSCMD_LOADCONF_0: pData = configUBX;
|
|
337 txLength = sizeof(configUBX) / sizeof(uint8_t);
|
|
338 break;
|
|
339 case GNSSCMD_LOADCONF_1: pData = setNMEA410;
|
|
340 txLength = sizeof(setNMEA410) / sizeof(uint8_t);
|
|
341 break;
|
|
342 case GNSSCMD_LOADCONF_2: pData = setGNSS;
|
|
343 txLength = sizeof(setGNSS) / sizeof(uint8_t);
|
|
344 break;
|
|
345 case GNSSCMD_GET_PVT_DATA: pData = getPVTData;
|
|
346 txLength = sizeof(getPVTData) / sizeof(uint8_t);
|
|
347 break;
|
|
348 case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData;
|
|
349 txLength = sizeof(getNavigatorData) / sizeof(uint8_t);
|
|
350 break;
|
|
351
|
|
352 default:
|
|
353 break;
|
|
354 }
|
|
355 if(txLength != 0)
|
|
356 {
|
|
357 UART6_SendCmdUbx(pData, txLength);
|
|
358 }
|
|
359 }
|
|
360
|
|
361 void UART6_Gnss_Control(void)
|
|
362 {
|
|
363 static uint32_t warmupTick = 0;
|
|
364
|
|
365 switch (gnssState)
|
|
366 {
|
|
367 case UART_GNSS_INIT: gnssState = UART_GNSS_WARMUP;
|
|
368 warmupTick = HAL_GetTick();
|
|
369 UART_clearRxBuffer();
|
|
370 break;
|
|
371 case UART_GNSS_WARMUP: if(time_elapsed_ms(warmupTick,HAL_GetTick()) > 1000)
|
|
372 {
|
|
373 gnssState = UART_GNSS_LOADCONF_0;
|
|
374 }
|
|
375 break;
|
|
376 case UART_GNSS_LOADCONF_0: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_0);
|
|
377 gnssState = UART_GNSS_LOADCONF_1;
|
|
378 rxState = GNSSRX_DETECT_ACK_0;
|
|
379 break;
|
|
380 case UART_GNSS_LOADCONF_1: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_1);
|
|
381 gnssState = UART_GNSS_LOADCONF_2;
|
|
382 rxState = GNSSRX_DETECT_ACK_0;
|
|
383 break;
|
|
384 case UART_GNSS_LOADCONF_2: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_2);
|
|
385 gnssState = UART_GNSS_IDLE;
|
|
386 rxState = GNSSRX_DETECT_ACK_0;
|
|
387 break;
|
|
388 case UART_GNSS_IDLE: UART6_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA);
|
|
389 gnssState = UART_GNSS_GET_PVT;
|
|
390 rxState = GNSSRX_DETECT_HEADER_0;
|
|
391 break;
|
|
392 default:
|
|
393 break;
|
|
394 }
|
|
395 }
|
|
396
|
|
397 void UART6_Gnss_ProcessData(uint8_t data)
|
|
398 {
|
|
399 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
|
|
400 switch(rxState)
|
|
401 {
|
|
402 case GNSSRX_DETECT_ACK_0:
|
|
403 case GNSSRX_DETECT_HEADER_0: if(data == 0xB5)
|
|
404 {
|
|
405 writeIndex = 0;
|
|
406 memset(GNSS_Handle.uartWorkingBuffer,0, sizeof(GNSS_Handle.uartWorkingBuffer));
|
|
407 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
|
|
408 rxState++;
|
|
409 }
|
|
410 break;
|
|
411 case GNSSRX_DETECT_ACK_1:
|
|
412 case GNSSRX_DETECT_HEADER_1: if(data == 0x62)
|
|
413 {
|
|
414 rxState++;
|
|
415 }
|
|
416 else
|
|
417 {
|
|
418 rxState = GNSSRX_DETECT_HEADER_0;
|
|
419 }
|
|
420 break;
|
|
421 case GNSSRX_DETECT_ACK_2: if(data == 0x05)
|
|
422 {
|
|
423 rxState++;
|
|
424 }
|
|
425 else
|
|
426 {
|
|
427 rxState = GNSSRX_DETECT_HEADER_0;
|
|
428 }
|
|
429 break;
|
|
430 case GNSSRX_DETECT_ACK_3: if((data == 0x01) || (data == 0x00))
|
|
431 {
|
|
432 GnssConnected = 1;
|
|
433 rxState = GNSSRX_READY;
|
|
434 }
|
|
435 else
|
|
436 {
|
|
437 rxState = GNSSRX_DETECT_HEADER_0;
|
|
438 }
|
|
439 break;
|
|
440 case GNSSRX_DETECT_HEADER_2: if(data == 0x01)
|
|
441 {
|
|
442 rxState++;
|
|
443 }
|
|
444 else
|
|
445 {
|
|
446 rxState = GNSSRX_DETECT_HEADER_0;
|
|
447 }
|
|
448 break;
|
|
449 case GNSSRX_DETECT_HEADER_3:
|
|
450 switch(data)
|
|
451 {
|
|
452 case 0x21: rxState = GNSSRX_READ_NAV_DATA;
|
|
453 dataToRead = 20;
|
|
454 break;
|
|
455 case 0x07: rxState = GNSSRX_READ_PVT_DATA;
|
|
456 dataToRead = 92;
|
|
457 break;
|
|
458 case 0x02: rxState = GNSSRX_READ_POSLLH_DATA;
|
|
459 break;
|
|
460 default: rxState = GNSSRX_DETECT_HEADER_0;
|
|
461 break;
|
|
462 }
|
|
463 break;
|
|
464 case GNSSRX_READ_NAV_DATA:
|
|
465 case GNSSRX_READ_PVT_DATA:
|
|
466 case GNSSRX_READ_POSLLH_DATA: if(dataToRead > 0)
|
|
467 {
|
|
468 dataToRead--;
|
|
469 }
|
|
470 else
|
|
471 {
|
|
472 switch(rxState)
|
|
473 {
|
|
474 case GNSSRX_READ_NAV_DATA: GNSS_ParseNavigatorData(&GNSS_Handle);
|
|
475 break;
|
|
476 case GNSSRX_READ_PVT_DATA: GNSS_ParsePVTData(&GNSS_Handle);
|
|
477 break;
|
|
478 case GNSSRX_READ_POSLLH_DATA: GNSS_ParsePOSLLHData(&GNSS_Handle);
|
|
479 break;
|
|
480 default: rxState = GNSSRX_DETECT_HEADER_0;
|
|
481 break;
|
|
482 }
|
|
483 rxState = GNSSRX_DETECT_HEADER_0;
|
|
484 gnssState = UART_GNSS_IDLE;
|
|
485 }
|
|
486 break;
|
|
487 default: rxState = GNSSRX_READY;
|
|
488 break;
|
|
489 }
|
|
490 }
|
|
491
|
|
492
|
|
493 void UART6_HandleUART()
|
|
494 {
|
|
495 static uint8_t retryRequest = 0;
|
|
496 static uint32_t lastRequestTick = 0;
|
|
497 static uint32_t TriggerTick = 0;
|
|
498 static uint8_t timeToTrigger = 0;
|
|
499 uint32_t tick = HAL_GetTick();
|
|
500
|
|
501 if(gnssState != UART_GNSS_INIT)
|
|
502 {
|
|
503 UART6_ReadData();
|
|
504 UART6_WriteData();
|
|
505 }
|
|
506 if(gnssState == UART_GNSS_INIT)
|
|
507 {
|
|
508 lastRequestTick = tick;
|
|
509 TriggerTick = tick - 10; /* just to make sure control is triggered */
|
|
510 timeToTrigger = 1;
|
|
511 retryRequest = 0;
|
|
512 }
|
|
513 else if(((retryRequest == 0) /* timeout or error */
|
|
514 && (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (gnssState != UART_GNSS_IDLE)) /* retry if no answer after half request interval */
|
|
515 || (gnssState == UART_GNSS_ERROR))))
|
|
516 {
|
|
517 /* The channel switch will cause the sensor to respond with an error message. */
|
|
518 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */
|
|
519
|
|
520 TriggerTick = tick;
|
|
521 timeToTrigger = COMMAND_TX_DELAY;
|
|
522 retryRequest = 1;
|
|
523 }
|
|
524
|
|
525 else if(time_elapsed_ms(lastRequestTick,tick) > 1000) /* switch sensor and / or trigger next request */
|
|
526 {
|
|
527 lastRequestTick = tick;
|
|
528 TriggerTick = tick;
|
|
529 retryRequest = 0;
|
|
530 timeToTrigger = 1;
|
|
531
|
|
532 if((gnssState == UART_GNSS_GET_PVT)) /* timeout */
|
|
533 {
|
|
534 gnssState = UART_GNSS_IDLE;
|
|
535 }
|
|
536 timeToTrigger = 1;
|
|
537 }
|
|
538 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger))
|
|
539 {
|
|
540 timeToTrigger = 0;
|
|
541 UART6_Gnss_Control();
|
|
542 }
|
|
543
|
|
544 }
|
|
545
|
|
546
|
|
547 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/
|