machine_wdt.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <string.h>
  28. #include "py/nlr.h"
  29. #include "py/obj.h"
  30. #include "py/runtime.h"
  31. #include "esp_task_wdt.h"
  32. const mp_obj_type_t machine_wdt_type;
  33. typedef struct _machine_wdt_obj_t {
  34. mp_obj_base_t base;
  35. } machine_wdt_obj_t;
  36. STATIC machine_wdt_obj_t wdt_default = {{&machine_wdt_type}};
  37. 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) {
  38. mp_arg_check_num(n_args, n_kw, 0, 1, false);
  39. mp_int_t id = 0;
  40. if (n_args > 0) {
  41. id = mp_obj_get_int(args[0]);
  42. }
  43. switch (id) {
  44. case 0:
  45. esp_task_wdt_add(NULL);
  46. return &wdt_default;
  47. default:
  48. mp_raise_ValueError(NULL);
  49. }
  50. }
  51. STATIC mp_obj_t machine_wdt_feed(mp_obj_t self_in) {
  52. (void)self_in;
  53. esp_task_wdt_reset();
  54. return mp_const_none;
  55. }
  56. STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_wdt_feed_obj, machine_wdt_feed);
  57. STATIC const mp_rom_map_elem_t machine_wdt_locals_dict_table[] = {
  58. { MP_ROM_QSTR(MP_QSTR_feed), MP_ROM_PTR(&machine_wdt_feed_obj) },
  59. };
  60. STATIC MP_DEFINE_CONST_DICT(machine_wdt_locals_dict, machine_wdt_locals_dict_table);
  61. const mp_obj_type_t machine_wdt_type = {
  62. { &mp_type_type },
  63. .name = MP_QSTR_WDT,
  64. .make_new = machine_wdt_make_new,
  65. .locals_dict = (mp_obj_t)&machine_wdt_locals_dict,
  66. };