VSF Documented
usart.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __HAL_DRIVER_GIGADEVICE_GD32H7XX_USART_H__
19#define __HAL_DRIVER_GIGADEVICE_GD32H7XX_USART_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_USART == ENABLED
26
27#include "../../__device.h"
28
29/*\note Refer to template/README.md for usage cases.
30 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
31 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
32 * For emulated drivers, **** No reimplementation ****.
33 */
34
35/*\note Includes CAN ONLY be put here. */
36/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
37
38// IPCore
39#if defined(__VSF_HAL_HW_USART_CLASS_IMPLEMENT)
40# define __VSF_CLASS_IMPLEMENT__
41#elif defined(__VSF_HAL_HW_USART_CLASS_INHERIT__)
42# define __VSF_CLASS_INHERIT__
43#endif
44
45#include "utilities/ooc_class.h"
46// IPCore end
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52/*============================ MACROS ========================================*/
53
54/*\note VSF_HW_USART_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
55 * while VSF_HW_USART_CFG_MULTI_CLASS should be in usart.c.
56 */
57
58// IPCore
59#ifndef VSF_HW_USART_CFG_MULTI_CLASS
60# define VSF_HW_USART_CFG_MULTI_CLASS VSF_USART_CFG_MULTI_CLASS
61#endif
62// IPCore end
63
64// HW
65/*\note hw USART driver can reimplement vsf_usart_mode_t/vsf_usart_irq_mask_t/vsf_usart_status_t.
66 * To enable reimplementation, please enable macro below:
67 * VSF_USART_CFG_REIMPLEMENT_TYPE_MODE for vsf_usart_mode_t
68 * VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS for vsf_usart_status_t
69 * VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_usart_irq_mask_t
70 * VSF_USART_CFG_REIMPLEMENT_TYPE_CMD for vsf_usart_cmd_t
71 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
72 * *** DO NOT reimplement these in emulated drivers. ***
73 */
74
75#define VSF_USART_CFG_REIMPLEMENT_TYPE_MODE ENABLED
76#define VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
77#define VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
78#define VSF_USART_CFG_REIMPLEMENT_TYPE_CMD ENABLED
79// HW end
80
81// TODO: add comments about fifo2req
82
83/*============================ TYPES =========================================*/
84
85// HW/IPCore, not for emulated drivers
86typedef enum vsf_usart_mode_t {
87 // 0..1: STB(13:12) in USART_CTL1, shift right by 12 to avoid conflict with BIT_LENGTH
88 VSF_USART_0_5_STOPBIT = (1 << 12) >> 12,
89 VSF_USART_1_STOPBIT = (0 << 12) >> 12,
90 VSF_USART_1_5_STOPBIT = (3 << 12) >> 12,
91 VSF_USART_2_STOPBIT = (2 << 12) >> 12,
92
93 // 2..3: TEN(3)/REN(2) in USART_CTL0
98
99 // 4..5: CTSEN(9)/RTSEN(8) in USART_CTL2, shift right by 4 to void conflict with PARITY
101 VSF_USART_RTS_HWCONTROL = (1 << 8) >> 4,
102 VSF_USART_CTS_HWCONTROL = (1 << 9) >> 4,
105
106 // 6: HDEN(3) in USART_CTL2, shift left by 3
109
110 // 9..10: PCEN(10)/PM(9) in USART_CTL0
112 VSF_USART_ODD_PARITY = (1 << 10) | (1 << 9),
114
115 // 23: CKEN(11) in USART_CTL1, shift left by 12
118 // 22: CPL(10) in USART_CTL1, shift left by 12
121 // 21: CPH(9) in USART_CTL1, shift left by 12
124 // 20: CLEN(8) in USART_CTL1, shift left by 12
127#define VSF_USART_SYNC_CLOCK_LAST_BIT_ENABLE VSF_USART_SYNC_CLOCK_LAST_BIT_ENABLE
128#define VSF_USART_SYNC_CLOCK_LAST_BIT_DISABLE VSF_USART_SYNC_CLOCK_LAST_BIT_DISABLE
129#define VSF_USART_SYNC_CLOCK_LAST_BIT_MASK VSF_USART_SYNC_CLOCK_LAST_BIT_ENABLE | VSF_USART_SYNC_CLOCK_LAST_BIT_DISABLE
130
131 // 12&28: WL1(28):WL0(12) in USART_CTL0
132 VSF_USART_10_BIT_LENGTH = (1 << 12) | (1 << 28),
136
137 // more vendor specified modes can be added here
138
139 // 13: MEN(13) in USART_CTL0
140 VSF_USART_MUTE = (1 << 13),
141 // 15: STRP(15) in USART_CTL1
142 VSF_USART_SWAP = (1 << 15),
143 // 16..17: TINV(17)/RINV(16) in USART_CTL1
144 VSF_USART_TX_INV = (1 << 17),
145 VSF_USART_RX_INV = (1 << 16),
146 // 18: OVER8(15) in USART_CR1
150
151
180
181 // not supported, allocate unused bits
182 // 6..8
187
191
195
201
203 // usart fifo interrupt
204 // 5: RFNEIE(5) in USART_CTL0
206 // 7: TFNFIE(7) in USART_CTL0
208 // 26: RTIE(26) in USART_CTL0
210
211 // 10: CTSIE(10) in USART_CTL2
213
214 // usart request interrupt
215 // TODO: add DMA support
218
219 // usart error interrupt
220 // 8: PERRIE(8) in USART_CTL0
222
223 // more vendor specified irq_masks can be added here
224
239
240 // not supported
241 // 0..2
245
250
251typedef enum vsf_usart_cmd_t {
253
256
259
260typedef struct vsf_usart_status_t {
261 union {
262 struct {
263 uint32_t parity_err : 1; // PERR(0) in USART_STAT
264 uint32_t frame_err : 1; // FERR(1) in USART_STAT
265 uint32_t noise_err : 1; // NERR(2) in USART_STAT
266 uint32_t overrun_err : 1; // ORERR(3) in USART_STAT
267 uint32_t idle : 1; // IDLEF(4) in USART_STAT
268 uint32_t rfne : 1; // RFNE(5) in USART_STAT
269 uint32_t trans_complete : 1; // TC(6) in USART_STAT
270 uint32_t tfnf : 1; // TFNF(7) in USART_STAT
271 uint32_t __dummy0 : 1; // LBDF(8) in USART_STAT
272 uint32_t cts_changed : 1; // CTSF(9) in USART_STAT
273 uint32_t cts_level : 1; // CTS(10) in USART_STAT
274 uint32_t rx_timeouted : 1; // RTF(11) in USART_STAT
276 uint32_t is_busy : 1; // BSY(16) in USART_STAT
278 };
280 };
282
283// HW/IPCore end
284
285/*============================ GLOBAL VARIABLES ==============================*/
286/*============================ PROTOTYPES ====================================*/
287
288// IPCore
289/*\note Extern APIs for ip core diriver.
290 * There is no requirement about how APIs of IPCore drivers should be implemented.
291 * Just consider the simplicity for actual peripheral drivers.
292 */
293// IPCore end
294
295#ifdef __cplusplus
296}
297#endif
298
299// IPCore
300#undef __VSF_HAL_HW_USART_CLASS_IMPLEMENT
301#undef __VSF_HAL_HW_USART_CLASS_INHERIT__
302// IPCore end
303
304#endif // VSF_HAL_USE_USART
305#endif // __HAL_DRIVER_GIGADEVICE_GD32H7XX_USART_H__
306/* EOF */
vsf_usart_mode_t
Definition uart.h:32
vsf_usart_irq_mask_t
Definition uart.h:105
@ VSF_USART_HALF_DUPLEX_DISABLE
Definition usart.h:108
@ VSF_USART_SYNC_CLOCK_ENABLE
Definition usart.h:116
@ __VSF_HW_USART_CTL0_MASK
Definition usart.h:152
@ VSF_USART_SYNC_CLOCK_PHASE_1_EDGE
Definition usart.h:122
@ VSF_USART_NO_PARITY
Definition usart.h:111
@ VSF_USART_10_BIT_LENGTH
Definition usart.h:132
@ VSF_USART_RTS_HWCONTROL
Definition usart.h:101
@ __VSF_HW_USART_CTL2_MASK
Definition usart.h:178
@ VSF_USART_RX_ENABLE
Definition usart.h:96
@ VSF_USART_MUTE
Definition usart.h:140
@ VSF_USART_TX_ENABLE
Definition usart.h:94
@ VSF_USART_SYNC_CLOCK_POLARITY_HIGH
Definition usart.h:120
@ __VSF_HW_USART_CTL1_MASK
Definition usart.h:163
@ VSF_USART_SYNC_CLOCK_POLARITY_LOW
Definition usart.h:119
@ VSF_USART_RX_DISABLE
Definition usart.h:97
@ VSF_USART_CTS_HWCONTROL
Definition usart.h:102
@ VSF_USART_SYNC_CLOCK_DISABLE
Definition usart.h:117
@ VSF_USART_RTS_CTS_HWCONTROL
Definition usart.h:103
@ VSF_USART_SYNC_CLOCK_PHASE_2_EDGE
Definition usart.h:123
@ VSF_USART_HALF_DUPLEX_ENABLE
Definition usart.h:107
@ VSF_USART_TX_DISABLE
Definition usart.h:95
@ VSF_USART_0_5_STOPBIT
Definition usart.h:88
@ VSF_USART_NO_HWCONTROL
Definition usart.h:100
@ VSF_USART_IRQ_MASK_CTS
Definition usart.h:212
@ __VSF_HW_USART_CTL0_IRQ_MASK
Definition usart.h:232
@ __VSF_HW_USART_CTL2_IRQ_MASK
Definition usart.h:238
#define VSF_USART_SYNC_CLOCK_LAST_BIT_ENABLE
Definition usart.h:127
#define VSF_USART_SYNC_CLOCK_LAST_BIT_DISABLE
Definition usart.h:128
vsf_usart_mode_t
Definition usart.h:42
@ VSF_USART_8_BIT_LENGTH
Definition usart.h:43
@ VSF_USART_EVEN_PARITY
Definition usart.h:62
@ VSF_USART_ODD_PARITY
Definition usart.h:61
@ VSF_USART_7_BIT_LENGTH
Definition usart.h:44
@ VSF_USART_1_STOPBIT
Definition usart.h:52
@ VSF_USART_2_STOPBIT
Definition usart.h:55
@ VSF_USART_5_BIT_LENGTH
Definition usart.h:46
@ VSF_USART_6_BIT_LENGTH
Definition usart.h:45
@ VSF_USART_1_5_STOPBIT
Definition usart.h:53
vsf_usart_irq_mask_t
Definition usart.h:86
@ VSF_USART_IRQ_MASK_TX_CPL
Definition usart.h:90
@ VSF_USART_IRQ_MASK_TX
Definition usart.h:88
@ VSF_USART_IRQ_MASK_RX
Definition usart.h:87
@ VSF_USART_IRQ_MASK_RX_TIMEOUT
Definition usart.h:98
@ VSF_USART_IRQ_MASK_RX_CPL
Definition usart.h:89
struct vsf_usart_status_t vsf_usart_status_t
@ VSF_USART_TX_FIFO_THRESH_HALF_FULL
Definition usart.h:166
@ VSF_USART_TX_INV
Definition usart.h:128
@ VSF_USART_RX_INV
Definition usart.h:129
@ VSF_USART_OVERSAMPLE_16
Definition usart.h:132
@ VSF_USART_SWAP
Definition usart.h:126
@ VSF_USART_RX_FIFO_THRESH_FULL
Definition usart.h:171
@ VSF_USART_RX_FIFO_THRESH_ONE
Definition usart.h:169
@ VSF_USART_FORCE_0_PARITY
Definition usart.h:162
@ __VSF_HW_USART_NOT_SUPPORT_MASK
Definition usart.h:173
@ VSF_USART_TX_FIFO_THRESH_ONE
Definition usart.h:165
@ VSF_USART_OVERSAMPLE_MASK
Definition usart.h:133
@ VSF_USART_9_BIT_LENGTH
Definition usart.h:119
@ VSF_USART_FORCE_1_PARITY
Definition usart.h:163
@ VSF_USART_RX_FIFO_THRESH_HALF_FULL
Definition usart.h:170
@ VSF_USART_TX_FIFO_THRESH_FULL
Definition usart.h:167
@ VSF_USART_OVERSAMPLE_8
Definition usart.h:131
vsf_usart_cmd_t
Definition usart.h:217
@ VSF_USART_CMD_SET_BREAK
Definition usart.h:220
@ __VSF_HW_USART_SUPPORT_CMD_MASK
Definition usart.h:223
@ VSF_USART_CMD_CLEAR_BREAK
Definition usart.h:221
@ VSF_USART_CMD_SEND_BREAK
Definition usart.h:218
@ VSF_USART_IRQ_MASK_OVERFLOW_ERR
Definition usart.h:210
@ VSF_USART_IRQ_MASK_BREAK_ERR
Definition usart.h:209
@ VSF_USART_IRQ_MASK_PARITY_ERR
Definition usart.h:195
@ __VSF_HW_USART_NOT_SUPPORT_IRQ_MASK
Definition usart.h:212
@ __VSF_HW_USART_IRQ_MASK
Definition usart.h:199
@ VSF_USART_IRQ_MASK_FRAME_ERR
Definition usart.h:208
unsigned uint32_t
Definition stdint.h:9
Definition uart.h:156
uint32_t tfnf
Definition usart.h:270
uint32_t noise_err
Definition usart.h:265
uint32_t __dummy2
Definition usart.h:277
uint32_t cts_changed
Definition usart.h:272
uint32_t trans_complete
Definition usart.h:269
uint32_t cts_level
Definition usart.h:273
uint32_t overrun_err
Definition usart.h:266
uint32_t idle
Definition usart.h:267
uint32_t __dummy0
Definition usart.h:271
uint32_t __dummy1
Definition usart.h:275
uint32_t is_busy
Definition usart.h:276
uint32_t value
Definition usart.h:279
uint32_t frame_err
Definition usart.h:264
uint32_t rx_timeouted
Definition usart.h:274
uint32_t rfne
Definition usart.h:268
uint32_t parity_err
Definition usart.h:263
vsf_usart_cmd_t
Predefined VSF USART command that can be reimplemented in specific hal drivers.
Definition vsf_template_usart.h:582