VSF Documented
vsf_pl011_uart.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_PL011_UART_H__
19#define __HAL_DRIVER_PL011_UART_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_USART == ENABLED
26
27#if defined(__VSF_HAL_PL011_UART_CLASS_IMPLEMENT)
28# define __VSF_CLASS_IMPLEMENT__
29#elif defined(__VSF_HAL_PL011_UART_CLASS_INHERIT__)
30# define __VSF_CLASS_INHERIT__
31#endif
32
33#include "utilities/ooc_class.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/*============================ MACROS ========================================*/
40
41#ifndef VSF_PL011_USART_CFG_MULTI_CLASS
42# define VSF_PL011_USART_CFG_MULTI_CLASS VSF_USART_CFG_MULTI_CLASS
43#endif
44
45#define VSF_USART_CFG_REIMPLEMENT_TYPE_MODE ENABLED
46#define VSF_USART_CFG_REIMPLEMENT_TYPE_IRQ_MASK ENABLED
47#define VSF_USART_CFG_REIMPLEMENT_TYPE_STATUS ENABLED
48
49/*============================ MACROFIED FUNCTIONS ===========================*/
50/*============================ TYPES =========================================*/
51
52typedef enum vsf_usart_mode_t {
53 // UARTLCR_H.WLEN
54 VSF_USART_8_BIT_LENGTH = (0x3ul << 5),
55 VSF_USART_7_BIT_LENGTH = (0x2ul << 5),
56# define VSF_USART_7_BIT_LENGTH VSF_USART_7_BIT_LENGTH
57 VSF_USART_6_BIT_LENGTH = (0x1ul << 5),
59 VSF_USART_5_BIT_LENGTH = (0x0ul << 5),
60# define VSF_USART_5_BIT_LENGTH VSF_USART_5_BIT_LENGTH
61
62 // UARTLCR_H.STP2
63 VSF_USART_1_STOPBIT = (0x0ul << 3),
64 VSF_USART_2_STOPBIT = (0x1ul << 3),
65# define VSF_USART_2_STOPBIT VSF_USART_2_STOPBIT
66
67 // UARTLCR_H.PEN / UARTLCR_H.EPS / UARTLCR_H.SPS PEN EPS SPS
68 VSF_USART_NO_PARITY = 0x0ul, // 0 X X
69 VSF_USART_ODD_PARITY = 0x2ul, // 1 0 0
70 VSF_USART_EVEN_PARITY = 0x6ul, // 1 1 0
71 VSF_USART_FORCE_0_PARITY = 0xEul, // 1 1 1
72# define VSF_USART_FORCE_0_PARITY VSF_USART_FORCE_0_PARITY
73 VSF_USART_FORCE_1_PARITY = 0xAul, // 1 0 1
74# define VSF_USART_FORCE_1_PARITY VSF_USART_FORCE_1_PARITY
75
90
91 // UARTCR.TXE
92 VSF_USART_TX_ENABLE = (0x1ul << (8 + 8)),
93 VSF_USART_TX_DISABLE = (0x0ul << (8 + 8)),
94# define VSF_USART_TX_DISABLE VSF_USART_TX_DISABLE
95
96 // UARTCR.RXE
97 VSF_USART_RX_ENABLE = (0x1ul << (8 + 9)),
98 VSF_USART_RX_DISABLE = (0x0ul << (8 + 9)),
99# define VSF_USART_RX_DISABLE VSF_USART_RX_DISABLE
100
101 // UARTCR.CTSEN / UARTCR.RTSEN
102 VSF_USART_NO_HWCONTROL = (0x0ul << (8 + 14)),
103 VSF_USART_RTS_HWCONTROL = (0x1ul << (8 + 14)),
104# define VSF_USART_RTS_HWCONTROL VSF_USART_RTS_HWCONTROL
105 VSF_USART_CTS_HWCONTROL = (0x2ul << (8 + 14)),
106# define VSF_USART_CTS_HWCONTROL VSF_USART_CTS_HWCONTROL
107 VSF_USART_RTS_CTS_HWCONTROL = (0x3ul << (8 + 14)),
108# define VSF_USART_RTS_CTS_HWCONTROL VSF_USART_RTS_CTS_HWCONTROL
109
113
114 // Not supported by hardware, just keep for build compatibility
115 VSF_USART_9_BIT_LENGTH = (0x1ul << 24),
116 VSF_USART_1_5_STOPBIT = (0x1ul << 25),
117 VSF_USART_0_5_STOPBIT = (0x1ul << 26),
118 VSF_USART_10_BIT_LENGTH = (0x1ul << 27),
123 // TX FIFO threshold (bits 8-9, mapped to PL011 TXIFLSEL: 0→0, 1→2, 2→3)
127# define VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY
130
131 // RX FIFO threshold (bits 10-11, mapped to PL011 RXIFLSEL: 0→0, 1→2, 2→3)
133# define VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY
137# define VSF_USART_RX_FIFO_THRESHOLD_FULL VSF_USART_RX_FIFO_THRESHOLD_FULL
139
140#define VSF_USART_TX_FIFO_THRESHOLD_MASK (0x3ul << 8)
141#define VSF_USART_RX_FIFO_THRESHOLD_MASK (0x3ul << 10)
142
144 // usart fifo interrupt
145 VSF_USART_IRQ_MASK_RX = (0x1ul << 4),
146 VSF_USART_IRQ_MASK_TX = (0x1ul << 5),
147
150
151 // usart error interrupt
153# define VSF_USART_IRQ_MASK_FRAME_ERR VSF_USART_IRQ_MASK_FRAME_ERR
157# define VSF_USART_IRQ_MASK_BREAK_ERR VSF_USART_IRQ_MASK_BREAK_ERR
161# define VSF_USART_IRQ_MASK_CTS VSF_USART_IRQ_MASK_CTS
162
163 // PL011 has no native idle detection; VSF maps RX_IDLE to RX_TIMEOUT
165# define VSF_USART_IRQ_MASK_RX_IDLE VSF_USART_IRQ_MASK_RX_IDLE
166
177
178 /* Chip wrappers may extend this enum with TX_CPL / RX_CPL / DMA-related
179 * masks at high bit positions (e.g. RP2040 uses bits 16-17). Force the
180 * enum's underlying type to a 32-bit signed int so those extra bits
181 * survive an `(vsf_usart_irq_mask_t)` cast under ARM EABI's
182 * -fshort-enums default. */
185
186typedef struct vsf_usart_status_t {
187 union {
188 struct {
192 uint32_t is_busy : 1;
198 };
200 };
202
203/*============================ INCLUDES ======================================*/
204/*============================ GLOBAL VARIABLES ==============================*/
205/*============================ INCLUDES ======================================*/
206
207// IP cores which will export class(es), need to include template before definition
208// of the class. Because the class member(s) maybe depend on the template.
210
211/*============================ TYPES =========================================*/
212
214#if VSF_PL011_USART_CFG_MULTI_CLASS == ENABLED
215 public_member(
216 vsf_usart_t vsf_usart;
218#endif
219 public_member(
220 void *reg;
222 protected_member(
225};
226
227/*============================ PROTOTYPES ====================================*/
228
230extern void vsf_pl011_usart_fini(vsf_pl011_usart_t *pl011_usart_ptr);
238extern uint_fast16_t vsf_pl011_usart_rxfifo_read(vsf_pl011_usart_t *pl011_usart_ptr, void *buffer_ptr, uint_fast16_t count);
240extern uint_fast16_t vsf_pl011_usart_txfifo_write(vsf_pl011_usart_t *pl011_usart_ptr, void *buffer_ptr, uint_fast16_t count);
241extern uintptr_t vsf_pl011_usart_rxdma_config(vsf_pl011_usart_t *pl011_usart_ptr, bool enable);
242extern uintptr_t vsf_pl011_usart_txdma_config(vsf_pl011_usart_t *pl011_usart_ptr, bool enable);
243extern void vsf_pl011_usart_irqhandler(vsf_pl011_usart_t *pl011_usart_ptr);
244
245#ifdef __cplusplus
246}
247#endif
248
249#endif
250#endif
251/* EOF */
vsf_err_t
Definition __type.h:42
Definition vsf_pl011_uart.h:213
vsf_usart_mode_t
Definition uart.h:32
vsf_usart_irq_mask_t
Definition uart.h:106
#define vsf_class(__name)
Definition ooc_class.h:52
const i_spi_t vsf_spi_irq_mask_t irq_mask
Definition spi_interface.h:38
uint32_t uintptr_t
Definition stdint.h:38
unsigned uint32_t
Definition stdint.h:9
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned short uint_fast16_t
Definition stdint.h:25
USART capability structure Defines the hardware capabilities and limitations of the USART interface.
Definition vsf_template_usart.h:1085
USART configuration structure Contains all parameters needed to initialize and configure a USART inst...
Definition vsf_template_usart.h:945
USART interrupt configuration structure Contains all necessary information for configuring USART inte...
Definition vsf_template_usart.h:931
USART status information structure Contains the current status of USART operations and FIFO threshold...
Definition uart.h:157
uint32_t cts
Definition vsf_pl011_uart.h:189
uint32_t ri
Definition vsf_pl011_uart.h:197
uint32_t is_busy
USART is busy with any operation.
Definition vsf_template_usart.h:1064
uint32_t value
Definition usart.h:284
uint32_t txff
Definition vsf_pl011_uart.h:194
uint32_t rxfe
Definition vsf_pl011_uart.h:193
uint32_t dsr
Definition vsf_pl011_uart.h:190
uint32_t dcd
Definition vsf_pl011_uart.h:191
uint32_t txfe
Definition vsf_pl011_uart.h:196
uint32_t rxff
Definition vsf_pl011_uart.h:195
USART instance structure Used for USART Multi Class support.
Definition vsf_template_usart.h:1138
class vsf_$ * reg
vsf_adc_isr_t isr
Definition adc.h:113
fsm_rt_t
Definition vsf_fsm.h:315
#define VSF_USART_7_BIT_LENGTH
Definition vsf_pl011_uart.h:56
#define VSF_USART_IRQ_MASK_RX_TIMEOUT
Definition vsf_pl011_uart.h:149
fsm_rt_t vsf_pl011_usart_disable(vsf_pl011_usart_t *pl011_usart_ptr)
vsf_usart_irq_mask_t vsf_pl011_usart_irq_disable(vsf_pl011_usart_t *pl011_usart_ptr, vsf_usart_irq_mask_t irq_mask)
#define VSF_USART_CTS_HWCONTROL
Definition vsf_pl011_uart.h:106
vsf_usart_mode_t
Definition vsf_pl011_uart.h:52
@ PL011_USART_ENABLE_MASK
Definition vsf_pl011_uart.h:110
@ VSF_USART_HALF_DUPLEX_DISABLE
Definition vsf_pl011_uart.h:122
@ PL011_USART_MODE_MASK
Definition vsf_pl011_uart.h:87
@ VSF_USART_8_BIT_LENGTH
Definition vsf_pl011_uart.h:54
@ VSF_USART_SYNC_CLOCK_ENABLE
Definition vsf_pl011_uart.h:119
@ PL011_USART_STOPBIT_MASK
Definition vsf_pl011_uart.h:80
@ VSF_USART_EVEN_PARITY
Definition vsf_pl011_uart.h:70
@ PL011_USART_BIT_LENGTH_MASK
Definition vsf_pl011_uart.h:76
@ VSF_USART_ODD_PARITY
Definition vsf_pl011_uart.h:69
@ VSF_USART_NO_PARITY
Definition vsf_pl011_uart.h:68
@ VSF_USART_10_BIT_LENGTH
Definition vsf_pl011_uart.h:118
@ VSF_USART_RX_ENABLE
Definition vsf_pl011_uart.h:97
@ VSF_USART_TX_ENABLE
Definition vsf_pl011_uart.h:92
@ VSF_USART_9_BIT_LENGTH
Definition vsf_pl011_uart.h:115
@ VSF_USART_1_STOPBIT
Definition vsf_pl011_uart.h:63
@ PL011_USART_PARITY_MASK
Definition vsf_pl011_uart.h:82
@ VSF_USART_SYNC_CLOCK_DISABLE
Definition vsf_pl011_uart.h:120
@ VSF_USART_HALF_DUPLEX_ENABLE
Definition vsf_pl011_uart.h:121
@ VSF_USART_0_5_STOPBIT
Definition vsf_pl011_uart.h:117
@ VSF_USART_NO_HWCONTROL
Definition vsf_pl011_uart.h:102
@ VSF_USART_1_5_STOPBIT
Definition vsf_pl011_uart.h:116
#define VSF_USART_IRQ_MASK_FRAME_ERR
Definition vsf_pl011_uart.h:153
#define VSF_USART_IRQ_MASK_CTS
Definition vsf_pl011_uart.h:161
#define VSF_USART_5_BIT_LENGTH
Definition vsf_pl011_uart.h:60
vsf_usart_irq_mask_t vsf_pl011_usart_irq_enable(vsf_pl011_usart_t *pl011_usart_ptr, vsf_usart_irq_mask_t irq_mask)
#define VSF_USART_FORCE_1_PARITY
Definition vsf_pl011_uart.h:74
vsf_err_t vsf_pl011_usart_init(vsf_pl011_usart_t *pl011_usart_ptr, vsf_usart_cfg_t *cfg_ptr, uint_fast32_t clk_hz)
#define VSF_USART_RX_FIFO_THRESHOLD_HALF_FULL
Definition vsf_pl011_uart.h:135
#define VSF_USART_TX_FIFO_THRESHOLD_EMPTY
Definition vsf_pl011_uart.h:125
fsm_rt_t vsf_pl011_usart_enable(vsf_pl011_usart_t *pl011_usart_ptr)
#define VSF_USART_TX_DISABLE
Definition vsf_pl011_uart.h:94
#define VSF_USART_RX_FIFO_THRESHOLD_FULL
Definition vsf_pl011_uart.h:137
void vsf_pl011_usart_fini(vsf_pl011_usart_t *pl011_usart_ptr)
#define VSF_USART_RTS_CTS_HWCONTROL
Definition vsf_pl011_uart.h:108
#define VSF_USART_IRQ_MASK_RX_OVERFLOW_ERR
Definition vsf_pl011_uart.h:159
vsf_usart_irq_mask_t
Definition vsf_pl011_uart.h:143
@ __VSF_USART_IRQ_FORCE_INT32
Definition vsf_pl011_uart.h:183
@ PL011_USART_IRQ_MASK_FIFO
Definition vsf_pl011_uart.h:171
@ VSF_USART_IRQ_MASK_TX
Definition vsf_pl011_uart.h:146
@ VSF_USART_IRQ_MASK_RX
Definition vsf_pl011_uart.h:145
@ PL011_USART_IRQ_MASK_ERROR
Definition vsf_pl011_uart.h:167
@ PL011_USART_IRQ_MASK
Definition vsf_pl011_uart.h:173
#define VSF_USART_RTS_HWCONTROL
Definition vsf_pl011_uart.h:104
uint_fast16_t vsf_pl011_usart_rxfifo_read(vsf_pl011_usart_t *pl011_usart_ptr, void *buffer_ptr, uint_fast16_t count)
vsf_usart_capability_t vsf_pl011_usart_capability(vsf_pl011_usart_t *pl011_usart_ptr, uint_fast32_t clk_hz)
vsf_usart_status_t vsf_pl011_usart_status(vsf_pl011_usart_t *pl011_usart_ptr)
#define VSF_USART_IRQ_MASK_BREAK_ERR
Definition vsf_pl011_uart.h:157
uint_fast16_t vsf_pl011_usart_rxfifo_get_data_count(vsf_pl011_usart_t *pl011_usart_ptr)
#define VSF_USART_FORCE_0_PARITY
Definition vsf_pl011_uart.h:72
struct vsf_usart_status_t vsf_usart_status_t
#define VSF_USART_RX_FIFO_THRESHOLD_NOT_EMPTY
Definition vsf_pl011_uart.h:133
uint_fast16_t vsf_pl011_usart_txfifo_write(vsf_pl011_usart_t *pl011_usart_ptr, void *buffer_ptr, uint_fast16_t count)
uintptr_t vsf_pl011_usart_rxdma_config(vsf_pl011_usart_t *pl011_usart_ptr, bool enable)
#define VSF_USART_IRQ_MASK_PARITY_ERR
Definition vsf_pl011_uart.h:155
#define VSF_USART_2_STOPBIT
Definition vsf_pl011_uart.h:65
uint_fast16_t vsf_pl011_usart_txfifo_get_free_count(vsf_pl011_usart_t *pl011_usart_ptr)
uintptr_t vsf_pl011_usart_txdma_config(vsf_pl011_usart_t *pl011_usart_ptr, bool enable)
#define VSF_USART_RX_DISABLE
Definition vsf_pl011_uart.h:99
#define VSF_USART_IRQ_MASK_RX_IDLE
Definition vsf_pl011_uart.h:165
#define VSF_USART_TX_FIFO_THRESHOLD_HALF_EMPTY
Definition vsf_pl011_uart.h:127
#define VSF_USART_TX_FIFO_THRESHOLD_NOT_FULL
Definition vsf_pl011_uart.h:129
void vsf_pl011_usart_irqhandler(vsf_pl011_usart_t *pl011_usart_ptr)
#define VSF_USART_6_BIT_LENGTH
Definition vsf_pl011_uart.h:58
Generated from commit: vsfteam/vsf@3b461d0