Watchdog timer, boot reason tracking, net_poll frame limit, reboot/picoboot CLI commands

This commit is contained in:
Ian Gulliver
2026-04-12 08:27:21 +09:00
parent 6c3e0757f9
commit 21c7900444
7 changed files with 25 additions and 9 deletions

View File

@@ -15,5 +15,6 @@ static constexpr handler_entry handlers[] = {
int main() { int main() {
handlers_init(); handlers_init();
dispatch_init(); dispatch_init();
handlers_start();
dispatch_run(handlers); dispatch_run(handlers);
} }

View File

@@ -7,6 +7,7 @@
extern std::string_view firmware_name; extern std::string_view firmware_name;
void handlers_init(); void handlers_init();
void handlers_start();
std::optional<ResponsePICOBOOT> handle_picoboot(const responder& resp, const RequestPICOBOOT&); std::optional<ResponsePICOBOOT> handle_picoboot(const responder& resp, const RequestPICOBOOT&);
std::optional<ResponseInfo> handle_info(const responder& resp, const RequestInfo&); std::optional<ResponseInfo> handle_info(const responder& resp, const RequestInfo&);
std::optional<ResponseLog> handle_log(const responder& resp, const RequestLog&); std::optional<ResponseLog> handle_log(const responder& resp, const RequestLog&);

View File

@@ -47,6 +47,7 @@ struct RequestInfo {
enum class boot_reason : uint8_t { enum class boot_reason : uint8_t {
cold_boot = 0, cold_boot = 0,
request_reboot = 1, request_reboot = 1,
watchdog = 2,
}; };
struct ResponseInfo { struct ResponseInfo {

View File

@@ -9,16 +9,25 @@
static constexpr uint32_t XIP_BASE_ADDR = 0x10000000; static constexpr uint32_t XIP_BASE_ADDR = 0x10000000;
static constexpr uint32_t FLASH_SIZE = 2 * 1024 * 1024; static constexpr uint32_t FLASH_SIZE = 2 * 1024 * 1024;
static constexpr uint32_t REBOOT_MAGIC = 0x504D5242;
static boot_reason detected_boot_reason; static boot_reason detected_boot_reason;
static void poke_watchdog() {
watchdog_update();
dispatch_schedule_ms(500, poke_watchdog);
}
void handlers_init() { void handlers_init() {
if (watchdog_hw->scratch[0] == REBOOT_MAGIC) auto val = static_cast<boot_reason>(watchdog_hw->scratch[0]);
detected_boot_reason = boot_reason::request_reboot; if (val == boot_reason::request_reboot || val == boot_reason::watchdog)
detected_boot_reason = val;
else else
detected_boot_reason = boot_reason::cold_boot; detected_boot_reason = boot_reason::cold_boot;
watchdog_hw->scratch[0] = 0; watchdog_hw->scratch[0] = static_cast<uint32_t>(boot_reason::watchdog);
watchdog_enable(1000, true);
}
void handlers_start() {
poke_watchdog();
} }
std::optional<ResponsePICOBOOT> handle_picoboot(const responder&, const RequestPICOBOOT&) { std::optional<ResponsePICOBOOT> handle_picoboot(const responder&, const RequestPICOBOOT&) {
@@ -80,7 +89,7 @@ std::optional<ResponseFlashWrite> handle_flash_write(const responder&, const Req
std::optional<ResponseReboot> handle_reboot(const responder&, const RequestReboot&) { std::optional<ResponseReboot> handle_reboot(const responder&, const RequestReboot&) {
dispatch_schedule_ms(100, []{ dispatch_schedule_ms(100, []{
watchdog_hw->scratch[0] = REBOOT_MAGIC; watchdog_hw->scratch[0] = static_cast<uint32_t>(boot_reason::request_reboot);
watchdog_reboot(0, 0, 0); watchdog_reboot(0, 0, 0);
}); });
return ResponseReboot{}; return ResponseReboot{};

View File

@@ -140,7 +140,7 @@ void net_poll(std::span<uint8_t> tx) {
w6300::irq_pending = false; w6300::irq_pending = false;
w6300::clear_interrupt(w6300::ik_int_all); w6300::clear_interrupt(w6300::ik_int_all);
static uint8_t rx_buf[1518]; static uint8_t rx_buf[1518];
while (w6300::get_socket_recv_buf(raw_socket) > 0) { for (int i = 0; i < 16 && w6300::get_socket_recv_buf(raw_socket) > 0; i++) {
auto result = w6300::recv(raw_socket, std::span{rx_buf}); auto result = w6300::recv(raw_socket, std::span{rx_buf});
if (!result) break; if (!result) break;
span_writer tx_writer(tx); span_writer tx_writer(tx);

View File

@@ -27,6 +27,7 @@ static constexpr handler_entry handlers[] = {
int main() { int main() {
handlers_init(); handlers_init();
dispatch_init(); dispatch_init();
handlers_start();
gpio_init(LED_PIN); gpio_init(LED_PIN);
gpio_set_dir(LED_PIN, GPIO_OUT); gpio_set_dir(LED_PIN, GPIO_OUT);

View File

@@ -11,6 +11,7 @@ type BootReason uint8
const ( const (
BootCold BootReason = 0 BootCold BootReason = 0
BootReboot BootReason = 1 BootReboot BootReason = 1
BootWatchdog BootReason = 2
) )
func (b BootReason) String() string { func (b BootReason) String() string {
@@ -19,6 +20,8 @@ func (b BootReason) String() string {
return "cold" return "cold"
case BootReboot: case BootReboot:
return "reboot" return "reboot"
case BootWatchdog:
return "watchdog"
default: default:
return "unknown" return "unknown"
} }