SmartSnippets DA1459x SDK
SEGGER_SYSVIEW.h
1 /*********************************************************************
2 * SEGGER Microcontroller GmbH *
3 * The Embedded Experts *
4 **********************************************************************
5 * *
6 * (c) 1995 - 2021 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 File : SEGGER_SYSVIEW.h
50 Purpose : System visualization API.
51 Revision: $Rev: 21292 $
52 */
53 
54 #ifndef SEGGER_SYSVIEW_H
55 #define SEGGER_SYSVIEW_H
56 
57 #if (dg_configSYSTEMVIEW == 1)
58 
59 /*********************************************************************
60 *
61 * #include Section
62 *
63 **********************************************************************
64 */
65 
66 #include "SEGGER.h"
67 #include "SEGGER_SYSVIEW_ConfDefaults.h"
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
73 
74 /*********************************************************************
75 *
76 * Defines, fixed
77 *
78 **********************************************************************
79 */
80 
81 #define SEGGER_SYSVIEW_MAJOR 3
82 #define SEGGER_SYSVIEW_MINOR 10
83 #define SEGGER_SYSVIEW_REV 0
84 #define SEGGER_SYSVIEW_VERSION ((SEGGER_SYSVIEW_MAJOR * 10000) + (SEGGER_SYSVIEW_MINOR * 100) + SEGGER_SYSVIEW_REV)
85 
86 #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.
87 #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.
88 
89 #define SEGGER_SYSVIEW_LOG (0u)
90 #define SEGGER_SYSVIEW_WARNING (1u)
91 #define SEGGER_SYSVIEW_ERROR (2u)
92 #define SEGGER_SYSVIEW_FLAG_APPEND (1u << 6)
93 
94 #define SEGGER_SYSVIEW_PREPARE_PACKET(p) (p) + 4
95 //
96 // SystemView events. First 32 IDs from 0 .. 31 are reserved for these
97 //
98 #define SYSVIEW_EVTID_NOP 0 // Dummy packet.
99 #define SYSVIEW_EVTID_OVERFLOW 1
100 #define SYSVIEW_EVTID_ISR_ENTER 2
101 #define SYSVIEW_EVTID_ISR_EXIT 3
102 #define SYSVIEW_EVTID_TASK_START_EXEC 4
103 #define SYSVIEW_EVTID_TASK_STOP_EXEC 5
104 #define SYSVIEW_EVTID_TASK_START_READY 6
105 #define SYSVIEW_EVTID_TASK_STOP_READY 7
106 #define SYSVIEW_EVTID_TASK_CREATE 8
107 #define SYSVIEW_EVTID_TASK_INFO 9
108 #define SYSVIEW_EVTID_TRACE_START 10
109 #define SYSVIEW_EVTID_TRACE_STOP 11
110 #define SYSVIEW_EVTID_SYSTIME_CYCLES 12
111 #define SYSVIEW_EVTID_SYSTIME_US 13
112 #define SYSVIEW_EVTID_SYSDESC 14
113 #define SYSVIEW_EVTID_MARK_START 15
114 #define SYSVIEW_EVTID_MARK_STOP 16
115 #define SYSVIEW_EVTID_IDLE 17
116 #define SYSVIEW_EVTID_ISR_TO_SCHEDULER 18
117 #define SYSVIEW_EVTID_TIMER_ENTER 19
118 #define SYSVIEW_EVTID_TIMER_EXIT 20
119 #define SYSVIEW_EVTID_STACK_INFO 21
120 #define SYSVIEW_EVTID_MODULEDESC 22
121 
122 #define SYSVIEW_EVTID_INIT 24
123 #define SYSVIEW_EVTID_NAME_RESOURCE 25
124 #define SYSVIEW_EVTID_PRINT_FORMATTED 26
125 #define SYSVIEW_EVTID_NUMMODULES 27
126 #define SYSVIEW_EVTID_END_CALL 28
127 #define SYSVIEW_EVTID_TASK_TERMINATE 29
128 
129 #define SYSVIEW_EVTID_EX 31
130 //
131 // SystemView extended events. Sent with ID 31.
132 //
133 #define SYSVIEW_EVTID_EX_MARK 0
134 #define SYSVIEW_EVTID_EX_NAME_MARKER 1
135 //
136 // Event masks to disable/enable events
137 //
138 #define SYSVIEW_EVTMASK_NOP (1 << SYSVIEW_EVTID_NOP)
139 #define SYSVIEW_EVTMASK_OVERFLOW (1 << SYSVIEW_EVTID_OVERFLOW)
140 #define SYSVIEW_EVTMASK_ISR_ENTER (1 << SYSVIEW_EVTID_ISR_ENTER)
141 #define SYSVIEW_EVTMASK_ISR_EXIT (1 << SYSVIEW_EVTID_ISR_EXIT)
142 #define SYSVIEW_EVTMASK_TASK_START_EXEC (1 << SYSVIEW_EVTID_TASK_START_EXEC)
143 #define SYSVIEW_EVTMASK_TASK_STOP_EXEC (1 << SYSVIEW_EVTID_TASK_STOP_EXEC)
144 #define SYSVIEW_EVTMASK_TASK_START_READY (1 << SYSVIEW_EVTID_TASK_START_READY)
145 #define SYSVIEW_EVTMASK_TASK_STOP_READY (1 << SYSVIEW_EVTID_TASK_STOP_READY)
146 #define SYSVIEW_EVTMASK_TASK_CREATE (1 << SYSVIEW_EVTID_TASK_CREATE)
147 #define SYSVIEW_EVTMASK_TASK_INFO (1 << SYSVIEW_EVTID_TASK_INFO)
148 #define SYSVIEW_EVTMASK_TRACE_START (1 << SYSVIEW_EVTID_TRACE_START)
149 #define SYSVIEW_EVTMASK_TRACE_STOP (1 << SYSVIEW_EVTID_TRACE_STOP)
150 #define SYSVIEW_EVTMASK_SYSTIME_CYCLES (1 << SYSVIEW_EVTID_SYSTIME_CYCLES)
151 #define SYSVIEW_EVTMASK_SYSTIME_US (1 << SYSVIEW_EVTID_SYSTIME_US)
152 #define SYSVIEW_EVTMASK_SYSDESC (1 << SYSVIEW_EVTID_SYSDESC)
153 #define SYSVIEW_EVTMASK_USER_START (1 << SYSVIEW_EVTID_USER_START)
154 #define SYSVIEW_EVTMASK_USER_STOP (1 << SYSVIEW_EVTID_USER_STOP)
155 #define SYSVIEW_EVTMASK_IDLE (1 << SYSVIEW_EVTID_IDLE)
156 #define SYSVIEW_EVTMASK_ISR_TO_SCHEDULER (1 << SYSVIEW_EVTID_ISR_TO_SCHEDULER)
157 #define SYSVIEW_EVTMASK_TIMER_ENTER (1 << SYSVIEW_EVTID_TIMER_ENTER)
158 #define SYSVIEW_EVTMASK_TIMER_EXIT (1 << SYSVIEW_EVTID_TIMER_EXIT)
159 #define SYSVIEW_EVTMASK_STACK_INFO (1 << SYSVIEW_EVTID_STACK_INFO)
160 #define SYSVIEW_EVTMASK_MODULEDESC (1 << SYSVIEW_EVTID_MODULEDESC)
161 
162 #define SYSVIEW_EVTMASK_INIT (1 << SYSVIEW_EVTID_INIT)
163 #define SYSVIEW_EVTMASK_NAME_RESOURCE (1 << SYSVIEW_EVTID_NAME_RESOURCE)
164 #define SYSVIEW_EVTMASK_PRINT_FORMATTED (1 << SYSVIEW_EVTID_PRINT_FORMATTED)
165 #define SYSVIEW_EVTMASK_NUMMODULES (1 << SYSVIEW_EVTID_NUMMODULES)
166 #define SYSVIEW_EVTMASK_END_CALL (1 << SYSVIEW_EVTID_END_CALL)
167 #define SYSVIEW_EVTMASK_TASK_TERMINATE (1 << SYSVIEW_EVTID_TASK_TERMINATE)
168 
169 #define SYSVIEW_EVTMASK_EX (1 << SYSVIEW_EVTID_EX)
170 
171 #define SYSVIEW_EVTMASK_ALL_INTERRUPTS ( SYSVIEW_EVTMASK_ISR_ENTER \
172  | SYSVIEW_EVTMASK_ISR_EXIT \
173  | SYSVIEW_EVTMASK_ISR_TO_SCHEDULER)
174 #define SYSVIEW_EVTMASK_ALL_TASKS ( SYSVIEW_EVTMASK_TASK_START_EXEC \
175  | SYSVIEW_EVTMASK_TASK_STOP_EXEC \
176  | SYSVIEW_EVTMASK_TASK_START_READY \
177  | SYSVIEW_EVTMASK_TASK_STOP_READY \
178  | SYSVIEW_EVTMASK_TASK_CREATE \
179  | SYSVIEW_EVTMASK_TASK_INFO \
180  | SYSVIEW_EVTMASK_STACK_INFO \
181  | SYSVIEW_EVTMASK_TASK_TERMINATE)
182 
183 /*********************************************************************
184 *
185 * Structures
186 *
187 **********************************************************************
188 */
189 
190 typedef struct {
191  U32 TaskID;
192  const char* sName;
193  U32 Prio;
194  U32 StackBase;
195  U32 StackSize;
196 } SEGGER_SYSVIEW_TASKINFO;
197 
198 typedef struct SEGGER_SYSVIEW_MODULE_STRUCT SEGGER_SYSVIEW_MODULE;
199 
200 struct SEGGER_SYSVIEW_MODULE_STRUCT {
201  const char* sModule;
202  U32 NumEvents;
203  U32 EventOffset;
204  void (*pfSendModuleDesc)(void);
205  SEGGER_SYSVIEW_MODULE* pNext;
206 };
207 
208 typedef void (SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC)(void);
209 
210 /*********************************************************************
211 *
212 * Global data
213 *
214 **********************************************************************
215 */
216 
217 #ifdef EXTERN
218  #undef EXTERN
219 #endif
220 
221 #ifndef SEGGER_SYSVIEW_C // Defined in SEGGER_SYSVIEW.c which includes this header beside other C-files
222  #define EXTERN extern
223 #else
224  #define EXTERN
225 #endif
226 
227 EXTERN unsigned int SEGGER_SYSVIEW_TickCnt;
228 EXTERN unsigned int SEGGER_SYSVIEW_InterruptId;
229 
230 #undef EXTERN
231 
232 /*********************************************************************
233 *
234 * API functions
235 *
236 **********************************************************************
237 */
238 
239 typedef struct {
240  U64 (*pfGetTime) (void);
241  void (*pfSendTaskList) (void);
242 } SEGGER_SYSVIEW_OS_API;
243 
244 /*********************************************************************
245 *
246 * Control and initialization functions
247 */
248 void SEGGER_SYSVIEW_Init (U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc);
249 void SEGGER_SYSVIEW_SetRAMBase (U32 RAMBaseAddress);
250 void SEGGER_SYSVIEW_Start (void);
251 void SEGGER_SYSVIEW_Stop (void);
252 void SEGGER_SYSVIEW_GetSysDesc (void);
253 void SEGGER_SYSVIEW_SendTaskList (void);
254 void SEGGER_SYSVIEW_SendTaskInfo (const SEGGER_SYSVIEW_TASKINFO* pInfo);
255 void SEGGER_SYSVIEW_SendSysDesc (const char* sSysDesc);
256 int SEGGER_SYSVIEW_IsStarted (void);
257 int SEGGER_SYSVIEW_GetChannelID (void);
258 
259 /*********************************************************************
260 *
261 * Event recording functions
262 */
263 void SEGGER_SYSVIEW_RecordVoid (unsigned int EventId);
264 void SEGGER_SYSVIEW_RecordU32 (unsigned int EventId, U32 Para0);
265 void SEGGER_SYSVIEW_RecordU32x2 (unsigned int EventId, U32 Para0, U32 Para1);
266 void SEGGER_SYSVIEW_RecordU32x3 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2);
267 void SEGGER_SYSVIEW_RecordU32x4 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3);
268 void SEGGER_SYSVIEW_RecordU32x5 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4);
269 void SEGGER_SYSVIEW_RecordU32x6 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5);
270 void SEGGER_SYSVIEW_RecordU32x7 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6);
271 void SEGGER_SYSVIEW_RecordU32x8 (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7);
272 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);
273 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);
274 void SEGGER_SYSVIEW_RecordString (unsigned int EventId, const char* pString);
275 void SEGGER_SYSVIEW_RecordSystime (void);
276 void SEGGER_SYSVIEW_RecordEnterISR (void);
277 void SEGGER_SYSVIEW_RecordExitISR (void);
278 void SEGGER_SYSVIEW_RecordExitISRToScheduler (void);
279 void SEGGER_SYSVIEW_RecordEnterTimer (U32 TimerId);
280 void SEGGER_SYSVIEW_RecordExitTimer (void);
281 void SEGGER_SYSVIEW_RecordEndCall (unsigned int EventID);
282 void SEGGER_SYSVIEW_RecordEndCallU32 (unsigned int EventID, U32 Para0);
283 
284 void SEGGER_SYSVIEW_OnIdle (void);
285 void SEGGER_SYSVIEW_OnTaskCreate (U32 TaskId);
286 void SEGGER_SYSVIEW_OnTaskTerminate (U32 TaskId);
287 void SEGGER_SYSVIEW_OnTaskStartExec (U32 TaskId);
288 void SEGGER_SYSVIEW_OnTaskStopExec (void);
289 void SEGGER_SYSVIEW_OnTaskStartReady (U32 TaskId);
290 void SEGGER_SYSVIEW_OnTaskStopReady (U32 TaskId, unsigned int Cause);
291 void SEGGER_SYSVIEW_MarkStart (unsigned int MarkerId);
292 void SEGGER_SYSVIEW_MarkStop (unsigned int MarkerId);
293 void SEGGER_SYSVIEW_Mark (unsigned int MarkerId);
294 void SEGGER_SYSVIEW_NameMarker (unsigned int MarkerId, const char* sName);
295 
296 void SEGGER_SYSVIEW_NameResource (U32 ResourceId, const char* sName);
297 
298 int SEGGER_SYSVIEW_SendPacket (U8* pPacket, U8* pPayloadEnd, unsigned int EventId);
299 
300 /*********************************************************************
301 *
302 * Event parameter encoding functions
303 */
304 U8* SEGGER_SYSVIEW_EncodeU32 (U8* pPayload, U32 Value);
305 U8* SEGGER_SYSVIEW_EncodeData (U8* pPayload, const char* pSrc, unsigned int Len);
306 U8* SEGGER_SYSVIEW_EncodeString (U8* pPayload, const char* s, unsigned int MaxLen);
307 U8* SEGGER_SYSVIEW_EncodeId (U8* pPayload, U32 Id);
308 U32 SEGGER_SYSVIEW_ShrinkId (U32 Id);
309 
310 
311 /*********************************************************************
312 *
313 * Middleware module registration
314 */
315 void SEGGER_SYSVIEW_RegisterModule (SEGGER_SYSVIEW_MODULE* pModule);
316 void SEGGER_SYSVIEW_RecordModuleDescription (const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription);
317 void SEGGER_SYSVIEW_SendModule (U8 ModuleId);
318 void SEGGER_SYSVIEW_SendModuleDescription (void);
319 void SEGGER_SYSVIEW_SendNumModules (void);
320 
321 /*********************************************************************
322 *
323 * printf-Style functions
324 */
325 #ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
326 void SEGGER_SYSVIEW_PrintfHostEx (const char* s, U32 Options, ...);
327 void SEGGER_SYSVIEW_PrintfTargetEx (const char* s, U32 Options, ...);
328 void SEGGER_SYSVIEW_PrintfHost (const char* s, ...);
329 void SEGGER_SYSVIEW_PrintfTarget (const char* s, ...);
330 void SEGGER_SYSVIEW_WarnfHost (const char* s, ...);
331 void SEGGER_SYSVIEW_WarnfTarget (const char* s, ...);
332 void SEGGER_SYSVIEW_ErrorfHost (const char* s, ...);
333 void SEGGER_SYSVIEW_ErrorfTarget (const char* s, ...);
334 #endif
335 
336 void SEGGER_SYSVIEW_Print (const char* s);
337 void SEGGER_SYSVIEW_Warn (const char* s);
338 void SEGGER_SYSVIEW_Error (const char* s);
339 
340 /*********************************************************************
341 *
342 * Run-time configuration functions
343 */
344 void SEGGER_SYSVIEW_EnableEvents (U32 EnableMask);
345 void SEGGER_SYSVIEW_DisableEvents (U32 DisableMask);
346 
347 /*********************************************************************
348 *
349 * Application-provided functions
350 */
351 void SEGGER_SYSVIEW_Conf (void);
352 U32 SEGGER_SYSVIEW_X_GetTimestamp (void);
353 U32 SEGGER_SYSVIEW_X_GetInterruptId (void);
354 
355 void SEGGER_SYSVIEW_X_StartComm (void);
356 void SEGGER_SYSVIEW_X_OnEventRecorded (unsigned NumBytes);
357 
358 #ifdef __cplusplus
359 }
360 #endif
361 
362 /*********************************************************************
363 *
364 * Compatibility API defines
365 */
366 #define SEGGER_SYSVIEW_OnUserStart SEGGER_SYSVIEW_MarkStart
367 #define SEGGER_SYSVIEW_OnUserStop SEGGER_SYSVIEW_MarkStop
368 
369 #endif /* (dg_configSYSTEMVIEW == 1) */
370 
371 #endif
372 
373 /*************************** End of file ****************************/