96c18958700bbc76ba1b748c752391bcd932354f
[fw/openocd] / src / target / armv7m_trace.h
1 /***************************************************************************
2  *   Copyright (C) 2015  Paul Fertser <fercerpav@gmail.com>                *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  ***************************************************************************/
14
15 #ifndef ARMV7M_TRACE_H
16 #define ARMV7M_TRACE_H
17
18 #include <command.h>
19
20 /**
21  * @file
22  * Holds the interface to TPIU, ITM and DWT configuration functions.
23  */
24
25 enum trace_config_type {
26         DISABLED,       /**< tracing is disabled */
27         EXTERNAL,       /**< trace output is captured externally */
28         INTERNAL        /**< trace output is handled by OpenOCD adapter driver */
29 };
30
31 enum tpio_pin_protocol {
32         SYNC,                   /**< synchronous trace output */
33         ASYNC_MANCHESTER,       /**< asynchronous output with Manchester coding */
34         ASYNC_UART              /**< asynchronous output with NRZ coding */
35 };
36
37 enum itm_ts_prescaler {
38         ITM_TS_PRESCALE1,       /**< no prescaling for the timestamp counter */
39         ITM_TS_PRESCALE4,       /**< refclock divided by 4 for the timestamp counter */
40         ITM_TS_PRESCALE16,      /**< refclock divided by 16 for the timestamp counter */
41         ITM_TS_PRESCALE64,      /**< refclock divided by 64 for the timestamp counter */
42 };
43
44 struct armv7m_trace_config {
45         /** Currently active trace capture mode */
46         enum trace_config_type config_type;
47
48         /** Currently active trace output mode */
49         enum tpio_pin_protocol pin_protocol;
50         /** TPIU formatter enable/disable (in async mode) */
51         bool formatter;
52         /** Synchronous output port width */
53         uint32_t port_size;
54
55         /** Bitmask of currenty enabled ITM stimuli */
56         uint32_t itm_ter[8];
57         /** Identifier for multi-source trace stream formatting */
58         unsigned int trace_bus_id;
59         /** Prescaler for the timestamp counter */
60         enum itm_ts_prescaler itm_ts_prescale;
61         /** Enable differential timestamps */
62         bool itm_diff_timestamps;
63         /** Enable async timestamps model */
64         bool itm_async_timestamps;
65         /** Enable synchronisation packet transmission (for sync port only) */
66         bool itm_synchro_packets;
67
68         /** Current frequency of TRACECLKIN (usually matches HCLK) */
69         unsigned int traceclkin_freq;
70         /** Current frequency of trace port */
71         unsigned int trace_freq;
72         /** Handle to output trace data in INTERNAL capture mode */
73         FILE *trace_file;
74 };
75
76 extern const struct command_registration armv7m_trace_command_handlers[];
77
78 /**
79  * Configure hardware accordingly to the current TPIU target settings
80  */
81 int armv7m_trace_tpiu_config(struct target *target);
82 /**
83  * Configure hardware accordingly to the current ITM target settings
84  */
85 int armv7m_trace_itm_config(struct target *target);
86
87 #endif