SEGGER_SYSVIEW.h 18 KB

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