| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837 |
- /*********************************************************************
- * SEGGER Microcontroller GmbH & Co. KG *
- * The Embedded Experts *
- **********************************************************************
- * *
- * (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG *
- * *
- * www.segger.com Support: support@segger.com *
- * *
- **********************************************************************
- * *
- * SEGGER SystemView * Real-time application analysis *
- * *
- **********************************************************************
- * *
- * All rights reserved. *
- * *
- * SEGGER strongly recommends to not make any changes *
- * to or modify the source code of this software in order to stay *
- * compatible with the RTT protocol and J-Link. *
- * *
- * Redistribution and use in source and binary forms, with or *
- * without modification, are permitted provided that the following *
- * conditions are met: *
- * *
- * o Redistributions of source code must retain the above copyright *
- * notice, this list of conditions and the following disclaimer. *
- * *
- * o Redistributions in binary form must reproduce the above *
- * copyright notice, this list of conditions and the following *
- * disclaimer in the documentation and/or other materials provided *
- * with the distribution. *
- * *
- * o Neither the name of SEGGER Microcontroller GmbH & Co. KG *
- * nor the names of its contributors may be used to endorse or *
- * promote products derived from this software without specific *
- * prior written permission. *
- * *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF *
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
- * DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR *
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT *
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; *
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH *
- * DAMAGE. *
- * *
- **********************************************************************
- * *
- * SystemView version: V2.52a *
- * *
- **********************************************************************
- -------------------------- END-OF-HEADER -----------------------------
- File : SEGGER_SYSVIEW.c
- Purpose : System visualization API implementation.
- Revision: $Rev: 6414 $
- Additional information:
- Packet format:
- Packets with IDs 0..23 are standard packets with known structure.
- For efficiency, they do *NOT* contain a length field.
- <ID><Data><TimeStampDelta>
- Packets with IDs 24..31 are standard packets with extendible
- structure and contain a length field.
- <ID><Lenght><Data><TimeStampDelta>
- Packets with IDs >= 32 always contain a length field.
- <ID><Length><Data><TimeStampDelta>
- Packet IDs:
- 0.. 31 : Standard packets, known by SystemViewer.
- 32..1023 : OS-definable packets, described in a SystemView description file.
- 1024..2047 : User-definable packets, described in a SystemView description file.
- 2048..32767: Undefined.
- Data encoding:
- Basic types (int, short, char, ...):
- Basic types are encoded little endian with most-significant bit variant
- encoding.
- Each encoded byte contains 7 data bits [6:0] and the MSB continuation bit.
- The continuation bit indicates whether the next byte belongs to the data
- (bit set) or this is the last byte (bit clear).
- The most significant bits of data are encoded first, proceeding to the
- least significant bits in the final byte (little endian).
- Example encoding:
- Data: 0x1F4 (500)
- Encoded: 0xF4 (First 7 data bits 74 | Continuation bit)
- 0x03 (Second 7 data bits 03, no continuation)
- Data: 0xFFFFFFFF
- Encoded: 0xFF 0xFF 0xFF 0xFF 0x0F
- Data: 0xA2 (162), 0x03 (3), 0x7000
- Encoded: 0xA2 0x01 0x03 0x80 0xE0 0x01
- Byte arrays and strings:
- Byte arrays and strings are encoded as <NumBytes> followed by the raw data.
- NumBytes is encoded as a basic type with a theoretical maximum of 4G.
- Example encoding:
- Data: "Hello World\0" (0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64 0x00)
- Encoded: 0x0B 0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57 0x6F 0x72 0x6C 0x64
- Examples packets:
- 01 F4 03 80 80 10 // Overflow packet. Data is a single U32.
- This packet means: 500 packets lost, Timestamp is 0x40000
- 02 0F 50 // ISR(15) Enter. Timestamp 80 (0x50)
- 03 20 // ISR Exit. Timestamp 32 (0x20) (Shortest possible packet.)
- Sample code for user defined Packets:
- #define MY_ID 0x400 // Any value between 0x400 and 0x7FF
- void SendMyPacket(unsigned Para0, unsigned Para1, const char* s) {
- U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + MAX_STR_LEN + 1];
- U8* pPayload;
- //
- pPayload = SEGGER_SYSVIEW_PPREPARE_PACKET(aPacket); // Prepare the packet for SystemView
- pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet
- pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet
- pPayload = SEGGER_SYSVIEW_EncodeString(pPayload, s, MAX_STR_LEN); // Add the string to the packet
- //
- SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, MY_ID); // Send the packet with EventId = MY_ID
- }
- #define MY_ID_1 0x401
- void SendOnePara(unsigned Para0) {
- SEGGER_SYSVIEW_RecordU32(MY_ID_1, Para0);
- }
- */
- /*********************************************************************
- *
- * #include section
- *
- **********************************************************************
- */
- #include "SEGGER_SYSVIEW_Int.h"
- #include "SEGGER_RTT.h"
- #include <string.h>
- #include <stdlib.h>
- #include <stdarg.h>
- /*********************************************************************
- *
- * Defines, fixed
- *
- **********************************************************************
- */
- #if SEGGER_SYSVIEW_ID_SHIFT
- #define SHRINK_ID(Id) (((Id) - _SYSVIEW_Globals.RAMBaseAddress) >> SEGGER_SYSVIEW_ID_SHIFT)
- #else
- #define SHRINK_ID(Id) ((Id) - _SYSVIEW_Globals.RAMBaseAddress)
- #endif
- #if SEGGER_SYSVIEW_RTT_CHANNEL > 0
- #define CHANNEL_ID_UP SEGGER_SYSVIEW_RTT_CHANNEL
- #define CHANNEL_ID_DOWN SEGGER_SYSVIEW_RTT_CHANNEL
- #else
- #define CHANNEL_ID_UP _SYSVIEW_Globals.UpChannel
- #define CHANNEL_ID_DOWN _SYSVIEW_Globals.DownChannel
- #endif
- /*********************************************************************
- *
- * Defines, configurable
- *
- **********************************************************************
- */
- // Timestamps may be less than full 32-bits, in which case we need to zero
- // the unused bits to properly handle overflows.
- // Note that this is a quite common scenario, as a 32-bit time such as
- // SysTick might be scaled down to reduce bandwith
- // or a 16-bit hardware time might be used.
- #if SEGGER_SYSVIEW_TIMESTAMP_BITS < 32 // Eliminate unused bits in case hardware timestamps are less than 32 bits
- #define MAKE_DELTA_32BIT(Delta) Delta <<= 32 - SEGGER_SYSVIEW_TIMESTAMP_BITS; \
- Delta >>= 32 - SEGGER_SYSVIEW_TIMESTAMP_BITS;
- #else
- #define MAKE_DELTA_32BIT(Delta)
- #endif
- /*********************************************************************
- *
- * Defines, fixed
- *
- **********************************************************************
- */
- #define ENABLE_STATE_OFF 0
- #define ENABLE_STATE_ON 1
- #define ENABLE_STATE_DROPPING 2
- #define FORMAT_FLAG_LEFT_JUSTIFY (1u << 0)
- #define FORMAT_FLAG_PAD_ZERO (1u << 1)
- #define FORMAT_FLAG_PRINT_SIGN (1u << 2)
- #define FORMAT_FLAG_ALTERNATE (1u << 3)
- #define MODULE_EVENT_OFFSET (512)
- /*********************************************************************
- *
- * Types, local
- *
- **********************************************************************
- */
- typedef struct {
- U8* pBuffer;
- U8* pPayload;
- U8* pPayloadStart;
- U32 Options;
- unsigned Cnt;
- } SEGGER_SYSVIEW_PRINTF_DESC;
- typedef struct {
- U8 EnableState; // 0: Disabled, 1: Enabled, (2: Dropping)
- U8 UpChannel;
- U8 RecursionCnt;
- U32 SysFreq;
- U32 CPUFreq;
- U32 LastTxTimeStamp;
- U32 RAMBaseAddress;
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- U32 PacketCount;
- #else
- U32 DropCount;
- U8 DownChannel;
- #endif
- U32 DisabledEvents;
- const SEGGER_SYSVIEW_OS_API* pOSAPI;
- SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC* pfSendSysDesc;
- } SEGGER_SYSVIEW_GLOBALS;
- /*********************************************************************
- *
- * Function prototypes, required
- *
- **********************************************************************
- */
- static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned int EventId);
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- static const U8 _abSync[10] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- #ifdef SEGGER_SYSVIEW_SECTION
- #if (defined __GNUC__)
- __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- __attribute__ ((section (SEGGER_SYSVIEW_SECTION))) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
- #endif
- #elif (defined __ICCARM__) || (defined __ICCRX__)
- #pragma location=SEGGER_SYSVIEW_SECTION
- static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
- #pragma location=SEGGER_SYSVIEW_SECTION
- static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
- #elif (defined __CC_ARM)
- __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- __attribute__ ((section (SEGGER_SYSVIEW_SECTION), zero_init)) static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
- #endif
- #else
- static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
- #endif
- #endif
- #else
- static char _UpBuffer [SEGGER_SYSVIEW_RTT_BUFFER_SIZE];
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- static char _DownBuffer[8]; // Small, fixed-size buffer, for back-channel comms
- #endif
- #endif
- static SEGGER_SYSVIEW_GLOBALS _SYSVIEW_Globals;
- static SEGGER_SYSVIEW_MODULE* _pFirstModule;
- static U8 _NumModules;
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- #define ENCODE_U32(pDest, Value) { \
- U8* pSysviewPointer; \
- U32 SysViewData; \
- pSysviewPointer = pDest; \
- SysViewData = Value; \
- while(SysViewData > 0x7F) { \
- *pSysviewPointer++ = (U8)(SysViewData | 0x80); \
- SysViewData >>= 7; \
- }; \
- *pSysviewPointer++ = (U8)SysViewData; \
- pDest = pSysviewPointer; \
- };
- #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
- static U8 _aPacket[SEGGER_SYSVIEW_MAX_PACKET_SIZE];
- #define RECORD_START(PacketSize) SEGGER_SYSVIEW_LOCK(); \
- pPayloadStart = _PreparePacket(_aPacket);
- #define RECORD_END() SEGGER_SYSVIEW_UNLOCK()
- #else
- #define RECORD_START(PacketSize) U8 aPacket[(PacketSize)]; \
- pPayloadStart = _PreparePacket(aPacket); \
- #define RECORD_END()
- #endif
- /*********************************************************************
- *
- * _EncodeData()
- *
- * Function description
- * Encode a byte buffer in variable-length format.
- *
- * Parameters
- * pPayload - Pointer to where string will be encoded.
- * pSrc - Pointer to data buffer to be encoded.
- * NumBytes - Number of bytes in the buffer to be encoded.
- *
- * Return value
- * Pointer to the byte following the value, i.e. the first free
- * byte in the payload and the next position to store payload
- * content.
- *
- * Additional information
- * The data is encoded as a count byte followed by the contents
- * of the data buffer.
- * Make sure NumBytes + 1 bytes are free for the payload.
- */
- static U8* _EncodeData(U8* pPayload, const char* pSrc, unsigned int NumBytes) {
- unsigned int n;
- //
- n = 0;
- *pPayload++ = NumBytes;
- while (n < NumBytes) {
- *pPayload++ = *pSrc++;
- n++;
- }
- return pPayload;
- }
- /*********************************************************************
- *
- * _EncodeStr()
- *
- * Function description
- * Encode a string in variable-length format.
- *
- * Parameters
- * pPayload - Pointer to where string will be encoded.
- * pText - String to encode.
- * Limit - Maximum number of characters to encode from string.
- *
- * Return value
- * Pointer to the byte following the value, i.e. the first free
- * byte in the payload and the next position to store payload
- * content.
- *
- * Additional information
- * The string is encoded as a count byte followed by the contents
- * of the string.
- * No more than 1 + Limit bytes will be encoded to the payload.
- */
- static U8 *_EncodeStr(U8 *pPayload, const char *pText, unsigned int Limit) {
- unsigned int n;
- unsigned int Len;
- //
- // Compute string len
- //
- Len = 0;
- while(*(pText + Len) != 0) {
- Len++;
- }
- if (Len > Limit) {
- Len = Limit;
- }
- //
- // Write Len
- //
- if (Len < 255) {
- *pPayload++ = Len;
- } else {
- *pPayload++ = 255;
- *pPayload++ = (Len & 255);
- *pPayload++ = ((Len >> 8) & 255);
- }
- //
- // copy string
- //
- n = 0;
- while (n < Len) {
- *pPayload++ = *pText++;
- n++;
- }
- return pPayload;
- }
- /*********************************************************************
- *
- * _PreparePacket()
- *
- * Function description
- * Prepare a SystemView event packet header.
- *
- * Parameters
- * pPacket - Pointer to start of packet to initialize.
- *
- * Return value
- * Pointer to first byte of packet payload.
- *
- * Additional information
- * The payload length and evnetId are not initialized.
- * PreparePacket only reserves space for them and they are
- * computed and filled in by the sending function.
- */
- static U8* _PreparePacket(U8* pPacket) {
- return pPacket + 4;
- }
- /*********************************************************************
- *
- * _HandleIncomingPacket()
- *
- * Function description
- * Read an incoming command from the down channel and process it.
- *
- * Additional information
- * This function is called each time after sending a packet.
- * Processing incoming packets is done asynchronous. SystemView might
- * already have sent event packets after the host has sent a command.
- */
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- static void _HandleIncomingPacket(void) {
- U8 Cmd;
- int Status;
- //
- Status = SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
- if (Status > 0) {
- switch (Cmd) {
- case SEGGER_SYSVIEW_COMMAND_ID_START:
- SEGGER_SYSVIEW_Start();
- break;
- case SEGGER_SYSVIEW_COMMAND_ID_STOP:
- SEGGER_SYSVIEW_Stop();
- break;
- case SEGGER_SYSVIEW_COMMAND_ID_GET_SYSTIME:
- SEGGER_SYSVIEW_RecordSystime();
- break;
- case SEGGER_SYSVIEW_COMMAND_ID_GET_TASKLIST:
- SEGGER_SYSVIEW_SendTaskList();
- break;
- case SEGGER_SYSVIEW_COMMAND_ID_GET_SYSDESC:
- SEGGER_SYSVIEW_GetSysDesc();
- break;
- case SEGGER_SYSVIEW_COMMAND_ID_GET_NUMMODULES:
- SEGGER_SYSVIEW_SendNumModules();
- break;
- case SEGGER_SYSVIEW_COMMAND_ID_GET_MODULEDESC:
- SEGGER_SYSVIEW_SendModuleDescription();
- break;
- case SEGGER_SYSVIEW_COMMAND_ID_GET_MODULE:
- Status = SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
- if (Status > 0) {
- SEGGER_SYSVIEW_SendModule(Cmd);
- }
- break;
- default:
- if (Cmd >= 128) { // Unknown extended command. Dummy read its parameter.
- SEGGER_RTT_ReadNoLock(CHANNEL_ID_DOWN, &Cmd, 1);
- }
- break;
- }
- }
- }
- #endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- /*********************************************************************
- *
- * _TrySendOverflowPacket()
- *
- * Function description
- * Try to transmit an SystemView Overflow packet containing the
- * number of dropped packets.
- *
- * Additional information
- * Format as follows:
- * 01 <DropCnt><TimeStamp> Max. packet len is 1 + 5 + 5 = 11
- *
- * Example packets sent
- * 01 20 40
- *
- * Return value
- * !=0: Success, Message sent (stored in RTT-Buffer)
- * ==0: Buffer full, Message *NOT* stored
- *
- */
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- static int _TrySendOverflowPacket(void) {
- U32 TimeStamp;
- I32 Delta;
- int Status;
- U8 aPacket[11];
- U8* pPayload;
- aPacket[0] = SYSVIEW_EVTID_OVERFLOW; // 1
- pPayload = &aPacket[1];
- ENCODE_U32(pPayload, _SYSVIEW_Globals.DropCount);
- //
- // Compute time stamp delta and append it to packet.
- //
- TimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP();
- Delta = TimeStamp - _SYSVIEW_Globals.LastTxTimeStamp;
- MAKE_DELTA_32BIT(Delta);
- ENCODE_U32(pPayload, Delta);
- //
- // Try to store packet in RTT buffer and update time stamp when this was successful
- //
- Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, aPacket, pPayload - aPacket);
- if (Status) {
- _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
- _SYSVIEW_Globals.EnableState--; // EnableState has been 2, will be 1. Always.
- } else {
- _SYSVIEW_Globals.DropCount++;
- }
- //
- return Status;
- }
- #endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- /*********************************************************************
- *
- * _SendSyncInfo()
- *
- * Function description
- * Send SystemView sync packet and system information in
- * post mortem mode.
- *
- * Additional information
- * Sync is 10 * 0x00 without timestamp
- */
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- static void _SendSyncInfo(void) {
- //
- // Add sync packet ( 10 * 0x00)
- // Send system description
- // Send system time
- // Send task list
- // Send module description
- // Send module information
- //
- SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, _abSync, 10);
- SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START);
- {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
- ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
- ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
- ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
- RECORD_END();
- }
- if (_SYSVIEW_Globals.pfSendSysDesc) {
- _SYSVIEW_Globals.pfSendSysDesc();
- }
- SEGGER_SYSVIEW_RecordSystime();
- SEGGER_SYSVIEW_SendTaskList();
- if (_NumModules > 0) {
- SEGGER_SYSVIEW_SendNumModules();
- for (int n = 0; n < _NumModules; n++) {
- SEGGER_SYSVIEW_SendModule(n);
- }
- SEGGER_SYSVIEW_SendModuleDescription();
- }
- }
- #endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- /*********************************************************************
- *
- * _SendPacket()
- *
- * Function description
- * Send a SystemView packet over RTT. RTT channel and mode are
- * configured by macros when the SystemView component is initialized.
- * This function takes care of maintaining the packet drop count
- * and sending overflow packets when necessary.
- * The packet must be passed without Id and Length because this
- * function prepends it to the packet before transmission.
- *
- * Parameters
- * pStartPacket - Pointer to start of packet payload.
- * There must be at least 4 bytes free to prepend Id and Length.
- * pEndPacket - Pointer to end of packet payload.
- * EventId - Id of the event to send.
- *
- */
- static void _SendPacket(U8* pStartPacket, U8* pEndPacket, unsigned int EventId) {
- unsigned int NumBytes;
- U32 TimeStamp;
- U32 Delta;
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE != 1)
- int Status;
- #endif
- #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0)
- SEGGER_SYSVIEW_LOCK();
- #endif
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- if (_SYSVIEW_Globals.EnableState == 0) {
- goto SendDone;
- }
- #else
- if (_SYSVIEW_Globals.EnableState == 1) { // Enabled, no dropped packets remaining
- goto Send;
- }
- if (_SYSVIEW_Globals.EnableState == 0) {
- goto SendDone;
- }
- //
- // Handle buffer full situations:
- // Have packets been dropped before because buffer was full?
- // In this case try to send and overflow packet.
- //
- if (_SYSVIEW_Globals.EnableState == 2) {
- _TrySendOverflowPacket();
- if (_SYSVIEW_Globals.EnableState != 1) {
- goto SendDone;
- }
- }
- Send:
- #endif
- //
- // Check if event is disabled from being recorded.
- //
- if (EventId < 32) {
- if (_SYSVIEW_Globals.DisabledEvents & ((U32)1u << EventId)) {
- goto SendDone;
- }
- }
- //
- // Prepare actual packet.
- // If it is a known packet, prepend eventId only,
- // otherwise prepend packet length and eventId.
- //
- if (EventId < 24) {
- *--pStartPacket = EventId;
- } else {
- NumBytes = pEndPacket - pStartPacket;
- if (NumBytes > 127) {
- *--pStartPacket = (NumBytes >> 7);
- *--pStartPacket = NumBytes | 0x80;
- } else {
- *--pStartPacket = NumBytes;
- }
- if (EventId > 127) {
- *--pStartPacket = (EventId >> 7);
- *--pStartPacket = EventId | 0x80;
- } else {
- *--pStartPacket = EventId;
- }
- }
- //
- // Compute time stamp delta and append it to packet.
- //
- TimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP();
- Delta = TimeStamp - _SYSVIEW_Globals.LastTxTimeStamp;
- MAKE_DELTA_32BIT(Delta);
- ENCODE_U32(pEndPacket, Delta);
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- //
- // Store packet in RTT buffer by overwriting old data and update time stamp
- //
- SEGGER_RTT_WriteWithOverwriteNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket);
- _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
- #else
- //
- // Try to store packet in RTT buffer and update time stamp when this was successful
- //
- Status = SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, pStartPacket, pEndPacket - pStartPacket);
- if (Status) {
- _SYSVIEW_Globals.LastTxTimeStamp = TimeStamp;
- } else {
- _SYSVIEW_Globals.EnableState++; // EnableState has been 1, will be 2. Always.
- }
- #endif
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- //
- // Add sync and system information periodically if we are in post mortem mode
- //
- if (_SYSVIEW_Globals.RecursionCnt == 0) { // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that.
- _SYSVIEW_Globals.RecursionCnt = 1;
- if (_SYSVIEW_Globals.PacketCount++ & (1 << SEGGER_SYSVIEW_SYNC_PERIOD_SHIFT)) {
- _SendSyncInfo();
- _SYSVIEW_Globals.PacketCount = 0;
- }
- _SYSVIEW_Globals.RecursionCnt = 0;
- }
- SendDone:
- ; // Avoid "label at end of compound statement" error when using static buffer
- #else
- SendDone:
- //
- // Check if host is sending data which needs to be processed.
- // Note that since this code is called for every packet, it is very time critical, so we do
- // only what is really needed here, which is checking if there is any data
- //
- if (SEGGER_RTT_HASDATA(CHANNEL_ID_DOWN)) {
- if (_SYSVIEW_Globals.RecursionCnt == 0) { // Avoid uncontrolled nesting. This way, this routine can call itself once, but no more often than that.
- _SYSVIEW_Globals.RecursionCnt = 1;
- _HandleIncomingPacket();
- _SYSVIEW_Globals.RecursionCnt = 0;
- }
- }
- #endif
- //
- #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0)
- SEGGER_SYSVIEW_UNLOCK(); // We are done. Unlock and return
- #endif
- }
- #ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
- /*********************************************************************
- *
- * _VPrintHost()
- *
- * Function description
- * Send a format string and its parameters to the host.
- *
- * Parameters
- * s Pointer to format string.
- * Options Options to be sent to the host.
- * pParamList Pointer to the list of arguments for the format string.
- */
- static int _VPrintHost(const char* s, U32 Options, va_list* pParamList) {
- U32 aParas[SEGGER_SYSVIEW_MAX_ARGUMENTS];
- U32* pParas;
- U32 NumArguments;
- const char* p;
- char c;
- U8* pPayload;
- U8* pPayloadStart;
- #if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
- U8 HasNonScalar;
-
- HasNonScalar = 0;
- #endif
- //
- // Count number of arguments by counting '%' characters in string.
- // If enabled, check for non-scalar modifier flags to format string on the target.
- //
- p = s;
- NumArguments = 0;
- for (;;) {
- c = *p++;
- if (c == 0) {
- break;
- }
- if (c == '%') {
- c = *p;
- #if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT == 0
- aParas[NumArguments++] = va_arg(*pParamList, int);
- if (NumArguments == SEGGER_SYSVIEW_MAX_ARGUMENTS) {
- break;
- }
- #else
- if (c == 's') {
- HasNonScalar = 1;
- break;
- } else {
- aParas[NumArguments++] = va_arg(*pParamList, int);
- if (NumArguments == SEGGER_SYSVIEW_MAX_ARGUMENTS) {
- break;
- }
- }
- #endif
- }
- }
- #if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
- if (HasNonScalar) {
- return -1;
- }
- #endif
- //
- // Send string and parameters to host
- //
- {
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_ARGUMENTS * SEGGER_SYSVIEW_QUANTA_U32);
- pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
- ENCODE_U32(pPayload, Options);
- ENCODE_U32(pPayload, NumArguments);
- pParas = aParas;
- while (NumArguments--) {
- ENCODE_U32(pPayload, (*pParas));
- pParas++;
- }
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
- RECORD_END();
- }
- return 0;
- }
- /*********************************************************************
- *
- * _StoreChar()
- *
- * Function description
- * Stores a character in the printf-buffer and sends the buffer when
- * it is filled.
- *
- * Parameters
- * p Pointer to the buffer description.
- * c Character to be printed.
- */
- static void _StoreChar(SEGGER_SYSVIEW_PRINTF_DESC * p, char c) {
- unsigned int Cnt;
- U8* pPayload;
- U32 Options;
- Cnt = p->Cnt;
- if ((Cnt + 1u) <= SEGGER_SYSVIEW_MAX_STRING_LEN) {
- *(p->pPayload++) = c;
- p->Cnt = Cnt + 1u;
- }
- //
- // Write part of string, when the buffer is full
- //
- if (p->Cnt == SEGGER_SYSVIEW_MAX_STRING_LEN) {
- *(p->pPayloadStart) = p->Cnt;
- pPayload = p->pPayload;
- Options = p->Options;
- ENCODE_U32(pPayload, Options);
- ENCODE_U32(pPayload, 0);
- _SendPacket(p->pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
- p->pPayloadStart = _PreparePacket(p->pBuffer);
- p->pPayload = p->pPayloadStart + 1u;
- p->Cnt = 0u;
- }
- }
- /*********************************************************************
- *
- * _PrintUnsigned()
- *
- * Function description
- * Print an unsigned integer with the given formatting into the
- * formatted string.
- *
- * Parameters
- * pBufferDesc Pointer to the buffer description.
- * v Value to be printed.
- * Base Base of the value.
- * NumDigits Number of digits to be printed.
- * FieldWidth Width of the printed field.
- * FormatFlags Flags for formatting the value.
- */
- static void _PrintUnsigned(SEGGER_SYSVIEW_PRINTF_DESC * pBufferDesc, unsigned int v, unsigned int Base, unsigned int NumDigits, unsigned int FieldWidth, unsigned int FormatFlags) {
- static const char _aV2C[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
- unsigned int Div;
- unsigned int Digit;
- unsigned int Number;
- unsigned int Width;
- char c;
- Number = v;
- Digit = 1u;
- //
- // Get actual field width
- //
- Width = 1u;
- while (Number >= Base) {
- Number = (Number / Base);
- Width++;
- }
- if (NumDigits > Width) {
- Width = NumDigits;
- }
- //
- // Print leading chars if necessary
- //
- if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) {
- if (FieldWidth != 0u) {
- if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && (NumDigits == 0u)) {
- c = '0';
- } else {
- c = ' ';
- }
- while ((FieldWidth != 0u) && (Width < FieldWidth)) {
- FieldWidth--;
- _StoreChar(pBufferDesc, c);
- }
- }
- }
- //
- // Compute Digit.
- // Loop until Digit has the value of the highest digit required.
- // Example: If the output is 345 (Base 10), loop 2 times until Digit is 100.
- //
- while (1) {
- 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)
- NumDigits--;
- } else {
- Div = v / Digit;
- if (Div < Base) { // Is our divider big enough to extract the highest digit from value? => Done
- break;
- }
- }
- Digit *= Base;
- }
- //
- // Output digits
- //
- do {
- Div = v / Digit;
- v -= Div * Digit;
- _StoreChar(pBufferDesc, _aV2C[Div]);
- Digit /= Base;
- } while (Digit);
- //
- // Print trailing spaces if necessary
- //
- if ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == FORMAT_FLAG_LEFT_JUSTIFY) {
- if (FieldWidth != 0u) {
- while ((FieldWidth != 0u) && (Width < FieldWidth)) {
- FieldWidth--;
- _StoreChar(pBufferDesc, ' ');
- }
- }
- }
- }
- /*********************************************************************
- *
- * _PrintInt()
- *
- * Function description
- * Print a signed integer with the given formatting into the
- * formatted string.
- *
- * Parameters
- * pBufferDesc Pointer to the buffer description.
- * v Value to be printed.
- * Base Base of the value.
- * NumDigits Number of digits to be printed.
- * FieldWidth Width of the printed field.
- * FormatFlags Flags for formatting the value.
- */
- static void _PrintInt(SEGGER_SYSVIEW_PRINTF_DESC * pBufferDesc, int v, unsigned int Base, unsigned int NumDigits, unsigned int FieldWidth, unsigned int FormatFlags) {
- unsigned int Width;
- int Number;
- Number = (v < 0) ? -v : v;
- //
- // Get actual field width
- //
- Width = 1u;
- while (Number >= (int)Base) {
- Number = (Number / (int)Base);
- Width++;
- }
- if (NumDigits > Width) {
- Width = NumDigits;
- }
- if ((FieldWidth > 0u) && ((v < 0) || ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN))) {
- FieldWidth--;
- }
- //
- // Print leading spaces if necessary
- //
- if ((((FormatFlags & FORMAT_FLAG_PAD_ZERO) == 0u) || (NumDigits != 0u)) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u)) {
- if (FieldWidth != 0u) {
- while ((FieldWidth != 0u) && (Width < FieldWidth)) {
- FieldWidth--;
- _StoreChar(pBufferDesc, ' ');
- }
- }
- }
- //
- // Print sign if necessary
- //
- if (v < 0) {
- v = -v;
- _StoreChar(pBufferDesc, '-');
- } else if ((FormatFlags & FORMAT_FLAG_PRINT_SIGN) == FORMAT_FLAG_PRINT_SIGN) {
- _StoreChar(pBufferDesc, '+');
- } else {
- }
- //
- // Print leading zeros if necessary
- //
- if (((FormatFlags & FORMAT_FLAG_PAD_ZERO) == FORMAT_FLAG_PAD_ZERO) && ((FormatFlags & FORMAT_FLAG_LEFT_JUSTIFY) == 0u) && (NumDigits == 0u)) {
- if (FieldWidth != 0u) {
- while ((FieldWidth != 0u) && (Width < FieldWidth)) {
- FieldWidth--;
- _StoreChar(pBufferDesc, '0');
- }
- }
- }
- //
- // Print number without sign
- //
- _PrintUnsigned(pBufferDesc, (unsigned int)v, Base, NumDigits, FieldWidth, FormatFlags);
- }
- /*********************************************************************
- *
- * _VPrintTarget()
- *
- * Function description
- * Stores a formatted string.
- * This data is read by the host.
- *
- * Parameters
- * sFormat Pointer to format string.
- * Options Options to be sent to the host.
- * pParamList Pointer to the list of arguments for the format string.
- */
- static void _VPrintTarget(const char* sFormat, U32 Options, va_list* pParamList) {
- SEGGER_SYSVIEW_PRINTF_DESC BufferDesc;
- char c;
- int v;
- unsigned int NumDigits;
- unsigned int FormatFlags;
- unsigned int FieldWidth;
- U8* pPayloadStart;
- #if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 1 + 2 * SEGGER_SYSVIEW_QUANTA_U32);
- SEGGER_SYSVIEW_LOCK();
- #else
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_MAX_STRING_LEN + 1 + 2 * SEGGER_SYSVIEW_QUANTA_U32);
- #endif
- #if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
- BufferDesc.pBuffer = aPacket;
- #else
- BufferDesc.pBuffer = _aPacket;
- #endif
- BufferDesc.Cnt = 0u;
- BufferDesc.pPayloadStart = pPayloadStart;
- BufferDesc.pPayload = BufferDesc.pPayloadStart + 1u;
- BufferDesc.Options = Options;
- do {
- c = *sFormat;
- sFormat++;
- if (c == 0u) {
- break;
- }
- if (c == '%') {
- //
- // Filter out flags
- //
- FormatFlags = 0u;
- v = 1;
- do {
- c = *sFormat;
- switch (c) {
- case '-': FormatFlags |= FORMAT_FLAG_LEFT_JUSTIFY; sFormat++; break;
- case '0': FormatFlags |= FORMAT_FLAG_PAD_ZERO; sFormat++; break;
- case '+': FormatFlags |= FORMAT_FLAG_PRINT_SIGN; sFormat++; break;
- case '#': FormatFlags |= FORMAT_FLAG_ALTERNATE; sFormat++; break;
- default: v = 0; break;
- }
- } while (v);
- //
- // filter out field with
- //
- FieldWidth = 0u;
- do {
- c = *sFormat;
- if ((c < '0') || (c > '9')) {
- break;
- }
- sFormat++;
- FieldWidth = (FieldWidth * 10u) + ((unsigned int)c - '0');
- } while (1);
- //
- // Filter out precision (number of digits to display)
- //
- NumDigits = 0u;
- c = *sFormat;
- if (c == '.') {
- sFormat++;
- do {
- c = *sFormat;
- if ((c < '0') || (c > '9')) {
- break;
- }
- sFormat++;
- NumDigits = NumDigits * 10u + ((unsigned int)c - '0');
- } while (1);
- }
- //
- // Filter out length modifier
- //
- c = *sFormat;
- do {
- if ((c == 'l') || (c == 'h')) {
- c = *sFormat;
- sFormat++;
- } else {
- break;
- }
- } while (1);
- //
- // Handle specifiers
- //
- switch (c) {
- case 'c': {
- char c0;
- v = va_arg(*pParamList, int);
- c0 = (char)v;
- _StoreChar(&BufferDesc, c0);
- break;
- }
- case 'd':
- v = va_arg(*pParamList, int);
- _PrintInt(&BufferDesc, v, 10u, NumDigits, FieldWidth, FormatFlags);
- break;
- case 'u':
- v = va_arg(*pParamList, int);
- _PrintUnsigned(&BufferDesc, (unsigned int)v, 10u, NumDigits, FieldWidth, FormatFlags);
- break;
- case 'x':
- case 'X':
- v = va_arg(*pParamList, int);
- _PrintUnsigned(&BufferDesc, (unsigned int)v, 16u, NumDigits, FieldWidth, FormatFlags);
- break;
- case 'p':
- v = va_arg(*pParamList, int);
- _PrintUnsigned(&BufferDesc, (unsigned int)v, 16u, 8u, 8u, 0u);
- break;
- case '%':
- _StoreChar(&BufferDesc, '%');
- break;
- default:
- break;
- }
- sFormat++;
- } else {
- _StoreChar(&BufferDesc, c);
- }
- } while (*sFormat);
- //
- // Write remaining data, if any
- //
- if (BufferDesc.Cnt != 0u) {
- *(BufferDesc.pPayloadStart) = BufferDesc.Cnt;
- ENCODE_U32(BufferDesc.pPayload, BufferDesc.Options);
- ENCODE_U32(BufferDesc.pPayload, 0);
- _SendPacket(BufferDesc.pPayloadStart, BufferDesc.pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
- }
- #if SEGGER_SYSVIEW_USE_STATIC_BUFFER == 0
- SEGGER_SYSVIEW_UNLOCK();
- RECORD_END();
- #else
- RECORD_END();
- #endif
- }
- #endif // SEGGER_SYSVIEW_EXCLUDE_PRINTF
- /*********************************************************************
- *
- * Public functions
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_Init()
- *
- * Function description
- * Initializes the SYSVIEW module.
- * Must be called before SystemViewer attaches to the system.
- *
- * Parameters
- * SysFreq - Frequency of timestamp, i.e. CPU core clock frequency.
- * CPUFreq - CPU core clock frequency.
- * pOSAPI - Pointer to the API structure for OS-specific functions.
- * pfSendSysDesc - Pointer to SendSysDesc callback function.
- *
- * Additional information
- * This function initializes the RTT channel used to transport
- * SEGGER SystemView packets.
- * The channel is assigned the label "SysView" for client software
- * to identify the SystemView channel.
- *
- * Notes
- * The channel is configured by the macro SEGGER_SYSVIEW_RTT_CHANNEL.
- */
- void SEGGER_SYSVIEW_Init(U32 SysFreq, U32 CPUFreq, const SEGGER_SYSVIEW_OS_API *pOSAPI, SEGGER_SYSVIEW_SEND_SYS_DESC_FUNC pfSendSysDesc) {
- #ifdef SEGGER_RTT_SECTION
- //
- // Explicitly initialize the RTT Control Block if it is in its dedicated section.
- //
- SEGGER_RTT_Init();
- #endif
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- #if SEGGER_SYSVIEW_RTT_CHANNEL > 0
- SEGGER_RTT_ConfigUpBuffer(SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
- #else
- _SYSVIEW_Globals.UpChannel = SEGGER_RTT_AllocUpBuffer ("SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
- #endif
- _SYSVIEW_Globals.RAMBaseAddress = SEGGER_SYSVIEW_ID_BASE;
- _SYSVIEW_Globals.LastTxTimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP();
- _SYSVIEW_Globals.pOSAPI = pOSAPI;
- _SYSVIEW_Globals.SysFreq = SysFreq;
- _SYSVIEW_Globals.CPUFreq = CPUFreq;
- _SYSVIEW_Globals.pfSendSysDesc = pfSendSysDesc;
- _SYSVIEW_Globals.EnableState = 0;
- _SYSVIEW_Globals.PacketCount = 0;
- #else // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- #if SEGGER_SYSVIEW_RTT_CHANNEL > 0
- SEGGER_RTT_ConfigUpBuffer (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
- SEGGER_RTT_ConfigDownBuffer (SEGGER_SYSVIEW_RTT_CHANNEL, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
- #else
- _SYSVIEW_Globals.UpChannel = SEGGER_RTT_AllocUpBuffer ("SysView", &_UpBuffer[0], sizeof(_UpBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
- //
- // TODO: Use SEGGER_RTT_AllocDownBuffer when SystemViewer is able to handle another Down Channel than Up Channel.
- //
- _SYSVIEW_Globals.DownChannel = _SYSVIEW_Globals.UpChannel;
- SEGGER_RTT_ConfigDownBuffer (_SYSVIEW_Globals.DownChannel, "SysView", &_DownBuffer[0], sizeof(_DownBuffer), SEGGER_RTT_MODE_NO_BLOCK_SKIP);
- #endif
- _SYSVIEW_Globals.RAMBaseAddress = SEGGER_SYSVIEW_ID_BASE;
- _SYSVIEW_Globals.LastTxTimeStamp = SEGGER_SYSVIEW_GET_TIMESTAMP();
- _SYSVIEW_Globals.pOSAPI = pOSAPI;
- _SYSVIEW_Globals.SysFreq = SysFreq;
- _SYSVIEW_Globals.CPUFreq = CPUFreq;
- _SYSVIEW_Globals.pfSendSysDesc = pfSendSysDesc;
- _SYSVIEW_Globals.EnableState = 0;
- #endif // (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_SetRAMBase()
- *
- * Function description
- * Sets the RAM base address, which is subtracted from IDs in order
- * to save bandwidth.
- *
- * Parameters
- * RAMBaseAddress - Lowest RAM Address. (i.e. 0x20000000 on most Cortex-M)
- */
- void SEGGER_SYSVIEW_SetRAMBase(U32 RAMBaseAddress) {
- _SYSVIEW_Globals.RAMBaseAddress = RAMBaseAddress;
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordVoid()
- *
- * Function description
- * Formats and sends a SystemView packet with an empty payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- */
- void SEGGER_SYSVIEW_RecordVoid(unsigned int EventID) {
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
- //
- _SendPacket(pPayloadStart, pPayloadStart, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32()
- *
- * Function description
- * Formats and sends a SystemView packet containing a single U32
- * parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Value - The 32-bit parameter encoded to SystemView packet payload.
- */
- void SEGGER_SYSVIEW_RecordU32(unsigned int EventID, U32 Value) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Value);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x2()
- *
- * Function description
- * Formats and sends a SystemView packet containing 2 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- */
- void SEGGER_SYSVIEW_RecordU32x2(unsigned int EventID, U32 Para0, U32 Para1) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x3()
- *
- * Function description
- * Formats and sends a SystemView packet containing 3 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- * Para2 - The 32-bit parameter encoded to SystemView packet payload.
- */
- void SEGGER_SYSVIEW_RecordU32x3(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 3 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- ENCODE_U32(pPayload, Para2);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x4()
- *
- * Function description
- * Formats and sends a SystemView packet containing 4 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- * Para2 - The 32-bit parameter encoded to SystemView packet payload.
- * Para3 - The 32-bit parameter encoded to SystemView packet payload.
- */
- void SEGGER_SYSVIEW_RecordU32x4(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- ENCODE_U32(pPayload, Para2);
- ENCODE_U32(pPayload, Para3);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x5()
- *
- * Function description
- * Formats and sends a SystemView packet containing 5 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- * Para2 - The 32-bit parameter encoded to SystemView packet payload.
- * Para3 - The 32-bit parameter encoded to SystemView packet payload.
- * Para4 - The 32-bit parameter encoded to SystemView packet payload.
- */
- void SEGGER_SYSVIEW_RecordU32x5(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- ENCODE_U32(pPayload, Para2);
- ENCODE_U32(pPayload, Para3);
- ENCODE_U32(pPayload, Para4);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x6()
- *
- * Function description
- * Formats and sends a SystemView packet containing 6 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- * Para2 - The 32-bit parameter encoded to SystemView packet payload.
- * Para3 - The 32-bit parameter encoded to SystemView packet payload.
- * Para4 - The 32-bit parameter encoded to SystemView packet payload.
- * Para5 - The 32-bit parameter encoded to SystemView packet payload.
- */
- void SEGGER_SYSVIEW_RecordU32x6(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 6 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- ENCODE_U32(pPayload, Para2);
- ENCODE_U32(pPayload, Para3);
- ENCODE_U32(pPayload, Para4);
- ENCODE_U32(pPayload, Para5);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x7()
- *
- * Function description
- * Formats and sends a SystemView packet containing 7 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- * Para2 - The 32-bit parameter encoded to SystemView packet payload.
- * Para3 - The 32-bit parameter encoded to SystemView packet payload.
- * Para4 - The 32-bit parameter encoded to SystemView packet payload.
- * Para5 - The 32-bit parameter encoded to SystemView packet payload.
- * Para6 - The 32-bit parameter encoded to SystemView packet payload.
- */
- void SEGGER_SYSVIEW_RecordU32x7(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 7 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- ENCODE_U32(pPayload, Para2);
- ENCODE_U32(pPayload, Para3);
- ENCODE_U32(pPayload, Para4);
- ENCODE_U32(pPayload, Para5);
- ENCODE_U32(pPayload, Para6);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x8()
- *
- * Function description
- * Formats and sends a SystemView packet containing 8 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- * Para2 - The 32-bit parameter encoded to SystemView packet payload.
- * Para3 - The 32-bit parameter encoded to SystemView packet payload.
- * Para4 - The 32-bit parameter encoded to SystemView packet payload.
- * Para5 - The 32-bit parameter encoded to SystemView packet payload.
- * Para6 - The 32-bit parameter encoded to SystemView packet payload.
- * Para7 - The 32-bit parameter encoded to SystemView packet payload.
- */
- void SEGGER_SYSVIEW_RecordU32x8(unsigned int EventID, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4, U32 Para5, U32 Para6, U32 Para7) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 8 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- ENCODE_U32(pPayload, Para2);
- ENCODE_U32(pPayload, Para3);
- ENCODE_U32(pPayload, Para4);
- ENCODE_U32(pPayload, Para5);
- ENCODE_U32(pPayload, Para6);
- ENCODE_U32(pPayload, Para7);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x9()
- *
- * Function description
- * Formats and sends a SystemView packet containing 9 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- * Para2 - The 32-bit parameter encoded to SystemView packet payload.
- * Para3 - The 32-bit parameter encoded to SystemView packet payload.
- * Para4 - The 32-bit parameter encoded to SystemView packet payload.
- * Para5 - The 32-bit parameter encoded to SystemView packet payload.
- * Para6 - The 32-bit parameter encoded to SystemView packet payload.
- * Para7 - The 32-bit parameter encoded to SystemView packet payload.
- * Para8 - The 32-bit parameter encoded to SystemView packet payload.
- */
- 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) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 9 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- ENCODE_U32(pPayload, Para2);
- ENCODE_U32(pPayload, Para3);
- ENCODE_U32(pPayload, Para4);
- ENCODE_U32(pPayload, Para5);
- ENCODE_U32(pPayload, Para6);
- ENCODE_U32(pPayload, Para7);
- ENCODE_U32(pPayload, Para8);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordU32x10()
- *
- * Function description
- * Formats and sends a SystemView packet containing 10 U32 parameter payload.
- *
- * Parameters
- * EventID - SystemView event ID.
- * Para0 - The 32-bit parameter encoded to SystemView packet payload.
- * Para1 - The 32-bit parameter encoded to SystemView packet payload.
- * Para2 - The 32-bit parameter encoded to SystemView packet payload.
- * Para3 - The 32-bit parameter encoded to SystemView packet payload.
- * Para4 - The 32-bit parameter encoded to SystemView packet payload.
- * Para5 - The 32-bit parameter encoded to SystemView packet payload.
- * Para6 - The 32-bit parameter encoded to SystemView packet payload.
- * Para7 - The 32-bit parameter encoded to SystemView packet payload.
- * Para8 - The 32-bit parameter encoded to SystemView packet payload.
- * Para9 - The 32-bit parameter encoded to SystemView packet payload.
- */
- 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) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 10 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, Para0);
- ENCODE_U32(pPayload, Para1);
- ENCODE_U32(pPayload, Para2);
- ENCODE_U32(pPayload, Para3);
- ENCODE_U32(pPayload, Para4);
- ENCODE_U32(pPayload, Para5);
- ENCODE_U32(pPayload, Para6);
- ENCODE_U32(pPayload, Para7);
- ENCODE_U32(pPayload, Para8);
- ENCODE_U32(pPayload, Para9);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordString()
- *
- * Function description
- * Formats and sends a SystemView packet containing a string.
- *
- * Parameters
- * EventID - SystemView event ID.
- * pString - The string to be sent in the SystemView packet payload.
- *
- * Additional information
- * The string is encoded as a count byte followed by the contents
- * of the string.
- * No more than SEGGER_SYSVIEW_MAX_STRING_LEN bytes will be encoded to the payload.
- */
- void SEGGER_SYSVIEW_RecordString(unsigned int EventID, const char* pString) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
- //
- pPayload = _EncodeStr(pPayloadStart, pString, SEGGER_SYSVIEW_MAX_STRING_LEN);
- _SendPacket(pPayloadStart, pPayload, EventID);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_Start()
- *
- * Function description
- * Start recording SystemView events.
- * This function is triggered by the host application.
- *
- * Additional information
- * This function enables transmission of SystemView packets recorded
- * by subsequent trace calls and records a SystemView Start event.
- *
- * As part of start, a SystemView Init packet is sent, containing the system
- * frequency. The list of current tasks, the current system time and the
- * system description string is sent, too.
- *
- * Notes
- * SEGGER_SYSVIEW_Start and SEGGER_SYSVIEW_Stop do not nest.
- */
- void SEGGER_SYSVIEW_Start(void) {
- if (_SYSVIEW_Globals.EnableState == 0) {
- _SYSVIEW_Globals.EnableState = 1;
- #if (SEGGER_SYSVIEW_POST_MORTEM_MODE == 1)
- _SendSyncInfo();
- #else
- SEGGER_SYSVIEW_LOCK();
- SEGGER_RTT_WriteSkipNoLock(CHANNEL_ID_UP, _abSync, 10);
- SEGGER_SYSVIEW_UNLOCK();
- SEGGER_SYSVIEW_RecordVoid(SYSVIEW_EVTID_TRACE_START);
- {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
- ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
- ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
- ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
- RECORD_END();
- }
- if (_SYSVIEW_Globals.pfSendSysDesc) {
- _SYSVIEW_Globals.pfSendSysDesc();
- }
- SEGGER_SYSVIEW_RecordSystime();
- SEGGER_SYSVIEW_SendTaskList();
- SEGGER_SYSVIEW_SendNumModules();
- #endif
- }
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_Stop()
- *
- * Function description
- * Stop recording SystemView events.
- *
- * Additional information
- * This function disables transmission of SystemView packets recorded
- * by subsequent trace calls. If transmission is enabled when
- * this function is called, a single SystemView Stop event is recorded
- * to the trace, send, and then trace transmission is halted.
- */
- void SEGGER_SYSVIEW_Stop(void) {
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
- //
- if (_SYSVIEW_Globals.EnableState) {
- _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TRACE_STOP);
- _SYSVIEW_Globals.EnableState = 0;
- }
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_GetSysDesc()
- *
- * Function description
- * Triggers a send of the system information and description.
- *
- */
- void SEGGER_SYSVIEW_GetSysDesc(void) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, _SYSVIEW_Globals.SysFreq);
- ENCODE_U32(pPayload, _SYSVIEW_Globals.CPUFreq);
- ENCODE_U32(pPayload, _SYSVIEW_Globals.RAMBaseAddress);
- ENCODE_U32(pPayload, SEGGER_SYSVIEW_ID_SHIFT);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_INIT);
- RECORD_END();
- if (_SYSVIEW_Globals.pfSendSysDesc) {
- _SYSVIEW_Globals.pfSendSysDesc();
- }
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_SendTaskInfo()
- *
- * Function description
- * Send a Task Info Packet, containing TaskId for identification,
- * task priority and task name.
- *
- * Parameters
- * pInfo - Pointer to task information to send.
- */
- void SEGGER_SYSVIEW_SendTaskInfo(const SEGGER_SYSVIEW_TASKINFO *pInfo) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + 1 + 32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, SHRINK_ID(pInfo->TaskID));
- ENCODE_U32(pPayload, pInfo->Prio);
- pPayload = _EncodeStr(pPayload, pInfo->sName, 32);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_INFO);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, SHRINK_ID(pInfo->TaskID));
- ENCODE_U32(pPayload, pInfo->StackBase);
- ENCODE_U32(pPayload, pInfo->StackSize);
- ENCODE_U32(pPayload, 0); // Stack End, future use
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_STACK_INFO);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_SendTaskList()
- *
- * Function description
- * Send all tasks descriptors to the host.
- */
- void SEGGER_SYSVIEW_SendTaskList(void) {
- if (_SYSVIEW_Globals.pOSAPI && _SYSVIEW_Globals.pOSAPI->pfSendTaskList) {
- _SYSVIEW_Globals.pOSAPI->pfSendTaskList();
- }
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_SendSysDesc()
- *
- * Function description
- * Send the system description string to the host.
- * The system description is used by SystemViewer to identify the
- * current application and handle events accordingly.
- *
- * Parameters
- * sSysDesc - Pointer to the 0-terminated system description string.
- *
- * Additional information
- * One system description string may not exceed SEGGER_SYSVIEW_MAX_STRING_LEN characters.
- *
- * The Following items can be described in a system description string.
- * Each item is identified by its identifier, followed by '=' and the value.
- * Items are separated by ','.
- */
- void SEGGER_SYSVIEW_SendSysDesc(const char *sSysDesc) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
- //
- pPayload = _EncodeStr(pPayloadStart, sSysDesc, SEGGER_SYSVIEW_MAX_STRING_LEN);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_SYSDESC);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordSystime()
- *
- * Function description
- * Formats and sends a SystemView Systime containing a single U64 or U32
- * parameter payload.
- */
- void SEGGER_SYSVIEW_RecordSystime(void) {
- U64 Systime;
- if (_SYSVIEW_Globals.pOSAPI && _SYSVIEW_Globals.pOSAPI->pfGetTime) {
- Systime = _SYSVIEW_Globals.pOSAPI->pfGetTime();
- SEGGER_SYSVIEW_RecordU32x2(SYSVIEW_EVTID_SYSTIME_US,
- (U32)(Systime),
- (U32)(Systime >> 32));
- } else {
- SEGGER_SYSVIEW_RecordU32(SYSVIEW_EVTID_SYSTIME_CYCLES, SEGGER_SYSVIEW_GET_TIMESTAMP());
- }
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordEnterISR()
- *
- * Function description
- * Format and send an ISR entry event.
- *
- * Additional information
- * Example packets sent
- * 02 0F 50 // ISR(15) Enter. Timestamp is 80 (0x50)
- */
- void SEGGER_SYSVIEW_RecordEnterISR(void) {
- unsigned v;
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- v = SEGGER_SYSVIEW_GET_INTERRUPT_ID();
- ENCODE_U32(pPayload, v);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_ISR_ENTER);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordExitISR()
- *
- * Function description
- * Format and send an ISR exit event.
- *
- * Additional information
- * Format as follows:
- * 03 <TimeStamp> // Max. packet len is 6
- *
- * Example packets sent
- * 03 20 // ISR Exit. Timestamp is 32 (0x20)
- */
- void SEGGER_SYSVIEW_RecordExitISR(void) {
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
- //
- _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_ISR_EXIT);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordExitISRToScheduler()
- *
- * Function description
- * Format and send an ISR exit into scheduler event.
- *
- * Additional information
- * Format as follows:
- * 18 <TimeStamp> // Max. packet len is 6
- *
- * Example packets sent
- * 18 20 // ISR Exit to Scheduler. Timestamp is 32 (0x20)
- */
- void SEGGER_SYSVIEW_RecordExitISRToScheduler(void) {
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
- //
- _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_ISR_TO_SCHEDULER);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordEnterTimer()
- *
- * Function description
- * Format and send a Timer entry event.
- *
- * Parameters
- * TimerId - Id of the timer which starts.
- */
- void SEGGER_SYSVIEW_RecordEnterTimer(U32 TimerId) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, SHRINK_ID(TimerId));
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TIMER_ENTER);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordExitTimer()
- *
- * Function description
- * Format and send a Timer exit event.
- */
- void SEGGER_SYSVIEW_RecordExitTimer(void) {
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
- //
- _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TIMER_EXIT);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordEndCall()
- *
- * Function description
- * Format and send an End API Call event without return value.
- *
- * Parameters
- * EventID - Id of API function which ends.
- */
- void SEGGER_SYSVIEW_RecordEndCall(unsigned int EventID) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, EventID);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_END_CALL);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordEndCallU32()
- *
- * Function description
- * Format and send an End API Call event with return value.
- *
- * Parameters
- * EventID - Id of API function which ends.
- * Para0 - Return value which will be returned by the API function.
- */
- void SEGGER_SYSVIEW_RecordEndCallU32(unsigned int EventID, U32 Para0) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, EventID);
- ENCODE_U32(pPayload, Para0);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_END_CALL);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnIdle()
- *
- * Function description
- * Record an Idle event.
- */
- void SEGGER_SYSVIEW_OnIdle(void) {
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
- //
- _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_IDLE);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnTaskCreate()
- *
- * Function description
- * Record a Task Create event. The Task Create event corresponds
- * to creating a task in the OS.
- *
- * Parameters
- * TaskId - Task ID of created task.
- */
- void SEGGER_SYSVIEW_OnTaskCreate(U32 TaskId) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- TaskId = SHRINK_ID(TaskId);
- ENCODE_U32(pPayload, TaskId);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_CREATE);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnTaskTerminate()
- *
- * Function description
- * Record a Task termination event.
- * The Task termination event corresponds to terminating a task in
- * the OS. If the TaskId is the currently active task,
- * SEGGER_SYSVIEW_OnTaskStopExec may be used, either.
- *
- * Parameters
- * TaskId - Task ID of terminated task.
- */
- void SEGGER_SYSVIEW_OnTaskTerminate(U32 TaskId) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- TaskId = SHRINK_ID(TaskId);
- ENCODE_U32(pPayload, TaskId);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_TERMINATE);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnTaskStartExec()
- *
- * Function description
- * Record a Task Start Execution event. The Task Start event
- * corresponds to when a task has started to execute rather than
- * when it is ready to execute.
- *
- * Parameters
- * TaskId - Task ID of task that started to execute.
- */
- void SEGGER_SYSVIEW_OnTaskStartExec(U32 TaskId) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- TaskId = SHRINK_ID(TaskId);
- ENCODE_U32(pPayload, TaskId);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_START_EXEC);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnTaskStopExec()
- *
- * Function description
- * Record a Task Stop Execution event. The Task Stop event
- * corresponds to when a task stops executing and terminates.
- */
- void SEGGER_SYSVIEW_OnTaskStopExec(void) {
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE);
- //
- _SendPacket(pPayloadStart, pPayloadStart, SYSVIEW_EVTID_TASK_STOP_EXEC);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnTaskStartReady()
- *
- * Function description
- * Record a Task Start Ready event.
- *
- * Parameters
- * TaskId - Task ID of task that started to execute.
- */
- void SEGGER_SYSVIEW_OnTaskStartReady(U32 TaskId) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- TaskId = SHRINK_ID(TaskId);
- ENCODE_U32(pPayload, TaskId);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_START_READY);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnTaskStopReady()
- *
- * Function description
- * Record a Task Stop Ready event.
- *
- * Parameters
- * TaskId - Task ID of task that completed execution.
- * Cause - Reason for task to stop (i.e. Idle/Sleep)
- */
- void SEGGER_SYSVIEW_OnTaskStopReady(U32 TaskId, unsigned int Cause) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- TaskId = SHRINK_ID(TaskId);
- ENCODE_U32(pPayload, TaskId);
- ENCODE_U32(pPayload, Cause);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_TASK_STOP_READY);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnUserStart()
- *
- * Function description
- * Send a user event start, such as start of a subroutine for profiling.
- *
- * Parameters
- * UserId - User defined ID for the event.
- */
- void SEGGER_SYSVIEW_OnUserStart(unsigned UserId) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, UserId);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_USER_START);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_OnUserStop()
- *
- * Function description
- * Send a user event stop, such as return of a subroutine for profiling.
- *
- * Parameters
- * UserId - User defined ID for the event.
- */
- void SEGGER_SYSVIEW_OnUserStop(unsigned UserId) {
- U8 * pPayload;
- U8 * pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, UserId);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_USER_STOP);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_NameResource()
- *
- * Function description
- * Send the name of a resource to be displayed in SystemViewer.
- *
- * Parameters
- * ResourceId - Id of the resource to be named. i.e. its address.
- * sName - Pointer to the resource name. (Max. SEGGER_SYSVIEW_MAX_STRING_LEN Bytes)
- */
- void SEGGER_SYSVIEW_NameResource(U32 ResourceId, const char* sName) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
- //
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, SHRINK_ID(ResourceId));
- pPayload = _EncodeStr(pPayload, sName, SEGGER_SYSVIEW_MAX_STRING_LEN);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_NAME_RESOURCE);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_SendPacket()
- *
- * Function description
- * Send an event packet.
- *
- * Parameters
- * pPacket - Pointer to the start of the packet.
- * pPayloadEnd - Pointer to the end of the payload.
- * Make sure there are at least 5 bytes free after the payload.
- * EventId - Id of the event packet.
- *
- * Return value
- * !=0: Success, Message sent.
- * ==0: Buffer full, Message *NOT* sent.
- */
- int SEGGER_SYSVIEW_SendPacket(U8* pPacket, U8* pPayloadEnd, unsigned int EventId) {
- #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
- SEGGER_SYSVIEW_LOCK();
- #endif
- _SendPacket(pPacket + 4, pPayloadEnd, EventId);
- #if (SEGGER_SYSVIEW_USE_STATIC_BUFFER == 1)
- SEGGER_SYSVIEW_UNLOCK();
- #endif
- return 0;
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_EncodeU32()
- *
- * Function description
- * Encode a U32 in variable-length format.
- *
- * Parameters
- * pPayload - Pointer to where U32 will be encoded.
- * Value - The 32-bit value to be encoded.
- *
- * Return value
- * Pointer to the byte following the value, i.e. the first free
- * byte in the payload and the next position to store payload
- * content.
- */
- U8* SEGGER_SYSVIEW_EncodeU32(U8* pPayload, U32 Value) {
- ENCODE_U32(pPayload, Value);
- return pPayload;
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_EncodeString()
- *
- * Function description
- * Encode a string in variable-length format.
- *
- * Parameters
- * pPayload - Pointer to where string will be encoded.
- * s - String to encode.
- * MaxLen - Maximum number of characters to encode from string.
- *
- * Return value
- * Pointer to the byte following the value, i.e. the first free
- * byte in the payload and the next position to store payload
- * content.
- *
- * Additional information
- * The string is encoded as a count byte followed by the contents
- * of the string.
- * No more than 1 + MaxLen bytes will be encoded to the payload.
- */
- U8* SEGGER_SYSVIEW_EncodeString(U8* pPayload, const char* s, unsigned int MaxLen) {
- return _EncodeStr(pPayload, s, MaxLen);
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_EncodeData()
- *
- * Function description
- * Encode a byte buffer in variable-length format.
- *
- * Parameters
- * pPayload - Pointer to where string will be encoded.
- * pSrc - Pointer to data buffer to be encoded.
- * NumBytes - Number of bytes in the buffer to be encoded.
- *
- * Return value
- * Pointer to the byte following the value, i.e. the first free
- * byte in the payload and the next position to store payload
- * content.
- *
- * Additional information
- * The data is encoded as a count byte followed by the contents
- * of the data buffer.
- * Make sure NumBytes + 1 bytes are free for the payload.
- */
- U8* SEGGER_SYSVIEW_EncodeData(U8 *pPayload, const char* pSrc, unsigned int NumBytes) {
- return _EncodeData(pPayload, pSrc, NumBytes);
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_EncodeId()
- *
- * Function description
- * Encode a 32-bit Id in shrunken variable-length format.
- *
- * Parameters
- * pPayload - Pointer to where the Id will be encoded.
- * Id - The 32-bit value to be encoded.
- *
- * Return value
- * Pointer to the byte following the value, i.e. the first free
- * byte in the payload and the next position to store payload
- * content.
- *
- * Additional information
- * The parameters to shrink an Id can be configured in
- * SEGGER_SYSVIEW_Conf.h and via SEGGER_SYSVIEW_SetRAMBase().
- * SEGGER_SYSVIEW_ID_BASE: Lowest Id reported by the application.
- * (i.e. 0x20000000 when all Ids are an address in this RAM)
- * SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to
- * save bandwidth. (i.e. 2 when Ids are 4 byte aligned)
- */
- U8* SEGGER_SYSVIEW_EncodeId(U8* pPayload, U32 Id) {
- Id = SHRINK_ID(Id);
- ENCODE_U32(pPayload, Id);
- return pPayload;
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_ShrinkId()
- *
- * Function description
- * Get the shrunken value of an Id for further processing like in
- * SEGGER_SYSVIEW_NameResource().
- *
- * Parameters
- * Id - The 32-bit value to be shrunken.
- *
- * Return value
- * Shrunken Id.
- *
- * Additional information
- * The parameters to shrink an Id can be configured in
- * SEGGER_SYSVIEW_Conf.h and via SEGGER_SYSVIEW_SetRAMBase().
- * SEGGER_SYSVIEW_ID_BASE: Lowest Id reported by the application.
- * (i.e. 0x20000000 when all Ids are an address in this RAM)
- * SEGGER_SYSVIEW_ID_SHIFT: Number of bits to shift the Id to
- * save bandwidth. (i.e. 2 when Ids are 4 byte aligned)
- */
- U32 SEGGER_SYSVIEW_ShrinkId(U32 Id) {
- return SHRINK_ID(Id);
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RegisterModule()
- *
- * Function description
- * Register a middleware module for recording its events.
- *
- * Parameters
- * pModule - The middleware module information.
- *
- * Additional information
- * SEGGER_SYSVIEW_MODULE elements:
- * sDescription - Pointer to a string containing the module name and optionally the module event description.
- * NumEvents - Number of events the module wants to register.
- * EventOffset - Offset to be added to the event Ids. Out parameter, set by this function. Do not modify after calling this function.
- * pfSendModuleDesc - Callback function pointer to send more detailed module description to SystemViewer.
- * pNext - Pointer to next registered module. Out parameter, set by this function. Do not modify after calling this function.
- */
- void SEGGER_SYSVIEW_RegisterModule(SEGGER_SYSVIEW_MODULE* pModule) {
- SEGGER_SYSVIEW_LOCK();
- if (_pFirstModule == 0) {
- //
- // No module registered, yet.
- // Start list with new module.
- // EventOffset is the base offset for modules
- //
- pModule->EventOffset = MODULE_EVENT_OFFSET;
- pModule->pNext = 0;
- _pFirstModule = pModule;
- _NumModules = 1;
- } else {
- //
- // Registreded module(s) present.
- // Prepend new module in list.
- // EventOffset set from number of events and offset of previous module.
- //
- pModule->EventOffset = _pFirstModule->EventOffset + _pFirstModule->NumEvents;
- pModule->pNext = _pFirstModule;
- _pFirstModule = pModule;
- _NumModules++;
- }
- SEGGER_SYSVIEW_SendModule(0);
- if (pModule->pfSendModuleDesc) {
- pModule->pfSendModuleDesc();
- }
- SEGGER_SYSVIEW_UNLOCK();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_RecordModuleDescription()
- *
- * Function description
- * Sends detailed information of a registered module to the host.
- *
- * Parameters
- * pModule - Pointer to the described module.
- * sDescription - Pointer to a description string.
- */
- void SEGGER_SYSVIEW_RecordModuleDescription(const SEGGER_SYSVIEW_MODULE* pModule, const char* sDescription) {
- U8 ModuleId;
- SEGGER_SYSVIEW_MODULE* p;
- p = _pFirstModule;
- ModuleId = 0;
- do {
- if (p == pModule) {
- break;
- }
- ModuleId++;
- p = p->pNext;
- } while (p);
- {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
- //
- pPayload = pPayloadStart;
- //
- // Send module description
- // Send event offset and number of events
- //
- ENCODE_U32(pPayload, ModuleId);
- ENCODE_U32(pPayload, (pModule->EventOffset));
- pPayload = _EncodeStr(pPayload, sDescription, SEGGER_SYSVIEW_MAX_STRING_LEN);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MODULEDESC);
- RECORD_END();
- }
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_SendModule()
- *
- * Function description
- * Sends the information of a registered module to the host.
- *
- * Parameters
- * ModuleId - Id of the requested module.
- */
- void SEGGER_SYSVIEW_SendModule(U8 ModuleId) {
- SEGGER_SYSVIEW_MODULE* pModule;
- U32 n;
- if (_pFirstModule != 0) {
- pModule = _pFirstModule;
- for (n = 0; n < ModuleId; n++) {
- pModule = pModule->pNext;
- if (pModule == 0) {
- break;
- }
- }
- if (pModule != 0) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + 1 + SEGGER_SYSVIEW_MAX_STRING_LEN);
- //
- pPayload = pPayloadStart;
- //
- // Send module description
- // Send event offset and number of events
- //
- ENCODE_U32(pPayload, ModuleId);
- ENCODE_U32(pPayload, (pModule->EventOffset));
- pPayload = _EncodeStr(pPayload, pModule->sModule, SEGGER_SYSVIEW_MAX_STRING_LEN);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_MODULEDESC);
- RECORD_END();
- }
- }
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_SendModuleDescription()
- *
- * Function description
- * Triggers a send of the registered module descriptions.
- *
- */
- void SEGGER_SYSVIEW_SendModuleDescription(void) {
- SEGGER_SYSVIEW_MODULE* pModule;
- if (_pFirstModule != 0) {
- pModule = _pFirstModule;
- do {
- if (pModule->pfSendModuleDesc) {
- pModule->pfSendModuleDesc();
- }
- pModule = pModule->pNext;
- } while (pModule);
- }
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_SendNumModules()
- *
- * Function description
- * Send the number of registered modules to the host.
- */
- void SEGGER_SYSVIEW_SendNumModules(void) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2*SEGGER_SYSVIEW_QUANTA_U32);
- pPayload = pPayloadStart;
- ENCODE_U32(pPayload, _NumModules);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_NUMMODULES);
- RECORD_END();
- }
- #ifndef SEGGER_SYSVIEW_EXCLUDE_PRINTF // Define in project to avoid warnings about variable parameter list
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_PrintfHostEx()
- *
- * Function description
- * Print a string which is formatted on the host by SystemViewer
- * with Additional information.
- *
- * Parameters
- * s - String to be formatted.
- * Options - Options for the string. i.e. Log level.
- *
- * Additional information
- * All format arguments are treated as 32-bit scalar values.
- */
- void SEGGER_SYSVIEW_PrintfHostEx(const char* s, U32 Options, ...) {
- va_list ParamList;
- #if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
- int r;
- va_start(ParamList, Options);
- r = _VPrintHost(s, Options, &ParamList);
- va_end(ParamList);
- if (r == -1) {
- va_start(ParamList, Options);
- _VPrintTarget(s, Options, &ParamList);
- va_end(ParamList);
- }
- #else
- va_start(ParamList, Options);
- _VPrintHost(s, Options, &ParamList);
- va_end(ParamList);
- #endif
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_PrintfHost()
- *
- * Function description
- * Print a string which is formatted on the host by SystemViewer.
- *
- * Parameters
- * s - String to be formatted.
- *
- * Additional information
- * All format arguments are treated as 32-bit scalar values.
- */
- void SEGGER_SYSVIEW_PrintfHost(const char* s, ...) {
- va_list ParamList;
- #if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
- int r;
- va_start(ParamList, s);
- r = _VPrintHost(s, SEGGER_SYSVIEW_LOG, &ParamList);
- va_end(ParamList);
- if (r == -1) {
- va_start(ParamList, s);
- _VPrintTarget(s, SEGGER_SYSVIEW_LOG, &ParamList);
- va_end(ParamList);
- }
- #else
- va_start(ParamList, s);
- _VPrintHost(s, SEGGER_SYSVIEW_LOG, &ParamList);
- va_end(ParamList);
- #endif
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_WarnfHost()
- *
- * Function description
- * Print a warnin string which is formatted on the host by
- * SystemViewer.
- *
- * Parameters
- * s - String to be formatted.
- *
- * Additional information
- * All format arguments are treated as 32-bit scalar values.
- */
- void SEGGER_SYSVIEW_WarnfHost(const char* s, ...) {
- va_list ParamList;
- #if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
- int r;
- va_start(ParamList, s);
- r = _VPrintHost(s, SEGGER_SYSVIEW_WARNING, &ParamList);
- va_end(ParamList);
- if (r == -1) {
- va_start(ParamList, s);
- _VPrintTarget(s, SEGGER_SYSVIEW_WARNING, &ParamList);
- va_end(ParamList);
- }
- #else
- va_start(ParamList, s);
- _VPrintHost(s, SEGGER_SYSVIEW_WARNING, &ParamList);
- va_end(ParamList);
- #endif
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_ErrorfHost()
- *
- * Function description
- * Print an error string which is formatted on the host by
- * SystemViewer.
- *
- * Parameters
- * s - String to be formatted.
- *
- * Additional information
- * All format arguments are treated as 32-bit scalar values.
- */
- void SEGGER_SYSVIEW_ErrorfHost(const char* s, ...) {
- va_list ParamList;
- #if SEGGER_SYSVIEW_PRINTF_IMPLICIT_FORMAT
- int r;
- va_start(ParamList, s);
- r = _VPrintHost(s, SEGGER_SYSVIEW_ERROR, &ParamList);
- va_end(ParamList);
- if (r == -1) {
- va_start(ParamList, s);
- _VPrintTarget(s, SEGGER_SYSVIEW_ERROR, &ParamList);
- va_end(ParamList);
- }
- #else
- va_start(ParamList, s);
- _VPrintHost(s, SEGGER_SYSVIEW_ERROR, &ParamList);
- va_end(ParamList);
- #endif
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_PrintfTargetEx()
- *
- * Function description
- * Print a string which is formatted on the target before sent to
- * the host with Additional information.
- *
- * Parameters
- * s - String to be formatted.
- * Options - Options for the string. i.e. Log level.
- */
- void SEGGER_SYSVIEW_PrintfTargetEx(const char* s, U32 Options, ...) {
- va_list ParamList;
- va_start(ParamList, Options);
- _VPrintTarget(s, Options, &ParamList);
- va_end(ParamList);
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_PrintfTarget()
- *
- * Function description
- * Print a string which is formatted on the target before sent to
- * the host.
- *
- * Parameters
- * s - String to be formatted.
- */
- void SEGGER_SYSVIEW_PrintfTarget(const char* s, ...) {
- va_list ParamList;
- va_start(ParamList, s);
- _VPrintTarget(s, SEGGER_SYSVIEW_LOG, &ParamList);
- va_end(ParamList);
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_WarnfTarget()
- *
- * Function description
- * Print a warning string which is formatted on the target before
- * sent to the host.
- *
- * Parameters
- * s - String to be formatted.
- */
- void SEGGER_SYSVIEW_WarnfTarget(const char* s, ...) {
- va_list ParamList;
- va_start(ParamList, s);
- _VPrintTarget(s, SEGGER_SYSVIEW_WARNING, &ParamList);
- va_end(ParamList);
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_ErrorfTarget()
- *
- * Function description
- * Print an error string which is formatted on the target before
- * sent to the host.
- *
- * Parameters
- * s - String to be formatted.
- */
- void SEGGER_SYSVIEW_ErrorfTarget(const char* s, ...) {
- va_list ParamList;
- va_start(ParamList, s);
- _VPrintTarget(s, SEGGER_SYSVIEW_ERROR, &ParamList);
- va_end(ParamList);
- }
- #endif // SEGGER_SYSVIEW_EXCLUDE_PRINTF
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_Print()
- *
- * Function description
- * Print a string to the host.
- *
- * Parameters
- * s - String to sent.
- */
- void SEGGER_SYSVIEW_Print(const char* s) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
- //
- pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
- ENCODE_U32(pPayload, SEGGER_SYSVIEW_LOG);
- ENCODE_U32(pPayload, 0);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_Warn()
- *
- * Function description
- * Print a warning string to the host.
- *
- * Parameters
- * s - String to sent.
- */
- void SEGGER_SYSVIEW_Warn(const char* s) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
- //
- pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
- ENCODE_U32(pPayload, SEGGER_SYSVIEW_WARNING);
- ENCODE_U32(pPayload, 0);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_Error()
- *
- * Function description
- * Print an error string to the host.
- *
- * Parameters
- * s - String to sent.
- */
- void SEGGER_SYSVIEW_Error(const char* s) {
- U8* pPayload;
- U8* pPayloadStart;
- RECORD_START(SEGGER_SYSVIEW_INFO_SIZE + 2 * SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN);
- //
- pPayload = _EncodeStr(pPayloadStart, s, SEGGER_SYSVIEW_MAX_STRING_LEN);
- ENCODE_U32(pPayload, SEGGER_SYSVIEW_ERROR);
- ENCODE_U32(pPayload, 0);
- _SendPacket(pPayloadStart, pPayload, SYSVIEW_EVTID_PRINT_FORMATTED);
- RECORD_END();
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_EnableEvents()
- *
- * Function description
- * Enable standard SystemView events to be generated.
- *
- * Parameters
- * EnableMask - Events to be enabled.
- */
- void SEGGER_SYSVIEW_EnableEvents(U32 EnableMask) {
- _SYSVIEW_Globals.DisabledEvents &= ~EnableMask;
- }
- /*********************************************************************
- *
- * SEGGER_SYSVIEW_DisableEvents()
- *
- * Function description
- * Disable standard SystemView events to not be generated.
- *
- * Parameters
- * DisableMask - Events to be disabled.
- */
- void SEGGER_SYSVIEW_DisableEvents(U32 DisableMask) {
- _SYSVIEW_Globals.DisabledEvents |= DisableMask;
- }
- /*************************** End of file ****************************/
|