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