update watchdog implementation for raspberrypi
This commit is contained in:
parent
0acf2e8c9b
commit
8ff408161a
|
@ -32,38 +32,39 @@
|
|||
|
||||
#include "src/rp2_common/hardware_watchdog/include/hardware/watchdog.h"
|
||||
|
||||
#define WATCHDOG_ENABLE watchdog_enable(self->timeout * 1000, false)
|
||||
|
||||
void common_hal_watchdog_feed(watchdog_watchdogtimer_obj_t *self) {
|
||||
watchdog_update();
|
||||
}
|
||||
|
||||
void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
|
||||
if (self->mode == WATCHDOGMODE_RESET) {
|
||||
mp_raise_RuntimeError(translate("WatchDogTimer cannot be deinitialized once mode is set to RESET"));
|
||||
} else {
|
||||
self->mode = WATCHDOGMODE_NONE;
|
||||
if (self->mode == WATCHDOGMODE_NONE) {
|
||||
return;
|
||||
}
|
||||
hw_clear_bits(&watchdog_hw->ctrl, WATCHDOG_CTRL_ENABLE_BITS);
|
||||
self->mode = WATCHDOGMODE_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
void watchdog_reset(void) {
|
||||
common_hal_watchdog_deinit(&common_hal_mcu_watchdogtimer_obj);
|
||||
common_hal_watchdog_deinit(&common_hal_mcu_watchdogtimer_obj);
|
||||
}
|
||||
*/
|
||||
|
||||
mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {
|
||||
return self->timeout;
|
||||
}
|
||||
|
||||
void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self, mp_float_t new_timeout) {
|
||||
// max timeout is 8.388607 sec
|
||||
// this is rounded down to 8.388 sec
|
||||
uint64_t timeout = new_timeout * 1000;
|
||||
if (timeout > 8388) {
|
||||
mp_raise_ValueError(translate("timeout duration exceeded the maximum supported value"));
|
||||
if (!(self->timeout < new_timeout || self->timeout > new_timeout)) {
|
||||
return;
|
||||
}
|
||||
if ((uint16_t)self->timeout != timeout) {
|
||||
watchdog_enable(timeout, false);
|
||||
self->timeout = new_timeout;
|
||||
|
||||
// max timeout is 8.388607 sec, this is rounded down to 8 sec
|
||||
mp_arg_validate_int_max(new_timeout, 8, MP_QSTR_timeout);
|
||||
self->timeout = new_timeout;
|
||||
|
||||
if (self->mode == WATCHDOGMODE_RESET) {
|
||||
WATCHDOG_ENABLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,12 +73,23 @@ watchdog_watchdogmode_t common_hal_watchdog_get_mode(watchdog_watchdogtimer_obj_
|
|||
}
|
||||
|
||||
void common_hal_watchdog_set_mode(watchdog_watchdogtimer_obj_t *self, watchdog_watchdogmode_t new_mode) {
|
||||
if (self->mode != new_mode) {
|
||||
if (new_mode == WATCHDOGMODE_RAISE) {
|
||||
mp_raise_NotImplementedError(translate("RAISE mode is not implemented"));
|
||||
} else if (new_mode == WATCHDOGMODE_NONE) {
|
||||
common_hal_watchdog_deinit(self);
|
||||
}
|
||||
self->mode = new_mode;
|
||||
if (self->mode == new_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (new_mode) {
|
||||
case WATCHDOGMODE_NONE:
|
||||
common_hal_watchdog_deinit(self);
|
||||
break;
|
||||
case WATCHDOGMODE_RAISE:
|
||||
mp_raise_NotImplementedError(NULL);
|
||||
break;
|
||||
case WATCHDOGMODE_RESET:
|
||||
WATCHDOG_ENABLE;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
self->mode = new_mode;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,6 @@ struct _watchdog_watchdogtimer_obj_t {
|
|||
};
|
||||
|
||||
// This needs to be called in order to disable the watchdog
|
||||
// void watchdog_reset(void);
|
||||
void watchdog_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H
|
||||
|
|
|
@ -201,6 +201,10 @@ void reset_port(void) {
|
|||
ssl_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_WATCHDOG
|
||||
watchdog_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_WIFI
|
||||
wifi_reset();
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue