Skip to content

Commit

Permalink
#81: directly enable the ISR on HWCDC restart if connected
Browse files Browse the repository at this point in the history
andreas committed Nov 4, 2024
1 parent 041b550 commit 1d5577a
Showing 2 changed files with 36 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/serial/GwSerial.h
Original file line number Diff line number Diff line change
@@ -4,6 +4,9 @@
#include "GwLog.h"
#include "GwBuffer.h"
#include "GwChannelInterface.h"
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
#include "hal/usb_serial_jtag_ll.h"
#endif

#define USBCDC_RESTART_TIME 100
class GwSerialStream;
@@ -77,7 +80,7 @@ template<typename T>
* workaround for the HWCDC beeing stuck at some point in time
* with availableForWrite == 0 but the ISR being disabled
* we simply give a small delay of 100ms for availableForWrite being 0
* and afterwards call isConnected that seems to retrigger the ISR
* and afterwards retrigger the ISR
*/
int availableForWrite(HWCDC* c){
int rt=c->availableForWrite();
@@ -88,8 +91,10 @@ template<typename T>
unsigned long now=millis();
if (now > (lastWritable+USBCDC_RESTART_TIME)){
lastWritable=now;
LOG_ERROR("***Restart USBCDC***");
c->isConnected(); //this seems to retrigger the ISR
if (c->isConnected()){
//this retriggers the ISR
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
}
}
return rt;
}
28 changes: 28 additions & 0 deletions tools/log.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /usr/bin/env perl
use strict;
use POSIX qw(strftime);
my ($dev,$speed)=@ARGV;
if (not defined $dev){
die "usage: $0 dev"
}
if (! -e $dev) {
die "$dev not found"
}
open(my $fh,"<",$dev) or die "unable to open $dev";
if (defined $speed){
print("setting speed $speed");
system("stty speed $speed < $dev") == 0 or die "unable to set speed";
}
my $last=0;
while (<$fh>){
my $x=time();
if ($last != 0){
if ($x > ($last+5)){
print("****gap***\n");
}
}
printf strftime("%Y/%m/%d-%H%M%S",localtime($x));
printf("[%04.2f]: ",$x-$last);
$last=$x;
print $_;
}

0 comments on commit 1d5577a

Please sign in to comment.