annotate Small_CPU/Src/uart.c @ 692:b052e812277c Betatest

Added compile switch for Sentinel rebreather option
author Ideenmodellierer
date Fri, 05 Aug 2022 15:27:01 +0200
parents fca2bd25e6e2
children f1b40364b0af
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"
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
23 #include "externalInterface.h"
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
24 #include "data_exchange.h"
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 /* Private variables ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
28 #define CHUNK_SIZE (20u) /* the DMA will handle chunk size transfers */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
29 #define CHUNKS_PER_BUFFER (3u)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
30 UART_HandleTypeDef huart1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
31
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
32 DMA_HandleTypeDef hdma_usart1_rx;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
34 uint8_t rxBuffer[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow fariations in buffer read time */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
35 static uint8_t rxWriteIndex; /* Index of the data item which is analysed */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
36 static uint8_t rxReadIndex; /* Index at which new data is stared */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
37 static uint8_t lastCmdIndex; /* Index of last command which has not been completly received */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
38 static uint8_t dmaActive; /* Indicator if DMA receiption needs to be started */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
40 float LED_Level = 0.0; /* Normalized LED value which may be used as indication for the health status of the sensor */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
41 float LED_ZeroOffset = 0.0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
42 float pCO2 = 0.0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
45 void MX_USART1_UART_Init(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
47 /* regular init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
48
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
49 huart1.Instance = USART1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
50 huart1.Init.BaudRate = 9600;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
51 huart1.Init.WordLength = UART_WORDLENGTH_8B;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
52 huart1.Init.StopBits = UART_STOPBITS_1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
53 huart1.Init.Parity = UART_PARITY_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
54 huart1.Init.Mode = UART_MODE_TX_RX;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
55 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
56 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
57
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
58 HAL_UART_Init(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
59
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
60 rxReadIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
61 lastCmdIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
62 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
63 dmaActive = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
64 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
66 void MX_USART1_UART_DeInit(void)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
67 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
68 HAL_DMA_DeInit(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
69 HAL_UART_DeInit(&huart1);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
70 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
71
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
72 void MX_USART1_DMA_Init()
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
73 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
74 /* DMA controller clock enable */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
75 __DMA2_CLK_ENABLE();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
76
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
77 /* Peripheral DMA init*/
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
78 hdma_usart1_rx.Instance = DMA2_Stream5;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
79 hdma_usart1_rx.Init.Channel = DMA_CHANNEL_4;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
80 hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; //DMA_MEMORY_TO_PERIPH;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
81 hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
82 hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
83 hdma_usart1_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
84 hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
85 hdma_usart1_rx.Init.Mode = DMA_NORMAL;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
86 hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
87 hdma_usart1_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
88 HAL_DMA_Init(&hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
89
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
90 __HAL_LINKDMA(&huart1,hdmarx,hdma_usart1_rx);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
91
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
92 /* DMA interrupt init */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
93 HAL_NVIC_SetPriority(DMA2_Stream5_IRQn, 0, 0);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
94 HAL_NVIC_EnableIRQ(DMA2_Stream5_IRQn);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
97 void ConvertByteToHexString(uint8_t byte, char* str)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
98 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
99 uint8_t worker = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
100 uint8_t digit = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
101 uint8_t digitCnt = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
103 worker = byte;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
104 while((worker!=0) && (digitCnt != 255))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
105 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
106 digit = worker % 16;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
107 if( digit < 10)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
108 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
109 digit += '0';
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
110 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
111 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
112 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
113 digit += 'A' - 10;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
114 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
115 str[digitCnt--]= digit;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
116 worker = worker / 16;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
117 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
118 }
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
119
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
120
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
121 #ifdef ENABLE_CO2_SUPPORT
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
122 void HandleUARTCO2Data(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
123 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
124 uint8_t localRX = rxReadIndex;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
125 uint8_t dataType = 0;
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
126 uint32_t dataValue = 0;
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
127 static receiveState_t rxState = RX_Ready;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
128 static uint32_t lastReceiveTick = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
129
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
130 while(localRX != rxWriteIndex)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
131 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
132 lastReceiveTick = HAL_GetTick();
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
133 if(rxState == RX_Ready) /* identify data content */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
134 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
135 switch(rxBuffer[localRX])
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
136 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
137 case 'l':
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
138 case 'D':
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
139 case 'Z':
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
140 dataType = rxBuffer[localRX];
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
141 rxState = RX_Data0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
142 dataValue = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
143 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
144
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
145 default: /* unknown or corrupted => ignore */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
146 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
147 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
148 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
149 else if((rxState >= RX_Data0) && (rxState <= RX_Data4))
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
150 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
151 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9'))
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
152 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
153 dataValue = dataValue * 10 + (rxBuffer[localRX] - '0');
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
154 rxState++;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
155 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
156 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
157 if((rxBuffer[localRX] == ' ') || (rxBuffer[localRX] == '\n')) /* Abort data detection */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
158 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
159 if(rxState == RX_DataComplete)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
160 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
161 if(externalInterface_GetCO2State() == 0)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
162 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
163 externalInterface_SetCO2State(EXT_INTERFACE_33V_ON);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
164 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
165 switch(dataType)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
166 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
167 case 'D': externalInterface_SetCO2SignalStrength(dataValue);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
168 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
169 case 'l': LED_ZeroOffset = dataValue;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
170 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
171 case 'Z': externalInterface_SetCO2Value(dataValue);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
172 break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
173 default: break;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
174 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
175 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
176 if(rxState != RX_Data0) /* reset state machine because message in wrong format */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
177 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
178 rxState = RX_Ready;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
179 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
180 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
181
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
182 localRX++;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
183 rxReadIndex++;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
184 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
185 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
186 localRX = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
187 rxReadIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
188 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
189 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
190
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
191 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 2000) /* check for communication timeout */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
192 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
193 externalInterface_SetCO2State(0);
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
194 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
195
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
196 if((dmaActive == 0) && (externalInterface_isEnabledPower33())) /* Should never happen in normal operation => restart in case of communication error */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
197 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
198 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
199 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
200 dmaActive = 1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
201 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
202 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 }
690
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
204 #endif
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
205
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
206 #ifdef ENABLE_SENTINEL_MODE
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
207 void HandleUARTSentinelData(void)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
208 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
209 uint8_t localRX = rxReadIndex;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
210 static uint8_t dataType = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
211 static uint32_t dataValue[3];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
212 static uint8_t dataValueIdx = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
213 static receiveState_t rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
214 static uint32_t lastReceiveTick = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
215 static uint8_t lastAlive = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
216 static uint8_t curAlive = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
217 static uint8_t checksum = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
218 char checksum_str[]="00";
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
219
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
220 while(localRX != rxWriteIndex)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
221 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
222 lastReceiveTick = HAL_GetTick();
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
223
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
224 switch(rxState)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
225 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
226 case RX_Ready: if((rxBuffer[localRX] >= 'a') && (rxBuffer[localRX] <= 'z'))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
227 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
228 rxState = RX_DetectStart;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
229 curAlive = rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
230 checksum = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
231 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
232 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
233
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
234 case RX_DetectStart: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
235 if(rxBuffer[localRX] == '1')
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
236 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
237 rxState = RX_SelectData;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
238 dataType = 0xFF;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
239
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
240 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
241 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
242 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
243 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
244 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
245 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
246
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
247 case RX_SelectData: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
248 switch(rxBuffer[localRX])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
249 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
250 case 'T': dataType = rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
251 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
252 case '0': if(dataType != 0xff)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
253 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
254 rxState = RX_Data0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
255 dataValueIdx = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
256 dataValue[0] = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
257
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
258 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
259 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
260 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
261 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
262 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
263 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
264 default: rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
265 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
266 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
267
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
268 case RX_Data0:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
269 case RX_Data1:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
270 case RX_Data2:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
271 case RX_Data4:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
272 case RX_Data5:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
273 case RX_Data6:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
274 case RX_Data8:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
275 case RX_Data9:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
276 case RX_Data10: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
277 if((rxBuffer[localRX] >= '0') && (rxBuffer[localRX] <= '9'))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
278 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
279 dataValue[dataValueIdx] = dataValue[dataValueIdx] * 10 + (rxBuffer[localRX] - '0');
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
280 rxState++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
281 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
282 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
283 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
284 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
285 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
286 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
287
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
288 case RX_Data3:
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
289 case RX_Data7: checksum += rxBuffer[localRX];
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
290 if(rxBuffer[localRX] == '0')
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
291 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
292 rxState++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
293 dataValueIdx++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
294 dataValue[dataValueIdx] = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
295 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
296 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
297 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
298 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
299 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
300 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
301 case RX_Data11: rxState = RX_DataComplete;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
302 ConvertByteToHexString(checksum,checksum_str);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
303 if(rxBuffer[localRX] == checksum_str[0])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
304 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
305 rxState = RX_DataComplete;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
306 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
307 else
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
308 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
309 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
310 }
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_DataComplete: if(rxBuffer[localRX] == checksum_str[1])
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
315 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
316 setExternalInterfaceChannel(0,(float)(dataValue[0] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
317 setExternalInterfaceChannel(1,(float)(dataValue[1] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
318 setExternalInterfaceChannel(2,(float)(dataValue[2] / 10.0));
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
319 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
320 rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
321 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
322
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
323
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
324 default: rxState = RX_Ready;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
325 break;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
326
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
327 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
328
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
329 localRX++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
330 rxReadIndex++;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
331 if(rxReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
332 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
333 localRX = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
334 rxReadIndex = 0;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
335 }
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 if(time_elapsed_ms(lastReceiveTick,HAL_GetTick()) > 4000) /* check for communication timeout */
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
339 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
340 if(curAlive == lastAlive)
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
341 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
342 setExternalInterfaceChannel(0,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
343 setExternalInterfaceChannel(1,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
344 setExternalInterfaceChannel(2,0.0);
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
345 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
346 lastAlive = curAlive;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
347 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
348
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
349 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
350 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
351 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
352 {
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
353 dmaActive = 1;
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
354 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
355 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
356 }
fca2bd25e6e2 Added Sentinel protocoll support:
Ideenmodellierer
parents: 662
diff changeset
357 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
359 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 {
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
361 if(huart == &huart1)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
362 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
363 dmaActive = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
364 rxWriteIndex+=CHUNK_SIZE;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
365 if(rxWriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
366 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
367 rxWriteIndex = 0;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
368 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
369 if((rxWriteIndex / CHUNK_SIZE) != (rxReadIndex / CHUNK_SIZE)) /* start next transfer if we did not catch up with read index */
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
370 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
371 if(externalInterface_isEnabledPower33())
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
372 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
373 if(HAL_OK == HAL_UART_Receive_DMA (&huart1, &rxBuffer[rxWriteIndex], CHUNK_SIZE))
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
374 {
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
375 dmaActive = 1;
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
376 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
377 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
378 }
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
379 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382
662
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
383
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
384
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
385
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
386
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
387
1b995079c045 PSCR Mode
heinrichs weikamp
parents: 38
diff changeset
388
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/