Skip to content

Commit ea0388b

Browse files
committed
nrf: add watchdog module
Add common-hal bindings to allow the watchdog module to be used on nrf platforms. Signed-off-by: Sean Cross <[email protected]>
1 parent 9b3f858 commit ea0388b

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

ports/nrf/common-hal/wdt/WDT.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

ports/nrf/common-hal/wdt/__init__.c

Whitespace-only changes.

0 commit comments

Comments
 (0)