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 VSF_USART_6_BIT_LENGTH = (0x1ul << 5),
57 VSF_USART_5_BIT_LENGTH = (0x0ul << 5),
58
59 // UARTLCR_H.STP2
60 VSF_USART_1_STOPBIT = (0x0ul << 3),
61 VSF_USART_2_STOPBIT = (0x1ul << 3),
62
63 // UARTLCR_H.PEN / UARTLCR_H.EPS / UARTLCR_H.SPS PEN EPS SPS
64 VSF_USART_NO_PARITY = 0x0ul, // 0 X X
65 VSF_USART_ODD_PARITY = 0x2ul, // 1 0 0
66 VSF_USART_EVEN_PARITY = 0x6ul, // 1 1 0
67 VSF_USART_FORCE_0_PARITY = 0xEul, // 1 1 1
68 VSF_USART_FORCE_1_PARITY = 0xAul, // 1 0 1
69
84
85 // UARTCR.TXE
86 VSF_USART_TX_ENABLE = (0x1ul << (8 + 8)),
87 VSF_USART_TX_DISABLE = (0x0ul << (8 + 8)),
88
89 // UARTCR.RXE
90 VSF_USART_RX_ENABLE = (0x1ul << (8 + 9)),
91 VSF_USART_RX_DISABLE = (0x0ul << (8 + 9)),
92
93 // UARTCR.CTSEN / UARTCR.RTSEN
94 VSF_USART_NO_HWCONTROL = (0x0ul << (8 + 14)),
95 VSF_USART_RTS_HWCONTROL = (0x1ul << (8 + 14)),
96 VSF_USART_CTS_HWCONTROL = (0x2ul << (8 + 14)),
97 VSF_USART_RTS_CTS_HWCONTROL = (0x3ul << (8 + 14)),
98
102
103 // Not supported by hardware, just keep for build
104 VSF_USART_9_BIT_LENGTH = (0x1ul << 24),
105 VSF_USART_1_5_STOPBIT = (0x1ul << 25),
107
109 // usart fifo interrupt
110 VSF_USART_IRQ_MASK_RX = (0x1ul << 4),
111 VSF_USART_IRQ_MASK_TX = (0x1ul << 5),
112
114
115 // usart error interrupt
120
131
132typedef struct vsf_usart_status_t {
133 union {
134 struct {
138 uint32_t is_busy : 1;
144 };
146 };
148
149/*============================ INCLUDES ======================================*/
150/*============================ GLOBAL VARIABLES ==============================*/
151/*============================ INCLUDES ======================================*/
152
153// IP cores which will export class(es), need to include template before definition
154// of the class. Because the class member(s) maybe depend on the template.
156
157/*============================ TYPES =========================================*/
158
160#if VSF_PL011_USART_CFG_MULTI_CLASS == ENABLED
161 public_member(
162 vsf_usart_t vsf_usart;
164#endif
165 public_member(
166 void *reg;
168 protected_member(
171};
172
173/*============================ PROTOTYPES ====================================*/
174
176extern void vsf_pl011_usart_fini(vsf_pl011_usart_t *pl011_usart_ptr);
184extern uint_fast16_t vsf_pl011_usart_rxfifo_read(vsf_pl011_usart_t *pl011_usart_ptr, void *buffer_ptr, uint_fast16_t count);
186extern uint_fast16_t vsf_pl011_usart_txfifo_write(vsf_pl011_usart_t *pl011_usart_ptr, void *buffer_ptr, uint_fast16_t count);
187extern uintptr_t vsf_pl011_usart_rxdma_config(vsf_pl011_usart_t *pl011_usart_ptr, bool enable);
188extern uintptr_t vsf_pl011_usart_txdma_config(vsf_pl011_usart_t *pl011_usart_ptr, bool enable);
189extern void vsf_pl011_usart_irqhandler(vsf_pl011_usart_t *pl011_usart_ptr);
190
191#ifdef __cplusplus
192}
193#endif
194
195#endif
196#endif
197/* EOF */
vsf_err_t
Definition __type.h:42
vsf_usart_mode_t
Definition uart.h:32
vsf_usart_irq_mask_t
Definition uart.h:105
Definition vsf_pl011_uart.h:159
#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
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
Definition vsf_template_usart.h:630
Definition vsf_template_usart.h:556
Definition vsf_template_usart.h:550
Definition uart.h:156
uint32_t cts
Definition vsf_pl011_uart.h:135
uint32_t ri
Definition vsf_pl011_uart.h:143
uint32_t is_busy
Definition usart.h:276
uint32_t value
Definition usart.h:279
uint32_t txff
Definition vsf_pl011_uart.h:140
uint32_t rxfe
Definition vsf_pl011_uart.h:139
uint32_t dsr
Definition vsf_pl011_uart.h:136
uint32_t dcd
Definition vsf_pl011_uart.h:137
uint32_t txfe
Definition vsf_pl011_uart.h:142
uint32_t rxff
Definition vsf_pl011_uart.h:141
Definition vsf_template_usart.h:661
class vsf_$ * reg
vsf_adc_isr_t isr
Definition adc.h:83
fsm_rt_t
Definition vsf_fsm.h:315
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)
vsf_usart_mode_t
Definition vsf_pl011_uart.h:52
@ PL011_USART_ENABLE_MASK
Definition vsf_pl011_uart.h:99
@ PL011_USART_MODE_MASK
Definition vsf_pl011_uart.h:81
@ VSF_USART_8_BIT_LENGTH
Definition vsf_pl011_uart.h:54
@ PL011_USART_STOPBIT_MASK
Definition vsf_pl011_uart.h:74
@ VSF_USART_EVEN_PARITY
Definition vsf_pl011_uart.h:66
@ PL011_USART_BIT_LENGTH_MASK
Definition vsf_pl011_uart.h:70
@ VSF_USART_ODD_PARITY
Definition vsf_pl011_uart.h:65
@ VSF_USART_NO_PARITY
Definition vsf_pl011_uart.h:64
@ VSF_USART_RTS_HWCONTROL
Definition vsf_pl011_uart.h:95
@ VSF_USART_RX_ENABLE
Definition vsf_pl011_uart.h:90
@ VSF_USART_FORCE_0_PARITY
Definition vsf_pl011_uart.h:67
@ VSF_USART_TX_ENABLE
Definition vsf_pl011_uart.h:86
@ VSF_USART_9_BIT_LENGTH
Definition vsf_pl011_uart.h:104
@ VSF_USART_7_BIT_LENGTH
Definition vsf_pl011_uart.h:55
@ VSF_USART_1_STOPBIT
Definition vsf_pl011_uart.h:60
@ VSF_USART_FORCE_1_PARITY
Definition vsf_pl011_uart.h:68
@ VSF_USART_RX_DISABLE
Definition vsf_pl011_uart.h:91
@ VSF_USART_2_STOPBIT
Definition vsf_pl011_uart.h:61
@ VSF_USART_CTS_HWCONTROL
Definition vsf_pl011_uart.h:96
@ VSF_USART_5_BIT_LENGTH
Definition vsf_pl011_uart.h:57
@ PL011_USART_PARITY_MASK
Definition vsf_pl011_uart.h:76
@ VSF_USART_RTS_CTS_HWCONTROL
Definition vsf_pl011_uart.h:97
@ VSF_USART_TX_DISABLE
Definition vsf_pl011_uart.h:87
@ VSF_USART_6_BIT_LENGTH
Definition vsf_pl011_uart.h:56
@ VSF_USART_NO_HWCONTROL
Definition vsf_pl011_uart.h:94
@ VSF_USART_1_5_STOPBIT
Definition vsf_pl011_uart.h:105
vsf_usart_irq_mask_t vsf_pl011_usart_irq_enable(vsf_pl011_usart_t *pl011_usart_ptr, vsf_usart_irq_mask_t irq_mask)
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)
fsm_rt_t vsf_pl011_usart_enable(vsf_pl011_usart_t *pl011_usart_ptr)
void vsf_pl011_usart_fini(vsf_pl011_usart_t *pl011_usart_ptr)
vsf_usart_irq_mask_t
Definition vsf_pl011_uart.h:108
@ VSF_USART_IRQ_MASK_OVERFLOW_ERR
Definition vsf_pl011_uart.h:119
@ PL011_USART_IRQ_MASK_FIFO
Definition vsf_pl011_uart.h:125
@ VSF_USART_IRQ_MASK_TX
Definition vsf_pl011_uart.h:111
@ VSF_USART_IRQ_MASK_BREAK_ERR
Definition vsf_pl011_uart.h:118
@ VSF_USART_IRQ_MASK_RX
Definition vsf_pl011_uart.h:110
@ VSF_USART_IRQ_MASK_RX_TIMEOUT
Definition vsf_pl011_uart.h:113
@ PL011_USART_IRQ_MASK_ERROR
Definition vsf_pl011_uart.h:121
@ VSF_USART_IRQ_MASK_PARITY_ERR
Definition vsf_pl011_uart.h:117
@ VSF_USART_IRQ_MASK_FRAME_ERR
Definition vsf_pl011_uart.h:116
@ PL011_USART_IRQ_MASK
Definition vsf_pl011_uart.h:127
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)
uint_fast16_t vsf_pl011_usart_rxfifo_get_data_count(vsf_pl011_usart_t *pl011_usart_ptr)
struct vsf_usart_status_t vsf_usart_status_t
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)
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)
void vsf_pl011_usart_irqhandler(vsf_pl011_usart_t *pl011_usart_ptr)