8000 esp8266/modmachinewdt: Implement machine.WDT class. · danni/micropython@263aaa7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 263aaa7

Browse files
committed
esp8266/modmachinewdt: Implement machine.WDT class.
1 parent 8f8f699 commit 263aaa7

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

esp8266/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ SRC_C = \
7878
modpybrtc.c \
7979
modpybadc.c \
8080
modpybuart.c \
81+
modmachinewdt.c \
8182
modmachinespi.c \
8283
modpybspi.c \
8384
modpybhspi.c \

esp8266/modmachine.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
//#define MACHINE_WAKE_SLEEP (0x02)
5050
#define MACHINE_WAKE_DEEPSLEEP (0x04)
5151

52+
extern const mp_obj_type_t esp_wdt_type;
53+
5254
STATIC mp_obj_t machine_freq(mp_uint_t n_args, const mp_obj_t *args) {
5355
if (n_args == 0) {
5456
// get
@@ -246,6 +248,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
246248

247249
{ MP_ROM_QSTR(MP_QSTR_RTC), MP_ROM_PTR(&pyb_rtc_type) },
248250
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&esp_timer_type) },
251+
{ MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&esp_wdt_type) },
249252
{ MP_ROM_QSTR(MP_QSTR_Pin), MP_ROM_PTR(&pyb_pin_type) },
250253
{ MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_PTR(&pyb_pwm_type) },
251254
{ MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&pyb_adc_type) },

esp8266/modmachinewdt.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 <stdio.h>
28+
#include <string.h>
29+
30+
#include "py/nlr.h"
31+
#include "py/obj.h"
32+
#include "py/runtime.h"
33+
#include "user_interface.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, mp_uint_t n_args, mp_uint_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+
system_soft_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 const mp_map_elem_t machine_wdt_locals_dict_table[] = {
67+
{ MP_OBJ_NEW_QSTR(MP_QSTR_feed), (mp_obj_t)&machine_wdt_feed_obj }
68+
};
69+
STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table);
70+
71+
const mp_obj_type_t esp_wdt_type = {
72+
{ &mp_type_type },
73+
.name = MP_QSTR_WDT,
74+
.make_new = machine_wdt_make_new,
75+
.locals_dict = (mp_obj_t)&machine_wdt_locals_dict,
76+
};

0 commit comments

Comments
 (0)
0