File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include "py/obj.h"
2
+ #include "py/runtime.h"
3
+
4
+ #include "shared-bindings/rtc/__init__.h"
5
+ #include "nrf_wdt.h"
6
+
7
+ #define WDT_RELOAD_COUNT 2
8
+
9
+ void common_hal_wdt_init (uint32_t duration , bool pause_during_sleep ) {
10
+ unsigned int channel ;
11
+ nrf_wdt_behaviour_t behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP_HALT ;
12
+ if (pause_during_sleep ) {
13
+ behaviour = NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT ;
14
+ }
15
+
16
+ nrf_wdt_behaviour_set (NRF_WDT , behaviour );
17
+
18
+ uint64_t ticks = (duration * 32768ULL ) / 1000 ;
19
+ if (ticks > UINT32_MAX ) {
20
+ mp_raise_ValueError (translate ("timeout duration exceeded the maximum supported value" ));
21
+ }
22
+ nrf_wdt_reload_value_set (NRF_WDT , (uint32_t ) ticks );
23
+
24
+ for (channel = 0 ; channel < WDT_RELOAD_COUNT ; channel ++ ) {
25
+ nrf_wdt_reload_request_enable (NRF_WDT , channel );
26
+ }
27
+
28
+ nrf_wdt_task_trigger (NRF_WDT , NRF_WDT_TASK_START );
29
+ }
30
+
31
+ void common_hal_wdt_feed (void ) {
32
+ unsigned int channel ;
33
+ for (channel = 0 ; channel < WDT_RELOAD_COUNT ; channel ++ ) {
34
+ nrf_wdt_reload_request_set (NRF_WDT , (nrf_wdt_rr_register_t )(NRF_WDT_RR0 + channel ));
35
+ }
36
+ }
37
+
38
+ void common_hal_wdt_disable (void ) {
39
+ // mp_raise_ValueError(translate("Watchdog timer cannot be disabled -- board will reset shortly"));
40
+ }
You can’t perform that action at this time.
0 commit comments