Skip to content

Commit

Permalink
Move log output to second core
Browse files Browse the repository at this point in the history
Outputting the log over serial was taking too long and usually
two packets were missed.

Moving it to the second core free the first core to capture all
packets.

There could be a race condition with the logging between the two cores,
a mutex has been added but hasn't been used.
  • Loading branch information
morio committed Dec 6, 2023
1 parent c575b63 commit e79ac69
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/sniffer/lib/QuokkADB/include/log_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ inline void dbgmsg(Params... params)
log_raw("\r\n");
}
}

void log_init();
void log_poll();
7 changes: 7 additions & 0 deletions src/sniffer/lib/QuokkADB/src/log_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include "log_cache.h"
#include <stdarg.h>
#include <pico/stdio.h>
#include <pico/mutex.h>

static mutex log_mutex;
// This memory buffer can be read by debugger and is also saved to zululog.txt
#define LOGBUFMASK (LOGBUFSIZE - 1)

Expand Down Expand Up @@ -117,6 +119,11 @@ void log_raw(bytearray array)
}
}

void log_init()
{
mutex_init(&log_mutex);
}

uint32_t log_get_buffer_len()
{
return g_logpos;
Expand Down
9 changes: 7 additions & 2 deletions src/sniffer/lib/QuokkADB/src/quokkadb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ ADBKbdRptParser KeyboardPrs;
ADBMouseRptParser MousePrs(KeyboardPrs);
FlashSettings setting_storage;

void initVariant()
{
log_init();
logmsg("---- Cache Logging Initialized ----");
}

/*------------ Core0 setup ------------*/
void setup()
{
Expand Down Expand Up @@ -104,7 +110,6 @@ void loop()
usb_reset = true;
Logmsg.println("ALL: Resetting devices");
}
log_poll();
}


Expand All @@ -118,5 +123,5 @@ void setup1()
/*------------ Core1 main loop ------------*/
void loop1()
{

log_poll();
}
13 changes: 9 additions & 4 deletions src/sniffer/lib/adb/include/adb.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <log_cache.h>

#ifndef ADB_START_BIT_DELAY
#define ADB_START_BIT_DELAY 100000
#define ADB_START_BIT_DELAY 20000
#endif

#define KBD_DEFAULT_ADDR 0x02
Expand Down Expand Up @@ -205,11 +205,16 @@ inline int32_t AdbInterface::Snoop16bitRegister(void)

// stop bit
low_time = wait_data_hi(130);
if (!low_time || low_time > 70)
{
if (!low_time || low_time < 40 )
{
logmsg("---- Error: No stop bit. Low time (us): ", low_time);
return -4;
}

else if(low_time < 70)
{
logmsg("---- Stop bit");
}
logmsg("---- End 16 bit snoop");
return data;
out:
return -5;
Expand Down

0 comments on commit e79ac69

Please sign in to comment.