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