|
| 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 | +}; |
0 commit comments