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_${SERIES/USART_IP}_USART_H__
19#define __HAL_DRIVER_${SERIES/USART_IP}_USART_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_USART == ENABLED
26
27// HW/IPCore
32// HW/IPCore end
33
34#include "../../__device.h"
35
36/*\note Refer to template/README.md for usage cases.
37 * For peripheral drivers, blackbox mode is recommended but not required, reimplementation part MUST be open.
38 * For IPCore drivers, class structure, MULTI_CLASS configuration, reimplementation and class APIs should be open to user.
39 * For emulated drivers, **** No reimplementation ****.
40 */
41
42/*\note Includes CAN ONLY be put here. */
43/*\note If current header is for a peripheral driver(hw driver), and inherit from an IPCore driver, include IPCore header here. */
44
45// IPCore
46#if defined(__VSF_HAL_${USART_IP}_USART_CLASS_IMPLEMENT)
47# define __VSF_CLASS_IMPLEMENT__
48#elif defined(__VSF_HAL_${USART_IP}_USART_CLASS_INHERIT__)
49# define __VSF_CLASS_INHERIT__
50#endif
51
52#include "utilities/ooc_class.h"
53// IPCore end
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
59/*============================ MACROS ========================================*/
60
61/*\note VSF_${USART_IP}_USART_CFG_MULTI_CLASS should be implemented for IP drives and open to user,
62 * while VSF_HW_USART_CFG_MULTI_CLASS should be in usart.c.
63 */
64
65// IPCore
66#ifndef VSF_${USART_IP}_USART_CFG_MULTI_CLASS
67# define VSF_${USART_IP}_USART_CFG_MULTI_CLASS VSF_USART_CFG_MULTI_CLASS
68#endif
69// IPCore end
70
71// HW
72/*\note hw USART driver can reimplement following types:
73 * To enable reimplementation, please enable macro below:
74 * VSF_USART_CFG_REIMPLEMENT_TYPE_MODE for vsf_usart_mode_t
75 * VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS for vsf_usart_status_t
76 * VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK for vsf_usart_irq_mask_t
77 * VSF_USART_CFG_REIMPLEMENT_TYPE_CTRL for vsf_usart_ctrl_t
78 * VSF_USART_CFG_REIMPLEMENT_TYPE_CFG for vsf_usart_cfg_t
79 * VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY for vsf_usart_capability_t
80 * Reimplementation is used for optimization hw/IPCore drivers, reimplement the bit mask according to hw registers.
81 * *** DO NOT reimplement these in emulated drivers. ***
82 */
83
84#define VSF_USART_CFG_REIMPLEMENT_TYPE_MODE ENABLED
85#define VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
86#define VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
87#define VSF_USART_CFG_REIMPLEMENT_TYPE_CTRL ENABLED
88#define VSF_USART_CFG_REIMPLEMENT_TYPE_CFG ENABLED
89#define VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY ENABLED
90// HW end
91
92// TODO: add comments about fifo2req
93
94/*============================ TYPES =========================================*/
95
96// IPCore
97vsf_class(vsf_${usart_ip}_usart_t) {
98#if VSF_${USART_IP}_CFG_MULTI_CLASS == ENABLED
99 public_member(
100 vsf_usart_t vsf_usart;
101 )
102#endif
103
104/*\note You can add more member in vsf_${usart_ip}_usart_t instance.
105 * For members accessible from child, put in protected_member.
106 * Else, put in private_member.
107 */
108
109 protected_member(
110 vsf_${usart_ip}_iwc_reg_t *reg;
113};
114// IPCore end
115
116// HW/IPCore, not for emulated drivers
117#if VSF_USART_CFG_REIMPLEMENT_TYPE_MODE == ENABLED
118typedef enum vsf_usart_mode_t {
119 VSF_USART_NO_PARITY = (0x0ul << 0),
120 VSF_USART_EVEN_PARITY = (0x1ul << 0),
121 VSF_USART_ODD_PARITY = (0x2ul << 0),
124
125 VSF_USART_1_STOPBIT = (0x0ul << 3),
126 VSF_USART_1_5_STOPBIT = (0x1ul << 3),
127 VSF_USART_0_5_STOPBIT = (0x2ul << 3),
128 VSF_USART_2_STOPBIT = (0x3ul << 3),
129
136
141
142 VSF_USART_TX_ENABLE = (0x0ul << 9),
143 VSF_USART_TX_DISABLE = (0x1ul << 9),
144
145 VSF_USART_RX_ENABLE = (0x0ul << 10),
146 VSF_USART_RX_DISABLE = (0x1ul << 10),
147
150
153
156 = (0x1ul << 13),
158 = (0x2ul << 15),
159
161 = (0x0ul << 15),
163 = (0x1ul << 15),
165
170
171 // more vendor specified modes can be added here
173#endif
174
175#if VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK == ENABLED
177 // request_rx/request_tx complete
180
181 // TX/RX reach fifo threshold, threshold on some devices is bound to 1
182 VSF_USART_IRQ_MASK_TX = (0x1ul << 2),
183 VSF_USART_IRQ_MASK_RX = (0x1ul << 3),
185
186 // clear to send interrupt
188
189 // Error interrupt
194
195 // only include VSF_USART_IRQ_MASK_TX_IDLE if hardware supports TX_IDLE interrupt
196// VSF_USART_IRQ_MASK_TX_IDLE = (0x1ul << 10),
197//#define VSF_USART_IRQ_MASK_TX_IDLE VSF_USART_IRQ_MASK_TX_IDLE
198
199 // only include VSF_USART_IRQ_MASK_RX_IDLE if hardware supports configurable RX_IDLE count and RX_IDLE interrupt
200 // or VSF_USART_IRQ_MASK_RX_IDLE will be mapped to VSF_USART_IRQ_MASK_RX_TIMEOUT
201// VSF_USART_IRQ_MASK_RX_IDLE = (0x1ul << 11),
202//#define VSF_USART_IRQ_MASK_RX_IDLE VSF_USART_IRQ_MASK_RX_IDLE
203
204 // more vendor specified irq_masks can be added here
206#endif
207
208#if VSF_USART_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
209typedef enum vsf_usart_ctrl_t {
210 // usart default command
214
215 // more vendor specified commnad can be added here
217#endif
218
223#if VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
224typedef struct vsf_usart_status_t {
225 union {
228 struct {
229 uint32_t is_busy : 1;
234 };
235 };
237#endif
238
243#if VSF_USART_CFG_REIMPLEMENT_TYPE_CFG == ENABLED
245typedef void vsf_usart_isr_handler_t(void *target_ptr,
246 vsf_usart_t *usart_ptr,
248typedef struct vsf_usart_isr_t {
250 void *target_ptr;
253typedef struct vsf_usart_cfg_t {
257# ifdef VSF_USART_IRQ_MASK_RX_IDLE
259# endif
261
262 // more vendor specified cfg can be added here
264#endif
265
266#if VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
267typedef struct vsf_usart_capability_t {
269
272
275
278
282
283 // more vendor specified capability can be added here
285#endif
286// HW/IPCore end
287
288/*============================ GLOBAL VARIABLES ==============================*/
289/*============================ PROTOTYPES ====================================*/
290
291// IPCore
292/*\note Extern APIs for ip core diriver.
293 * There is no requirement about how APIs of IPCore drivers should be implemented.
294 * Just consider the simplicity for actual peripheral drivers.
295 */
296// IPCore end
297
298#ifdef __cplusplus
299}
300#endif
301
302// IPCore
303#undef __VSF_HAL_${USART_IP}_USART_CLASS_IMPLEMENT
304#undef __VSF_HAL_${USART_IP}_USART_CLASS_INHERIT__
305// IPCore end
306
307#endif // VSF_HAL_USE_USART
308#endif // __HAL_DRIVER_${SERIES/USART_IP}_USART_H__
309/* EOF */
vsf_usart_mode_t
Definition uart.h:32
vsf_usart_irq_mask_t
Definition uart.h:106
@ VSF_USART_HALF_DUPLEX_DISABLE
Definition usart.h:108
@ VSF_USART_SYNC_CLOCK_PHASE_1_EDGE
Definition usart.h:122
@ VSF_USART_10_BIT_LENGTH
Definition usart.h:132
@ VSF_USART_RTS_HWCONTROL
Definition usart.h:101
@ VSF_USART_FORCE_0_PARITY
Definition usart.h:186
@ VSF_USART_1_STOPBIT
Definition usart.h:89
@ VSF_USART_FORCE_1_PARITY
Definition usart.h:187
@ VSF_USART_2_STOPBIT
Definition usart.h:91
@ VSF_USART_CTS_HWCONTROL
Definition usart.h:102
@ VSF_USART_RTS_CTS_HWCONTROL
Definition usart.h:103
@ VSF_USART_HALF_DUPLEX_ENABLE
Definition usart.h:107
@ VSF_USART_0_5_STOPBIT
Definition usart.h:88
@ VSF_USART_NO_HWCONTROL
Definition usart.h:100
@ VSF_USART_1_5_STOPBIT
Definition usart.h:90
@ VSF_USART_IRQ_MASK_OVERFLOW_ERR
Definition usart.h:249
@ VSF_USART_IRQ_MASK_CTS
Definition usart.h:217
@ VSF_USART_IRQ_MASK_BREAK_ERR
Definition usart.h:248
@ VSF_USART_IRQ_MASK_PARITY_ERR
Definition usart.h:226
@ VSF_USART_IRQ_MASK_FRAME_ERR
Definition usart.h:247
vsf_usart_ctrl_t
Definition usart.h:256
@ VSF_USART_CTRL_CLEAR_BREAK
Definition usart.h:260
@ VSF_USART_CTRL_SEND_BREAK
Definition usart.h:257
@ VSF_USART_CTRL_SET_BREAK
Definition usart.h:259
struct vsf_usart_cfg_t vsf_usart_cfg_t
struct vsf_usart_capability_t vsf_usart_capability_t
@ VSF_USART_TX_FIFO_THRESHOLD_EMPTY
Definition usart.h:112
@ VSF_USART_SYNC_CLOCK_ENABLE
Definition usart.h:91
@ VSF_USART_EVEN_PARITY
Definition usart.h:78
@ VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY
Definition usart.h:114
@ VSF_USART_ODD_PARITY
Definition usart.h:77
@ VSF_USART_NO_PARITY
Definition usart.h:76
@ VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL
Definition usart.h:115
@ VSF_USART_RX_ENABLE
Definition usart.h:72
@ VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL
Definition usart.h:107
@ VSF_USART_TX_ENABLE
Definition usart.h:70
@ VSF_USART_SYNC_CLOCK_POLARITY_HIGH
Definition usart.h:95
@ VSF_USART_9_BIT_LENGTH
Definition usart.h:81
@ VSF_USART_SYNC_CLOCK_POLARITY_LOW
Definition usart.h:94
@ VSF_USART_RX_DISABLE
Definition usart.h:73
@ VSF_USART_SYNC_CLOCK_DISABLE
Definition usart.h:92
@ VSF_USART_SYNC_CLOCK_PHASE_2_EDGE
Definition usart.h:98
@ VSF_USART_TX_DISABLE
Definition usart.h:71
@ VSF_USART_RX_FIFO_THRESHOLD_FULL
Definition usart.h:119
@ VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY
Definition usart.h:108
struct vsf_usart_isr_t vsf_usart_isr_t
void vsf_usart_isr_handler_t(void *target_ptr, vsf_usart_t *usart_ptr, vsf_usart_irq_mask_t irq_mask)
Definition usart.h:329
vsf_usart_mode_t
Definition usart.h:42
@ VSF_USART_8_BIT_LENGTH
Definition usart.h:43
@ VSF_USART_7_BIT_LENGTH
Definition usart.h:44
@ VSF_USART_5_BIT_LENGTH
Definition usart.h:46
@ VSF_USART_6_BIT_LENGTH
Definition usart.h:45
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
Definition adc.h:94
vsf_arch_prio_t
Definition cortex_a_generic.h:88
#define vsf_class(__name)
Definition ooc_class.h:48
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_template_hal_driver.h:196
USART capability structure Defines the hardware capabilities and limitations of the USART interface.
Definition vsf_template_usart.h:764
uint8_t max_data_bits
Maximum data bits per frame.
Definition vsf_template_usart.h:776
uint8_t support_set_and_clear_break
Support set and clear break.
Definition vsf_template_usart.h:781
vsf_usart_irq_mask_t irq_mask
Definition usart.h:349
uint8_t support_rx_timeout
Support receive timeout.
Definition vsf_template_usart.h:779
uint8_t rxfifo_depth
RX FIFO depth in data frames (0 means no FIFO)
Definition vsf_template_usart.h:774
uint8_t support_send_break
Support send break.
Definition vsf_template_usart.h:780
uint8_t txfifo_depth
TX FIFO depth in data frames (0 means no FIFO)
Definition vsf_template_usart.h:773
uint8_t min_data_bits
Minimum data bits per frame.
Definition vsf_template_usart.h:777
uint32_t min_baudrate
Minimum supported baudrate (bps)
Definition vsf_template_usart.h:771
uint32_t max_baudrate
Maximum supported baudrate (bps)
Definition vsf_template_usart.h:770
USART configuration structure Contains all parameters needed to initialize and configure a USART inst...
Definition vsf_template_usart.h:660
uint32_t mode
USART working mode.
Definition vsf_template_usart.h:661
uint32_t baudrate
Baudrate in Hz.
Definition vsf_template_usart.h:662
uint32_t rx_timeout
RX timeout in microseconds.
Definition vsf_template_usart.h:663
uint32_t rx_idle_cnt
Definition vsf_template_usart.h:665
vsf_usart_isr_t isr
Interrupt configuration.
Definition vsf_template_usart.h:667
USART interrupt configuration structure Contains all necessary information for configuring USART inte...
Definition vsf_template_usart.h:646
vsf_usart_isr_handler_t * handler_fn
Interrupt handler function pointer.
Definition vsf_template_usart.h:647
vsf_arch_prio_t prio
Interrupt priority.
Definition vsf_template_usart.h:649
void * target_ptr
User target pointer.
Definition vsf_template_usart.h:648
USART status information structure Contains the current status of USART operations and FIFO threshold...
Definition uart.h:156
uint32_t is_busy
USART is busy with any operation.
Definition vsf_template_usart.h:745
uint32_t is_tx_busy
TX is busy transmitting data.
Definition vsf_template_usart.h:746
uint32_t value
Definition usart.h:284
uint32_t tx_fifo_thresh
TX FIFO threshold level (0-255)
Definition vsf_template_usart.h:748
uint32_t rx_fifo_thresh
RX FIFO threshold level (0-255)
Definition vsf_template_usart.h:749
uint32_t is_rx_busy
RX is busy receiving data.
Definition vsf_template_usart.h:747
USART instance structure Used for USART Multi Class support.
Definition vsf_template_usart.h:810
class vsf_$ * reg
vsf_usart_isr_t isr
Definition usart.h:112
void vsf_usart_isr_handler_t(void *target_ptr, vsf_usart_t *usart_ptr, vsf_usart_irq_mask_t irq_mask)
Definition usart.h:245
vsf_usart_ctrl_t
USART control commands Defines the available control operations for USART instances.
Definition vsf_template_usart.h:680
Generated from commit: vsfteam/vsf@cfd571b