Skip to content

Commit 4e8fe9d

Browse files
committed
Fix usb data loss due to packet timeout
1 parent 5a3e774 commit 4e8fe9d

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

Inc/nw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern "C" {
1818
// ====================================================================================================
1919

2020
#define NWCLIENT_SERVER_PORT (3443) /* Server port definition */
21-
#define TRANSFER_SIZE (65536)
21+
#define TRANSFER_SIZE (256000)
2222

2323
// ====================================================================================================
2424

Src/orbmortem.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define MAX_TAGS (10) /* How many tags we will allow */
3636

3737
#define INTERVAL_TIME_MS (1000) /* Intervaltime between acculumator resets */
38-
#define HANG_TIME_MS (990) /* Time without a packet after which we dump the buffer */
38+
#define HANG_TIME_MS (200) /* Time without a packet after which we dump the buffer */
3939
#define TICK_TIME_MS (100) /* Time intervals for screen updates and keypress check */
4040

4141
/* Record for options, either defaults or from command line */
@@ -696,16 +696,16 @@ static void _dumpBuffer( struct RunTime *r )
696696
/* Pump the received messages through the ETM decoder, it will callback to _etmCB with complete sentences */
697697
int bytesAvailable = ( ( r->wp + r->options->buflen ) - r->rp ) % r->options->buflen;
698698

699-
/* If we've started wrapping (i.e. the rx ring buffer is full) then any guesses about sync status are invalid */
700-
if ( bytesAvailable == r->options->buflen - 1 )
699+
/* If we started wrapping (i.e. the rx ring buffer got full) then any guesses about sync status are invalid */
700+
if ( ( bytesAvailable == r->options->buflen - 1 ) && ( !r->singleShot ) )
701701
{
702702
ETMDecoderForceSync( &r->i, false );
703703
}
704704

705705
if ( ( bytesAvailable + r->rp ) > r->options->buflen )
706706
{
707707
/* Buffer is wrapped - submit both parts */
708-
ETMDecoderPump( &r->i, &r->pmBuffer[r->rp], r->options->buflen - r->rp, _etmCB, _etmReport, r );
708+
ETMDecoderPump( &r->i, &r->pmBuffer[r->rp], r->options->buflen - r->rp - 1, _etmCB, _etmReport, r );
709709
ETMDecoderPump( &r->i, &r->pmBuffer[0], r->rp, _etmCB, _etmReport, r );
710710
}
711711
else

Src/orbuculum.c

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ static const struct deviceList
6969
//#define DUMP_BLOCK
7070

7171
/* How many transfer buffers from the source to allocate */
72-
#define NUM_RAW_BLOCKS (10)
72+
#define NUM_RAW_BLOCKS (3)
7373

7474
/* What time spread to defer them over (less than orbmortem timeout) */
75-
#define BLOCK_TOTAL_SPREAD (400)
75+
#define BLOCK_TOTAL_SPREAD (100)
7676

7777
/* Interval between blocks for timeouts */
7878
#define BLOCK_TIMEOUT_INTERVAL_MS (BLOCK_TOTAL_SPREAD/NUM_RAW_BLOCKS)
@@ -247,6 +247,16 @@ static int _setSerialConfig ( int f, speed_t speed )
247247
}
248248
#endif
249249
// ====================================================================================================
250+
static void _doExit( void )
251+
252+
{
253+
_r.ending = true;
254+
255+
nwclientShutdown( _r.n );
256+
/* Give them a bit of time, then we're leaving anyway */
257+
usleep( 200 );
258+
}
259+
// ====================================================================================================
250260
void _printHelp( char *progName )
251261

252262
{
@@ -499,12 +509,14 @@ void *_checkInterval( void *params )
499509
{
500510
struct TPIUCommsStats *c = TPIUGetCommsStats( &r->t );
501511

512+
/* For now we don't transmit this...
502513
genericsPrintf( C_RESET " LEDS: %s%s%s%s" C_RESET " Frames: "C_DATA "%u" C_RESET,
503514
c->leds & 1 ? C_DATA_IND "d" : C_RESET "-",
504515
c->leds & 2 ? C_TX_IND "t" : C_RESET "-",
505516
c->leds & 0x20 ? C_OVF_IND "O" : C_RESET "-",
506517
c->leds & 0x80 ? C_HB_IND "h" : C_RESET "-",
507518
c->totalFrames );
519+
*/
508520

509521
genericsReport( V_INFO, " Pending:%5d Lost:%5d",
510522
c->pendingCount,
@@ -671,7 +683,8 @@ static void _usb_callback( struct libusb_transfer *t )
671683
/* For the USB case the ringbuffer isn't used .. packets are sent directly from this callback */
672684

673685
{
674-
if ( t->status == LIBUSB_TRANSFER_COMPLETED && ( t->actual_length > 0 ) )
686+
/* Whatever the status that comes back, there may be data... */
687+
if ( t->actual_length > 0 )
675688
{
676689
_r.intervalBytes += t->actual_length;
677690

@@ -821,12 +834,24 @@ int usbFeeder( struct RunTime *r )
821834
BLOCK_TIMEOUT_INTERVAL_MS * ( t + 1 )
822835
);
823836

824-
libusb_submit_transfer( r->rawBlock[t].usbtfr );
837+
int ret = libusb_submit_transfer( r->rawBlock[t].usbtfr );
838+
839+
if ( ret )
840+
{
841+
genericsReport( V_ERROR, "Error submitting USB requests %d" EOL, ret );
842+
_doExit();
843+
}
825844
}
826845

827846
while ( !r->ending )
828847
{
829-
libusb_handle_events_completed( NULL, ( int * )&r->ending );
848+
int ret = libusb_handle_events_completed( NULL, ( int * )&r->ending );
849+
850+
if ( ret )
851+
{
852+
genericsReport( V_ERROR, "Error waiting for USB requests to complete %d" EOL, ret );
853+
_doExit();
854+
}
830855
}
831856

832857
libusb_close( handle );
@@ -1013,16 +1038,6 @@ int fileFeeder( struct RunTime *r )
10131038
return true;
10141039
}
10151040
// ====================================================================================================
1016-
static void _doExit( void )
1017-
1018-
{
1019-
_r.ending = true;
1020-
1021-
nwclientShutdown( _r.n );
1022-
/* Give them a bit of time, then we're leaving anyway */
1023-
usleep( 200 );
1024-
}
1025-
// ====================================================================================================
10261041
int main( int argc, char *argv[] )
10271042

10281043
{

0 commit comments

Comments
 (0)