]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/coresightps_dcc_v1_2/src/xcoresightpsdcc.c
Update the Xilinx UltraScale+ 64-bit demo to use the hardware definition and BSP...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / coresightps_dcc_v1_2 / src / xcoresightpsdcc.c
1 /******************************************************************************
2 *
3 * Copyright (C) 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 xcoresightpsdcc.c
36 * @addtogroup coresightps_dcc_v1_1
37 * @{
38 *
39 * Functions in this file are the minimum required functions for the
40 * XCoreSightPs driver.
41 *
42 * @note         None.
43 *
44 *
45 * <pre>
46 * MODIFICATION HISTORY:
47 *
48 * Ver   Who    Date             Changes
49 * ----- -----  -------- -----------------------------------------------
50 * 1.00  kvn    02/14/15 First release
51 * 1.1   kvn    06/12/15 Add support for Zynq Ultrascale+ MP.
52 *       kvn    08/18/15 Modified Makefile according to compiler changes.
53 * 1.2   kvn    10/09/15 Add support for IAR Compiler.
54 *
55 * </pre>
56 *
57 ******************************************************************************/
58
59 /***************************** Include Files *********************************/
60
61 #include <xil_types.h>
62 #include <xpseudo_asm.h>
63
64 #ifdef __ICCARM__
65 #define INLINE
66 #else
67 #define INLINE __inline
68 #endif
69
70 /* DCC Status Bits */
71 #define XCORESIGHTPS_DCC_STATUS_RX (1 << 30)
72 #define XCORESIGHTPS_DCC_STATUS_TX (1 << 29)
73
74 static INLINE u32 XCoresightPs_DccGetStatus(void);
75
76 /****************************************************************************/
77 /**
78 *
79 * This functions sends a single byte using the DCC. It is blocking in that it
80 * waits for the transmitter to become non-full before it writes the byte to
81 * the transmit register.
82 *
83 * @param        BaseAddress is a dummy parameter to match the function proto
84 *               of functions for other stdio devices.
85 * @param        Data is the byte of data to send
86 *
87 * @return       None.
88 *
89 * @note         None.
90 *
91 ******************************************************************************/
92 void XCoresightPs_DccSendByte(u32 BaseAddress, u8 Data)
93 {
94         (void) BaseAddress;
95         while (XCoresightPs_DccGetStatus() & XCORESIGHTPS_DCC_STATUS_TX)
96         dsb();
97 #ifdef __aarch64__
98         asm volatile ("msr dbgdtrtx_el0, %0" : : "r" (Data));
99 #elif defined (__GNUC__) || defined (__ICCARM__)
100         asm volatile("mcr p14, 0, %0, c0, c5, 0"
101                         : : "r" (Data));
102 #else
103         {
104                 volatile register u32 Reg __asm("cp14:0:c0:c5:0");
105                 Reg = Data;
106         }
107 #endif
108         isb();
109
110 }
111
112 /****************************************************************************/
113 /**
114 *
115 * This functions receives a single byte using the DCC. It is blocking in that
116 * it waits for the receiver to become non-empty before it reads from the
117 * receive register.
118 *
119 * @param        BaseAddress is a dummy parameter to match the function proto
120 *               of functions for other stdio devices.
121 *
122 * @return       The byte of data received.
123 *
124 * @note         None.
125 *
126 ******************************************************************************/
127 u8 XCoresightPs_DccRecvByte(u32 BaseAddress)
128 {
129         u8 Data;
130         (void) BaseAddress;
131
132         while (!(XCoresightPs_DccGetStatus() & XCORESIGHTPS_DCC_STATUS_RX))
133                 dsb();
134
135 #ifdef __aarch64__
136         asm volatile ("mrs %0, dbgdtrrx_el0" : "=r" (Data));
137 #elif defined (__GNUC__) || defined (__ICCARM__)
138         asm volatile("mrc p14, 0, %0, c0, c5, 0"
139                         : "=r" (Data));
140 #else
141         {
142                 volatile register u32 Reg __asm("cp14:0:c0:c5:0");
143                 Data = Reg;
144         }
145 #endif
146         isb();
147
148         return Data;
149 }
150
151
152 /****************************************************************************/
153 /**INLINE
154 *
155 * This functions read the status register of the DCC.
156 *
157 * @param        BaseAddress is the base address of the device
158 *
159 * @return       The contents of the Status Register.
160 *
161 * @note         None.
162 *
163 ******************************************************************************/
164 static INLINE u32 XCoresightPs_DccGetStatus(void)
165 {
166         u32 Status;
167
168 #ifdef __aarch64__
169         asm volatile ("mrs %0, mdccsr_el0" : "=r" (Status));
170 #elif defined (__GNUC__) || defined (__ICCARM__)
171         asm volatile("mrc p14, 0, %0, c0, c1, 0"
172                         : "=r" (Status) : : "cc");
173 #else
174         {
175                 volatile register u32 Reg __asm("cp14:0:c0:c1:0");
176                 Status = Reg;
177         }
178 #endif
179         return Status;
180 }
181 /** @} */