|
1 |
| -/** |
2 |
| - ****************************************************************************** |
3 |
| - * @file uart_emul.h |
4 |
| - * @author WI6LABS |
5 |
| - * @version V1.0.0 |
6 |
| - * @date 01-August-2016 |
7 |
| - * @brief Adaptation from stm32f4xx_hal_uart_emul.h |
8 |
| - * Header file of UART Emulation HAL module. |
9 |
| - ****************************************************************************** |
10 |
| - * @attention |
11 |
| - * |
12 |
| - * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
13 |
| - * |
14 |
| - * Redistribution and use in source and binary forms, with or without modification, |
15 |
| - * are permitted provided that the following conditions are met: |
16 |
| - * 1. Redistributions of source code must retain the above copyright notice, |
17 |
| - * this list of conditions and the following disclaimer. |
18 |
| - * 2. Redistributions in binary form must reproduce the above copyright notice, |
19 |
| - * this list of conditions and the following disclaimer in the documentation |
20 |
| - * and/or other materials provided with the distribution. |
21 |
| - * 3. Neither the name of STMicroelectronics nor the names of its contributors |
22 |
| - * may be used to endorse or promote products derived from this software |
23 |
| - * without specific prior written permission. |
24 |
| - * |
25 |
| - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
26 |
| - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
27 |
| - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
28 |
| - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
29 |
| - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
30 |
| - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
31 |
| - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
32 |
| - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
33 |
| - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
34 |
| - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
35 |
| - * |
36 |
| - ****************************************************************************** |
37 |
| - */ |
38 |
| - |
39 |
| -/* Define to prevent recursive inclusion -------------------------------------*/ |
40 |
| -#ifndef __UART_EMUL_H |
41 |
| -#define __UART_EMUL_H |
42 |
| - |
43 |
| -#ifdef __cplusplus |
44 |
| - extern "C" { |
45 |
| -#endif |
46 |
| - |
47 |
| -/* Includes ------------------------------------------------------------------*/ |
48 |
| -#include "stm32_def.h" |
49 |
| - |
50 |
| -/** @addtogroup STM32F4xx_HAL_Driver |
51 |
| - * @{ |
52 |
| - */ |
53 |
| - |
54 |
| -/** @addtogroup UART_EMUL_HAL_Driver |
55 |
| - * @{ |
56 |
| - */ |
57 |
| - |
58 |
| -/* Exported types ------------------------------------------------------------*/ |
59 |
| - |
60 |
| -/** |
61 |
| - * @brief UART Emulation Init Structure definition |
62 |
| - */ |
63 |
| -typedef struct |
64 |
| -{ |
65 |
| - uint8_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled. |
66 |
| - This parameter can be a value of @ref UART_Emul_Mode */ |
67 |
| - |
68 |
| - uint32_t BaudRate; /*!< This member configures the UART communication baud rate.*/ |
69 |
| - |
70 |
| - |
71 |
| - uint8_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. |
72 |
| - This parameter can be a value of @ref UART_Emul_Word_Length */ |
73 |
| - |
74 |
| - uint8_t StopBits; /*!< Specifies the number of stop bits transmitted. |
75 |
| - This parameter can be a value of @ref UART_Emul_Stop_Bits */ |
76 |
| - |
77 |
| - |
78 |
| - uint8_t Parity; /*!< Specifies the parity mode. |
79 |
| - This parameter can be a value of @ref UART_Emul_Parity |
80 |
| - @note When parity is enabled, the computed parity is inserted |
81 |
| - at the MSB position of the transmitted data*/ |
82 |
| - |
83 |
| - uint16_t RxPinNumber; /*!< Specifies the number of Receiver Pin. |
84 |
| - This parameter can be a value of @ref GPIO_pins_define */ |
85 |
| - |
86 |
| - uint16_t TxPinNumber; /*!< Specifies the number of Transmitter Pin. |
87 |
| - his parameter can be a value of @ref GPIO_pins_define */ |
88 |
| -}UART_Emul_InitTypeDef; |
89 |
| - |
90 |
| -/** |
91 |
| - * @brief HAL UART Emulation State structures definition |
92 |
| - */ |
93 |
| -typedef enum |
94 |
| -{ |
95 |
| - HAL_UART_EMUL_STATE_RESET = 0x00, /*!< Peripheral is not yet Initialized */ |
96 |
| - HAL_UART_EMUL_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */ |
97 |
| - HAL_UART_EMUL_STATE_BUSY = 0x02, /*!< An internal process is ongoing */ |
98 |
| - HAL_UART_EMUL_STATE_BUSY_TX = 0x04, /*!< Data Transmission process is ongoing */ |
99 |
| - HAL_UART_EMUL_STATE_BUSY_RX = 0x08, /*!< Data Reception process is ongoing */ |
100 |
| - HAL_UART_EMUL_STATE_BUSY_TX_RX = 0x10, /*!< Data Transmission and Reception process is ongoing */ |
101 |
| - HAL_UART_EMUL_STATE_ERROR = 0x20 /*!< Error */ |
102 |
| - |
103 |
| -}HAL_UART_Emul_StateTypeDef; |
104 |
| - |
105 |
| -/** |
106 |
| - * @brief HAL UART Emulation Error Code structure definition |
107 |
| - */ |
108 |
| -typedef enum |
109 |
| -{ |
110 |
| - HAL_UART_EMUL_ERROR_NONE = 0x00, /*!< No error */ |
111 |
| - HAL_UART_EMUL_ERROR_FE = 0x01, /*!< frame error */ |
112 |
| - HAL_UART_EMUL_ERROR_RE = 0x02, /*!< receiver error */ |
113 |
| - HAL_UART_EMUL_ERROR_PE = 0x04 /*!< transfer error */ |
114 |
| -}HAL_UART_Emul_ErrorTypeDef; |
115 |
| - |
116 |
| -/** |
117 |
| - * @brief Universal Asynchronous Receiver Transmitter |
118 |
| - */ |
119 |
| - |
120 |
| -typedef struct |
121 |
| -{ |
122 |
| - __IO uint8_t SR; /*!< UART Emulation Status register software */ |
123 |
| - |
124 |
| -} UART_Emul_TypeDef; |
125 |
| - |
126 |
| -/** |
127 |
| - * @brief UART Emulation handle Structure definition |
128 |
| - */ |
129 |
| -typedef struct |
130 |
| -{ |
131 |
| - UART_Emul_TypeDef Instance; /* Instance for UART Emulation register */ |
132 |
| - |
133 |
| - UART_Emul_InitTypeDef Init; /* UART Emulation communication parameters */ |
134 |
| - |
135 |
| - uint8_t *pTxBuffPtr; /* Pointer to UART Emulation Tx transfer Buffer */ |
136 |
| - |
137 |
| - uint16_t TxXferSize; /* UART Emulation Tx Transfer size */ |
138 |
| - |
139 |
| - uint16_t TxXferCount; /* UART Emulation Tx Transfer Counter */ |
140 |
| - |
141 |
| - uint8_t *pRxBuffPtr; /* Pointer to UART Emulation Rx transfer Buffer */ |
142 |
| - |
143 |
| - uint16_t RxXferSize; /* UART Emulation Rx Transfer size */ |
144 |
| - |
145 |
| - uint16_t RxXferCount; /* UART Emulation Rx Transfer Counter */ |
146 |
| - |
147 |
| -#ifdef STM32F0xx |
148 |
| - uint16_t TxXferByte; |
149 |
| - |
150 |
| - uint8_t TxBitSize; |
151 |
| - |
152 |
| - uint8_t TxBitCount; |
153 |
| - |
154 |
| - uint16_t RxXferByte; |
155 |
| - |
156 |
| - uint8_t RxBitSize; |
157 |
| - |
158 |
| - uint8_t RxBitCount; |
159 |
| -#endif |
160 |
| - GPIO_TypeDef *RxPortName; /* UART Emulation Rx port name */ |
161 |
| - |
162 |
| - GPIO_TypeDef *TxPortName; /* UART Emulation Tx port name */ |
163 |
| - |
164 |
| - __IO HAL_UART_Emul_StateTypeDef State; /* UART Emulation communication state */ |
165 |
| - |
166 |
| - __IO HAL_UART_Emul_ErrorTypeDef ErrorCode; /* UART Emulation Error code */ |
167 |
| - |
168 |
| -}UART_Emul_HandleTypeDef; |
169 |
| - |
170 |
| - |
171 |
| - |
172 |
| -/* Exported constants --------------------------------------------------------*/ |
173 |
| -/** @defgroup UART_Emulation_Exported_Constants |
174 |
| - * @{ |
175 |
| - */ |
176 |
| - |
177 |
| -/** @defgroup UART_Emul_Word_Length |
178 |
| - * @{ |
179 |
| - */ |
180 |
| - |
181 |
| -#define UART_EMUL_WORDLENGTH_5B ((uint8_t)0x05) |
182 |
| -#define UART_EMUL_WORDLENGTH_6B ((uint8_t)0x06) |
183 |
| -#define UART_EMUL_WORDLENGTH_7B ((uint8_t)0x07) |
184 |
| -#define UART_EMUL_WORDLENGTH_8B ((uint8_t)0x08) |
185 |
| -#define UART_EMUL_WORDLENGTH_9B ((uint8_t)0x09) |
186 |
| -#define IS_UART_EMUL_WORD_LENGTH(LENGTH) (((LENGTH) == UART_EMUL_WORDLENGTH_5B)||\ |
187 |
| - ((LENGTH) == UART_EMUL_WORDLENGTH_6B)||\ |
188 |
| - ((LENGTH) == UART_EMUL_WORDLENGTH_7B)||\ |
189 |
| - ((LENGTH) == UART_EMUL_WORDLENGTH_8B)||\ |
190 |
| - ((LENGTH) == UART_EMUL_WORDLENGTH_9B)) |
191 |
| -/** |
192 |
| - * @} |
193 |
| - */ |
194 |
| - |
195 |
| -/** @defgroup UART_Emul_Stop_Bits |
196 |
| - * @{ |
197 |
| - */ |
198 |
| -#define UART_EMUL_STOPBITS_1 ((uint8_t)0x01) |
199 |
| -#define UART_EMUL_STOPBITS_2 ((uint8_t)0x02) |
200 |
| -#define IS_UART_EMUL_STOPBITS(STOPBITS) (((STOPBITS) == UART_EMUL_STOPBITS_1)||\ |
201 |
| - ((STOPBITS) == UART_EMUL_STOPBITS_2)) |
202 |
| - |
203 |
| -/** |
204 |
| - * @} |
205 |
| - */ |
206 |
| - |
207 |
| -/** @defgroup UART_Emul_Parity |
208 |
| - * @{ |
209 |
| - */ |
210 |
| -#define UART_EMUL_PARITY_NONE ((uint8_t)0x00) |
211 |
| -#define UART_EMUL_PARITY_EVEN ((uint8_t)0x01) |
212 |
| -#define UART_EMUL_PARITY_ODD ((uint8_t)0x02) |
213 |
| -#define IS_UART_EMUL_PARITY(PARITY) (((PARITY) == UART_EMUL_PARITY_NONE) || \ |
214 |
| - ((PARITY) == UART_EMUL_PARITY_EVEN) || \ |
215 |
| - ((PARITY) == UART_EMUL_PARITY_ODD)) |
216 |
| -/** |
217 |
| - * @} |
218 |
| - */ |
219 |
| - |
220 |
| -/** @defgroup UART_Emul_Mode |
221 |
| - * @{ |
222 |
| - */ |
223 |
| -#define UART_EMUL_MODE_RX ((uint8_t)0x01) |
224 |
| -#define UART_EMUL_MODE_TX ((uint8_t)0x02) |
225 |
| -#define UART_EMUL_MODE_TX_RX ((uint8_t)0x03) |
226 |
| -#define IS_UART_EMUL_MODE(MODE) (((MODE) == UART_EMUL_MODE_RX) || \ |
227 |
| - ((MODE) == UART_EMUL_MODE_TX ) || \ |
228 |
| - ((MODE) == UART_EMUL_MODE_TX_RX )) |
229 |
| -/** |
230 |
| - * @} |
231 |
| - */ |
232 |
| - |
233 |
| -/** @defgroup UART_Emul_Flags |
234 |
| - * Elements values convention: 0xXX |
235 |
| - * - 0xXX : Flag mask in the SR register software |
236 |
| - * @{ |
237 |
| - */ |
238 |
| -#define UART_EMUL_FLAG_RC ((uint8_t)0x01) |
239 |
| -#define UART_EMUL_FLAG_TC ((uint8_t)0x02) |
240 |
| -#define UART_EMUL_FLAG_FE ((uint8_t)0x04) |
241 |
| -#define UART_EMUL_FLAG_PE ((uint8_t)0x08) |
242 |
| - |
243 |
| -/** |
244 |
| - * @} |
245 |
| - */ |
246 |
| - |
247 |
| -/* Exported constants --------------------------------------------------------*/ |
248 |
| - |
249 |
| -/** @defgroup Baudrate_Constants |
250 |
| - * @{ |
251 |
| - */ |
252 |
| - |
253 |
| -/** |
254 |
| - * |
255 |
| - */ |
256 |
| -#define BAUDRATE_4800 ((uint32_t)0x12C0) /* Baudrate Selection 4800 */ |
257 |
| -#define BAUDRATE_9600 ((uint32_t)0x2580) /* Baudrate Selection 9600 */ |
258 |
| -#define BAUDRATE_14400 ((uint32_t)0x3840) /* Baudrate Selection 14400 */ |
259 |
| -#define BAUDRATE_19200 ((uint32_t)0x4b00) /* Baudrate Selection 19200 */ |
260 |
| -#define BAUDRATE_38400 ((uint32_t)0x9600) /* Baudrate Selection 38400 */ |
261 |
| -#define BAUDRATE_57600 ((uint32_t)0xE100) /* Baudrate Selection 57600 */ |
262 |
| -#define BAUDRATE_115200 ((uint32_t)0x1C200) /* Baudrate Selection 115200 */ |
263 |
| -#define IS_UART_EMUL_BAUDRATE(BaudRate) (((BaudRate) == BAUDRATE_4800 ) || \ |
264 |
| - ((BaudRate) == BAUDRATE_9600 ) || \ |
265 |
| - ((BaudRate) == BAUDRATE_14400 ) || \ |
266 |
| - ((BaudRate) == BAUDRATE_19200 ) || \ |
267 |
| - ((BaudRate) == BAUDRATE_38400 ) || \ |
268 |
| - ((BaudRate) == BAUDRATE_57600 ) || \ |
269 |
| - ((BaudRate) == BAUDRATE_115200)) |
270 |
| -/** |
271 |
| - * @} |
272 |
| - */ |
273 |
| - |
274 |
| - /** @defgroup UART Emulation constant |
275 |
| - * @{ |
276 |
| - */ |
277 |
| - |
278 |
| -#define FIRST_BYTE ((uint8_t)0x01) |
279 |
| -#define BitMask ((uint8_t)0x01) |
280 |
| -#define RX_BUFFER_SIZE ((uint8_t)0x0C) |
281 |
| -#define TX_BUFFER_SIZE ((uint8_t)0x0C) |
282 |
| - |
283 |
| -#ifndef STM32F0xx |
284 |
| -/* Definition Handler for UART Emulation receive mode */ |
285 |
| -#ifdef STM32F3xx |
286 |
| -#define UART_EMUL_TX_DMA_IRQHandler DMA1_Channel2_IRQHandler |
287 |
| -#define UART_EMUL_RX_DMA_IRQHandler DMA1_Channel3_IRQHandler |
288 |
| - |
289 |
| -#define UART_EMUL_TX_DMA_IRQn DMA1_Channel2_IRQn |
290 |
| -#define UART_EMUL_RX_DMA_IRQn DMA1_Channel3_IRQn |
291 |
| -#else |
292 |
| -#define UART_EMUL_TX_DMA_IRQHandler DMA2_Stream1_IRQHandler |
293 |
| -#define UART_EMUL_RX_DMA_IRQHandler DMA2_Stream2_IRQHandler |
294 |
| - |
295 |
| -#define UART_EMUL_TX_DMA_IRQn DMA2_Stream1_IRQn |
296 |
| -#define UART_EMUL_RX_DMA_IRQn DMA2_Stream2_IRQn |
297 |
| -#endif |
298 |
| - |
299 |
| -/* Defenition of UART Emulation timer */ |
300 |
| -#define UART_EMUL_TX_TIMER_INSTANCE TIM1 |
301 |
| -#define UART_EMUL_RX_TIMER_INSTANCE TIM1 |
302 |
| - |
303 |
| -#define TIM_DMA_Handle_Tx TIM_DMA_ID_CC1 |
304 |
| -#define TIM_DMA_Handle_Rx TIM_DMA_ID_CC2 |
305 |
| - |
306 |
| -#define TIM_Channel_Tx TIM_CHANNEL_1 |
307 |
| -#define TIM_Channel_Rx TIM_CHANNEL_2 |
308 |
| - |
309 |
| -#define TIM_DMA_source_Tx TIM_DMA_CC1 |
310 |
| -#define TIM_DMA_source_Rx TIM_DMA_CC2 |
311 |
| - |
312 |
| -#define DMA_Channel_Tx DMA_CHANNEL_6 |
313 |
| -#define DMA_Channel_Rx DMA_CHANNEL_6 |
314 |
| - |
315 |
| -#define DMA_Stream_Tx DMA2_Stream1 |
316 |
| -#define DMA_Stream_Rx DMA2_Stream2 |
317 |
| -#endif |
318 |
| -/* Exported macro ------------------------------------------------------------*/ |
319 |
| - |
320 |
| -/** @brief Checks whether the specified UART Emulation flag is set or not. |
321 |
| - * @param __HANDLE__: specifies the UART Emulation Handle. |
322 |
| - * @param __FLAG__: specifies the flag to check. |
323 |
| - * This parameter can be one of the following values: |
324 |
| - * @arg UART_EMUL_FLAG_RC: Receiver Complete flag |
325 |
| - * @arg UART_EMUL_FLAG_TC: Transmission Complete flag |
326 |
| - * @arg UART_EMUL_FLAG_FE: Framing Error flag |
327 |
| - * @arg UART_EMUL_FLAG_PE: Parity Error flag |
328 |
| - * @retval The new state of __FLAG__ (TRUE or FALSE). |
329 |
| - */ |
330 |
| -#define __HAL_UART_EMUL_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance.SR & (__FLAG__)) == (__FLAG__)) |
331 |
| - |
332 |
| -/** @brief Clears the specified UART Emulation flag. |
333 |
| - * @param __HANDLE__: specifies the UART Emulation Handle. |
334 |
| - * |
335 |
| - * @param __FLAG__: specifies the flag to check. |
336 |
| - * This parameter can be any combination of the following values: |
337 |
| - * @arg UART_EMUL_FLAG_RC : Receiver Complet. |
338 |
| - * @arg UART_EMUL_FLAG_TC : Transmitter Complet. |
339 |
| - * @arg UART_EMUL_FLAG_FE : Frame Error. |
340 |
| - * @arg UART_EMUL_FLAG_PE : Parity Error. |
341 |
| - * |
342 |
| - * @retval None |
343 |
| - */ |
344 |
| -#define __HAL_UART_EMUL_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance.SR &= ~(__FLAG__)) |
345 |
| - |
346 |
| -/** @brief Set the specified UART Emulation flag. |
347 |
| - * @param __HANDLE__: specifies the UART Emulation Handle. |
348 |
| - * |
349 |
| - * @param __FLAG__: specifies the flag to check. |
350 |
| - * This parameter can be any combination of the following values: |
351 |
| - * @arg UART_EMUL_FLAG_RC : Receiver Complete. |
352 |
| - * @arg UART_EMUL_FLAG_TC : Transmitter Complete. |
353 |
| - * @arg UART_EMUL_FLAG_FE : Frame Error. |
354 |
| - * @arg UART_EMUL_FLAG_PE : Parity Error. |
355 |
| - * |
356 |
| - * @retval None |
357 |
| - */ |
358 |
| -#define __HAL_UART_EMUL_SET_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance.SR |= (__FLAG__)) |
359 |
| - |
360 |
| -/** @brief Determinate the length for the frame . |
361 |
| - * @param __HANDLE__: specifies the UART Emulation Handle. |
362 |
| - * @param None |
363 |
| - * @retval None |
364 |
| - */ |
365 |
| -#define __HAL_UART_EMUL_FRAME_LENGTH(__HANDLE__) (uint16_t)((__HANDLE__)->Init.WordLength + (__HANDLE__)->Init.StopBits + 1) |
366 |
| - |
367 |
| -#ifdef STM32F0xx |
368 |
| -#define MASK_STOP_BIT(__HANDLE__) ((uint16_t)~(0x0003 << (__HAL_UART_EMUL_FRAME_LENGTH(__HANDLE__) - (__HANDLE__)->Init.StopBits))) |
369 |
| - |
370 |
| -#define __UART_EMUL_TX_TIMER TIM15_E |
371 |
| -#define __UART_EMUL_RX_TIMER TIM17_E |
372 |
| -#else |
373 |
| -/** @brief Enable the clock for UART Emulation. |
374 |
| - * clock in the peripherique used in this driver Timer and DMA |
375 |
| - * @param None |
376 |
| - * @retval None |
377 |
| - */ |
378 |
| -#ifdef STM32F3xx |
379 |
| -#define __UART_EMUL_CLK_ENABLE() __TIM1_CLK_ENABLE();\ |
380 |
| - __DMA1_CLK_ENABLE(); |
381 |
| - |
382 |
| -#else |
383 |
| -#define __UART_EMUL_CLK_ENABLE() __TIM1_CLK_ENABLE();\ |
384 |
| - __HAL_RCC_DMA2_CLK_ENABLE(); |
385 |
| -#endif |
386 |
| -/** @brief Disable the clock for UART Emulation. |
387 |
| - * clock in the peripherique used in this emulation Timer and DMA |
388 |
| - * @param None |
389 |
| - * @retval None |
390 |
| - */ |
391 |
| -#ifdef STM32F3xx |
392 |
| -#define __UART_EMUL_CLK_DISABLE() __TIM1_CLK_DISABLE();\ |
393 |
| - __DMA1_CLK_DISABLE(); |
394 |
| - |
395 |
| -#else |
396 |
| -#define __UART_EMUL_CLK_DISABLE() __TIM1_CLK_DISABLE();\ |
397 |
| - __HAL_RCC_DMA2_CLK_DISABLE(); |
398 |
| -#endif |
399 |
| -#endif |
400 |
| - |
401 |
| -/* Exported functions --------------------------------------------------------*/ |
402 |
| -/* Initialization/de-initialization functions **********************************/ |
403 |
| -HAL_StatusTypeDef HAL_UART_Emul_Init(UART_Emul_HandleTypeDef *huart); |
404 |
| -HAL_StatusTypeDef HAL_UART_Emul_DeInit(UART_Emul_HandleTypeDef *huart); |
405 |
| -void HAL_UART_Emul_MspInit(UART_Emul_HandleTypeDef *huart); |
406 |
| -void HAL_UART_Emul_MspDeInit(UART_Emul_HandleTypeDef *huart); |
407 |
| - |
408 |
| -/* IO operation functions *******************************************************/ |
409 |
| -#ifdef STM32F0xx |
410 |
| -HAL_StatusTypeDef HAL_UART_Emul_Transmit(UART_Emul_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
411 |
| -HAL_StatusTypeDef HAL_UART_Emul_Receive(UART_Emul_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
412 |
| -#else |
413 |
| -HAL_StatusTypeDef HAL_UART_Emul_Transmit_DMA(UART_Emul_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
414 |
| -HAL_StatusTypeDef HAL_UART_Emul_Receive_DMA(UART_Emul_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
415 |
| -#endif |
416 |
| -void HAL_UART_Emul_IRQHandler(UART_Emul_HandleTypeDef *huart); |
417 |
| -void HAL_UART_Emul_RxCpltCallback(UART_Emul_HandleTypeDef *huart); |
418 |
| -void HAL_UART_Emul_TxCpltCallback(UART_Emul_HandleTypeDef *huart); |
419 |
| -void HAL_UART_Emul_ErrorCallback(UART_Emul_HandleTypeDef *huart); |
420 |
| -void UART_EMUL_EXTI_RX(void); |
421 |
| -#ifdef STM32F0xx |
422 |
| -typedef enum { |
423 |
| - TIM1_E = 0, |
424 |
| - TIM2_E, |
425 |
| - TIM3_E, |
426 |
| - TIM6_E, |
427 |
| - TIM7_E, |
428 |
| - TIM14_E, |
429 |
| - TIM15_E, |
430 |
| - TIM16_E, |
431 |
| - TIM17_E, |
432 |
| - NB_TIMER_MANAGED |
433 |
| -} timer_id_e; |
434 |
| -#endif |
435 |
| -#ifdef STM32F3xx |
436 |
| -typedef enum { |
437 |
| - TIM1_E = 0, |
438 |
| - TIM2_E, |
439 |
| - TIM3_E, |
440 |
| - TIM4_E, |
441 |
| - TIM6_E, |
442 |
| - TIM7_E, |
443 |
| - TIM8_E, |
444 |
| - TIM15_E, |
445 |
| - TIM16_E, |
446 |
| - TIM17_E, |
447 |
| - TIM20_E, |
448 |
| - NB_TIMER_MANAGED |
449 |
| -} timer_id_e; |
450 |
| -#endif |
451 |
| -/* Peripheral State functions **************************************************/ |
452 |
| -HAL_UART_Emul_StateTypeDef HAL_UART_Emul_GetState(UART_Emul_HandleTypeDef *huart); |
453 |
| -uint32_t HAL_UART_Emul_GetError(UART_Emul_HandleTypeDef *huart); |
454 |
| -/** |
455 |
| - * @} |
456 |
| - */ |
457 |
| - |
458 |
| -/** |
459 |
| - * @} |
460 |
| - */ |
461 |
| - |
462 |
| -#ifdef __cplusplus |
463 |
| -} |
464 |
| -#endif |
465 |
| - |
466 |
| -#endif /* __UART_EMUL_H */ |
467 |
| - |
468 |
| -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * @file uart_emul.h |
| 4 | + * @author WI6LABS |
| 5 | + * @version V1.0.0 |
| 6 | + * @date 25-April-2017 |
| 7 | + * @brief Header for uart emulation module |
| 8 | + ****************************************************************************** |
| 9 | + * @attention |
| 10 | + * |
| 11 | + * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
| 12 | + * |
| 13 | + * Redistribution and use in source and binary forms, with or without modification, |
| 14 | + * are permitted provided that the following conditions are met: |
| 15 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 16 | + * this list of conditions and the following disclaimer. |
| 17 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 18 | + * this list of conditions and the following disclaimer in the documentation |
| 19 | + * and/or other materials provided with the distribution. |
| 20 | + * 3. Neither the name of STMicroelectronics nor the names of its contributors |
| 21 | + * may be used to endorse or promote products derived from this software |
| 22 | + * without specific prior written permission. |
| 23 | + * |
| 24 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 25 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 27 | + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 28 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 29 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 30 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 31 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 32 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 33 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 | + * |
| 35 | + ****************************************************************************** |
| 36 | + */ |
| 37 | + |
| 38 | +/* Define to prevent recursive inclusion -------------------------------------*/ |
| 39 | +#ifndef __UART_EMUL_H |
| 40 | +#define __UART_EMUL_H |
| 41 | + |
| 42 | +/* Includes ------------------------------------------------------------------*/ |
| 43 | +#include "stm32_def.h" |
| 44 | +#include "timer.h" |
| 45 | + |
| 46 | +#ifdef __cplusplus |
| 47 | + extern "C" { |
| 48 | +#endif |
| 49 | + |
| 50 | +/* Exported types ------------------------------------------------------------*/ |
| 51 | +typedef enum { |
| 52 | + UART1_EMUL_E = 0, |
| 53 | + NB_UART_EMUL_MANAGED |
| 54 | +} uart_emul_id_e; |
| 55 | + |
| 56 | +typedef enum { |
| 57 | + NATIVE_UART_E = 0, |
| 58 | + EMULATED_UART_E = 1, |
| 59 | + NB_UART_OPTION |
| 60 | +} uart_option_e; |
| 61 | + |
| 62 | +/* Exported constants --------------------------------------------------------*/ |
| 63 | +#define UART_RCV_SIZE 128 |
| 64 | + |
| 65 | +/* Exported macro ------------------------------------------------------------*/ |
| 66 | +/* Exported functions ------------------------------------------------------- */ |
| 67 | +void uart_emul_init(uart_emul_id_e uart_id, uint32_t baudRate); |
| 68 | +void uart_emul_deinit(uart_emul_id_e uart_id); |
| 69 | +int uart_emul_available(uart_emul_id_e uart_id); |
| 70 | +int8_t uart_emul_read(uart_emul_id_e uart_id); |
| 71 | +size_t uart_emul_write(uart_emul_id_e uart_id, uint8_t data); |
| 72 | +int8_t uart_emul_peek(uart_emul_id_e uart_id); |
| 73 | +void uart_emul_flush(uart_emul_id_e uart_id); |
| 74 | +void uart_emul_attached_handler(stimer_t *obj, void (*irqHandle)(void)); |
| 75 | + |
| 76 | +#ifdef __cplusplus |
| 77 | +} |
| 78 | +#endif |
| 79 | + |
| 80 | +#endif /* __UART_EMUL_H */ |
| 81 | + |
| 82 | +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
0 commit comments