Skip to content

Commit

Permalink
Move from COBS to OTAG
Browse files Browse the repository at this point in the history
  • Loading branch information
mubes committed Jun 16, 2024
1 parent cf8676f commit 7761f26
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 189 deletions.
4 changes: 2 additions & 2 deletions Inc/itmfifos.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "tpiuDecoder.h"
#include "itmDecoder.h"
#include "cobs.h"
#include "otag.h"

#include "generics.h"

Expand All @@ -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 */
Expand Down
21 changes: 10 additions & 11 deletions Src/itmfifos.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 */

Expand All @@ -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 */
};
Expand Down Expand Up @@ -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] );
}
Expand Down Expand Up @@ -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-- )
Expand Down Expand Up @@ -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 */
Expand Down
28 changes: 21 additions & 7 deletions Src/orbcat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <inttypes.h>
#include <getopt.h>
#include <time.h>
#include <signal.h>

#include "nw.h"
#include "git_version_info.h"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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[] )

Expand All @@ -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();

Expand Down Expand Up @@ -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 )
{
Expand Down
56 changes: 40 additions & 16 deletions Src/orbdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
#include <ctype.h>
#include <stdio.h>
#include <getopt.h>
#include <signal.h>

#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"

Expand All @@ -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 ----------------- */

Expand Down Expand Up @@ -71,7 +72,8 @@ struct
struct ITMPacket h;
struct TPIUDecoder t;
struct TPIUPacket p;
struct COBS c;
struct OTAG c;
bool ending;
} _r;

// ====================================================================================================
Expand Down Expand Up @@ -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: <filename> 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: <Server>:<Port> to use" EOL );
genericsPrintf( " -t, --tag: <stream> Which TPIU stream or COBS tag to use (normally 1)" EOL );
genericsPrintf( " -t, --tag: <stream> Which TPIU stream or OTAG tag to use (normally 1)" EOL );
genericsPrintf( " -v, --verbose: <level> 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 );
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -289,6 +292,10 @@ bool _processOptions( int argc, char *argv[] )
{
options.port = NWCLIENT_SERVER_PORT;
}
else
{
portExplicit = true;
}

break;

Expand Down Expand Up @@ -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" );
Expand All @@ -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:
Expand All @@ -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] );
}
Expand All @@ -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[] )
{
Expand All @@ -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 );
Expand All @@ -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 );

Expand All @@ -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
{
Expand Down
Loading

0 comments on commit 7761f26

Please sign in to comment.