Skip to content

Commit cd95d3d

Browse files
committed
esp32/Makefile: Implement machine.WDT()
esp32/machine_wdt.c: Implement machine.WDT() esp32/modmachine.c: Implement machine.WDT() esp32/modmachine.h: Implement machine.WDT() esp32/sdkconfig.h: Implement machine.WDT()
1 parent 51642d7 commit cd95d3d

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

esp32/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ SRC_C = \
129129
modesp.c \
130130
espneopixel.c \
131131
machine_hw_spi.c \
132+
machine_wdt.c \
132133
mpthreadport.c \
133134
$(SRC_MOD)
134135

esp32/machine_wdt.c

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

esp32/modmachine.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
113113

114114
{ MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) },
115115

116+
{ MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&esp_wdt_type) },
116117
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&machine_pin_type) },
117118
{ MP_ROM_QSTR(MP_QSTR_TouchPad), MP_ROM_PTR(&machine_touchpad_type) },
118119
{ MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&machine_adc_type) },

esp32/modmachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern const mp_obj_type_t machine_touchpad_type;
88
extern const mp_obj_type_t machine_adc_type;
99
extern const mp_obj_type_t machine_dac_type;
1010
extern const mp_obj_type_t machine_hw_spi_type;
11+
extern const mp_obj_type_t esp_wdt_type;
1112

1213
void machine_pins_init(void);
1314
void machine_pins_deinit(void);

esp32/sdkconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define CONFIG_INT_WDT_TIMEOUT_MS 300
4141
#define CONFIG_INT_WDT_CHECK_CPU1 0
4242
#define CONFIG_TASK_WDT 1
43+
#define CONFIG_TASK_WDT_PANIC 1
4344
#define CONFIG_TASK_WDT_TIMEOUT_S 5
4445
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK 0
4546
#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy