SEGGER_SYSVIEW.c 89 KB

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