Skip to content

Commit

Permalink
Add support for TPIU encoded orbflow channel 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mubes committed Aug 25, 2024
1 parent 89ed9e8 commit 9c6e7ce
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Src/oflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ static void _pumpcb( struct Frame *p, void *param )
}

void OFLOWPump( struct OFLOW *t, const uint8_t *incoming, int len,
void ( *packetRxed )( struct OFLOWFrame *p, void *param ),
void *param )
void ( *packetRxed )( struct OFLOWFrame *p, void *param ),
void *param )


/* Assemble this packet into a complete frame and call back */
Expand Down
72 changes: 41 additions & 31 deletions Src/orbuculum.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ bool _processOptions( int argc, char *argv[], struct RunTime *r )
case 'm':
r->options->intervalReportTime = atoi( optarg );

if ( r->options->intervalReportTime<100 )
if ( r->options->intervalReportTime < 100 )
{
genericsReport( V_ERROR, "intervalReportTime is out of range" EOL );
return false;
Expand Down Expand Up @@ -759,7 +759,7 @@ void _checkInterval( void *params )

if ( tnow - r->tagCount[i].ts < LAST_TAG_SEEN_TIME_NS )
{
if ( !r->tagCount[i].hasHandler )
if ( ( !r->tagCount[i].hasHandler ) && r->options->useTPIU )
{
genericsPrintf( C_NOCHAN" [%d:" "%3d%%] " C_RESET, i, w / 10 );
}
Expand Down Expand Up @@ -828,8 +828,6 @@ static void _purgeBlock( struct RunTime *r, bool createOFLOW )

h++;
}

_checkInterval( r );
}
// ====================================================================================================
static void _TPIUpacketRxed( enum TPIUPumpEvent e, struct TPIUPacket *p, void *param )
Expand Down Expand Up @@ -913,6 +911,12 @@ static void _OFLOWpacketRxed( struct OFLOWFrame *p, void *param )
{
genericsReport( V_WARN, "Bad packet received" EOL );
}
else if ( ( r->options->useTPIU ) && ( h->channel == DEFAULT_ITM_STREAM ) )
{
/* Deal with the bizzare combination of OFLOW and TPIU in channel 1 */
/* Accounting will be done in TPIUPump2 */
TPIUPump2( &r->t, p->d, p->len, _TPIUpacketRxed, r );
}
else
{
/* Account for this reception */
Expand Down Expand Up @@ -981,8 +985,8 @@ static void _processNonOFLOWBlock( struct RunTime *r, ssize_t fillLevel, uint8_t
while ( fillLevel )
{
OFLOWEncode( DEFAULT_ITM_STREAM, 0, b,
( fillLevel < OFLOW_MAX_PACKET_LEN ) ? fillLevel : OFLOW_MAX_PACKET_LEN,
&oflowOtg );
( fillLevel < OFLOW_MAX_PACKET_LEN ) ? fillLevel : OFLOW_MAX_PACKET_LEN,
&oflowOtg );
nwclientSend( r->oflowHandler, oflowOtg.len, oflowOtg.d );
b += ( fillLevel < OFLOW_MAX_PACKET_LEN ) ? fillLevel : OFLOW_MAX_PACKET_LEN;
fillLevel -= ( fillLevel < OFLOW_MAX_PACKET_LEN ) ? fillLevel : OFLOW_MAX_PACKET_LEN;
Expand All @@ -996,36 +1000,45 @@ static void _handleBlock( struct RunTime *r, ssize_t fillLevel, uint8_t *buffer
/* Handle an incoming block from any source in either 'conventional' or orbflow format */

{
genericsReport( V_DEBUG, "RXED Packet of %d bytes%s" EOL, fillLevel, ( r->options->intervalReportTime ) ? EOL : "" );

if ( r->opFileHandle )
if ( fillLevel )
{
if ( write( r->opFileHandle, buffer, fillLevel ) <= 0 )
genericsReport( V_DEBUG, "RXED Packet of %d bytes%s" EOL, fillLevel, ( r->options->intervalReportTime ) ? EOL : "" );

if ( r->opFileHandle )
{
genericsExit( -3, "Writing to file failed" EOL );
if ( write( r->opFileHandle, buffer, fillLevel ) <= 0 )
{
genericsExit( -3, "Writing to file failed" EOL );
}
}
}

if ( r->usingOFLOW )
{
if ( r->options->intervalReportTime )
if ( r->usingOFLOW )
{
/* We need to decode this so we can get the stats out of it .. we don't bother if we don't need stats */
OFLOWPump( &r->oflow, buffer, fillLevel, _OFLOWpacketRxed, r );
if ( r->options->intervalReportTime )
{
/* We need to decode this so we can get the stats out of it .. we don't bother if we don't need stats */
OFLOWPump( &r->oflow, buffer, fillLevel, _OFLOWpacketRxed, r );
}

/* ...and reflect this packet to the outgoing OFLOW channels, if we don't need to reconstruct them */
if ( !r->options->useTPIU )
{
nwclientSend( r->oflowHandler, fillLevel, buffer );
}
}
else
{
_processNonOFLOWBlock( r, fillLevel, buffer );
}

/* ...and reflect this packet to the outgoing OFLOW channels */
nwclientSend( r->oflowHandler, fillLevel, buffer );
}
else
{
_processNonOFLOWBlock( r, fillLevel, buffer );
}
r->intervalRawBytes += fillLevel;

r->intervalRawBytes += fillLevel;
/* Send the block to clients, but only send OFLOW if it wasn't OFLOW already */
/* or if we're decoding TPIU in the default tag */
_purgeBlock( r, ( !r->usingOFLOW ) || r->options->useTPIU );
}

/* Send the block to clients, but only send OFLOW if it wasn't OFLOW already */
_purgeBlock( r, !r->usingOFLOW );
_checkInterval( r );
}

// ====================================================================================================
Expand All @@ -1037,10 +1050,7 @@ static void _usb_callback( struct libusb_transfer *t )

{
/* Whatever the status that comes back, there may be data... */
if ( t->actual_length > 0 )
{
_handleBlock( &_r, t->actual_length, t->buffer );
}
_handleBlock( &_r, t->actual_length, t->buffer );

if ( ( t->status != LIBUSB_TRANSFER_COMPLETED ) &&
( t->status != LIBUSB_TRANSFER_TIMED_OUT ) &&
Expand Down
1 change: 1 addition & 0 deletions Support/gdbtrace.init
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ end
# ====================================================================

define stopETM
_setAddressesETM4
if (((*$TRCDEVARCH)&0xfff0ffff) ==0x47704a13)
set *($TRCPRGCTLR) &= ~(1<<0)
while ((*$TRCSTATR)&(1<<0)==0)
Expand Down

0 comments on commit 9c6e7ce

Please sign in to comment.