Add timing to hw ping, reduce sleep to 1ms in WaitForResponse, no impact on CPU

This commit is contained in:
Philippe Teuwen 2023-10-20 00:33:58 +02:00
commit b9ae38f888
2 changed files with 10 additions and 3 deletions

View file

@ -35,6 +35,7 @@
#include "pmflash.h" // rdv40validation_t #include "pmflash.h" // rdv40validation_t
#include "cmdflashmem.h" // get_signature.. #include "cmdflashmem.h" // get_signature..
#include "uart/uart.h" // configure timeout #include "uart/uart.h" // configure timeout
#include "util_posix.h"
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
@ -979,6 +980,7 @@ static int CmdPing(const char *Cmd) {
arg_u64_0("l", "len", "<dec>", "length of payload to send"), arg_u64_0("l", "len", "<dec>", "length of payload to send"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, true); CLIExecWithReturn(ctx, Cmd, argtable, true);
uint32_t len = arg_get_u32_def(ctx, 1, 32); uint32_t len = arg_get_u32_def(ctx, 1, 32);
CLIParserFree(ctx); CLIParserFree(ctx);
@ -1000,13 +1002,18 @@ static int CmdPing(const char *Cmd) {
data[i] = i & 0xFF; data[i] = i & 0xFF;
} }
uint64_t tms = msclock();
SendCommandNG(CMD_PING, data, len); SendCommandNG(CMD_PING, data, len);
if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) { if (WaitForResponseTimeout(CMD_PING, &resp, 1000)) {
tms = msclock() - tms;
if (len) { if (len) {
bool error = (memcmp(data, resp.data.asBytes, len) != 0); bool error = (memcmp(data, resp.data.asBytes, len) != 0);
PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received") " and content ( %s )", error ? _RED_("fail") : _GREEN_("ok")); PrintAndLogEx((error) ? ERR : SUCCESS, "Ping response " _GREEN_("received")
" in " _YELLOW_("%" PRIu64) " ms and content ( %s )",
tms, error ? _RED_("fail") : _GREEN_("ok"));
} else { } else {
PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received")); PrintAndLogEx(SUCCESS, "Ping response " _GREEN_("received")
" in " _YELLOW_("%" PRIu64) " ms", tms);
} }
} else } else
PrintAndLogEx(WARNING, "Ping response " _RED_("timeout")); PrintAndLogEx(WARNING, "Ping response " _RED_("timeout"));

View file

@ -802,7 +802,7 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms
show_warning = false; show_warning = false;
} }
// just to avoid CPU busy loop: // just to avoid CPU busy loop:
msleep(10); msleep(1);
} }
return false; return false;
} }