diff --git a/Inc/itmfifos.h b/Inc/itmfifos.h index 8d212951..fe905a9c 100644 --- a/Inc/itmfifos.h +++ b/Inc/itmfifos.h @@ -11,7 +11,7 @@ #include "tpiuDecoder.h" #include "itmDecoder.h" -#include "cobs.h" +#include "otag.h" #include "generics.h" @@ -27,7 +27,7 @@ extern "C" { struct Channel; struct itmfifosHandle; -enum Prot { PROT_COBS, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; +enum Prot { PROT_OTAG, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; /* Fifos running */ void itmfifoForceSync( struct itmfifosHandle *f, bool synced ); /* Force sync status */ diff --git a/Src/itmfifos.c b/Src/itmfifos.c index 871752fe..194eecdc 100644 --- a/Src/itmfifos.c +++ b/Src/itmfifos.c @@ -21,7 +21,7 @@ #include "generics.h" #include "tpiuDecoder.h" #include "itmDecoder.h" -#include "cobs.h" +#include "otag.h" #include "fileWriter.h" #include "itmfifos.h" #include "msgDecoder.h" @@ -61,7 +61,7 @@ struct itmfifosHandle struct ITMPacket h; struct TPIUDecoder t; struct TPIUPacket p; - struct COBS cobs; + struct OTAG ot; enum timeDelay timeStatus; /* Indicator of if this time is exact */ uint64_t timeStamp; /* Latest received time */ @@ -73,11 +73,10 @@ struct itmfifosHandle bool filewriter; /* Is the filewriter in use? */ bool forceITMSync; /* Is ITM to be forced into sync? */ bool permafile; /* Use permanent files rather than fifos */ - int tag; /* Which COBS or TPIU stream are we decoding? */ - struct Frame cobsPart; /* Any part frame that has been received */ + int tag; /* Which OTAG or TPIU stream are we decoding? */ bool amEnding; /* Flag indicating end is in progress */ - enum Prot protocol; /* What protocol to communicate (default to COBS (== orbuculum)) */ + enum Prot protocol; /* What protocol to communicate (default to OTAG (== orbuculum)) */ struct Channel c[NUM_CHANNELS + 1]; /* Output for each channel */ }; @@ -554,14 +553,14 @@ static void _tpiuProtocolPump( struct itmfifosHandle *f, uint8_t c ) // ==================================================================================================== -static void _COBSpacketRxed ( struct Frame *p, void *param ) +static void _OTAGpacketRxed ( struct OTAGFrame *p, void *param ) { struct itmfifosHandle *f = ( struct itmfifosHandle * )param; - if ( p->d[0] == f->tag ) + if ( p->tag == f->tag ) { - for ( int i = 1; i < p->len; i++ ) + for ( int i = 0; i < p->len; i++ ) { _itmPumpProcess( f, p->d[i] ); } @@ -699,9 +698,9 @@ void itmfifoProtocolPump( struct itmfifosHandle *f, uint8_t *c, int len ) { - if ( PROT_COBS == f->protocol ) + if ( PROT_OTAG == f->protocol ) { - COBSPump( &f->cobs, c, len, _COBSpacketRxed, f ); + OTAGPump( &f->ot, c, len, _OTAGpacketRxed, f ); } else while ( len-- ) @@ -739,7 +738,7 @@ bool itmfifoCreate( struct itmfifosHandle *f ) /* Reset the TPIU handler before we start */ TPIUDecoderInit( &f->t ); - COBSInit( &f->cobs ); + OTAGInit( &f->ot ); ITMDecoderInit( &f->i, f->forceITMSync ); /* Cycle through channels and create a fifo for each one that is enabled */ diff --git a/Src/orbcat.c b/Src/orbcat.c index bf9a8d4b..11f3d39a 100644 --- a/Src/orbcat.c +++ b/Src/orbcat.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "nw.h" #include "git_version_info.h" @@ -108,7 +109,7 @@ struct uint64_t dwtte; /* Timestamp for dwt print age */ uint64_t oldte; /* Old time for interval calculation */ char dwtText[MAX_STRING_LENGTH]; /* DWT text that arrived while a line was in progress */ - + bool ending; /* Time to shut up shop */ } _r; #define DWT_TO_US (100000L) @@ -964,7 +965,7 @@ static void _feedStream( struct Stream *stream ) struct timeval t; unsigned char cbw[TRANSFER_SIZE]; - while ( true ) + while ( !_r.ending ) { size_t receivedSize; @@ -1016,6 +1017,13 @@ static void _feedStream( struct Stream *stream ) } } +// ==================================================================================================== +static void _intHandler( int sig ) + +{ + /* CTRL-C exit is not an error... */ + _r.ending = true; +} // ==================================================================================================== int main( int argc, char *argv[] ) @@ -1033,11 +1041,17 @@ int main( int argc, char *argv[] ) OTAGInit( &_r.c ); MSGSeqInit( &_r.d, &_r.i, MSG_REORDER_BUFLEN ); - while ( true ) + /* This ensures the signal handler gets called */ + if ( SIG_ERR == signal( SIGINT, _intHandler ) ) + { + genericsExit( -1, "Failed to establish Int handler" EOL ); + } + + while ( !_r.ending ) { struct Stream *stream = NULL; - while ( true ) + while ( !_r.ending ) { stream = _tryOpenStream(); @@ -1070,10 +1084,10 @@ int main( int argc, char *argv[] ) if ( stream != NULL ) { _feedStream( stream ); - } - stream->close( stream ); - free( stream ); + stream->close( stream ); + free( stream ); + } if ( options.endTerminate ) { diff --git a/Src/orbdump.c b/Src/orbdump.c index a842e5cd..11ff5cbc 100644 --- a/Src/orbdump.c +++ b/Src/orbdump.c @@ -10,13 +10,14 @@ #include #include #include +#include #include "generics.h" #include "uthash.h" #include "git_version_info.h" #include "generics.h" #include "tpiuDecoder.h" -#include "cobs.h" +#include "otag.h" #include "itmDecoder.h" #include "stream.h" @@ -27,8 +28,8 @@ #define DEFAULT_OUTFILE "/dev/stdout" #define DEFAULT_TIMELEN 10000 -enum Prot { PROT_COBS, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; -const char *protString[] = {"COBS", "ITM", "TPIU", NULL}; +enum Prot { PROT_OTAG, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; +const char *protString[] = {"OTAG", "ITM", "TPIU", NULL}; /* ---------- CONFIGURATION ----------------- */ @@ -71,7 +72,8 @@ struct struct ITMPacket h; struct TPIUDecoder t; struct TPIUPacket p; - struct COBS c; + struct OTAG c; + bool ending; } _r; // ==================================================================================================== @@ -167,10 +169,10 @@ void _printHelp( const char *const progName ) genericsPrintf( " -M, --no-colour: Supress colour in output" EOL ); genericsPrintf( " -n, --itm-sync: Enforce sync requirement for ITM (i.e. ITM needs to issue syncs)" EOL ); genericsPrintf( " -o, --output-file: to be used for dump file (defaults to %s)" EOL, options.outfile ); - genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to COBS if -s is not set, otherwise ITM unless" EOL \ + genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to OTAG if -s is not set, otherwise ITM unless" EOL \ " explicitly set to TPIU to decode TPIU frames on channel set by -t" EOL ); genericsPrintf( " -s, --server: : to use" EOL ); - genericsPrintf( " -t, --tag: Which TPIU stream or COBS tag to use (normally 1)" EOL ); + genericsPrintf( " -t, --tag: Which TPIU stream or OTAG tag to use (normally 1)" EOL ); genericsPrintf( " -v, --verbose: Verbose mode 0(errors)..3(debug)" EOL ); genericsPrintf( " -V, --version: Print version and exit" EOL ); genericsPrintf( " -w, --sync-write: Write synchronously to the output file after every packet" EOL ); @@ -205,6 +207,7 @@ bool _processOptions( int argc, char *argv[] ) int c, optionIndex = 0; bool protExplicit = false; bool serverExplicit = false; + bool portExplicit = false; while ( ( c = getopt_long ( argc, argv, "hVl:Mno:p:s:t:v:w", _longOptions, &optionIndex ) ) != -1 ) switch ( c ) @@ -289,6 +292,10 @@ bool _processOptions( int argc, char *argv[] ) { options.port = NWCLIENT_SERVER_PORT; } + else + { + portExplicit = true; + } break; @@ -319,12 +326,17 @@ bool _processOptions( int argc, char *argv[] ) return false; } - /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not COBS */ + /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not OTAG */ if ( serverExplicit && !protExplicit ) { options.protocol = PROT_ITM; } + if ( ( options.protocol == PROT_TPIU ) && !portExplicit ) + { + options.port = NWCLIENT_SERVER_PORT; + } + genericsReport( V_INFO, "orbdump version " GIT_DESCRIBE EOL ); genericsReport( V_INFO, "Server : %s:%d" EOL, options.server, options.port ); genericsReport( V_INFO, "ForceSync : %s" EOL, options.forceITMSync ? "true" : "false" ); @@ -343,8 +355,8 @@ bool _processOptions( int argc, char *argv[] ) switch ( options.protocol ) { - case PROT_COBS: - genericsReport( V_INFO, "Decoding COBS (Orbuculum) with ITM in stream %d" EOL, options.tag ); + case PROT_OTAG: + genericsReport( V_INFO, "Decoding OTAG (Orbuculum) with ITM in stream %d" EOL, options.tag ); break; case PROT_ITM: @@ -365,12 +377,12 @@ bool _processOptions( int argc, char *argv[] ) // ==================================================================================================== -static void _COBSpacketRxed ( struct Frame *p, void *param ) +static void _OTAGpacketRxed ( struct OTAGFrame *p, void *param ) { - if ( p->d[0] == options.tag ) + if ( p->tag == options.tag ) { - for ( int i = 1; i < p->len; i++ ) + for ( int i = 0; i < p->len; i++ ) { ITMPump( &_r.i, p->d[i] ); } @@ -383,7 +395,13 @@ static struct Stream *_tryOpenStream( void ) { return streamCreateSocket( options.server, options.port ); } +// ==================================================================================================== +static void _intHandler( int sig ) +{ + /* CTRL-C exit is not an error... */ + _r.ending = true; +} // ==================================================================================================== int main( int argc, char *argv[] ) { @@ -407,9 +425,15 @@ int main( int argc, char *argv[] ) /* Reset the TPIU handler before we start */ TPIUDecoderInit( &_r.t ); ITMDecoderInit( &_r.i, options.forceITMSync ); - COBSInit( &_r.c ); + OTAGInit( &_r.c ); struct Stream *stream = _tryOpenStream(); + /* This ensures the signal handler gets called */ + if ( SIG_ERR == signal( SIGINT, _intHandler ) ) + { + genericsExit( -1, "Failed to establish Int handler" EOL ); + } + if ( stream == NULL ) { genericsReport( V_ERROR, "Could not connect" EOL ); @@ -428,7 +452,7 @@ int main( int argc, char *argv[] ) genericsReport( V_INFO, "Waiting for sync" EOL ); /* Start the process of collecting the data */ - while ( true ) + while ( !_r.ending ) { enum ReceiveResult result = stream->receive( stream, cbw, TRANSFER_SIZE, NULL, &receivedSize ); @@ -453,9 +477,9 @@ int main( int argc, char *argv[] ) } - if ( PROT_COBS == options.protocol ) + if ( PROT_OTAG == options.protocol ) { - COBSPump( &_r.c, cbw, receivedSize, _COBSpacketRxed, &_r ); + OTAGPump( &_r.c, cbw, receivedSize, _OTAGpacketRxed, &_r ); } else { diff --git a/Src/orbfifo.c b/Src/orbfifo.c index f71d0b08..18636d03 100644 --- a/Src/orbfifo.c +++ b/Src/orbfifo.c @@ -29,7 +29,7 @@ #include "itmfifos.h" -const char *protString[] = {"COBS", "ITM", "TPIU", NULL}; +const char *protString[] = {"OTAG", "ITM", "TPIU", NULL}; //#define DUMP_BLOCK @@ -79,10 +79,10 @@ static void _printHelp( const char *const progName ) genericsPrintf( " -h, --help: This help" EOL ); genericsPrintf( " -M, --no-colour: Supress colour in output" EOL ); genericsPrintf( " -P, --permanent: Create permanent files rather than fifos" EOL ); - genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to COBS if -s is not set, otherwise ITM unless" EOL \ + genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to OTAG if -s is not set, otherwise ITM unless" EOL \ " explicitly set to TPIU to decode TPIU frames on stream set by -t" EOL ); genericsPrintf( " -s, --server: : to use" EOL ); - genericsPrintf( " -t, --tag: Which TPIU stream or COBS tag to use (normally 1)" EOL ); + genericsPrintf( " -t, --tag: Which TPIU stream or OTAG tag to use (normally 1)" EOL ); genericsPrintf( " -v, --verbose: Verbose mode 0(errors)..3(debug)" EOL ); genericsPrintf( " -V, --version: Print version and exit" EOL ); genericsPrintf( " -W, --writer-path: Enable filewriter functionality using specified base path" EOL ); @@ -125,6 +125,7 @@ static bool _processOptions( int argc, char *argv[] ) char *chanIndex; bool protExplicit = false; bool serverExplicit = false; + bool portExplicit = false; while ( ( c = getopt_long ( argc, argv, "b:c:Ef:hVn:Pp:s:t:v:w:", _longOptions, &optionIndex ) ) != -1 ) switch ( c ) @@ -220,6 +221,10 @@ static bool _processOptions( int argc, char *argv[] ) { options.port = NWCLIENT_SERVER_PORT; } + else + { + portExplicit = true; + } break; @@ -322,12 +327,17 @@ static bool _processOptions( int argc, char *argv[] ) // ------------------------------------ } - /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not COBS */ + /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not OTAG */ if ( serverExplicit && !protExplicit ) { itmfifoSetProtocol( _r.f, PROT_ITM ); } + if ( ( itmfifoGetProtocol( _r.f ) == PROT_TPIU ) && !portExplicit ) + { + options.port = NWCLIENT_SERVER_PORT; + } + /* ... and dump the config if we're being verbose */ genericsReport( V_INFO, "orbfifo version " GIT_DESCRIBE EOL ); @@ -349,8 +359,8 @@ static bool _processOptions( int argc, char *argv[] ) switch ( itmfifoGetProtocol( _r.f ) ) { - case PROT_COBS: - genericsReport( V_INFO, "Decoding COBS (Orbuculum) with ITM in stream %d" EOL, itmfifoGettag( _r.f ) ); + case PROT_OTAG: + genericsReport( V_INFO, "Decoding OTAG (Orbuculum) with ITM in stream %d" EOL, itmfifoGettag( _r.f ) ); break; case PROT_ITM: diff --git a/Src/orblcd.c b/Src/orblcd.c index bf2dbeb1..2dbf6507 100644 --- a/Src/orblcd.c +++ b/Src/orblcd.c @@ -19,13 +19,14 @@ #include #include #include +#include #include "git_version_info.h" #include "generics.h" #include "tpiuDecoder.h" #include "itmDecoder.h" #include "msgDecoder.h" -#include "cobs.h" +#include "otag.h" #include "stream.h" #include "nw.h" #include "orblcd_protocol.h" @@ -65,8 +66,8 @@ struct TApp }; /************** APPLICATION SPECIFIC ENDS ***************************************************************/ -enum Prot { PROT_COBS, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; -const char *protString[] = {"COBS", "ITM", "TPIU", NULL}; +enum Prot { PROT_OTAG, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; +const char *protString[] = {"OTAG", "ITM", "TPIU", NULL}; /* Record for options, either defaults or from command line */ struct Options @@ -74,12 +75,12 @@ struct Options /* Source information */ int port; /* Source port, or zero if no port set */ char *server; /* Source server */ - enum Prot protocol; /* What protocol to communicate (default to COBS (== orbuculum)) */ + enum Prot protocol; /* What protocol to communicate (default to OTAG (== orbuculum)) */ char *file; /* File host connection */ bool fileTerminate; /* Terminate when file read isn't successful */ /* Demux information */ - uint32_t tag; /* Which TPIU or COBS stream are we decoding? */ + uint32_t tag; /* Which TPIU or OTAG stream are we decoding? */ bool forceITMSync; /* Do we need ITM syncs? */ } _options = {.forceITMSync = true, .tag = 1, .port = OTCLIENT_SERVER_PORT, .server = "localhost"}; @@ -91,7 +92,7 @@ struct RunTime struct ITMPacket h; struct TPIUDecoder t; struct TPIUPacket p; - struct COBS c; + struct OTAG c; bool ending; /* Flag indicating app is terminating */ bool errored; /* Flag indicating problem in reception process */ @@ -372,14 +373,14 @@ static struct Stream *_tryOpenStream( struct RunTime *r ) } // ==================================================================================================== -static void _COBSpacketRxed ( struct Frame *p, void *param ) +static void _OTAGpacketRxed ( struct OTAGFrame *p, void *param ) { struct RunTime *r = ( struct RunTime * )param; - if ( p->d[0] == r->options->tag ) + if ( p->tag == r->options->tag ) { - for ( int i = 1; i < p->len; i++ ) + for ( int i = 0; i < p->len; i++ ) { _itmPumpProcess( p->d[i], r ); } @@ -398,7 +399,7 @@ static bool _feedStream( struct Stream *stream, struct RunTime *r ) }; SDL_Event e; - while ( true ) + while ( !_r.ending ) { size_t receivedSize; enum ReceiveResult result = stream->receive( stream, cbw, TRANSFER_SIZE, &t, &receivedSize ); @@ -428,9 +429,9 @@ static bool _feedStream( struct Stream *stream, struct RunTime *r ) } } - if ( PROT_COBS == r->options->protocol ) + if ( PROT_OTAG == r->options->protocol ) { - COBSPump( &_r.c, cbw, receivedSize, _COBSpacketRxed, &_r ); + OTAGPump( &_r.c, cbw, receivedSize, _OTAGpacketRxed, &_r ); } else { @@ -464,11 +465,11 @@ void _printHelp( const char *const progName ) genericsPrintf( " -f, --input-file: Take input from specified file" EOL ); genericsPrintf( " -h, --help: This help" EOL ); genericsPrintf( " -n, --itm-sync: Enforce sync requirement for ITM (i.e. ITM needsd to issue syncs)" EOL ); - genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to COBS if -s is not set, otherwise ITM unless" EOL \ + genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to OTAG if -s is not set, otherwise ITM unless" EOL \ " explicitly set to TPIU to decode TPIU frames on channel set by -t" EOL ); genericsPrintf( " -s, --server: : to use" EOL ); genericsPrintf( " -S, --sbcolour: to be used for single bit renders, ignored for other bit depths" EOL ); - genericsPrintf( " -t, --tag: : Which TPIU stream or COBS tag to use (normally 1)" EOL ); + genericsPrintf( " -t, --tag: : Which TPIU stream or OTAG tag to use (normally 1)" EOL ); genericsPrintf( " -v, --verbose: Verbose mode 0(errors)..3(debug)" EOL ); genericsPrintf( " -V, --version: Print version and exit" EOL ); genericsPrintf( " -w, --window: Set title for output window" EOL ); @@ -507,6 +508,7 @@ bool _processOptions( int argc, char *argv[], struct RunTime *r ) int c, optionIndex = 0; bool protExplicit = false; bool serverExplicit = false; + bool portExplicit = false; while ( ( c = getopt_long ( argc, argv, "c:Ef:hnp:s:S:t:v:Vw:z:", _longOptions, &optionIndex ) ) != -1 ) switch ( c ) @@ -588,6 +590,10 @@ bool _processOptions( int argc, char *argv[], struct RunTime *r ) { r->options->port = NWCLIENT_SERVER_PORT; } + else + { + portExplicit = true; + } break; @@ -645,12 +651,17 @@ bool _processOptions( int argc, char *argv[], struct RunTime *r ) /* ... and dump the config if we're being verbose */ _printVersion(); - /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not COBS */ + /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not OTAG */ if ( serverExplicit && !protExplicit ) { r->options->protocol = PROT_ITM; } + if ( ( r->options->protocol == PROT_TPIU ) && !portExplicit ) + { + r->options->port = NWCLIENT_SERVER_PORT; + } + genericsReport( V_INFO, "App Channel : Data=%d, Control=%d" EOL, r->app->chan, r->app->chan + 1 ); genericsReport( V_INFO, "SB Colour : 0x%x" EOL, r->app->sbcolour ); genericsReport( V_INFO, "Relative Scale : %1.2f:1" EOL, r->app->scale ); @@ -683,8 +694,8 @@ bool _processOptions( int argc, char *argv[], struct RunTime *r ) switch ( r->options->protocol ) { - case PROT_COBS: - genericsReport( V_INFO, "Decoding COBS (Orbuculum) with ITM in stream %d" EOL, r->options->tag ); + case PROT_OTAG: + genericsReport( V_INFO, "Decoding OTAG (Orbuculum) with ITM in stream %d" EOL, r->options->tag ); break; case PROT_ITM: @@ -702,6 +713,14 @@ bool _processOptions( int argc, char *argv[], struct RunTime *r ) return true; } + +// ==================================================================================================== +static void _intHandler( int sig ) + +{ + /* CTRL-C exit is not an error... */ + _r.ending = true; +} // ==================================================================================================== // ==================================================================================================== // ==================================================================================================== @@ -722,24 +741,30 @@ int main( int argc, char *argv[] ) /* Reset the TPIU handler before we start */ TPIUDecoderInit( &_r.t ); ITMDecoderInit( &_r.i, _r.options->forceITMSync ); - COBSInit( &_r.c ); + OTAGInit( &_r.c ); if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { genericsExit( -1, "Could not initailise SDL" ); } + /* This ensures the signal handler gets called */ + if ( SIG_ERR == signal( SIGINT, _intHandler ) ) + { + genericsExit( -1, "Failed to establish Int handler" EOL ); + } + /* Load up default colour index map R3G3B2 */ for ( int i = 0; i < 256; i++ ) { _r.app->map8to24bit[i] = ( ( i & 0xE0 ) << 21 ) | ( ( i & 0x1c ) << 13 ) | ( i << 6 ); } - while ( true ) + while ( !_r.ending ) { struct Stream *stream = NULL; - while ( true ) + while ( !_r.ending ) { stream = _tryOpenStream( &_r ); @@ -766,7 +791,7 @@ int main( int argc, char *argv[] ) } /* Checking every 100ms for a connection is quite often enough */ - usleep( 10000 ); + usleep( 100000 ); } if ( stream != NULL ) @@ -775,10 +800,10 @@ int main( int argc, char *argv[] ) { break; } - } - stream->close( stream ); - free( stream ); + stream->close( stream ); + free( stream ); + } if ( _r.options->fileTerminate ) { diff --git a/Src/orbmortem.c b/Src/orbmortem.c index c38e140a..e3a9a05f 100644 --- a/Src/orbmortem.c +++ b/Src/orbmortem.c @@ -24,7 +24,7 @@ #include "nw.h" #include "traceDecoder.h" #include "tpiuDecoder.h" -#include "cobs.h" +#include "otag.h" #include "loadelf.h" #include "sio.h" #include "stream.h" @@ -59,12 +59,12 @@ struct Options int buflen; /* Length of post-mortem buffer, in bytes */ int channel; /* When TPIU is in use, which channel to decode? */ - int tag; /* ch TPIU or OTAG stream are we decoding? */ + int tag; /* which TPIU or OTAG stream are we decoding? */ int port; /* Source information */ char *server; - enum Prot protocol; + enum Prot commProt; bool mono; /* Supress colour in output */ - enum TRACEprotocol tProtocol; /* Encoding protocol to use */ + enum TRACEprotocol traceProt; /* Encoding protocol to use */ bool noAltAddr; /* Flag to *not* use alternate addressing */ char *openFileCL; /* Command line for opening refernced file */ @@ -74,7 +74,7 @@ struct Options .port = OTCLIENT_SERVER_PORT, .server = REMOTE_SERVER, .demangle = true, - .tProtocol = TRACE_PROT_ETM35, + .traceProt = TRACE_PROT_ETM35, .tag = 2, .buflen = DEFAULT_PM_BUFLEN_K * 1024 }; @@ -102,7 +102,7 @@ struct RunTime { struct TRACEDecoder i; struct TPIUDecoder t; - struct COBS c; + struct OTAG c; const char *progName; /* Name by which this program was called */ struct symbol *s; /* Symbols read from elf */ @@ -310,9 +310,9 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) case 'P': /* Index through protocol strings looking for match or end of list */ - for ( r->options->tProtocol = TRACE_PROT_LIST_START; - ( ( r->options->tProtocol != TRACE_PROT_NUM ) && strcasecmp( optarg, TRACEDecodeGetProtocolName( r->options->tProtocol ) ) ); - r->options->tProtocol++ ) + for ( r->options->traceProt = TRACE_PROT_LIST_START; + ( ( r->options->traceProt != TRACE_PROT_NUM ) && strcasecmp( optarg, TRACEDecodeGetProtocolName( r->options->traceProt ) ) ); + r->options->traceProt++ ) {} break; @@ -320,19 +320,19 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) // ------------------------------------ case 'p': - r->options->protocol = PROT_UNKNOWN; + r->options->commProt = PROT_UNKNOWN; protExplicit = true; for ( int i = 0; protString[i]; i++ ) { if ( !strcmp( protString[i], optarg ) ) { - r->options->protocol = i; + r->options->commProt = i; break; } } - if ( r->options->protocol == PROT_UNKNOWN ) + if ( r->options->commProt == PROT_UNKNOWN ) { genericsReport( V_ERROR, "Unrecognised protocol type" EOL ); return false; @@ -415,7 +415,7 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) /* If we set an explicit server and port and didn't set a protocol chances are we want TPIU, not OTAG */ if ( serverExplicit && !protExplicit && r->options->port != OTCLIENT_SERVER_PORT ) { - r->options->protocol = PROT_TPIU; + r->options->commProt = PROT_TPIU; genericsReport( V_INFO, "(Auto-set ETM over TPIU for TCP::%s:%d, override by setting protocol explicitly)" EOL, r->options->server, r->options->port ); } @@ -438,16 +438,16 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) genericsReport( V_INFO, "Elf File : %s" EOL, r->options->elffile ); - if ( r->options->tProtocol >= TRACE_PROT_NONE ) + if ( r->options->traceProt >= TRACE_PROT_NONE ) { genericsExit( V_ERROR, "Unrecognised decode protocol" EOL ); } else { - genericsReport( V_INFO, "Protocol : %s" EOL, TRACEDecodeGetProtocolName( r->options->tProtocol ) ); + genericsReport( V_INFO, "Protocol : %s" EOL, TRACEDecodeGetProtocolName( r->options->traceProt ) ); } - if ( ( r->options->tProtocol == TRACE_PROT_MTB ) && ( !r->options->file ) ) + if ( ( r->options->traceProt == TRACE_PROT_MTB ) && ( !r->options->file ) ) { genericsExit( V_ERROR, "MTB only makes sense when input is from a file" EOL ); } @@ -462,7 +462,7 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) genericsExit( -1, "Illegal value for Post Mortem Buffer length" EOL ); } - switch ( r->options->tProtocol ) + switch ( r->options->commProt ) { case PROT_OTAG: genericsReport( V_INFO, "Decoding OTAG with ETM in stream %d" EOL, r->options->tag ); @@ -513,7 +513,7 @@ static void _processBlock( struct RunTime *r ) y = r->rawBlock.fillLevel; #endif - if ( PROT_TPIU == r->options->protocol ) + if ( PROT_TPIU == r->options->commProt ) { struct TPIUPacket p; @@ -612,14 +612,14 @@ static bool _rxAdd( struct RunTime *r, uint8_t c ) // ==================================================================================================== -static void _COBSpacketRxed ( struct Frame *p, void *param ) +static void _OTAGpacketRxed ( struct OTAGFrame *p, void *param ) { struct RunTime *r = ( struct RunTime * )param; - if ( p->d[0] == r->options->tag ) + if ( p->tag == r->options->tag ) { - for ( int i = 1; i < p->len; i++ ) + for ( int i = 0; i < p->len; i++ ) { if ( _rxAdd( r, p->d[i] ) ) { @@ -869,7 +869,7 @@ static void _traceCB( void *d ) /* ============================ */ if ( TRACEStateChanged( &r->i, EV_CH_EX_ENTRY ) ) { - switch ( r->options->protocol ) + switch ( r->options->traceProt ) { case TRACE_PROT_ETM35: _appendToOPBuffer( r, NULL, r->op.currentLine, LT_EVENT, "========== Exception Entry%s (%d (%s) at 0x%08x) ==========", @@ -914,7 +914,7 @@ static void _traceCB( void *d ) /* address reporting is switched on. It will give 'false positives' for uncalculable instructions (e.g. bx lr) but */ /* it's a decent safety net to be sure the jump decoder is working correctly. */ - if ( r->options->tProtocol != TRACE_PROT_MTB ) + if ( r->options->traceProt != TRACE_PROT_MTB ) { _traceReport( V_DEBUG, "%sCommanded CPU Address change (Was:0x%08x Commanded:0x%08x)" EOL, ( r->op.workingAddr == cpu->addr ) ? "" : "***INCONSISTENT*** ", r->op.workingAddr, cpu->addr ); @@ -1423,18 +1423,20 @@ int main( int argc, char *argv[] ) /* Create the buffer memory */ _r.pmBuffer = ( uint8_t * )calloc( 1, _r.options->buflen ); - TRACEDecoderInit( &_r.i, _r.options->tProtocol, !( _r.options->noAltAddr ), _traceReport ); + TRACEDecoderInit( &_r.i, _r.options->traceProt, !( _r.options->noAltAddr ), _traceReport ); - if ( PROT_TPIU == _r.options->protocol ) + if ( PROT_TPIU == _r.options->commProt ) { TPIUDecoderInit( &_r.t ); } + OTAGInit( &_r.c ); + /* Create a screen and interaction handler */ _r.sio = SIOsetup( _r.progName, _r.options->elffile, ( _r.options->file != NULL ) ); /* Put a record of the protocol in use on screen */ - SIOtagText( _r.sio, TRACEDecodeGetProtocolName( _r.options->tProtocol ) ); + SIOtagText( _r.sio, TRACEDecodeGetProtocolName( _r.options->traceProt ) ); while ( !_r.ending ) { @@ -1443,7 +1445,7 @@ int main( int argc, char *argv[] ) /* Keep trying to open a network connection at half second intervals */ while ( 1 ) { - stream = streamCreateSocket( _r.options->server, _r.options->port + ( ( PROT_TPIU == _r.options->protocol ) ? 1 : 0 ) ); + stream = streamCreateSocket( _r.options->server, _r.options->port + ( ( PROT_TPIU == _r.options->commProt ) ? 1 : 0 ) ); if ( stream ) { @@ -1501,9 +1503,9 @@ int main( int argc, char *argv[] ) { /* Pump all of the data through the protocol handler */ - if ( PROT_OTAG == _r.options->protocol ) + if ( PROT_OTAG == _r.options->commProt ) { - COBSPump( &_r.c, _r.rawBlock.buffer, _r.rawBlock.fillLevel, _COBSpacketRxed, &_r ); + OTAGPump( &_r.c, _r.rawBlock.buffer, _r.rawBlock.fillLevel, _OTAGpacketRxed, &_r ); } else { diff --git a/Src/orbprofile.c b/Src/orbprofile.c index 898f1905..ea1516ce 100644 --- a/Src/orbprofile.c +++ b/Src/orbprofile.c @@ -21,7 +21,7 @@ #include "uthash.h" #include "generics.h" #include "traceDecoder.h" -#include "cobs.h" +#include "otag.h" #include "symbols.h" #include "nw.h" #include "ext_fileformats.h" @@ -31,8 +31,8 @@ #define DEFAULT_DURATION_MS (1000) /* Default time to sample, in mS */ #define HANDLE_MASK (0xFFFFFF) /* cachegrind cannot cope with large file handle numbers */ -enum Prot { PROT_COBS, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; -const char *protString[] = {"COBS", "ITM", "TPIU", NULL}; +enum Prot { PROT_OTAG, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; +const char *protString[] = {"OTAG", "ITM", "TPIU", NULL}; /* How many transfer buffers from the source to allocate */ #define NUM_RAW_BLOCKS (1000) @@ -65,12 +65,12 @@ struct Options /* Record for options, either defaults int sampleDuration; /* How long we are going to sample for */ bool mono; /* Supress colour in output */ bool noaltAddr; /* Dont use alternate addressing */ - int tag; /* Which TPIU or COBS stream are we decoding? */ + int tag; /* Which TPIU or OTAG stream are we decoding? */ enum TRACEprotocol tProtocol; /* Encoding protocol to use */ int port; /* Source information for where to connect to */ char *server; - enum Prot protocol; /* What protocol to communicate (default to COBS (== orbuculum)) */ + enum Prot protocol; /* What protocol to communicate (default to OTAG (== orbuculum)) */ } _options = @@ -116,7 +116,7 @@ struct RunTime /* Subsystem data support */ struct TRACEDecoder i; struct SymbolSet *s; /* Symbols read from elf */ - struct COBS c; + struct OTAG c; /* Calls related info */ struct edge *calls; /* Call data table */ @@ -469,9 +469,9 @@ static void _printHelp( const char *const progName ) genericsPrintf( " -M, --no-colour: Supress colour in output" EOL ); genericsPrintf( " -O, --objdump-opts: Options to pass directly to objdump" EOL ); genericsPrintf( " -P, --trace-proto: {ETM35|MTB} trace protocol to use, default is ETM35" EOL ); - genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to COBS if -s is not set, otherwise TPIU" EOL ); + genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to OTAG if -s is not set, otherwise TPIU" EOL ); genericsPrintf( " -s, --server: : to use" EOL ); - genericsPrintf( " -t, --tag: : Which TPIU stream or COBS tag to use (normally 2)" EOL ); + genericsPrintf( " -t, --tag: : Which TPIU stream or OTAG tag to use (normally 2)" EOL ); genericsPrintf( " -T, --all-truncate: truncate -d material off all references (i.e. make output relative)" EOL ); genericsPrintf( " -v, --verbose: Verbose mode 0(errors)..3(debug)" EOL ); genericsPrintf( " -V, --version: Print version and exit" EOL ); @@ -691,7 +691,7 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) // ------------------------------------ } - /* If we set an explicit server and port and didn't set a protocol chances are we want TPIU, not COBS */ + /* If we set an explicit server and port and didn't set a protocol chances are we want TPIU, not OTAG */ if ( serverExplicit && !protExplicit ) { r->options->protocol = PROT_TPIU; @@ -719,14 +719,14 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) genericsReport( V_INFO, "Elf File : %s (%s Names)" EOL, r->options->elffile, r->options->truncateDeleteMaterial ? "Truncate" : "Don't Truncate" ); genericsReport( V_INFO, "Objdump options : %s" EOL, r->options->odoptions ? r->options->odoptions : "None" ); genericsReport( V_INFO, "Protocol : %s" EOL, TRACEDecodeGetProtocolName( r->options->tProtocol ) ); - genericsReport( V_INFO, "Tag (TPIU/COBS) : %d" EOL, r->options->tag ); + genericsReport( V_INFO, "Tag (TPIU/OTAG) : %d" EOL, r->options->tag ); genericsReport( V_INFO, "DOT file : %s" EOL, r->options->dotfile ? r->options->dotfile : "None" ); genericsReport( V_INFO, "Sample Duration : %d mS" EOL, r->options->sampleDuration ); switch ( r->options->protocol ) { - case PROT_COBS: - genericsReport( V_INFO, "Decoding COBS (Orbuculum) with ITM in stream %d" EOL, r->options->tag ); + case PROT_OTAG: + genericsReport( V_INFO, "Decoding OTAG (Orbuculum) with ITM in stream %d" EOL, r->options->tag ); break; case PROT_ITM: @@ -766,12 +766,12 @@ static void _intHandler( int sig ) // ==================================================================================================== -static void _COBSpacketRxed ( struct Frame *p, void *param ) +static void _OTAGpacketRxed ( struct OTAGFrame *p, void *param ) { - if ( p->d[0] == _r.options->tag ) + if ( p->tag == _r.options->tag ) { - TRACEDecoderPump( &_r.i, &( p->d[1] ), p->len - 1, _traceCB, &_r ); + TRACEDecoderPump( &_r.i, p->d, p->len, _traceCB, &_r ); } } // ==================================================================================================== @@ -815,9 +815,9 @@ static void *_processBlocks( void *params ) #endif - if ( PROT_COBS == r->options->protocol ) + if ( PROT_OTAG == r->options->protocol ) { - COBSPump( &_r.c, r->rawBlock[r->rp].buffer, r->rawBlock[r->rp].fillLevel, _COBSpacketRxed, &_r ); + OTAGPump( &_r.c, r->rawBlock[r->rp].buffer, r->rawBlock[r->rp].fillLevel, _OTAGpacketRxed, &_r ); } else { @@ -883,7 +883,7 @@ int main( int argc, char *argv[] ) #endif TRACEDecoderInit( &_r.i, _r.options->tProtocol, !_r.options->noaltAddr, genericsReport ); - COBSInit( &_r.c ); + OTAGInit( &_r.c ); while ( !_r.ending ) { diff --git a/Src/orbstat.c b/Src/orbstat.c index aba4cbc7..1182cff8 100644 --- a/Src/orbstat.c +++ b/Src/orbstat.c @@ -21,7 +21,7 @@ #include "itmDecoder.h" #include "tpiuDecoder.h" #include "msgDecoder.h" -#include "cobs.h" +#include "otag.h" #include "symbols.h" #include "nw.h" #include "ext_fileformats.h" @@ -38,8 +38,8 @@ #define IN_EVENT (0x40000000) #define OUT_EVENT (0x50000000) -enum Prot { PROT_COBS, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; -const char *protString[] = {"COBS", "ITM", "TPIU", NULL}; +enum Prot { PROT_OTAG, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; +const char *protString[] = {"OTAG", "ITM", "TPIU", NULL}; /* States for sample reception state machine */ enum CDState { CD_waitinout, CD_waitsrc, CD_waitdst }; @@ -66,11 +66,11 @@ struct Options /* Record for options, either defaults bool forceITMSync; /* Do we assume ITM starts synced? */ bool mono; /* Supress colour in output */ - uint32_t tag; /* Which TPIU or COBS stream are we decoding? */ + uint32_t tag; /* Which TPIU or OTAG stream are we decoding? */ int port; /* Source information for where to connect to */ char *server; - enum Prot protocol; /* What protocol to communicate (default to COBS (== orbuculum)) */ + enum Prot protocol; /* What protocol to communicate (default to OTAG (== orbuculum)) */ } _options = { @@ -98,7 +98,7 @@ struct RunTime struct ITMPacket h; struct TPIUDecoder t; struct TPIUPacket p; - struct COBS c; + struct OTAG c; struct msg m; /* Decoded message out of ITM layer */ const char *progName; /* Name by which this program was called */ @@ -484,10 +484,10 @@ static void _printHelp( struct RunTime *r ) genericsPrintf( " -n, --itm-sync: Enforce sync requirement for ITM (i.e. ITM needs to issue syncs)" EOL ); genericsPrintf( " -M, --no-colour: Supress colour in output" EOL ); genericsPrintf( " -O, --objdump-opts: Options to pass directly to objdump" EOL ); - genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to COBS if -s is not set, otherwise ITM unless" EOL \ + genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to OTAG if -s is not set, otherwise ITM unless" EOL \ " explicitly set to TPIU to decode TPIU frames on channel set by -t" EOL ); genericsPrintf( " -s, --server: : to use" EOL ); - genericsPrintf( " -t, --tag: : Which TPIU stream or COBS tag to use (normally 1)" EOL ); + genericsPrintf( " -t, --tag: : Which TPIU stream or OTAG tag to use (normally 1)" EOL ); genericsPrintf( " -T, --all-truncate: truncate -d material off all references (i.e. make output relative)" EOL ); genericsPrintf( " -v, --verbose: Verbose mode 0(errors)..3(debug)" EOL ); genericsPrintf( " -V, --version: Print version and exit" EOL ); @@ -534,6 +534,7 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) int c, optionIndex = 0; bool protExplicit = false; bool serverExplicit = false; + bool portExplicit = false; while ( ( c = getopt_long ( argc, argv, "Dd:e:Ef:g:hI:nO:p:s:t:Tv:Vy:z:", _longOptions, &optionIndex ) ) != -1 ) switch ( c ) @@ -645,6 +646,10 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) { r->options->port = NWCLIENT_SERVER_PORT; } + else + { + portExplicit = true; + } break; @@ -699,12 +704,17 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) // ------------------------------------ } - /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not COBS */ + /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not OTAG */ if ( serverExplicit && !protExplicit ) { r->options->protocol = PROT_ITM; } + if ( ( r->options->protocol == PROT_TPIU ) && !portExplicit ) + { + r->options->port = NWCLIENT_SERVER_PORT; + } + if ( !r->options->elffile ) { genericsReport( V_ERROR, "Elf File not specified" EOL ); @@ -728,8 +738,8 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) switch ( r->options->protocol ) { - case PROT_COBS: - genericsReport( V_INFO, "Decoding COBS (Orbuculum) with ITM in stream %d" EOL, r->options->tag ); + case PROT_OTAG: + genericsReport( V_INFO, "Decoding OTAG (Orbuculum) with ITM in stream %d" EOL, r->options->tag ); break; case PROT_ITM: @@ -748,34 +758,23 @@ static bool _processOptions( int argc, char *argv[], struct RunTime *r ) return true; } // ==================================================================================================== -// ==================================================================================================== -static void _doExit( void ) - -/* Perform any explicit exit functions */ - -{ - _r.ending = true; - /* Give them a bit of time, then we're leaving anyway */ - usleep( 200 ); -} -// ==================================================================================================== static void _intHandler( int sig ) /* Catch CTRL-C so things can be cleaned up properly via atexit functions */ { /* CTRL-C exit is not an error... */ - _doExit(); + _r.ending = true; } // ==================================================================================================== -static void _COBSpacketRxed ( struct Frame *p, void *param ) +static void _OTAGpacketRxed ( struct OTAGFrame *p, void *param ) { struct RunTime *r = ( struct RunTime * )param; - if ( p->d[0] == r->options->tag ) + if ( p->tag == r->options->tag ) { - for ( int i = 1; i < p->len; i++ ) + for ( int i = 0; i < p->len; i++ ) { _itmPumpProcess( r, p->d[i] ); } @@ -804,9 +803,6 @@ int main( int argc, char *argv[] ) genericsScreenHandling( !_r.options->mono ); - /* Make sure the fifos get removed at the end */ - atexit( _doExit ); - /* This ensures the atexit gets called */ if ( SIG_ERR == signal( SIGINT, _intHandler ) ) { @@ -826,7 +822,7 @@ int main( int argc, char *argv[] ) /* Reset the TPIU handler before we start */ TPIUDecoderInit( &_r.t ); ITMDecoderInit( &_r.i, _r.options->forceITMSync ); - COBSInit( &_r.c ); + OTAGInit( &_r.c ); while ( !_r.ending ) { @@ -907,9 +903,9 @@ int main( int argc, char *argv[] ) /* ...and record the fact that we received some data */ _r.intervalBytes += _r.rawBlock.fillLevel; - if ( PROT_COBS == _r.options->protocol ) + if ( PROT_OTAG == _r.options->protocol ) { - COBSPump( &_r.c, _r.rawBlock.buffer, _r.rawBlock.fillLevel, _COBSpacketRxed, &_r ); + OTAGPump( &_r.c, _r.rawBlock.buffer, _r.rawBlock.fillLevel, _OTAGpacketRxed, &_r ); } else { diff --git a/Src/orbtop.c b/Src/orbtop.c index 68f7ad38..fae96db1 100644 --- a/Src/orbtop.c +++ b/Src/orbtop.c @@ -24,7 +24,7 @@ #include "generics.h" #include "tpiuDecoder.h" #include "itmDecoder.h" -#include "cobs.h" +#include "otag.h" #include "symbols.h" #include "msgSeq.h" #include "nw.h" @@ -53,8 +53,8 @@ struct reportLine struct nameEntry *n; }; -enum Prot { PROT_COBS, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; -const char *protString[] = {"COBS", "ITM", "TPIU", NULL}; +enum Prot { PROT_OTAG, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; +const char *protString[] = {"OTAG", "ITM", "TPIU", NULL}; struct exceptionRecord /* Record of exception activity */ @@ -77,7 +77,7 @@ struct exceptionRecord /* Record of exception activity */ /* ---------- CONFIGURATION ----------------- */ struct /* Record for options, either defaults or from command line */ { - uint32_t tag; /* Which TPIU or COBS stream are we decoding? */ + uint32_t tag; /* Which TPIU or OTAG stream are we decoding? */ bool reportFilenames; /* Report filenames for each routine? */ bool outputExceptions; /* Set to include exceptions in output flow */ bool forceITMSync; /* Must ITM start synced? */ @@ -102,8 +102,7 @@ struct /* Record for options, either defau int port; /* Source information */ char *server; - enum Prot protocol; /* What protocol to communicate (default to COBS (== orbuculum)) */ - + enum Prot protocol; /* What protocol to communicate (default to OTAG (== orbuculum)) */ } options = { @@ -127,7 +126,7 @@ struct struct ITMPacket h; struct TPIUDecoder t; struct TPIUPacket p; - struct COBS c; + struct OTAG c; enum timeDelay timeStatus; /* Indicator of if this time is exact */ uint64_t timeStamp; /* Latest received time */ struct Frame cobsPart; /* Any part frame that has been received */ @@ -153,6 +152,8 @@ struct uint32_t interrupts; uint32_t sleeps; uint32_t notFound; + bool ending; /* Flag to exit */ + } _r; // ==================================================================================================== @@ -849,7 +850,7 @@ void _itmPumpProcess( uint8_t c ) } /* We are synced timewise, so empty anything that has been waiting */ - while ( 1 ) + while ( true ) { p = MSGSeqGetPacket( &_r.d ); @@ -958,12 +959,12 @@ void _printHelp( const char *const progName ) genericsPrintf( " -n, --itm-sync: Enforce sync requirement for ITM (i.e. ITM needs to issue syncs)" EOL ); genericsPrintf( " -o, --output-file: to be used for output live file" EOL ); genericsPrintf( " -O, --objdump-opts: Options to pass directly to objdump" EOL ); - genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to COBS if -s is not set, otherwise ITM unless" EOL \ + genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to OTAG if -s is not set, otherwise ITM unless" EOL \ " explicitly set to TPIU to decode TPIU frames on channel set by -t" EOL ); genericsPrintf( " -r, --routines: to record in live file (default %d routines)" EOL, options.maxRoutines ); genericsPrintf( " -R, --report-files: Report filenames as part of function discriminator" EOL ); genericsPrintf( " -s, --server: : to use" EOL ); - genericsPrintf( " -t, --tag: Which TPIU stream or COBS tag to use (normally 1)" EOL ); + genericsPrintf( " -t, --tag: Which TPIU stream or OTAG tag to use (normally 1)" EOL ); genericsPrintf( " -v, --verbose: Verbose mode 0(errors)..3(debug)" EOL ); genericsPrintf( " -V, --version: Print version and exit" EOL ); genericsPrintf( EOL "Environment Variables;" EOL ); @@ -1192,7 +1193,7 @@ bool _processOptions( int argc, char *argv[] ) // ------------------------------------ } - /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not COBS */ + /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not OTAG */ if ( serverExplicit && !protExplicit ) { options.protocol = PROT_ITM; @@ -1225,8 +1226,8 @@ bool _processOptions( int argc, char *argv[] ) switch ( options.protocol ) { - case PROT_COBS: - genericsReport( V_INFO, "Decoding COBS (Orbuculum) with ITM in stream %d" EOL, options.tag ); + case PROT_OTAG: + genericsReport( V_INFO, "Decoding OTAG (Orbuculum) with ITM in stream %d" EOL, options.tag ); break; case PROT_ITM: @@ -1246,12 +1247,12 @@ bool _processOptions( int argc, char *argv[] ) } // ==================================================================================================== -static void _COBSpacketRxed ( struct Frame *p, void *param ) +static void _OTAGpacketRxed ( struct OTAGFrame *p, void *param ) { - if ( p->d[0] == options.tag ) + if ( p->tag == options.tag ) { - for ( int i = 1; i < p->len; i++ ) + for ( int i = 0; i < p->len; i++ ) { _itmPumpProcess( p->d[i] ); } @@ -1272,6 +1273,13 @@ static struct Stream *_openStream( void ) } } +// ==================================================================================================== +static void _intHandler( int sig ) + +{ + /* CTRL-C exit is not an error... */ + _r.ending = true; +} // ==================================================================================================== // ==================================================================================================== // ==================================================================================================== @@ -1330,9 +1338,15 @@ int main( int argc, char *argv[] ) /* Reset the TPIU handler before we start */ TPIUDecoderInit( &_r.t ); ITMDecoderInit( &_r.i, options.forceITMSync ); - COBSInit( &_r.c ); + OTAGInit( &_r.c ); MSGSeqInit( &_r.d, &_r.i, MSG_REORDER_BUFLEN ); + /* This ensures the signal handler gets called */ + if ( SIG_ERR == signal( SIGINT, _intHandler ) ) + { + genericsExit( -1, "Failed to establish Int handler" EOL ); + } + /* First interval will be from startup to first packet arriving */ _r.lastReportus = _timestamp(); _r.currentException = NO_EXCEPTION; @@ -1356,7 +1370,7 @@ int main( int argc, char *argv[] ) } } - while ( 1 ) + while ( !_r.ending ) { struct Stream *stream = _openStream(); @@ -1384,7 +1398,7 @@ int main( int argc, char *argv[] ) thisTime = _r.lastReportus = _timestamp(); - while ( 1 ) + while ( !_r.ending ) { remainTime = ( ( _r.lastReportus + options.displayInterval - thisTime ) ); @@ -1452,9 +1466,9 @@ int main( int argc, char *argv[] ) if ( receivedSize ) { - if ( PROT_COBS == options.protocol ) + if ( PROT_OTAG == options.protocol ) { - COBSPump( &_r.c, cbw, receivedSize, _COBSpacketRxed, &_r ); + OTAGPump( &_r.c, cbw, receivedSize, _OTAGpacketRxed, &_r ); } else { @@ -1524,7 +1538,7 @@ int main( int argc, char *argv[] ) free( stream ); } - if ( ( !ITMDecoderGetStats( &_r.i )->tpiuSyncCount ) ) + if ( !_r.ending && ( !ITMDecoderGetStats( &_r.i )->tpiuSyncCount ) ) { genericsReport( V_ERROR, "Read failed" EOL ); } diff --git a/Src/orbzmq.c b/Src/orbzmq.c index cb653bf3..8de551d7 100644 --- a/Src/orbzmq.c +++ b/Src/orbzmq.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "generics.h" #include "git_version_info.h" @@ -17,7 +18,7 @@ #include "tpiuDecoder.h" #include "itmDecoder.h" #include "msgDecoder.h" -#include "cobs.h" +#include "otag.h" #define NUM_CHANNELS 32 #define HWFIFO_NAME "hwevent" @@ -25,8 +26,8 @@ #define DEFAULT_ZMQ_BIND_URL "tcp://*:3442" /* by default bind to all source interfaces */ -enum Prot { PROT_COBS, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; -const char *protString[] = {"COBS", "ITM", "TPIU", NULL}; +enum Prot { PROT_OTAG, PROT_ITM, PROT_TPIU, PROT_UNKNOWN }; +const char *protString[] = {"OTAG", "ITM", "TPIU", NULL}; // Record for options, either defaults or from command line @@ -50,7 +51,7 @@ struct /* Source information */ int port; char *server; - enum Prot protocol; /* What protocol to communicate (default to COBS (== orbuculum)) */ + enum Prot protocol; /* What protocol to communicate (default to OTAG (== orbuculum)) */ bool mono; /* Supress colour in output */ char *file; /* File host connection */ @@ -72,7 +73,7 @@ struct struct ITMPacket h; struct TPIUDecoder t; struct TPIUPacket p; - struct COBS c; + struct OTAG c; /* Timestamp info */ uint64_t lastHWExceptionTS; @@ -81,6 +82,8 @@ struct void *zmqContext; void *zmqSocket; + bool ending; + } _r; // ==================================================================================================== @@ -474,10 +477,10 @@ void _printHelp( const char *const progName ) genericsPrintf( " -h, --help: This help" EOL ); genericsPrintf( " -M, --no-colour: Supress colour in output" EOL ); genericsPrintf( " -n, --itm-sync: Enforce sync requirement for ITM (i.e. ITM needs to issue syncs)" EOL ); - genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to COBS if -s is not set, otherwise ITM unless" EOL \ + genericsPrintf( " -p, --protocol: Protocol to communicate. Defaults to OTAG if -s is not set, otherwise ITM unless" EOL \ " explicitly set to TPIU to decode TPIU frames on channel set by -t" EOL ); genericsPrintf( " -s, --server: : to use, default %s:%d" EOL, options.server, options.port ); - genericsPrintf( " -t, --tag: : Which TPIU stream or COBS tag to use (normally 1)" EOL ); + genericsPrintf( " -t, --tag: : Which TPIU stream or OTAG tag to use (normally 1)" EOL ); genericsPrintf( " -v, --verbose: Verbose mode 0(errors)..3(debug)" EOL ); genericsPrintf( " -V, --version: Print version and exit" EOL ); genericsPrintf( " -z, --zbind: : ZeroMQ bind URL, default %s" EOL, options.bindUrl ); @@ -580,6 +583,7 @@ bool _processOptions( int argc, char *argv[] ) int32_t hwOutputs; bool protExplicit = false; bool serverExplicit = false; + bool portExplicit = false; for ( int g = 0; g < NUM_CHANNELS; g++ ) { @@ -666,6 +670,10 @@ bool _processOptions( int argc, char *argv[] ) { options.port = NWCLIENT_SERVER_PORT; } + else + { + portExplicit = true; + } break; @@ -778,12 +786,17 @@ bool _processOptions( int argc, char *argv[] ) } } - /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not COBS */ + /* If we set an explicit server and port and didn't set a protocol chances are we want ITM, not OTAG */ if ( serverExplicit && !protExplicit ) { options.protocol = PROT_ITM; } + if ( ( options.protocol == PROT_TPIU ) && !portExplicit ) + { + options.port = NWCLIENT_SERVER_PORT; + } + genericsReport( V_INFO, "orbzmq version " GIT_DESCRIBE EOL ); genericsReport( V_INFO, "Server : %s:%d" EOL, options.server, options.port ); genericsReport( V_INFO, "ForceSync : %s" EOL, options.forceITMSync ? "true" : "false" ); @@ -834,8 +847,8 @@ bool _processOptions( int argc, char *argv[] ) switch ( options.protocol ) { - case PROT_COBS: - genericsReport( V_INFO, "Decoding COBS (Orbuculum) with ITM in stream %d" EOL, options.tag ); + case PROT_OTAG: + genericsReport( V_INFO, "Decoding OTAG (Orbuculum) with ITM in stream %d" EOL, options.tag ); break; case PROT_ITM: @@ -869,13 +882,13 @@ static struct Stream *_tryOpenStream() } // ==================================================================================================== -static void _COBSpacketRxed ( struct Frame *p, void *param ) +static void _OTAGpacketRxed ( struct OTAGFrame *p, void *param ) { - if ( p->d[0] == options.tag ) + if ( p->tag == options.tag ) { - for ( int i = 1; i < p->len; i++ ) + for ( int i = 0; i < p->len; i++ ) { _itmPumpProcess( p->d[i] ); } @@ -887,7 +900,7 @@ static void _feedStream( struct Stream *stream ) { unsigned char cbw[TRANSFER_SIZE]; - while ( true ) + while ( !_r.ending ) { size_t receivedSize; enum ReceiveResult result = stream->receive( stream, cbw, TRANSFER_SIZE, NULL, &receivedSize ); @@ -908,9 +921,9 @@ static void _feedStream( struct Stream *stream ) } } - if ( PROT_COBS == options.protocol ) + if ( PROT_OTAG == options.protocol ) { - COBSPump( &_r.c, cbw, receivedSize, _COBSpacketRxed, &_r ); + OTAGPump( &_r.c, cbw, receivedSize, _OTAGpacketRxed, &_r ); } else { @@ -926,6 +939,16 @@ static void _feedStream( struct Stream *stream ) } } +// ==================================================================================================== +static void _intHandler( int sig ) + +{ + /* CTRL-C exit is not an error... */ + _r.ending = true; +} +// ==================================================================================================== +// ==================================================================================================== +// ==================================================================================================== int main( int argc, char *argv[] ) { @@ -945,13 +968,19 @@ int main( int argc, char *argv[] ) /* Reset the TPIU handler before we start */ TPIUDecoderInit( &_r.t ); ITMDecoderInit( &_r.i, options.forceITMSync ); - COBSInit( &_r.c ); + OTAGInit( &_r.c ); - while ( true ) + /* This ensures the signal handler gets called */ + if ( SIG_ERR == signal( SIGINT, _intHandler ) ) + { + genericsExit( -1, "Failed to establish Int handler" EOL ); + } + + while ( !_r.ending ) { struct Stream *stream = NULL; - while ( true ) + while ( !_r.ending ) { stream = _tryOpenStream(); @@ -984,10 +1013,10 @@ int main( int argc, char *argv[] ) if ( stream != NULL ) { _feedStream( stream ); - } - stream->close( stream ); - free( stream ); + stream->close( stream ); + free( stream ); + } if ( options.endTerminate ) {