1 /***************************************************************************
2 * Copyright (C) 2015 Paul Fertser <fercerpav@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 ***************************************************************************/
18 #ifndef OPENOCD_TARGET_ARMV7M_TRACE_H
19 #define OPENOCD_TARGET_ARMV7M_TRACE_H
21 #include <server/server.h>
22 #include <target/target.h>
27 * Holds the interface to TPIU, ITM and DWT configuration functions.
30 enum trace_config_type {
31 TRACE_CONFIG_TYPE_DISABLED, /**< tracing is disabled */
32 TRACE_CONFIG_TYPE_EXTERNAL, /**< trace output is captured externally */
33 TRACE_CONFIG_TYPE_INTERNAL /**< trace output is handled by OpenOCD adapter driver */
36 enum trace_internal_channel {
37 TRACE_INTERNAL_CHANNEL_TCL_ONLY, /** trace data is sent only to 'tcl_trace' */
38 TRACE_INTERNAL_CHANNEL_FILE, /** trace data is appended to a file */
39 TRACE_INTERNAL_CHANNEL_TCP /** trace data is appended to a TCP/IP port*/
42 enum tpiu_pin_protocol {
43 TPIU_PIN_PROTOCOL_SYNC, /**< synchronous trace output */
44 TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER, /**< asynchronous output with Manchester coding */
45 TPIU_PIN_PROTOCOL_ASYNC_UART /**< asynchronous output with NRZ coding */
48 enum itm_ts_prescaler {
49 ITM_TS_PRESCALE1, /**< no prescaling for the timestamp counter */
50 ITM_TS_PRESCALE4, /**< refclock divided by 4 for the timestamp counter */
51 ITM_TS_PRESCALE16, /**< refclock divided by 16 for the timestamp counter */
52 ITM_TS_PRESCALE64, /**< refclock divided by 64 for the timestamp counter */
55 struct armv7m_trace_config {
56 /** Currently active trace capture mode */
57 enum trace_config_type config_type;
59 /** The used channel when internal mode is selected */
60 enum trace_internal_channel internal_channel;
62 /** Currently active trace output mode */
63 enum tpiu_pin_protocol pin_protocol;
64 /** TPIU formatter enable/disable (in async mode) */
66 /** Synchronous output port width */
69 /** Bitmask of currently enabled ITM stimuli */
71 /** Identifier for multi-source trace stream formatting */
72 unsigned int trace_bus_id;
73 /** Prescaler for the timestamp counter */
74 enum itm_ts_prescaler itm_ts_prescale;
75 /** Enable differential timestamps */
76 bool itm_diff_timestamps;
77 /** Enable async timestamps model */
78 bool itm_async_timestamps;
79 /** Enable synchronisation packet transmission (for sync port only) */
80 bool itm_synchro_packets;
81 /** Config ITM after target examine */
82 bool itm_deferred_config;
84 /** Current frequency of TRACECLKIN (usually matches HCLK) */
85 unsigned int traceclkin_freq;
86 /** Current frequency of trace port */
87 unsigned int trace_freq;
88 /** Handle to output trace data in INTERNAL capture mode via file */
90 /** Handle to output trace data in INTERNAL capture mode via tcp */
91 struct service *trace_service;
94 extern const struct command_registration armv7m_trace_command_handlers[];
97 * Configure hardware accordingly to the current TPIU target settings
99 int armv7m_trace_tpiu_config(struct target *target);
101 * Disable TPIU data gathering at exit
103 int armv7m_trace_tpiu_exit(struct target *target);
105 * Configure hardware accordingly to the current ITM target settings
107 int armv7m_trace_itm_config(struct target *target);
109 #endif /* OPENOCD_TARGET_ARMV7M_TRACE_H */