annotate Small_CPU/Src/uart_Internal.c @ 952:33e24b77cc6c Evo_2_23 tip

Bugfix ppo2 high/low check in OC mode: The fallback option which is used in CC mode was applied to the OC mode as well. As result the check could be deactivated depending on the fallback state, even if a OC dive is performed. now the check will always be performed if the dive mode is OC. Added vibration warning: The internal buzzer of the GPIO_V2 may now be used as additional warning notificator. It can be activated using the check button in the customer view menu. The vibration will be active while the warning message is displayed in the dive window. In case the diver is in the menu then the warning will be active for a shorter duration.
author Ideenmodellierer
date Sun, 29 Dec 2024 18:33:02 +0100
parents f41974734268
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
1 /**
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
2 ******************************************************************************
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
3 * @file uart_Internal.c
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
5 * @version V0.0.1
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
6 * @date 03-November-2044
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
7 * @brief Control functions for devices connected to the internal UART
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
8 *
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
9 @verbatim
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
10 ==============================================================================
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
11 ##### How to use #####
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
12 ==============================================================================
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
13 @endverbatim
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
14 ******************************************************************************
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
15 * @attention
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
16 *
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
17 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
18 *
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
19 ******************************************************************************
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
20 */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
21 /* Includes ------------------------------------------------------------------*/
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
22 #include "uart.h"
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
23 #include "uart_Internal.h"
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
24 #include "uartProtocol_GNSS.h"
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
25 #include "GNSS.h"
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
26 #include "externalInterface.h"
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
27 #include "data_exchange.h"
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
28 #include <string.h> /* memset */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
29
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
30
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
31 /* Private variables ---------------------------------------------------------*/
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
32
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
33 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor (UART mux) */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
34 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
35 #define TIMEOUT_SENSOR_ANSWER (300) /* Time till a request is repeated if no answer was received */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
36
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
37 DMA_HandleTypeDef hdma_usart6_rx, hdma_usart6_tx;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
38
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
39 uint8_t tx6Buffer[CHUNK_SIZE]; /* tx uses less bytes */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
40
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
41 uint8_t rxBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow variations in buffer read time */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
42 uint8_t txBufferUart6[CHUNK_SIZE * CHUNKS_PER_BUFFER]; /* The complete buffer has a X * chunk size to allow variations in buffer read time */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
43
932
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
44 sUartComCtrl Uart6Ctrl;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
45
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
46 /* Exported functions --------------------------------------------------------*/
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
47
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
48 void GNSS_IO_init() {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
49
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
50 GPIO_InitTypeDef GPIO_InitStruct = { 0 };
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
51 /* Peripheral clock enable */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
52 __HAL_RCC_USART6_CLK_ENABLE()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
53 ;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
54
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
55 __HAL_RCC_GPIOA_CLK_ENABLE()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
56 ;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
57 /**USART6 GPIO Configuration
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
58 PA11 ------> USART6_TX
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
59 PA12 ------> USART6_RX
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
60 */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
61 GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
62 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
63 GPIO_InitStruct.Pull = GPIO_NOPULL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
64 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
65 GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
66 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
67
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
68 /* USART6 DMA Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
69 /* USART6_RX Init */
923
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
70 hdma_usart6_rx.Instance = DMA2_Stream2;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
71 hdma_usart6_rx.Init.Channel = DMA_CHANNEL_5;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
72 hdma_usart6_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
73 hdma_usart6_rx.Init.PeriphInc = DMA_PINC_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
74 hdma_usart6_rx.Init.MemInc = DMA_MINC_ENABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
75 hdma_usart6_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
76 hdma_usart6_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
77 hdma_usart6_rx.Init.Mode = DMA_NORMAL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
78 hdma_usart6_rx.Init.Priority = DMA_PRIORITY_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
79 hdma_usart6_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
80 HAL_DMA_Init(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
81
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
82 __HAL_LINKDMA(&huart6, hdmarx, hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
83
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
84 /* USART6_TX Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
85 hdma_usart6_tx.Instance = DMA2_Stream6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
86 hdma_usart6_tx.Init.Channel = DMA_CHANNEL_5;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
87 hdma_usart6_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
88 hdma_usart6_tx.Init.PeriphInc = DMA_PINC_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
89 hdma_usart6_tx.Init.MemInc = DMA_MINC_ENABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
90 hdma_usart6_tx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
91 hdma_usart6_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
92 hdma_usart6_tx.Init.Mode = DMA_NORMAL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
93 hdma_usart6_tx.Init.Priority = DMA_PRIORITY_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
94 hdma_usart6_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
95 HAL_DMA_Init(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
96
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
97 __HAL_LINKDMA(&huart6, hdmatx, hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
98
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
99 /* USART6 interrupt Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
100 HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
101 HAL_NVIC_EnableIRQ(USART6_IRQn);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
102
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
103 MX_USART6_DMA_Init();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
104
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
105 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
106
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
107 void MX_USART6_DMA_Init() {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
108 /* DMA controller clock enable */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
109 __HAL_RCC_DMA2_CLK_ENABLE();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
110
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
111 /* DMA interrupt init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
112 /* DMA2_Stream2_IRQn interrupt configuration */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
113 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
114 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
115 /* DMA2_Stream6_IRQn interrupt configuration */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
116 HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
117 HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
118 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
119
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
120
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
121 void MX_USART6_UART_DeInit(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
122 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
123 HAL_DMA_Abort(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
124 HAL_DMA_DeInit(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
125 HAL_DMA_Abort(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
126 HAL_DMA_DeInit(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
127 HAL_UART_DeInit(&huart6);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
128 HAL_UART_DeInit(&huart6);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
129 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
130
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
131 void MX_USART6_UART_Init(void) {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
132 huart6.Instance = USART6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
133 huart6.Init.BaudRate = 9600;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
134 huart6.Init.WordLength = UART_WORDLENGTH_8B;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
135 huart6.Init.StopBits = UART_STOPBITS_1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
136 huart6.Init.Parity = UART_PARITY_NONE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
137 huart6.Init.Mode = UART_MODE_TX_RX;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
138 huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
139 huart6.Init.OverSampling = UART_OVERSAMPLING_16;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
140 HAL_UART_Init(&huart6);
923
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
141
932
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
142 UART_clearRxBuffer(&Uart6Ctrl);
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
143
932
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
144 Uart6Ctrl.pHandle = &huart6;
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
145 Uart6Ctrl.dmaRxActive = 0;
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
146 Uart6Ctrl.dmaTxActive = 0;
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
147 Uart6Ctrl.pRxBuffer = rxBufferUart6;
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
148 Uart6Ctrl.pTxBuffer = txBufferUart6;
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
149 Uart6Ctrl.rxReadIndex = 0;
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
150 Uart6Ctrl.rxWriteIndex = 0;
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
151 Uart6Ctrl.txBufferQueLen = 0;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
152
932
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
153 UART_SetGnssCtrl(&Uart6Ctrl);
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
154 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
155
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
156 void UART6_HandleUART()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
157 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
158 static uint8_t retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
159 static uint32_t lastRequestTick = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
160 static uint32_t TriggerTick = 0;
939
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
161 static uint16_t timeToTrigger = 0;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
162 uint32_t tick = HAL_GetTick();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
163
932
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
164 uartGnssStatus_t gnssState = uartGnss_GetState();
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
165
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
166 if(gnssState != UART_GNSS_INIT)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
167 {
932
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
168 UART_ReadData(SENSOR_GNSS);
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
169 UART_WriteData(&Uart6Ctrl);
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
170 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
171 if(gnssState == UART_GNSS_INIT)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
172 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
173 lastRequestTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
174 TriggerTick = tick - 10; /* just to make sure control is triggered */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
175 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
176 retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
177 }
939
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
178 else if((gnssState == UART_GNSS_INACTIVE) && (!uartGnss_isPowerDownRequested())) /* send dummy bytes to wakeup receiver */
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
179 {
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
180 txBufferUart6[0] = 0xFF;
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
181 txBufferUart6[1] = 0xFF;
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
182 HAL_UART_Transmit_DMA(Uart6Ctrl.pHandle, Uart6Ctrl.pTxBuffer,2);
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
183 timeToTrigger = 500; /* receiver needs 500ms for wakeup */
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
184 lastRequestTick = tick;
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
185 gnssState = UART_GNSS_PWRUP;
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
186 uartGnss_SetState(gnssState);
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
187 }
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
188 else if(((retryRequest == 0) /* timeout or error */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
189 && (((time_elapsed_ms(lastRequestTick,tick) > (TIMEOUT_SENSOR_ANSWER)) && (gnssState != UART_GNSS_IDLE)) /* retry if no answer after half request interval */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
190 || (gnssState == UART_GNSS_ERROR))))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
191 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
192 /* The channel switch will cause the sensor to respond with an error message. */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
193 /* The sensor needs ~30ms to recover before he is ready to receive the next command => transmission delay needed */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
194
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
195 TriggerTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
196 timeToTrigger = COMMAND_TX_DELAY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
197 retryRequest = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
198 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
199
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
200 else if(time_elapsed_ms(lastRequestTick,tick) > 1000) /* switch sensor and / or trigger next request */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
201 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
202 lastRequestTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
203 TriggerTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
204 retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
205 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
206
939
f41974734268 Resume UART com with gnss after sleep:
Ideenmodellierer
parents: 932
diff changeset
207 if((gnssState == UART_GNSS_GET_SAT) || (gnssState == UART_GNSS_GET_PVT) || (gnssState == UART_GNSS_PWRUP)) /* timeout */
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
208 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
209 gnssState = UART_GNSS_IDLE;
932
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
210 uartGnss_SetState(gnssState);
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
211 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
212 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
213 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
214 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
215 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
216 timeToTrigger = 0;
932
effadaa3a1f7 Cleanup Gnss UART implementation:
Ideenmodellierer
parents: 931
diff changeset
217 uartGnss_Control();
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
218 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
219
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
220 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
221
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
222
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
223 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/