1 /******************************************************************************
3 * Copyright (C) 2015-2016 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_4
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.
54 * 1.3 asa 07/01/16 Made changes to ensure that the file does not compile
55 * for MB BSPs. Instead it throws up a warning. This
56 * fixes the CR#953056.
60 ******************************************************************************/
62 /***************************** Include Files *********************************/
64 #warning "The driver is supported only for ARM architecture"
67 #include <xil_types.h>
68 #include <xpseudo_asm.h>
73 #define INLINE __inline
77 #define XCORESIGHTPS_DCC_STATUS_RX (1 << 30)
78 #define XCORESIGHTPS_DCC_STATUS_TX (1 << 29)
80 static INLINE u32 XCoresightPs_DccGetStatus(void);
82 /****************************************************************************/
85 * This functions sends a single byte using the DCC. It is blocking in that it
86 * waits for the transmitter to become non-full before it writes the byte to
87 * the transmit register.
89 * @param BaseAddress is a dummy parameter to match the function proto
90 * of functions for other stdio devices.
91 * @param Data is the byte of data to send
97 ******************************************************************************/
98 void XCoresightPs_DccSendByte(u32 BaseAddress, u8 Data)
101 while (XCoresightPs_DccGetStatus() & XCORESIGHTPS_DCC_STATUS_TX)
104 asm volatile ("msr dbgdtrtx_el0, %0" : : "r" (Data));
105 #elif defined (__GNUC__) || defined (__ICCARM__)
106 asm volatile("mcr p14, 0, %0, c0, c5, 0"
110 volatile register u32 Reg __asm("cp14:0:c0:c5:0");
118 /****************************************************************************/
121 * This functions receives a single byte using the DCC. It is blocking in that
122 * it waits for the receiver to become non-empty before it reads from the
125 * @param BaseAddress is a dummy parameter to match the function proto
126 * of functions for other stdio devices.
128 * @return The byte of data received.
132 ******************************************************************************/
133 u8 XCoresightPs_DccRecvByte(u32 BaseAddress)
138 while (!(XCoresightPs_DccGetStatus() & XCORESIGHTPS_DCC_STATUS_RX))
142 asm volatile ("mrs %0, dbgdtrrx_el0" : "=r" (Data));
143 #elif defined (__GNUC__) || defined (__ICCARM__)
144 asm volatile("mrc p14, 0, %0, c0, c5, 0"
148 volatile register u32 Reg __asm("cp14:0:c0:c5:0");
158 /****************************************************************************/
161 * This functions read the status register of the DCC.
163 * @param BaseAddress is the base address of the device
165 * @return The contents of the Status Register.
169 ******************************************************************************/
170 static INLINE u32 XCoresightPs_DccGetStatus(void)
175 asm volatile ("mrs %0, mdccsr_el0" : "=r" (Status));
176 #elif defined (__GNUC__) || defined (__ICCARM__)
177 asm volatile("mrc p14, 0, %0, c0, c1, 0"
178 : "=r" (Status) : : "cc");
181 volatile register u32 Reg __asm("cp14:0:c0:c1:0");