Watchdog timer, boot reason tracking, net_poll frame limit, reboot/picoboot CLI commands
This commit is contained in:
@@ -15,5 +15,6 @@ static constexpr handler_entry handlers[] = {
|
||||
int main() {
|
||||
handlers_init();
|
||||
dispatch_init();
|
||||
handlers_start();
|
||||
dispatch_run(handlers);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
extern std::string_view firmware_name;
|
||||
|
||||
void handlers_init();
|
||||
void handlers_start();
|
||||
std::optional<ResponsePICOBOOT> handle_picoboot(const responder& resp, const RequestPICOBOOT&);
|
||||
std::optional<ResponseInfo> handle_info(const responder& resp, const RequestInfo&);
|
||||
std::optional<ResponseLog> handle_log(const responder& resp, const RequestLog&);
|
||||
|
||||
@@ -47,6 +47,7 @@ struct RequestInfo {
|
||||
enum class boot_reason : uint8_t {
|
||||
cold_boot = 0,
|
||||
request_reboot = 1,
|
||||
watchdog = 2,
|
||||
};
|
||||
|
||||
struct ResponseInfo {
|
||||
|
||||
@@ -9,16 +9,25 @@
|
||||
|
||||
static constexpr uint32_t XIP_BASE_ADDR = 0x10000000;
|
||||
static constexpr uint32_t FLASH_SIZE = 2 * 1024 * 1024;
|
||||
static constexpr uint32_t REBOOT_MAGIC = 0x504D5242;
|
||||
|
||||
static boot_reason detected_boot_reason;
|
||||
|
||||
static void poke_watchdog() {
|
||||
watchdog_update();
|
||||
dispatch_schedule_ms(500, poke_watchdog);
|
||||
}
|
||||
|
||||
void handlers_init() {
|
||||
if (watchdog_hw->scratch[0] == REBOOT_MAGIC)
|
||||
detected_boot_reason = boot_reason::request_reboot;
|
||||
auto val = static_cast<boot_reason>(watchdog_hw->scratch[0]);
|
||||
if (val == boot_reason::request_reboot || val == boot_reason::watchdog)
|
||||
detected_boot_reason = val;
|
||||
else
|
||||
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&) {
|
||||
@@ -80,7 +89,7 @@ std::optional<ResponseFlashWrite> handle_flash_write(const responder&, const Req
|
||||
|
||||
std::optional<ResponseReboot> handle_reboot(const responder&, const RequestReboot&) {
|
||||
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);
|
||||
});
|
||||
return ResponseReboot{};
|
||||
|
||||
@@ -140,7 +140,7 @@ void net_poll(std::span<uint8_t> tx) {
|
||||
w6300::irq_pending = false;
|
||||
w6300::clear_interrupt(w6300::ik_int_all);
|
||||
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});
|
||||
if (!result) break;
|
||||
span_writer tx_writer(tx);
|
||||
|
||||
@@ -27,6 +27,7 @@ static constexpr handler_entry handlers[] = {
|
||||
int main() {
|
||||
handlers_init();
|
||||
dispatch_init();
|
||||
handlers_start();
|
||||
|
||||
gpio_init(LED_PIN);
|
||||
gpio_set_dir(LED_PIN, GPIO_OUT);
|
||||
|
||||
Reference in New Issue
Block a user