]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/uartps_v2_1/src/xuartps_hw.c
Preparing for next release...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / uartps_v2_1 / src / xuartps_hw.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2010 - 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 xuartps_hw.c
36 *
37 *
38 * <pre>
39 * MODIFICATION HISTORY:
40 *
41 * Ver   Who    Date     Changes
42 * ----- ------ -------- ----------------------------------------------
43 * 1.00  drg/jz 01/12/10 First Release
44 * 1.05a hk     08/22/13 Added reset function
45 * </pre>
46 *
47 *****************************************************************************/
48
49 /***************************** Include Files ********************************/
50 #include "xuartps_hw.h"
51
52 /************************** Constant Definitions ****************************/
53
54
55 /***************** Macros (Inline Functions) Definitions ********************/
56
57
58 /************************** Function Prototypes ******************************/
59
60
61 /************************** Variable Definitions *****************************/
62
63 /****************************************************************************/
64 /**
65 *
66 * This function sends one byte using the device. This function operates in
67 * polled mode and blocks until the data has been put into the TX FIFO register.
68 *
69 * @param        BaseAddress contains the base address of the device.
70 * @param        Data contains the byte to be sent.
71 *
72 * @return       None.
73 *
74 * @note         None.
75 *
76 *****************************************************************************/
77 void XUartPs_SendByte(u32 BaseAddress, u8 Data)
78 {
79                 /*
80                  * Wait until there is space in TX FIFO
81                  */
82                 while (XUartPs_IsTransmitFull(BaseAddress));
83
84                 /*
85                  * Write the byte into the TX FIFO
86                  */
87                 XUartPs_WriteReg(BaseAddress, XUARTPS_FIFO_OFFSET, Data);
88 }
89
90 /****************************************************************************/
91 /**
92 *
93 * This function receives a byte from the device. It operates in polled mode
94 * and blocks until a byte has received.
95 *
96 * @param        BaseAddress contains the base address of the device.
97 *
98 * @return       The data byte received.
99 *
100 * @note         None.
101 *
102 *****************************************************************************/
103 u8 XUartPs_RecvByte(u32 BaseAddress)
104 {
105                 /*
106                  * Wait until there is data
107                  */
108                 while (!XUartPs_IsReceiveData(BaseAddress));
109
110                 /*
111                  * Return the byte received
112                  */
113                 return (XUartPs_ReadReg(BaseAddress, XUARTPS_FIFO_OFFSET));
114 }
115
116 /****************************************************************************/
117 /**
118 *
119 * This function resets UART
120 *
121 * @param        BaseAddress contains the base address of the device.
122 *
123 * @return       None
124 *
125 * @note         None.
126 *
127 *****************************************************************************/
128 void XUartPs_ResetHw(u32 BaseAddress)
129 {
130
131         /*
132          * Disable interrupts
133          */
134         XUartPs_WriteReg(BaseAddress, XUARTPS_IDR_OFFSET, XUARTPS_IXR_MASK);
135
136         /*
137          * Disable receive and transmit
138          */
139         XUartPs_WriteReg(BaseAddress, XUARTPS_CR_OFFSET,
140                                 XUARTPS_CR_RX_DIS | XUARTPS_CR_TX_DIS);
141
142         /*
143          * Software reset of receive and transmit
144          * This clears the FIFO.
145          */
146         XUartPs_WriteReg(BaseAddress, XUARTPS_CR_OFFSET,
147                                 XUARTPS_CR_TXRST | XUARTPS_CR_RXRST);
148
149         /*
150          * Clear status flags - SW reset wont clear sticky flags.
151          */
152         XUartPs_WriteReg(BaseAddress, XUARTPS_ISR_OFFSET, XUARTPS_IXR_MASK);
153
154         /*
155          * Mode register reset value : All zeroes
156          * Normal mode, even parity, 1 stop bit
157          */
158         XUartPs_WriteReg(BaseAddress, XUARTPS_MR_OFFSET,
159                                 XUARTPS_MR_CHMODE_NORM);
160
161         /*
162          * Rx and TX trigger register reset values
163          */
164         XUartPs_WriteReg(BaseAddress, XUARTPS_RXWM_OFFSET,
165                                 XUARTPS_RXWM_RESET_VAL);
166         XUartPs_WriteReg(BaseAddress, XUARTPS_TXWM_OFFSET,
167                                 XUARTPS_TXWM_RESET_VAL);
168
169         /*
170          * Rx timeout disabled by default
171          */
172         XUartPs_WriteReg(BaseAddress, XUARTPS_RXTOUT_OFFSET,
173                                 XUARTPS_RXTOUT_DISABLE);
174
175         /*
176          * Baud rate generator and dividor reset values
177          */
178         XUartPs_WriteReg(BaseAddress, XUARTPS_BAUDGEN_OFFSET,
179                                 XUARTPS_BAUDGEN_RESET_VAL);
180         XUartPs_WriteReg(BaseAddress, XUARTPS_BAUDDIV_OFFSET,
181                                 XUARTPS_BAUDDIV_RESET_VAL);
182
183         /*
184          * Control register reset value -
185          * RX and TX are disable by default
186          */
187         XUartPs_WriteReg(BaseAddress, XUARTPS_CR_OFFSET,
188                                 XUARTPS_CR_RX_DIS | XUARTPS_CR_TX_DIS |
189                                 XUARTPS_CR_STOPBRK);
190
191 }
192