Mercurial > public > ostc4
annotate Small_CPU/Src/uart.c @ 946:80ae8ea7f0a0 Evo_2_23
GNSS set to full power at startup:
In case of an reset the module would continue in sleep mode if it was in this state. To avoid this the module will now always set to full power at startup of the RTE.
author | Ideenmodellierer |
---|---|
date | Sun, 22 Dec 2024 20:52:08 +0100 |
parents | 3029f0332f4f |
children |
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" |
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
809
diff
changeset
|
25 #include "uartProtocol_Sentinel.h" |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
26 #include "uartProtocol_GNSS.h" |
662 | 27 #include "externalInterface.h" |
28 #include "data_exchange.h" | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
29 #include <string.h> /* memset */ |
38 | 30 |
922 | 31 #ifdef ENABLE_GPIO_V2 |
32 extern UART_HandleTypeDef huart6; | |
932 | 33 extern sUartComCtrl Uart6Ctrl; |
922 | 34 #endif |
889 | 35 |
38 | 36 /* Private variables ---------------------------------------------------------*/ |
37 | |
922 | 38 DMA_HandleTypeDef hdma_usart1_rx, hdma_usart1_tx; |
38 | 39 |
890
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
40 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow variations in buffer read time */ |
936 | 41 uint8_t txBuffer[TX_BUF_SIZE]; /* tx uses less bytes */ |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
42 uint8_t txBufferQue[TX_BUF_SIZE]; /* In MUX mode command may be send shortly after each other => allow q 1 entry que */ |
932 | 43 |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
44 |
890
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
45 static uint8_t lastCmdIndex; /* Index of last command which has not been completely received */ |
932 | 46 |
47 sUartComCtrl Uart1Ctrl; | |
48 static sUartComCtrl* pGnssCtrl = NULL; | |
794 | 49 |
921 | 50 static uint32_t LastCmdRequestTick = 0; /* Used by ADC handler to avoid interferance with UART communication */ |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
51 |
38 | 52 /* Exported functions --------------------------------------------------------*/ |
53 | |
932 | 54 |
55 void UART_SetGnssCtrl(sUartComCtrl* pTarget) | |
56 { | |
57 pGnssCtrl = pTarget; | |
58 } | |
59 | |
60 sUartComCtrl* UART_GetGnssCtrl() | |
61 { | |
62 return pGnssCtrl; | |
63 } | |
64 | |
65 | |
66 void UART_clearRxBuffer(sUartComCtrl* pUartCtrl) | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
67 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
68 uint16_t index = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
69 do |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
70 { |
932 | 71 pUartCtrl->pRxBuffer[index++] = BUFFER_NODATA_LOW; |
72 pUartCtrl->pRxBuffer[index++] = BUFFER_NODATA_HIGH; | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
73 } while (index < sizeof(rxBuffer)); |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
74 |
932 | 75 pUartCtrl->rxReadIndex = 0; |
76 pUartCtrl->rxWriteIndex = 0; | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
77 } |
794 | 78 |
662 | 79 void MX_USART1_UART_Init(void) |
38 | 80 { |
662 | 81 /* regular init */ |
82 huart1.Instance = USART1; | |
803
96ffad0a4e57
Cleanup initialisation / deinitialization:
Ideenmodellierer
parents:
798
diff
changeset
|
83 huart1.Init.BaudRate = 19200; |
662 | 84 huart1.Init.WordLength = UART_WORDLENGTH_8B; |
85 huart1.Init.StopBits = UART_STOPBITS_1; | |
86 huart1.Init.Parity = UART_PARITY_NONE; | |
87 huart1.Init.Mode = UART_MODE_TX_RX; | |
88 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
89 huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |
90 | |
91 HAL_UART_Init(&huart1); | |
92 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
93 MX_USART1_DMA_Init(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
94 |
932 | 95 UART_clearRxBuffer(&Uart1Ctrl); |
662 | 96 lastCmdIndex = 0; |
932 | 97 |
98 Uart1Ctrl.pHandle = &huart1; | |
99 Uart1Ctrl.rxWriteIndex = 0; | |
100 Uart1Ctrl.rxReadIndex = 0; | |
101 Uart1Ctrl.dmaRxActive = 0; | |
102 Uart1Ctrl.dmaTxActive = 0; | |
103 Uart1Ctrl.pRxBuffer = rxBuffer; | |
104 Uart1Ctrl.pTxBuffer = txBuffer; | |
105 Uart1Ctrl.txBufferQueLen = 0; | |
106 | |
107 #ifndef ENABLE_GPIO_V2 | |
108 UART_SetGnssCtrl(&Uart1Ctrl); | |
109 #endif | |
662 | 110 } |
38 | 111 |
889 | 112 |
113 | |
662 | 114 void MX_USART1_UART_DeInit(void) |
115 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
116 HAL_DMA_Abort(&hdma_usart1_rx); |
662 | 117 HAL_DMA_DeInit(&hdma_usart1_rx); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
118 HAL_DMA_Abort(&hdma_usart1_tx); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
119 HAL_DMA_DeInit(&hdma_usart1_tx); |
662 | 120 HAL_UART_DeInit(&huart1); |
932 | 121 Uart1Ctrl.dmaRxActive = 0; |
122 Uart1Ctrl.dmaTxActive = 0; | |
123 Uart1Ctrl.txBufferQueLen = 0; | |
662 | 124 } |
125 | |
126 void MX_USART1_DMA_Init() | |
127 { | |
128 /* DMA controller clock enable */ | |
129 __DMA2_CLK_ENABLE(); | |
130 | |
131 /* Peripheral DMA init*/ | |
132 hdma_usart1_rx.Instance = DMA2_Stream5; | |
133 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4; | |
134 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH; | |
135 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
136 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; | |
137 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
138 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
139 hdma_usart1_rx.Init.Mode = DMA_NORMAL; | |
140 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; | |
141 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
142 HAL_DMA_Init(&hdma_usart1_rx); | |
143 | |
144 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx); | |
145 | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
146 hdma_usart1_tx.Instance = DMA2_Stream7; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
147 hdma_usart1_tx.Init.Channel = DMA_CHANNEL_4; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
148 hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
149 hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
150 hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
151 hdma_usart1_tx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
152 hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
153 hdma_usart1_tx.Init.Mode = DMA_NORMAL; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
154 hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
155 hdma_usart1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
156 HAL_DMA_Init(&hdma_usart1_tx); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
157 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
158 __HAL_LINKDMA(&huart1,hdmatx,hdma_usart1_tx); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
159 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
160 |
662 | 161 /* DMA interrupt init */ |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
162 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 2, 2); |
662 | 163 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
164 HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 2, 1); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
165 HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn); |
38 | 166 } |
167 | |
932 | 168 void UART_MUX_SelectAddress(uint8_t muxAddress) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
169 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
170 uint8_t indexstr[4]; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
171 |
794 | 172 if(muxAddress <= MAX_MUX_CHANNEL) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
173 { |
794 | 174 indexstr[0] = '~'; |
175 indexstr[1] = muxAddress; | |
176 indexstr[2] = 0x0D; | |
177 indexstr[3] = 0x0A; | |
932 | 178 if(!Uart1Ctrl.dmaTxActive) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
179 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
180 memcpy(txBuffer, indexstr, 4); |
932 | 181 Uart1Ctrl.dmaTxActive = 0; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
182 if(HAL_OK == HAL_UART_Transmit_DMA(&huart1,txBuffer,4)) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
183 { |
932 | 184 Uart1Ctrl.dmaTxActive = 1; |
185 while(Uart1Ctrl.dmaTxActive) | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
186 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
187 HAL_Delay(1); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
188 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
189 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
190 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
191 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
192 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
193 memcpy(txBufferQue, indexstr, 4); |
932 | 194 Uart1Ctrl.txBufferQueLen = 4; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
195 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
196 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
197 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
198 |
794 | 199 |
200 void UART_SendCmdString(uint8_t *cmdString) | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
201 { |
794 | 202 uint8_t cmdLength = strlen((char*)cmdString); |
203 | |
932 | 204 if(Uart1Ctrl.dmaTxActive == 0) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
205 { |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
206 if(cmdLength < TX_BUF_SIZE) /* A longer string is an indication for a missing 0 termination */ |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
207 { |
932 | 208 if(Uart1Ctrl.dmaRxActive == 0) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
209 { |
932 | 210 UART_StartDMA_Receiption(&Uart1Ctrl); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
211 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
212 memcpy(txBuffer, cmdString, cmdLength); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
213 if(HAL_OK == HAL_UART_Transmit_DMA(&huart1,txBuffer,cmdLength)) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
214 { |
932 | 215 Uart1Ctrl.dmaTxActive = 1; |
921 | 216 LastCmdRequestTick = HAL_GetTick(); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
217 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
218 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
219 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
220 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
221 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
222 memcpy(txBufferQue, cmdString, cmdLength); |
932 | 223 Uart1Ctrl.txBufferQueLen = cmdLength; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
224 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
225 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
226 |
933 | 227 void UART_AddFletcher(uint8_t* pBuffer, uint8_t length) |
228 { | |
229 uint8_t ck_A = 0; | |
230 uint8_t ck_B = 0; | |
231 uint8_t index = 0; | |
232 | |
233 | |
234 pBuffer += 2; /* skip sync chars */ | |
235 for(index = 2; index < length; index++) | |
236 { | |
237 ck_A += *pBuffer++; | |
238 ck_B += ck_A; | |
239 } | |
240 *pBuffer++ = ck_A; | |
241 *pBuffer++ = ck_B; | |
242 } | |
243 | |
922 | 244 void UART_SendCmdUbx(const uint8_t *cmd, uint8_t len) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
245 { |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
246 if(len < TX_BUF_SIZE) /* A longer string is an indication for a missing 0 termination */ |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
247 { |
932 | 248 if(pGnssCtrl != NULL) |
794 | 249 { |
932 | 250 if(pGnssCtrl->dmaRxActive == 0) |
251 { | |
252 UART_StartDMA_Receiption(pGnssCtrl); | |
253 } | |
254 memcpy(pGnssCtrl->pTxBuffer, cmd, len); | |
933 | 255 UART_AddFletcher(pGnssCtrl->pTxBuffer, len); |
256 len += 2; | |
932 | 257 if(HAL_OK == HAL_UART_Transmit_DMA(pGnssCtrl->pHandle,pGnssCtrl->pTxBuffer,len)) |
258 { | |
259 pGnssCtrl->dmaTxActive = 1; | |
260 LastCmdRequestTick = HAL_GetTick(); | |
261 } | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
262 } |
794 | 263 } |
264 } | |
265 | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
266 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
267 void StringToInt(char *pstr, uint32_t *puInt32) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
268 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
269 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
270 uint32_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
271 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
272 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
273 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
274 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
275 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
276 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
277 *puInt32 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
278 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
279 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
280 void StringToUInt64(char *pstr, uint64_t *puint64) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
281 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
282 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
283 uint64_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
284 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
285 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
286 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
287 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
288 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
289 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
290 *puint64 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
291 } |
662 | 292 |
932 | 293 void UART_StartDMA_Receiption(sUartComCtrl* pUartCtrl) |
742 | 294 { |
932 | 295 if(pUartCtrl->dmaRxActive == 0) |
742 | 296 { |
932 | 297 if(((pUartCtrl->rxWriteIndex / CHUNK_SIZE) != (pUartCtrl->rxReadIndex / CHUNK_SIZE)) || ((UART_isEndIndication(pUartCtrl, pUartCtrl->rxWriteIndex)) && (UART_isEndIndication(pUartCtrl, pUartCtrl->rxWriteIndex + 1)))) /* start next transfer if we did not catch up with read index */ |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
298 { |
932 | 299 if(HAL_OK == HAL_UART_Receive_DMA (pUartCtrl->pHandle, &pUartCtrl->pRxBuffer[pUartCtrl->rxWriteIndex], CHUNK_SIZE)) |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
300 { |
932 | 301 pUartCtrl->dmaRxActive = 1; |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
302 } |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
303 } |
742 | 304 } |
305 } | |
690 | 306 |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
307 void UART_ChangeBaudrate(uint32_t newBaudrate) |
38 | 308 { |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
309 MX_USART1_UART_DeInit(); |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
310 huart1.Init.BaudRate = newBaudrate; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
311 HAL_UART_Init(&huart1); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
312 MX_USART1_DMA_Init(); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
313 HAL_NVIC_SetPriority(USART1_IRQn, 1, 3); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
314 HAL_NVIC_EnableIRQ(USART1_IRQn); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
315 |
932 | 316 UART_clearRxBuffer(&Uart1Ctrl); |
317 Uart1Ctrl.rxReadIndex = 0; | |
318 Uart1Ctrl.rxWriteIndex = 0; | |
319 Uart1Ctrl.dmaRxActive = 0; | |
320 Uart1Ctrl.txBufferQueLen = 0; | |
38 | 321 } |
690 | 322 |
932 | 323 void UART_HandleRxComplete(sUartComCtrl* pUartCtrl) |
324 { | |
325 pUartCtrl->dmaRxActive = 0; | |
326 pUartCtrl->rxWriteIndex+=CHUNK_SIZE; | |
327 if(pUartCtrl->rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
328 { | |
329 pUartCtrl->rxWriteIndex = 0; | |
330 } | |
331 UART_StartDMA_Receiption(pUartCtrl); | |
332 } | |
662 | 333 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
38 | 334 { |
932 | 335 if(huart == &huart1) |
336 { | |
337 UART_HandleRxComplete(&Uart1Ctrl); | |
338 } | |
922 | 339 #ifdef ENABLE_GPIO_V2 |
932 | 340 if(huart == &huart6) |
341 { | |
342 UART_HandleRxComplete(&Uart6Ctrl); | |
343 } | |
922 | 344 #endif |
38 | 345 } |
932 | 346 |
347 void UART_HandleTxComplete(sUartComCtrl* pUartCtrl) | |
348 { | |
349 pUartCtrl->dmaTxActive = 0; | |
350 UART_WriteData(pUartCtrl); | |
351 if(pUartCtrl->txBufferQueLen) | |
352 { | |
353 memcpy(pUartCtrl->pTxBuffer, pUartCtrl->pTxQue, pUartCtrl->txBufferQueLen); | |
354 HAL_UART_Transmit_DMA(pUartCtrl->pHandle,pUartCtrl->pTxBuffer,pUartCtrl->txBufferQueLen); | |
355 pUartCtrl->dmaTxActive = 1; | |
356 pUartCtrl->txBufferQueLen = 0; | |
357 } | |
358 } | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
359 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
360 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
361 if(huart == &huart1) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
362 { |
932 | 363 UART_HandleTxComplete(&Uart1Ctrl); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
364 } |
922 | 365 #ifdef ENABLE_GPIO_V2 |
366 if(huart == &huart6) | |
367 { | |
932 | 368 UART_HandleTxComplete(&Uart6Ctrl); |
922 | 369 } |
370 #endif | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
371 } |
38 | 372 |
932 | 373 uint8_t UART_isEndIndication(sUartComCtrl* pCtrl, uint8_t index) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
374 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
375 uint8_t ret = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
376 if(index % 2) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
377 { |
932 | 378 if(pCtrl->pRxBuffer[index] == BUFFER_NODATA_HIGH) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
379 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
380 ret = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
381 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
382 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
383 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
384 { |
932 | 385 if(pCtrl->pRxBuffer[index] == BUFFER_NODATA_LOW) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
386 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
387 ret = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
388 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
389 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
390 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
391 return ret; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
392 } |
794 | 393 void UART_ReadData(uint8_t sensorType) |
394 { | |
932 | 395 uint8_t localRX; |
396 uint8_t futureIndex; | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
397 uint8_t moreData = 0; |
38 | 398 |
932 | 399 sUartComCtrl* pUartCtrl; |
400 | |
401 if(sensorType == SENSOR_GNSS) | |
402 { | |
403 #ifdef ENABLE_GPIO_V2 | |
404 pUartCtrl = &Uart6Ctrl; | |
405 #else | |
406 pUartCtrl = &Uart1Ctrl; | |
407 #endif | |
408 } | |
409 else | |
410 { | |
411 pUartCtrl = &Uart1Ctrl; | |
412 } | |
413 localRX = pUartCtrl->rxReadIndex; | |
414 futureIndex = pUartCtrl->rxReadIndex + 1; | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
415 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
794 | 416 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
417 futureIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
418 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
419 |
932 | 420 if(!UART_isEndIndication(pUartCtrl, futureIndex)) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
421 { |
932 | 422 moreData = 1; |
423 } | |
424 | |
425 //if((!isEndIndication(pUartCtrl, localRX)) || (!isEndIndication(pUartCtrl,futureIndex))) do | |
426 if((!UART_isEndIndication(pUartCtrl, localRX)) || (moreData)) | |
427 do | |
428 { | |
429 while((!UART_isEndIndication(pUartCtrl, localRX)) || (moreData)) | |
794 | 430 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
431 moreData = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
432 switch (sensorType) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
433 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
434 case SENSOR_MUX: |
932 | 435 case SENSOR_DIGO2: uartO2_ProcessData(pUartCtrl->pRxBuffer[localRX]); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
436 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
437 #ifdef ENABLE_CO2_SUPPORT |
932 | 438 case SENSOR_CO2: uartCo2_ProcessData(pUartCtrl->pRxBuffer[localRX]); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
439 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
440 #endif |
932 | 441 #if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2 |
442 case SENSOR_GNSS: uartGnss_ProcessData(pUartCtrl->pRxBuffer[localRX]); | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
443 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
444 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
445 #ifdef ENABLE_SENTINEL_MODE |
932 | 446 case SENSOR_SENTINEL: uartSentinel_ProcessData(pUartCtrl->pRxBuffer[localRX]); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
447 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
448 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
449 default: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
450 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
451 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
452 if(localRX % 2) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
453 { |
932 | 454 pUartCtrl->pRxBuffer[localRX] = BUFFER_NODATA_HIGH; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
455 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
456 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
457 { |
932 | 458 pUartCtrl->pRxBuffer[localRX] = BUFFER_NODATA_LOW; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
459 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
460 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
461 localRX++; |
932 | 462 pUartCtrl->rxReadIndex++; |
463 if(pUartCtrl->rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
464 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
465 localRX = 0; |
932 | 466 pUartCtrl->rxReadIndex = 0; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
467 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
468 futureIndex++; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
469 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
470 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
471 futureIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
472 } |
794 | 473 } |
932 | 474 if(!UART_isEndIndication(pUartCtrl, futureIndex)) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
475 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
476 moreData = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
477 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
478 } while(moreData); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
479 } |
794 | 480 |
932 | 481 void UART_WriteData(sUartComCtrl* pUartCtrl) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
482 { |
932 | 483 if(pUartCtrl->pHandle->hdmatx->State == HAL_DMA_STATE_READY) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
484 { |
932 | 485 pUartCtrl->pHandle->gState = HAL_UART_STATE_READY; |
486 pUartCtrl->dmaTxActive = 0; | |
794 | 487 } |
932 | 488 if(pUartCtrl->pHandle->hdmarx->State == HAL_DMA_STATE_READY) |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
489 { |
932 | 490 pUartCtrl->pHandle->RxState = HAL_UART_STATE_READY; |
491 pUartCtrl->dmaRxActive = 0; | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
492 } |
794 | 493 } |
494 | |
495 void UART_FlushRxBuffer(void) | |
496 { | |
932 | 497 uint8_t futureIndex = Uart1Ctrl.rxReadIndex + 1; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
498 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
499 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
500 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
501 futureIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
502 } |
932 | 503 while((rxBuffer[Uart1Ctrl.rxReadIndex] != BUFFER_NODATA_LOW) && (rxBuffer[futureIndex] != BUFFER_NODATA_HIGH)) |
794 | 504 { |
932 | 505 if(Uart1Ctrl.rxReadIndex % 2) |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
506 { |
932 | 507 rxBuffer[Uart1Ctrl.rxReadIndex++] = BUFFER_NODATA_HIGH; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
508 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
509 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
510 { |
932 | 511 rxBuffer[Uart1Ctrl.rxReadIndex++] = BUFFER_NODATA_LOW; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
512 } |
932 | 513 if(Uart1Ctrl.rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
794 | 514 { |
932 | 515 Uart1Ctrl.rxReadIndex = 0; |
794 | 516 } |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
517 futureIndex++; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
518 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
519 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
520 futureIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
521 } |
794 | 522 } |
523 } | |
662 | 524 |
861 | 525 uint8_t UART_isComActive(uint8_t sensorId) |
526 { | |
527 uint8_t active = 1; | |
809 | 528 |
921 | 529 if(time_elapsed_ms(LastCmdRequestTick, HAL_GetTick()) > 300) /* UART activity should be inactive 300ms after last command */ |
861 | 530 { |
531 active = 0; | |
532 } | |
533 return active; | |
534 } | |
809 | 535 |
921 | 536 |
38 | 537 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |