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