2020-05-20 08:08:07 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Paul Sokolovsky
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "py/runtime.h"
|
2020-05-21 01:47:23 -04:00
|
|
|
#include "shared-bindings/watchdog/__init__.h"
|
2020-05-22 00:35:29 -04:00
|
|
|
#include "shared-bindings/watchdog/WatchDogMode.h"
|
2020-05-20 08:08:07 -04:00
|
|
|
|
|
|
|
//| """Watchdog Timer
|
|
|
|
//|
|
2020-05-21 01:47:23 -04:00
|
|
|
//| The `watchdog` module provides support for a Watchdog Timer. This timer will reset the device
|
2020-05-20 08:08:07 -04:00
|
|
|
//| if it hasn't been fed after a specified amount of time. This is useful to ensure the board
|
2020-05-27 13:58:21 -04:00
|
|
|
//| has not crashed or locked up. Note that on some platforms the watchdog timer cannot be disabled
|
|
|
|
//| once it has been enabled.
|
2020-05-20 08:08:07 -04:00
|
|
|
//|
|
2020-05-27 13:58:21 -04:00
|
|
|
//| The `WatchDogTimer` is used to restart the system when the application crashes and ends
|
2020-05-20 08:08:07 -04:00
|
|
|
//| up into a non recoverable state. Once started it cannot be stopped or
|
|
|
|
//| reconfigured in any way. After enabling, the application must "feed" the
|
|
|
|
//| watchdog periodically to prevent it from expiring and resetting the system.
|
|
|
|
//|
|
|
|
|
//| Example usage::
|
|
|
|
//|
|
2020-05-22 00:35:29 -04:00
|
|
|
//| from microcontroller import watchdog as w
|
|
|
|
//| from watchdog import WatchDogMode
|
|
|
|
//| w.timeout=2.5 # Set a timeout of 2.5 seconds
|
|
|
|
//| w.mode = WatchDogMode.RAISE
|
|
|
|
//| w.feed()"""
|
2023-02-01 03:08:41 -05:00
|
|
|
//|
|
2022-04-29 13:41:22 -04:00
|
|
|
|
|
|
|
//| class WatchDogTimeout(Exception):
|
|
|
|
//| """Exception raised when the watchdog timer is set to
|
|
|
|
//| ``WatchDogMode.RAISE`` and expires.
|
|
|
|
//|
|
|
|
|
//| Example::
|
|
|
|
//|
|
|
|
|
//| import microcontroller
|
|
|
|
//| import watchdog
|
|
|
|
//| import time
|
|
|
|
//|
|
|
|
|
//| wdt = microcontroller.watchdog
|
|
|
|
//| wdt.timeout = 5
|
|
|
|
//|
|
|
|
|
//| while True:
|
|
|
|
//| wdt.mode = watchdog.WatchDogMode.RAISE
|
|
|
|
//| print("Starting loop -- should exit after five seconds")
|
|
|
|
//| try:
|
|
|
|
//| while True:
|
|
|
|
//| time.sleep(10) # Also works with pass
|
|
|
|
//| except watchdog.WatchDogTimeout as e:
|
|
|
|
//| print("Watchdog expired")
|
|
|
|
//| except Exception as e:
|
|
|
|
//| print("Other exception")
|
2020-05-20 08:08:07 -04:00
|
|
|
//|
|
2022-04-29 13:41:22 -04:00
|
|
|
//| print("Exited loop")
|
|
|
|
//| """
|
2022-09-29 20:22:32 -04:00
|
|
|
//|
|
2020-05-22 00:35:29 -04:00
|
|
|
|
2023-09-19 21:09:29 -04:00
|
|
|
MP_DEFINE_CONST_OBJ_TYPE(
|
|
|
|
mp_type_WatchDogTimeout,
|
|
|
|
MP_QSTR_WatchDogTimeout,
|
|
|
|
MP_TYPE_FLAG_NONE,
|
|
|
|
make_new, mp_obj_exception_make_new,
|
|
|
|
attr, mp_obj_exception_attr,
|
|
|
|
parent, &mp_type_Exception
|
|
|
|
);
|
2020-05-22 06:52:21 -04:00
|
|
|
|
|
|
|
mp_obj_exception_t mp_watchdog_timeout_exception = {
|
|
|
|
.base.type = &mp_type_WatchDogTimeout,
|
2021-03-15 09:57:36 -04:00
|
|
|
.args = (mp_obj_tuple_t *)&mp_const_empty_tuple_obj,
|
2021-08-02 02:30:48 -04:00
|
|
|
.traceback = (mp_obj_traceback_t *)&mp_const_empty_traceback_obj,
|
2020-05-22 06:52:21 -04:00
|
|
|
};
|
|
|
|
|
2020-05-22 00:35:29 -04:00
|
|
|
STATIC const mp_rom_map_elem_t watchdog_module_globals_table[] = {
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_watchdog) },
|
|
|
|
{ MP_ROM_QSTR(MP_QSTR_WatchDogMode), MP_ROM_PTR(&watchdog_watchdogmode_type) },
|
2020-05-26 22:21:43 -04:00
|
|
|
{ MP_ROM_QSTR(MP_QSTR_WatchDogTimeout), MP_ROM_PTR(&mp_type_WatchDogTimeout) },
|
2020-05-22 00:35:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
STATIC MP_DEFINE_CONST_DICT(watchdog_module_globals, watchdog_module_globals_table);
|
|
|
|
|
|
|
|
const mp_obj_module_t watchdog_module = {
|
|
|
|
.base = { &mp_type_module },
|
2021-03-15 09:57:36 -04:00
|
|
|
.globals = (mp_obj_dict_t *)&watchdog_module_globals,
|
2020-05-22 00:35:29 -04:00
|
|
|
};
|
Convert more modules to use MP_REGISTER_MODULE
Convert _eve, _pew, aesio, alarm, audiopwmio, bitops, camera, canio, dualbank, gnss, i2cperipheral, imagecapture, ipaddress, memorymonitor, sdioio, socketpool, ssl, uheap, ustack, watchdog, and wifi modules to use MP_REGISTER_MODULE.
Related to #5183.
2021-09-01 00:12:00 -04:00
|
|
|
|
2023-08-07 20:45:57 -04:00
|
|
|
MP_REGISTER_MODULE(MP_QSTR_watchdog, watchdog_module);
|