nrf: machine: Add mechanism to starve the watchdog
A soft reset doesn't reconfigure the watchdog which means if previous software on the device has set a bad timeout then we are stuck without until the battery runs flat or a watchdog reset takes place. Add a mechanism to stop feeding the dog so that we can wait for it to trigger. Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>wasp-os
parent
9d5e23fc71
commit
89f48aca20
|
@ -28,8 +28,11 @@
|
||||||
|
|
||||||
#if MICROPY_PY_MACHINE_WDT
|
#if MICROPY_PY_MACHINE_WDT
|
||||||
|
|
||||||
|
#include "wdt.h"
|
||||||
#include "nrf_wdt.h"
|
#include "nrf_wdt.h"
|
||||||
|
|
||||||
|
bool wdt_starve;
|
||||||
|
|
||||||
#if MICROPY_HW_HAS_WDT_BUTTON
|
#if MICROPY_HW_HAS_WDT_BUTTON
|
||||||
static void button_init(void)
|
static void button_init(void)
|
||||||
{
|
{
|
||||||
|
@ -85,11 +88,17 @@ void wdt_feed(bool isr)
|
||||||
* implementing a (reasonably robust) long-press reset button.
|
* implementing a (reasonably robust) long-press reset button.
|
||||||
*/
|
*/
|
||||||
#if MICROPY_HW_HAS_WDT_BUTTON
|
#if MICROPY_HW_HAS_WDT_BUTTON
|
||||||
if (!button_pressed())
|
if (button_pressed())
|
||||||
|
return;
|
||||||
#else
|
#else
|
||||||
if (!isr)
|
if (isr)
|
||||||
|
return;
|
||||||
#endif
|
#endif
|
||||||
nrf_wdt_reload_request_set(0);
|
|
||||||
|
if (wdt_starve)
|
||||||
|
return;
|
||||||
|
|
||||||
|
nrf_wdt_reload_request_set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MICROPY_PY_MACHINE_WDT
|
#endif // MICROPY_PY_MACHINE_WDT
|
||||||
|
|
|
@ -25,7 +25,12 @@
|
||||||
#ifndef __MICROPY_INCLUDED_LIB_WDT_H__
|
#ifndef __MICROPY_INCLUDED_LIB_WDT_H__
|
||||||
#define __MICROPY_INCLUDED_LIB_WDT_H__
|
#define __MICROPY_INCLUDED_LIB_WDT_H__
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
extern bool wdt_starve;
|
||||||
|
|
||||||
void wdt_init(void);
|
void wdt_init(void);
|
||||||
void wdt_feed(bool isr);
|
void wdt_feed(bool isr);
|
||||||
|
|
||||||
|
|
||||||
#endif // __MICROPY_INCLUDED_LIB_WDT_H__
|
#endif // __MICROPY_INCLUDED_LIB_WDT_H__
|
||||||
|
|
|
@ -54,6 +54,9 @@
|
||||||
#if MICROPY_PY_MACHINE_RTCOUNTER
|
#if MICROPY_PY_MACHINE_RTCOUNTER
|
||||||
#include "rtcounter.h"
|
#include "rtcounter.h"
|
||||||
#endif
|
#endif
|
||||||
|
#if MICROPY_PY_MACHINE_WDT
|
||||||
|
#include "wdt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PYB_RESET_HARD (0)
|
#define PYB_RESET_HARD (0)
|
||||||
#define PYB_RESET_WDT (1)
|
#define PYB_RESET_WDT (1)
|
||||||
|
@ -163,6 +166,14 @@ STATIC mp_obj_t machine_enter_serial_dfu(void) {
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_enter_serial_dfu_obj, machine_enter_serial_dfu);
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_enter_serial_dfu_obj, machine_enter_serial_dfu);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_PY_MACHINE_WDT
|
||||||
|
STATIC mp_obj_t machine_starve_wdt(void) {
|
||||||
|
wdt_starve = true;
|
||||||
|
return mp_const_none;
|
||||||
|
}
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_starve_wdt_obj, machine_starve_wdt);
|
||||||
|
#endif
|
||||||
|
|
||||||
STATIC mp_obj_t machine_soft_reset(void) {
|
STATIC mp_obj_t machine_soft_reset(void) {
|
||||||
pyexec_system_exit = PYEXEC_FORCED_EXIT;
|
pyexec_system_exit = PYEXEC_FORCED_EXIT;
|
||||||
nlr_raise(mp_obj_new_exception(&mp_type_SystemExit));
|
nlr_raise(mp_obj_new_exception(&mp_type_SystemExit));
|
||||||
|
@ -214,6 +225,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
|
||||||
#if MICROPY_PY_MACHINE_DFU_BOOTLOADER
|
#if MICROPY_PY_MACHINE_DFU_BOOTLOADER
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enter_ota_dfu), MP_ROM_PTR(&machine_enter_ota_dfu_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_enter_ota_dfu), MP_ROM_PTR(&machine_enter_ota_dfu_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enter_serial_dfu), MP_ROM_PTR(&machine_enter_serial_dfu_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_enter_serial_dfu), MP_ROM_PTR(&machine_enter_serial_dfu_obj) },
|
||||||
|
#endif
|
||||||
|
#if MICROPY_PY_MACHINE_WDT
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_starve_wdt), MP_ROM_PTR(&machine_starve_wdt_obj) },
|
||||||
#endif
|
#endif
|
||||||
{ MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) },
|
||||||
|
|
Loading…
Reference in New Issue