summaryrefslogtreecommitdiff
path: root/ports/nrf
diff options
context:
space:
mode:
authorSean Cross <sean@xobs.io>2020-05-20 20:09:28 +0800
committerSean Cross <sean@xobs.io>2020-05-27 11:28:48 +0800
commitabd01c5fbb3005fd30e41407c8f8b9d0dad5ef55 (patch)
tree4a9791322fab8561288138cbd7c48c645b41df42 /ports/nrf
parentf4719609f7af49697e4b7e0292fc520e39b26daf (diff)
nrf: add watchdog module
Add common-hal bindings to allow the watchdog module to be used on nrf platforms. Signed-off-by: Sean Cross <sean@xobs.io>
Diffstat (limited to 'ports/nrf')
-rw-r--r--ports/nrf/common-hal/wdt/WDT.c40
-rw-r--r--ports/nrf/common-hal/wdt/__init__.c0
2 files changed, 40 insertions, 0 deletions
diff --git a/ports/nrf/common-hal/wdt/WDT.c b/ports/nrf/common-hal/wdt/WDT.c
new file mode 100644
index 000000000..172bd3346
--- /dev/null
+++ b/ports/nrf/common-hal/wdt/WDT.c
@@ -0,0 +1,40 @@
+#include "py/obj.h"
+#include "py/runtime.h"
+
+#include "shared-bindings/rtc/__init__.h"
+#include "nrf_wdt.h"
+
+#define WDT_RELOAD_COUNT 2
+
+void common_hal_wdt_init(uint32_t duration, bool pause_during_sleep) {
+ unsigned int channel;
+ nrf_wdt_behaviour_t behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP_HALT;
+ if (pause_during_sleep) {
+ behaviour = NRF_WDT_BEHAVIOUR_PAUSE_SLEEP_HALT;
+ }
+
+ nrf_wdt_behaviour_set(NRF_WDT, behaviour);
+
+ uint64_t ticks = (duration * 32768ULL) / 1000;
+ if (ticks > UINT32_MAX) {
+ mp_raise_ValueError(translate("timeout duration exceeded the maximum supported value"));
+ }
+ nrf_wdt_reload_value_set(NRF_WDT, (uint32_t) ticks);
+
+ for (channel = 0; channel < WDT_RELOAD_COUNT; channel++) {
+ nrf_wdt_reload_request_enable(NRF_WDT, channel);
+ }
+
+ nrf_wdt_task_trigger(NRF_WDT, NRF_WDT_TASK_START);
+}
+
+void common_hal_wdt_feed(void) {
+ unsigned int channel;
+ for (channel = 0; channel < WDT_RELOAD_COUNT; channel++) {
+ nrf_wdt_reload_request_set(NRF_WDT, (nrf_wdt_rr_register_t)(NRF_WDT_RR0 + channel));
+ }
+}
+
+void common_hal_wdt_disable(void) {
+ // mp_raise_ValueError(translate("Watchdog timer cannot be disabled -- board will reset shortly"));
+}
diff --git a/ports/nrf/common-hal/wdt/__init__.c b/ports/nrf/common-hal/wdt/__init__.c
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/ports/nrf/common-hal/wdt/__init__.c