8000 esp32: Implement machine.WDT() class. · micropython/micropython-esp32@1a7c852 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 1a7c852

Browse files
MrSurlydpgeorge
authored andcommitted
esp32: Implement machine.WDT() class.
1 parent 3362cbb commit 1a7c852

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

ports/esp32/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ SRC_C = \
141141
moduhashlib.c \
142142
espneopixel.c \
143143
machine_hw_spi.c \
144+
machine_wdt.c \
144145
mpthreadport.c \
145146
$(SRC_MOD)
146147

ports/esp32/machine_wdt.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2016 Paul Sokolovsky
7+
* Copyright (c) 2017 Eric Poulsen
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#include <string.h>
29+
30+
#include "py/nlr.h"
31+
#include "py/obj.h"
32+
#include "py/runtime.h"
33+
34+
#include "esp_task_wdt.h"
35+
36+
const mp_obj_type_t machine_wdt_type;
37+
38+
typedef struct _machine_wdt_obj_t {
39+
mp_obj_base_t base;
40+
} machine_wdt_obj_t;
41+
42+
STATIC machine_wdt_obj_t wdt_default = {{&machine_wdt_type}};
43+
44+
STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
45+
mp_arg_check_num(n_args, n_kw, 0, 1, false);
46+
47+
mp_int_t id = 0;
48+
if (n_args > 0) {
49+
id = mp_obj_get_int(args[0]);
50+
}
51+
52+
switch (id) {
53+
case 0:
54+
esp_task_wdt_feed();
55+
return &wdt_default;
56+
default:
57+
mp_raise_ValueError(NULL);
58+
}
59+
}
60+
61+
STATIC mp_obj_t machine_wdt_feed(mp_obj_t self_in) {
62+
(void)self_in;
63+
esp_task_wdt_feed();
64+
return mp_const_none;
65+
}
66+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_feed_obj, machine_wdt_feed);
67+
68+
STATIC const mp_map_elem_t machine_wdt_locals_dict_table[] = {
69+
{ MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&machine_wdt_feed_obj },
70+
};
71+
STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table);
72+
73+
const mp_obj_type_t machine_wdt_type = {
74+
{ &mp_type_type },
75+
.name = MP_QSTR_WDT,
76+
.make_new = machine_wdt_make_new,
77+
.locals_dict = (mp_obj_t)&machine_wdt_locals_dict,
78+
};

ports/esp32/modmachine.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
114114
{ MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) },
115115

116116
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) },
117+
{ MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) },
117118
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
118119
{ MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) },
119120
{ MP_ROM_QSTR(MP_QSTR_TouchPad), MP_ROM_PTR(&machine_touchpad_type) },

ports/esp32/modmachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "py/obj.h"
55

66
extern const mp_obj_type_t machine_timer_type;
7+
extern const mp_obj_type_t machine_wdt_type;
78
extern const mp_obj_type_t machine_pin_type;
89
extern const mp_obj_type_t machine_touchpad_type;
910
extern const mp_obj_type_t machine_adc_type;

ports/esp32/sdkconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#define CONFIG_INT_WDT_TIMEOUT_MS 300
4646
#define CONFIG_INT_WDT_CHECK_CPU1 0
4747
#define CONFIG_TASK_WDT 1
48+
#define CONFIG_TASK_WDT_PANIC 1
4849
#define CONFIG_TASK_WDT_TIMEOUT_S 5
4950
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK 0
5051
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 0

0 commit comments

Comments
 (0)
0