annotate Small_CPU/Src/uart.c @ 800:f8a112c5e71d

Cleanup warnings
author Ideenmodellierer
date Tue, 08 Aug 2023 17:29:03 +0200
parents e9eba334b942
children 96ffad0a4e57
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"
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
25 #include "externalInterface.h"
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
26 #include "data_exchange.h"
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
27 #include <string.h> /* memset */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
31
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
32
781
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
33 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */
01b3eb9d55c3 Update real multiplexer implementation:
Ideenmodellierer
parents: 779
diff changeset
34 #define CHUNKS_PER_BUFFER (5u)
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
35
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
36 UART_HandleTypeDef huart1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
37
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
38 DMA_HandleTypeDef hdma_usart1_rx;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
40 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
41 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
42 static uint8_t rxReadIndex; /* Index at which new data is stared */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
43 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
44 static uint8_t dmaActive; /* Indicator if DMA reception needs to be started */
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
45
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
46
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
47 static uint8_t SentinelConnected = 0; /* Binary indicator if a sensor is connected or not */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
49
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
52
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
53 void MX_USART1_UART_Init(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
55 /* regular init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
56
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
57 huart1.Instance = USART1;
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
58
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
59 if(externalInterface_GetUARTProtocol() == 0x04)
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
60 {
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
61 huart1.Init.BaudRate = 19200;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
62 }
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
63 else
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
64 {
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
65 huart1.Init.BaudRate = 9600;
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
66 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
67 huart1.Init.WordLength = UART_WORDLENGTH_8B;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
68 huart1.Init.StopBits = UART_STOPBITS_1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
69 huart1.Init.Parity = UART_PARITY_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
70 huart1.Init.Mode = UART_MODE_TX_RX;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
71 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
72 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
73
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
74 HAL_UART_Init(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
75
704
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
76 MX_USART1_DMA_Init();
f1b40364b0af Added protocol functions for UART DiveO2 sensor:
Ideenmodellierer
parents: 690
diff changeset
77
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
78 memset(rxBuffer,BUFFER_NODATA,sizeof(rxBuffer));
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
79 rxReadIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
80 lastCmdIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
81 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
82 dmaActive = 0;
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
83
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
84 SentinelConnected = 0;
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
85
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
86 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
88 void MX_USART1_UART_DeInit(void)
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 HAL_DMA_Abort(&hdma_usart1_rx);
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
91 HAL_DMA_DeInit(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
92 HAL_UART_DeInit(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
93 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
94
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
95 void MX_USART1_DMA_Init()
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
96 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
97 /* DMA controller clock enable */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
98 __DMA2_CLK_ENABLE();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
99
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
100 /* Peripheral DMA init*/
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
101 hdma_usart1_rx.Instance = DMA2_Stream5;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
102 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
103 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
104 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
105 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
106 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
107 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
108 hdma_usart1_rx.Init.Mode = DMA_NORMAL;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
109 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
110 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
111 HAL_DMA_Init(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
112
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
113 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
114
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
115 /* DMA interrupt init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
116 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
117 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
120 void UART_MUX_SelectAddress(uint8_t muxAddress)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
121 {
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
122 uint8_t indexstr[4];
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
123
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
124 if(muxAddress <= MAX_MUX_CHANNEL)
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
125 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
126 indexstr[0] = '~';
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
127 indexstr[1] = muxAddress;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
128 indexstr[2] = 0x0D;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
129 indexstr[3] = 0x0A;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
130
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
131 HAL_UART_Transmit(&huart1,indexstr,4,10);
779
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
132 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
133 }
0b5f45448eb6 Added UART multiplexer support for DiveO2:
Ideenmodellierer
parents: 747
diff changeset
134
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
135
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
136 void UART_SendCmdString(uint8_t *cmdString)
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
137 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
138 uint8_t cmdLength = strlen((char*)cmdString);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
139
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
140 if(cmdLength < 20) /* A longer string is an indication for a missing 0 termination */
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
141 {
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
142 if(dmaActive == 0)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
143 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
144 UART_StartDMA_Receiption();
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
145 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
146 HAL_UART_Transmit(&huart1,cmdString,cmdLength,10);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
147 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
148 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
149
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
150
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
151 void StringToInt(char *pstr, uint32_t *puInt32)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
152 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
153 uint8_t index = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
154 uint32_t result = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
155 while((pstr[index] >= '0') && (pstr[index] <= '9'))
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
156 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
157 result *=10;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
158 result += pstr[index] - '0';
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
159 index++;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
160 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
161 *puInt32 = result;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
162 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
163
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
164 void StringToUInt64(char *pstr, uint64_t *puint64)
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
165 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
166 uint8_t index = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
167 uint64_t result = 0;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
168 while((pstr[index] >= '0') && (pstr[index] <= '9'))
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
169 {
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
170 result *=10;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
171 result += pstr[index] - '0';
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
172 index++;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
173 }
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
174 *puint64 = result;
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
175 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
176 void ConvertByteToHexString(uint8_t byte, char* str)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
177 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
178 uint8_t worker = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
179 uint8_t digit = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
180 uint8_t digitCnt = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
182 worker = byte;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
183 while((worker!=0) && (digitCnt != 255))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
184 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
185 digit = worker % 16;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
186 if( digit < 10)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
187 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
188 digit += '0';
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
189 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
190 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
191 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
192 digit += 'A' - 10;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
193 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
194 str[digitCnt--]= digit;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
195 worker = worker / 16;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
196 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
197 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
198
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
199 void UART_StartDMA_Receiption()
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
200 {
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
201 if(dmaActive == 0)
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
202 {
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
203 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
204 {
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
205 dmaActive = 1;
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
206 }
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
207 }
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
208 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
209
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
210 void UART_ChangeBaudrate(uint32_t newBaudrate)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 {
725
621265ec3d23 Update CO2 sensor implementation:
Ideenmodellierer
parents: 721
diff changeset
212
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
213 // HAL_DMA_Abort(&hdma_usart1_rx);
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
214 MX_USART1_UART_DeInit();
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
215 //HAL_UART_Abort(&huart1);
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
216 //HAL_DMA_DeInit(&hdma_usart1_rx);
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
217
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
218
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
219 // huart1.Instance->BRR = UART_BRR_SAMPLING8(HAL_RCC_GetPCLK2Freq()/2, newBaudrate);
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
220 huart1.Init.BaudRate = newBaudrate;
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
221 HAL_UART_Init(&huart1);
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
222 MX_USART1_DMA_Init();
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
223 if(dmaActive)
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
224 {
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
225 rxReadIndex = 0;
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
226 rxWriteIndex = 0;
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
227 dmaActive = 0;
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
228 UART_StartDMA_Receiption();
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
229 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
231
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
232 #ifdef ENABLE_SENTINEL_MODE
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
233 void UART_HandleSentinelData(void)
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
234 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
235 uint8_t localRX = rxReadIndex;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
236 static uint8_t dataType = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
237 static uint32_t dataValue[3];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
238 static uint8_t dataValueIdx = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
239 static receiveState_t rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
240 static uint32_t lastReceiveTick = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
241 static uint8_t lastAlive = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
242 static uint8_t curAlive = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
243 static uint8_t checksum = 0;
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
244 static char checksum_str[]="00";
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
245
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
246 while((rxBuffer[localRX]!=0))
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
247 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
248 lastReceiveTick = HAL_GetTick();
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
249
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
250 switch(rxState)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
251 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
252 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z'))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
253 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
254 rxState = RX_DetectStart;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
255 curAlive = rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
256 checksum = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
257 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
258 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
259
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
260 case RX_DetectStart: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
261 if(rxBuffer[localRX] == '1')
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
262 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
263 rxState = RX_SelectData;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
264 dataType = 0xFF;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
265
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
266 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
267 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
268 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
269 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
270 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
271 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
272
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
273 case RX_SelectData: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
274 switch(rxBuffer[localRX])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
275 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
276 case 'T': dataType = rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
277 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
278 case '0': if(dataType != 0xff)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
279 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
280 rxState = RX_Data0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
281 dataValueIdx = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
282 dataValue[0] = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
283
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
284 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
285 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
286 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
287 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
288 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
289 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
290 default: rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
291 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
292 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
293
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
294 case RX_Data0:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
295 case RX_Data1:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
296 case RX_Data2:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
297 case RX_Data4:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
298 case RX_Data5:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
299 case RX_Data6:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
300 case RX_Data8:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
301 case RX_Data9:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
302 case RX_Data10: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
303 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9'))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
304 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
305 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0');
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
306 rxState++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
307 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
308 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
309 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
310 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
311 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
312 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
313
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
314 case RX_Data3:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
315 case RX_Data7: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
316 if(rxBuffer[localRX] == '0')
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
317 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
318 rxState++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
319 dataValueIdx++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
320 dataValue[dataValueIdx] = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
321 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
322 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
323 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
324 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
325 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
326 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
327 case RX_Data11: rxState = RX_DataComplete;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
328 ConvertByteToHexString(checksum,checksum_str);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
329 if(rxBuffer[localRX] == checksum_str[0])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
330 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
331 rxState = RX_DataComplete;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
332 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
333 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
334 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
335 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
336 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
337
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
338 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
339
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
340 case RX_DataComplete: if(rxBuffer[localRX] == checksum_str[1])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
341 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
342 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
343 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
344 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0));
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
345 SentinelConnected = 1;
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
346 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
347 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
348 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
349
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
350
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
351 default: rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
352 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
353
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
354 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
355 localRX++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
356 rxReadIndex++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
357 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
358 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
359 localRX = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
360 rxReadIndex = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
361 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
362 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
363
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
364 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
365 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
366 if(curAlive == lastAlive)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
367 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
368 setExternalInterfaceChannel(0,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
369 setExternalInterfaceChannel(1,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
370 setExternalInterfaceChannel(2,0.0);
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
371 SentinelConnected = 0;
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
372 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
373 lastAlive = curAlive;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
374 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
375
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
376 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
377 {
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
378 UART_StartDMA_Receiption();
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
379 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
380 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
381 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
383
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
384
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
385 uint8_t UART_isSentinelConnected()
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
386 {
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
387 return SentinelConnected;
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
388 }
729
d646a0f724a7 Added auto detection functionality for sensors connected to the external interface:
Ideenmodellierer
parents: 725
diff changeset
389
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
390 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
392 if(huart == &huart1)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
393 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
394 dmaActive = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
395 rxWriteIndex+=CHUNK_SIZE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
396 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
397 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
398 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
399 }
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
400 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE) || (rxWriteIndex == rxReadIndex)) /* start next transfer if we did not catch up with read index */
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
401 {
787
aeb72882f30a Dev Bugfx Empty buffer indication and stability improvments:
Ideenmodellierer
parents: 785
diff changeset
402 if(externalInterface_GetUARTProtocol() != 0)
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
403 {
742
e23fe82cbf8c Update Sentinel protocol:
Ideenmodellierer
parents: 731
diff changeset
404 UART_StartDMA_Receiption();
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
405 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
406 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
407 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
410 void UART_ReadData(uint8_t sensorType)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
411 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
412 uint8_t localRX = rxReadIndex;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
414 while((rxBuffer[localRX]!=BUFFER_NODATA))
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
415 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
416 switch (sensorType)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
417 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
418 case SENSOR_MUX:
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
419 case SENSOR_DIGO2: uartO2_ProcessData(rxBuffer[localRX]);
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
420 break;
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
421 #ifdef ENABLE_CO2_SUPPORT
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
422 case SENSOR_CO2: uartCo2_ProcessData(rxBuffer[localRX]);
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
423 break;
798
e9eba334b942 Migrated CO2 protocol implementation to new format:
Ideenmodellierer
parents: 794
diff changeset
424 #endif
794
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
425 default:
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
426 break;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
427 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
428
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
429 rxBuffer[localRX] = BUFFER_NODATA;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
430 localRX++;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
431 rxReadIndex++;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
432 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
433 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
434 localRX = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
435 rxReadIndex = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
436 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
437 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
438 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
439
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
440 void UART_FlushRxBuffer(void)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
441 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
442 while(rxBuffer[rxReadIndex] != BUFFER_NODATA)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
443 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
444 rxBuffer[rxReadIndex] = BUFFER_NODATA;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
445 rxReadIndex++;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
446 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
447 {
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
448 rxReadIndex = 0;
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
449 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
450 }
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
451
bb37d4f3e50e Restructure UART based sensor handling:
Ideenmodellierer
parents: 787
diff changeset
452 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
453
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/