1 /******************************************************************************
3 * Copyright (C) 2002 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /****************************************************************************/
37 * This header file contains identifiers and low-level driver functions (or
38 * macros) that can be used to access the device. High-level driver functions
39 * are defined in xuartlite.h.
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ---- -------- -------------------------------------------------------
46 * 1.00b rpm 04/25/02 First release
47 * 1.00b rpm 07/07/03 Removed references to XUartLite_GetControlReg macro
48 * since the control register is write-only
49 * 1.12a mta 03/21/07 Updated to new coding style
50 * 1.13a sv 01/21/08 Updated driver to support access through DCR bus
51 * 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
52 * renamed to remove _m from the name.
55 *****************************************************************************/
57 #ifndef XUARTLITE_L_H /* prevent circular inclusions */
58 #define XUARTLITE_L_H /* by using protection macros */
64 /***************************** Include Files ********************************/
66 #include "xil_types.h"
67 #include "xil_assert.h"
71 * XPAR_XUARTLITE_USE_DCR_BRIDGE has to be set to 1 if the UartLite device is
72 * accessed through a DCR bus connected to a bridge.
74 #define XPAR_XUARTLITE_USE_DCR_BRIDGE 0
76 #if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
81 /************************** Constant Definitions ****************************/
83 /* UART Lite register offsets */
85 #if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
86 #define XUL_RX_FIFO_OFFSET 0 /* receive FIFO, read only */
87 #define XUL_TX_FIFO_OFFSET 1 /* transmit FIFO, write only */
88 #define XUL_STATUS_REG_OFFSET 2 /* status register, read only */
89 #define XUL_CONTROL_REG_OFFSET 3 /* control reg, write only */
93 #define XUL_RX_FIFO_OFFSET 0 /* receive FIFO, read only */
94 #define XUL_TX_FIFO_OFFSET 4 /* transmit FIFO, write only */
95 #define XUL_STATUS_REG_OFFSET 8 /* status register, read only */
96 #define XUL_CONTROL_REG_OFFSET 12 /* control reg, write only */
100 /* Control Register bit positions */
102 #define XUL_CR_ENABLE_INTR 0x10 /* enable interrupt */
103 #define XUL_CR_FIFO_RX_RESET 0x02 /* reset receive FIFO */
104 #define XUL_CR_FIFO_TX_RESET 0x01 /* reset transmit FIFO */
106 /* Status Register bit positions */
108 #define XUL_SR_PARITY_ERROR 0x80
109 #define XUL_SR_FRAMING_ERROR 0x40
110 #define XUL_SR_OVERRUN_ERROR 0x20
111 #define XUL_SR_INTR_ENABLED 0x10 /* interrupt enabled */
112 #define XUL_SR_TX_FIFO_FULL 0x08 /* transmit FIFO full */
113 #define XUL_SR_TX_FIFO_EMPTY 0x04 /* transmit FIFO empty */
114 #define XUL_SR_RX_FIFO_FULL 0x02 /* receive FIFO full */
115 #define XUL_SR_RX_FIFO_VALID_DATA 0x01 /* data in receive FIFO */
117 /* The following constant specifies the size of the Transmit/Receive FIFOs.
118 * The FIFO size is fixed to 16 in the Uartlite IP and the size is not
119 * configurable. This constant is not used in the driver.
121 #define XUL_FIFO_SIZE 16
123 /* Stop bits are fixed at 1. Baud, parity, and data bits are fixed on a
126 #define XUL_STOP_BITS 1
128 /* Parity definitions
130 #define XUL_PARITY_NONE 0
131 #define XUL_PARITY_ODD 1
132 #define XUL_PARITY_EVEN 2
134 /**************************** Type Definitions ******************************/
136 /***************** Macros (Inline Functions) Definitions ********************/
139 * Define the appropriate I/O access method to memory mapped I/O or DCR.
141 #if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
143 #define XUartLite_In32 XIo_DcrIn
144 #define XUartLite_Out32 XIo_DcrOut
148 #define XUartLite_In32 Xil_In32
149 #define XUartLite_Out32 Xil_Out32
154 /****************************************************************************/
157 * Write a value to a UartLite register. A 32 bit write is performed.
159 * @param BaseAddress is the base address of the UartLite device.
160 * @param RegOffset is the register offset from the base to write to.
161 * @param Data is the data written to the register.
165 * @note C-style signature:
166 * void XUartLite_WriteReg(u32 BaseAddress, u32 RegOffset,
169 ****************************************************************************/
170 #define XUartLite_WriteReg(BaseAddress, RegOffset, Data) \
171 XUartLite_Out32((BaseAddress) + (RegOffset), (u32)(Data))
173 /****************************************************************************/
176 * Read a value from a UartLite register. A 32 bit read is performed.
178 * @param BaseAddress is the base address of the UartLite device.
179 * @param RegOffset is the register offset from the base to read from.
181 * @return Data read from the register.
183 * @note C-style signature:
184 * u32 XUartLite_ReadReg(u32 BaseAddress, u32 RegOffset)
186 ****************************************************************************/
187 #define XUartLite_ReadReg(BaseAddress, RegOffset) \
188 XUartLite_In32((BaseAddress) + (RegOffset))
191 /****************************************************************************/
194 * Set the contents of the control register. Use the XUL_CR_* constants defined
195 * above to create the bit-mask to be written to the register.
197 * @param BaseAddress is the base address of the device
198 * @param Mask is the 32-bit value to write to the control register
202 * @note C-style Signature:
203 * void XUartLite_SetControlReg(u32 BaseAddress, u32 Mask);
205 *****************************************************************************/
206 #define XUartLite_SetControlReg(BaseAddress, Mask) \
207 XUartLite_WriteReg((BaseAddress), XUL_CONTROL_REG_OFFSET, (Mask))
210 /****************************************************************************/
213 * Get the contents of the status register. Use the XUL_SR_* constants defined
214 * above to interpret the bit-mask returned.
216 * @param BaseAddress is the base address of the device
218 * @return A 32-bit value representing the contents of the status register.
220 * @note C-style Signature:
221 * u32 XUartLite_GetStatusReg(u32 BaseAddress);
223 *****************************************************************************/
224 #define XUartLite_GetStatusReg(BaseAddress) \
225 XUartLite_ReadReg((BaseAddress), XUL_STATUS_REG_OFFSET)
228 /****************************************************************************/
231 * Check to see if the receiver has data.
233 * @param BaseAddress is the base address of the device
235 * @return TRUE if the receiver is empty, FALSE if there is data present.
237 * @note C-style Signature:
238 * int XUartLite_IsReceiveEmpty(u32 BaseAddress);
240 *****************************************************************************/
241 #define XUartLite_IsReceiveEmpty(BaseAddress) \
242 ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_RX_FIFO_VALID_DATA) != \
243 XUL_SR_RX_FIFO_VALID_DATA)
246 /****************************************************************************/
249 * Check to see if the transmitter is full.
251 * @param BaseAddress is the base address of the device
253 * @return TRUE if the transmitter is full, FALSE otherwise.
255 * @note C-style Signature:
256 * int XUartLite_IsTransmitFull(u32 BaseAddress);
258 *****************************************************************************/
259 #define XUartLite_IsTransmitFull(BaseAddress) \
260 ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_TX_FIFO_FULL) == \
264 /****************************************************************************/
267 * Check to see if the interrupt is enabled.
269 * @param BaseAddress is the base address of the device
271 * @return TRUE if the interrupt is enabled, FALSE otherwise.
273 * @note C-style Signature:
274 * int XUartLite_IsIntrEnabled(u32 BaseAddress);
276 *****************************************************************************/
277 #define XUartLite_IsIntrEnabled(BaseAddress) \
278 ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_INTR_ENABLED) == \
282 /****************************************************************************/
285 * Enable the device interrupt. We cannot read the control register, so we
286 * just write the enable interrupt bit and clear all others. Since the only
287 * other ones are the FIFO reset bits, this works without side effects.
289 * @param BaseAddress is the base address of the device
293 * @note C-style Signature:
294 * void XUartLite_EnableIntr(u32 BaseAddress);
296 *****************************************************************************/
297 #define XUartLite_EnableIntr(BaseAddress) \
298 XUartLite_SetControlReg((BaseAddress), XUL_CR_ENABLE_INTR)
301 /****************************************************************************/
304 * Disable the device interrupt. We cannot read the control register, so we
305 * just clear all bits. Since the only other ones are the FIFO reset bits,
306 * this works without side effects.
308 * @param BaseAddress is the base address of the device
312 * @note C-style Signature:
313 * void XUartLite_DisableIntr(u32 BaseAddress);
315 *****************************************************************************/
316 #define XUartLite_DisableIntr(BaseAddress) \
317 XUartLite_SetControlReg((BaseAddress), 0)
319 /************************** Function Prototypes *****************************/
321 void XUartLite_SendByte(u32 BaseAddress, u8 Data);
322 u8 XUartLite_RecvByte(u32 BaseAddress);
328 #endif /* end of protection macro */