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>
This commit is contained in:
parent
f4719609f7
commit
abd01c5fbb
40
ports/nrf/common-hal/wdt/WDT.c
Normal file
40
ports/nrf/common-hal/wdt/WDT.c
Normal file
@ -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"));
|
||||
}
|
0
ports/nrf/common-hal/wdt/__init__.c
Normal file
0
ports/nrf/common-hal/wdt/__init__.c
Normal file
Loading…
x
Reference in New Issue
Block a user