Embedded Xinu Operating System
An ongoing research project and educational operating system.
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
pl011.h
Go to the documentation of this file.
1 
5 /* Embedded Xinu, Copyright (C) 2009, 2013. All rights reserved. */
6 
7 #ifndef _PL011_H_
8 #define _PL011_H_
9 
15 {
16  volatile unsigned int dr; //0x00
17  volatile unsigned int rsrecr; //0x04
18  volatile unsigned int dont_use_a; //0x08
19  volatile unsigned int dont_use_b; //0x0C
20  volatile unsigned int dont_use_c; //0x10
21  volatile unsigned int dont_use_d; //0x14
22  volatile unsigned int fr; //0x18
23  volatile unsigned int dont_use_e; //0x1C
24  volatile unsigned int ilpr; //0x20
25  volatile unsigned int ibrd; //0x24
26  volatile unsigned int fbrd; //0x28
27  volatile unsigned int lcrh; //0x2C
28  volatile unsigned int cr; //0x30
29  volatile unsigned int ifls; //0x34
30  volatile unsigned int imsc; //0x38
31  volatile unsigned int ris; //0x3C
32  volatile unsigned int mis; //0x40
33  volatile unsigned int icr; //0x44
34 };
35 
36 /* UART Bit flags for control and status registers */
37 #define PL011_DR_OE (1<<11) //set to 1 on overrun error
38 #define PL011_DR_BE (1<<10) //set to 1 on break condition
39 #define PL011_DR_PE (1<<9) //set to 1 on parity error
40 #define PL011_DR_FE (1<<8) //set to 1 on framing error
41 
42 #define PL011_RSRECR_OE (1<<3) //set to 1 on overrun error
43 #define PL011_RSRECR_BE (1<<2) //set to 1 on break condition
44 #define PL011_RSRECR_PE (1<<1) //set to 1 on parity error
45 #define PL011_RSRECR_FE (1<<0) //set to 1 on framing error
46 
47 #define PL011_FR_RI (1<<8) //set to 1 when ring indicator pin is low
48 #define PL011_FR_TXFE (1<<7) //set to 1 when TX FIFO/register is empty
49 #define PL011_FR_RXFF (1<<6) //set to 1 when RX FIFO/register is full
50 #define PL011_FR_TXFF (1<<5) //set to 1 when TX FIFO/register is full
51 #define PL011_FR_RXFE (1<<4) //set to 1 when RX FIFO/register is empty
52 #define PL011_FR_BUSY (1<<3) //set to 1 when UART is transmitting data
53 #define PL011_FR_DCD (1<<2) //set to 1 when DCD pin is low
54 #define PL011_FR_DSR (1<<1) //set to 1 when DSR pin is low
55 #define PL011_FR_CTS (1<<0) //set to 1 when CTS pin is low
56 
57 #define PL011_LCRH_SPS (1<<7) //
58 //word length
59 #define PL011_LCRH_WLEN_8BIT (0b11<<5)
60 #define PL011_LCRH_WLEN_7BIT (0b10<<5)
61 #define PL011_LCRH_WLEN_6BIT (0b01<<5)
62 #define PL011_LCRH_WLEN_5BIT (0b00<<5)
63 #define PL011_LCRH_FEN (1<<4) //set to 1 to enable TX and RX FIFOs
64 #define PL011_LCRH_STP2 (1<<3) //set to 1 to send 2 stop bits
65 #define PL011_LCRH_EPS (1<<2) //set to 1 for even parity, 0 for odd
66 #define PL011_LCRH_PEN (1<<1) //set to 1 to enable parity
67 #define PL011_LCRH_BRK (1<<0) //set to 1 to force the TX pin low
68 
69 #define PL011_CR_CTSEN (1<<15) //set to 1 to enable CTS hardware flow control
70 #define PL011_CR_RTSEN (1<<14) //set to 1 to enable RTS hardware flow control
71 #define PL011_CR_OUT2 (1<<13) //set to 1 to set out2 to 0
72 #define PL011_CR_OUT1 (1<<12) //set to 1 to set out1 to 0
73 #define PL011_CR_RTS (1<<11) //set to 1 to set the RTS pin low
74 #define PL011_CR_DTR (1<<10) //set to 1 to set the DTR pin low
75 #define PL011_CR_RXE (1<<9) //set to 1 to enable receiving
76 #define PL011_CR_TXE (1<<8) //set to 1 to enable transmitting
77 #define PL011_CR_LBE (1<<7) //set to 1 to enable loopback
78 #define PL011_CR_SIRLP (1<<2) //sets SIR IrDA mode (unused?)
79 #define PL011_CR_SIREN (1<<1) //enables SIR IrDA mode (unused?)
80 #define PL011_CR_UARTEN (1<<0) //set to 1 to enable the UART
81 
82 //RX FIFO fill interrupt threshold
83 #define PL011_IFLS_RXIFLSEL_EIGHTH (0b000<<3)
84 #define PL011_IFLS_RXIFLSEL_QUARTER (0b001<<3)
85 #define PL011_IFLS_RXIFLSEL_HALF (0b010<<3)
86 #define PL011_IFLS_RXIFLSEL_THREEQUARTERS (0b011<<3)
87 #define PL011_IFLS_RXIFLSEL_SEVENEIGHTHS (0b100<<3)
88 //TX FIFO fill interrupt threshold
89 #define PL011_IFLS_TXIFLSEL_EIGHTH (0b000<<0)
90 #define PL011_IFLS_TXIFLSEL_QUARTER (0b001<<0)
91 #define PL011_IFLS_TXIFLSEL_HALF (0b010<<0)
92 #define PL011_IFLS_TXIFLSEL_THREEQUARTERS (0b011<<0)
93 #define PL011_IFLS_TXIFLSEL_SEVENEIGHTHS (0b100<<0)
94 
95 #define PL011_IMSC_OEIM (1<<10) //overrun error mask bit, if 1: this interrupt is enabled
96 #define PL011_IMSC_BEIN (1<<9) //break error mask bit, if 1: this interrupt is enabled
97 #define PL011_IMSC_PEIM (1<<8) //parity error mask bit, if 1: this interrupt is enabled
98 #define PL011_IMSC_FEIM (1<<7) //framing error mask bit, if 1: this interrupt is enabled
99 #define PL011_IMSC_RTIM (1<<6) //receive timeout mask bit, if 1: this interrupt is enabled
100 #define PL011_IMSC_TXIM (1<<5) //transmit interrupt mask bit, if 1: this interrupt is enabled
101 #define PL011_IMSC_RXIM (1<<4) //receive interrupt mask bit, if 1: this interrupt is enabled
102 #define PL011_IMSC_DSRMIM (1<<3) //DSR interrupt mask bit, if 1: this interrupt is enabled
103 #define PL011_IMSC_DCDMIM (1<<2) //DCD interrupt mask bit, if 1: this interrupt is enabled
104 #define PL011_IMSC_CTSMIM (1<<1) //CTS interrupt mask bit, if 1: this interrupt is enabled
105 #define PL011_IMSC_RIMIM (1<<0) //RI interrupt mask bit, if 1: this interrupt is enabled
106 
107 #define PL011_RIS_OERIS (1<<10) //overrun error interrupt status
108 #define PL011_RIS_BERIS (1<<9) //break error interrupt status
109 #define PL011_RIS_PERIS (1<<8) //parity error interrupt status
110 #define PL011_RIS_FERIS (1<<7) //framing error interrupt status
111 #define PL011_RIS_RTRIS (1<<6) //receive timeout interrupt status
112 #define PL011_RIS_TXRIS (1<<5) //transmit interrupt status
113 #define PL011_RIS_RXRIS (1<<4) //receive interrupt status
114 #define PL011_RIS_DSRRMIS (1<<3) //DSR interrupt status
115 #define PL011_RIS_DCDRMIS (1<<2) //DCD interrupt status
116 #define PL011_RIS_CTSRMIS (1<<1) //CTS interrupt status
117 #define PL011_RIS_RIRMIS (1<<0) //RI interrupt status
118 
119 //read only
120 #define PL011_MIS_OEMIS (1<<10) //overrun error interrupt status
121 #define PL011_MIS_BEMIS (1<<9) //break error interrupt status
122 #define PL011_MIS_PEMIS (1<<8) //parity error interrupt status
123 #define PL011_MIS_FEMIS (1<<7) //framing error interrupt status
124 #define PL011_MIS_RTMIS (1<<6) //receive timeout interrupt status
125 #define PL011_MIS_TXMIS (1<<5) //transmit interrupt status
126 #define PL011_MIS_RXMIS (1<<4) //receive interrupt status
127 #define PL011_MIS_DSRMMIS (1<<3) //DSR interrupt status
128 #define PL011_MIS_DCDMMIS (1<<2) //DCD interrupt status
129 #define PL011_MIS_CTSMMIS (1<<1) //CTS interrupt status
130 #define PL011_MIS_RIMMIS (1<<0) //RI interrupt status
131 
132 #define PL011_ICR_OEIC (1<<10) //overrun error interrupt clear
133 #define PL011_ICR_BEIC (1<<9) //break error interrupt clear
134 #define PL011_ICR_PEIC (1<<8) //parity error interrupt clear
135 #define PL011_ICR_FEIC (1<<7) //framing error interrupt clear
136 #define PL011_ICR_RTIC (1<<6) //receive timeout interrupt clear
137 #define PL011_ICR_TXIC (1<<5) //transmit interrupt clear
138 #define PL011_ICR_RXIC (1<<4) //receive interrupt clear
139 #define PL011_ICR_DSRMIC (1<<3) //DSR interrupt clear
140 #define PL011_ICR_DCDMIC (1<<2) //DCD interrupt clear
141 #define PL011_ICR_CTSMIC (1<<1) //CTS interrupt clear
142 #define PL011_ICR_RIMIC (1<<0) //RI interrupt clear
143 
144 #define PL011_FIFO_LEN 8
146 /* Different versions of Pi have different
147  * UART clock frequencies */
148 #ifdef _XINU_PLATFORM_ARM_RPI_3_
149 #define UARTCLK 48000000
150 #elif defined _XINU_PLATFORM_ARM_RPI_
151 #define UARTCLK 3000000
152 #endif
153 
154 #define PL011_BAUD_INT(x) (UARTCLK / (16 * (x)))
155 #define PL011_BAUD_FRAC(x) (int)((((UARTCLK / (16.0 * (x)))-PL011_BAUD_INT(x))*64.0)+0.5) //9600 baud may be slightly off with this calcualtion
156 
157 #endif /* _PL011_H_ */
volatile unsigned int fr
Definition: pl011.h:22
volatile unsigned int fbrd
Definition: pl011.h:26
volatile unsigned int icr
Definition: pl011.h:33
volatile unsigned int dont_use_c
Definition: pl011.h:20
volatile unsigned int mis
Definition: pl011.h:32
volatile unsigned int ifls
Definition: pl011.h:29
volatile unsigned int imsc
Definition: pl011.h:30
volatile unsigned int ilpr
Definition: pl011.h:24
volatile unsigned int lcrh
Definition: pl011.h:27
volatile unsigned int dont_use_b
Definition: pl011.h:19
volatile unsigned int cr
Definition: pl011.h:28
volatile unsigned int ibrd
Definition: pl011.h:25
volatile unsigned int rsrecr
Definition: pl011.h:17
volatile unsigned int dr
Definition: pl011.h:16
Definition: pl011.h:14
volatile unsigned int dont_use_d
Definition: pl011.h:21
volatile unsigned int ris
Definition: pl011.h:31