annotate Small_CPU/Src/uart_Internal.c @ 923:6fc0e3d230e4 Evo_2_23 tip

UART6 DMA handling: Make sure that RX transmission uses DMA stream 2
author Ideenmodellierer
date Mon, 04 Nov 2024 20:21:02 +0100
parents 7c996354b8ac
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);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
32 static uint8_t gnssState = UART_GNSS_INIT;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
33
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
34 /* Private variables ---------------------------------------------------------*/
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
35
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
36
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
37 #define TX_BUF_SIZE (40u) /* max length for commands */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
38 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
39 #define CHUNKS_PER_BUFFER (6u)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
40
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
41 #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
42 #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
43 #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
44
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
45
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
46 static receiveStateGnss_t rxState = GNSSRX_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
47 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
48
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
49 static uint8_t writeIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
50
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
51 static uint8_t dataToRead = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
52
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
53 DMA_HandleTypeDef hdma_usart6_rx, hdma_usart6_tx;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
54
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
55 uint8_t tx6Buffer[CHUNK_SIZE]; /* tx uses less bytes */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
56 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
57 uint8_t tx6BufferQueLen;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
58
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
59 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
60 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
61
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
62 static uint8_t rx6WriteIndex; /* Index of the data item which is analysed */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
63 static uint8_t rx6ReadIndex; /* Index at which new data is stared */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
64
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
65 static uint8_t dmaRx6Active; /* Indicator if DMA reception needs to be started */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
66 static uint8_t dmaTx6Active; /* Indicator if DMA reception needs to be started */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
67
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
68
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
69 /* Exported functions --------------------------------------------------------*/
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
70
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
71 void UART_clearRx6Buffer(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
72 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
73 uint16_t index = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
74 do
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
75 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
76 rxBufferUart6[index++] = BUFFER_NODATA_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
77 rxBufferUart6[index++] = BUFFER_NODATA_HIGH;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
78 } while (index < sizeof(rxBufferUart6));
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
79
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
80 rx6ReadIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
81 rx6WriteIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
82 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
83
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
84 void GNSS_IO_init() {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
85
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
86 GPIO_InitTypeDef GPIO_InitStruct = { 0 };
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
87 /* Peripheral clock enable */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
88 __HAL_RCC_USART6_CLK_ENABLE()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
89 ;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
90
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
91 __HAL_RCC_GPIOA_CLK_ENABLE()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
92 ;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
93 /**USART6 GPIO Configuration
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
94 PA11 ------> USART6_TX
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
95 PA12 ------> USART6_RX
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
96 */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
97 GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
98 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
99 GPIO_InitStruct.Pull = GPIO_NOPULL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
100 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
101 GPIO_InitStruct.Alternate = GPIO_AF8_USART6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
102 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
103
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
104 /* USART6 DMA Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
105 /* USART6_RX Init */
923
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
106 hdma_usart6_rx.Instance = DMA2_Stream2;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
107 hdma_usart6_rx.Init.Channel = DMA_CHANNEL_5;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
108 hdma_usart6_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
109 hdma_usart6_rx.Init.PeriphInc = DMA_PINC_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
110 hdma_usart6_rx.Init.MemInc = DMA_MINC_ENABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
111 hdma_usart6_rx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
112 hdma_usart6_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
113 hdma_usart6_rx.Init.Mode = DMA_NORMAL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
114 hdma_usart6_rx.Init.Priority = DMA_PRIORITY_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
115 hdma_usart6_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
116 HAL_DMA_Init(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
117
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
118 __HAL_LINKDMA(&huart6, hdmarx, hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
119
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
120 /* USART6_TX Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
121 hdma_usart6_tx.Instance = DMA2_Stream6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
122 hdma_usart6_tx.Init.Channel = DMA_CHANNEL_5;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
123 hdma_usart6_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
124 hdma_usart6_tx.Init.PeriphInc = DMA_PINC_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
125 hdma_usart6_tx.Init.MemInc = DMA_MINC_ENABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
126 hdma_usart6_tx.Init.PeriphDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
127 hdma_usart6_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
128 hdma_usart6_tx.Init.Mode = DMA_NORMAL;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
129 hdma_usart6_tx.Init.Priority = DMA_PRIORITY_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
130 hdma_usart6_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
131 HAL_DMA_Init(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
132
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
133 __HAL_LINKDMA(&huart6, hdmatx, hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
134
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
135 /* USART6 interrupt Init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
136 HAL_NVIC_SetPriority(USART6_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
137 HAL_NVIC_EnableIRQ(USART6_IRQn);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
138
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
139 MX_USART6_DMA_Init();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
140
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 void MX_USART6_DMA_Init() {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
144 /* DMA controller clock enable */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
145 __HAL_RCC_DMA2_CLK_ENABLE();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
146
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
147 /* DMA interrupt init */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
148 /* DMA2_Stream2_IRQn interrupt configuration */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
149 HAL_NVIC_SetPriority(DMA2_Stream2_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
150 HAL_NVIC_EnableIRQ(DMA2_Stream2_IRQn);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
151 /* DMA2_Stream6_IRQn interrupt configuration */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
152 HAL_NVIC_SetPriority(DMA2_Stream6_IRQn, 0, 0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
153 HAL_NVIC_EnableIRQ(DMA2_Stream6_IRQn);
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
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
157 void MX_USART6_UART_DeInit(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
158 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
159 HAL_DMA_Abort(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
160 HAL_DMA_DeInit(&hdma_usart6_rx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
161 HAL_DMA_Abort(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
162 HAL_DMA_DeInit(&hdma_usart6_tx);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
163 HAL_UART_DeInit(&huart6);
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 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
166
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
167 void MX_USART6_UART_Init(void) {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
168 huart6.Instance = USART6;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
169 huart6.Init.BaudRate = 9600;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
170 huart6.Init.WordLength = UART_WORDLENGTH_8B;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
171 huart6.Init.StopBits = UART_STOPBITS_1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
172 huart6.Init.Parity = UART_PARITY_NONE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
173 huart6.Init.Mode = UART_MODE_TX_RX;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
174 huart6.Init.HwFlowCtl = UART_HWCONTROL_NONE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
175 huart6.Init.OverSampling = UART_OVERSAMPLING_16;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
176 HAL_UART_Init(&huart6);
923
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
177
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
178 UART_clearRx6Buffer();
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
179 dmaRx6Active = 0;
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
180 dmaTx6Active = 0;
6fc0e3d230e4 UART6 DMA handling:
Ideenmodellierer
parents: 922
diff changeset
181 tx6BufferQueLen = 0;
922
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
182 }
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 void UART6_SendCmdUbx(const uint8_t *cmd, uint8_t len)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
187 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
188 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
189 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
190 if(dmaRx6Active == 0)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
191 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
192 UART_StartDMA_Receiption();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
193 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
194 memcpy(tx6Buffer, cmd, len);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
195 if(HAL_OK == HAL_UART_Transmit_DMA(&huart6,tx6Buffer,len))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
196 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
197 dmaTx6Active = 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 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
201
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
202 uint8_t isEndIndication6(uint8_t index)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
203 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
204 uint8_t ret = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
205 if(index % 2)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
206 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
207 if(rxBufferUart6[index] == BUFFER_NODATA_HIGH)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
208 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
209 ret = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
210 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
211 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
212 else
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(rxBufferUart6[index] == BUFFER_NODATA_LOW)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
215 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
216 ret = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
217 }
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 return ret;
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 void UART6_StartDMA_Receiption()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
224 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
225 if(dmaRx6Active == 0)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
226 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
227 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
228 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
229 if(HAL_OK == HAL_UART_Receive_DMA (&huart6, &rxBufferUart6[rx6WriteIndex], CHUNK_SIZE))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
230 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
231 dmaRx6Active = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
232 }
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 void UART6_RxCpltCallback(UART_HandleTypeDef *huart)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
240 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
241 if(huart == &huart6)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
242 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
243 dmaRx6Active = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
244 rx6WriteIndex+=CHUNK_SIZE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
245 if(rx6WriteIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
246 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
247 rx6WriteIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
248 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
249 UART6_StartDMA_Receiption();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
250 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
251 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
252 void UART6_TxCpltCallback(UART_HandleTypeDef *huart)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
253 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
254 if(huart == &huart6)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
255 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
256 dmaTx6Active = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
257 UART6_WriteData();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
258 if(tx6BufferQueLen)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
259 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
260 memcpy(tx6Buffer, tx6BufferQue, tx6BufferQueLen);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
261 HAL_UART_Transmit_DMA(&huart6,tx6Buffer,tx6BufferQueLen);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
262 dmaTx6Active = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
263 tx6BufferQueLen = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
264 }
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 void UART6_ReadData()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
269 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
270 uint8_t localRX = rx6ReadIndex;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
271 uint8_t futureIndex = rx6ReadIndex + 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
272 uint8_t moreData = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
273
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
274 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
275 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
276 futureIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
277 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
278
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
279 if((!isEndIndication6(localRX)) || (!isEndIndication6(futureIndex))) do
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
280 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
281 while((!isEndIndication6(localRX)) || (moreData))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
282 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
283 moreData = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
284 UART6_Gnss_ProcessData(rxBufferUart6[localRX]);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
285
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
286 if(localRX % 2)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
287 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
288 rxBufferUart6[localRX] = BUFFER_NODATA_HIGH;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
289 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
290 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
291 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
292 rxBufferUart6[localRX] = BUFFER_NODATA_LOW;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
293 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
294
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
295 localRX++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
296 rx6ReadIndex++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
297 if(rx6ReadIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
298 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
299 localRX = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
300 rx6ReadIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
301 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
302 futureIndex++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
303 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
304 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
305 futureIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
306 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
307 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
308 if(!isEndIndication6(futureIndex))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
309 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
310 moreData = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
311 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
312 } while(moreData);
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 void UART6_WriteData(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
316 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
317 if(huart6.hdmatx->State == HAL_DMA_STATE_READY)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
318 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
319 huart6.gState = HAL_UART_STATE_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
320 dmaTx6Active = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
321 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
322 if(huart6.hdmarx->State == HAL_DMA_STATE_READY)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
323 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
324 huart6.RxState = HAL_UART_STATE_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
325 dmaRx6Active = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
326 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
327 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
328
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
329 void UART6_Gnss_SendCmd(uint8_t GnssCmd)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
330 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
331 const uint8_t* pData;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
332 uint8_t txLength = 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 switch (GnssCmd)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
335 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
336 case GNSSCMD_LOADCONF_0: pData = configUBX;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
337 txLength = sizeof(configUBX) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
338 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
339 case GNSSCMD_LOADCONF_1: pData = setNMEA410;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
340 txLength = sizeof(setNMEA410) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
341 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
342 case GNSSCMD_LOADCONF_2: pData = setGNSS;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
343 txLength = sizeof(setGNSS) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
344 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
345 case GNSSCMD_GET_PVT_DATA: pData = getPVTData;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
346 txLength = sizeof(getPVTData) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
347 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
348 case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
349 txLength = sizeof(getNavigatorData) / sizeof(uint8_t);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
350 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
351
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
352 default:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
353 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
354 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
355 if(txLength != 0)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
356 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
357 UART6_SendCmdUbx(pData, txLength);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
358 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
359 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
360
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
361 void UART6_Gnss_Control(void)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
362 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
363 static uint32_t warmupTick = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
364
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
365 switch (gnssState)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
366 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
367 case UART_GNSS_INIT: gnssState = UART_GNSS_WARMUP;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
368 warmupTick = HAL_GetTick();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
369 UART_clearRxBuffer();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
370 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
371 case UART_GNSS_WARMUP: if(time_elapsed_ms(warmupTick,HAL_GetTick()) > 1000)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
372 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
373 gnssState = UART_GNSS_LOADCONF_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
374 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
375 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
376 case UART_GNSS_LOADCONF_0: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_0);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
377 gnssState = UART_GNSS_LOADCONF_1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
378 rxState = GNSSRX_DETECT_ACK_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
379 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
380 case UART_GNSS_LOADCONF_1: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_1);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
381 gnssState = UART_GNSS_LOADCONF_2;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
382 rxState = GNSSRX_DETECT_ACK_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
383 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
384 case UART_GNSS_LOADCONF_2: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_2);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
385 gnssState = UART_GNSS_IDLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
386 rxState = GNSSRX_DETECT_ACK_0;
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_IDLE: UART6_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
389 gnssState = UART_GNSS_GET_PVT;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
390 rxState = GNSSRX_DETECT_HEADER_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 default:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
393 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
394 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
395 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
396
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
397 void UART6_Gnss_ProcessData(uint8_t data)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
398 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
399 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
400 switch(rxState)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
401 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
402 case GNSSRX_DETECT_ACK_0:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
403 case GNSSRX_DETECT_HEADER_0: if(data == 0xB5)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
404 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
405 writeIndex = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
406 memset(GNSS_Handle.uartWorkingBuffer,0, sizeof(GNSS_Handle.uartWorkingBuffer));
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
407 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
408 rxState++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
409 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
410 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
411 case GNSSRX_DETECT_ACK_1:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
412 case GNSSRX_DETECT_HEADER_1: if(data == 0x62)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
413 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
414 rxState++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
415 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
416 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
417 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
418 rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
419 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
420 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
421 case GNSSRX_DETECT_ACK_2: if(data == 0x05)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
422 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
423 rxState++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
424 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
425 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
426 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
427 rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
428 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
429 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
430 case GNSSRX_DETECT_ACK_3: if((data == 0x01) || (data == 0x00))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
431 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
432 GnssConnected = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
433 rxState = GNSSRX_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
434 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
435 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
436 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
437 rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
438 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
439 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
440 case GNSSRX_DETECT_HEADER_2: if(data == 0x01)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
441 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
442 rxState++;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
443 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
444 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
445 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
446 rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
447 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
448 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
449 case GNSSRX_DETECT_HEADER_3:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
450 switch(data)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
451 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
452 case 0x21: rxState = GNSSRX_READ_NAV_DATA;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
453 dataToRead = 20;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
454 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
455 case 0x07: rxState = GNSSRX_READ_PVT_DATA;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
456 dataToRead = 92;
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 0x02: rxState = GNSSRX_READ_POSLLH_DATA;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
459 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
460 default: rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
461 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
462 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
463 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
464 case GNSSRX_READ_NAV_DATA:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
465 case GNSSRX_READ_PVT_DATA:
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
466 case GNSSRX_READ_POSLLH_DATA: if(dataToRead > 0)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
467 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
468 dataToRead--;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
469 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
470 else
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
471 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
472 switch(rxState)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
473 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
474 case GNSSRX_READ_NAV_DATA: GNSS_ParseNavigatorData(&GNSS_Handle);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
475 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
476 case GNSSRX_READ_PVT_DATA: GNSS_ParsePVTData(&GNSS_Handle);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
477 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
478 case GNSSRX_READ_POSLLH_DATA: GNSS_ParsePOSLLHData(&GNSS_Handle);
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
479 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
480 default: rxState = GNSSRX_DETECT_HEADER_0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
481 break;
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 gnssState = UART_GNSS_IDLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
485 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
486 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
487 default: rxState = GNSSRX_READY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
488 break;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
489 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
490 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
491
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
492
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
493 void UART6_HandleUART()
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
494 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
495 static uint8_t retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
496 static uint32_t lastRequestTick = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
497 static uint32_t TriggerTick = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
498 static uint8_t timeToTrigger = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
499 uint32_t tick = HAL_GetTick();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
500
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
501 if(gnssState != UART_GNSS_INIT)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
502 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
503 UART6_ReadData();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
504 UART6_WriteData();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
505 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
506 if(gnssState == UART_GNSS_INIT)
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
507 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
508 lastRequestTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
509 TriggerTick = tick - 10; /* just to make sure control is triggered */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
510 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
511 retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
512 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
513 else if(((retryRequest == 0) /* timeout or error */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
514 && (((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
515 || (gnssState == UART_GNSS_ERROR))))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
516 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
517 /* The channel switch will cause the sensor to respond with an error message. */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
518 /* 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
519
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
520 TriggerTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
521 timeToTrigger = COMMAND_TX_DELAY;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
522 retryRequest = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
523 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
524
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
525 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
526 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
527 lastRequestTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
528 TriggerTick = tick;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
529 retryRequest = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
530 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
531
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
532 if((gnssState == UART_GNSS_GET_PVT)) /* timeout */
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
533 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
534 gnssState = UART_GNSS_IDLE;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
535 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
536 timeToTrigger = 1;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
537 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
538 if((timeToTrigger != 0) && (time_elapsed_ms(TriggerTick,tick) > timeToTrigger))
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
539 {
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
540 timeToTrigger = 0;
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
541 UART6_Gnss_Control();
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
542 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
543
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
544 }
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
545
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
546
7c996354b8ac Moved UART6 into a separate unit:
Ideenmodellierer
parents:
diff changeset
547 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/