Mercurial > public > ostc4
annotate Small_CPU/Src/uart.c @ 889:cf3967fe6924 Evo_2_23
GNSS work in progress
| author | heinrichsweikamp |
|---|---|
| date | Fri, 06 Sep 2024 16:46:22 +0200 |
| parents | ad96f99ebc78 |
| children | 651d21777b61 |
| 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" |
| 662 | 26 #include "externalInterface.h" |
| 27 #include "data_exchange.h" | |
|
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
28 #include <string.h> /* memset */ |
| 38 | 29 |
| 889 | 30 |
| 38 | 31 /* Private variables ---------------------------------------------------------*/ |
| 32 | |
| 794 | 33 |
|
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
34 |
| 781 | 35 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */ |
| 36 #define CHUNKS_PER_BUFFER (5u) | |
| 794 | 37 |
| 889 | 38 |
| 662 | 39 |
| 889 | 40 DMA_HandleTypeDef hdma_usart1_rx, hdma_usart6_rx, hdma_usart6_tx; |
| 38 | 41 |
| 662 | 42 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */ |
| 889 | 43 uint8_t rxBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */ |
| 44 uint8_t txBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */ | |
| 45 | |
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
46 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
|
47 static uint8_t rxReadIndex; /* Index at which new data is stared */ |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
48 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */ |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
49 static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */ |
| 794 | 50 |
|
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
51 |
| 889 | 52 |
| 53 | |
| 38 | 54 /* Exported functions --------------------------------------------------------*/ |
| 55 | |
| 794 | 56 |
| 662 | 57 void MX_USART1_UART_Init(void) |
| 38 | 58 { |
| 662 | 59 /* regular init */ |
| 60 | |
| 61 huart1.Instance = USART1; | |
|
803
96ffad0a4e57
Cleanup initialisation / deinitialization:
Ideenmodellierer
parents:
798
diff
changeset
|
62 huart1.Init.BaudRate = 19200; |
| 662 | 63 huart1.Init.WordLength = UART_WORDLENGTH_8B; |
| 64 huart1.Init.StopBits = UART_STOPBITS_1; | |
| 65 huart1.Init.Parity = UART_PARITY_NONE; | |
| 66 huart1.Init.Mode = UART_MODE_TX_RX; | |
| 67 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 68 huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |
| 69 | |
| 70 HAL_UART_Init(&huart1); | |
| 71 | |
|
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
72 MX_USART1_DMA_Init(); |
|
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
73 |
|
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
74 memset(rxBuffer,BUFFER_NODATA,sizeof(rxBuffer)); |
| 662 | 75 rxReadIndex = 0; |
| 76 lastCmdIndex = 0; | |
| 77 rxWriteIndex = 0; | |
| 78 dmaActive = 0; | |
| 79 } | |
| 38 | 80 |
| 889 | 81 |
| 82 | |
| 662 | 83 void MX_USART1_UART_DeInit(void) |
| 84 { | |
|
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
85 HAL_DMA_Abort(&hdma_usart1_rx); |
| 662 | 86 HAL_DMA_DeInit(&hdma_usart1_rx); |
| 87 HAL_UART_DeInit(&huart1); | |
|
803
96ffad0a4e57
Cleanup initialisation / deinitialization:
Ideenmodellierer
parents:
798
diff
changeset
|
88 dmaActive = 0; |
| 662 | 89 } |
| 90 | |
| 91 void MX_USART1_DMA_Init() | |
| 92 { | |
| 93 /* DMA controller clock enable */ | |
| 94 __DMA2_CLK_ENABLE(); | |
| 95 | |
| 96 /* Peripheral DMA init*/ | |
| 97 hdma_usart1_rx.Instance = DMA2_Stream5; | |
| 98 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4; | |
| 99 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH; | |
| 100 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
| 101 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; | |
| 102 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 103 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 104 hdma_usart1_rx.Init.Mode = DMA_NORMAL; | |
| 105 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; | |
| 106 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
| 107 HAL_DMA_Init(&hdma_usart1_rx); | |
| 108 | |
| 109 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx); | |
| 110 | |
| 111 /* DMA interrupt init */ | |
| 112 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0); | |
| 113 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn); | |
| 38 | 114 } |
| 115 | |
| 889 | 116 void GNSS_IO_init() { |
| 117 | |
| 118 GPIO_InitTypeDef GPIO_InitStruct = { 0 }; | |
| 119 /* Peripheral clock enable */ | |
| 120 __HAL_RCC_USART6_CLK_ENABLE(); | |
| 121 | |
| 122 __HAL_RCC_GPIOA_CLK_ENABLE(); | |
| 123 /**USART6 GPIO Configuration | |
| 124 PA11 ------> USART6_TX | |
| 125 PA12 ------> USART6_RX | |
| 126 */ | |
| 127 GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12; | |
| 128 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | |
| 129 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
| 130 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | |
| 131 GPIO_InitStruct.Alternate = GPIO_AF8_USART6; | |
| 132 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
| 133 | |
| 134 /* USART6 DMA Init */ | |
| 135 /* USART6_RX Init */ | |
| 136 hdma_usart6_rx.Instance = DMA2_Stream2; | |
| 137 hdma_usart6_rx.Init.Channel = DMA_CHANNEL_5; | |
| 138 hdma_usart6_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; | |
| 139 hdma_usart6_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
| 140 hdma_usart6_rx.Init.MemInc = DMA_MINC_ENABLE; | |
| 141 hdma_usart6_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; | |
| 142 hdma_usart6_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 143 hdma_usart6_rx.Init.Mode = DMA_NORMAL; | |
| 144 hdma_usart6_rx.Init.Priority = DMA_PRIORITY_LOW; | |
| 145 hdma_usart6_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
| 146 HAL_DMA_Init(&hdma_usart6_rx); | |
| 147 | |
| 148 __HAL_LINKDMA(&huart6, hdmarx, hdma_usart6_rx); | |
| 149 | |
| 150 /* USART6_TX Init */ | |
| 151 hdma_usart6_tx.Instance = DMA2_Stream6; | |
| 152 hdma_usart6_tx.Init.Channel = DMA_CHANNEL_5; | |
| 153 hdma_usart6_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; | |
| 154 hdma_usart6_tx.Init.PeriphInc = DMA_PINC_DISABLE; | |
| 155 hdma_usart6_tx.Init.MemInc = DMA_MINC_ENABLE; | |
| 156 hdma_usart6_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; | |
| 157 hdma_usart6_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
| 158 hdma_usart6_tx.Init.Mode = DMA_NORMAL; | |
| 159 hdma_usart6_tx.Init.Priority = DMA_PRIORITY_LOW; | |
| 160 hdma_usart6_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
| 161 HAL_DMA_Init(&hdma_usart6_tx); | |
| 162 | |
| 163 __HAL_LINKDMA(&huart6, hdmatx, hdma_usart6_tx); | |
| 164 | |
| 165 /* USART6 interrupt Init */ | |
| 166 HAL_NVIC_SetPriority(USART6_IRQn, 0, 0); | |
| 167 HAL_NVIC_EnableIRQ(USART6_IRQn); | |
| 168 /* USER CODE BEGIN USART6_MspInit 1 */ | |
| 169 | |
| 170 /* USER CODE END USART6_MspInit 1 */ | |
| 171 | |
| 172 MX_USART6_DMA_Init(); | |
| 173 | |
| 174 } | |
| 175 | |
| 176 void MX_USART6_DMA_Init() { | |
| 177 /* DMA controller clock enable */ | |
| 178 __HAL_RCC_DMA2_CLK_ENABLE(); | |
| 179 | |
| 180 /* DMA interrupt init */ | |
| 181 /* DMA2_Stream2_IRQn interrupt configuration */ | |
| 182 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0); | |
| 183 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn); | |
| 184 /* DMA2_Stream6_IRQn interrupt configuration */ | |
| 185 HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0); | |
| 186 HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn); | |
| 187 } | |
| 188 | |
| 189 /** | |
| 190 * @brief USART6 Initialization Function | |
| 191 * @param None | |
| 192 * @retval None | |
| 193 */ | |
| 194 void MX_USART6_UART_Init(void) | |
| 195 { | |
| 196 /* USER CODE BEGIN USART6_Init 0 */ | |
| 197 | |
| 198 /* USER CODE END USART6_Init 0 */ | |
| 199 | |
| 200 /* USER CODE BEGIN USART6_Init 1 */ | |
| 201 | |
| 202 /* USER CODE END USART6_Init 1 */ | |
| 203 huart6.Instance = USART6; | |
| 204 huart6.Init.BaudRate = 9600; | |
| 205 huart6.Init.WordLength = UART_WORDLENGTH_8B; | |
| 206 huart6.Init.StopBits = UART_STOPBITS_1; | |
| 207 huart6.Init.Parity = UART_PARITY_NONE; | |
| 208 huart6.Init.Mode = UART_MODE_TX_RX; | |
| 209 huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
| 210 huart6.Init.OverSampling = UART_OVERSAMPLING_16; | |
| 211 HAL_UART_Init(&huart6); | |
| 212 | |
| 213 /* USER CODE BEGIN USART6_Init 2 */ | |
| 214 | |
| 215 /* USER CODE END USART6_Init 2 */ | |
| 216 } | |
| 217 | |
| 794 | 218 void UART_MUX_SelectAddress(uint8_t muxAddress) |
|
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
219 { |
|
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
220 uint8_t indexstr[4]; |
|
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
221 |
| 794 | 222 if(muxAddress <= MAX_MUX_CHANNEL) |
|
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
223 { |
| 794 | 224 indexstr[0] = '~'; |
| 225 indexstr[1] = muxAddress; | |
| 226 indexstr[2] = 0x0D; | |
| 227 indexstr[3] = 0x0A; | |
| 228 | |
| 229 HAL_UART_Transmit(&huart1,indexstr,4,10); | |
|
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
230 } |
|
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
231 } |
|
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
232 |
| 794 | 233 |
| 234 void UART_SendCmdString(uint8_t *cmdString) | |
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
235 { |
| 794 | 236 uint8_t cmdLength = strlen((char*)cmdString); |
| 237 | |
| 238 if(cmdLength < 20) /* A longer string is an indication for a missing 0 termination */ | |
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
239 { |
| 794 | 240 if(dmaActive == 0) |
| 241 { | |
| 242 UART_StartDMA_Receiption(); | |
| 243 } | |
| 244 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10); | |
| 245 } | |
| 246 } | |
| 247 | |
|
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
248 |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
249 void StringToInt(char *pstr, uint32_t *puInt32) |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
250 { |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
251 uint8_t index = 0; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
252 uint32_t result = 0; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
253 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
254 { |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
255 result *=10; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
256 result += pstr[index] - '0'; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
257 index++; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
258 } |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
259 *puInt32 = result; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
260 } |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
261 |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
262 void StringToUInt64(char *pstr, uint64_t *puint64) |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
263 { |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
264 uint8_t index = 0; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
265 uint64_t result = 0; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
266 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
267 { |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
268 result *=10; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
269 result += pstr[index] - '0'; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
270 index++; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
271 } |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
272 *puint64 = result; |
|
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
273 } |
| 662 | 274 |
| 742 | 275 void UART_StartDMA_Receiption() |
| 276 { | |
|
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
277 if(dmaActive == 0) |
| 742 | 278 { |
|
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
279 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE)) |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
280 { |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
281 dmaActive = 1; |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
282 } |
| 742 | 283 } |
| 284 } | |
| 690 | 285 |
|
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
286 void UART_ChangeBaudrate(uint32_t newBaudrate) |
| 38 | 287 { |
| 809 | 288 uint8_t dmaWasActive = dmaActive; |
|
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
289 // HAL_DMA_Abort(&hdma_usart1_rx); |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
290 MX_USART1_UART_DeInit(); |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
291 //HAL_UART_Abort(&huart1); |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
292 //HAL_DMA_DeInit(&hdma_usart1_rx); |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
293 |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
294 |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
295 // huart1.Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq()/2, newBaudrate); |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
296 huart1.Init.BaudRate = newBaudrate; |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
297 HAL_UART_Init(&huart1); |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
298 MX_USART1_DMA_Init(); |
| 809 | 299 if(dmaWasActive) |
| 794 | 300 { |
| 809 | 301 memset(rxBuffer,BUFFER_NODATA,sizeof(rxBuffer)); |
|
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
302 rxReadIndex = 0; |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
303 rxWriteIndex = 0; |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
304 dmaActive = 0; |
| 742 | 305 UART_StartDMA_Receiption(); |
| 662 | 306 } |
| 38 | 307 } |
| 690 | 308 |
| 662 | 309 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
| 38 | 310 { |
| 662 | 311 if(huart == &huart1) |
| 312 { | |
| 313 dmaActive = 0; | |
| 314 rxWriteIndex+=CHUNK_SIZE; | |
| 315 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 316 { | |
| 317 rxWriteIndex = 0; | |
| 318 } | |
|
787
aeb72882f30a
Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents:
785
diff
changeset
|
319 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE) || (rxWriteIndex == rxReadIndex)) /* start next transfer if we did not catch up with read index */ |
| 662 | 320 { |
| 809 | 321 UART_StartDMA_Receiption(); |
| 662 | 322 } |
| 323 } | |
| 38 | 324 } |
| 325 | |
| 794 | 326 void UART_ReadData(uint8_t sensorType) |
| 327 { | |
| 328 uint8_t localRX = rxReadIndex; | |
| 38 | 329 |
| 794 | 330 while((rxBuffer[localRX]!=BUFFER_NODATA)) |
| 331 { | |
| 332 switch (sensorType) | |
| 333 { | |
| 334 case SENSOR_MUX: | |
| 335 case SENSOR_DIGO2: uartO2_ProcessData(rxBuffer[localRX]); | |
| 336 break; | |
|
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
337 #ifdef ENABLE_CO2_SUPPORT |
|
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
338 case SENSOR_CO2: uartCo2_ProcessData(rxBuffer[localRX]); |
| 794 | 339 break; |
|
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
340 #endif |
|
842
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
809
diff
changeset
|
341 #ifdef ENABLE_SENTINEL_MODE |
|
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
809
diff
changeset
|
342 case SENSOR_SENTINEL: uartSentinel_ProcessData(rxBuffer[localRX]); |
|
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
809
diff
changeset
|
343 break; |
|
c3dd461ca3f9
Migrated Sentinel protocol to new UART structure:
Ideenmodellierer
parents:
809
diff
changeset
|
344 #endif |
| 794 | 345 default: |
| 346 break; | |
| 347 } | |
| 348 | |
| 349 rxBuffer[localRX] = BUFFER_NODATA; | |
| 350 localRX++; | |
| 351 rxReadIndex++; | |
| 352 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 353 { | |
| 354 localRX = 0; | |
| 355 rxReadIndex = 0; | |
| 356 } | |
| 357 } | |
| 358 } | |
| 359 | |
| 360 void UART_FlushRxBuffer(void) | |
| 361 { | |
| 362 while(rxBuffer[rxReadIndex] != BUFFER_NODATA) | |
| 363 { | |
| 364 rxBuffer[rxReadIndex] = BUFFER_NODATA; | |
| 365 rxReadIndex++; | |
| 366 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
| 367 { | |
| 368 rxReadIndex = 0; | |
| 369 } | |
| 370 } | |
| 371 } | |
| 662 | 372 |
| 861 | 373 uint8_t UART_isComActive(uint8_t sensorId) |
| 374 { | |
| 375 uint8_t active = 1; | |
| 809 | 376 |
| 861 | 377 uint8_t ComState = externalInterface_GetSensorState(sensorId + EXT_INTERFACE_MUX_OFFSET); |
| 378 | |
| 379 if((ComState == UART_COMMON_INIT) || (ComState == UART_COMMON_IDLE) || (ComState == UART_COMMON_ERROR)) | |
| 380 { | |
| 381 active = 0; | |
| 382 } | |
| 383 return active; | |
| 384 } | |
| 809 | 385 |
| 38 | 386 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |
