1 /******************************************************************************
3 * Copyright (C) 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 /*****************************************************************************/
35 * @file xcoresightpsdcc.c
36 * @addtogroup coresightps_dcc_v1_1
39 * Functions in this file are the minimum required functions for the
40 * XCoreSightPs driver.
46 * MODIFICATION HISTORY:
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.
57 ******************************************************************************/
59 /***************************** Include Files *********************************/
61 #include <xil_types.h>
62 #include <xpseudo_asm.h>
67 #define INLINE __inline
71 #define XCORESIGHTPS_DCC_STATUS_RX (1 << 30)
72 #define XCORESIGHTPS_DCC_STATUS_TX (1 << 29)
74 static INLINE u32 XCoresightPs_DccGetStatus(void);
76 /****************************************************************************/
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.
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
91 ******************************************************************************/
92 void XCoresightPs_DccSendByte(u32 BaseAddress, u8 Data)
95 while (XCoresightPs_DccGetStatus() & XCORESIGHTPS_DCC_STATUS_TX)
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"
104 volatile register u32 Reg __asm("cp14:0:c0:c5:0");
112 /****************************************************************************/
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
119 * @param BaseAddress is a dummy parameter to match the function proto
120 * of functions for other stdio devices.
122 * @return The byte of data received.
126 ******************************************************************************/
127 u8 XCoresightPs_DccRecvByte(u32 BaseAddress)
132 while (!(XCoresightPs_DccGetStatus() & XCORESIGHTPS_DCC_STATUS_RX))
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"
142 volatile register u32 Reg __asm("cp14:0:c0:c5:0");
152 /****************************************************************************/
155 * This functions read the status register of the DCC.
157 * @param BaseAddress is the base address of the device
159 * @return The contents of the Status Register.
163 ******************************************************************************/
164 static INLINE u32 XCoresightPs_DccGetStatus(void)
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");
175 volatile register u32 Reg __asm("cp14:0:c0:c1:0");