Ultibo API
C/C++ API for Ultibo Core
Loading...
Searching...
No Matches
pl011.h
Go to the documentation of this file.
1/*
2 * This file is part of the Ultibo project, https://ultibo.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2026 Garry Wood <garry@softoz.com.au>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26#ifndef _ULTIBO_PL011_H
27#define _ULTIBO_PL011_H
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#include "ultibo/uart.h"
34#include "ultibo/threads.h"
35
36#define PL011_UART_RX_BUFFER
37
39#define PL011_UART_DESCRIPTION "ARM PrimeCell PL011 UART"
40
41#define PL011_UART_MIN_BAUD 300
42#define PL011_UART_MAX_BAUD 1500000
43
44#define PL011_UART_MIN_DATABITS SERIAL_DATA_5BIT
45#define PL011_UART_MAX_DATABITS SERIAL_DATA_8BIT
46
47#define PL011_UART_MIN_STOPBITS SERIAL_STOP_1BIT
48#define PL011_UART_MAX_STOPBITS SERIAL_STOP_2BIT
49
50#define PL011_UART_MAX_PARITY SERIAL_PARITY_EVEN
51
52#define PL011_UART_MAX_FLOW SERIAL_FLOW_RTS_CTS
53
54#define PL011_UART_CLOCK_RATE 24000000
55#ifdef PL011_UART_RX_BUFFER
56#define PL011_UART_RX_POLL_LIMIT 256
57#define PL011_UART_RX_BUFFER_SIZE 1024
58#endif
59
61#define PL011_UART_DR_OE (1 << 11)
62#define PL011_UART_DR_BE (1 << 10)
63#define PL011_UART_DR_PE (1 << 9)
64#define PL011_UART_DR_FE (1 << 8)
65#define PL011_UART_DR_DATA (0xFF << 0)
66#define PL011_UART_DR_ERROR PL011_UART_DR_OE | PL011_UART_DR_BE | PL011_UART_DR_PE | PL011_UART_DR_FE
67
69#define PL011_UART_RSRECR_OE (1 << 3)
70#define PL011_UART_RSRECR_BE (1 << 2)
71#define PL011_UART_RSRECR_PE (1 << 1)
72#define PL011_UART_RSRECR_FE (1 << 0)
73
75#define PL011_UART_FR_RI (1 << 8)
76#define PL011_UART_FR_TXFE (1 << 7)
77#define PL011_UART_FR_RXFF (1 << 6)
78#define PL011_UART_FR_TXFF (1 << 5)
79#define PL011_UART_FR_RXFE (1 << 4)
80#define PL011_UART_FR_BUSY (1 << 3)
81#define PL011_UART_FR_DCD (1 << 2)
82#define PL011_UART_FR_DSR (1 << 1)
83#define PL011_UART_FR_CTS (1 << 0)
84
86
88#define PL011_UART_IBRD_MASK (0xFFFF << 0)
89
91#define PL011_UART_FBRD_MASK (0x3F << 0)
92
94#define PL011_UART_LCRH_SPS (1 << 7)
95#define PL011_UART_LCRH_WLEN (3 << 5)
96#define PL011_UART_LCRH_WLEN8 (3 << 5)
97#define PL011_UART_LCRH_WLEN7 (2 << 5)
98#define PL011_UART_LCRH_WLEN6 (1 << 5)
99#define PL011_UART_LCRH_WLEN5 (0 << 5)
100#define PL011_UART_LCRH_FEN (1 << 4)
101#define PL011_UART_LCRH_STP2 (1 << 3)
102#define PL011_UART_LCRH_EPS (1 << 2)
103#define PL011_UART_LCRH_PEN (1 << 1)
104#define PL011_UART_LCRH_BRK (1 << 0)
105
107#define PL011_UART_CR_CTSEN (1 << 15)
108#define PL011_UART_CR_RTSEN (1 << 14)
109#define PL011_UART_CR_OUT2 (1 << 13)
110#define PL011_UART_CR_OUT1 (1 << 12)
111#define PL011_UART_CR_RTS (1 << 11)
112#define PL011_UART_CR_DTR (1 << 10)
113#define PL011_UART_CR_RXE (1 << 9)
114#define PL011_UART_CR_TXE (1 << 8)
115#define PL011_UART_CR_LBE (1 << 7)
117#define PL011_UART_CR_SIRLP (1 << 2)
118#define PL011_UART_CR_SIREN (1 << 1)
119#define PL011_UART_CR_UARTEN (1 << 0)
120
122#define PL011_UART_IFLS_RXIFPSEL (7 << 9)
123#define PL011_UART_IFLS_TXIFPSEL (7 << 6)
124#define PL011_UART_IFLS_RXIFLSEL (7 << 3)
125#define PL011_UART_IFLS_RXIFLSEL1_8 (0 << 3)
126#define PL011_UART_IFLS_RXIFLSEL1_4 (1 << 3)
127#define PL011_UART_IFLS_RXIFLSEL1_2 (2 << 3)
128#define PL011_UART_IFLS_RXIFLSEL3_4 (3 << 3)
129#define PL011_UART_IFLS_RXIFLSEL7_8 (4 << 3)
130#define PL011_UART_IFLS_TXIFLSEL (7 << 0)
131#define PL011_UART_IFLS_TXIFLSEL1_8 (0 << 0)
132#define PL011_UART_IFLS_TXIFLSEL1_4 (1 << 0)
133#define PL011_UART_IFLS_TXIFLSEL1_2 (2 << 0)
134#define PL011_UART_IFLS_TXIFLSEL3_4 (3 << 0)
135#define PL011_UART_IFLS_TXIFLSEL7_8 (4 << 0)
136
138#define PL011_UART_IMSC_OEIM (1 << 10)
139#define PL011_UART_IMSC_BEIM (1 << 9)
140#define PL011_UART_IMSC_PEIM (1 << 8)
141#define PL011_UART_IMSC_FEIM (1 << 7)
142#define PL011_UART_IMSC_RTIM (1 << 6)
143#define PL011_UART_IMSC_TXIM (1 << 5)
144#define PL011_UART_IMSC_RXIM (1 << 4)
145#define PL011_UART_IMSC_DSRMIM (1 << 3)
146#define PL011_UART_IMSC_DCDMIM (1 << 2)
147#define PL011_UART_IMSC_CTSMIM (1 << 1)
148#define PL011_UART_IMSC_RIMIM (1 << 0)
149
151#define PL011_UART_RIS_OERIS (1 << 10)
152#define PL011_UART_RIS_BERIS (1 << 9)
153#define PL011_UART_RIS_PERIS (1 << 8)
154#define PL011_UART_RIS_FERIS (1 << 7)
155#define PL011_UART_RIS_RTRIS (1 << 6)
156#define PL011_UART_RIS_TXRIS (1 << 5)
157#define PL011_UART_RIS_RXRIS (1 << 4)
158#define PL011_UART_RIS_DSRMRIS (1 << 3)
159#define PL011_UART_RIS_DCDMRIS (1 << 2)
160#define PL011_UART_RIS_CTSMRIS (1 << 1)
161#define PL011_UART_RIS_RIMRIS (1 << 0)
162
164#define PL011_UART_MIS_OEMIS (1 << 10)
165#define PL011_UART_MIS_BEMIS (1 << 9)
166#define PL011_UART_MIS_PEMIS (1 << 8)
167#define PL011_UART_MIS_FEMIS (1 << 7)
168#define PL011_UART_MIS_RTMIS (1 << 6)
169#define PL011_UART_MIS_TXMIS (1 << 5)
170#define PL011_UART_MIS_RXMIS (1 << 4)
171#define PL011_UART_MIS_DSRMMIS (1 << 3)
172#define PL011_UART_MIS_DCDMMIS (1 << 2)
173#define PL011_UART_MIS_CTSMMIS (1 << 1)
174#define PL011_UART_MIS_RIMMIS (1 << 0)
175
177#define PL011_UART_ICR_OEIC (1 << 10)
178#define PL011_UART_ICR_BEIC (1 << 9)
179#define PL011_UART_ICR_PEIC (1 << 8)
180#define PL011_UART_ICR_FEIC (1 << 7)
181#define PL011_UART_ICR_RTIC (1 << 6)
182#define PL011_UART_ICR_TXIC (1 << 5)
183#define PL011_UART_ICR_RXIC (1 << 4)
184#define PL011_UART_ICR_DSRMIC (1 << 3)
185#define PL011_UART_ICR_DCDMIC (1 << 2)
186#define PL011_UART_ICR_CTSMIC (1 << 1)
187#define PL011_UART_ICR_RIMIC (1 << 0)
188
191
193
195
197
199
204{
205 uint32_t dr;
206 uint32_t rsrecr;
207 uint32_t reserved01;
208 uint32_t reserved02;
209 uint32_t reserved03;
210 uint32_t reserved04;
211 uint32_t fr;
212 uint32_t reserved05;
213 uint32_t ilpr;
214 uint32_t ibrd;
215 uint32_t fbrd;
216 uint32_t lcrh;
217 uint32_t cr;
218 uint32_t ifls;
219 uint32_t imsc;
220 uint32_t ris;
221 uint32_t mis;
222 uint32_t icr;
223 uint32_t dmacr;
224 uint32_t reserved11;
225 uint32_t reserved12;
226 uint32_t reserved13;
227 uint32_t reserved14;
228 uint32_t reserved15;
229 uint32_t reserved16;
230 uint32_t reserved17;
231 uint32_t reserved18;
232 uint32_t reserved19;
233 uint32_t reserved1a;
234 uint32_t reserved1b;
235 uint32_t reserved1c;
236 uint32_t reserved1d;
237 uint32_t itcr;
238 uint32_t itip;
239 uint32_t itop;
240 uint32_t tdr;
241};
242
243
244typedef struct _PL011_UART PL011_UART;
246{
247 // UART Properties
249 // PL011 Properties
250 uint32_t irq;
252 uint32_t clockrate;
254 #ifdef PL011_UART_RX_BUFFER
255 uint32_t start;
256 uint32_t count;
258 #endif
259 // Statistics Properties
260 uint32_t interruptcount;
261};
262
264
273UART_DEVICE * STDCALL pl011_uart_create(size_t address, char *name, uint32_t irq, uint32_t clockrate);
274
281
282#ifdef __cplusplus
283}
284#endif
285
286#endif // _ULTIBO_PL011_H
#define STDCALL
Definition globaltypes.h:45
HANDLE SPIN_HANDLE
Definition globaltypes.h:104
uint32_t STDCALL pl011_uart_destroy(UART_DEVICE *uart)
Close, deregister and destroy a PL011 UART device created by this driver.
struct _PL011_UART PL011_UART
Definition pl011.h:244
#define PL011_UART_RX_BUFFER_SIZE
Definition pl011.h:57
UART_DEVICE *STDCALL pl011_uart_create(size_t address, char *name, uint32_t irq, uint32_t clockrate)
Create and register a new PL011 UART device which can be accessed using the UART API.
struct _PL011_UART_REGISTERS PL011_UART_REGISTERS
Definition pl011.h:202
Definition pl011.h:204
uint32_t reserved1b
Definition pl011.h:234
uint32_t fr
Flag register.
Definition pl011.h:211
uint32_t rsrecr
Receive Status Register / Error Clear Register.
Definition pl011.h:206
uint32_t reserved19
Definition pl011.h:232
uint32_t ifls
Interrupt FIFO Level Select Register.
Definition pl011.h:218
uint32_t reserved1a
Definition pl011.h:233
uint32_t ibrd
Integer Baud rate divisor.
Definition pl011.h:214
uint32_t ris
Raw Interrupt Status Register.
Definition pl011.h:220
uint32_t reserved05
Definition pl011.h:212
uint32_t reserved1d
Definition pl011.h:236
uint32_t reserved15
Definition pl011.h:228
uint32_t reserved16
Definition pl011.h:229
uint32_t itcr
Test Control Register.
Definition pl011.h:237
uint32_t reserved02
Definition pl011.h:208
uint32_t imsc
Interrupt Mask Set Clear Register.
Definition pl011.h:219
uint32_t itop
Integration Test Output Register.
Definition pl011.h:239
uint32_t reserved14
Definition pl011.h:227
uint32_t ilpr
IrDA Low-Power Counter Register.
Definition pl011.h:213
uint32_t reserved01
Definition pl011.h:207
uint32_t dmacr
DMA Control Register.
Definition pl011.h:223
uint32_t cr
Control register.
Definition pl011.h:217
uint32_t fbrd
Fractional Baud rate divisor.
Definition pl011.h:215
uint32_t icr
Interrupt Clear Register.
Definition pl011.h:222
uint32_t reserved11
Definition pl011.h:224
uint32_t tdr
Test Data Register.
Definition pl011.h:240
uint32_t dr
Data Register.
Definition pl011.h:205
uint32_t lcrh
Line Control register.
Definition pl011.h:216
uint32_t reserved13
Definition pl011.h:226
uint32_t reserved1c
Definition pl011.h:235
uint32_t reserved12
Definition pl011.h:225
uint32_t itip
Integration Test Input Register.
Definition pl011.h:238
uint32_t reserved18
Definition pl011.h:231
uint32_t reserved03
Definition pl011.h:209
uint32_t reserved04
Definition pl011.h:210
uint32_t mis
Masked Interrupt Status Register.
Definition pl011.h:221
uint32_t reserved17
Definition pl011.h:230
Definition pl011.h:246
uint16_t buffer[PL011_UART_RX_BUFFER_SIZE]
Buffer for received data (Includes data and status).
Definition pl011.h:257
uint32_t irq
Definition pl011.h:250
uint32_t interruptcount
Number of interrupt requests received by the device.
Definition pl011.h:260
SPIN_HANDLE lock
Device lock (Differs from lock in UART device) (Spin lock due to use by interrupt handler).
Definition pl011.h:251
uint32_t start
Index of first available buffer entry.
Definition pl011.h:255
UART_DEVICE uart
Definition pl011.h:248
uint32_t count
Number of available entries in the buffer.
Definition pl011.h:256
PL011_UART_REGISTERS * registers
Device registers.
Definition pl011.h:253
uint32_t clockrate
Device clock rate.
Definition pl011.h:252
struct _UART_DEVICE UART_DEVICE
Definition uart.h:130