annotate Small_CPU/Src/uart_Internal.c @ 922:7c996354b8ac Evo_2_23

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