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