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 component contains the implementation of the XUartLite component which is
38 * the driver for the Xilinx UART Lite device. This UART is a minimal hardware
39 * implementation with minimal features. Most of the features, including baud
40 * rate, parity, and number of data bits are only configurable when the hardware
41 * device is built, rather than at run time by software.
43 * The device has 16 byte transmit and receive FIFOs and supports interrupts.
44 * The device does not have any way to disable the receiver such that the
45 * receive FIFO may contain unwanted data. The FIFOs are not flushed when the
46 * driver is initialized, but a function is provided to allow the user to
47 * reset the FIFOs if desired.
49 * The driver defaults to no interrupts at initialization such that interrupts
50 * must be enabled if desired. An interrupt is generated when the transmit FIFO
51 * transitions from having data to being empty or when any data is contained in
54 * In order to use interrupts, it's necessary for the user to connect the driver
55 * interrupt handler, XUartLite_InterruptHandler, to the interrupt system of the
56 * application. This function does not save and restore the processor context
57 * such that the user must provide it. Send and receive handlers may be set for
58 * the driver such that the handlers are called when transmit and receive
59 * interrupts occur. The handlers are called from interrupt context and are
60 * designed to allow application specific processing to be performed.
62 * The functions, XUartLite_Send and XUartLite_Recv, are provided in the driver
63 * to allow data to be sent and received. They are designed to be used in
64 * polled or interrupt modes.
66 * The driver provides a status for each received byte indicating any parity
67 * frame or overrun error. The driver provides statistics which allow visibility
70 * <b>Initialization & Configuration</b>
72 * The XUartLite_Config structure is used by the driver to configure itself. This
73 * configuration structure is typically created by the tool-chain based on HW
76 * To support multiple runtime loading and initialization strategies employed
77 * by various operating systems, the driver instance can be initialized in one
78 * of the following ways:
80 * - XUartLite_Initialize(InstancePtr, DeviceId) - The driver looks up its own
81 * configuration structure created by the tool-chain based on an ID provided
84 * - XUartLite_CfgInitialize(InstancePtr, CfgPtr, EffectiveAddr) - Uses a
85 * configuration structure provided by the caller. If running in a system
86 * with address translation, the provided virtual memory base address
87 * replaces the physical address present in the configuration structure.
89 * <b>RTOS Independence</b>
91 * This driver is intended to be RTOS and processor independent. It works
92 * with physical addresses only. Any needs for dynamic memory management,
93 * threads or thread mutual exclusion, virtual memory, or cache control must
94 * be satisfied by the layer above this driver.
98 * The driver is partitioned such that a minimal implementation may be used.
99 * More features require additional files to be linked in.
102 * MODIFICATION HISTORY:
104 * Ver Who Date Changes
105 * ----- ---- -------- -----------------------------------------------
106 * 1.00a ecm 08/31/01 First release
107 * 1.00b jhl 02/21/02 Repartitioned the driver for smaller files
108 * 1.01a jvb 12/14/05 I separated dependency on the static config table and
109 * xparameters.h from the driver initialization by moving
110 * _Initialize and _LookupConfig to _sinit.c. I also added
111 * the new _CfgInitialize routine.
112 * 1.02a rpm 02/14/07 Added check for outstanding transmission before
113 * calling the send callback (avoids extraneous
114 * callback invocations) in interrupt service routine.
115 * 1.12a mta 03/31/07 Updated to new coding conventions
116 * 1.13a sv 01/21/08 Updated driver to support access through DCR bus
117 * 1.14a sdm 08/22/08 Removed support for static interrupt handlers from the MDD
119 * 1.14a sdm 09/26/08 Updated code to avoid race condition in
120 * XUartLite_SendBuffer
121 * 2.00a ktn 10/20/09 Updated to use HAL Processor APIs. The macros have been
122 * renamed to remove _m from the name. XUartLite_mClearStats
123 * macro is removed and XUartLite_ClearStats function should
124 * be used in its place.
125 * 2.01a adk 18/04/13 Updated the code to avoid unused variable
126 * warnings when compiling with the -Wextra -Wall flags
127 * In the file xuartlite.c. CR:704999.
128 * Added notes for CR 710483 that the XUL_FIFO_SIZE is not
129 * used in the driver. This is the size of the FIFO for
130 * Transmit/Receive FIFOs which cannot be changed.
131 * 3.0 adk 17/12/13 Fixed CR:741186,761863 Changes are made in the file
132 * xuartlite_selftest.c
133 * 3.0 adk 19/12/13 Update the driver as per new TCL API's
137 *****************************************************************************/
139 #ifndef XUARTLITE_H /* prevent circular inclusions */
140 #define XUARTLITE_H /* by using protection macros */
146 /***************************** Include Files ********************************/
148 #include "xil_types.h"
149 #include "xil_assert.h"
152 /************************** Constant Definitions ****************************/
154 /**************************** Type Definitions ******************************/
157 * Callback function. The first argument is a callback reference passed in by
158 * the upper layer when setting the callback functions, and passed back to the
159 * upper layer when the callback is invoked.
160 * The second argument is the ByteCount which is the number of bytes that
161 * actually moved from/to the buffer provided in the _Send/_Receive call.
163 typedef void (*XUartLite_Handler)(void *CallBackRef, unsigned int ByteCount);
166 * Statistics for the XUartLite driver
169 u32 TransmitInterrupts; /**< Number of transmit interrupts */
170 u32 ReceiveInterrupts; /**< Number of receive interrupts */
171 u32 CharactersTransmitted; /**< Number of characters transmitted */
172 u32 CharactersReceived; /**< Number of characters received */
173 u32 ReceiveOverrunErrors; /**< Number of receive overruns */
174 u32 ReceiveParityErrors; /**< Number of receive parity errors */
175 u32 ReceiveFramingErrors; /**< Number of receive framing errors */
179 * The following data type is used to manage the buffers that are handled
180 * when sending and receiving data in the interrupt mode. It is intended
181 * for internal use only.
185 unsigned int RequestedBytes;
186 unsigned int RemainingBytes;
190 * This typedef contains configuration information for the device.
193 u16 DeviceId; /**< Unique ID of device */
194 u32 RegBaseAddr; /**< Register base address */
195 u32 BaudRate; /**< Fixed baud rate */
196 u8 UseParity; /**< Parity generator enabled when TRUE */
197 u8 ParityOdd; /**< Parity generated is odd when TRUE, even
199 u8 DataBits; /**< Fixed data bits */
203 * The XUartLite driver instance data. The user is required to allocate a
204 * variable of this type for every UART Lite device in the system. A pointer
205 * to a variable of this type is then passed to the driver API functions.
208 XUartLite_Stats Stats; /* Component Statistics */
209 u32 RegBaseAddress; /* Base address of registers */
210 u32 IsReady; /* Device is initialized and ready */
212 XUartLite_Buffer SendBuffer;
213 XUartLite_Buffer ReceiveBuffer;
215 XUartLite_Handler RecvHandler;
216 void *RecvCallBackRef; /* Callback ref for recv handler */
217 XUartLite_Handler SendHandler;
218 void *SendCallBackRef; /* Callback ref for send handler */
222 /***************** Macros (Inline Functions) Definitions ********************/
225 /************************** Function Prototypes *****************************/
228 * Initialization functions in xuartlite_sinit.c
230 int XUartLite_Initialize(XUartLite *InstancePtr, u16 DeviceId);
231 XUartLite_Config *XUartLite_LookupConfig(u16 DeviceId);
234 * Required functions, in file xuart.c
236 int XUartLite_CfgInitialize(XUartLite *InstancePtr,
237 XUartLite_Config *Config,
240 void XUartLite_ResetFifos(XUartLite *InstancePtr);
242 unsigned int XUartLite_Send(XUartLite *InstancePtr, u8 *DataBufferPtr,
243 unsigned int NumBytes);
244 unsigned int XUartLite_Recv(XUartLite *InstancePtr, u8 *DataBufferPtr,
245 unsigned int NumBytes);
247 int XUartLite_IsSending(XUartLite *InstancePtr);
250 * Functions for statistics, in file xuartlite_stats.c
252 void XUartLite_GetStats(XUartLite *InstancePtr, XUartLite_Stats *StatsPtr);
253 void XUartLite_ClearStats(XUartLite *InstancePtr);
256 * Functions for self-test, in file xuartlite_selftest.c
258 int XUartLite_SelfTest(XUartLite *InstancePtr);
261 * Functions for interrupts, in file xuartlite_intr.c
263 void XUartLite_EnableInterrupt(XUartLite *InstancePtr);
264 void XUartLite_DisableInterrupt(XUartLite *InstancePtr);
266 void XUartLite_SetRecvHandler(XUartLite *InstancePtr, XUartLite_Handler FuncPtr,
268 void XUartLite_SetSendHandler(XUartLite *InstancePtr, XUartLite_Handler FuncPtr,
271 void XUartLite_InterruptHandler(XUartLite *InstancePtr);
277 #endif /* end of protection macro */