1+ /*
2+ * This file is a part of: https://github.com/brilliantlabsAR/frame-codebase
3+ *
4+ * Authored by: Raj Nakarja / Brilliant Labs Ltd. (raj@brilliant.xyz)
5+ * Rohit Rathnam / Silicon Witchery AB (rohit@siliconwitchery.com)
6+ * Uma S. Gupta / Techno Exponent (umasankar@technoexponent.com)
7+ *
8+ * ISC Licence
9+ *
10+ * Copyright © 2023 Brilliant Labs Ltd.
11+ *
12+ * Permission to use, copy, modify, and/or distribute this software for any
13+ * purpose with or without fee is hereby granted, provided that the above
14+ * copyright notice and this permission notice appear in all copies.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
17+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
19+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
20+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
21+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22+ * PERFORMANCE OF THIS SOFTWARE.
23+ */
24+
25+ #include "lua.h"
26+ #include "nrfx_wdt.h"
27+
28+ static nrfx_wdt_t watchdog = NRFX_WDT_INSTANCE (0 );
29+
30+ void init_watchdog (void )
31+ {
32+ nrfx_wdt_config_t watchdog_config = {
33+ .behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP_MASK ,
34+ .reload_value = 6000 ,
35+ .interrupt_priority = NRFX_WDT_DEFAULT_CONFIG_IRQ_PRIORITY ,
36+ };
37+
38+ nrfx_wdt_channel_id watchdog_channel = NRF_WDT_RR0 ;
39+
40+ check_error (nrfx_wdt_init (& watchdog , & watchdog_config , NULL ));
41+ check_error (nrfx_wdt_channel_alloc (& watchdog , & watchdog_channel ));
42+
43+ nrfx_wdt_enable (& watchdog );
44+ nrfx_wdt_feed (& watchdog );
45+ }
46+
47+ void reload_watchdog (lua_State * L , lua_Debug * ar )
48+ {
49+ nrfx_wdt_channel_feed (& watchdog , NRF_WDT_RR0 );
50+ }
51+
52+ void sethook_watchdog (lua_State * L )
53+ {
54+ lua_sethook (L , reload_watchdog , LUA_MASKCALL | LUA_MASKCOUNT , 2000 );
55+ }
0 commit comments