SEGGER_SYSVIEW.h 17 KB

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