annotate Small_CPU/Src/uart.c @ 928:9b7859554beb Evo_2_23 tip

Cleanup Internal Uart: The compile switches have been updated to allow GNSS data flow if new GPIO config is available or if GNSS is enabled for the external UART.
author Ideenmodellierer
date Tue, 26 Nov 2024 21:30:06 +0100
parents 7c996354b8ac
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;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
33 extern void UART6_RxCpltCallback(UART_HandleTypeDef *huart);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
34 extern void UART6_TxCpltCallback(UART_HandleTypeDef *huart);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
35 #endif
889
cf3967fe6924 GNSS work in progress
heinrichsweikamp
parents: 861
diff changeset
36
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
43
889
cf3967fe6924 GNSS work in progress
heinrichsweikamp
parents: 861
diff changeset
44
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
45
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
46 DMA_HandleTypeDef hdma_usart1_rx, hdma_usart1_tx;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
58
921
eb4109d7d1e9 Improved mix mode ADC conversion:
Ideenmodellierer
parents: 918
diff changeset
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
cf3967fe6924 GNSS work in progress
heinrichsweikamp
parents: 861
diff changeset
62
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
77
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
78 void MX_USART1_UART_Init(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
80 /* regular init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
81 huart1.Instance = USART1;
803
96ffad0a4e57 Cleanup initialisation / deinitialization:
Ideenmodellierer
parents: 798
diff changeset
82 huart1.Init.BaudRate = 19200;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
83 huart1.Init.WordLength = UART_WORDLENGTH_8B;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
84 huart1.Init.StopBits = UART_STOPBITS_1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
85 huart1.Init.Parity = UART_PARITY_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
86 huart1.Init.Mode = UART_MODE_TX_RX;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
87 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
88 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
89
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
90 HAL_UART_Init(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
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
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
95 rxReadIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
96 lastCmdIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
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
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
101 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102
889
cf3967fe6924 GNSS work in progress
heinrichsweikamp
parents: 861
diff changeset
103
cf3967fe6924 GNSS work in progress
heinrichsweikamp
parents: 861
diff changeset
104
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
105 void MX_USART1_UART_DeInit(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
106 {
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
107 HAL_DMA_Abort(&hdma_usart1_rx);
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
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
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
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
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
115 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
116
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
117 void MX_USART1_DMA_Init()
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
118 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
119 /* DMA controller clock enable */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
120 __DMA2_CLK_ENABLE();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
121
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
122 /* Peripheral DMA init*/
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
123 hdma_usart1_rx.Instance = DMA2_Stream5;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
124 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
125 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
126 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
127 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
128 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
129 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
130 hdma_usart1_rx.Init.Mode = DMA_NORMAL;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
131 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
132 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
133 HAL_DMA_Init(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
134
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
135 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
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
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
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
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
163 if(muxAddress <= MAX_MUX_CHANNEL)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
164 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
165 indexstr[0] = '~';
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
166 indexstr[1] = muxAddress;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
167 indexstr[2] = 0x0D;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
190
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
193 uint8_t cmdLength = strlen((char*)cmdString);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
eb4109d7d1e9 Improved mix mode ADC conversion:
Ideenmodellierer
parents: 918
diff changeset
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
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
223 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
224 UART_StartDMA_Receiption();
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
eb4109d7d1e9 Improved mix mode ADC conversion:
Ideenmodellierer
parents: 918
diff changeset
230 LastCmdRequestTick = HAL_GetTick();
918
f72613a152dd Switch external interface tx communication to DMA:
Ideenmodellierer
parents: 916
diff changeset
231 }
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
232 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
233 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
261
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
262 void UART_StartDMA_Receiption()
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
263 {
916
4832981f9af8 External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents: 894
diff changeset
264 if(dmaRxActive == 0)
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
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
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
273 }
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
274 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
275
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
276 void UART_ChangeBaudrate(uint32_t newBaudrate)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
291
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
292 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
294 if(huart == &huart1)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
295 {
916
4832981f9af8 External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents: 894
diff changeset
296 dmaRxActive = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
297 rxWriteIndex+=CHUNK_SIZE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
298 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
299 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
300 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
301 }
918
f72613a152dd Switch external interface tx communication to DMA:
Ideenmodellierer
parents: 916
diff changeset
302 UART_StartDMA_Receiption();
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
303 }
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
304 #ifdef ENABLE_GPIO_V2
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
305 if(huart == &huart6)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
306 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
307 UART6_RxCpltCallback(huart);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
308 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
309 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
325 #ifdef ENABLE_GPIO_V2
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
326 if(huart == &huart6)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
327 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
328 UART6_TxCpltCallback(huart);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
329 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents: 921
diff changeset
330 #endif
916
4832981f9af8 External sensor UART: Switch to DMA TX transfers:
Ideenmodellierer
parents: 894
diff changeset
331 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
353 void UART_ReadData(uint8_t sensorType)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
354 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
430 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
431
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
432 void UART_FlushRxBuffer(void)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
450 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
451 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
452 rxReadIndex = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
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
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
459 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
460 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
461
861
ad96f99ebc78 Synchronize ADC and UART activities:
Ideenmodellierer
parents: 842
diff changeset
462 uint8_t UART_isComActive(uint8_t sensorId)
ad96f99ebc78 Synchronize ADC and UART activities:
Ideenmodellierer
parents: 842
diff changeset
463 {
ad96f99ebc78 Synchronize ADC and UART activities:
Ideenmodellierer
parents: 842
diff changeset
464 uint8_t active = 1;
809
9602a7338f28 DevBugfix CO2 sensor in streaming mode:
Ideenmodellierer
parents: 803
diff changeset
465
921
eb4109d7d1e9 Improved mix mode ADC conversion:
Ideenmodellierer
parents: 918
diff changeset
466 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
467 {
ad96f99ebc78 Synchronize ADC and UART activities:
Ideenmodellierer
parents: 842
diff changeset
468 active = 0;
ad96f99ebc78 Synchronize ADC and UART activities:
Ideenmodellierer
parents: 842
diff changeset
469 }
ad96f99ebc78 Synchronize ADC and UART activities:
Ideenmodellierer
parents: 842
diff changeset
470 return active;
ad96f99ebc78 Synchronize ADC and UART activities:
Ideenmodellierer
parents: 842
diff changeset
471 }
809
9602a7338f28 DevBugfix CO2 sensor in streaming mode:
Ideenmodellierer
parents: 803
diff changeset
472
921
eb4109d7d1e9 Improved mix mode ADC conversion:
Ideenmodellierer
parents: 918
diff changeset
473
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/