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 /*********************************************************************
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          10
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 //
134 // Event masks to disable/enable events
135 //
136 #define   SYSVIEW_EVTMASK_NOP               (1 << SYSVIEW_EVTID_NOP)
137 #define   SYSVIEW_EVTMASK_OVERFLOW          (1 << SYSVIEW_EVTID_OVERFLOW)
138 #define   SYSVIEW_EVTMASK_ISR_ENTER         (1 << SYSVIEW_EVTID_ISR_ENTER)
139 #define   SYSVIEW_EVTMASK_ISR_EXIT          (1 << SYSVIEW_EVTID_ISR_EXIT)
140 #define   SYSVIEW_EVTMASK_TASK_START_EXEC   (1 << SYSVIEW_EVTID_TASK_START_EXEC)
141 #define   SYSVIEW_EVTMASK_TASK_STOP_EXEC    (1 << SYSVIEW_EVTID_TASK_STOP_EXEC)
142 #define   SYSVIEW_EVTMASK_TASK_START_READY  (1 << SYSVIEW_EVTID_TASK_START_READY)
143 #define   SYSVIEW_EVTMASK_TASK_STOP_READY   (1 << SYSVIEW_EVTID_TASK_STOP_READY)
144 #define   SYSVIEW_EVTMASK_TASK_CREATE       (1 << SYSVIEW_EVTID_TASK_CREATE)
145 #define   SYSVIEW_EVTMASK_TASK_INFO         (1 << SYSVIEW_EVTID_TASK_INFO)
146 #define   SYSVIEW_EVTMASK_TRACE_START       (1 << SYSVIEW_EVTID_TRACE_START)
147 #define   SYSVIEW_EVTMASK_TRACE_STOP        (1 << SYSVIEW_EVTID_TRACE_STOP)
148 #define   SYSVIEW_EVTMASK_SYSTIME_CYCLES    (1 << SYSVIEW_EVTID_SYSTIME_CYCLES)
149 #define   SYSVIEW_EVTMASK_SYSTIME_US        (1 << SYSVIEW_EVTID_SYSTIME_US)
150 #define   SYSVIEW_EVTMASK_SYSDESC           (1 << SYSVIEW_EVTID_SYSDESC)
151 #define   SYSVIEW_EVTMASK_USER_START        (1 << SYSVIEW_EVTID_USER_START)
152 #define   SYSVIEW_EVTMASK_USER_STOP         (1 << SYSVIEW_EVTID_USER_STOP)
153 #define   SYSVIEW_EVTMASK_IDLE              (1 << SYSVIEW_EVTID_IDLE)
154 #define   SYSVIEW_EVTMASK_ISR_TO_SCHEDULER  (1 << SYSVIEW_EVTID_ISR_TO_SCHEDULER)
155 #define   SYSVIEW_EVTMASK_TIMER_ENTER       (1 << SYSVIEW_EVTID_TIMER_ENTER)
156 #define   SYSVIEW_EVTMASK_TIMER_EXIT        (1 << SYSVIEW_EVTID_TIMER_EXIT)
157 #define   SYSVIEW_EVTMASK_STACK_INFO        (1 << SYSVIEW_EVTID_STACK_INFO)
158 #define   SYSVIEW_EVTMASK_MODULEDESC        (1 << SYSVIEW_EVTID_MODULEDESC)
159 
160 #define   SYSVIEW_EVTMASK_INIT              (1 << SYSVIEW_EVTID_INIT)
161 #define   SYSVIEW_EVTMASK_NAME_RESOURCE     (1 << SYSVIEW_EVTID_NAME_RESOURCE)
162 #define   SYSVIEW_EVTMASK_PRINT_FORMATTED   (1 << SYSVIEW_EVTID_PRINT_FORMATTED)
163 #define   SYSVIEW_EVTMASK_NUMMODULES        (1 << SYSVIEW_EVTID_NUMMODULES)
164 #define   SYSVIEW_EVTMASK_END_CALL          (1 << SYSVIEW_EVTID_END_CALL)
165 #define   SYSVIEW_EVTMASK_TASK_TERMINATE    (1 << SYSVIEW_EVTID_TASK_TERMINATE)
166 
167 #define   SYSVIEW_EVTMASK_EX                (1 << SYSVIEW_EVTID_EX)
168 
169 #define   SYSVIEW_EVTMASK_ALL_INTERRUPTS    ( SYSVIEW_EVTMASK_ISR_ENTER           \
170                                             | SYSVIEW_EVTMASK_ISR_EXIT            \
171                                             | SYSVIEW_EVTMASK_ISR_TO_SCHEDULER)
172 #define   SYSVIEW_EVTMASK_ALL_TASKS         ( SYSVIEW_EVTMASK_TASK_START_EXEC     \
173                                             | SYSVIEW_EVTMASK_TASK_STOP_EXEC      \
174                                             | SYSVIEW_EVTMASK_TASK_START_READY    \
175                                             | SYSVIEW_EVTMASK_TASK_STOP_READY     \
176                                             | SYSVIEW_EVTMASK_TASK_CREATE         \
177                                             | SYSVIEW_EVTMASK_TASK_INFO           \
178                                             | SYSVIEW_EVTMASK_STACK_INFO          \
179                                             | SYSVIEW_EVTMASK_TASK_TERMINATE)
180 
181 /*********************************************************************
182 *
183 *       Structures
184 *
185 **********************************************************************
186 */
187 
188 typedef struct {
189   U32          TaskID;
190   const char*  sName;
191   U32          Prio;
192   U32          StackBase;
193   U32          StackSize;
194 } SEGGER_SYSVIEW_TASKINFO;
195 
196 typedef struct SEGGER_SYSVIEW_MODULE_STRUCT SEGGER_SYSVIEW_MODULE;
197 
198 struct SEGGER_SYSVIEW_MODULE_STRUCT {
199   const char*                   sModule;
200         U32                     NumEvents;
201         U32                     EventOffset;
202         void                    (*pfSendModuleDesc)(void);
203         SEGGER_SYSVIEW_MODULE*  pNext;
204 };
205 
206 typedef void (SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC)(void);
207 
208 
209 /*********************************************************************
210 *
211 *       Global data
212 *
213 **********************************************************************
214 */
215 
216 #ifdef   EXTERN
217   #undef EXTERN
218 #endif
219 
220 #ifndef SEGGER_SYSVIEW_C       // Defined in SEGGER_SYSVIEW.c which includes this header beside other C-files
221   #define EXTERN extern
222 #else
223   #define EXTERN
224 #endif
225 
226 EXTERN unsigned int SEGGER_SYSVIEW_TickCnt;
227 EXTERN unsigned int SEGGER_SYSVIEW_InterruptId;
228 
229 #undef EXTERN
230 
231 /*********************************************************************
232 *
233 *       API functions
234 *
235 **********************************************************************
236 */
237 
238 typedef struct {
239   U64  (*pfGetTime)      (void);
240   void (*pfSendTaskList) (void);
241 } SEGGER_SYSVIEW_OS_API;
242 
243 /*********************************************************************
244 *
245 *       Control and initialization functions
246 */
247 void SEGGER_SYSVIEW_Init                          (U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc);
248 void SEGGER_SYSVIEW_SetRAMBase                    (U32 RAMBaseAddress);
249 void SEGGER_SYSVIEW_Start                         (void);
250 void SEGGER_SYSVIEW_Stop                          (void);
251 void SEGGER_SYSVIEW_GetSysDesc                    (void);
252 void SEGGER_SYSVIEW_SendTaskList                  (void);
253 void SEGGER_SYSVIEW_SendTaskInfo                  (const SEGGER_SYSVIEW_TASKINFO* pInfo);
254 void SEGGER_SYSVIEW_SendSysDesc                   (const char* sSysDesc);
255 int  SEGGER_SYSVIEW_IsStarted                     (void);
256 int  SEGGER_SYSVIEW_GetChannelID                  (void);
257 
258 /*********************************************************************
259 *
260 *       Event recording functions
261 */
262 void SEGGER_SYSVIEW_RecordVoid                    (unsigned int EventId);
263 void SEGGER_SYSVIEW_RecordU32                     (unsigned int EventId, U32 Para0);
264 void SEGGER_SYSVIEW_RecordU32x2                   (unsigned int EventId, U32 Para0, U32 Para1);
265 void SEGGER_SYSVIEW_RecordU32x3                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2);
266 void SEGGER_SYSVIEW_RecordU32x4                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3);
267 void SEGGER_SYSVIEW_RecordU32x5                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4);
268 void SEGGER_SYSVIEW_RecordU32x6                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5);
269 void SEGGER_SYSVIEW_RecordU32x7                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6);
270 void SEGGER_SYSVIEW_RecordU32x8                   (unsigned int EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7);
271 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);
272 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);
273 void SEGGER_SYSVIEW_RecordString                  (unsigned int EventId, const char* pString);
274 void SEGGER_SYSVIEW_RecordSystime                 (void);
275 void SEGGER_SYSVIEW_RecordEnterISR                (void);
276 void SEGGER_SYSVIEW_RecordExitISR                 (void);
277 void SEGGER_SYSVIEW_RecordExitISRToScheduler      (void);
278 void SEGGER_SYSVIEW_RecordEnterTimer              (U32 TimerId);
279 void SEGGER_SYSVIEW_RecordExitTimer               (void);
280 void SEGGER_SYSVIEW_RecordEndCall                 (unsigned int EventID);
281 void SEGGER_SYSVIEW_RecordEndCallU32              (unsigned int EventID, U32 Para0);
282 void SEGGER_SYSVIEW_Record_StringU32              (unsigned int EventID, const char* pString, U32 Value);
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 *       Middleware module registration
313 */
314 void SEGGER_SYSVIEW_RegisterModule                (SEGGER_SYSVIEW_MODULE* pModule);
315 void SEGGER_SYSVIEW_RecordModuleDescription       (const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription);
316 void SEGGER_SYSVIEW_SendModule                    (U8 ModuleId);
317 void SEGGER_SYSVIEW_SendModuleDescription         (void);
318 void SEGGER_SYSVIEW_SendNumModules                (void);
319 
320 /*********************************************************************
321 *
322 *       printf-Style functions
323 */
324 #ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
325 void SEGGER_SYSVIEW_PrintfHostEx                  (const char* s, U32 Options, ...);
326 void SEGGER_SYSVIEW_PrintfTargetEx                (const char* s, U32 Options, ...);
327 void SEGGER_SYSVIEW_PrintfHost                    (const char* s, ...);
328 void SEGGER_SYSVIEW_PrintfTarget                  (const char* s, ...);
329 void SEGGER_SYSVIEW_WarnfHost                     (const char* s, ...);
330 void SEGGER_SYSVIEW_WarnfTarget                   (const char* s, ...);
331 void SEGGER_SYSVIEW_ErrorfHost                    (const char* s, ...);
332 void SEGGER_SYSVIEW_ErrorfTarget                  (const char* s, ...);
333 #endif
334 
335 void SEGGER_SYSVIEW_Print                         (const char* s);
336 void SEGGER_SYSVIEW_Warn                          (const char* s);
337 void SEGGER_SYSVIEW_Error                         (const char* s);
338 
339 /*********************************************************************
340 *
341 *       Run-time configuration functions
342 */
343 void SEGGER_SYSVIEW_EnableEvents                  (U32 EnableMask);
344 void SEGGER_SYSVIEW_DisableEvents                 (U32 DisableMask);
345 
346 /*********************************************************************
347 *
348 *       Application-provided functions
349 */
350 void SEGGER_SYSVIEW_Conf                          (void);
351 U32  SEGGER_SYSVIEW_X_GetTimestamp                (void);
352 U32  SEGGER_SYSVIEW_X_GetInterruptId              (void);
353 
354 void SEGGER_SYSVIEW_X_StartComm                   (void);
355 void SEGGER_SYSVIEW_X_OnEventRecorded             (unsigned NumBytes);
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 
361 /*********************************************************************
362 *
363 *       Compatibility API defines
364 */
365 #define SEGGER_SYSVIEW_OnUserStart      SEGGER_SYSVIEW_MarkStart
366 #define SEGGER_SYSVIEW_OnUserStop       SEGGER_SYSVIEW_MarkStop
367 
368 #endif
369 
370 /*************************** End of file ****************************/
371