1 /******************************************************************************
3 * Copyright (C) 2010 - 2015 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 /****************************************************************************/
36 * @addtogroup uartps_v3_1
41 * MODIFICATION HISTORY:
43 * Ver Who Date Changes
44 * ----- ------ -------- ----------------------------------------------
45 * 1.00 drg/jz 01/12/10 First Release
46 * 1.05a hk 08/22/13 Added reset function
47 * 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
50 *****************************************************************************/
52 /***************************** Include Files ********************************/
53 #include "xuartps_hw.h"
55 /************************** Constant Definitions ****************************/
58 /***************** Macros (Inline Functions) Definitions ********************/
61 /************************** Function Prototypes ******************************/
64 /************************** Variable Definitions *****************************/
66 /****************************************************************************/
69 * This function sends one byte using the device. This function operates in
70 * polled mode and blocks until the data has been put into the TX FIFO register.
72 * @param BaseAddress contains the base address of the device.
73 * @param Data contains the byte to be sent.
79 *****************************************************************************/
80 void XUartPs_SendByte(u32 BaseAddress, u8 Data)
82 /* Wait until there is space in TX FIFO */
83 while (XUartPs_IsTransmitFull(BaseAddress)) {
87 /* Write the byte into the TX FIFO */
88 XUartPs_WriteReg(BaseAddress, XUARTPS_FIFO_OFFSET, (u32)Data);
91 /****************************************************************************/
94 * This function receives a byte from the device. It operates in polled mode
95 * and blocks until a byte has received.
97 * @param BaseAddress contains the base address of the device.
99 * @return The data byte received.
103 *****************************************************************************/
104 u8 XUartPs_RecvByte(u32 BaseAddress)
107 /* Wait until there is data */
108 while (!XUartPs_IsReceiveData(BaseAddress)) {
111 RecievedByte = XUartPs_ReadReg(BaseAddress, XUARTPS_FIFO_OFFSET);
112 /* Return the byte received */
113 return (u8)RecievedByte;
116 /****************************************************************************/
119 * This function resets UART
121 * @param BaseAddress contains the base address of the device.
127 *****************************************************************************/
128 void XUartPs_ResetHw(u32 BaseAddress)
131 /* Disable interrupts */
132 XUartPs_WriteReg(BaseAddress, XUARTPS_IDR_OFFSET, XUARTPS_IXR_MASK);
134 /* Disable receive and transmit */
135 XUartPs_WriteReg(BaseAddress, XUARTPS_CR_OFFSET,
136 ((u32)XUARTPS_CR_RX_DIS | (u32)XUARTPS_CR_TX_DIS));
139 * Software reset of receive and transmit
140 * This clears the FIFO.
142 XUartPs_WriteReg(BaseAddress, XUARTPS_CR_OFFSET,
143 ((u32)XUARTPS_CR_TXRST | (u32)XUARTPS_CR_RXRST));
145 /* Clear status flags - SW reset wont clear sticky flags. */
146 XUartPs_WriteReg(BaseAddress, XUARTPS_ISR_OFFSET, XUARTPS_IXR_MASK);
149 * Mode register reset value : All zeroes
150 * Normal mode, even parity, 1 stop bit
152 XUartPs_WriteReg(BaseAddress, XUARTPS_MR_OFFSET,
153 XUARTPS_MR_CHMODE_NORM);
155 /* Rx and TX trigger register reset values */
156 XUartPs_WriteReg(BaseAddress, XUARTPS_RXWM_OFFSET,
157 XUARTPS_RXWM_RESET_VAL);
158 XUartPs_WriteReg(BaseAddress, XUARTPS_TXWM_OFFSET,
159 XUARTPS_TXWM_RESET_VAL);
161 /* Rx timeout disabled by default */
162 XUartPs_WriteReg(BaseAddress, XUARTPS_RXTOUT_OFFSET,
163 XUARTPS_RXTOUT_DISABLE);
165 /* Baud rate generator and dividor reset values */
166 XUartPs_WriteReg(BaseAddress, XUARTPS_BAUDGEN_OFFSET,
167 XUARTPS_BAUDGEN_RESET_VAL);
168 XUartPs_WriteReg(BaseAddress, XUARTPS_BAUDDIV_OFFSET,
169 XUARTPS_BAUDDIV_RESET_VAL);
172 * Control register reset value -
173 * RX and TX are disable by default
175 XUartPs_WriteReg(BaseAddress, XUARTPS_CR_OFFSET,
176 ((u32)XUARTPS_CR_RX_DIS | (u32)XUARTPS_CR_TX_DIS |
177 (u32)XUARTPS_CR_STOPBRK));