SEGGER_SYSVIEW.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*********************************************************************
  2. * SEGGER MICROCONTROLLER GmbH & Co. KG *
  3. * Solutions for real time microcontroller applications *
  4. **********************************************************************
  5. * *
  6. * (c) 2015 - 2016 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. * * This software may in its unmodified form be freely redistributed *
  19. * in source form. *
  20. * * The source code may be modified, provided the source code *
  21. * retains the above copyright notice, this list of conditions and *
  22. * the following disclaimer. *
  23. * * Modified versions of this software in source or linkable form *
  24. * may not be distributed without prior consent of SEGGER. *
  25. * *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND *
  27. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, *
  28. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
  29. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
  30. * SEGGER Microcontroller BE LIABLE FOR ANY DIRECT, INDIRECT, *
  31. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
  32. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, *
  35. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
  36. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
  37. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
  38. * *
  39. **********************************************************************
  40. * *
  41. * SystemView version: V2.40 *
  42. * *
  43. **********************************************************************
  44. -------------------------- END-OF-HEADER -----------------------------
  45. File : SEGGER_SYSVIEW.h
  46. Purpose : System visualization API.
  47. Revision: $Rev: 3807 $
  48. */
  49. #ifndef SEGGER_SYSVIEW_H
  50. #define SEGGER_SYSVIEW_H
  51. /*********************************************************************
  52. *
  53. * #include Section
  54. *
  55. **********************************************************************
  56. */
  57. #include "SEGGER.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /*********************************************************************
  62. *
  63. * Defines, fixed
  64. *
  65. **********************************************************************
  66. */
  67. #define SEGGER_SYSVIEW_VERSION 21000
  68. #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.
  69. #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.
  70. #define SEGGER_SYSVIEW_LOG (0u)
  71. #define SEGGER_SYSVIEW_WARNING (1u)
  72. #define SEGGER_SYSVIEW_ERROR (2u)
  73. #define SEGGER_SYSVIEW_FLAG_APPEND (1u << 6)
  74. #define SEGGER_SYSVIEW_PREPARE_PACKET(p) (p) + 4
  75. //
  76. // SystemView events. First 32 IDs from 0 .. 31 are reserved for these
  77. //
  78. #define SYSVIEW_EVTID_NOP 0 // Dummy packet.
  79. #define SYSVIEW_EVTID_OVERFLOW 1
  80. #define SYSVIEW_EVTID_ISR_ENTER 2
  81. #define SYSVIEW_EVTID_ISR_EXIT 3
  82. #define SYSVIEW_EVTID_TASK_START_EXEC 4
  83. #define SYSVIEW_EVTID_TASK_STOP_EXEC 5
  84. #define SYSVIEW_EVTID_TASK_START_READY 6
  85. #define SYSVIEW_EVTID_TASK_STOP_READY 7
  86. #define SYSVIEW_EVTID_TASK_CREATE 8
  87. #define SYSVIEW_EVTID_TASK_INFO 9
  88. #define SYSVIEW_EVTID_TRACE_START 10
  89. #define SYSVIEW_EVTID_TRACE_STOP 11
  90. #define SYSVIEW_EVTID_SYSTIME_CYCLES 12
  91. #define SYSVIEW_EVTID_SYSTIME_US 13
  92. #define SYSVIEW_EVTID_SYSDESC 14
  93. #define SYSVIEW_EVTID_USER_START 15
  94. #define SYSVIEW_EVTID_USER_STOP 16
  95. #define SYSVIEW_EVTID_IDLE 17
  96. #define SYSVIEW_EVTID_ISR_TO_SCHEDULER 18
  97. #define SYSVIEW_EVTID_TIMER_ENTER 19
  98. #define SYSVIEW_EVTID_TIMER_EXIT 20
  99. #define SYSVIEW_EVTID_STACK_INFO 21
  100. #define SYSVIEW_EVTID_MODULEDESC 22
  101. #define SYSVIEW_EVTID_INIT 24
  102. #define SYSVIEW_EVTID_NAME_RESOURCE 25
  103. #define SYSVIEW_EVTID_PRINT_FORMATTED 26
  104. #define SYSVIEW_EVTID_NUMMODULES 27
  105. #define SYSVIEW_EVTID_END_CALL 28
  106. #define SYSVIEW_EVTID_TASK_TERMINATE 29
  107. #define SYSVIEW_EVTID_EX 31
  108. //
  109. // Event masks to disable/enable events
  110. //
  111. #define SYSVIEW_EVTMASK_NOP (1 << SYSVIEW_EVTID_NOP)
  112. #define SYSVIEW_EVTMASK_OVERFLOW (1 << SYSVIEW_EVTID_OVERFLOW)
  113. #define SYSVIEW_EVTMASK_ISR_ENTER (1 << SYSVIEW_EVTID_ISR_ENTER)
  114. #define SYSVIEW_EVTMASK_ISR_EXIT (1 << SYSVIEW_EVTID_ISR_EXIT)
  115. #define SYSVIEW_EVTMASK_TASK_START_EXEC (1 << SYSVIEW_EVTID_TASK_START_EXEC)
  116. #define SYSVIEW_EVTMASK_TASK_STOP_EXEC (1 << SYSVIEW_EVTID_TASK_STOP_EXEC)
  117. #define SYSVIEW_EVTMASK_TASK_START_READY (1 << SYSVIEW_EVTID_TASK_START_READY)
  118. #define SYSVIEW_EVTMASK_TASK_STOP_READY (1 << SYSVIEW_EVTID_TASK_STOP_READY)
  119. #define SYSVIEW_EVTMASK_TASK_CREATE (1 << SYSVIEW_EVTID_TASK_CREATE)
  120. #define SYSVIEW_EVTMASK_TASK_INFO (1 << SYSVIEW_EVTID_TASK_INFO)
  121. #define SYSVIEW_EVTMASK_TRACE_START (1 << SYSVIEW_EVTID_TRACE_START)
  122. #define SYSVIEW_EVTMASK_TRACE_STOP (1 << SYSVIEW_EVTID_TRACE_STOP)
  123. #define SYSVIEW_EVTMASK_SYSTIME_CYCLES (1 << SYSVIEW_EVTID_SYSTIME_CYCLES)
  124. #define SYSVIEW_EVTMASK_SYSTIME_US (1 << SYSVIEW_EVTID_SYSTIME_US)
  125. #define SYSVIEW_EVTMASK_SYSDESC (1 << SYSVIEW_EVTID_SYSDESC)
  126. #define SYSVIEW_EVTMASK_USER_START (1 << SYSVIEW_EVTID_USER_START)
  127. #define SYSVIEW_EVTMASK_USER_STOP (1 << SYSVIEW_EVTID_USER_STOP)
  128. #define SYSVIEW_EVTMASK_IDLE (1 << SYSVIEW_EVTID_IDLE)
  129. #define SYSVIEW_EVTMASK_ISR_TO_SCHEDULER (1 << SYSVIEW_EVTID_ISR_TO_SCHEDULER)
  130. #define SYSVIEW_EVTMASK_TIMER_ENTER (1 << SYSVIEW_EVTID_TIMER_ENTER)
  131. #define SYSVIEW_EVTMASK_TIMER_EXIT (1 << SYSVIEW_EVTID_TIMER_EXIT)
  132. #define SYSVIEW_EVTMASK_STACK_INFO (1 << SYSVIEW_EVTID_STACK_INFO)
  133. #define SYSVIEW_EVTMASK_MODULEDESC (1 << SYSVIEW_EVTID_MODULEDESC)
  134. #define SYSVIEW_EVTMASK_INIT (1 << SYSVIEW_EVTID_INIT)
  135. #define SYSVIEW_EVTMASK_NAME_RESOURCE (1 << SYSVIEW_EVTID_NAME_RESOURCE)
  136. #define SYSVIEW_EVTMASK_PRINT_FORMATTED (1 << SYSVIEW_EVTID_PRINT_FORMATTED)
  137. #define SYSVIEW_EVTMASK_NUMMODULES (1 << SYSVIEW_EVTID_NUMMODULES)
  138. #define SYSVIEW_EVTMASK_END_CALL (1 << SYSVIEW_EVTID_END_CALL)
  139. #define SYSVIEW_EVTMASK_TASK_TERMINATE (1 << SYSVIEW_EVTID_TASK_TERMINATE)
  140. #define SYSVIEW_EVTMASK_EX (1 << SYSVIEW_EVTID_EX)
  141. #define SYSVIEW_EVTMASK_ALL_INTERRUPTS ( SYSVIEW_EVTMASK_ISR_ENTER \
  142. | SYSVIEW_EVTMASK_ISR_EXIT \
  143. | SYSVIEW_EVTMASK_ISR_TO_SCHEDULER)
  144. #define SYSVIEW_EVTMASK_ALL_TASKS ( SYSVIEW_EVTMASK_TASK_START_EXEC \
  145. | SYSVIEW_EVTMASK_TASK_STOP_EXEC \
  146. | SYSVIEW_EVTMASK_TASK_START_READY \
  147. | SYSVIEW_EVTMASK_TASK_STOP_READY \
  148. | SYSVIEW_EVTMASK_TASK_CREATE \
  149. | SYSVIEW_EVTMASK_TASK_INFO \
  150. | SYSVIEW_EVTMASK_STACK_INFO \
  151. | SYSVIEW_EVTMASK_TASK_TERMINATE)
  152. /*********************************************************************
  153. *
  154. * Structures
  155. *
  156. **********************************************************************
  157. */
  158. typedef struct {
  159. U32 TaskID;
  160. const char* sName;
  161. U32 Prio;
  162. U32 StackBase;
  163. U32 StackSize;
  164. } SEGGER_SYSVIEW_TASKINFO;
  165. typedef struct SEGGER_SYSVIEW_MODULE_STRUCT SEGGER_SYSVIEW_MODULE;
  166. struct SEGGER_SYSVIEW_MODULE_STRUCT {
  167. const char* sModule;
  168. U32 NumEvents;
  169. U32 EventOffset;
  170. void (*pfSendModuleDesc)(void);
  171. SEGGER_SYSVIEW_MODULE* pNext;
  172. };
  173. typedef void (SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC)(void);
  174. /*********************************************************************
  175. *
  176. * API functions
  177. *
  178. **********************************************************************
  179. */
  180. #ifndef U64
  181. #ifdef _WIN32
  182. #define U64 unsigned __int64
  183. #else
  184. #define U64 unsigned long long
  185. #endif
  186. #endif
  187. typedef struct {
  188. U64 (*pfGetTime) (void);
  189. void (*pfSendTaskList) (void);
  190. } SEGGER_SYSVIEW_OS_API;
  191. /*********************************************************************
  192. *
  193. * Control and initialization functions
  194. */
  195. void SEGGER_SYSVIEW_Init (U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc);
  196. void SEGGER_SYSVIEW_SetRAMBase (U32 RAMBaseAddress);
  197. void SEGGER_SYSVIEW_Start (void);
  198. void SEGGER_SYSVIEW_Stop (void);
  199. void SEGGER_SYSVIEW_GetSysDesc (void);
  200. void SEGGER_SYSVIEW_SendTaskList (void);
  201. void SEGGER_SYSVIEW_SendTaskInfo (const SEGGER_SYSVIEW_TASKINFO* pInfo);
  202. void SEGGER_SYSVIEW_SendSysDesc (const char* sSysDesc);
  203. /*********************************************************************
  204. *
  205. * Event recording functions
  206. */
  207. void SEGGER_SYSVIEW_RecordVoid (unsigned EventId);
  208. void SEGGER_SYSVIEW_RecordU32 (unsigned EventId, U32 Para0);
  209. void SEGGER_SYSVIEW_RecordU32x2 (unsigned EventId, U32 Para0, U32 Para1);
  210. void SEGGER_SYSVIEW_RecordU32x3 (unsigned EventId, U32 Para0, U32 Para1, U32 Para2);
  211. void SEGGER_SYSVIEW_RecordU32x4 (unsigned EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3);
  212. void SEGGER_SYSVIEW_RecordU32x5 (unsigned EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4);
  213. void SEGGER_SYSVIEW_RecordU32x6 (unsigned EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5);
  214. void SEGGER_SYSVIEW_RecordU32x7 (unsigned EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6);
  215. void SEGGER_SYSVIEW_RecordU32x8 (unsigned EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7);
  216. void SEGGER_SYSVIEW_RecordU32x9 (unsigned EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8);
  217. void SEGGER_SYSVIEW_RecordU32x10 (unsigned EventId, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8, U32 Para9);
  218. void SEGGER_SYSVIEW_RecordString (unsigned EventId, const char* pString);
  219. void SEGGER_SYSVIEW_RecordSystime (void);
  220. void SEGGER_SYSVIEW_RecordEnterISR (void);
  221. void SEGGER_SYSVIEW_RecordExitISR (void);
  222. void SEGGER_SYSVIEW_RecordExitISRToScheduler (void);
  223. void SEGGER_SYSVIEW_RecordEnterTimer (U32 TimerId);
  224. void SEGGER_SYSVIEW_RecordExitTimer (void);
  225. void SEGGER_SYSVIEW_RecordEndCall (unsigned EventID);
  226. void SEGGER_SYSVIEW_RecordEndCallU32 (unsigned EventID, U32 Para0);
  227. void SEGGER_SYSVIEW_OnIdle (void);
  228. void SEGGER_SYSVIEW_OnTaskCreate (unsigned TaskId);
  229. void SEGGER_SYSVIEW_OnTaskTerminate (unsigned TaskId);
  230. void SEGGER_SYSVIEW_OnTaskStartExec (unsigned TaskId);
  231. void SEGGER_SYSVIEW_OnTaskStopExec (void);
  232. void SEGGER_SYSVIEW_OnTaskStartReady (unsigned TaskId);
  233. void SEGGER_SYSVIEW_OnTaskStopReady (unsigned TaskId, unsigned Cause);
  234. void SEGGER_SYSVIEW_OnUserStart (unsigned UserId); // Start of user defined event (such as a subroutine to profile)
  235. void SEGGER_SYSVIEW_OnUserStop (unsigned UserId); // Start of user defined event
  236. void SEGGER_SYSVIEW_NameResource (U32 ResourceId, const char* sName);
  237. int SEGGER_SYSVIEW_SendPacket (U8* pPacket, U8* pPayloadEnd, unsigned EventId);
  238. /*********************************************************************
  239. *
  240. * Event parameter encoding functions
  241. */
  242. U8* SEGGER_SYSVIEW_EncodeU32 (U8* pPayload, unsigned Value);
  243. U8* SEGGER_SYSVIEW_EncodeData (U8* pPayload, const char* pSrc, unsigned Len);
  244. U8* SEGGER_SYSVIEW_EncodeString (U8* pPayload, const char* s, unsigned MaxLen);
  245. U8* SEGGER_SYSVIEW_EncodeId (U8* pPayload, unsigned Id);
  246. U32 SEGGER_SYSVIEW_ShrinkId (U32 Id);
  247. /*********************************************************************
  248. *
  249. * Middleware module registration
  250. */
  251. void SEGGER_SYSVIEW_RegisterModule (SEGGER_SYSVIEW_MODULE* pModule);
  252. void SEGGER_SYSVIEW_RecordModuleDescription (const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription);
  253. void SEGGER_SYSVIEW_SendModule (U8 ModuleId);
  254. void SEGGER_SYSVIEW_SendModuleDescription (void);
  255. void SEGGER_SYSVIEW_SendNumModules (void);
  256. /*********************************************************************
  257. *
  258. * printf-Style functions
  259. */
  260. #ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
  261. void SEGGER_SYSVIEW_PrintfHostEx (const char* s, U32 Options, ...);
  262. void SEGGER_SYSVIEW_PrintfTargetEx (const char* s, U32 Options, ...);
  263. void SEGGER_SYSVIEW_PrintfHost (const char* s, ...);
  264. void SEGGER_SYSVIEW_PrintfTarget (const char* s, ...);
  265. void SEGGER_SYSVIEW_WarnfHost (const char* s, ...);
  266. void SEGGER_SYSVIEW_WarnfTarget (const char* s, ...);
  267. void SEGGER_SYSVIEW_ErrorfHost (const char* s, ...);
  268. void SEGGER_SYSVIEW_ErrorfTarget (const char* s, ...);
  269. #endif
  270. void SEGGER_SYSVIEW_Print (const char* s);
  271. void SEGGER_SYSVIEW_Warn (const char* s);
  272. void SEGGER_SYSVIEW_Error (const char* s);
  273. /*********************************************************************
  274. *
  275. * Run-time configuration functions
  276. */
  277. void SEGGER_SYSVIEW_EnableEvents (U32 EnableMask);
  278. void SEGGER_SYSVIEW_DisableEvents (U32 DisableMask);
  279. /*********************************************************************
  280. *
  281. * Application-provided functions
  282. */
  283. void SEGGER_SYSVIEW_Conf (void);
  284. U32 SEGGER_SYSVIEW_X_GetTimestamp (void);
  285. U32 SEGGER_SYSVIEW_X_GetInterruptId (void);
  286. #ifdef __cplusplus
  287. }
  288. #endif
  289. #endif
  290. /*************************** End of file ****************************/