diff options
author | Marc Zyngier <maz@kernel.org> | 2024-04-17 20:27:18 +0100 |
---|---|---|
committer | Marc Zyngier <maz@kernel.org> | 2024-04-17 20:43:47 +0100 |
commit | 7baed05fabdbb38bb7d0380f75ed5a6eb5d7c634 (patch) | |
tree | 2a9807daefa2e0fa5faffe9e3fb08ee003f8f90b | |
parent | a234634e22658a7d6c24e78990bff4f644c03e96 (diff) | |
download | cs-sw-master.tar.gz |
Although CS has been pretty reliable for me, I recently experienced
a lockup in the middle of a remote debugging session. And I really
mean *very* remote, without a living (or dead) soul able to pull
the plug on the damn thing.
So while I know there is an annoying bug hiding somewhere, I also
think the device should be able to get back to a sane state on its
own.
So let's add a watchdog and a timer. The timer kicks the watchdog
every second, and the watchdog will reset the pico after 5s without
kicking. To test the feature, there is a "^\" command available
in debug mode that will crash the CS, leading to a reset after 5s.
The default conserver configuration is to reconnect after a minute,
which seems to be good enough for my use cases. Other console SW
probably have something similar.
Signed-off-by: Marc Zyngier <maz@kernel.org>
-rw-r--r-- | README | 5 | ||||
-rw-r--r-- | vdmtool.c | 28 |
2 files changed, 30 insertions, 3 deletions
@@ -241,12 +241,15 @@ which is completely self explainatory, but let's expand on it anyway: That's a debug feature... - ^_ 1 Configure the Mac's serial on Primary USB pins. On v3+, this - also isolates the micro-USb connector. On older versions, it + also isolates the micro-USB connector. On older versions, it doesn't, so make sure you don't have anything plugged there. - ^_ 2 Configure the Mac's serial on SBU pins, which is the default. On v3+, this enables the use of the micro-USB connector. +- ^_ ^\ crashes the Central Scrutinizer when in debug mode. This + allows testing the watchdog reset functionnality. + - ^_ ? prints the help message (duh). Finally, the Port 0:/1: lines indicate which I2C/UART combinations the @@ -446,9 +446,11 @@ static void help(struct vdm_context *cxt) "^_ 2 Serial on SBU pins\n"); if (upstream_is_serial()) - cprintf_cont(cxt, "^_ ^@ Send break\n"); + cprintf_cont(cxt, "^_ ^@ Send break\n"); if (PORT(cxt) == 0 && !vdm_contexts[1].hw) - cprintf_cont(cxt, "^_ ^U Switch upstream port USB/Serial\n"); + cprintf_cont(cxt, "^_ ^U Switch upstream port USB/Serial\n"); + if (cxt->verbose) + cprintf_cont(cxt, "^_ ^\\ Crash me now\n"); cprintf_cont(cxt, "^_ ? This message\n"); for (int i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) { @@ -550,6 +552,12 @@ static bool serial_handler(struct vdm_context *cxt) cxt->pending = true; evt_disconnect(cxt); break; + case 0x1c: /* ^\ */ + if (cxt->verbose) { + void (*crashme)(void) = NULL - 1; + crashme(); + } + break; case '?': help(cxt); break; @@ -716,6 +724,18 @@ static bool m1_pd_bmc_run_one(struct vdm_context *cxt) return serial_handler(cxt) || cxt->pending; } +/* A tick every second, watchdog fires after 5s */ +#define WDT_PERIOD_MS (5 * 1000) +#define TICK_PERIOD_MS (1 * 1000) +#define TICK_PERIOD_US (TICK_PERIOD_MS * 1000) + +static int64_t tick_cb(alarm_id_t id, void *arg) +{ + watchdog_update(); + + return TICK_PERIOD_US; +} + #define for_each_cxt(___c) \ for (struct vdm_context *___c = &vdm_contexts[0]; \ (___c - vdm_contexts) < CONFIG_USB_PD_PORT_COUNT; \ @@ -724,6 +744,10 @@ static bool m1_pd_bmc_run_one(struct vdm_context *cxt) void m1_pd_bmc_run(void) { + watchdog_enable(WDT_PERIOD_MS, 1); + + add_alarm_in_ms(TICK_PERIOD_MS, tick_cb, NULL, true); + while (1) { bool busy = false; |