annotate Small_CPU/Src/uart.c @ 921:eb4109d7d1e9 Evo_2_23

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