Mercurial > public > ostc4
annotate Small_CPU/Src/uart.c @ 929:63c340abd70e Evo_2_23
Add a line to the compass heading dive menu that shows the currently set heading to enable the
diver to confirm it / add it to notes.
Also add a log entry every time a new compass heading is set or the heading is cleared.
And add a way to add compass headings to the log without changing the currently set heading -
this was added after discussion with cave divers who are interested in recording headings
when mapping out caves.
From mikeller
author | heinrichsweikamp |
---|---|
date | Mon, 02 Dec 2024 11:16:10 +0100 |
parents | 7c996354b8ac |
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; | |
33 extern void UART6_RxCpltCallback(UART_HandleTypeDef *huart); | |
34 extern void UART6_TxCpltCallback(UART_HandleTypeDef *huart); | |
35 #endif | |
889 | 36 |
38 | 37 /* Private variables ---------------------------------------------------------*/ |
38 | |
794 | 39 |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
40 #define TX_BUF_SIZE (40u) /* max length for commands */ |
781 | 41 #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
|
42 #define CHUNKS_PER_BUFFER (6u) |
794 | 43 |
889 | 44 |
662 | 45 |
922 | 46 DMA_HandleTypeDef hdma_usart1_rx, hdma_usart1_tx; |
38 | 47 |
890
651d21777b61
cleanup and disable function for GNSS uart and DMA
heinrichsweikamp
parents:
889
diff
changeset
|
48 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
|
49 uint8_t txBuffer[CHUNK_SIZE]; /* tx uses less bytes */ |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
50 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
|
51 uint8_t txBufferQueLen; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
52 |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 static uint8_t dmaTxActive; /* Indicator if DMA reception needs to be started */ |
794 | 58 |
921 | 59 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
|
60 |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
61 static uint8_t isEndIndication(uint8_t index); |
889 | 62 |
38 | 63 /* Exported functions --------------------------------------------------------*/ |
64 | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
65 void UART_clearRxBuffer(void) |
916
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 uint16_t index = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
68 do |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
69 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
70 rxBuffer[index++] = BUFFER_NODATA_LOW; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
71 rxBuffer[index++] = BUFFER_NODATA_HIGH; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
72 } while (index < sizeof(rxBuffer)); |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
73 |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
74 rxReadIndex = 0; |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
75 rxWriteIndex = 0; |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
76 } |
794 | 77 |
662 | 78 void MX_USART1_UART_Init(void) |
38 | 79 { |
662 | 80 /* regular init */ |
81 huart1.Instance = USART1; | |
803
96ffad0a4e57
Cleanup initialisation / deinitialization:
Ideenmodellierer
parents:
798
diff
changeset
|
82 huart1.Init.BaudRate = 19200; |
662 | 83 huart1.Init.WordLength = UART_WORDLENGTH_8B; |
84 huart1.Init.StopBits = UART_STOPBITS_1; | |
85 huart1.Init.Parity = UART_PARITY_NONE; | |
86 huart1.Init.Mode = UART_MODE_TX_RX; | |
87 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
88 huart1.Init.OverSampling = UART_OVERSAMPLING_16; | |
89 | |
90 HAL_UART_Init(&huart1); | |
91 | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
92 MX_USART1_DMA_Init(); |
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
93 |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
94 UART_clearRxBuffer(); |
662 | 95 rxReadIndex = 0; |
96 lastCmdIndex = 0; | |
97 rxWriteIndex = 0; | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
98 dmaRxActive = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
99 dmaTxActive = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
100 txBufferQueLen = 0; |
662 | 101 } |
38 | 102 |
889 | 103 |
104 | |
662 | 105 void MX_USART1_UART_DeInit(void) |
106 { | |
704
f1b40364b0af
Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents:
690
diff
changeset
|
107 HAL_DMA_Abort(&hdma_usart1_rx); |
662 | 108 HAL_DMA_DeInit(&hdma_usart1_rx); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
109 HAL_DMA_Abort(&hdma_usart1_tx); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
110 HAL_DMA_DeInit(&hdma_usart1_tx); |
662 | 111 HAL_UART_DeInit(&huart1); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
112 dmaRxActive = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
113 dmaTxActive = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
114 txBufferQueLen = 0; |
662 | 115 } |
116 | |
117 void MX_USART1_DMA_Init() | |
118 { | |
119 /* DMA controller clock enable */ | |
120 __DMA2_CLK_ENABLE(); | |
121 | |
122 /* Peripheral DMA init*/ | |
123 hdma_usart1_rx.Instance = DMA2_Stream5; | |
124 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4; | |
125 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH; | |
126 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE; | |
127 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE; | |
128 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; | |
129 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; | |
130 hdma_usart1_rx.Init.Mode = DMA_NORMAL; | |
131 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW; | |
132 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; | |
133 HAL_DMA_Init(&hdma_usart1_rx); | |
134 | |
135 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx); | |
136 | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
137 hdma_usart1_tx.Instance = DMA2_Stream7; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
138 hdma_usart1_tx.Init.Channel = DMA_CHANNEL_4; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
139 hdma_usart1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
140 hdma_usart1_tx.Init.PeriphInc = DMA_PINC_DISABLE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
141 hdma_usart1_tx.Init.MemInc = DMA_MINC_ENABLE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
142 hdma_usart1_tx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
143 hdma_usart1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
144 hdma_usart1_tx.Init.Mode = DMA_NORMAL; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
145 hdma_usart1_tx.Init.Priority = DMA_PRIORITY_LOW; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
146 hdma_usart1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
147 HAL_DMA_Init(&hdma_usart1_tx); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
148 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
149 __HAL_LINKDMA(&huart1,hdmatx,hdma_usart1_tx); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
150 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
151 |
662 | 152 /* DMA interrupt init */ |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
153 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 2, 2); |
662 | 154 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
155 HAL_NVIC_SetPriority(DMA2_Stream7_IRQn, 2, 1); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
156 HAL_NVIC_EnableIRQ(DMA2_Stream7_IRQn); |
38 | 157 } |
158 | |
794 | 159 void UART_MUX_SelectAddress(uint8_t muxAddress) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
160 { |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
161 uint8_t indexstr[4]; |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
162 |
794 | 163 if(muxAddress <= MAX_MUX_CHANNEL) |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
164 { |
794 | 165 indexstr[0] = '~'; |
166 indexstr[1] = muxAddress; | |
167 indexstr[2] = 0x0D; | |
168 indexstr[3] = 0x0A; | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
169 if(!dmaTxActive) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
170 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
171 memcpy(txBuffer, indexstr, 4); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
172 dmaTxActive = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
173 if(HAL_OK == HAL_UART_Transmit_DMA(&huart1,txBuffer,4)) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
174 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
175 dmaTxActive = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
176 while(dmaTxActive) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
177 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
178 HAL_Delay(1); |
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 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
181 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
182 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
183 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
184 memcpy(txBufferQue, indexstr, 4); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
185 txBufferQueLen = 4; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
186 } |
779
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
187 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
188 } |
0b5f45448eb6
Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents:
747
diff
changeset
|
189 |
794 | 190 |
191 void UART_SendCmdString(uint8_t *cmdString) | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
192 { |
794 | 193 uint8_t cmdLength = strlen((char*)cmdString); |
194 | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
195 if(dmaTxActive == 0) |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
196 { |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
197 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
|
198 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
199 if(dmaRxActive == 0) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
200 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
201 UART_StartDMA_Receiption(); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
202 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
203 memcpy(txBuffer, cmdString, cmdLength); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
204 if(HAL_OK == HAL_UART_Transmit_DMA(&huart1,txBuffer,cmdLength)) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
205 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
206 dmaTxActive = 1; |
921 | 207 LastCmdRequestTick = HAL_GetTick(); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
208 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
209 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
210 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
211 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
212 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
213 memcpy(txBufferQue, cmdString, cmdLength); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
214 txBufferQueLen = cmdLength; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
215 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
216 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
217 |
922 | 218 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
|
219 { |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
220 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
|
221 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
222 if(dmaRxActive == 0) |
794 | 223 { |
224 UART_StartDMA_Receiption(); | |
225 } | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
226 memcpy(txBuffer, cmd, len); |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
227 if(HAL_OK == HAL_UART_Transmit_DMA(&huart1,txBuffer,len)) |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
228 { |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
229 dmaTxActive = 1; |
921 | 230 LastCmdRequestTick = HAL_GetTick(); |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
231 } |
794 | 232 } |
233 } | |
234 | |
729
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
235 |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
236 void StringToInt(char *pstr, uint32_t *puInt32) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
237 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
238 uint8_t index = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
239 uint32_t result = 0; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
240 while((pstr[index] >= '0') && (pstr[index] <= '9')) |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
241 { |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
242 result *=10; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
243 result += pstr[index] - '0'; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
244 index++; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
245 } |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
246 *puInt32 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
247 } |
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 StringToUInt64(char *pstr, uint64_t *puint64) |
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 uint64_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 *puint64 = result; |
d646a0f724a7
Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents:
725
diff
changeset
|
260 } |
662 | 261 |
742 | 262 void UART_StartDMA_Receiption() |
263 { | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
264 if(dmaRxActive == 0) |
742 | 265 { |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
266 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
|
267 { |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
268 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
|
269 { |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
270 dmaRxActive = 1; |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
271 } |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
272 } |
742 | 273 } |
274 } | |
690 | 275 |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
276 void UART_ChangeBaudrate(uint32_t newBaudrate) |
38 | 277 { |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
278 MX_USART1_UART_DeInit(); |
798
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
279 huart1.Init.BaudRate = newBaudrate; |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
280 HAL_UART_Init(&huart1); |
e9eba334b942
Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents:
794
diff
changeset
|
281 MX_USART1_DMA_Init(); |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
282 HAL_NVIC_SetPriority(USART1_IRQn, 1, 3); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
283 HAL_NVIC_EnableIRQ(USART1_IRQn); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
284 |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
285 UART_clearRxBuffer(); |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
286 rxReadIndex = 0; |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
287 rxWriteIndex = 0; |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
288 dmaRxActive = 0; |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
289 txBufferQueLen = 0; |
38 | 290 } |
690 | 291 |
662 | 292 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
38 | 293 { |
662 | 294 if(huart == &huart1) |
295 { | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
296 dmaRxActive = 0; |
662 | 297 rxWriteIndex+=CHUNK_SIZE; |
298 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | |
299 { | |
300 rxWriteIndex = 0; | |
301 } | |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
302 UART_StartDMA_Receiption(); |
662 | 303 } |
922 | 304 #ifdef ENABLE_GPIO_V2 |
305 if(huart == &huart6) | |
306 { | |
307 UART6_RxCpltCallback(huart); | |
308 } | |
309 #endif | |
38 | 310 } |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
311 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
312 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
313 if(huart == &huart1) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
314 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
315 dmaTxActive = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
316 UART_WriteData(); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
317 if(txBufferQueLen) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
318 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
319 memcpy(txBuffer, txBufferQue, txBufferQueLen); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
320 HAL_UART_Transmit_DMA(&huart1,txBuffer,txBufferQueLen); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
321 dmaTxActive = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
322 txBufferQueLen = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
323 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
324 } |
922 | 325 #ifdef ENABLE_GPIO_V2 |
326 if(huart == &huart6) | |
327 { | |
328 UART6_TxCpltCallback(huart); | |
329 } | |
330 #endif | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
331 } |
38 | 332 |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
333 uint8_t isEndIndication(uint8_t index) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
334 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
335 uint8_t ret = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
336 if(index % 2) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
337 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
338 if(rxBuffer[index] == BUFFER_NODATA_HIGH) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
339 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
340 ret = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
341 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
342 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
343 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
344 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
345 if(rxBuffer[index] == BUFFER_NODATA_LOW) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
346 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
347 ret = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
348 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
349 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
350 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
351 return ret; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
352 } |
794 | 353 void UART_ReadData(uint8_t sensorType) |
354 { | |
355 uint8_t localRX = rxReadIndex; | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
356 uint8_t futureIndex = rxReadIndex + 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
357 uint8_t moreData = 0; |
38 | 358 |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
359 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
794 | 360 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
361 futureIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
362 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
363 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
364 if((!isEndIndication(localRX)) || (!isEndIndication(futureIndex))) do |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
365 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
366 while((!isEndIndication(localRX)) || (moreData)) |
794 | 367 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
368 moreData = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
369 switch (sensorType) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
370 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
371 case SENSOR_MUX: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
372 case SENSOR_DIGO2: uartO2_ProcessData(rxBuffer[localRX]); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
373 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
374 #ifdef ENABLE_CO2_SUPPORT |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
375 case SENSOR_CO2: uartCo2_ProcessData(rxBuffer[localRX]); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
376 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
377 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
378 #ifdef ENABLE_GNSS_SUPPORT |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
379 case SENSOR_GNSS: uartGnss_ProcessData(rxBuffer[localRX]); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
380 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
381 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
382 #ifdef ENABLE_SENTINEL_MODE |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
383 case SENSOR_SENTINEL: uartSentinel_ProcessData(rxBuffer[localRX]); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
384 break; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
385 #endif |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
386 default: |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
387 break; |
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 if(localRX % 2) |
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 rxBuffer[localRX] = BUFFER_NODATA_HIGH; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
392 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
393 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
394 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
395 rxBuffer[localRX] = BUFFER_NODATA_LOW; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
396 } |
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 localRX++; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
399 rxReadIndex++; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
400 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
401 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
402 localRX = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
403 rxReadIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
404 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
405 futureIndex++; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
406 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
407 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
408 futureIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
409 } |
794 | 410 } |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
411 if(!isEndIndication(futureIndex)) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
412 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
413 moreData = 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
414 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
415 } while(moreData); |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
416 } |
794 | 417 |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
418 void UART_WriteData(void) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
419 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
420 if(huart1.hdmatx->State == HAL_DMA_STATE_READY) |
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 huart1.gState = HAL_UART_STATE_READY; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
423 dmaTxActive = 0; |
794 | 424 } |
918
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
425 if(huart1.hdmarx->State == HAL_DMA_STATE_READY) |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
426 { |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
427 huart1.RxState = HAL_UART_STATE_READY; |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
428 dmaRxActive = 0; |
f72613a152dd
Switch external interface tx communication to DMA:
Ideenmodellierer
parents:
916
diff
changeset
|
429 } |
794 | 430 } |
431 | |
432 void UART_FlushRxBuffer(void) | |
433 { | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
434 uint8_t futureIndex = rxReadIndex + 1; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
435 |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
436 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
437 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
438 futureIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
439 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
440 while((rxBuffer[rxReadIndex] != BUFFER_NODATA_LOW) && (rxBuffer[futureIndex] != BUFFER_NODATA_HIGH)) |
794 | 441 { |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
442 if(rxReadIndex % 2) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
443 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
444 rxBuffer[rxReadIndex++] = BUFFER_NODATA_HIGH; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
445 } |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
446 else |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
447 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
448 rxBuffer[rxReadIndex++] = BUFFER_NODATA_LOW; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
449 } |
794 | 450 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
451 { | |
452 rxReadIndex = 0; | |
453 } | |
916
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
454 futureIndex++; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
455 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
456 { |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
457 futureIndex = 0; |
4832981f9af8
External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents:
894
diff
changeset
|
458 } |
794 | 459 } |
460 } | |
662 | 461 |
861 | 462 uint8_t UART_isComActive(uint8_t sensorId) |
463 { | |
464 uint8_t active = 1; | |
809 | 465 |
921 | 466 if(time_elapsed_ms(LastCmdRequestTick, HAL_GetTick()) > 300) /* UART activity should be inactive 300ms after last command */ |
861 | 467 { |
468 active = 0; | |
469 } | |
470 return active; | |
471 } | |
809 | 472 |
921 | 473 |
38 | 474 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |