1 /*********************************************************************
2 *                    SEGGER Microcontroller GmbH                     *
3 *                        The Embedded Experts                        *
4 **********************************************************************
5 *                                                                    *
6 *            (c) 1995 - 2019 SEGGER Microcontroller GmbH             *
7 *                                                                    *
8 *       www.segger.com     Support: support@segger.com               *
9 *                                                                    *
10 **********************************************************************
11 *                                                                    *
12 *       SEGGER SystemView * Real-time application analysis           *
13 *                                                                    *
14 **********************************************************************
15 *                                                                    *
16 * All rights reserved.                                               *
17 *                                                                    *
18 * SEGGER strongly recommends to not make any changes                 *
19 * to or modify the source code of this software in order to stay     *
20 * compatible with the SystemView and RTT protocol, and J-Link.       *
21 *                                                                    *
22 * Redistribution and use in source and binary forms, with or         *
23 * without modification, are permitted provided that the following    *
24 * condition is met:                                                  *
25 *                                                                    *
26 * o Redistributions of source code must retain the above copyright   *
27 *   notice, this condition and the following disclaimer.             *
28 *                                                                    *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND             *
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,        *
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF           *
32 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE           *
33 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
34 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR           *
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  *
36 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;    *
37 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF      *
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT          *
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE  *
40 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH   *
41 * DAMAGE.                                                            *
42 *                                                                    *
43 **********************************************************************
44 *                                                                    *
45 *       SystemView version: 3.30                                    *
46 *                                                                    *
47 **********************************************************************
48 -------------------------- END-OF-HEADER -----------------------------
49 
50 File    : SEGGER_SYSVIEW_Config_AliOSThings.c
51 Purpose : Sample setup configuration of SystemView with AliOSThings.
52 Revision: $Rev: 7745 $
53 */
54 #include "SEGGER_SYSVIEW.h"
55 
56 extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
57 
58 /*********************************************************************
59 *
60 *       Defines, configurable
61 *
62 **********************************************************************
63 */
64 // The application name to be displayed in SystemViewer
65 #define SYSVIEW_APP_NAME        "trace"
66 
67 // The target device name
68 #define SYSVIEW_DEVICE_NAME     "Cortex-M33"
69 
70 // Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h
71 #define SYSVIEW_TIMESTAMP_FREQ  (hal_sys_timer_calc_cpu_freq(5, 0))
72 
73 // System Frequency. SystemcoreClock is used in most CMSIS compatible projects.
74 #define SYSVIEW_CPU_FREQ        (hal_sys_timer_calc_cpu_freq(5, 0))
75 
76 // The lowest RAM address used for IDs (pointers)
77 #define SYSVIEW_RAM_BASE        (0x10000000)
78 
79 /*********************************************************************
80 *
81 *       Defines, fixed
82 *
83 **********************************************************************
84 */
85 #define DEMCR (*(volatile U32*)    (0xE000EDFCuL)) // Debug Exception and Monitor Control Register
86 #define TRACEENA_BIT               (1uL << 24) // Trace enable bit
87 
88 #define DWT_CTRL                  (*(volatile unsigned int*) (0xE0001000uL))  // DWT Control Register
89 #define NOCYCCNT_BIT              (1uL << 25)                           // Cycle counter support bit
90 #define CYCCNTENA_BIT             (1uL << 0)                            // Cycle counter enable bit
91 
92 // If events will be recorded without a debug probe (J-Link) attached,
93 // enable the cycle counter
94 //
95 #define ENABLE_DWT_CYCCNT (SEGGER_SYSVIEW_POST_MORTEM_MODE || SEGGER_SYSVIEW_USE_INTERNAL_RECORDER)
96 
97 /*********************************************************************
98 *
99 *       _cbSendSystemDesc()
100 *
101 *  Function description
102 *    Sends SystemView description strings.
103 */
_cbSendSystemDesc(void)104 static void _cbSendSystemDesc(void) {
105   SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=AliOSThings");
106   SEGGER_SYSVIEW_SendSysDesc("I#34=SysTick");
107 }
108 
109 /*********************************************************************
110 *
111 *       Global functions
112 *
113 **********************************************************************
114 */
SEGGER_SYSVIEW_Conf(void)115 void SEGGER_SYSVIEW_Conf(void) {
116 
117 #if ENABLE_DWT_CYCCNT
118 // If no debugger is connected, the DWT must be enabled by the application //
119 if ((DEMCR & TRACEENA_BIT) == 0) {
120     DEMCR |= TRACEENA_BIT;
121   }
122 #endif
123   //
124   //  The cycle counter must be activated in order
125   //  to use time related functions.
126   //
127   if ((DWT_CTRL & NOCYCCNT_BIT) == 0) {       // Cycle counter supported?
128     if ((DWT_CTRL & CYCCNTENA_BIT) == 0) {    // Cycle counter not enabled?
129       DWT_CTRL |= CYCCNTENA_BIT;              // Enable Cycle counter
130     }
131   }
132   SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ,
133                       &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc);
134   SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE);
135 
136 #if SEGGER_SYSVIEW_START_ON_INIT
137   SEGGER_SYSVIEW_Start();
138   // Start recording to catch system initialization.
139 #endif
140 }
141 
142 /*************************** End of file ****************************/
143