Mercurial > public > ostc4
annotate Small_CPU/Src/uartProtocol_GNSS.c @ 932:effadaa3a1f7 Evo_2_23
Cleanup Gnss UART implementation:
The first draft of the internal UART implementation was just a copy of the external UART handling. To avoid duplicated code and maintainance issue both UARTs (external/internal 6/1) share the same functions. To enable this a control structure has to be used as function input which defines the none shared resources like DMA control and rx/tx buffers
author | Ideenmodellierer |
---|---|
date | Sat, 07 Dec 2024 21:28:08 +0100 |
parents | 7c996354b8ac |
children | 3029f0332f4f |
rev | line source |
---|---|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
1 /** |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
2 ****************************************************************************** |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
3 * @file uartProtocol_GNSS.c |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
4 * @author heinrichs weikamp gmbh |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
5 * @version V0.0.1 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
6 * @date 30-Sep-2024 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
7 * @brief Interface functionality operation of GNSS devices |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
8 * |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
9 @verbatim |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
10 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
11 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
12 @endverbatim |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
13 ****************************************************************************** |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
14 * @attention |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
15 * |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
16 * <h2><center>© COPYRIGHT(c) 2024 heinrichs weikamp</center></h2> |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
17 * |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
18 ****************************************************************************** |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
19 */ |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
20 /* Includes ------------------------------------------------------------------*/ |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
21 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
22 #include <string.h> |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
23 #include "scheduler.h" |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
24 #include <uartProtocol_GNSS.h> |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
25 #include "uart.h" |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
26 #include "GNSS.h" |
919 | 27 #include "configuration.h" |
28 #include "externalInterface.h" | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
29 |
932 | 30 |
31 #if defined ENABLE_GNSS || defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2 | |
32 | |
33 static uartGnssStatus_t gnssState = UART_GNSS_INIT; | |
34 static gnssRequest_s activeRequest = {0,0}; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
35 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
36 static receiveStateGnss_t rxState = GNSSRX_READY; |
919 | 37 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */ |
38 | |
39 static uint8_t writeIndex = 0; | |
40 | |
41 static uint8_t dataToRead = 0; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
42 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
43 void ConvertByteToHexString(uint8_t byte, char* str) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
44 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
45 uint8_t worker = 0; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
46 uint8_t digit = 0; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
47 uint8_t digitCnt = 1; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
48 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
49 worker = byte; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
50 while((worker!=0) && (digitCnt != 255)) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
51 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
52 digit = worker % 16; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
53 if( digit < 10) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
54 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
55 digit += '0'; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
56 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
57 else |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
58 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
59 digit += 'A' - 10; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
60 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
61 str[digitCnt--]= digit; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
62 worker = worker / 16; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
63 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
64 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
65 |
919 | 66 |
932 | 67 uartGnssStatus_t uartGnss_GetState() |
68 { | |
69 return gnssState; | |
70 } | |
71 void uartGnss_SetState(uartGnssStatus_t newState) | |
72 { | |
73 gnssState = newState; | |
74 } | |
75 | |
76 void UART_Gnss_SendCmd(uint8_t GnssCmd) | |
919 | 77 { |
922 | 78 const uint8_t* pData; |
919 | 79 uint8_t txLength = 0; |
80 | |
81 switch (GnssCmd) | |
82 { | |
83 case GNSSCMD_LOADCONF_0: pData = configUBX; | |
84 txLength = sizeof(configUBX) / sizeof(uint8_t); | |
85 break; | |
86 case GNSSCMD_LOADCONF_1: pData = setNMEA410; | |
87 txLength = sizeof(setNMEA410) / sizeof(uint8_t); | |
88 break; | |
89 case GNSSCMD_LOADCONF_2: pData = setGNSS; | |
90 txLength = sizeof(setGNSS) / sizeof(uint8_t); | |
91 break; | |
92 case GNSSCMD_GET_PVT_DATA: pData = getPVTData; | |
93 txLength = sizeof(getPVTData) / sizeof(uint8_t); | |
94 break; | |
95 case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData; | |
96 txLength = sizeof(getNavigatorData) / sizeof(uint8_t); | |
97 break; | |
932 | 98 case GNSSCMD_GET_NAVSAT_DATA: pData = getNavSat; |
99 txLength = sizeof(getNavSat) / sizeof(uint8_t); | |
100 break; | |
919 | 101 default: |
102 break; | |
103 } | |
104 if(txLength != 0) | |
105 { | |
932 | 106 activeRequest.class = pData[2]; |
107 activeRequest.id = pData[3]; | |
919 | 108 UART_SendCmdUbx(pData, txLength); |
109 } | |
110 } | |
111 | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
112 void uartGnss_Control(void) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
113 { |
919 | 114 static uint32_t warmupTick = 0; |
932 | 115 static uint8_t dataToggle = 0; |
116 uint8_t activeSensor = 0; | |
117 sUartComCtrl* pUartCtrl = UART_GetGnssCtrl(); | |
118 // uartGnssStatus_t localComState; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
119 |
932 | 120 if(pUartCtrl == &Uart1Ctrl) |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
121 { |
932 | 122 activeSensor = externalInterface_GetActiveUartSensor(); |
123 gnssState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); | |
124 } | |
125 | |
126 switch (gnssState) | |
127 { | |
128 case UART_GNSS_INIT: gnssState = UART_GNSS_WARMUP; | |
919 | 129 warmupTick = HAL_GetTick(); |
932 | 130 UART_clearRxBuffer(pUartCtrl); |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
131 break; |
919 | 132 case UART_GNSS_WARMUP: if(time_elapsed_ms(warmupTick,HAL_GetTick()) > 1000) |
133 { | |
932 | 134 gnssState = UART_GNSS_LOADCONF_0; |
919 | 135 } |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
136 break; |
932 | 137 case UART_GNSS_LOADCONF_0: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_0); |
138 rxState = GNSSRX_DETECT_ACK_0; | |
139 break; | |
140 case UART_GNSS_LOADCONF_1: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_1); | |
141 rxState = GNSSRX_DETECT_ACK_0; | |
142 break; | |
143 case UART_GNSS_LOADCONF_2: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_2); | |
919 | 144 rxState = GNSSRX_DETECT_ACK_0; |
145 break; | |
932 | 146 case UART_GNSS_IDLE: if(dataToggle) |
147 { | |
148 UART_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA); | |
149 gnssState = UART_GNSS_GET_PVT; | |
150 rxState = GNSSRX_DETECT_HEADER_0; | |
151 dataToggle = 0; | |
152 } | |
153 else | |
154 { | |
155 UART_Gnss_SendCmd(GNSSCMD_GET_NAVSAT_DATA); | |
156 gnssState = UART_GNSS_GET_SAT; | |
157 rxState = GNSSRX_DETECT_HEADER_0; | |
158 dataToggle = 1; | |
159 } | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
160 break; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
161 default: |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
162 break; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
163 } |
932 | 164 if(pUartCtrl == &Uart1Ctrl) |
165 { | |
166 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,gnssState); | |
167 } | |
919 | 168 |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
169 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
170 |
919 | 171 void uartGnss_ProcessData(uint8_t data) |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
172 { |
932 | 173 static uint16_t rxLength = 0; |
174 static uint8_t ck_A = 0; | |
175 static uint8_t ck_B = 0; | |
176 static uint8_t ck_A_Ref = 0; | |
177 static uint8_t ck_B_Ref = 0; | |
178 | |
919 | 179 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; |
932 | 180 if((rxState >= GNSSRX_DETECT_HEADER_2) && (rxState < GNSSRX_READ_CK_A)) |
181 { | |
182 ck_A += data; | |
183 ck_B += ck_A; | |
184 } | |
185 | |
919 | 186 switch(rxState) |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
187 { |
919 | 188 case GNSSRX_DETECT_ACK_0: |
189 case GNSSRX_DETECT_HEADER_0: if(data == 0xB5) | |
190 { | |
191 writeIndex = 0; | |
932 | 192 memset(GNSS_Handle.uartWorkingBuffer,0xff, sizeof(GNSS_Handle.uartWorkingBuffer)); |
919 | 193 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; |
194 rxState++; | |
932 | 195 ck_A = 0; |
196 ck_B = 0; | |
919 | 197 } |
198 break; | |
199 case GNSSRX_DETECT_ACK_1: | |
200 case GNSSRX_DETECT_HEADER_1: if(data == 0x62) | |
201 { | |
202 rxState++; | |
203 } | |
204 else | |
205 { | |
206 rxState = GNSSRX_DETECT_HEADER_0; | |
207 } | |
208 break; | |
209 case GNSSRX_DETECT_ACK_2: if(data == 0x05) | |
210 { | |
211 rxState++; | |
212 } | |
213 else | |
214 { | |
215 rxState = GNSSRX_DETECT_HEADER_0; | |
216 } | |
217 break; | |
932 | 218 case GNSSRX_DETECT_ACK_3: if((data == 0x01)) |
919 | 219 { |
932 | 220 if((gnssState >= UART_GNSS_LOADCONF_0) && (gnssState <= UART_GNSS_LOADCONF_2)) |
221 { | |
222 if(gnssState == UART_GNSS_LOADCONF_2) | |
223 { | |
224 gnssState = UART_GNSS_IDLE; | |
225 } | |
226 else | |
227 { | |
228 gnssState++; | |
229 } | |
230 } | |
919 | 231 GnssConnected = 1; |
232 rxState = GNSSRX_READY; | |
233 } | |
234 else | |
235 { | |
236 rxState = GNSSRX_DETECT_HEADER_0; | |
237 } | |
238 break; | |
932 | 239 case GNSSRX_DETECT_HEADER_2: if(data == activeRequest.class) |
919 | 240 { |
241 rxState++; | |
242 } | |
243 else | |
244 { | |
245 rxState = GNSSRX_DETECT_HEADER_0; | |
246 } | |
247 break; | |
932 | 248 case GNSSRX_DETECT_HEADER_3: if(data == activeRequest.id) |
249 { | |
250 rxState = GNSSRX_DETECT_LENGTH_0; | |
251 } | |
252 else | |
919 | 253 { |
932 | 254 rxState = GNSSRX_DETECT_HEADER_0; |
919 | 255 } |
932 | 256 break; |
257 case GNSSRX_DETECT_LENGTH_0: rxLength = GNSS_Handle.uartWorkingBuffer[4]; | |
258 rxState = GNSSRX_DETECT_LENGTH_1; | |
259 break; | |
260 case GNSSRX_DETECT_LENGTH_1: rxLength += (GNSS_Handle.uartWorkingBuffer[5] << 8); | |
261 rxState = GNSSRX_READ_DATA; | |
262 dataToRead = rxLength; | |
263 break; | |
264 case GNSSRX_READ_DATA: if(dataToRead > 0) | |
919 | 265 { |
266 dataToRead--; | |
267 } | |
932 | 268 if(dataToRead == 0) |
919 | 269 { |
932 | 270 rxState = GNSSRX_READ_CK_A; |
919 | 271 } |
272 break; | |
932 | 273 case GNSSRX_READ_CK_A: ck_A_Ref = data; |
274 rxState++; | |
275 break; | |
276 case GNSSRX_READ_CK_B: ck_B_Ref = data; | |
277 if((ck_A_Ref == ck_A) && (ck_B_Ref == ck_B)) | |
278 { | |
279 switch(gnssState) | |
280 { | |
281 case UART_GNSS_GET_PVT:GNSS_ParsePVTData(&GNSS_Handle); | |
282 break; | |
283 case UART_GNSS_GET_SAT: GNSS_ParseNavSatData(&GNSS_Handle); | |
284 break; | |
285 default: | |
286 break; | |
287 } | |
288 } | |
289 rxState = GNSSRX_DETECT_HEADER_0; | |
290 gnssState = UART_GNSS_IDLE; | |
291 break; | |
292 | |
919 | 293 default: rxState = GNSSRX_READY; |
294 break; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
295 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
296 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
297 |
919 | 298 uint8_t uartGnss_isSensorConnected() |
299 { | |
300 return GnssConnected; | |
301 } | |
302 | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
303 #endif |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
304 |