reset watchdog conditionally

This commit is contained in:
MicroDev 2023-03-15 19:03:57 +05:30
parent 8ff408161a
commit 11cf031284
No known key found for this signature in database
GPG Key ID: 2C0867BE60967730
6 changed files with 66 additions and 8 deletions

6
main.c
View File

@ -243,6 +243,12 @@ void supervisor_execution_status(void) {
}
#endif
#if CIRCUITPY_WATCHDOG
pyexec_result_t *pyexec_result(void) {
return &_exec_result;
}
#endif
// Look for the first file that exists in the list of filenames, using mp_import_stat().
// Return its index. If no file found, return -1.
STATIC const char *first_existing_file_in_list(const char *const *filenames, size_t n_filenames) {

View File

@ -28,8 +28,12 @@
#include "py/runtime.h"
#include "shared/runtime/pyexec.h"
#include "shared-bindings/watchdog/__init__.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "common-hal/watchdog/WatchDogTimer.h"
#include "component/wdt.h"
@ -79,7 +83,16 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
}
void watchdog_reset(void) {
common_hal_watchdog_deinit(&common_hal_mcu_watchdogtimer_obj);
watchdog_watchdogtimer_obj_t *self = &common_hal_mcu_watchdogtimer_obj;
if (self->mode == WATCHDOGMODE_RESET) {
mp_obj_t exception = pyexec_result()->exception;
if (exception != MP_OBJ_NULL &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
return;
}
}
common_hal_watchdog_deinit(self);
}
mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {

View File

@ -25,11 +25,14 @@
*/
#include "py/runtime.h"
#include "common-hal/watchdog/WatchDogTimer.h"
#include "shared/runtime/pyexec.h"
#include "shared-bindings/watchdog/__init__.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "common-hal/watchdog/WatchDogTimer.h"
#include "esp_task_wdt.h"
extern void esp_task_wdt_isr_user_handler(void);
@ -66,7 +69,16 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
}
void watchdog_reset(void) {
common_hal_watchdog_deinit(&common_hal_mcu_watchdogtimer_obj);
watchdog_watchdogtimer_obj_t *self = &common_hal_mcu_watchdogtimer_obj;
if (self->mode == WATCHDOGMODE_RESET) {
mp_obj_t exception = pyexec_result()->exception;
if (exception != MP_OBJ_NULL &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
return;
}
}
common_hal_watchdog_deinit(self);
}
static void wdt_config(uint32_t timeout, watchdog_watchdogmode_t mode) {

View File

@ -33,12 +33,14 @@
#include "py/objproperty.h"
#include "py/runtime.h"
#include "common-hal/watchdog/WatchDogTimer.h"
#include "shared/runtime/pyexec.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/watchdog/__init__.h"
#include "shared-bindings/watchdog/WatchDogTimer.h"
#include "common-hal/watchdog/WatchDogTimer.h"
#include "supervisor/port.h"
#include "nrf/timers.h"
@ -108,7 +110,16 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
}
void watchdog_reset(void) {
common_hal_watchdog_deinit(&common_hal_mcu_watchdogtimer_obj);
watchdog_watchdogtimer_obj_t *self = &common_hal_mcu_watchdogtimer_obj;
if (self->mode == WATCHDOGMODE_RESET) {
mp_obj_t exception = pyexec_result()->exception;
if (exception != MP_OBJ_NULL &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
return;
}
}
common_hal_watchdog_deinit(self);
}
mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {

View File

@ -25,12 +25,15 @@
*/
#include "py/runtime.h"
#include "common-hal/watchdog/WatchDogTimer.h"
#include "shared/runtime/pyexec.h"
#include "shared-bindings/watchdog/__init__.h"
#include "shared-bindings/microcontroller/__init__.h"
#include "src/rp2_common/hardware_watchdog/include/hardware/watchdog.h"
#include "common-hal/watchdog/WatchDogTimer.h"
#include "hardware/watchdog.h"
#define WATCHDOG_ENABLE watchdog_enable(self->timeout * 1000, false)
@ -47,7 +50,16 @@ void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) {
}
void watchdog_reset(void) {
common_hal_watchdog_deinit(&common_hal_mcu_watchdogtimer_obj);
watchdog_watchdogtimer_obj_t *self = &common_hal_mcu_watchdogtimer_obj;
if (self->mode == WATCHDOGMODE_RESET) {
mp_obj_t exception = pyexec_result()->exception;
if (exception != MP_OBJ_NULL &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception)) &&
exception != MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception))) {
return;
}
}
common_hal_watchdog_deinit(self);
}
mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) {

View File

@ -67,6 +67,10 @@ extern uint8_t pyexec_repl_active;
int pyexec_exit_handler(const void *source, pyexec_result_t *result);
#endif
#if CIRCUITPY_WATCHDOG
pyexec_result_t *pyexec_result(void);
#endif
#if MICROPY_REPL_INFO
mp_obj_t pyb_set_repl_info(mp_obj_t o_value);
MP_DECLARE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj);