annotate Small_CPU/Src/uart_Internal.c @ 931:5a9bc2e6112d Evo_2_23 tip

Added Sat Status Overview: In addition to the navigation data now information regarding the satelliete and signal status are visualized. To enable the a new command has been added to the communication protocol and the position view has been extended.
author Ideenmodellierer
date Tue, 03 Dec 2024 20:32:51 +0100
parents 908d9a8e8c84
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 static uint8_t isEndIndication6(uint8_t index);
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
32 static uartGnssStatus_t gnssState = UART_GNSS_INIT;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
33 static gnssRequest_s activeRequest = {0,0};
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
34
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
35 /* Private variables ---------------------------------------------------------*/
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
36
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
37
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
38 #define TX_BUF_SIZE (40u) /* max length for commands */
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
39 #define CHUNK_SIZE (50u) /* the DMA will handle chunk size transfers */
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
40 #define CHUNKS_PER_BUFFER (3u)
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
41
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
42 #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
43 #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
44 #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
45
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
46
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
47 static receiveStateGnss_t rxState = GNSSRX_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
48 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
49
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
50 static uint8_t writeIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
51
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
52 static uint16_t dataToRead = 0;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
53
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
54 DMA_HandleTypeDef hdma_usart6_rx, hdma_usart6_tx;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
55
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
56 uint8_t tx6Buffer[CHUNK_SIZE]; /* tx uses less bytes */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
57 uint8_t tx6BufferQue[TX_BUF_SIZE]; /* In MUX mode command may be send shortly after each other => allow q 1 entry que */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
58 uint8_t tx6BufferQueLen;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
59
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
60 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
61 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
62
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
63 static uint8_t rx6WriteIndex; /* Index of the data item which is analysed */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
64 static uint8_t rx6ReadIndex; /* Index at which new data is stared */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
65
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
66 static uint8_t dmaRx6Active; /* Indicator if DMA reception needs to be started */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
67 static uint8_t dmaTx6Active; /* Indicator if DMA reception needs to be started */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
68
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
69
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
70 /* Exported functions --------------------------------------------------------*/
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
71
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
72 void UART_clearRx6Buffer(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
73 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
74 uint16_t index = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
75 do
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
76 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
77 rxBufferUart6[index++] = BUFFER_NODATA_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
78 rxBufferUart6[index++] = BUFFER_NODATA_HIGH;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
79 } while (index < sizeof(rxBufferUart6));
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
80
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
81 rx6ReadIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
82 rx6WriteIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
83 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
84
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
85 void GNSS_IO_init() {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
86
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
87 GPIO_InitTypeDef GPIO_InitStruct = { 0 };
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
88 /* Peripheral clock enable */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
89 __HAL_RCC_USART6_CLK_ENABLE()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
90 ;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
91
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
92 __HAL_RCC_GPIOA_CLK_ENABLE()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
93 ;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
94 /**USART6 GPIO Configuration
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
95 PA11 ------> USART6_TX
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
96 PA12 ------> USART6_RX
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
97 */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
98 GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
99 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
100 GPIO_InitStruct.Pull = GPIO_NOPULL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
101 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
102 GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
103 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
104
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
105 /* USART6 DMA Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
106 /* USART6_RX Init */
923
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
107 hdma_usart6_rx.Instance = DMA2_Stream2;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
108 hdma_usart6_rx.Init.Channel = DMA_CHANNEL_5;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
109 hdma_usart6_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
110 hdma_usart6_rx.Init.PeriphInc = DMA_PINC_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
111 hdma_usart6_rx.Init.MemInc = DMA_MINC_ENABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
112 hdma_usart6_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
113 hdma_usart6_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
114 hdma_usart6_rx.Init.Mode = DMA_NORMAL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
115 hdma_usart6_rx.Init.Priority = DMA_PRIORITY_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
116 hdma_usart6_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
117 HAL_DMA_Init(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
118
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
119 __HAL_LINKDMA(&huart6, hdmarx, hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
120
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
121 /* USART6_TX Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
122 hdma_usart6_tx.Instance = DMA2_Stream6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
123 hdma_usart6_tx.Init.Channel = DMA_CHANNEL_5;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
124 hdma_usart6_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
125 hdma_usart6_tx.Init.PeriphInc = DMA_PINC_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
126 hdma_usart6_tx.Init.MemInc = DMA_MINC_ENABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
127 hdma_usart6_tx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
128 hdma_usart6_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
129 hdma_usart6_tx.Init.Mode = DMA_NORMAL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
130 hdma_usart6_tx.Init.Priority = DMA_PRIORITY_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
131 hdma_usart6_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
132 HAL_DMA_Init(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
133
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
134 __HAL_LINKDMA(&huart6, hdmatx, hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
135
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
136 /* USART6 interrupt Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
137 HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
138 HAL_NVIC_EnableIRQ(USART6_IRQn);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
139
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
140 MX_USART6_DMA_Init();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
141
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
142 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
143
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
144 void MX_USART6_DMA_Init() {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
145 /* DMA controller clock enable */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
146 __HAL_RCC_DMA2_CLK_ENABLE();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
147
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
148 /* DMA interrupt init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
149 /* DMA2_Stream2_IRQn interrupt configuration */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
150 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
151 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
152 /* DMA2_Stream6_IRQn interrupt configuration */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
153 HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
154 HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
155 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
156
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
157
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
158 void MX_USART6_UART_DeInit(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
159 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
160 HAL_DMA_Abort(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
161 HAL_DMA_DeInit(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
162 HAL_DMA_Abort(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
163 HAL_DMA_DeInit(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
164 HAL_UART_DeInit(&huart6);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
165 HAL_UART_DeInit(&huart6);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
166 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
167
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
168 void MX_USART6_UART_Init(void) {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
169 huart6.Instance = USART6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
170 huart6.Init.BaudRate = 9600;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
171 huart6.Init.WordLength = UART_WORDLENGTH_8B;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
172 huart6.Init.StopBits = UART_STOPBITS_1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
173 huart6.Init.Parity = UART_PARITY_NONE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
174 huart6.Init.Mode = UART_MODE_TX_RX;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
175 huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
176 huart6.Init.OverSampling = UART_OVERSAMPLING_16;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
177 HAL_UART_Init(&huart6);
923
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
178
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
179 UART_clearRx6Buffer();
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
180 dmaRx6Active = 0;
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
181 dmaTx6Active = 0;
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
182 tx6BufferQueLen = 0;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
183 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
184
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
185
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
186
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
187 void UART6_SendCmdUbx(const uint8_t *cmd, uint8_t len)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
188 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
189 if(len < TX_BUF_SIZE) /* A longer string is an indication for a missing 0 termination */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
190 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
191 if(dmaRx6Active == 0)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
192 {
927
908d9a8e8c84 Cleanup Internal Uart:
Ideenmodellierer
parents: 923
diff changeset
193 UART6_StartDMA_Receiption();
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
194 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
195 memcpy(tx6Buffer, cmd, len);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
196 if(HAL_OK == HAL_UART_Transmit_DMA(&huart6,tx6Buffer,len))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
197 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
198 dmaTx6Active = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
199 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
200 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
201 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
202
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
203 uint8_t isEndIndication6(uint8_t index)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
204 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
205 uint8_t ret = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
206 if(index % 2)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
207 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
208 if(rxBufferUart6[index] == BUFFER_NODATA_HIGH)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
209 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
210 ret = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
211 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
212 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
213 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
214 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
215 if(rxBufferUart6[index] == BUFFER_NODATA_LOW)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
216 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
217 ret = 1;
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 return ret;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
222 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
223
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
224 void UART6_StartDMA_Receiption()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
225 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
226 if(dmaRx6Active == 0)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
227 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
228 if(((rx6WriteIndex / CHUNK_SIZE) != (rx6ReadIndex / CHUNK_SIZE)) || ((isEndIndication6(rx6WriteIndex)) && (isEndIndication6(rx6WriteIndex + 1)))) /* start next transfer if we did not catch up with read index */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
229 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
230 if(HAL_OK == HAL_UART_Receive_DMA (&huart6, &rxBufferUart6[rx6WriteIndex], CHUNK_SIZE))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
231 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
232 dmaRx6Active = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
233 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
234 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
235 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
236 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
237
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
238
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
239
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
240 void UART6_RxCpltCallback(UART_HandleTypeDef *huart)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
241 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
242 if(huart == &huart6)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
243 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
244 dmaRx6Active = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
245 rx6WriteIndex+=CHUNK_SIZE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
246 if(rx6WriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
247 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
248 rx6WriteIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
249 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
250 UART6_StartDMA_Receiption();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
251 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
252 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
253 void UART6_TxCpltCallback(UART_HandleTypeDef *huart)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
254 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
255 if(huart == &huart6)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
256 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
257 dmaTx6Active = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
258 UART6_WriteData();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
259 if(tx6BufferQueLen)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
260 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
261 memcpy(tx6Buffer, tx6BufferQue, tx6BufferQueLen);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
262 HAL_UART_Transmit_DMA(&huart6,tx6Buffer,tx6BufferQueLen);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
263 dmaTx6Active = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
264 tx6BufferQueLen = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
265 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
266 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
267 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
268
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
269 void UART6_ReadData()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
270 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
271 uint8_t localRX = rx6ReadIndex;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
272 uint8_t futureIndex = rx6ReadIndex + 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
273 uint8_t moreData = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
274
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
275 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
276 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
277 futureIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
278 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
279
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
280 if(!isEndIndication6(futureIndex))
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
281 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
282 moreData = 1;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
283 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
284
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
285 if((!isEndIndication6(localRX)) || (moreData))
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
286 do
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
287 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
288 while((!isEndIndication6(localRX)) || (moreData))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
289 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
290 moreData = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
291 UART6_Gnss_ProcessData(rxBufferUart6[localRX]);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
292
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
293 if(localRX % 2)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
294 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
295 rxBufferUart6[localRX] = BUFFER_NODATA_HIGH;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
296 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
297 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
298 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
299 rxBufferUart6[localRX] = BUFFER_NODATA_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
300 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
301
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
302 localRX++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
303 rx6ReadIndex++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
304 if(rx6ReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
305 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
306 localRX = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
307 rx6ReadIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
308 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
309 futureIndex++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
310 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
311 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
312 futureIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
313 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
314 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
315 if(!isEndIndication6(futureIndex))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
316 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
317 moreData = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
318 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
319 } while(moreData);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
320 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
321
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
322 void UART6_WriteData(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
323 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
324 if(huart6.hdmatx->State == HAL_DMA_STATE_READY)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
325 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
326 huart6.gState = HAL_UART_STATE_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
327 dmaTx6Active = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
328 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
329 if(huart6.hdmarx->State == HAL_DMA_STATE_READY)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
330 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
331 huart6.RxState = HAL_UART_STATE_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
332 dmaRx6Active = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
333 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
334 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
335
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
336 void UART6_Gnss_SendCmd(uint8_t GnssCmd)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
337 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
338 const uint8_t* pData;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
339 uint8_t txLength = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
340
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
341 switch (GnssCmd)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
342 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
343 case GNSSCMD_LOADCONF_0: pData = configUBX;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
344 txLength = sizeof(configUBX) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
345 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
346 case GNSSCMD_LOADCONF_1: pData = setNMEA410;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
347 txLength = sizeof(setNMEA410) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
348 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
349 case GNSSCMD_LOADCONF_2: pData = setGNSS;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
350 txLength = sizeof(setGNSS) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
351 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
352 case GNSSCMD_GET_PVT_DATA: pData = getPVTData;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
353 txLength = sizeof(getPVTData) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
354 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
355 case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
356 txLength = sizeof(getNavigatorData) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
357 break;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
358 case GNSSCMD_GET_NAVSAT_DATA: pData = getNavSat;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
359 txLength = sizeof(getNavSat) / sizeof(uint8_t);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
360 break;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
361 default:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
362 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
363 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
364 if(txLength != 0)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
365 {
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
366 activeRequest.class = pData[2];
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
367 activeRequest.id = pData[3];
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
368 UART6_SendCmdUbx(pData, txLength);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
369 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
370 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
371
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
372 void UART6_Gnss_Control(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
373 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
374 static uint32_t warmupTick = 0;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
375 static uint8_t dataToggle = 0;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
376
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
377 switch (gnssState)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
378 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
379 case UART_GNSS_INIT: gnssState = UART_GNSS_WARMUP;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
380 warmupTick = HAL_GetTick();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
381 UART_clearRxBuffer();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
382 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
383 case UART_GNSS_WARMUP: if(time_elapsed_ms(warmupTick,HAL_GetTick()) > 1000)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
384 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
385 gnssState = UART_GNSS_LOADCONF_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
386 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
387 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
388 case UART_GNSS_LOADCONF_0: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
389 gnssState = UART_GNSS_LOADCONF_1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
390 rxState = GNSSRX_DETECT_ACK_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
391 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
392 case UART_GNSS_LOADCONF_1: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_1);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
393 gnssState = UART_GNSS_LOADCONF_2;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
394 rxState = GNSSRX_DETECT_ACK_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
395 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
396 case UART_GNSS_LOADCONF_2: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_2);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
397 gnssState = UART_GNSS_IDLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
398 rxState = GNSSRX_DETECT_ACK_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
399 break;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
400 case UART_GNSS_IDLE: if(dataToggle)
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
401 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
402 UART6_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
403 gnssState = UART_GNSS_GET_PVT;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
404 rxState = GNSSRX_DETECT_HEADER_0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
405 dataToggle = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
406 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
407 else
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
408 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
409 UART6_Gnss_SendCmd(GNSSCMD_GET_NAVSAT_DATA);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
410 gnssState = UART_GNSS_GET_SAT;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
411 rxState = GNSSRX_DETECT_HEADER_0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
412 dataToggle = 1;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
413 }
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
414 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
415 default:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
416 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
417 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
418 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
419
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
420 void UART6_Gnss_ProcessData(uint8_t data)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
421 {
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
422 static uint16_t rxLength = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
423 static uint8_t ck_A = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
424 static uint8_t ck_B = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
425 static uint8_t ck_A_Ref = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
426 static uint8_t ck_B_Ref = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
427
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
428 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
429 if((rxState >= GNSSRX_DETECT_HEADER_2) && (rxState < GNSSRX_READ_CK_A))
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
430 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
431 ck_A += data;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
432 ck_B += ck_A;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
433 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
434
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
435 switch(rxState)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
436 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
437 case GNSSRX_DETECT_ACK_0:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
438 case GNSSRX_DETECT_HEADER_0: if(data == 0xB5)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
439 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
440 writeIndex = 0;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
441 memset(GNSS_Handle.uartWorkingBuffer,0xff, sizeof(GNSS_Handle.uartWorkingBuffer));
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
442 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
443 rxState++;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
444 ck_A = 0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
445 ck_B = 0;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
446 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
447 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
448 case GNSSRX_DETECT_ACK_1:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
449 case GNSSRX_DETECT_HEADER_1: if(data == 0x62)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
450 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
451 rxState++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
452 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
453 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
454 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
455 rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
456 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
457 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
458 case GNSSRX_DETECT_ACK_2: if(data == 0x05)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
459 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
460 rxState++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
461 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
462 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
463 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
464 rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
465 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
466 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
467 case GNSSRX_DETECT_ACK_3: if((data == 0x01) || (data == 0x00))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
468 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
469 GnssConnected = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
470 rxState = GNSSRX_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
471 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
472 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
473 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
474 rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
475 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
476 break;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
477 case GNSSRX_DETECT_HEADER_2: if(data == activeRequest.class)
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
478 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
479 rxState++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
480 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
481 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
482 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
483 rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
484 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
485 break;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
486 case GNSSRX_DETECT_HEADER_3: if(data == activeRequest.id)
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
487 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
488 rxState = GNSSRX_DETECT_LENGTH_0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
489 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
490 else
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
491 {
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
492 rxState = GNSSRX_DETECT_HEADER_0;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
493 }
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
494 break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
495 case GNSSRX_DETECT_LENGTH_0: rxLength = GNSS_Handle.uartWorkingBuffer[4];
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
496 rxState = GNSSRX_DETECT_LENGTH_1;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
497 break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
498 case GNSSRX_DETECT_LENGTH_1: rxLength += (GNSS_Handle.uartWorkingBuffer[5] << 8);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
499 rxState = GNSSRX_READ_DATA;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
500 dataToRead = rxLength;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
501 break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
502 case GNSSRX_READ_DATA: if(dataToRead > 0)
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
503 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
504 dataToRead--;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
505 }
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
506 if(dataToRead == 0)
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
507 {
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
508 rxState = GNSSRX_READ_CK_A;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
509 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
510 break;
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
511 case GNSSRX_READ_CK_A: ck_A_Ref = data;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
512 rxState++;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
513 break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
514 case GNSSRX_READ_CK_B: ck_B_Ref = data;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
515 if((ck_A_Ref == ck_A) && (ck_B_Ref == ck_B))
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
516 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
517 switch(gnssState)
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
518 {
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
519 case UART_GNSS_GET_PVT:GNSS_ParsePVTData(&GNSS_Handle);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
520 break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
521 case UART_GNSS_GET_SAT: GNSS_ParseNavSatData(&GNSS_Handle);
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
522 break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
523 default:
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
524 break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
525 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
526 }
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
527 rxState = GNSSRX_DETECT_HEADER_0;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
528 gnssState = UART_GNSS_IDLE;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
529 break;
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
530
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
531 default: rxState = GNSSRX_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
532 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
533 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
534 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
535
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
536
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
537 void UART6_HandleUART()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
538 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
539 static uint8_t retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
540 static uint32_t lastRequestTick = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
541 static uint32_t TriggerTick = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
542 static uint8_t timeToTrigger = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
543 uint32_t tick = HAL_GetTick();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
544
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
545 if(gnssState != UART_GNSS_INIT)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
546 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
547 UART6_ReadData();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
548 UART6_WriteData();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
549 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
550 if(gnssState == UART_GNSS_INIT)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
551 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
552 lastRequestTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
553 TriggerTick = tick - 10; /* just to make sure control is triggered */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
554 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
555 retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
556 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
557 else if(((retryRequest == 0) /* timeout or error */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
558 && (((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
559 || (gnssState == UART_GNSS_ERROR))))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
560 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
561 /* The channel switch will cause the sensor to respond with an error message. */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
562 /* 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
563
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
564 TriggerTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
565 timeToTrigger = COMMAND_TX_DELAY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
566 retryRequest = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
567 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
568
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
569 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
570 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
571 lastRequestTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
572 TriggerTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
573 retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
574 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
575
931
5a9bc2e6112d Added Sat Status Overview:
Ideenmodellierer
parents: 927
diff changeset
576 if((gnssState == UART_GNSS_GET_SAT) || (gnssState == UART_GNSS_GET_PVT)) /* timeout */
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
577 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
578 gnssState = UART_GNSS_IDLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
579 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
580 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
581 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
582 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
583 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
584 timeToTrigger = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
585 UART6_Gnss_Control();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
586 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
587
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
588 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
589
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
590
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
591 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/