SEGGER_SYSVIEW.c 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749
  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.c
  46. Purpose : System visualization API implementation.
  47. Revision: $Rev: 4039 $
  48. Additional information:
  49. Packet format:
  50. Packets with IDs 0..23 are standard packets with known structure.
  51. For efficiency, they do *NOT* contain a length field.
  52. <ID><Data><TimeStampDelta>
  53. Packets with IDs 24..31 are standard packets with extendible
  54. structure and contain a length field.
  55. <ID><Lenght><Data><TimeStampDelta>
  56. Packets with IDs >= 32 always contain a length field.
  57. <ID><Length><Data><TimeStampDelta>
  58. Packet IDs:
  59. 0.. 31 : Standard packets, known by SystemViewer.
  60. 32..1023 : OS-definable packets, described in a SystemView description file.
  61. 1024..2047 : User-definable packets, described in a SystemView description file.
  62. 2048..32767: Undefined.
  63. Data encoding:
  64. Basic types (int, short, char, ...):
  65. Basic types are encoded little endian with most-significant bit variant
  66. encoding.
  67. Each encoded byte contains 7 data bits [6:0] and the MSB continuation bit.
  68. The continuation bit indicates whether the next byte belongs to the data
  69. (bit set) or this is the last byte (bit clear).
  70. The most significant bits of data are encoded first, proceeding to the
  71. least significant bits in the final byte (little endian).
  72. Example encoding:
  73. Data: 0x1F4 (500)
  74. Encoded: 0xF4 (First 7 data bits 74 | Continuation bit)
  75. 0x03 (Second 7 data bits 03, no continuation)
  76. Data: 0xFFFFFFFF
  77. Encoded: 0xFF 0xFF 0xFF 0xFF 0x0F
  78. Data: 0xA2 (162), 0x03 (3), 0x7000
  79. Encoded: 0xA2 0x01 0x03 0x80 0xE0 0x01
  80. Byte arrays and strings:
  81. Byte arrays and strings are encoded as <NumBytes> followed by the raw data.
  82. NumBytes is encoded as a basic type with a theoretical maximum of 4G.
  83. Example encoding:
  84. Data: "Hello World\0" (0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64 0x00)
  85. Encoded: 0x0B 0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64
  86. Examples packets:
  87. 01 F4 03 80 80 10 // Overflow packet. Data is a single U32.
  88. This packet means: 500 packets lost, Timestamp is 0x40000
  89. 02 0F 50 // ISR(15) Enter. Timestamp 80 (0x50)
  90. 03 20 // ISR Exit. Timestamp 32 (0x20) (Shortest possible packet.)
  91. Sample code for user defined Packets:
  92. #define MY_ID 0x400 // Any value between 0x400 and 0x7FF
  93. void SendMyPacket(unsigned Para0, unsigned Para1, const char* s) {
  94. U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + MAX_STR_LEN + 1];
  95. U8* pPayload;
  96. //
  97. pPayload = SEGGER_SYSVIEW_PPREPARE_PACKET(aPacket); // Prepare the packet for SystemView
  98. pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet
  99. pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet
  100. pPayload = SEGGER_SYSVIEW_EncodeString(pPayload, s, MAX_STR_LEN); // Add the string to the packet
  101. //
  102. SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, MY_ID); // Send the packet with EventId = MY_ID
  103. }
  104. #define MY_ID_1 0x401
  105. void SendOnePara(unsigned Para0) {
  106. SEGGER_SYSVIEW_RecordU32(MY_ID_1, Para0);
  107. }
  108. */
  109. /*********************************************************************
  110. *
  111. * #include section
  112. *
  113. **********************************************************************
  114. */
  115. #include "SEGGER_SYSVIEW_Int.h"
  116. #include "SEGGER_RTT.h"
  117. #include <string.h>
  118. #include <stdlib.h>
  119. #include <stdarg.h>
  120. /*********************************************************************
  121. *
  122. * Defines, fixed
  123. *
  124. **********************************************************************
  125. */
  126. #if SEGGER_SYSVIEW_ID_SHIFT
  127. #define SHRINK_ID(Id) (((Id) - _SYSVIEW_Globals.RAMBaseAddress) >> SEGGER_SYSVIEW_ID_SHIFT)
  128. #else
  129. #define SHRINK_ID(Id) ((Id) - _SYSVIEW_Globals.RAMBaseAddress)
  130. #endif
  131. #if SEGGER_SYSVIEW_RTT_CHANNEL > 0
  132. #define CHANNEL_ID_UP SEGGER_SYSVIEW_RTT_CHANNEL
  133. #define CHANNEL_ID_DOWN SEGGER_SYSVIEW_RTT_CHANNEL
  134. #else
  135. #define CHANNEL_ID_UP _SYSVIEW_Globals.UpChannel
  136. #define CHANNEL_ID_DOWN _SYSVIEW_Globals.DownChannel
  137. #endif
  138. /*********************************************************************
  139. *
  140. * Defines, configurable
  141. *
  142. **********************************************************************
  143. */
  144. // Timestamps may be less than full 32-bits, in which case we need to zero
  145. // the unused bits to properly handle overflows.
  146. // Note that this is a quite common scenario, as a 32-bit time such as
  147. // SysTick might be scaled down to reduce bandwith
  148. // or a 16-bit hardware time might be used.
  149. #if SEGGER_SYSVIEW_TIMESTAMP_BITS < 32 // Eliminate unused bits in case hardware timestamps are less than 32 bits
  150. #define MAKE_DELTA_32BIT(Delta) Delta <<= 32 - SEGGER_SYSVIEW_TIMESTAMP_BITS; \
  151. Delta >>= 32 - SEGGER_SYSVIEW_TIMESTAMP_BITS;
  152. #else
  153. #define MAKE_DELTA_32BIT(Delta)
  154. #endif
  155. /*********************************************************************
  156. *
  157. * Defines, fixed
  158. *
  159. **********************************************************************
  160. */
  161. #define ENABLE_STATE_OFF 0
  162. #define ENABLE_STATE_ON 1
  163. #define ENABLE_STATE_DROPPING 2
  164. #define FORMAT_FLAG_LEFT_JUSTIFY (1u << 0)
  165. #define FORMAT_FLAG_PAD_ZERO (1u << 1)
  166. #define FORMAT_FLAG_PRINT_SIGN (1u << 2)
  167. #define FORMAT_FLAG_ALTERNATE (1u << 3)
  168. #define MODULE_EVENT_OFFSET (512)
  169. /*********************************************************************
  170. *
  171. * Types, local
  172. *
  173. **********************************************************************
  174. */
  175. typedef struct {
  176. U8* pBuffer;
  177. U8* pPayload;
  178. U8* pPayloadStart;
  179. U32 Options;
  180. unsigned Cnt;
  181. } SEGGER_SYSVIEW_PRINTF_DESC;
  182. typedef struct {
  183. U8 EnableState; // 0: Disabled, 1: Enabled, (2: Dropping)
  184. U8 UpChannel;
  185. U8 RecursionCnt;
  186. U32 SysFreq;
  187. U32 CPUFreq;
  188. U32 LastTxTimeStamp;
  189. U32 RAMBaseAddress;
  190. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  191. U32 PacketCount;
  192. #else
  193. U32 DropCount;
  194. U8 DownChannel;
  195. #endif
  196. U32 DisabledEvents;
  197. const SEGGER_SYSVIEW_OS_API* pOSAPI;
  198. SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC* pfSendSysDesc;
  199. } SEGGER_SYSVIEW_GLOBALS;
  200. /*********************************************************************
  201. *
  202. * Function prototypes, required
  203. *
  204. **********************************************************************
  205. */
  206. static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned EventId);
  207. /*********************************************************************
  208. *
  209. * Static data
  210. *
  211. **********************************************************************
  212. */
  213. static const U8 _abSync[10] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  214. #ifdef SEGGER_SYSVIEW_SECTION
  215. #if (defined __GNUC__)
  216. __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
  217. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  218. __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
  219. #endif
  220. #elif (defined __ICCARM__) || (defined __ICCRX__)
  221. #pragma location=SEGGER_SYSVIEW_SECTION
  222. static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
  223. #pragma location=SEGGER_SYSVIEW_SECTION
  224. static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
  225. #elif (defined __CC_ARM__)
  226. __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
  227. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  228. __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
  229. #endif
  230. #else
  231. static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
  232. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  233. static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
  234. #endif
  235. #endif
  236. #else
  237. static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
  238. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  239. static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
  240. #endif
  241. #endif
  242. static SEGGER_SYSVIEW_GLOBALS _SYSVIEW_Globals;
  243. static SEGGER_SYSVIEW_MODULE* _pFirstModule;
  244. static U8 _NumModules;
  245. /*********************************************************************
  246. *
  247. * Static code
  248. *
  249. **********************************************************************
  250. */
  251. #define ENCODE_U32(pDest, Value) { \
  252. U8* pSysviewPointer; \
  253. U32 SysViewData; \
  254. pSysviewPointer = pDest; \
  255. SysViewData = Value; \
  256. while(SysViewData > 0x7F) { \
  257. *pSysviewPointer++ = (U8)(SysViewData | 0x80); \
  258. SysViewData >>= 7; \
  259. }; \
  260. *pSysviewPointer++ = (U8)SysViewData; \
  261. pDest = pSysviewPointer; \
  262. };
  263. #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
  264. static U8 _aPacket[SEGGER_SYSVIEW_MAX_PACKET_SIZE];
  265. #define RECORD_START(PacketSize) SEGGER_SYSVIEW_LOCK(); \
  266. pPayloadStart = _PreparePacket(_aPacket);
  267. #define RECORD_END() SEGGER_SYSVIEW_UNLOCK()
  268. #else
  269. #define RECORD_START(PacketSize) U8 aPacket[(PacketSize)]; \
  270. pPayloadStart = _PreparePacket(aPacket); \
  271. #define RECORD_END()
  272. #endif
  273. /*********************************************************************
  274. *
  275. * _EncodeData()
  276. *
  277. * Function description
  278. * Encode a byte buffer in variable-length format.
  279. *
  280. * Parameters
  281. * pPayload - Pointer to where string will be encoded.
  282. * pSrc - Pointer to data buffer to be encoded.
  283. * NumBytes - Number of bytes in the buffer to be encoded.
  284. *
  285. * Return value
  286. * Pointer to the byte following the value, i.e. the first free
  287. * byte in the payload and the next position to store payload
  288. * content.
  289. *
  290. * Additional information
  291. * The data is encoded as a count byte followed by the contents
  292. * of the data buffer.
  293. * Make sure NumBytes + 1 bytes are free for the payload.
  294. */
  295. static U8* _EncodeData(U8* pPayload, const char* pSrc, unsigned NumBytes) {
  296. unsigned n;
  297. //
  298. n = 0;
  299. *pPayload++ = NumBytes;
  300. while (n < NumBytes) {
  301. *pPayload++ = *pSrc++;
  302. n++;
  303. }
  304. return pPayload;
  305. }
  306. /*********************************************************************
  307. *
  308. * _EncodeStr()
  309. *
  310. * Function description
  311. * Encode a string in variable-length format.
  312. *
  313. * Parameters
  314. * pPayload - Pointer to where string will be encoded.
  315. * pText - String to encode.
  316. * Limit - Maximum number of characters to encode from string.
  317. *
  318. * Return value
  319. * Pointer to the byte following the value, i.e. the first free
  320. * byte in the payload and the next position to store payload
  321. * content.
  322. *
  323. * Additional information
  324. * The string is encoded as a count byte followed by the contents
  325. * of the string.
  326. * No more than 1 + Limit bytes will be encoded to the payload.
  327. */
  328. static U8 *_EncodeStr(U8 *pPayload, const char *pText, unsigned Limit) {
  329. unsigned n;
  330. unsigned Len;
  331. //
  332. // Compute string len
  333. //
  334. Len = 0;
  335. while(*(pText + Len) != 0) {
  336. Len++;
  337. }
  338. if (Len > Limit) {
  339. Len = Limit;
  340. }
  341. //
  342. // Write Len
  343. //
  344. if (Len < 255) {
  345. *pPayload++ = Len;
  346. } else {
  347. *pPayload++ = 255;
  348. *pPayload++ = (Len & 255);
  349. *pPayload++ = ((Len >> 8) & 255);
  350. }
  351. //
  352. // copy string
  353. //
  354. n = 0;
  355. while (n < Len) {
  356. *pPayload++ = *pText++;
  357. n++;
  358. }
  359. return pPayload;
  360. }
  361. /*********************************************************************
  362. *
  363. * _PreparePacket()
  364. *
  365. * Function description
  366. * Prepare a SystemView event packet header.
  367. *
  368. * Parameters
  369. * pPacket - Pointer to start of packet to initialize.
  370. *
  371. * Return value
  372. * Pointer to first byte of packet payload.
  373. *
  374. * Additional information
  375. * The payload length and evnetId are not initialized.
  376. * PreparePacket only reserves space for them and they are
  377. * computed and filled in by the sending function.
  378. */
  379. static U8* _PreparePacket(U8* pPacket) {
  380. return pPacket + 4;
  381. }
  382. /*********************************************************************
  383. *
  384. * _HandleIncomingPacket()
  385. *
  386. * Function description
  387. * Read an incoming command from the down channel and process it.
  388. *
  389. * Additional information
  390. * This function is called each time after sending a packet.
  391. * Processing incoming packets is done asynchronous. SystemView might
  392. * already have sent event packets after the host has sent a command.
  393. */
  394. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  395. static void _HandleIncomingPacket(void) {
  396. U8 Cmd;
  397. int Status;
  398. //
  399. Status = SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
  400. if (Status > 0) {
  401. switch (Cmd) {
  402. case SEGGER_SYSVIEW_COMMAND_ID_START:
  403. SEGGER_SYSVIEW_Start();
  404. break;
  405. case SEGGER_SYSVIEW_COMMAND_ID_STOP:
  406. SEGGER_SYSVIEW_Stop();
  407. break;
  408. case SEGGER_SYSVIEW_COMMAND_ID_GET_SYSTIME:
  409. SEGGER_SYSVIEW_RecordSystime();
  410. break;
  411. case SEGGER_SYSVIEW_COMMAND_ID_GET_TASKLIST:
  412. SEGGER_SYSVIEW_SendTaskList();
  413. break;
  414. case SEGGER_SYSVIEW_COMMAND_ID_GET_SYSDESC:
  415. SEGGER_SYSVIEW_GetSysDesc();
  416. break;
  417. case SEGGER_SYSVIEW_COMMAND_ID_GET_NUMMODULES:
  418. SEGGER_SYSVIEW_SendNumModules();
  419. break;
  420. case SEGGER_SYSVIEW_COMMAND_ID_GET_MODULEDESC:
  421. SEGGER_SYSVIEW_SendModuleDescription();
  422. break;
  423. case SEGGER_SYSVIEW_COMMAND_ID_GET_MODULE:
  424. Status = SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
  425. if (Status > 0) {
  426. SEGGER_SYSVIEW_SendModule(Cmd);
  427. }
  428. break;
  429. default:
  430. if (Cmd >= 128) { // Unknown extended command. Dummy read its parameter.
  431. SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
  432. }
  433. break;
  434. }
  435. }
  436. }
  437. #endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  438. /*********************************************************************
  439. *
  440. * _TrySendOverflowPacket()
  441. *
  442. * Function description
  443. * Try to transmit an SystemView Overflow packet containing the
  444. * number of dropped packets.
  445. *
  446. * Additional information
  447. * Format as follows:
  448. * 01 <DropCnt><TimeStamp> Max. packet len is 1 + 5 + 5 = 11
  449. *
  450. * Example packets sent
  451. * 01 20 40
  452. *
  453. * Return value
  454. * !=0: Success, Message sent (stored in RTT-Buffer)
  455. * ==0: Buffer full, Message *NOT* stored
  456. *
  457. */
  458. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  459. static int _TrySendOverflowPacket(void) {
  460. U32 TimeStamp;
  461. I32 Delta;
  462. int Status;
  463. U8 aPacket[11];
  464. U8* pPayload;
  465. aPacket[0] = SYSVIEW_EVTID_OVERFLOW; // 1
  466. pPayload = &aPacket[1];
  467. ENCODE_U32(pPayload, _SYSVIEW_Globals.DropCount);
  468. //
  469. // Compute time stamp delta and append it to packet.
  470. //
  471. TimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP();
  472. Delta = TimeStamp - _SYSVIEW_Globals.LastTxTimeStamp;
  473. MAKE_DELTA_32BIT(Delta);
  474. ENCODE_U32(pPayload, Delta);
  475. //
  476. // Try to store packet in RTT buffer and update time stamp when this was successful
  477. //
  478. Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, aPacket, pPayload - aPacket);
  479. if (Status) {
  480. _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
  481. _SYSVIEW_Globals.EnableState--; // EnableState has been 2, will be 1. Always.
  482. } else {
  483. _SYSVIEW_Globals.DropCount++;
  484. }
  485. //
  486. return Status;
  487. }
  488. #endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  489. /*********************************************************************
  490. *
  491. * _SendSyncInfo()
  492. *
  493. * Function description
  494. * Send SystemView sync packet and system information in
  495. * post mortem mode.
  496. *
  497. * Additional information
  498. * Sync is 10 * 0x00 without timestamp
  499. */
  500. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  501. static void _SendSyncInfo(void) {
  502. //
  503. // Add sync packet ( 10 * 0x00)
  504. // Send system description
  505. // Send system time
  506. // Send task list
  507. // Send module description
  508. // Send module information
  509. //
  510. SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, _abSync, 10);
  511. SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START);
  512. {
  513. U8* pPayload;
  514. U8* pPayloadStart;
  515. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
  516. //
  517. pPayload = pPayloadStart;
  518. ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
  519. ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
  520. ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
  521. ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
  522. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
  523. RECORD_END();
  524. }
  525. if (_SYSVIEW_Globals.pfSendSysDesc) {
  526. _SYSVIEW_Globals.pfSendSysDesc();
  527. }
  528. SEGGER_SYSVIEW_RecordSystime();
  529. SEGGER_SYSVIEW_SendTaskList();
  530. if (_NumModules > 0) {
  531. SEGGER_SYSVIEW_SendNumModules();
  532. for (int n = 0; n < _NumModules; n++) {
  533. SEGGER_SYSVIEW_SendModule(n);
  534. }
  535. SEGGER_SYSVIEW_SendModuleDescription();
  536. }
  537. }
  538. #endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  539. /*********************************************************************
  540. *
  541. * _SendPacket()
  542. *
  543. * Function description
  544. * Send a SystemView packet over RTT. RTT channel and mode are
  545. * configured by macros when the SystemView component is initialized.
  546. * This function takes care of maintaining the packet drop count
  547. * and sending overflow packets when necessary.
  548. * The packet must be passed without Id and Length because this
  549. * function prepends it to the packet before transmission.
  550. *
  551. * Parameters
  552. * pStartPacket - Pointer to start of packet payload.
  553. * There must be at least 4 bytes free to prepend Id and Length.
  554. * pEndPacket - Pointer to end of packet payload.
  555. * EventId - Id of the event to send.
  556. *
  557. */
  558. static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned EventId) {
  559. unsigned NumBytes;
  560. U32 TimeStamp;
  561. U32 Delta;
  562. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
  563. int Status;
  564. #endif
  565. #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0)
  566. SEGGER_SYSVIEW_LOCK();
  567. #endif
  568. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  569. if (_SYSVIEW_Globals.EnableState == 0) {
  570. goto SendDone;
  571. }
  572. #else
  573. if (_SYSVIEW_Globals.EnableState == 1) { // Enabled, no dropped packets remaining
  574. goto Send;
  575. }
  576. if (_SYSVIEW_Globals.EnableState == 0) {
  577. goto SendDone;
  578. }
  579. //
  580. // Handle buffer full situations:
  581. // Have packets been dropped before because buffer was full?
  582. // In this case try to send and overflow packet.
  583. //
  584. if (_SYSVIEW_Globals.EnableState == 2) {
  585. _TrySendOverflowPacket();
  586. if (_SYSVIEW_Globals.EnableState != 1) {
  587. goto SendDone;
  588. }
  589. }
  590. Send:
  591. #endif
  592. //
  593. // Check if event is disabled from being recorded.
  594. //
  595. if (EventId < 32) {
  596. if (_SYSVIEW_Globals.DisabledEvents & ((U32)1u << EventId)) {
  597. goto SendDone;
  598. }
  599. }
  600. //
  601. // Prepare actual packet.
  602. // If it is a known packet, prepend eventId only,
  603. // otherwise prepend packet length and eventId.
  604. //
  605. if (EventId < 24) {
  606. *--pStartPacket = EventId;
  607. } else {
  608. NumBytes = pEndPacket - pStartPacket;
  609. if (NumBytes > 127) {
  610. *--pStartPacket = (NumBytes >> 7);
  611. *--pStartPacket = NumBytes | 0x80;
  612. } else {
  613. *--pStartPacket = NumBytes;
  614. }
  615. if (EventId > 127) {
  616. *--pStartPacket = (EventId >> 7);
  617. *--pStartPacket = EventId | 0x80;
  618. } else {
  619. *--pStartPacket = EventId;
  620. }
  621. }
  622. //
  623. // Compute time stamp delta and append it to packet.
  624. //
  625. TimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP();
  626. Delta = TimeStamp - _SYSVIEW_Globals.LastTxTimeStamp;
  627. MAKE_DELTA_32BIT(Delta);
  628. ENCODE_U32(pEndPacket, Delta);
  629. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  630. //
  631. // Store packet in RTT buffer by overwriting old data and update time stamp
  632. //
  633. SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket);
  634. _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
  635. #else
  636. //
  637. // Try to store packet in RTT buffer and update time stamp when this was successful
  638. //
  639. Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket);
  640. if (Status) {
  641. _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
  642. } else {
  643. _SYSVIEW_Globals.EnableState++; // EnableState has been 1, will be 2. Always.
  644. }
  645. #endif
  646. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  647. //
  648. // Add sync and system information periodically if we are in post mortem mode
  649. //
  650. if (_SYSVIEW_Globals.RecursionCnt == 0) { // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that.
  651. _SYSVIEW_Globals.RecursionCnt = 1;
  652. if (_SYSVIEW_Globals.PacketCount++ & (1 << SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT)) {
  653. _SendSyncInfo();
  654. _SYSVIEW_Globals.PacketCount = 0;
  655. }
  656. _SYSVIEW_Globals.RecursionCnt = 0;
  657. }
  658. SendDone:
  659. ; // Avoid "label at end of compound statement" error when using static buffer
  660. #else
  661. SendDone:
  662. //
  663. // Check if host is sending data which needs to be processed.
  664. // Note that since this code is called for every packet, it is very time critical, so we do
  665. // only what is really needed here, which is checking if there is any data
  666. //
  667. if (SEGGER_RTT_HASDATA(CHANNEL_ID_DOWN)) {
  668. if (_SYSVIEW_Globals.RecursionCnt == 0) { // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that.
  669. _SYSVIEW_Globals.RecursionCnt = 1;
  670. _HandleIncomingPacket();
  671. _SYSVIEW_Globals.RecursionCnt = 0;
  672. }
  673. }
  674. #endif
  675. //
  676. #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0)
  677. SEGGER_SYSVIEW_UNLOCK(); // We are done. Unlock and return
  678. #endif
  679. }
  680. #ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
  681. /*********************************************************************
  682. *
  683. * _APrintHost()
  684. *
  685. * Function description
  686. * Prepares a string and its parameters to be formatted on the host.
  687. *
  688. * Parameters
  689. * s Pointer to format string.
  690. * Options Options to be sent to the host.
  691. * pArguments Pointer to array of arguments for the format string.
  692. * NumArguments Number of arguments in the array.
  693. */
  694. static void _APrintHost(const char* s, U32 Options, U32* pArguments, U32 NumArguments) {
  695. U8* pPayload;
  696. U8* pPayloadStart;
  697. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_ARGUMENTS * SEGGER_SYSVIEW_QUANTA_U32);
  698. pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
  699. ENCODE_U32(pPayload, Options);
  700. ENCODE_U32(pPayload, NumArguments);
  701. while (NumArguments--) {
  702. ENCODE_U32(pPayload, (*pArguments++));
  703. }
  704. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
  705. RECORD_END();
  706. }
  707. /*********************************************************************
  708. *
  709. * _VPrintHost()
  710. *
  711. * Function description
  712. * Prepares a string and its parameters to be formatted on the host.
  713. *
  714. * Parameters
  715. * s Pointer to format string.
  716. * Options Options to be sent to the host.
  717. * pParamList Pointer to the list of arguments for the format string.
  718. */
  719. static void _VPrintHost(const char* s, U32 Options, va_list* pParamList) {
  720. U32 aParas[SEGGER_SYSVIEW_MAX_ARGUMENTS];
  721. U32 NumArguments;
  722. const char* p;
  723. p = s;
  724. NumArguments = 0;
  725. while (*p) {
  726. if (*p == '%') {
  727. aParas[NumArguments++] = va_arg(*pParamList, int);
  728. if (NumArguments == SEGGER_SYSVIEW_MAX_ARGUMENTS) {
  729. break;
  730. }
  731. }
  732. p++;
  733. }
  734. _APrintHost(s, Options, aParas, NumArguments);
  735. }
  736. /*********************************************************************
  737. *
  738. * _StoreChar()
  739. *
  740. * Function description
  741. * Stores a character in the printf-buffer and sends the buffer when
  742. * it is filled.
  743. *
  744. * Parameters
  745. * p Pointer to the buffer description.
  746. * c Character to be printed.
  747. */
  748. static void _StoreChar(SEGGER_SYSVIEW_PRINTF_DESC * p, char c) {
  749. unsigned Cnt;
  750. U8* pPayload;
  751. U32 Options;
  752. Cnt = p->Cnt;
  753. if ((Cnt + 1u) <= SEGGER_SYSVIEW_MAX_STRING_LEN) {
  754. *(p->pPayload++) = c;
  755. p->Cnt = Cnt + 1u;
  756. }
  757. //
  758. // Write part of string, when the buffer is full
  759. //
  760. if (p->Cnt == SEGGER_SYSVIEW_MAX_STRING_LEN) {
  761. *(p->pPayloadStart) = p->Cnt;
  762. pPayload = p->pPayload;
  763. Options = p->Options;
  764. ENCODE_U32(pPayload, Options);
  765. ENCODE_U32(pPayload, 0);
  766. _SendPacket(p->pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
  767. p->pPayloadStart = _PreparePacket(p->pBuffer);
  768. p->pPayload = p->pPayloadStart + 1u;
  769. p->Cnt = 0u;
  770. }
  771. }
  772. /*********************************************************************
  773. *
  774. * _PrintUnsigned()
  775. *
  776. * Function description
  777. * Print an unsigned integer with the given formatting into the
  778. * formatted string.
  779. *
  780. * Parameters
  781. * pBufferDesc Pointer to the buffer description.
  782. * v Value to be printed.
  783. * Base Base of the value.
  784. * NumDigits Number of digits to be printed.
  785. * FieldWidth Width of the printed field.
  786. * FormatFlags Flags for formatting the value.
  787. */
  788. static void _PrintUnsigned(SEGGER_SYSVIEW_PRINTF_DESC * pBufferDesc, unsigned v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
  789. static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
  790. unsigned Div;
  791. unsigned Digit;
  792. unsigned Number;
  793. unsigned Width;
  794. char c;
  795. Number = v;
  796. Digit = 1u;
  797. //
  798. // Get actual field width
  799. //
  800. Width = 1u;
  801. while (Number >= Base) {
  802. Number = (Number / Base);
  803. Width++;
  804. }
  805. if (NumDigits > Width) {
  806. Width = NumDigits;
  807. }
  808. //
  809. // Print leading chars if necessary
  810. //
  811. if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) {
  812. if (FieldWidth != 0u) {
  813. if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) {
  814. c = '0';
  815. } else {
  816. c = ' ';
  817. }
  818. while ((FieldWidth != 0u) && (Width < FieldWidth)) {
  819. FieldWidth--;
  820. _StoreChar(pBufferDesc, c);
  821. }
  822. }
  823. }
  824. //
  825. // Compute Digit.
  826. // Loop until Digit has the value of the highest digit required.
  827. // Example: If the output is 345 (Base 10), loop 2 times until Digit is 100.
  828. //
  829. while (1) {
  830. if (NumDigits > 1u) { // User specified a min number of digits to print? => Make sure we loop at least that often, before checking anything else (> 1 check avoids problems with NumDigits being signed / unsigned)
  831. NumDigits--;
  832. } else {
  833. Div = v / Digit;
  834. if (Div < Base) { // Is our divider big enough to extract the highest digit from value? => Done
  835. break;
  836. }
  837. }
  838. Digit *= Base;
  839. }
  840. //
  841. // Output digits
  842. //
  843. do {
  844. Div = v / Digit;
  845. v -= Div * Digit;
  846. _StoreChar(pBufferDesc, _aV2C[Div]);
  847. Digit /= Base;
  848. } while (Digit);
  849. //
  850. // Print trailing spaces if necessary
  851. //
  852. if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) {
  853. if (FieldWidth != 0u) {
  854. while ((FieldWidth != 0u) && (Width < FieldWidth)) {
  855. FieldWidth--;
  856. _StoreChar(pBufferDesc, ' ');
  857. }
  858. }
  859. }
  860. }
  861. /*********************************************************************
  862. *
  863. * _PrintInt()
  864. *
  865. * Function description
  866. * Print a signed integer with the given formatting into the
  867. * formatted string.
  868. *
  869. * Parameters
  870. * pBufferDesc Pointer to the buffer description.
  871. * v Value to be printed.
  872. * Base Base of the value.
  873. * NumDigits Number of digits to be printed.
  874. * FieldWidth Width of the printed field.
  875. * FormatFlags Flags for formatting the value.
  876. */
  877. static void _PrintInt(SEGGER_SYSVIEW_PRINTF_DESC * pBufferDesc, int v, unsigned Base, unsigned NumDigits, unsigned FieldWidth, unsigned FormatFlags) {
  878. unsigned Width;
  879. int Number;
  880. Number = (v < 0) ? -v : v;
  881. //
  882. // Get actual field width
  883. //
  884. Width = 1u;
  885. while (Number >= (int)Base) {
  886. Number = (Number / (int)Base);
  887. Width++;
  888. }
  889. if (NumDigits > Width) {
  890. Width = NumDigits;
  891. }
  892. if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) {
  893. FieldWidth--;
  894. }
  895. //
  896. // Print leading spaces if necessary
  897. //
  898. if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) {
  899. if (FieldWidth != 0u) {
  900. while ((FieldWidth != 0u) && (Width < FieldWidth)) {
  901. FieldWidth--;
  902. _StoreChar(pBufferDesc, ' ');
  903. }
  904. }
  905. }
  906. //
  907. // Print sign if necessary
  908. //
  909. if (v < 0) {
  910. v = -v;
  911. _StoreChar(pBufferDesc, '-');
  912. } else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) {
  913. _StoreChar(pBufferDesc, '+');
  914. } else {
  915. }
  916. //
  917. // Print leading zeros if necessary
  918. //
  919. if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) {
  920. if (FieldWidth != 0u) {
  921. while ((FieldWidth != 0u) && (Width < FieldWidth)) {
  922. FieldWidth--;
  923. _StoreChar(pBufferDesc, '0');
  924. }
  925. }
  926. }
  927. //
  928. // Print number without sign
  929. //
  930. _PrintUnsigned(pBufferDesc, (unsigned)v, Base, NumDigits, FieldWidth, FormatFlags);
  931. }
  932. /*********************************************************************
  933. *
  934. * _VPrintTarget()
  935. *
  936. * Function description
  937. * Stores a formatted string.
  938. * This data is read by the host.
  939. *
  940. * Parameters
  941. * sFormat Pointer to format string.
  942. * Options Options to be sent to the host.
  943. * pParamList Pointer to the list of arguments for the format string.
  944. */
  945. static void _VPrintTarget(const char* sFormat, U32 Options, va_list* pParamList) {
  946. SEGGER_SYSVIEW_PRINTF_DESC BufferDesc;
  947. char c;
  948. int v;
  949. unsigned NumDigits;
  950. unsigned FormatFlags;
  951. unsigned FieldWidth;
  952. U8* pPayloadStart;
  953. #if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
  954. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 1 + 2 * SEGGER_SYSVIEW_QUANTA_U32);
  955. SEGGER_SYSVIEW_LOCK();
  956. #else
  957. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 1 + 2 * SEGGER_SYSVIEW_QUANTA_U32);
  958. #endif
  959. #if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
  960. BufferDesc.pBuffer = aPacket;
  961. #else
  962. BufferDesc.pBuffer = _aPacket;
  963. #endif
  964. BufferDesc.Cnt = 0u;
  965. BufferDesc.pPayloadStart = pPayloadStart;
  966. BufferDesc.pPayload = BufferDesc.pPayloadStart + 1u;
  967. BufferDesc.Options = Options;
  968. do {
  969. c = *sFormat;
  970. sFormat++;
  971. if (c == 0u) {
  972. break;
  973. }
  974. if (c == '%') {
  975. //
  976. // Filter out flags
  977. //
  978. FormatFlags = 0u;
  979. v = 1;
  980. do {
  981. c = *sFormat;
  982. switch (c) {
  983. case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break;
  984. case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break;
  985. case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break;
  986. case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break;
  987. default: v = 0; break;
  988. }
  989. } while (v);
  990. //
  991. // filter out field with
  992. //
  993. FieldWidth = 0u;
  994. do {
  995. c = *sFormat;
  996. if ((c < '0') || (c > '9')) {
  997. break;
  998. }
  999. sFormat++;
  1000. FieldWidth = (FieldWidth * 10u) + ((unsigned)c - '0');
  1001. } while (1);
  1002. //
  1003. // Filter out precision (number of digits to display)
  1004. //
  1005. NumDigits = 0u;
  1006. c = *sFormat;
  1007. if (c == '.') {
  1008. sFormat++;
  1009. do {
  1010. c = *sFormat;
  1011. if ((c < '0') || (c > '9')) {
  1012. break;
  1013. }
  1014. sFormat++;
  1015. NumDigits = NumDigits * 10u + ((unsigned)c - '0');
  1016. } while (1);
  1017. }
  1018. //
  1019. // Filter out length modifier
  1020. //
  1021. c = *sFormat;
  1022. do {
  1023. if ((c == 'l') || (c == 'h')) {
  1024. c = *sFormat;
  1025. sFormat++;
  1026. } else {
  1027. break;
  1028. }
  1029. } while (1);
  1030. //
  1031. // Handle specifiers
  1032. //
  1033. switch (c) {
  1034. case 'c': {
  1035. char c0;
  1036. v = va_arg(*pParamList, int);
  1037. c0 = (char)v;
  1038. _StoreChar(&BufferDesc, c0);
  1039. break;
  1040. }
  1041. case 'd':
  1042. v = va_arg(*pParamList, int);
  1043. _PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags);
  1044. break;
  1045. case 'u':
  1046. v = va_arg(*pParamList, int);
  1047. _PrintUnsigned(&BufferDesc, (unsigned)v, 10u, NumDigits, FieldWidth, FormatFlags);
  1048. break;
  1049. case 'x':
  1050. case 'X':
  1051. v = va_arg(*pParamList, int);
  1052. _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, NumDigits, FieldWidth, FormatFlags);
  1053. break;
  1054. case 'p':
  1055. v = va_arg(*pParamList, int);
  1056. _PrintUnsigned(&BufferDesc, (unsigned)v, 16u, 8u, 8u, 0u);
  1057. break;
  1058. case '%':
  1059. _StoreChar(&BufferDesc, '%');
  1060. break;
  1061. default:
  1062. break;
  1063. }
  1064. sFormat++;
  1065. } else {
  1066. _StoreChar(&BufferDesc, c);
  1067. }
  1068. } while (*sFormat);
  1069. //
  1070. // Write remaining data, if any
  1071. //
  1072. if (BufferDesc.Cnt != 0u) {
  1073. *(BufferDesc.pPayloadStart) = BufferDesc.Cnt;
  1074. ENCODE_U32(BufferDesc.pPayload, BufferDesc.Options);
  1075. ENCODE_U32(BufferDesc.pPayload, 0);
  1076. _SendPacket(BufferDesc.pPayloadStart, BufferDesc.pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
  1077. }
  1078. #if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
  1079. SEGGER_SYSVIEW_UNLOCK();
  1080. RECORD_END();
  1081. #else
  1082. RECORD_END();
  1083. #endif
  1084. }
  1085. #endif // SEGGER_SYSVIEW_EXCLUDE_PRINTF
  1086. /*********************************************************************
  1087. *
  1088. * Public functions
  1089. *
  1090. **********************************************************************
  1091. */
  1092. /*********************************************************************
  1093. *
  1094. * SEGGER_SYSVIEW_Init()
  1095. *
  1096. * Function description
  1097. * Initializes the SYSVIEW module.
  1098. * Must be called before SystemViewer attaches to the system.
  1099. *
  1100. * Parameters
  1101. * SysFreq - Frequency of timestamp, i.e. CPU core clock frequency.
  1102. * CPUFreq - CPU core clock frequency.
  1103. * pOSAPI - Pointer to the API structure for OS-specific functions.
  1104. * pfSendSysDesc - Pointer to SendSysDesc callback function.
  1105. *
  1106. * Additional information
  1107. * This function initializes the RTT channel used to transport
  1108. * SEGGER SystemView packets.
  1109. * The channel is assigned the label "SysView" for client software
  1110. * to identify the SystemView channel.
  1111. *
  1112. * Notes
  1113. * The channel is configured by the macro SEGGER_SYSVIEW_RTT_CHANNEL.
  1114. */
  1115. void SEGGER_SYSVIEW_Init(U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc) {
  1116. #ifdef SEGGER_RTT_SECTION
  1117. //
  1118. // Explicitly initialize the RTT Control Block if it is in its dedicated section.
  1119. //
  1120. SEGGER_RTT_Init();
  1121. #endif
  1122. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  1123. #if SEGGER_SYSVIEW_RTT_CHANNEL > 0
  1124. SEGGER_RTT_ConfigUpBuffer(SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
  1125. #else
  1126. _SYSVIEW_Globals.UpChannel = SEGGER_RTT_AllocUpBuffer ("SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
  1127. #endif
  1128. _SYSVIEW_Globals.RAMBaseAddress = SEGGER_SYSVIEW_ID_BASE;
  1129. _SYSVIEW_Globals.LastTxTimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP();
  1130. _SYSVIEW_Globals.pOSAPI = pOSAPI;
  1131. _SYSVIEW_Globals.SysFreq = SysFreq;
  1132. _SYSVIEW_Globals.CPUFreq = CPUFreq;
  1133. _SYSVIEW_Globals.pfSendSysDesc = pfSendSysDesc;
  1134. _SYSVIEW_Globals.EnableState = 0;
  1135. _SYSVIEW_Globals.PacketCount = 0;
  1136. #else // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  1137. #if SEGGER_SYSVIEW_RTT_CHANNEL > 0
  1138. SEGGER_RTT_ConfigUpBuffer (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
  1139. SEGGER_RTT_ConfigDownBuffer (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
  1140. #else
  1141. _SYSVIEW_Globals.UpChannel = SEGGER_RTT_AllocUpBuffer ("SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
  1142. //
  1143. // TODO: Use SEGGER_RTT_AllocDownBuffer when SystemViewer is able to handle another Down Channel than Up Channel.
  1144. //
  1145. _SYSVIEW_Globals.DownChannel = _SYSVIEW_Globals.UpChannel;
  1146. SEGGER_RTT_ConfigDownBuffer (_SYSVIEW_Globals.DownChannel, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
  1147. #endif
  1148. _SYSVIEW_Globals.RAMBaseAddress = SEGGER_SYSVIEW_ID_BASE;
  1149. _SYSVIEW_Globals.LastTxTimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP();
  1150. _SYSVIEW_Globals.pOSAPI = pOSAPI;
  1151. _SYSVIEW_Globals.SysFreq = SysFreq;
  1152. _SYSVIEW_Globals.CPUFreq = CPUFreq;
  1153. _SYSVIEW_Globals.pfSendSysDesc = pfSendSysDesc;
  1154. _SYSVIEW_Globals.EnableState = 0;
  1155. #endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  1156. }
  1157. /*********************************************************************
  1158. *
  1159. * SEGGER_SYSVIEW_SetRAMBase()
  1160. *
  1161. * Function description
  1162. * Sets the RAM base address, which is subtracted from IDs in order
  1163. * to save bandwidth.
  1164. *
  1165. * Parameters
  1166. * RAMBaseAddress - Lowest RAM Address. (i.e. 0x20000000 on most Cortex-M)
  1167. */
  1168. void SEGGER_SYSVIEW_SetRAMBase(U32 RAMBaseAddress) {
  1169. _SYSVIEW_Globals.RAMBaseAddress = RAMBaseAddress;
  1170. }
  1171. /*********************************************************************
  1172. *
  1173. * SEGGER_SYSVIEW_RecordVoid()
  1174. *
  1175. * Function description
  1176. * Formats and sends a SystemView packet with an empty payload.
  1177. *
  1178. * Parameters
  1179. * EventID - SystemView event ID.
  1180. */
  1181. void SEGGER_SYSVIEW_RecordVoid(unsigned EventID) {
  1182. U8* pPayloadStart;
  1183. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
  1184. //
  1185. _SendPacket(pPayloadStart, pPayloadStart, EventID);
  1186. RECORD_END();
  1187. }
  1188. /*********************************************************************
  1189. *
  1190. * SEGGER_SYSVIEW_RecordU32()
  1191. *
  1192. * Function description
  1193. * Formats and sends a SystemView packet containing a single U32
  1194. * parameter payload.
  1195. *
  1196. * Parameters
  1197. * EventID - SystemView event ID.
  1198. * Value - The 32-bit parameter encoded to SystemView packet payload.
  1199. */
  1200. void SEGGER_SYSVIEW_RecordU32(unsigned EventID, U32 Value) {
  1201. U8* pPayload;
  1202. U8* pPayloadStart;
  1203. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1204. //
  1205. pPayload = pPayloadStart;
  1206. ENCODE_U32(pPayload, Value);
  1207. _SendPacket(pPayloadStart, pPayload, EventID);
  1208. RECORD_END();
  1209. }
  1210. /*********************************************************************
  1211. *
  1212. * SEGGER_SYSVIEW_RecordU32x2()
  1213. *
  1214. * Function description
  1215. * Formats and sends a SystemView packet containing 2 U32 parameter payload.
  1216. *
  1217. * Parameters
  1218. * EventID - SystemView event ID.
  1219. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1220. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1221. */
  1222. void SEGGER_SYSVIEW_RecordU32x2(unsigned EventID, U32 Para0, U32 Para1) {
  1223. U8* pPayload;
  1224. U8* pPayloadStart;
  1225. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
  1226. //
  1227. pPayload = pPayloadStart;
  1228. ENCODE_U32(pPayload, Para0);
  1229. ENCODE_U32(pPayload, Para1);
  1230. _SendPacket(pPayloadStart, pPayload, EventID);
  1231. RECORD_END();
  1232. }
  1233. /*********************************************************************
  1234. *
  1235. * SEGGER_SYSVIEW_RecordU32x3()
  1236. *
  1237. * Function description
  1238. * Formats and sends a SystemView packet containing 3 U32 parameter payload.
  1239. *
  1240. * Parameters
  1241. * EventID - SystemView event ID.
  1242. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1243. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1244. * Para2 - The 32-bit parameter encoded to SystemView packet payload.
  1245. */
  1246. void SEGGER_SYSVIEW_RecordU32x3(unsigned EventID, U32 Para0, U32 Para1, U32 Para2) {
  1247. U8* pPayload;
  1248. U8* pPayloadStart;
  1249. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 3 * SEGGER_SYSVIEW_QUANTA_U32);
  1250. //
  1251. pPayload = pPayloadStart;
  1252. ENCODE_U32(pPayload, Para0);
  1253. ENCODE_U32(pPayload, Para1);
  1254. ENCODE_U32(pPayload, Para2);
  1255. _SendPacket(pPayloadStart, pPayload, EventID);
  1256. RECORD_END();
  1257. }
  1258. /*********************************************************************
  1259. *
  1260. * SEGGER_SYSVIEW_RecordU32x4()
  1261. *
  1262. * Function description
  1263. * Formats and sends a SystemView packet containing 4 U32 parameter payload.
  1264. *
  1265. * Parameters
  1266. * EventID - SystemView event ID.
  1267. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1268. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1269. * Para2 - The 32-bit parameter encoded to SystemView packet payload.
  1270. * Para3 - The 32-bit parameter encoded to SystemView packet payload.
  1271. */
  1272. void SEGGER_SYSVIEW_RecordU32x4(unsigned EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3) {
  1273. U8* pPayload;
  1274. U8* pPayloadStart;
  1275. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
  1276. //
  1277. pPayload = pPayloadStart;
  1278. ENCODE_U32(pPayload, Para0);
  1279. ENCODE_U32(pPayload, Para1);
  1280. ENCODE_U32(pPayload, Para2);
  1281. ENCODE_U32(pPayload, Para3);
  1282. _SendPacket(pPayloadStart, pPayload, EventID);
  1283. RECORD_END();
  1284. }
  1285. /*********************************************************************
  1286. *
  1287. * SEGGER_SYSVIEW_RecordU32x5()
  1288. *
  1289. * Function description
  1290. * Formats and sends a SystemView packet containing 5 U32 parameter payload.
  1291. *
  1292. * Parameters
  1293. * EventID - SystemView event ID.
  1294. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1295. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1296. * Para2 - The 32-bit parameter encoded to SystemView packet payload.
  1297. * Para3 - The 32-bit parameter encoded to SystemView packet payload.
  1298. * Para4 - The 32-bit parameter encoded to SystemView packet payload.
  1299. */
  1300. void SEGGER_SYSVIEW_RecordU32x5(unsigned EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) {
  1301. U8* pPayload;
  1302. U8* pPayloadStart;
  1303. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32);
  1304. //
  1305. pPayload = pPayloadStart;
  1306. ENCODE_U32(pPayload, Para0);
  1307. ENCODE_U32(pPayload, Para1);
  1308. ENCODE_U32(pPayload, Para2);
  1309. ENCODE_U32(pPayload, Para3);
  1310. ENCODE_U32(pPayload, Para4);
  1311. _SendPacket(pPayloadStart, pPayload, EventID);
  1312. RECORD_END();
  1313. }
  1314. /*********************************************************************
  1315. *
  1316. * SEGGER_SYSVIEW_RecordU32x6()
  1317. *
  1318. * Function description
  1319. * Formats and sends a SystemView packet containing 6 U32 parameter payload.
  1320. *
  1321. * Parameters
  1322. * EventID - SystemView event ID.
  1323. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1324. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1325. * Para2 - The 32-bit parameter encoded to SystemView packet payload.
  1326. * Para3 - The 32-bit parameter encoded to SystemView packet payload.
  1327. * Para4 - The 32-bit parameter encoded to SystemView packet payload.
  1328. * Para5 - The 32-bit parameter encoded to SystemView packet payload.
  1329. */
  1330. void SEGGER_SYSVIEW_RecordU32x6(unsigned EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5) {
  1331. U8* pPayload;
  1332. U8* pPayloadStart;
  1333. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 6 * SEGGER_SYSVIEW_QUANTA_U32);
  1334. //
  1335. pPayload = pPayloadStart;
  1336. ENCODE_U32(pPayload, Para0);
  1337. ENCODE_U32(pPayload, Para1);
  1338. ENCODE_U32(pPayload, Para2);
  1339. ENCODE_U32(pPayload, Para3);
  1340. ENCODE_U32(pPayload, Para4);
  1341. ENCODE_U32(pPayload, Para5);
  1342. _SendPacket(pPayloadStart, pPayload, EventID);
  1343. RECORD_END();
  1344. }
  1345. /*********************************************************************
  1346. *
  1347. * SEGGER_SYSVIEW_RecordU32x7()
  1348. *
  1349. * Function description
  1350. * Formats and sends a SystemView packet containing 7 U32 parameter payload.
  1351. *
  1352. * Parameters
  1353. * EventID - SystemView event ID.
  1354. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1355. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1356. * Para2 - The 32-bit parameter encoded to SystemView packet payload.
  1357. * Para3 - The 32-bit parameter encoded to SystemView packet payload.
  1358. * Para4 - The 32-bit parameter encoded to SystemView packet payload.
  1359. * Para5 - The 32-bit parameter encoded to SystemView packet payload.
  1360. * Para6 - The 32-bit parameter encoded to SystemView packet payload.
  1361. */
  1362. void SEGGER_SYSVIEW_RecordU32x7(unsigned EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6) {
  1363. U8* pPayload;
  1364. U8* pPayloadStart;
  1365. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 7 * SEGGER_SYSVIEW_QUANTA_U32);
  1366. //
  1367. pPayload = pPayloadStart;
  1368. ENCODE_U32(pPayload, Para0);
  1369. ENCODE_U32(pPayload, Para1);
  1370. ENCODE_U32(pPayload, Para2);
  1371. ENCODE_U32(pPayload, Para3);
  1372. ENCODE_U32(pPayload, Para4);
  1373. ENCODE_U32(pPayload, Para5);
  1374. ENCODE_U32(pPayload, Para6);
  1375. _SendPacket(pPayloadStart, pPayload, EventID);
  1376. RECORD_END();
  1377. }
  1378. /*********************************************************************
  1379. *
  1380. * SEGGER_SYSVIEW_RecordU32x8()
  1381. *
  1382. * Function description
  1383. * Formats and sends a SystemView packet containing 8 U32 parameter payload.
  1384. *
  1385. * Parameters
  1386. * EventID - SystemView event ID.
  1387. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1388. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1389. * Para2 - The 32-bit parameter encoded to SystemView packet payload.
  1390. * Para3 - The 32-bit parameter encoded to SystemView packet payload.
  1391. * Para4 - The 32-bit parameter encoded to SystemView packet payload.
  1392. * Para5 - The 32-bit parameter encoded to SystemView packet payload.
  1393. * Para6 - The 32-bit parameter encoded to SystemView packet payload.
  1394. * Para7 - The 32-bit parameter encoded to SystemView packet payload.
  1395. */
  1396. void SEGGER_SYSVIEW_RecordU32x8(unsigned EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7) {
  1397. U8* pPayload;
  1398. U8* pPayloadStart;
  1399. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 8 * SEGGER_SYSVIEW_QUANTA_U32);
  1400. //
  1401. pPayload = pPayloadStart;
  1402. ENCODE_U32(pPayload, Para0);
  1403. ENCODE_U32(pPayload, Para1);
  1404. ENCODE_U32(pPayload, Para2);
  1405. ENCODE_U32(pPayload, Para3);
  1406. ENCODE_U32(pPayload, Para4);
  1407. ENCODE_U32(pPayload, Para5);
  1408. ENCODE_U32(pPayload, Para6);
  1409. ENCODE_U32(pPayload, Para7);
  1410. _SendPacket(pPayloadStart, pPayload, EventID);
  1411. RECORD_END();
  1412. }
  1413. /*********************************************************************
  1414. *
  1415. * SEGGER_SYSVIEW_RecordU32x9()
  1416. *
  1417. * Function description
  1418. * Formats and sends a SystemView packet containing 9 U32 parameter payload.
  1419. *
  1420. * Parameters
  1421. * EventID - SystemView event ID.
  1422. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1423. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1424. * Para2 - The 32-bit parameter encoded to SystemView packet payload.
  1425. * Para3 - The 32-bit parameter encoded to SystemView packet payload.
  1426. * Para4 - The 32-bit parameter encoded to SystemView packet payload.
  1427. * Para5 - The 32-bit parameter encoded to SystemView packet payload.
  1428. * Para6 - The 32-bit parameter encoded to SystemView packet payload.
  1429. * Para7 - The 32-bit parameter encoded to SystemView packet payload.
  1430. * Para8 - The 32-bit parameter encoded to SystemView packet payload.
  1431. */
  1432. void SEGGER_SYSVIEW_RecordU32x9(unsigned EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7, U32 Para8) {
  1433. U8* pPayload;
  1434. U8* pPayloadStart;
  1435. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 9 * SEGGER_SYSVIEW_QUANTA_U32);
  1436. //
  1437. pPayload = pPayloadStart;
  1438. ENCODE_U32(pPayload, Para0);
  1439. ENCODE_U32(pPayload, Para1);
  1440. ENCODE_U32(pPayload, Para2);
  1441. ENCODE_U32(pPayload, Para3);
  1442. ENCODE_U32(pPayload, Para4);
  1443. ENCODE_U32(pPayload, Para5);
  1444. ENCODE_U32(pPayload, Para6);
  1445. ENCODE_U32(pPayload, Para7);
  1446. ENCODE_U32(pPayload, Para8);
  1447. _SendPacket(pPayloadStart, pPayload, EventID);
  1448. RECORD_END();
  1449. }
  1450. /*********************************************************************
  1451. *
  1452. * SEGGER_SYSVIEW_RecordU32x10()
  1453. *
  1454. * Function description
  1455. * Formats and sends a SystemView packet containing 10 U32 parameter payload.
  1456. *
  1457. * Parameters
  1458. * EventID - SystemView event ID.
  1459. * Para0 - The 32-bit parameter encoded to SystemView packet payload.
  1460. * Para1 - The 32-bit parameter encoded to SystemView packet payload.
  1461. * Para2 - The 32-bit parameter encoded to SystemView packet payload.
  1462. * Para3 - The 32-bit parameter encoded to SystemView packet payload.
  1463. * Para4 - The 32-bit parameter encoded to SystemView packet payload.
  1464. * Para5 - The 32-bit parameter encoded to SystemView packet payload.
  1465. * Para6 - The 32-bit parameter encoded to SystemView packet payload.
  1466. * Para7 - The 32-bit parameter encoded to SystemView packet payload.
  1467. * Para8 - The 32-bit parameter encoded to SystemView packet payload.
  1468. * Para9 - The 32-bit parameter encoded to SystemView packet payload.
  1469. */
  1470. 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) {
  1471. U8* pPayload;
  1472. U8* pPayloadStart;
  1473. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 10 * SEGGER_SYSVIEW_QUANTA_U32);
  1474. //
  1475. pPayload = pPayloadStart;
  1476. ENCODE_U32(pPayload, Para0);
  1477. ENCODE_U32(pPayload, Para1);
  1478. ENCODE_U32(pPayload, Para2);
  1479. ENCODE_U32(pPayload, Para3);
  1480. ENCODE_U32(pPayload, Para4);
  1481. ENCODE_U32(pPayload, Para5);
  1482. ENCODE_U32(pPayload, Para6);
  1483. ENCODE_U32(pPayload, Para7);
  1484. ENCODE_U32(pPayload, Para8);
  1485. ENCODE_U32(pPayload, Para9);
  1486. _SendPacket(pPayloadStart, pPayload, EventID);
  1487. RECORD_END();
  1488. }
  1489. /*********************************************************************
  1490. *
  1491. * SEGGER_SYSVIEW_RecordString()
  1492. *
  1493. * Function description
  1494. * Formats and sends a SystemView packet containing a string.
  1495. *
  1496. * Parameters
  1497. * EventID - SystemView event ID.
  1498. * pString - The string to be sent in the SystemView packet payload.
  1499. *
  1500. * Additional information
  1501. * The string is encoded as a count byte followed by the contents
  1502. * of the string.
  1503. * No more than SEGGER_SYSVIEW_MAX_STRING_LEN bytes will be encoded to the payload.
  1504. */
  1505. void SEGGER_SYSVIEW_RecordString(unsigned EventID, const char* pString) {
  1506. U8* pPayload;
  1507. U8* pPayloadStart;
  1508. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
  1509. //
  1510. pPayload = _EncodeStr(pPayloadStart, pString, SEGGER_SYSVIEW_MAX_STRING_LEN);
  1511. _SendPacket(pPayloadStart, pPayload, EventID);
  1512. RECORD_END();
  1513. }
  1514. /*********************************************************************
  1515. *
  1516. * SEGGER_SYSVIEW_Start()
  1517. *
  1518. * Function description
  1519. * Start recording SystemView events.
  1520. * This function is triggered by the host application.
  1521. *
  1522. * Additional information
  1523. * This function enables transmission of SystemView packets recorded
  1524. * by subsequent trace calls and records a SystemView Start event.
  1525. *
  1526. * As part of start, a SystemView Init packet is sent, containing the system
  1527. * frequency. The list of current tasks, the current system time and the
  1528. * system description string is sent, too.
  1529. *
  1530. * Notes
  1531. * SEGGER_SYSVIEW_Start and SEGGER_SYSVIEW_Stop do not nest.
  1532. */
  1533. void SEGGER_SYSVIEW_Start(void) {
  1534. if (_SYSVIEW_Globals.EnableState == 0) {
  1535. _SYSVIEW_Globals.EnableState = 1;
  1536. #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
  1537. _SendSyncInfo();
  1538. #else
  1539. SEGGER_SYSVIEW_LOCK();
  1540. SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, _abSync, 10);
  1541. SEGGER_SYSVIEW_UNLOCK();
  1542. SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START);
  1543. {
  1544. U8* pPayload;
  1545. U8* pPayloadStart;
  1546. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
  1547. //
  1548. pPayload = pPayloadStart;
  1549. ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
  1550. ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
  1551. ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
  1552. ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
  1553. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
  1554. RECORD_END();
  1555. }
  1556. if (_SYSVIEW_Globals.pfSendSysDesc) {
  1557. _SYSVIEW_Globals.pfSendSysDesc();
  1558. }
  1559. SEGGER_SYSVIEW_RecordSystime();
  1560. SEGGER_SYSVIEW_SendTaskList();
  1561. SEGGER_SYSVIEW_SendNumModules();
  1562. #endif
  1563. }
  1564. }
  1565. /*********************************************************************
  1566. *
  1567. * SEGGER_SYSVIEW_Stop()
  1568. *
  1569. * Function description
  1570. * Stop recording SystemView events.
  1571. *
  1572. * Additional information
  1573. * This function disables transmission of SystemView packets recorded
  1574. * by subsequent trace calls. If transmission is enabled when
  1575. * this function is called, a single SystemView Stop event is recorded
  1576. * to the trace, send, and then trace transmission is halted.
  1577. */
  1578. void SEGGER_SYSVIEW_Stop(void) {
  1579. U8* pPayloadStart;
  1580. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
  1581. //
  1582. if (_SYSVIEW_Globals.EnableState) {
  1583. _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TRACE_STOP);
  1584. _SYSVIEW_Globals.EnableState = 0;
  1585. }
  1586. RECORD_END();
  1587. }
  1588. /*********************************************************************
  1589. *
  1590. * SEGGER_SYSVIEW_GetSysDesc()
  1591. *
  1592. * Function description
  1593. * Triggers a send of the system information and description.
  1594. *
  1595. */
  1596. void SEGGER_SYSVIEW_GetSysDesc(void) {
  1597. U8* pPayload;
  1598. U8* pPayloadStart;
  1599. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
  1600. //
  1601. pPayload = pPayloadStart;
  1602. ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
  1603. ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
  1604. ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
  1605. ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
  1606. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
  1607. RECORD_END();
  1608. if (_SYSVIEW_Globals.pfSendSysDesc) {
  1609. _SYSVIEW_Globals.pfSendSysDesc();
  1610. }
  1611. }
  1612. /*********************************************************************
  1613. *
  1614. * SEGGER_SYSVIEW_SendTaskInfo()
  1615. *
  1616. * Function description
  1617. * Send a Task Info Packet, containing TaskId for identification,
  1618. * task priority and task name.
  1619. *
  1620. * Parameters
  1621. * pInfo - Pointer to task information to send.
  1622. */
  1623. void SEGGER_SYSVIEW_SendTaskInfo(const SEGGER_SYSVIEW_TASKINFO *pInfo) {
  1624. U8* pPayload;
  1625. U8* pPayloadStart;
  1626. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + 1 + 32);
  1627. //
  1628. pPayload = pPayloadStart;
  1629. ENCODE_U32(pPayload, SHRINK_ID(pInfo->TaskID));
  1630. ENCODE_U32(pPayload, pInfo->Prio);
  1631. pPayload = _EncodeStr(pPayload, pInfo->sName, 32);
  1632. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_INFO);
  1633. //
  1634. pPayload = pPayloadStart;
  1635. ENCODE_U32(pPayload, SHRINK_ID(pInfo->TaskID));
  1636. ENCODE_U32(pPayload, pInfo->StackBase);
  1637. ENCODE_U32(pPayload, pInfo->StackSize);
  1638. ENCODE_U32(pPayload, 0); // Stack End, future use
  1639. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_STACK_INFO);
  1640. RECORD_END();
  1641. }
  1642. /*********************************************************************
  1643. *
  1644. * SEGGER_SYSVIEW_SendTaskList()
  1645. *
  1646. * Function description
  1647. * Send all tasks descriptors to the host.
  1648. */
  1649. void SEGGER_SYSVIEW_SendTaskList(void) {
  1650. if (_SYSVIEW_Globals.pOSAPI && _SYSVIEW_Globals.pOSAPI->pfSendTaskList) {
  1651. _SYSVIEW_Globals.pOSAPI->pfSendTaskList();
  1652. }
  1653. }
  1654. /*********************************************************************
  1655. *
  1656. * SEGGER_SYSVIEW_SendSysDesc()
  1657. *
  1658. * Function description
  1659. * Send the system description string to the host.
  1660. * The system description is used by SystemViewer to identify the
  1661. * current application and handle events accordingly.
  1662. *
  1663. * Parameters
  1664. * sSysDesc - Pointer to the 0-terminated system description string.
  1665. *
  1666. * Additional information
  1667. * One system description string may not exceed SEGGER_SYSVIEW_MAX_STRING_LEN characters.
  1668. *
  1669. * The Following items can be described in a system description string.
  1670. * Each item is identified by its identifier, followed by '=' and the value.
  1671. * Items are separated by ','.
  1672. */
  1673. void SEGGER_SYSVIEW_SendSysDesc(const char *sSysDesc) {
  1674. U8* pPayload;
  1675. U8* pPayloadStart;
  1676. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
  1677. //
  1678. pPayload = _EncodeStr(pPayloadStart, sSysDesc, SEGGER_SYSVIEW_MAX_STRING_LEN);
  1679. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_SYSDESC);
  1680. RECORD_END();
  1681. }
  1682. /*********************************************************************
  1683. *
  1684. * SEGGER_SYSVIEW_RecordSystime()
  1685. *
  1686. * Function description
  1687. * Formats and sends a SystemView Systime containing a single U64 or U32
  1688. * parameter payload.
  1689. */
  1690. void SEGGER_SYSVIEW_RecordSystime(void) {
  1691. U64 Systime;
  1692. if (_SYSVIEW_Globals.pOSAPI && _SYSVIEW_Globals.pOSAPI->pfGetTime) {
  1693. Systime = _SYSVIEW_Globals.pOSAPI->pfGetTime();
  1694. SEGGER_SYSVIEW_RecordU32x2(SYSVIEW_EVTID_SYSTIME_US,
  1695. (U32)(Systime),
  1696. (U32)(Systime >> 32));
  1697. } else {
  1698. SEGGER_SYSVIEW_RecordU32(SYSVIEW_EVTID_SYSTIME_CYCLES, SEGGER_SYSVIEW_GET_TIMESTAMP());
  1699. }
  1700. }
  1701. /*********************************************************************
  1702. *
  1703. * SEGGER_SYSVIEW_RecordEnterISR()
  1704. *
  1705. * Function description
  1706. * Format and send an ISR entry event.
  1707. *
  1708. * Additional information
  1709. * Example packets sent
  1710. * 02 0F 50 // ISR(15) Enter. Timestamp is 80 (0x50)
  1711. */
  1712. void SEGGER_SYSVIEW_RecordEnterISR(void) {
  1713. unsigned v;
  1714. U8* pPayload;
  1715. U8* pPayloadStart;
  1716. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1717. //
  1718. pPayload = pPayloadStart;
  1719. v = SEGGER_SYSVIEW_GET_INTERRUPT_ID();
  1720. ENCODE_U32(pPayload, v);
  1721. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_ISR_ENTER);
  1722. RECORD_END();
  1723. }
  1724. /*********************************************************************
  1725. *
  1726. * SEGGER_SYSVIEW_RecordExitISR()
  1727. *
  1728. * Function description
  1729. * Format and send an ISR exit event.
  1730. *
  1731. * Additional information
  1732. * Format as follows:
  1733. * 03 <TimeStamp> // Max. packet len is 6
  1734. *
  1735. * Example packets sent
  1736. * 03 20 // ISR Exit. Timestamp is 32 (0x20)
  1737. */
  1738. void SEGGER_SYSVIEW_RecordExitISR(void) {
  1739. U8* pPayloadStart;
  1740. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
  1741. //
  1742. _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_ISR_EXIT);
  1743. RECORD_END();
  1744. }
  1745. /*********************************************************************
  1746. *
  1747. * SEGGER_SYSVIEW_RecordExitISRToScheduler()
  1748. *
  1749. * Function description
  1750. * Format and send an ISR exit into scheduler event.
  1751. *
  1752. * Additional information
  1753. * Format as follows:
  1754. * 18 <TimeStamp> // Max. packet len is 6
  1755. *
  1756. * Example packets sent
  1757. * 18 20 // ISR Exit to Scheduler. Timestamp is 32 (0x20)
  1758. */
  1759. void SEGGER_SYSVIEW_RecordExitISRToScheduler(void) {
  1760. U8* pPayloadStart;
  1761. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
  1762. //
  1763. _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_ISR_TO_SCHEDULER);
  1764. RECORD_END();
  1765. }
  1766. /*********************************************************************
  1767. *
  1768. * SEGGER_SYSVIEW_RecordEnterTimer()
  1769. *
  1770. * Function description
  1771. * Format and send a Timer entry event.
  1772. *
  1773. * Parameters
  1774. * TimerId - Id of the timer which starts.
  1775. */
  1776. void SEGGER_SYSVIEW_RecordEnterTimer(U32 TimerId) {
  1777. U8* pPayload;
  1778. U8* pPayloadStart;
  1779. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1780. //
  1781. pPayload = pPayloadStart;
  1782. ENCODE_U32(pPayload, SHRINK_ID(TimerId));
  1783. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TIMER_ENTER);
  1784. RECORD_END();
  1785. }
  1786. /*********************************************************************
  1787. *
  1788. * SEGGER_SYSVIEW_RecordExitTimer()
  1789. *
  1790. * Function description
  1791. * Format and send a Timer exit event.
  1792. */
  1793. void SEGGER_SYSVIEW_RecordExitTimer(void) {
  1794. U8* pPayloadStart;
  1795. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
  1796. //
  1797. _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TIMER_EXIT);
  1798. RECORD_END();
  1799. }
  1800. /*********************************************************************
  1801. *
  1802. * SEGGER_SYSVIEW_RecordEndCall()
  1803. *
  1804. * Function description
  1805. * Format and send an End API Call event without return value.
  1806. *
  1807. * Parameters
  1808. * EventID - Id of API function which ends.
  1809. */
  1810. void SEGGER_SYSVIEW_RecordEndCall(unsigned EventID) {
  1811. U8* pPayload;
  1812. U8* pPayloadStart;
  1813. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1814. //
  1815. pPayload = pPayloadStart;
  1816. ENCODE_U32(pPayload, EventID);
  1817. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_END_CALL);
  1818. RECORD_END();
  1819. }
  1820. /*********************************************************************
  1821. *
  1822. * SEGGER_SYSVIEW_RecordEndCallU32()
  1823. *
  1824. * Function description
  1825. * Format and send an End API Call event with return value.
  1826. *
  1827. * Parameters
  1828. * EventID - Id of API function which ends.
  1829. * Para0 - Return value which will be returned by the API function.
  1830. */
  1831. void SEGGER_SYSVIEW_RecordEndCallU32(unsigned EventID, U32 Para0) {
  1832. U8* pPayload;
  1833. U8* pPayloadStart;
  1834. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
  1835. //
  1836. pPayload = pPayloadStart;
  1837. ENCODE_U32(pPayload, EventID);
  1838. ENCODE_U32(pPayload, Para0);
  1839. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_END_CALL);
  1840. RECORD_END();
  1841. }
  1842. /*********************************************************************
  1843. *
  1844. * SEGGER_SYSVIEW_OnIdle()
  1845. *
  1846. * Function description
  1847. * Record an Idle event.
  1848. */
  1849. void SEGGER_SYSVIEW_OnIdle(void) {
  1850. U8* pPayloadStart;
  1851. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
  1852. //
  1853. _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_IDLE);
  1854. RECORD_END();
  1855. }
  1856. /*********************************************************************
  1857. *
  1858. * SEGGER_SYSVIEW_OnTaskCreate()
  1859. *
  1860. * Function description
  1861. * Record a Task Create event. The Task Create event corresponds
  1862. * to creating a task in the OS.
  1863. *
  1864. * Parameters
  1865. * TaskId - Task ID of created task.
  1866. */
  1867. void SEGGER_SYSVIEW_OnTaskCreate(unsigned TaskId) {
  1868. U8* pPayload;
  1869. U8* pPayloadStart;
  1870. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1871. //
  1872. pPayload = pPayloadStart;
  1873. TaskId = SHRINK_ID(TaskId);
  1874. ENCODE_U32(pPayload, TaskId);
  1875. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_CREATE);
  1876. RECORD_END();
  1877. }
  1878. /*********************************************************************
  1879. *
  1880. * SEGGER_SYSVIEW_OnTaskTerminate()
  1881. *
  1882. * Function description
  1883. * Record a Task termination event.
  1884. * The Task termination event corresponds to terminating a task in
  1885. * the OS. If the TaskId is the currently active task,
  1886. * SEGGER_SYSVIEW_OnTaskStopExec may be used, either.
  1887. *
  1888. * Parameters
  1889. * TaskId - Task ID of terminated task.
  1890. */
  1891. void SEGGER_SYSVIEW_OnTaskTerminate(unsigned TaskId) {
  1892. U8* pPayload;
  1893. U8* pPayloadStart;
  1894. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1895. //
  1896. pPayload = pPayloadStart;
  1897. TaskId = SHRINK_ID(TaskId);
  1898. ENCODE_U32(pPayload, TaskId);
  1899. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_TERMINATE);
  1900. RECORD_END();
  1901. }
  1902. /*********************************************************************
  1903. *
  1904. * SEGGER_SYSVIEW_OnTaskStartExec()
  1905. *
  1906. * Function description
  1907. * Record a Task Start Execution event. The Task Start event
  1908. * corresponds to when a task has started to execute rather than
  1909. * when it is ready to execute.
  1910. *
  1911. * Parameters
  1912. * TaskId - Task ID of task that started to execute.
  1913. */
  1914. void SEGGER_SYSVIEW_OnTaskStartExec(unsigned TaskId) {
  1915. U8* pPayload;
  1916. U8* pPayloadStart;
  1917. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1918. //
  1919. pPayload = pPayloadStart;
  1920. TaskId = SHRINK_ID(TaskId);
  1921. ENCODE_U32(pPayload, TaskId);
  1922. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_START_EXEC);
  1923. RECORD_END();
  1924. }
  1925. /*********************************************************************
  1926. *
  1927. * SEGGER_SYSVIEW_OnTaskStopExec()
  1928. *
  1929. * Function description
  1930. * Record a Task Stop Execution event. The Task Stop event
  1931. * corresponds to when a task stops executing and terminates.
  1932. */
  1933. void SEGGER_SYSVIEW_OnTaskStopExec(void) {
  1934. U8* pPayloadStart;
  1935. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
  1936. //
  1937. _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TASK_STOP_EXEC);
  1938. RECORD_END();
  1939. }
  1940. /*********************************************************************
  1941. *
  1942. * SEGGER_SYSVIEW_OnTaskStartReady()
  1943. *
  1944. * Function description
  1945. * Record a Task Start Ready event.
  1946. *
  1947. * Parameters
  1948. * TaskId - Task ID of task that started to execute.
  1949. */
  1950. void SEGGER_SYSVIEW_OnTaskStartReady(unsigned TaskId) {
  1951. U8* pPayload;
  1952. U8* pPayloadStart;
  1953. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1954. //
  1955. pPayload = pPayloadStart;
  1956. TaskId = SHRINK_ID(TaskId);
  1957. ENCODE_U32(pPayload, TaskId);
  1958. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_START_READY);
  1959. RECORD_END();
  1960. }
  1961. /*********************************************************************
  1962. *
  1963. * SEGGER_SYSVIEW_OnTaskStopReady()
  1964. *
  1965. * Function description
  1966. * Record a Task Stop Ready event.
  1967. *
  1968. * Parameters
  1969. * TaskId - Task ID of task that completed execution.
  1970. * Cause - Reason for task to stop (i.e. Idle/Sleep)
  1971. */
  1972. void SEGGER_SYSVIEW_OnTaskStopReady(unsigned TaskId, unsigned Cause) {
  1973. U8* pPayload;
  1974. U8* pPayloadStart;
  1975. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
  1976. //
  1977. pPayload = pPayloadStart;
  1978. TaskId = SHRINK_ID(TaskId);
  1979. ENCODE_U32(pPayload, TaskId);
  1980. ENCODE_U32(pPayload, Cause);
  1981. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_STOP_READY);
  1982. RECORD_END();
  1983. }
  1984. /*********************************************************************
  1985. *
  1986. * SEGGER_SYSVIEW_OnUserStart()
  1987. *
  1988. * Function description
  1989. * Send a user event start, such as start of a subroutine for profiling.
  1990. *
  1991. * Parameters
  1992. * UserId - User defined ID for the event.
  1993. */
  1994. void SEGGER_SYSVIEW_OnUserStart(unsigned UserId) {
  1995. U8* pPayload;
  1996. U8* pPayloadStart;
  1997. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  1998. //
  1999. pPayload = pPayloadStart;
  2000. ENCODE_U32(pPayload, UserId);
  2001. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_USER_START);
  2002. RECORD_END();
  2003. }
  2004. /*********************************************************************
  2005. *
  2006. * SEGGER_SYSVIEW_OnUserStop()
  2007. *
  2008. * Function description
  2009. * Send a user event stop, such as return of a subroutine for profiling.
  2010. *
  2011. * Parameters
  2012. * UserId - User defined ID for the event.
  2013. */
  2014. void SEGGER_SYSVIEW_OnUserStop(unsigned UserId) {
  2015. U8 * pPayload;
  2016. U8 * pPayloadStart;
  2017. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
  2018. //
  2019. pPayload = pPayloadStart;
  2020. ENCODE_U32(pPayload, UserId);
  2021. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_USER_STOP);
  2022. RECORD_END();
  2023. }
  2024. /*********************************************************************
  2025. *
  2026. * SEGGER_SYSVIEW_NameResource()
  2027. *
  2028. * Function description
  2029. * Send the name of a resource to be displayed in SystemViewer.
  2030. *
  2031. * Parameters
  2032. * ResourceId - Id of the resource to be named. i.e. its address.
  2033. * sName - Pointer to the resource name. (Max. SEGGER_SYSVIEW_MAX_STRING_LEN Bytes)
  2034. */
  2035. void SEGGER_SYSVIEW_NameResource(U32 ResourceId, const char* sName) {
  2036. U8* pPayload;
  2037. U8* pPayloadStart;
  2038. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
  2039. //
  2040. pPayload = pPayloadStart;
  2041. ENCODE_U32(pPayload, SHRINK_ID(ResourceId));
  2042. pPayload = _EncodeStr(pPayload, sName, SEGGER_SYSVIEW_MAX_STRING_LEN);
  2043. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_NAME_RESOURCE);
  2044. RECORD_END();
  2045. }
  2046. /*********************************************************************
  2047. *
  2048. * SEGGER_SYSVIEW_SendPacket()
  2049. *
  2050. * Function description
  2051. * Send an event packet.
  2052. *
  2053. * Parameters
  2054. * pPacket - Pointer to the start of the packet.
  2055. * pPayloadEnd - Pointer to the end of the payload.
  2056. * Make sure there are at least 5 bytes free after the payload.
  2057. * EventId - Id of the event packet.
  2058. *
  2059. * Return value
  2060. * !=0: Success, Message sent.
  2061. * ==0: Buffer full, Message *NOT* sent.
  2062. */
  2063. int SEGGER_SYSVIEW_SendPacket(U8* pPacket, U8* pPayloadEnd, unsigned EventId) {
  2064. #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
  2065. SEGGER_SYSVIEW_LOCK();
  2066. #endif
  2067. _SendPacket(pPacket + 4, pPayloadEnd, EventId);
  2068. #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
  2069. SEGGER_SYSVIEW_UNLOCK();
  2070. #endif
  2071. return 0;
  2072. }
  2073. /*********************************************************************
  2074. *
  2075. * SEGGER_SYSVIEW_EncodeU32()
  2076. *
  2077. * Function description
  2078. * Encode a U32 in variable-length format.
  2079. *
  2080. * Parameters
  2081. * pPayload - Pointer to where U32 will be encoded.
  2082. * Value - The 32-bit value to be encoded.
  2083. *
  2084. * Return value
  2085. * Pointer to the byte following the value, i.e. the first free
  2086. * byte in the payload and the next position to store payload
  2087. * content.
  2088. */
  2089. U8* SEGGER_SYSVIEW_EncodeU32(U8* pPayload, unsigned Value) {
  2090. ENCODE_U32(pPayload, Value);
  2091. return pPayload;
  2092. }
  2093. /*********************************************************************
  2094. *
  2095. * SEGGER_SYSVIEW_EncodeString()
  2096. *
  2097. * Function description
  2098. * Encode a string in variable-length format.
  2099. *
  2100. * Parameters
  2101. * pPayload - Pointer to where string will be encoded.
  2102. * s - String to encode.
  2103. * MaxLen - Maximum number of characters to encode from string.
  2104. *
  2105. * Return value
  2106. * Pointer to the byte following the value, i.e. the first free
  2107. * byte in the payload and the next position to store payload
  2108. * content.
  2109. *
  2110. * Additional information
  2111. * The string is encoded as a count byte followed by the contents
  2112. * of the string.
  2113. * No more than 1 + MaxLen bytes will be encoded to the payload.
  2114. */
  2115. U8* SEGGER_SYSVIEW_EncodeString(U8* pPayload, const char* s, unsigned MaxLen) {
  2116. return _EncodeStr(pPayload, s, MaxLen);
  2117. }
  2118. /*********************************************************************
  2119. *
  2120. * SEGGER_SYSVIEW_EncodeData()
  2121. *
  2122. * Function description
  2123. * Encode a byte buffer in variable-length format.
  2124. *
  2125. * Parameters
  2126. * pPayload - Pointer to where string will be encoded.
  2127. * pSrc - Pointer to data buffer to be encoded.
  2128. * NumBytes - Number of bytes in the buffer to be encoded.
  2129. *
  2130. * Return value
  2131. * Pointer to the byte following the value, i.e. the first free
  2132. * byte in the payload and the next position to store payload
  2133. * content.
  2134. *
  2135. * Additional information
  2136. * The data is encoded as a count byte followed by the contents
  2137. * of the data buffer.
  2138. * Make sure NumBytes + 1 bytes are free for the payload.
  2139. */
  2140. U8* SEGGER_SYSVIEW_EncodeData(U8 *pPayload, const char* pSrc, unsigned NumBytes) {
  2141. return _EncodeData(pPayload, pSrc, NumBytes);
  2142. }
  2143. /*********************************************************************
  2144. *
  2145. * SEGGER_SYSVIEW_EncodeId()
  2146. *
  2147. * Function description
  2148. * Encode a 32-bit Id in shrunken variable-length format.
  2149. *
  2150. * Parameters
  2151. * pPayload - Pointer to where the Id will be encoded.
  2152. * Id - The 32-bit value to be encoded.
  2153. *
  2154. * Return value
  2155. * Pointer to the byte following the value, i.e. the first free
  2156. * byte in the payload and the next position to store payload
  2157. * content.
  2158. *
  2159. * Additional information
  2160. * The parameters to shrink an Id can be configured in
  2161. * SEGGER_SYSVIEW_Conf.h and via SEGGER_SYSVIEW_SetRAMBase().
  2162. * SEGGER_SYSVIEW_ID_BASE: Lowest Id reported by the application.
  2163. * (i.e. 0x20000000 when all Ids are an address in this RAM)
  2164. * SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to
  2165. * save bandwidth. (i.e. 2 when Ids are 4 byte aligned)
  2166. */
  2167. U8* SEGGER_SYSVIEW_EncodeId(U8* pPayload, unsigned Id) {
  2168. Id = SHRINK_ID(Id);
  2169. ENCODE_U32(pPayload, Id);
  2170. return pPayload;
  2171. }
  2172. /*********************************************************************
  2173. *
  2174. * SEGGER_SYSVIEW_ShrinkId()
  2175. *
  2176. * Function description
  2177. * Get the shrunken value of an Id for further processing like in
  2178. * SEGGER_SYSVIEW_NameResource().
  2179. *
  2180. * Parameters
  2181. * Id - The 32-bit value to be shrunken.
  2182. *
  2183. * Return value
  2184. * Shrunken Id.
  2185. *
  2186. * Additional information
  2187. * The parameters to shrink an Id can be configured in
  2188. * SEGGER_SYSVIEW_Conf.h and via SEGGER_SYSVIEW_SetRAMBase().
  2189. * SEGGER_SYSVIEW_ID_BASE: Lowest Id reported by the application.
  2190. * (i.e. 0x20000000 when all Ids are an address in this RAM)
  2191. * SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to
  2192. * save bandwidth. (i.e. 2 when Ids are 4 byte aligned)
  2193. */
  2194. U32 SEGGER_SYSVIEW_ShrinkId(U32 Id) {
  2195. return SHRINK_ID(Id);
  2196. }
  2197. /*********************************************************************
  2198. *
  2199. * SEGGER_SYSVIEW_RegisterModule()
  2200. *
  2201. * Function description
  2202. * Register a middleware module for recording its events.
  2203. *
  2204. * Parameters
  2205. * pModule - The middleware module information.
  2206. *
  2207. * Additional information
  2208. * SEGGER_SYSVIEW_MODULE elements:
  2209. * sDescription - Pointer to a string containing the module name and optionally the module event description.
  2210. * NumEvents - Number of events the module wants to register.
  2211. * EventOffset - Offset to be added to the event Ids. Out parameter, set by this function. Do not modify after calling this function.
  2212. * pfSendModuleDesc - Callback function pointer to send more detailed module description to SystemViewer.
  2213. * pNext - Pointer to next registered module. Out parameter, set by this function. Do not modify after calling this function.
  2214. */
  2215. void SEGGER_SYSVIEW_RegisterModule(SEGGER_SYSVIEW_MODULE* pModule) {
  2216. SEGGER_SYSVIEW_LOCK();
  2217. if (_pFirstModule == 0) {
  2218. //
  2219. // No module registered, yet.
  2220. // Start list with new module.
  2221. // EventOffset is the base offset for modules
  2222. //
  2223. pModule->EventOffset = MODULE_EVENT_OFFSET;
  2224. pModule->pNext = 0;
  2225. _pFirstModule = pModule;
  2226. _NumModules = 1;
  2227. } else {
  2228. //
  2229. // Registreded module(s) present.
  2230. // Prepend new module in list.
  2231. // EventOffset set from number of events and offset of previous module.
  2232. //
  2233. pModule->EventOffset = _pFirstModule->EventOffset + _pFirstModule->NumEvents;
  2234. pModule->pNext = _pFirstModule;
  2235. _pFirstModule = pModule;
  2236. _NumModules++;
  2237. }
  2238. SEGGER_SYSVIEW_SendModule(0);
  2239. if (pModule->pfSendModuleDesc) {
  2240. pModule->pfSendModuleDesc();
  2241. }
  2242. SEGGER_SYSVIEW_UNLOCK();
  2243. }
  2244. /*********************************************************************
  2245. *
  2246. * SEGGER_SYSVIEW_RecordModuleDescription()
  2247. *
  2248. * Function description
  2249. * Sends detailed information of a registered module to the host.
  2250. *
  2251. * Parameters
  2252. * pModule - Pointer to the described module.
  2253. * sDescription - Pointer to a description string.
  2254. */
  2255. void SEGGER_SYSVIEW_RecordModuleDescription(const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription) {
  2256. U8 ModuleId;
  2257. SEGGER_SYSVIEW_MODULE* p;
  2258. p = _pFirstModule;
  2259. ModuleId = 0;
  2260. do {
  2261. if (p == pModule) {
  2262. break;
  2263. }
  2264. ModuleId++;
  2265. p = p->pNext;
  2266. } while (p);
  2267. {
  2268. U8* pPayload;
  2269. U8* pPayloadStart;
  2270. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
  2271. //
  2272. pPayload = pPayloadStart;
  2273. //
  2274. // Send module description
  2275. // Send event offset and number of events
  2276. //
  2277. ENCODE_U32(pPayload, ModuleId);
  2278. ENCODE_U32(pPayload, (pModule->EventOffset));
  2279. pPayload = _EncodeStr(pPayload, sDescription, SEGGER_SYSVIEW_MAX_STRING_LEN);
  2280. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MODULEDESC);
  2281. RECORD_END();
  2282. }
  2283. }
  2284. /*********************************************************************
  2285. *
  2286. * SEGGER_SYSVIEW_SendModule()
  2287. *
  2288. * Function description
  2289. * Sends the information of a registered module to the host.
  2290. *
  2291. * Parameters
  2292. * ModuleId - Id of the requested module.
  2293. */
  2294. void SEGGER_SYSVIEW_SendModule(U8 ModuleId) {
  2295. SEGGER_SYSVIEW_MODULE* pModule;
  2296. U32 n;
  2297. if (_pFirstModule != 0) {
  2298. pModule = _pFirstModule;
  2299. for (n = 0; n < ModuleId; n++) {
  2300. pModule = pModule->pNext;
  2301. if (pModule == 0) {
  2302. break;
  2303. }
  2304. }
  2305. if (pModule != 0) {
  2306. U8* pPayload;
  2307. U8* pPayloadStart;
  2308. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
  2309. //
  2310. pPayload = pPayloadStart;
  2311. //
  2312. // Send module description
  2313. // Send event offset and number of events
  2314. //
  2315. ENCODE_U32(pPayload, ModuleId);
  2316. ENCODE_U32(pPayload, (pModule->EventOffset));
  2317. pPayload = _EncodeStr(pPayload, pModule->sModule, SEGGER_SYSVIEW_MAX_STRING_LEN);
  2318. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MODULEDESC);
  2319. RECORD_END();
  2320. }
  2321. }
  2322. }
  2323. /*********************************************************************
  2324. *
  2325. * SEGGER_SYSVIEW_SendModuleDescription()
  2326. *
  2327. * Function description
  2328. * Triggers a send of the registered module descriptions.
  2329. *
  2330. */
  2331. void SEGGER_SYSVIEW_SendModuleDescription(void) {
  2332. SEGGER_SYSVIEW_MODULE* pModule;
  2333. if (_pFirstModule != 0) {
  2334. pModule = _pFirstModule;
  2335. do {
  2336. if (pModule->pfSendModuleDesc) {
  2337. pModule->pfSendModuleDesc();
  2338. }
  2339. pModule = pModule->pNext;
  2340. } while (pModule);
  2341. }
  2342. }
  2343. /*********************************************************************
  2344. *
  2345. * SEGGER_SYSVIEW_SendNumModules()
  2346. *
  2347. * Function description
  2348. * Send the number of registered modules to the host.
  2349. */
  2350. void SEGGER_SYSVIEW_SendNumModules(void) {
  2351. U8* pPayload;
  2352. U8* pPayloadStart;
  2353. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2*SEGGER_SYSVIEW_QUANTA_U32);
  2354. pPayload = pPayloadStart;
  2355. ENCODE_U32(pPayload, _NumModules);
  2356. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_NUMMODULES);
  2357. RECORD_END();
  2358. }
  2359. #ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
  2360. /*********************************************************************
  2361. *
  2362. * SEGGER_SYSVIEW_PrintfHostEx()
  2363. *
  2364. * Function description
  2365. * Print a string which is formatted on the host by SystemViewer
  2366. * with Additional information.
  2367. *
  2368. * Parameters
  2369. * s - String to be formatted.
  2370. * Options - Options for the string. i.e. Log level.
  2371. *
  2372. * Additional information
  2373. * All format arguments are treated as 32-bit scalar values.
  2374. */
  2375. void SEGGER_SYSVIEW_PrintfHostEx(const char* s, U32 Options, ...) {
  2376. va_list ParamList;
  2377. va_start(ParamList, Options);
  2378. _VPrintHost(s, Options, &ParamList);
  2379. va_end(ParamList);
  2380. }
  2381. /*********************************************************************
  2382. *
  2383. * SEGGER_SYSVIEW_PrintfHost()
  2384. *
  2385. * Function description
  2386. * Print a string which is formatted on the host by SystemViewer.
  2387. *
  2388. * Parameters
  2389. * s - String to be formatted.
  2390. *
  2391. * Additional information
  2392. * All format arguments are treated as 32-bit scalar values.
  2393. */
  2394. void SEGGER_SYSVIEW_PrintfHost(const char* s, ...) {
  2395. va_list ParamList;
  2396. va_start(ParamList, s);
  2397. _VPrintHost(s, SEGGER_SYSVIEW_LOG, &ParamList);
  2398. va_end(ParamList);
  2399. }
  2400. /*********************************************************************
  2401. *
  2402. * SEGGER_SYSVIEW_WarnfHost()
  2403. *
  2404. * Function description
  2405. * Print a warnin string which is formatted on the host by
  2406. * SystemViewer.
  2407. *
  2408. * Parameters
  2409. * s - String to be formatted.
  2410. *
  2411. * Additional information
  2412. * All format arguments are treated as 32-bit scalar values.
  2413. */
  2414. void SEGGER_SYSVIEW_WarnfHost(const char* s, ...) {
  2415. va_list ParamList;
  2416. va_start(ParamList, s);
  2417. _VPrintHost(s, SEGGER_SYSVIEW_WARNING, &ParamList);
  2418. va_end(ParamList);
  2419. }
  2420. /*********************************************************************
  2421. *
  2422. * SEGGER_SYSVIEW_ErrorfHost()
  2423. *
  2424. * Function description
  2425. * Print an error string which is formatted on the host by
  2426. * SystemViewer.
  2427. *
  2428. * Parameters
  2429. * s - String to be formatted.
  2430. *
  2431. * Additional information
  2432. * All format arguments are treated as 32-bit scalar values.
  2433. */
  2434. void SEGGER_SYSVIEW_ErrorfHost(const char* s, ...) {
  2435. va_list ParamList;
  2436. va_start(ParamList, s);
  2437. _VPrintHost(s, SEGGER_SYSVIEW_ERROR, &ParamList);
  2438. va_end(ParamList);
  2439. }
  2440. /*********************************************************************
  2441. *
  2442. * SEGGER_SYSVIEW_PrintfTargetEx()
  2443. *
  2444. * Function description
  2445. * Print a string which is formatted on the target before sent to
  2446. * the host with Additional information.
  2447. *
  2448. * Parameters
  2449. * s - String to be formatted.
  2450. * Options - Options for the string. i.e. Log level.
  2451. */
  2452. void SEGGER_SYSVIEW_PrintfTargetEx(const char* s, U32 Options, ...) {
  2453. va_list ParamList;
  2454. va_start(ParamList, Options);
  2455. _VPrintTarget(s, Options, &ParamList);
  2456. va_end(ParamList);
  2457. }
  2458. /*********************************************************************
  2459. *
  2460. * SEGGER_SYSVIEW_PrintfTarget()
  2461. *
  2462. * Function description
  2463. * Print a string which is formatted on the target before sent to
  2464. * the host.
  2465. *
  2466. * Parameters
  2467. * s - String to be formatted.
  2468. */
  2469. void SEGGER_SYSVIEW_PrintfTarget(const char* s, ...) {
  2470. va_list ParamList;
  2471. va_start(ParamList, s);
  2472. _VPrintTarget(s, SEGGER_SYSVIEW_LOG, &ParamList);
  2473. va_end(ParamList);
  2474. }
  2475. /*********************************************************************
  2476. *
  2477. * SEGGER_SYSVIEW_WarnfTarget()
  2478. *
  2479. * Function description
  2480. * Print a warning string which is formatted on the target before
  2481. * sent to the host.
  2482. *
  2483. * Parameters
  2484. * s - String to be formatted.
  2485. */
  2486. void SEGGER_SYSVIEW_WarnfTarget(const char* s, ...) {
  2487. va_list ParamList;
  2488. va_start(ParamList, s);
  2489. _VPrintTarget(s, SEGGER_SYSVIEW_WARNING, &ParamList);
  2490. va_end(ParamList);
  2491. }
  2492. /*********************************************************************
  2493. *
  2494. * SEGGER_SYSVIEW_ErrorfTarget()
  2495. *
  2496. * Function description
  2497. * Print an error string which is formatted on the target before
  2498. * sent to the host.
  2499. *
  2500. * Parameters
  2501. * s - String to be formatted.
  2502. */
  2503. void SEGGER_SYSVIEW_ErrorfTarget(const char* s, ...) {
  2504. va_list ParamList;
  2505. va_start(ParamList, s);
  2506. _VPrintTarget(s, SEGGER_SYSVIEW_ERROR, &ParamList);
  2507. va_end(ParamList);
  2508. }
  2509. #endif // SEGGER_SYSVIEW_EXCLUDE_PRINTF
  2510. /*********************************************************************
  2511. *
  2512. * SEGGER_SYSVIEW_Print()
  2513. *
  2514. * Function description
  2515. * Print a string to the host.
  2516. *
  2517. * Parameters
  2518. * s - String to sent.
  2519. */
  2520. void SEGGER_SYSVIEW_Print(const char* s) {
  2521. U8* pPayload;
  2522. U8* pPayloadStart;
  2523. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
  2524. //
  2525. pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
  2526. ENCODE_U32(pPayload, SEGGER_SYSVIEW_LOG);
  2527. ENCODE_U32(pPayload, 0);
  2528. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
  2529. RECORD_END();
  2530. }
  2531. /*********************************************************************
  2532. *
  2533. * SEGGER_SYSVIEW_Warn()
  2534. *
  2535. * Function description
  2536. * Print a warning string to the host.
  2537. *
  2538. * Parameters
  2539. * s - String to sent.
  2540. */
  2541. void SEGGER_SYSVIEW_Warn(const char* s) {
  2542. U8* pPayload;
  2543. U8* pPayloadStart;
  2544. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
  2545. //
  2546. pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
  2547. ENCODE_U32(pPayload, SEGGER_SYSVIEW_WARNING);
  2548. ENCODE_U32(pPayload, 0);
  2549. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
  2550. RECORD_END();
  2551. }
  2552. /*********************************************************************
  2553. *
  2554. * SEGGER_SYSVIEW_Error()
  2555. *
  2556. * Function description
  2557. * Print an error string to the host.
  2558. *
  2559. * Parameters
  2560. * s - String to sent.
  2561. */
  2562. void SEGGER_SYSVIEW_Error(const char* s) {
  2563. U8* pPayload;
  2564. U8* pPayloadStart;
  2565. RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
  2566. //
  2567. pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
  2568. ENCODE_U32(pPayload, SEGGER_SYSVIEW_ERROR);
  2569. ENCODE_U32(pPayload, 0);
  2570. _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
  2571. RECORD_END();
  2572. }
  2573. /*********************************************************************
  2574. *
  2575. * SEGGER_SYSVIEW_EnableEvents()
  2576. *
  2577. * Function description
  2578. * Enable standard SystemView events to be generated.
  2579. *
  2580. * Parameters
  2581. * EnableMask - Events to be enabled.
  2582. */
  2583. void SEGGER_SYSVIEW_EnableEvents(U32 EnableMask) {
  2584. _SYSVIEW_Globals.DisabledEvents &= ~EnableMask;
  2585. }
  2586. /*********************************************************************
  2587. *
  2588. * SEGGER_SYSVIEW_DisableEvents()
  2589. *
  2590. * Function description
  2591. * Disable standard SystemView events to not be generated.
  2592. *
  2593. * Parameters
  2594. * DisableMask - Events to be disabled.
  2595. */
  2596. void SEGGER_SYSVIEW_DisableEvents(U32 DisableMask) {
  2597. _SYSVIEW_Globals.DisabledEvents |= DisableMask;
  2598. }
  2599. /*************************** End of file ****************************/