RTEMS 6.1-rc2
Loading...
Searching...
No Matches
uartlite_l.h
1/******************************************************************************
2* Copyright (C) 2002 - 2020 Xilinx, Inc. All rights reserved.
3* SPDX-License-Identifier: MIT
4******************************************************************************/
5
6/****************************************************************************/
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/****************************************************************************/
162#define XUartLite_WriteReg(BaseAddress, RegOffset, Data) \
163 XUartLite_Out32((BaseAddress) + (RegOffset), (u32)(Data))
164
165/****************************************************************************/
179#define XUartLite_ReadReg(BaseAddress, RegOffset) \
180 XUartLite_In32((BaseAddress) + (RegOffset))
181
182
183/****************************************************************************/
198#define XUartLite_SetControlReg(BaseAddress, Mask) \
199 XUartLite_WriteReg((BaseAddress), XUL_CONTROL_REG_OFFSET, (Mask))
200
201
202/****************************************************************************/
216#define XUartLite_GetStatusReg(BaseAddress) \
217 XUartLite_ReadReg((BaseAddress), XUL_STATUS_REG_OFFSET)
218
219
220/****************************************************************************/
233#define XUartLite_IsReceiveEmpty(BaseAddress) \
234 ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_RX_FIFO_VALID_DATA) != \
235 XUL_SR_RX_FIFO_VALID_DATA)
236
237#ifdef __rtems__
238/****************************************************************************/
251#define XUartLite_IsTransmitEmpty(BaseAddress) \
252 ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_TX_FIFO_EMPTY) == \
253 XUL_SR_TX_FIFO_EMPTY)
254#endif /* __rtems__ */
255
256/****************************************************************************/
269#define XUartLite_IsTransmitFull(BaseAddress) \
270 ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_TX_FIFO_FULL) == \
271 XUL_SR_TX_FIFO_FULL)
272
273
274/****************************************************************************/
287#define XUartLite_IsIntrEnabled(BaseAddress) \
288 ((XUartLite_GetStatusReg((BaseAddress)) & XUL_SR_INTR_ENABLED) == \
289 XUL_SR_INTR_ENABLED)
290
291
292/****************************************************************************/
307#define XUartLite_EnableIntr(BaseAddress) \
308 XUartLite_SetControlReg((BaseAddress), XUL_CR_ENABLE_INTR)
309
310
311/****************************************************************************/
326#define XUartLite_DisableIntr(BaseAddress) \
327 XUartLite_SetControlReg((BaseAddress), 0)
328
329/************************** Function Prototypes *****************************/
330
331void XUartLite_SendByte(UINTPTR BaseAddress, u8 Data);
332u8 XUartLite_RecvByte(UINTPTR BaseAddress);
333
334#ifdef __cplusplus
335}
336#endif
337
338#endif /* end of protection macro */
339
340
u8 XUartLite_RecvByte(UINTPTR BaseAddress)
Definition: uartlite_l.c:92
void XUartLite_SendByte(UINTPTR BaseAddress, u8 Data)
Definition: uartlite_l.c:70