annotate Small_CPU/Src/uart.c @ 943:e7f87ade3037 Evo_2_23 tip

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