From 015774a04faa50708ce3692dc3748989e19e98e9 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 3 Sep 2016 20:45:11 +0300 Subject: [PATCH] esp8266/modmachinewdt: Add .deinit() method. --- esp8266/esp_mphal.c | 4 ---- esp8266/etshal.h | 3 +++ esp8266/modmachinewdt.c | 11 ++++++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index 06049e3956..dc6944fd4c 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -36,10 +36,6 @@ #include "extmod/misc.h" #include "lib/utils/pyexec.h" -extern void ets_wdt_disable(void); -extern void wdt_feed(void); -extern void ets_delay_us(); - STATIC byte input_buf_array[256]; ringbuf_t input_buf = {input_buf_array, sizeof(input_buf_array)}; void mp_hal_debug_tx_strn_cooked(void *env, const char *str, uint32_t len); diff --git a/esp8266/etshal.h b/esp8266/etshal.h index dd61ddec93..e7326a43ba 100644 --- a/esp8266/etshal.h +++ b/esp8266/etshal.h @@ -20,6 +20,9 @@ void ets_timer_arm_new(os_timer_t *tim, uint32_t millis, bool repeat, bool is_mi void ets_timer_setfn(os_timer_t *tim, ETSTimerFunc callback, void *cb_data); void ets_timer_disarm(os_timer_t *tim); +extern void ets_wdt_disable(void); +extern void wdt_feed(void); + // Opaque structure typedef char MD5_CTX[64]; diff --git a/esp8266/modmachinewdt.c b/esp8266/modmachinewdt.c index e0b1ff5d78..6dc4c0d18c 100644 --- a/esp8266/modmachinewdt.c +++ b/esp8266/modmachinewdt.c @@ -31,6 +31,7 @@ #include "py/obj.h" #include "py/runtime.h" #include "user_interface.h" +#include "etshal.h" const mp_obj_type_t esp_wdt_type; @@ -63,8 +64,16 @@ STATIC mp_obj_t machine_wdt_feed(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_feed_obj, machine_wdt_feed); +STATIC mp_obj_t machine_wdt_deinit(mp_obj_t self_in) { + (void)self_in; + ets_wdt_disable(); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_deinit_obj, machine_wdt_deinit); + STATIC const mp_map_elem_t machine_wdt_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&machine_wdt_feed_obj } + { MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&machine_wdt_feed_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_deinit), (mp_obj_t)&machine_wdt_deinit_obj }, }; STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table);