Mercurial > public > ostc4
annotate Small_CPU/Src/uart.c @ 804:391b3d420a39
Cleanup initialisation code:
Some variables were not initialised during awake transition and the mapping of to the legacy adc slots were done at several location. This has been cleaned up not.
Do not run UART during ADC sensor detection:
A operation UART sensor caused the false detection of a not connected ADC sensor. To avoid this the UART is now deactivated during ADC detection phase.
author | Ideenmodellierer |
---|---|
date | Thu, 10 Aug 2023 21:35:34 +0200 |
parents | 96ffad0a4e57 |
children | 9602a7338f28 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file uart.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @version V0.0.1 | |
6 * @date 27-March-2014 | |
7 * @brief button control | |
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" | |
794 | 23 #include "uartProtocol_O2.h" |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
24 #include "uartProtocol_Co2.h" |
662 | 25 #include "externalInterface.h" |
26 #include "data_exchange.h" | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
27 #include <string.h> /* memset */ |
38 | 28 |
29 /* Private variables ---------------------------------------------------------*/ | |
30 | |
794 | 31 |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
32 |
781 | 33 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */ |
34 #define CHUNKS_PER_BUFFER (5u) | |
794 | 35 |
662 | 36 UART_HandleTypeDef huart1; |
37 | |
38 DMA_HandleTypeDef hdma_usart1_rx; | |
38 | 39 |
662 | 40 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */ |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
41 static uint8_t rxWriteIndex; /* Index of the data item which is analysed */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
42 static uint8_t rxReadIndex; /* Index at which new data is stared */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
43 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */ |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
44 static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */ |
794 | 45 |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
46 |
742 | 47 static uint8_t SentinelConnected = 0; /* Binary indicator if a sensor is connected or not */ |
38 | 48 |
794 | 49 |
38 | 50 /* Exported functions --------------------------------------------------------*/ |
51 | |
794 | 52 |
662 | 53 void MX_USART1_UART_Init(void) |
38 | 54 { |
662 | 55 /* regular init */ |
56 | |
57 huart1.Instance = USART1; | |
803
96ffad0a4e57
Cleanup initialisation / deinitialization:
Ideenmodellierer
parents:
798
diff
changeset
|
58 huart1.Init.BaudRate = 19200; |
662 | 59 huart1.Init.WordLength = UART_WORDLENGTH_8B; |
60 huart1.Init.StopBits = UART_STOPBITS_1; | |
61 huart1.Init.Parity = UART_PARITY_NONE; | |
62 huart1.Init.Mode = UART_MODE_TX_RX; | |
63 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
64 huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |
65 | |
66 HAL_UART_Init(&huart1); | |
67 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
68 MX_USART1_DMA_Init(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
69 |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
70 memset(rxBuffer,BUFFER_NODATA,sizeof(rxBuffer)); |
662 | 71 rxReadIndex = 0; |
72 lastCmdIndex = 0; | |
73 rxWriteIndex = 0; | |
74 dmaActive = 0; | |
794 | 75 |
742 | 76 SentinelConnected = 0; |
794 | 77 |
662 | 78 } |
38 | 79 |
662 | 80 void MX_USART1_UART_DeInit(void) |
81 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
82 HAL_DMA_Abort(&hdma_usart1_rx); |
662 | 83 HAL_DMA_DeInit(&hdma_usart1_rx); |
84 HAL_UART_DeInit(&huart1); | |
803
96ffad0a4e57
Cleanup initialisation / deinitialization:
Ideenmodellierer
parents:
798
diff
changeset
|
85 dmaActive = 0; |
662 | 86 } |
87 | |
88 void MX_USART1_DMA_Init() | |
89 { | |
90 /* DMA controller clock enable */ | |
91 __DMA2_CLK_ENABLE(); | |
92 | |
93 /* Peripheral DMA init*/ | |
94 hdma_usart1_rx.Instance = DMA2_Stream5; | |
95 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4; | |
96 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH; | |
97 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
98 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; | |
99 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
100 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
101 hdma_usart1_rx.Init.Mode = DMA_NORMAL; | |
102 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; | |
103 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
104 HAL_DMA_Init(&hdma_usart1_rx); | |
105 | |
106 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx); | |
107 | |
108 /* DMA interrupt init */ | |
109 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0); | |
110 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn); | |
38 | 111 } |
112 | |
794 | 113 void UART_MUX_SelectAddress(uint8_t muxAddress) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
114 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
115 uint8_t indexstr[4]; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
116 |
794 | 117 if(muxAddress <= MAX_MUX_CHANNEL) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
118 { |
794 | 119 indexstr[0] = '~'; |
120 indexstr[1] = muxAddress; | |
121 indexstr[2] = 0x0D; | |
122 indexstr[3] = 0x0A; | |
123 | |
124 HAL_UART_Transmit(&huart1,indexstr,4,10); | |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
125 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
126 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
127 |
794 | 128 |
129 void UART_SendCmdString(uint8_t *cmdString) | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
130 { |
794 | 131 uint8_t cmdLength = strlen((char*)cmdString); |
132 | |
133 if(cmdLength < 20) /* A longer string is an indication for a missing 0 termination */ | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
134 { |
794 | 135 if(dmaActive == 0) |
136 { | |
137 UART_StartDMA_Receiption(); | |
138 } | |
139 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); | |
140 } | |
141 } | |
142 | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
143 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
144 void StringToInt(char *pstr, uint32_t *puInt32) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
145 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
146 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
147 uint32_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
148 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
149 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
150 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
151 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
152 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
153 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
154 *puInt32 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
155 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
156 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
157 void StringToUInt64(char *pstr, uint64_t *puint64) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
158 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
159 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
160 uint64_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
161 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
162 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
163 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
164 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
165 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
166 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
167 *puint64 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
168 } |
690 | 169 void ConvertByteToHexString(uint8_t byte, char* str) |
170 { | |
171 uint8_t worker = 0; | |
172 uint8_t digit = 0; | |
173 uint8_t digitCnt = 1; | |
38 | 174 |
690 | 175 worker = byte; |
176 while((worker!=0) && (digitCnt != 255)) | |
177 { | |
178 digit = worker % 16; | |
179 if( digit < 10) | |
180 { | |
181 digit += '0'; | |
182 } | |
183 else | |
184 { | |
185 digit += 'A' - 10; | |
186 } | |
187 str[digitCnt--]= digit; | |
188 worker = worker / 16; | |
189 } | |
190 } | |
662 | 191 |
742 | 192 void UART_StartDMA_Receiption() |
193 { | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
194 if(dmaActive == 0) |
742 | 195 { |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
196 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
197 { |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
198 dmaActive = 1; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
199 } |
742 | 200 } |
201 } | |
690 | 202 |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
203 void UART_ChangeBaudrate(uint32_t newBaudrate) |
38 | 204 { |
725 | 205 |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
206 // HAL_DMA_Abort(&hdma_usart1_rx); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
207 MX_USART1_UART_DeInit(); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
208 //HAL_UART_Abort(&huart1); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
209 //HAL_DMA_DeInit(&hdma_usart1_rx); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
210 |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
211 |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
212 // huart1.Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq()/2, newBaudrate); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
213 huart1.Init.BaudRate = newBaudrate; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
214 HAL_UART_Init(&huart1); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
215 MX_USART1_DMA_Init(); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
216 if(dmaActive) |
794 | 217 { |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
218 rxReadIndex = 0; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
219 rxWriteIndex = 0; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
220 dmaActive = 0; |
742 | 221 UART_StartDMA_Receiption(); |
662 | 222 } |
38 | 223 } |
690 | 224 |
225 #ifdef ENABLE_SENTINEL_MODE | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
226 void UART_HandleSentinelData(void) |
690 | 227 { |
228 uint8_t localRX = rxReadIndex; | |
229 static uint8_t dataType = 0; | |
230 static uint32_t dataValue[3]; | |
231 static uint8_t dataValueIdx = 0; | |
232 static receiveState_t rxState = RX_Ready; | |
233 static uint32_t lastReceiveTick = 0; | |
234 static uint8_t lastAlive = 0; | |
235 static uint8_t curAlive = 0; | |
236 static uint8_t checksum = 0; | |
742 | 237 static char checksum_str[]="00"; |
690 | 238 |
742 | 239 while((rxBuffer[localRX]!=0)) |
690 | 240 { |
241 lastReceiveTick = HAL_GetTick(); | |
242 | |
243 switch(rxState) | |
244 { | |
245 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z')) | |
246 { | |
247 rxState = RX_DetectStart; | |
248 curAlive = rxBuffer[localRX]; | |
249 checksum = 0; | |
250 } | |
251 break; | |
252 | |
253 case RX_DetectStart: checksum += rxBuffer[localRX]; | |
254 if(rxBuffer[localRX] == '1') | |
255 { | |
256 rxState = RX_SelectData; | |
257 dataType = 0xFF; | |
258 | |
259 } | |
260 else | |
261 { | |
262 rxState = RX_Ready; | |
263 } | |
264 break; | |
265 | |
266 case RX_SelectData: checksum += rxBuffer[localRX]; | |
267 switch(rxBuffer[localRX]) | |
268 { | |
269 case 'T': dataType = rxBuffer[localRX]; | |
270 break; | |
271 case '0': if(dataType != 0xff) | |
272 { | |
273 rxState = RX_Data0; | |
274 dataValueIdx = 0; | |
275 dataValue[0] = 0; | |
276 | |
277 } | |
278 else | |
279 { | |
280 rxState = RX_Ready; | |
281 } | |
282 break; | |
283 default: rxState = RX_Ready; | |
284 } | |
285 break; | |
286 | |
287 case RX_Data0: | |
288 case RX_Data1: | |
289 case RX_Data2: | |
290 case RX_Data4: | |
291 case RX_Data5: | |
292 case RX_Data6: | |
293 case RX_Data8: | |
294 case RX_Data9: | |
295 case RX_Data10: checksum += rxBuffer[localRX]; | |
296 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9')) | |
297 { | |
298 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0'); | |
299 rxState++; | |
300 } | |
301 else | |
302 { | |
303 rxState = RX_Ready; | |
304 } | |
305 break; | |
306 | |
307 case RX_Data3: | |
308 case RX_Data7: checksum += rxBuffer[localRX]; | |
309 if(rxBuffer[localRX] == '0') | |
310 { | |
311 rxState++; | |
312 dataValueIdx++; | |
313 dataValue[dataValueIdx] = 0; | |
314 } | |
315 else | |
316 { | |
317 rxState = RX_Ready; | |
318 } | |
319 break; | |
320 case RX_Data11: rxState = RX_DataComplete; | |
321 ConvertByteToHexString(checksum,checksum_str); | |
322 if(rxBuffer[localRX] == checksum_str[0]) | |
323 { | |
324 rxState = RX_DataComplete; | |
325 } | |
326 else | |
327 { | |
328 rxState = RX_Ready; | |
329 } | |
330 | |
331 break; | |
332 | |
333 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1]) | |
334 { | |
335 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0)); | |
336 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0)); | |
337 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0)); | |
742 | 338 SentinelConnected = 1; |
690 | 339 } |
340 rxState = RX_Ready; | |
341 break; | |
342 | |
343 | |
344 default: rxState = RX_Ready; | |
345 break; | |
346 | |
347 } | |
348 localRX++; | |
349 rxReadIndex++; | |
350 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
351 { | |
352 localRX = 0; | |
353 rxReadIndex = 0; | |
354 } | |
355 } | |
356 | |
357 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */ | |
358 { | |
359 if(curAlive == lastAlive) | |
360 { | |
361 setExternalInterfaceChannel(0,0.0); | |
362 setExternalInterfaceChannel(1,0.0); | |
363 setExternalInterfaceChannel(2,0.0); | |
742 | 364 SentinelConnected = 0; |
690 | 365 } |
366 lastAlive = curAlive; | |
367 } | |
368 | |
369 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */ | |
370 { | |
742 | 371 UART_StartDMA_Receiption(); |
690 | 372 } |
373 } | |
374 #endif | |
38 | 375 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
376 |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
377 |
742 | 378 uint8_t UART_isSentinelConnected() |
379 { | |
380 return SentinelConnected; | |
381 } | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
382 |
662 | 383 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
38 | 384 { |
662 | 385 if(huart == &huart1) |
386 { | |
387 dmaActive = 0; | |
388 rxWriteIndex+=CHUNK_SIZE; | |
389 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
390 { | |
391 rxWriteIndex = 0; | |
392 } | |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
393 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE) || (rxWriteIndex == rxReadIndex)) /* start next transfer if we did not catch up with read index */ |
662 | 394 { |
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
395 if(externalInterface_GetUARTProtocol() != 0) |
662 | 396 { |
742 | 397 UART_StartDMA_Receiption(); |
662 | 398 } |
399 } | |
400 } | |
38 | 401 } |
402 | |
794 | 403 void UART_ReadData(uint8_t sensorType) |
404 { | |
405 uint8_t localRX = rxReadIndex; | |
38 | 406 |
794 | 407 while((rxBuffer[localRX]!=BUFFER_NODATA)) |
408 { | |
409 switch (sensorType) | |
410 { | |
411 case SENSOR_MUX: | |
412 case SENSOR_DIGO2: uartO2_ProcessData(rxBuffer[localRX]); | |
413 break; | |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
414 #ifdef ENABLE_CO2_SUPPORT |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
415 case SENSOR_CO2: uartCo2_ProcessData(rxBuffer[localRX]); |
794 | 416 break; |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
417 #endif |
794 | 418 default: |
419 break; | |
420 } | |
421 | |
422 rxBuffer[localRX] = BUFFER_NODATA; | |
423 localRX++; | |
424 rxReadIndex++; | |
425 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
426 { | |
427 localRX = 0; | |
428 rxReadIndex = 0; | |
429 } | |
430 } | |
431 } | |
432 | |
433 void UART_FlushRxBuffer(void) | |
434 { | |
435 while(rxBuffer[rxReadIndex] != BUFFER_NODATA) | |
436 { | |
437 rxBuffer[rxReadIndex] = BUFFER_NODATA; | |
438 rxReadIndex++; | |
439 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
440 { | |
441 rxReadIndex = 0; | |
442 } | |
443 } | |
444 | |
445 } | |
662 | 446 |
38 | 447 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |