systemview  1.3.1
systemview
SEGGER_SYSVIEW.h
1 /*********************************************************************
2 * SEGGER Microcontroller GmbH & Co. KG *
3 * The Embedded Experts *
4 **********************************************************************
5 * *
6 * (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
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 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 * conditions are met: *
25 * *
26 * o Redistributions of source code must retain the above copyright *
27 * notice, this list of conditions and the following disclaimer. *
28 * *
29 * o Redistributions in binary form must reproduce the above *
30 * copyright notice, this list of conditions and the following *
31 * disclaimer in the documentation and/or other materials provided *
32 * with the distribution. *
33 * *
34 * o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
35 * nor the names of its contributors may be used to endorse or *
36 * promote products derived from this software without specific *
37 * prior written permission. *
38 * *
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
40 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
41 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
43 * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
44 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
45 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
46 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
47 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
48 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
49 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
50 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
51 * DAMAGE. *
52 * *
53 **********************************************************************
54 * *
55 * SystemView version: V2.52a *
56 * *
57 **********************************************************************
58 * *
59 * Copyright 2017-2020 MicroEJ Corp. This file has been modified by MicroEJ Corp. *
60 * *
61 **********************************************************************
62 -------------------------- END-OF-HEADER -----------------------------
63 File : SEGGER_SYSVIEW.h
64 Purpose : System visualization API.
65 Revision: $Rev: 5497 $
66 */
67 
68 #ifndef SEGGER_SYSVIEW_H
69 #define SEGGER_SYSVIEW_H
70 
71 /*********************************************************************
72 *
73 * #include Section
74 *
75 **********************************************************************
76 */
77 
78 #include "SEGGER.h"
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
84 
85 /*********************************************************************
86 *
87 * Defines, fixed
88 *
89 **********************************************************************
90 */
91 
92 #define SEGGER_SYSVIEW_VERSION 21000
93 
94 #define SEGGER_SYSVIEW_INFO_SIZE 9 // Minimum size, which has to be reserved for a packet. 1-2 byte of message type, 0-2 byte of payload length, 1-5 bytes of timestamp.
95 #define SEGGER_SYSVIEW_QUANTA_U32 5 // Maximum number of bytes to encode a U32, should be reserved for each 32-bit value in a packet.
96 
97 #define SEGGER_SYSVIEW_LOG (0u)
98 #define SEGGER_SYSVIEW_WARNING (1u)
99 #define SEGGER_SYSVIEW_ERROR (2u)
100 #define SEGGER_SYSVIEW_FLAG_APPEND (1u << 6)
101 
102 #define SEGGER_SYSVIEW_PREPARE_PACKET(p) (p) + 4
103 //
104 // SystemView events. First 32 IDs from 0 .. 31 are reserved for these
105 //
106 #define SYSVIEW_EVTID_NOP 0 // Dummy packet.
107 #define SYSVIEW_EVTID_OVERFLOW 1
108 #define SYSVIEW_EVTID_ISR_ENTER 2
109 #define SYSVIEW_EVTID_ISR_EXIT 3
110 #define SYSVIEW_EVTID_TASK_START_EXEC 4
111 #define SYSVIEW_EVTID_TASK_STOP_EXEC 5
112 #define SYSVIEW_EVTID_TASK_START_READY 6
113 #define SYSVIEW_EVTID_TASK_STOP_READY 7
114 #define SYSVIEW_EVTID_TASK_CREATE 8
115 #define SYSVIEW_EVTID_TASK_INFO 9
116 #define SYSVIEW_EVTID_TRACE_START 10
117 #define SYSVIEW_EVTID_TRACE_STOP 11
118 #define SYSVIEW_EVTID_SYSTIME_CYCLES 12
119 #define SYSVIEW_EVTID_SYSTIME_US 13
120 #define SYSVIEW_EVTID_SYSDESC 14
121 #define SYSVIEW_EVTID_USER_START 15
122 #define SYSVIEW_EVTID_USER_STOP 16
123 #define SYSVIEW_EVTID_IDLE 17
124 #define SYSVIEW_EVTID_ISR_TO_SCHEDULER 18
125 #define SYSVIEW_EVTID_TIMER_ENTER 19
126 #define SYSVIEW_EVTID_TIMER_EXIT 20
127 #define SYSVIEW_EVTID_STACK_INFO 21
128 #define SYSVIEW_EVTID_MODULEDESC 22
129 
130 #define SYSVIEW_EVTID_INIT 24
131 #define SYSVIEW_EVTID_NAME_RESOURCE 25
132 #define SYSVIEW_EVTID_PRINT_FORMATTED 26
133 #define SYSVIEW_EVTID_NUMMODULES 27
134 #define SYSVIEW_EVTID_END_CALL 28
135 #define SYSVIEW_EVTID_TASK_TERMINATE 29
136 
137 #define SYSVIEW_EVTID_EX 31
138 //
139 // Event masks to disable/enable events
140 //
141 #define SYSVIEW_EVTMASK_NOP (1 << SYSVIEW_EVTID_NOP)
142 #define SYSVIEW_EVTMASK_OVERFLOW (1 << SYSVIEW_EVTID_OVERFLOW)
143 #define SYSVIEW_EVTMASK_ISR_ENTER (1 << SYSVIEW_EVTID_ISR_ENTER)
144 #define SYSVIEW_EVTMASK_ISR_EXIT (1 << SYSVIEW_EVTID_ISR_EXIT)
145 #define SYSVIEW_EVTMASK_TASK_START_EXEC (1 << SYSVIEW_EVTID_TASK_START_EXEC)
146 #define SYSVIEW_EVTMASK_TASK_STOP_EXEC (1 << SYSVIEW_EVTID_TASK_STOP_EXEC)
147 #define SYSVIEW_EVTMASK_TASK_START_READY (1 << SYSVIEW_EVTID_TASK_START_READY)
148 #define SYSVIEW_EVTMASK_TASK_STOP_READY (1 << SYSVIEW_EVTID_TASK_STOP_READY)
149 #define SYSVIEW_EVTMASK_TASK_CREATE (1 << SYSVIEW_EVTID_TASK_CREATE)
150 #define SYSVIEW_EVTMASK_TASK_INFO (1 << SYSVIEW_EVTID_TASK_INFO)
151 #define SYSVIEW_EVTMASK_TRACE_START (1 << SYSVIEW_EVTID_TRACE_START)
152 #define SYSVIEW_EVTMASK_TRACE_STOP (1 << SYSVIEW_EVTID_TRACE_STOP)
153 #define SYSVIEW_EVTMASK_SYSTIME_CYCLES (1 << SYSVIEW_EVTID_SYSTIME_CYCLES)
154 #define SYSVIEW_EVTMASK_SYSTIME_US (1 << SYSVIEW_EVTID_SYSTIME_US)
155 #define SYSVIEW_EVTMASK_SYSDESC (1 << SYSVIEW_EVTID_SYSDESC)
156 #define SYSVIEW_EVTMASK_USER_START (1 << SYSVIEW_EVTID_USER_START)
157 #define SYSVIEW_EVTMASK_USER_STOP (1 << SYSVIEW_EVTID_USER_STOP)
158 #define SYSVIEW_EVTMASK_IDLE (1 << SYSVIEW_EVTID_IDLE)
159 #define SYSVIEW_EVTMASK_ISR_TO_SCHEDULER (1 << SYSVIEW_EVTID_ISR_TO_SCHEDULER)
160 #define SYSVIEW_EVTMASK_TIMER_ENTER (1 << SYSVIEW_EVTID_TIMER_ENTER)
161 #define SYSVIEW_EVTMASK_TIMER_EXIT (1 << SYSVIEW_EVTID_TIMER_EXIT)
162 #define SYSVIEW_EVTMASK_STACK_INFO (1 << SYSVIEW_EVTID_STACK_INFO)
163 #define SYSVIEW_EVTMASK_MODULEDESC (1 << SYSVIEW_EVTID_MODULEDESC)
164 
165 #define SYSVIEW_EVTMASK_INIT (1 << SYSVIEW_EVTID_INIT)
166 #define SYSVIEW_EVTMASK_NAME_RESOURCE (1 << SYSVIEW_EVTID_NAME_RESOURCE)
167 #define SYSVIEW_EVTMASK_PRINT_FORMATTED (1 << SYSVIEW_EVTID_PRINT_FORMATTED)
168 #define SYSVIEW_EVTMASK_NUMMODULES (1 << SYSVIEW_EVTID_NUMMODULES)
169 #define SYSVIEW_EVTMASK_END_CALL (1 << SYSVIEW_EVTID_END_CALL)
170 #define SYSVIEW_EVTMASK_TASK_TERMINATE (1 << SYSVIEW_EVTID_TASK_TERMINATE)
171 
172 #define SYSVIEW_EVTMASK_EX (1 << SYSVIEW_EVTID_EX)
173 
174 #define SYSVIEW_EVTMASK_ALL_INTERRUPTS ( SYSVIEW_EVTMASK_ISR_ENTER \
175  | SYSVIEW_EVTMASK_ISR_EXIT \
176  | SYSVIEW_EVTMASK_ISR_TO_SCHEDULER)
177 #define SYSVIEW_EVTMASK_ALL_TASKS ( SYSVIEW_EVTMASK_TASK_START_EXEC \
178  | SYSVIEW_EVTMASK_TASK_STOP_EXEC \
179  | SYSVIEW_EVTMASK_TASK_START_READY \
180  | SYSVIEW_EVTMASK_TASK_STOP_READY \
181  | SYSVIEW_EVTMASK_TASK_CREATE \
182  | SYSVIEW_EVTMASK_TASK_INFO \
183  | SYSVIEW_EVTMASK_STACK_INFO \
184  | SYSVIEW_EVTMASK_TASK_TERMINATE)
185 
186 /*********************************************************************
187 *
188 * Structures
189 *
190 **********************************************************************
191 */
192 
193 typedef struct {
194  U32 TaskID;
195  const char* sName;
196  U32 Prio;
197  U32 StackBase;
198  U32 StackSize;
199  U32 IsMicroEJThread; // Added by MicroEJ Corp.
201 
202 typedef struct SEGGER_SYSVIEW_MODULE_STRUCT SEGGER_SYSVIEW_MODULE;
203 
205  const char* sModule;
206  U32 NumEvents;
207  U32 EventOffset;
208  void (*pfSendModuleDesc)(void);
209  SEGGER_SYSVIEW_MODULE* pNext;
210 };
211 
212 typedef void (SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC)(void);
213 
214 /*********************************************************************
215 *
216 * API functions
217 *
218 **********************************************************************
219 */
220 
221 typedef struct {
222  U64 (*pfGetTime) (void);
223  void (*pfSendTaskList) (void);
225 
226 /*********************************************************************
227 *
228 * Control and initialization functions
229 */
230 void SEGGER_SYSVIEW_Init (U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc);
231 void SEGGER_SYSVIEW_SetRAMBase (U32 RAMBaseAddress);
232 void SEGGER_SYSVIEW_Start (void);
233 void SEGGER_SYSVIEW_Stop (void);
234 void SEGGER_SYSVIEW_GetSysDesc (void);
235 void SEGGER_SYSVIEW_SendTaskList (void);
236 void SEGGER_SYSVIEW_SendTaskInfo (const SEGGER_SYSVIEW_TASKINFO* pInfo);
237 void SEGGER_SYSVIEW_SendSysDesc (const char* sSysDesc);
238 int SEGGER_SYSVIEW_isConnected (void); // Added by MicroEJ Corp.
239 void SEGGER_SYSVIEW_setMicroJVMTask (U32); // Added by MicroEJ Corp.
240 void SEGGER_SYSVIEW_setMicroJVMTaskPriority (U32); // Added by MicroEJ Corp.
241 void SEGGER_SYSVIEW_setCurrentMicroEJTask (U32); // Added by MicroEJ Corp.
242 
243 /*********************************************************************
244 *
245 * Event recording functions
246 */
247 void SEGGER_SYSVIEW_RecordVoid (unsigned int EventId);
248 void SEGGER_SYSVIEW_RecordU32 (unsigned int EventId, U32 Para0);
249 void SEGGER_SYSVIEW_RecordU32x2 (unsigned int EventId, U32 Para0, U32 Para1);
250 void SEGGER_SYSVIEW_RecordU32x3 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2);
251 void SEGGER_SYSVIEW_RecordU32x4 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3);
252 void SEGGER_SYSVIEW_RecordU32x5 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4);
253 void SEGGER_SYSVIEW_RecordU32x6 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5);
254 void SEGGER_SYSVIEW_RecordU32x7 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6);
255 void SEGGER_SYSVIEW_RecordU32x8 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7);
256 void SEGGER_SYSVIEW_RecordU32x9 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8);
257 void SEGGER_SYSVIEW_RecordU32x10 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8, U32 Para9);
258 void SEGGER_SYSVIEW_RecordString (unsigned int EventId, const char* pString);
259 void SEGGER_SYSVIEW_RecordSystime (void);
260 void SEGGER_SYSVIEW_RecordEnterISR (void);
261 void SEGGER_SYSVIEW_RecordExitISR (void);
262 void SEGGER_SYSVIEW_RecordExitISRToScheduler (void);
263 void SEGGER_SYSVIEW_RecordEnterTimer (U32 TimerId);
264 void SEGGER_SYSVIEW_RecordExitTimer (void);
265 void SEGGER_SYSVIEW_RecordEndCall (unsigned int EventID);
266 void SEGGER_SYSVIEW_RecordEndCallU32 (unsigned int EventID, U32 Para0);
267 
268 void SEGGER_SYSVIEW_OnIdle (void);
269 void SEGGER_SYSVIEW_OnTaskCreate (U32 TaskId);
270 void SEGGER_SYSVIEW_OnTaskTerminate (U32 TaskId);
271 void SEGGER_SYSVIEW_OnTaskStartExec (U32 TaskId);
272 void SEGGER_SYSVIEW_OnTaskStopExec (void);
273 void SEGGER_SYSVIEW_OnTaskStartReady (U32 TaskId);
274 void SEGGER_SYSVIEW_OnTaskStopReady (U32 TaskId, unsigned int Cause);
275 void SEGGER_SYSVIEW_OnUserStart (unsigned int UserId); // Start of user defined event (such as a subroutine to profile)
276 void SEGGER_SYSVIEW_OnUserStop (unsigned int UserId); // Start of user defined event
277 
278 void SEGGER_SYSVIEW_NameResource (U32 ResourceId, const char* sName);
279 
280 int SEGGER_SYSVIEW_SendPacket (U8* pPacket, U8* pPayloadEnd, unsigned int EventId);
281 
282 /*********************************************************************
283 *
284 * Event parameter encoding functions
285 */
286 U8* SEGGER_SYSVIEW_EncodeU32 (U8* pPayload, U32 Value);
287 U8* SEGGER_SYSVIEW_EncodeData (U8* pPayload, const char* pSrc, unsigned int Len);
288 U8* SEGGER_SYSVIEW_EncodeString (U8* pPayload, const char* s, unsigned int MaxLen);
289 U8* SEGGER_SYSVIEW_EncodeId (U8* pPayload, U32 Id);
290 U32 SEGGER_SYSVIEW_ShrinkId (U32 Id);
291 
292 
293 /*********************************************************************
294 *
295 * Middleware module registration
296 */
297 void SEGGER_SYSVIEW_RegisterModule (SEGGER_SYSVIEW_MODULE* pModule);
298 void SEGGER_SYSVIEW_RecordModuleDescription (const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription);
299 void SEGGER_SYSVIEW_SendModule (U8 ModuleId);
300 void SEGGER_SYSVIEW_SendModuleDescription (void);
301 void SEGGER_SYSVIEW_SendNumModules (void);
302 
303 /*********************************************************************
304 *
305 * printf-Style functions
306 */
307 #ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
308 void SEGGER_SYSVIEW_PrintfHostEx (const char* s, U32 Options, ...);
309 void SEGGER_SYSVIEW_PrintfTargetEx (const char* s, U32 Options, ...);
310 void SEGGER_SYSVIEW_PrintfHost (const char* s, ...);
311 void SEGGER_SYSVIEW_PrintfTarget (const char* s, ...);
312 void SEGGER_SYSVIEW_WarnfHost (const char* s, ...);
313 void SEGGER_SYSVIEW_WarnfTarget (const char* s, ...);
314 void SEGGER_SYSVIEW_ErrorfHost (const char* s, ...);
315 void SEGGER_SYSVIEW_ErrorfTarget (const char* s, ...);
316 #endif
317 
318 void SEGGER_SYSVIEW_Print (const char* s);
319 void SEGGER_SYSVIEW_Warn (const char* s);
320 void SEGGER_SYSVIEW_Error (const char* s);
321 
322 /*********************************************************************
323 *
324 * Run-time configuration functions
325 */
326 void SEGGER_SYSVIEW_EnableEvents (U32 EnableMask);
327 void SEGGER_SYSVIEW_DisableEvents (U32 DisableMask);
328 
329 /*********************************************************************
330 *
331 * Application-provided functions
332 */
333 void SEGGER_SYSVIEW_Conf (void);
334 U32 SEGGER_SYSVIEW_X_GetTimestamp (void);
335 U32 SEGGER_SYSVIEW_X_GetInterruptId (void);
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 
341 #endif
342 
343 /*************************** End of file ****************************/