]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/uartlite_v3_0/src/xuartlite_l.h
Common scheduler code:
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / uartlite_v3_0 / src / xuartlite_l.h
1 /******************************************************************************
2 *
3 * Copyright (C) 2002 - 2014 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34 *
35 * @file xuartlite_l.h
36 *
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.
40 *
41 * <pre>
42 * MODIFICATION HISTORY:
43 *
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.
53 * </pre>
54 *
55 *****************************************************************************/
56
57 #ifndef XUARTLITE_L_H /* prevent circular inclusions */
58 #define XUARTLITE_L_H /* by using protection macros */
59
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63
64 /***************************** Include Files ********************************/
65
66 #include "xil_types.h"
67 #include "xil_assert.h"
68 #include "xil_io.h"
69
70 /*
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.
73  */
74 #define XPAR_XUARTLITE_USE_DCR_BRIDGE 0
75
76 #if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
77 #include "xio_dcr.h"
78 #endif
79
80
81 /************************** Constant Definitions ****************************/
82
83 /* UART Lite register offsets */
84
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 */
90
91 #else
92
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 */
97
98 #endif
99
100 /* Control Register bit positions */
101
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 */
105
106 /* Status Register bit positions */
107
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 */
116
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.
120  */
121 #define XUL_FIFO_SIZE                   16
122
123 /* Stop bits are fixed at 1. Baud, parity, and data bits are fixed on a
124  * per instance basis
125  */
126 #define XUL_STOP_BITS                   1
127
128 /* Parity definitions
129  */
130 #define XUL_PARITY_NONE                 0
131 #define XUL_PARITY_ODD                  1
132 #define XUL_PARITY_EVEN                 2
133
134 /**************************** Type Definitions ******************************/
135
136 /***************** Macros (Inline Functions) Definitions ********************/
137
138 /*
139  * Define the appropriate I/O access method to memory mapped I/O or DCR.
140  */
141 #if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
142
143 #define XUartLite_In32  XIo_DcrIn
144 #define XUartLite_Out32 XIo_DcrOut
145
146 #else
147
148 #define XUartLite_In32  Xil_In32
149 #define XUartLite_Out32 Xil_Out32
150
151 #endif
152
153
154 /****************************************************************************/
155 /**
156 *
157 * Write a value to a UartLite register. A 32 bit write is performed.
158 *
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.
162 *
163 * @return       None.
164 *
165 * @note         C-style signature:
166 *               void XUartLite_WriteReg(u32 BaseAddress, u32 RegOffset,
167 *                                       u32 Data)
168 *
169 ****************************************************************************/
170 #define XUartLite_WriteReg(BaseAddress, RegOffset, Data) \
171         XUartLite_Out32((BaseAddress) + (RegOffset), (u32)(Data))
172
173 /****************************************************************************/
174 /**
175 *
176 * Read a value from a UartLite register. A 32 bit read is performed.
177 *
178 * @param        BaseAddress is the base address of the UartLite device.
179 * @param        RegOffset is the register offset from the base to read from.
180 *
181 * @return       Data read from the register.
182 *
183 * @note         C-style signature:
184 *               u32 XUartLite_ReadReg(u32 BaseAddress, u32 RegOffset)
185 *
186 ****************************************************************************/
187 #define XUartLite_ReadReg(BaseAddress, RegOffset) \
188         XUartLite_In32((BaseAddress) + (RegOffset))
189
190
191 /****************************************************************************/
192 /**
193 *
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.
196 *
197 * @param        BaseAddress is the base address of the device
198 * @param        Mask is the 32-bit value to write to the control register
199 *
200 * @return       None.
201 *
202 * @note         C-style Signature:
203 *               void XUartLite_SetControlReg(u32 BaseAddress, u32 Mask);
204 *
205 *****************************************************************************/
206 #define XUartLite_SetControlReg(BaseAddress, Mask) \
207         XUartLite_WriteReg((BaseAddress), XUL_CONTROL_REG_OFFSET, (Mask))
208
209
210 /****************************************************************************/
211 /**
212 *
213 * Get the contents of the status register. Use the XUL_SR_* constants defined
214 * above to interpret the bit-mask returned.
215 *
216 * @param        BaseAddress is the  base address of the device
217 *
218 * @return       A 32-bit value representing the contents of the status register.
219 *
220 * @note         C-style Signature:
221 *               u32 XUartLite_GetStatusReg(u32 BaseAddress);
222 *
223 *****************************************************************************/
224 #define XUartLite_GetStatusReg(BaseAddress) \
225                 XUartLite_ReadReg((BaseAddress), XUL_STATUS_REG_OFFSET)
226
227
228 /****************************************************************************/
229 /**
230 *
231 * Check to see if the receiver has data.
232 *
233 * @param        BaseAddress is the  base address of the device
234 *
235 * @return       TRUE if the receiver is empty, FALSE if there is data present.
236 *
237 * @note         C-style Signature:
238 *               int XUartLite_IsReceiveEmpty(u32 BaseAddress);
239 *
240 *****************************************************************************/
241 #define XUartLite_IsReceiveEmpty(BaseAddress) \
242   ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_RX_FIFO_VALID_DATA) != \
243         XUL_SR_RX_FIFO_VALID_DATA)
244
245
246 /****************************************************************************/
247 /**
248 *
249 * Check to see if the transmitter is full.
250 *
251 * @param        BaseAddress is the  base address of the device
252 *
253 * @return       TRUE if the transmitter is full, FALSE otherwise.
254 *
255 * @note         C-style Signature:
256 *               int XUartLite_IsTransmitFull(u32 BaseAddress);
257 *
258 *****************************************************************************/
259 #define XUartLite_IsTransmitFull(BaseAddress) \
260         ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_TX_FIFO_FULL) == \
261           XUL_SR_TX_FIFO_FULL)
262
263
264 /****************************************************************************/
265 /**
266 *
267 * Check to see if the interrupt is enabled.
268 *
269 * @param        BaseAddress is the  base address of the device
270 *
271 * @return       TRUE if the interrupt is enabled, FALSE otherwise.
272 *
273 * @note         C-style Signature:
274 *               int XUartLite_IsIntrEnabled(u32 BaseAddress);
275 *
276 *****************************************************************************/
277 #define XUartLite_IsIntrEnabled(BaseAddress) \
278         ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_INTR_ENABLED) == \
279           XUL_SR_INTR_ENABLED)
280
281
282 /****************************************************************************/
283 /**
284 *
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.
288 *
289 * @param        BaseAddress is the  base address of the device
290 *
291 * @return       None.
292 *
293 * @note         C-style Signature:
294 *               void XUartLite_EnableIntr(u32 BaseAddress);
295 *
296 *****************************************************************************/
297 #define XUartLite_EnableIntr(BaseAddress) \
298                 XUartLite_SetControlReg((BaseAddress), XUL_CR_ENABLE_INTR)
299
300
301 /****************************************************************************/
302 /**
303 *
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.
307 *
308 * @param        BaseAddress is the  base address of the device
309 *
310 * @return       None.
311 *
312 * @note         C-style Signature:
313 *               void XUartLite_DisableIntr(u32 BaseAddress);
314 *
315 *****************************************************************************/
316 #define XUartLite_DisableIntr(BaseAddress) \
317                 XUartLite_SetControlReg((BaseAddress), 0)
318
319 /************************** Function Prototypes *****************************/
320
321 void XUartLite_SendByte(u32 BaseAddress, u8 Data);
322 u8 XUartLite_RecvByte(u32 BaseAddress);
323
324 #ifdef __cplusplus
325 }
326 #endif
327
328 #endif /* end of protection macro */
329
330