source: rtems/bsps/microblaze/include/dev/serial/uartlite_l.h @ d03776e

Last change on this file since d03776e was d03776e, checked in by Alex White <alex.white@…>, on 10/01/21 at 04:57:01

microblaze: Rework for RTEMS 6

This reworks the existing MicroBlaze? architecture port and BSP to
achieve basic functionality using the latest RTEMS APIs.

  • Property mode set to 100644
File size: 10.0 KB
Line 
1/******************************************************************************
2* Copyright (C) 2002 - 2020 Xilinx, Inc.  All rights reserved.
3* SPDX-License-Identifier: MIT
4******************************************************************************/
5
6/****************************************************************************/
7/**
8*
9* @file xuartlite_l.h
10* @addtogroup uartlite_v3_5
11* @{
12*
13* This header file contains identifiers and low-level driver functions (or
14* macros) that can be used to access the device.  High-level driver functions
15* are defined in xuartlite.h.
16*
17* <pre>
18* MODIFICATION HISTORY:
19*
20* Ver   Who  Date     Changes
21* ----- ---- -------- -------------------------------------------------------
22* 1.00b rpm  04/25/02 First release
23* 1.00b rpm  07/07/03 Removed references to XUartLite_GetControlReg macro
24*                     since the control register is write-only
25* 1.12a mta  03/21/07 Updated to new coding style
26* 1.13a sv   01/21/08 Updated driver to support access through DCR bus
27* 2.00a ktn  10/20/09 Updated to use HAL Processor APIs. The macros have been
28*                     renamed to remove _m from the name.
29* 3.2   sk   11/10/15 Used UINTPTR instead of u32 for Baseaddress CR# 867425.
30*                     Changed the prototypes of XUartLite_SendByte,
31*                     XUartLite_RecvByte APIs.
32* </pre>
33*
34*****************************************************************************/
35
36#ifndef XUARTLITE_L_H /* prevent circular inclusions */
37#define XUARTLITE_L_H /* by using protection macros */
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/***************************** Include Files ********************************/
44
45#ifndef __rtems__
46#include "xil_types.h"
47#include "xil_assert.h"
48#include "xil_io.h"
49#else
50#include <common/xil_types.h>
51static inline u32 Xil_In32(UINTPTR Addr)
52{
53        return *(volatile u32 *) Addr;
54}
55static inline void Xil_Out32(UINTPTR Addr, u32 Value)
56{
57        volatile u32 *LocalAddr = (volatile u32 *)Addr;
58        *LocalAddr = Value;
59}
60#endif /* __rtems__ */
61
62/*
63 * XPAR_XUARTLITE_USE_DCR_BRIDGE has to be set to 1 if the UartLite device is
64 * accessed through a DCR bus connected to a bridge.
65 */
66#define XPAR_XUARTLITE_USE_DCR_BRIDGE 0
67
68#if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
69#include "xio_dcr.h"
70#endif
71
72
73/************************** Constant Definitions ****************************/
74
75/* UART Lite register offsets */
76
77#if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
78#define XUL_RX_FIFO_OFFSET              0       /* receive FIFO, read only */
79#define XUL_TX_FIFO_OFFSET              1       /* transmit FIFO, write only */
80#define XUL_STATUS_REG_OFFSET           2       /* status register, read only */
81#define XUL_CONTROL_REG_OFFSET          3       /* control reg, write only */
82
83#else
84
85#define XUL_RX_FIFO_OFFSET              0       /* receive FIFO, read only */
86#define XUL_TX_FIFO_OFFSET              4       /* transmit FIFO, write only */
87#define XUL_STATUS_REG_OFFSET           8       /* status register, read only */
88#define XUL_CONTROL_REG_OFFSET          12      /* control reg, write only */
89
90#endif
91
92/* Control Register bit positions */
93
94#define XUL_CR_ENABLE_INTR              0x10    /* enable interrupt */
95#define XUL_CR_FIFO_RX_RESET            0x02    /* reset receive FIFO */
96#define XUL_CR_FIFO_TX_RESET            0x01    /* reset transmit FIFO */
97
98/* Status Register bit positions */
99
100#define XUL_SR_PARITY_ERROR             0x80
101#define XUL_SR_FRAMING_ERROR            0x40
102#define XUL_SR_OVERRUN_ERROR            0x20
103#define XUL_SR_INTR_ENABLED             0x10    /* interrupt enabled */
104#define XUL_SR_TX_FIFO_FULL             0x08    /* transmit FIFO full */
105#define XUL_SR_TX_FIFO_EMPTY            0x04    /* transmit FIFO empty */
106#define XUL_SR_RX_FIFO_FULL             0x02    /* receive FIFO full */
107#define XUL_SR_RX_FIFO_VALID_DATA       0x01    /* data in receive FIFO */
108
109/* The following constant specifies the size of the Transmit/Receive FIFOs.
110 * The FIFO size is fixed to 16 in the Uartlite IP and the size is not
111 * configurable. This constant is not used in the driver.
112 */
113#define XUL_FIFO_SIZE                   16
114
115/* Stop bits are fixed at 1. Baud, parity, and data bits are fixed on a
116 * per instance basis
117 */
118#define XUL_STOP_BITS                   1
119
120/* Parity definitions
121 */
122#define XUL_PARITY_NONE                 0
123#define XUL_PARITY_ODD                  1
124#define XUL_PARITY_EVEN                 2
125
126/**************************** Type Definitions ******************************/
127
128/***************** Macros (Inline Functions) Definitions ********************/
129
130/*
131 * Define the appropriate I/O access method to memory mapped I/O or DCR.
132 */
133#if (XPAR_XUARTLITE_USE_DCR_BRIDGE != 0)
134
135#define XUartLite_In32  XIo_DcrIn
136#define XUartLite_Out32 XIo_DcrOut
137
138#else
139
140#define XUartLite_In32  Xil_In32
141#define XUartLite_Out32 Xil_Out32
142
143#endif
144
145
146/****************************************************************************/
147/**
148*
149* Write a value to a UartLite register. A 32 bit write is performed.
150*
151* @param        BaseAddress is the base address of the UartLite device.
152* @param        RegOffset is the register offset from the base to write to.
153* @param        Data is the data written to the register.
154*
155* @return       None.
156*
157* @note         C-style signature:
158*               void XUartLite_WriteReg(u32 BaseAddress, u32 RegOffset,
159*                                       u32 Data)
160*
161****************************************************************************/
162#define XUartLite_WriteReg(BaseAddress, RegOffset, Data) \
163        XUartLite_Out32((BaseAddress) + (RegOffset), (u32)(Data))
164
165/****************************************************************************/
166/**
167*
168* Read a value from a UartLite register. A 32 bit read is performed.
169*
170* @param        BaseAddress is the base address of the UartLite device.
171* @param        RegOffset is the register offset from the base to read from.
172*
173* @return       Data read from the register.
174*
175* @note         C-style signature:
176*               u32 XUartLite_ReadReg(u32 BaseAddress, u32 RegOffset)
177*
178****************************************************************************/
179#define XUartLite_ReadReg(BaseAddress, RegOffset) \
180        XUartLite_In32((BaseAddress) + (RegOffset))
181
182
183/****************************************************************************/
184/**
185*
186* Set the contents of the control register. Use the XUL_CR_* constants defined
187* above to create the bit-mask to be written to the register.
188*
189* @param        BaseAddress is the base address of the device
190* @param        Mask is the 32-bit value to write to the control register
191*
192* @return       None.
193*
194* @note         C-style Signature:
195*               void XUartLite_SetControlReg(u32 BaseAddress, u32 Mask);
196*
197*****************************************************************************/
198#define XUartLite_SetControlReg(BaseAddress, Mask) \
199        XUartLite_WriteReg((BaseAddress), XUL_CONTROL_REG_OFFSET, (Mask))
200
201
202/****************************************************************************/
203/**
204*
205* Get the contents of the status register. Use the XUL_SR_* constants defined
206* above to interpret the bit-mask returned.
207*
208* @param        BaseAddress is the  base address of the device
209*
210* @return       A 32-bit value representing the contents of the status register.
211*
212* @note         C-style Signature:
213*               u32 XUartLite_GetStatusReg(u32 BaseAddress);
214*
215*****************************************************************************/
216#define XUartLite_GetStatusReg(BaseAddress) \
217                XUartLite_ReadReg((BaseAddress), XUL_STATUS_REG_OFFSET)
218
219
220/****************************************************************************/
221/**
222*
223* Check to see if the receiver has data.
224*
225* @param        BaseAddress is the  base address of the device
226*
227* @return       TRUE if the receiver is empty, FALSE if there is data present.
228*
229* @note         C-style Signature:
230*               int XUartLite_IsReceiveEmpty(u32 BaseAddress);
231*
232*****************************************************************************/
233#define XUartLite_IsReceiveEmpty(BaseAddress) \
234  ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_RX_FIFO_VALID_DATA) != \
235        XUL_SR_RX_FIFO_VALID_DATA)
236
237
238/****************************************************************************/
239/**
240*
241* Check to see if the transmitter is full.
242*
243* @param        BaseAddress is the  base address of the device
244*
245* @return       TRUE if the transmitter is full, FALSE otherwise.
246*
247* @note         C-style Signature:
248*               int XUartLite_IsTransmitFull(u32 BaseAddress);
249*
250*****************************************************************************/
251#define XUartLite_IsTransmitFull(BaseAddress) \
252        ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_TX_FIFO_FULL) == \
253          XUL_SR_TX_FIFO_FULL)
254
255
256/****************************************************************************/
257/**
258*
259* Check to see if the interrupt is enabled.
260*
261* @param        BaseAddress is the  base address of the device
262*
263* @return       TRUE if the interrupt is enabled, FALSE otherwise.
264*
265* @note         C-style Signature:
266*               int XUartLite_IsIntrEnabled(u32 BaseAddress);
267*
268*****************************************************************************/
269#define XUartLite_IsIntrEnabled(BaseAddress) \
270        ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_INTR_ENABLED) == \
271          XUL_SR_INTR_ENABLED)
272
273
274/****************************************************************************/
275/**
276*
277* Enable the device interrupt. We cannot read the control register, so we
278* just write the enable interrupt bit and clear all others. Since the only
279* other ones are the FIFO reset bits, this works without side effects.
280*
281* @param        BaseAddress is the  base address of the device
282*
283* @return       None.
284*
285* @note         C-style Signature:
286*               void XUartLite_EnableIntr(u32 BaseAddress);
287*
288*****************************************************************************/
289#define XUartLite_EnableIntr(BaseAddress) \
290                XUartLite_SetControlReg((BaseAddress), XUL_CR_ENABLE_INTR)
291
292
293/****************************************************************************/
294/**
295*
296* Disable the device interrupt. We cannot read the control register, so we
297* just clear all bits. Since the only other ones are the FIFO reset bits,
298* this works without side effects.
299*
300* @param        BaseAddress is the  base address of the device
301*
302* @return       None.
303*
304* @note         C-style Signature:
305*               void XUartLite_DisableIntr(u32 BaseAddress);
306*
307*****************************************************************************/
308#define XUartLite_DisableIntr(BaseAddress) \
309                XUartLite_SetControlReg((BaseAddress), 0)
310
311/************************** Function Prototypes *****************************/
312
313void XUartLite_SendByte(UINTPTR BaseAddress, u8 Data);
314u8 XUartLite_RecvByte(UINTPTR BaseAddress);
315
316#ifdef __cplusplus
317}
318#endif
319
320#endif /* end of protection macro */
321
322
323/** @} */
Note: See TracBrowser for help on using the repository browser.