µOS++ IIIe Reference 6.3.17
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
trace-itm.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2015 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#if defined(__ARM_EABI__)
29
30// ----------------------------------------------------------------------------
31
32#if defined(TRACE)
33
34#include <cmsis-plus/os-app-config.h>
35
36#if defined(OS_USE_TRACE_ITM)
37
39
40// TODO: Find a better way to include the ITM definitions (including
41// the entire vendor header is averkill).
42#include <cmsis_device.h>
43
44// ----------------------------------------------------------------------------
45
46namespace os
47{
48 namespace trace
49 {
50 // ------------------------------------------------------------------------
51
52 void
53 initialize (void)
54 {
55 // For ITM no inits required.
56 // The debug registers are set the JTAG software.
57 }
58
59 // ----------------------------------------------------------------------
60
61#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
62
63 // ITM is the ARM standard mechanism, running over SWD/SWO on Cortex-M3/M4
64 // devices, and is the recommended setting, if available.
65 //
66 // The JLink probe and the GDB server fully support SWD/SWO
67 // and the JLink Debugging plug-in enables it by default.
68 // The current OpenOCD does not include support to parse the SWO stream,
69 // so this configuration will not work on OpenOCD (will not crash, but
70 // nothing will be displayed in the output console).
71
72#if !defined(OS_INTEGER_TRACE_ITM_STIMULUS_PORT)
73#define OS_INTEGER_TRACE_ITM_STIMULUS_PORT (0)
74#endif
75
76 ssize_t
77 write (const void* buf, std::size_t nbyte)
78 {
79 if (buf == nullptr || nbyte == 0)
80 {
81 return 0;
82 }
83
84 const char* cbuf = (const char*) buf;
85
86 for (size_t i = 0; i < nbyte; i++)
87 {
88 // Check if ITM or the stimulus port are not enabled.
89 if (((ITM->TCR & ITM_TCR_ITMENA_Msk) == 0)
90 || ((ITM->TER & (1UL << OS_INTEGER_TRACE_ITM_STIMULUS_PORT))
91 == 0))
92 {
93 // Return the number of sent characters (may be 0).
94 return (ssize_t) i;
95 }
96
97 // Wait until STIMx is ready...
98 while (ITM->PORT[OS_INTEGER_TRACE_ITM_STIMULUS_PORT].u32 == 0)
99 ;
100 // then send data, one byte at a time
102 (uint8_t) (*cbuf++);
103 }
104
105 // All characters successfully sent.
106 return (ssize_t) nbyte;
107 }
108
109#else
110
111#error "ITM available only on ARCH 7M"
112
113#endif /* defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) */
114
115 } /* namespace trace */
116} /* namespace os */
117
118#endif /* defined(OS_USE_TRACE_ITM) */
119#endif /* defined(TRACE) */
120
121// ----------------------------------------------------------------------------
122
123#endif /* defined(__ARM_EABI__) */
124
125
#define OS_INTEGER_TRACE_ITM_STIMULUS_PORT
Define the ITM stimulus port used for the trace messages.
void initialize(void)
Definition trace.cpp:50
ssize_t write(const void *buf, std::size_t nbyte)
Write the given number of bytes to the trace output channel.
Definition trace.cpp:60
System namespace.