armv7m: add a TCP channel to stream captured trace
[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  *   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  ***************************************************************************/
17
18 #ifndef OPENOCD_TARGET_ARMV7M_TRACE_H
19 #define OPENOCD_TARGET_ARMV7M_TRACE_H
20
21 #include <server/server.h>
22 #include <target/target.h>
23 #include <command.h>
24
25 /**
26  * @file
27  * Holds the interface to TPIU, ITM and DWT configuration functions.
28  */
29
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 */
34 };
35
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*/
40 };
41
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 */
46 };
47
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 */
53 };
54
55 struct armv7m_trace_config {
56         /** Currently active trace capture mode */
57         enum trace_config_type config_type;
58
59         /** The used channel when internal mode is selected */
60         enum trace_internal_channel internal_channel;
61
62         /** Currently active trace output mode */
63         enum tpiu_pin_protocol pin_protocol;
64         /** TPIU formatter enable/disable (in async mode) */
65         bool formatter;
66         /** Synchronous output port width */
67         uint32_t port_size;
68
69         /** Bitmask of currently enabled ITM stimuli */
70         uint32_t itm_ter[8];
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
82         /** Current frequency of TRACECLKIN (usually matches HCLK) */
83         unsigned int traceclkin_freq;
84         /** Current frequency of trace port */
85         unsigned int trace_freq;
86         /** Handle to output trace data in INTERNAL capture mode via file */
87         FILE *trace_file;
88         /** Handle to output trace data in INTERNAL capture mode via tcp */
89         struct service *trace_service;
90 };
91
92 extern const struct command_registration armv7m_trace_command_handlers[];
93
94 /**
95  * Configure hardware accordingly to the current TPIU target settings
96  */
97 int armv7m_trace_tpiu_config(struct target *target);
98 /**
99  * Configure hardware accordingly to the current ITM target settings
100  */
101 int armv7m_trace_itm_config(struct target *target);
102
103 #endif /* OPENOCD_TARGET_ARMV7M_TRACE_H */