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 // more vendor specified irq_masks can be added here
197#endif
198
199#if VSF_USART_CFG_REIMPLEMENT_TYPE_CTRL == ENABLED
200typedef enum vsf_usart_ctrl_t {
201 // usart default command
205
206 // more vendor specified commnad can be added here
208#endif
209
214#if VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS == ENABLED
215typedef struct vsf_usart_status_t {
216 union {
219 struct {
220 uint32_t is_busy : 1;
225 };
226 };
228#endif
229
234#if VSF_USART_CFG_REIMPLEMENT_TYPE_CFG == ENABLED
236typedef void vsf_usart_isr_handler_t(void *target_ptr,
237 vsf_usart_t *usart_ptr,
239typedef struct vsf_usart_isr_t {
241 void *target_ptr;
244typedef struct vsf_usart_cfg_t {
249
250 // more vendor specified cfg can be added here
252#endif
253
254#if VSF_USART_CFG_REIMPLEMENT_TYPE_CAPABILITY == ENABLED
255typedef struct vsf_usart_capability_t {
257
260
263
266
270
271 // more vendor specified capability can be added here
273#endif
274// HW/IPCore end
275
276/*============================ GLOBAL VARIABLES ==============================*/
277/*============================ PROTOTYPES ====================================*/
278
279// IPCore
280/*\note Extern APIs for ip core diriver.
281 * There is no requirement about how APIs of IPCore drivers should be implemented.
282 * Just consider the simplicity for actual peripheral drivers.
283 */
284// IPCore end
285
286#ifdef __cplusplus
287}
288#endif
289
290// IPCore
291#undef __VSF_HAL_${USART_IP}_USART_CLASS_IMPLEMENT
292#undef __VSF_HAL_${USART_IP}_USART_CLASS_INHERIT__
293// IPCore end
294
295#endif // VSF_HAL_USE_USART
296#endif // __HAL_DRIVER_${SERIES/USART_IP}_USART_H__
297/* 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_ENABLE
Definition usart.h:116
@ VSF_USART_EVEN_PARITY
Definition usart.h:113
@ VSF_USART_ODD_PARITY
Definition usart.h:112
@ 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_USART_RX_ENABLE
Definition usart.h:96
@ VSF_USART_FORCE_0_PARITY
Definition usart.h:186
@ VSF_USART_TX_ENABLE
Definition usart.h:94
@ VSF_USART_SYNC_CLOCK_POLARITY_HIGH
Definition usart.h:120
@ VSF_USART_1_STOPBIT
Definition usart.h:89
@ VSF_USART_FORCE_1_PARITY
Definition usart.h:187
@ VSF_USART_SYNC_CLOCK_POLARITY_LOW
Definition usart.h:119
@ VSF_USART_RX_DISABLE
Definition usart.h:97
@ VSF_USART_2_STOPBIT
Definition usart.h:91
@ 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_1_5_STOPBIT
Definition usart.h:90
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
@ VSF_USART_TX_FIFO_THRESHOLD_EMPTY
Definition usart.h:116
@ VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY
Definition usart.h:117
@ VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL
Definition usart.h:118
@ VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL
Definition usart.h:114
@ VSF_USART_9_BIT_LENGTH
Definition usart.h:109
@ VSF_USART_RX_FIFO_THRESHOLD_FULL
Definition usart.h:119
@ VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY
Definition usart.h:115
@ VSF_USART_IRQ_MASK_OVERFLOW_ERR
Definition usart.h:210
@ VSF_USART_IRQ_MASK_CTS
Definition usart.h:183
@ VSF_USART_IRQ_MASK_BREAK_ERR
Definition usart.h:209
@ VSF_USART_IRQ_MASK_PARITY_ERR
Definition usart.h:192
@ VSF_USART_IRQ_MASK_FRAME_ERR
Definition usart.h:208
vsf_usart_ctrl_t
Definition usart.h:217
@ VSF_USART_CTRL_CLEAR_BREAK
Definition usart.h:221
@ VSF_USART_CTRL_SEND_BREAK
Definition usart.h:218
@ VSF_USART_CTRL_SET_BREAK
Definition usart.h:220
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:729
uint8_t max_data_bits
Maximum data bits per frame.
Definition vsf_template_usart.h:741
uint8_t support_set_and_clear_break
Support set and clear break.
Definition vsf_template_usart.h:746
vsf_usart_irq_mask_t irq_mask
Definition usart.h:256
uint8_t support_rx_timeout
Support receive timeout.
Definition vsf_template_usart.h:744
uint8_t rxfifo_depth
RX FIFO depth in data frames (0 means no FIFO)
Definition vsf_template_usart.h:739
uint8_t support_send_break
Support send break.
Definition vsf_template_usart.h:745
uint8_t txfifo_depth
TX FIFO depth in data frames (0 means no FIFO)
Definition vsf_template_usart.h:738
uint8_t min_data_bits
Minimum data bits per frame.
Definition vsf_template_usart.h:742
uint32_t min_baudrate
Minimum supported baudrate (bps)
Definition vsf_template_usart.h:736
uint32_t max_baudrate
Maximum supported baudrate (bps)
Definition vsf_template_usart.h:735
USART configuration structure Contains all parameters needed to initialize and configure a USART inst...
Definition vsf_template_usart.h:628
uint32_t mode
USART working mode.
Definition vsf_template_usart.h:629
uint32_t baudrate
Baudrate in Hz.
Definition vsf_template_usart.h:630
uint32_t rx_timeout
RX timeout in microseconds.
Definition vsf_template_usart.h:631
vsf_usart_isr_t isr
Interrupt configuration.
Definition vsf_template_usart.h:632
USART interrupt configuration structure Contains all necessary information for configuring USART inte...
Definition vsf_template_usart.h:614
vsf_usart_isr_handler_t * handler_fn
Interrupt handler function pointer.
Definition vsf_template_usart.h:615
vsf_arch_prio_t prio
Interrupt priority.
Definition vsf_template_usart.h:617
void * target_ptr
User target pointer.
Definition vsf_template_usart.h:616
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:710
uint32_t is_tx_busy
TX is busy transmitting data.
Definition vsf_template_usart.h:711
uint32_t value
Definition usart.h:284
uint32_t tx_fifo_thresh
TX FIFO threshold level (0-255)
Definition vsf_template_usart.h:713
uint32_t rx_fifo_thresh
RX FIFO threshold level (0-255)
Definition vsf_template_usart.h:714
uint32_t is_rx_busy
RX is busy receiving data.
Definition vsf_template_usart.h:712
USART instance structure Used for USART Multi Class support.
Definition vsf_template_usart.h:775
vsf_usart_irq_mask_t
Definition usart.h:176
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:236
vsf_usart_ctrl_t
USART control commands Defines the available control operations for USART instances.
Definition vsf_template_usart.h:645
Generated from commit: vsfteam/vsf@2b286be