You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/09/27 19:22:19 UTC
incubator-mynewt-core git commit: native watchdog impl for nordic,
get around only resetting watchdog every 120s
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop 8897a2f1a -> ca65261bf
native watchdog impl for nordic, get around only resetting watchdog every 120s
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ca65261b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ca65261b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ca65261b
Branch: refs/heads/develop
Commit: ca65261bf834a803be364be9161a3807075a20e8
Parents: 8897a2f
Author: Sterling Hughes <st...@apache.org>
Authored: Tue Sep 27 12:22:10 2016 -0700
Committer: Sterling Hughes <st...@apache.org>
Committed: Tue Sep 27 12:22:10 2016 -0700
----------------------------------------------------------------------
hw/hal/include/hal/hal_watchdog.h | 3 +-
hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c | 44 ++++++++++++--------------
hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c | 44 ++++++++++++--------------
3 files changed, 42 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca65261b/hw/hal/include/hal/hal_watchdog.h
----------------------------------------------------------------------
diff --git a/hw/hal/include/hal/hal_watchdog.h b/hw/hal/include/hal/hal_watchdog.h
index 4fc334e..d84d932 100644
--- a/hw/hal/include/hal/hal_watchdog.h
+++ b/hw/hal/include/hal/hal_watchdog.h
@@ -20,6 +20,7 @@
#ifndef _HAL_WATCHDOG_H_
#define _HAL_WATCHDOG_H_
+#include <stdint.h>
/*
* Set a recurring watchdog timer to fire no sooner than in 'expire_secs'
* seconds. Watchdog should be tickled periodically with a frequency
@@ -31,7 +32,7 @@
* @return < 0 on failure; on success return the actual
* expiration time as positive value
*/
-int hal_watchdog_init(int expire_msecs);
+int hal_watchdog_init(uint32_t expire_msecs);
/*
* Starts the watchdog.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca65261b/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c b/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c
index 7eeb65d..4bc9d2a 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c
@@ -24,10 +24,8 @@
#include "app_util_platform.h"
#include "nrf.h"
+#include "nrf_drv_common.h"
#include "nrf_wdt.h"
-#include "nrf_drv_wdt.h"
-
-extern void WDT_IRQHandler(void);
static void
nrf51_hal_wdt_default_handler(void)
@@ -35,43 +33,41 @@ nrf51_hal_wdt_default_handler(void)
assert(0);
}
-int
-hal_watchdog_init(int expire_msecs)
+/**@brief WDT interrupt handler. */
+static void
+WDT_IRQHandler(void)
{
- nrf_drv_wdt_config_t cfg;
- nrf_drv_wdt_channel_id cid;
- int rc;
+ if (nrf_wdt_int_enable_check(NRF_WDT_INT_TIMEOUT_MASK) == true) {
+ nrf_wdt_event_clear(NRF_WDT_EVENT_TIMEOUT);
+ nrf51_hal_wdt_default_handler();
+ }
+}
+int
+hal_watchdog_init(uint32_t expire_msecs)
+{
NVIC_SetVector(WDT_IRQn, (uint32_t) WDT_IRQHandler);
- cfg.behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP;
- cfg.interrupt_priority = WDT_CONFIG_IRQ_PRIORITY;
- cfg.reload_value = (uint32_t) expire_msecs;
+ nrf_wdt_behaviour_set(NRF_WDT_BEHAVIOUR_RUN_SLEEP);
- rc = nrf_drv_wdt_init(&cfg, nrf51_hal_wdt_default_handler);
- if (rc != 0) {
- goto err;
- }
-
- rc = nrf_drv_wdt_channel_alloc(&cid);
- if (rc != 0) {
- goto err;
- }
+ /* Program in timeout in msecs */
+ nrf_wdt_reload_value_set((expire_msecs * 32768ULL) / 1000);
+ nrf_drv_common_irq_enable(WDT_IRQn, APP_IRQ_PRIORITY_HIGH);
+ nrf_wdt_reload_request_enable(NRF_WDT_RR0);
return (0);
-err:
- return (rc);
}
void
hal_watchdog_enable(void)
{
- nrf_drv_wdt_enable();
+ nrf_wdt_int_enable(NRF_WDT_INT_TIMEOUT_MASK);
+ nrf_wdt_task_trigger(NRF_WDT_TASK_START);
}
void
hal_watchdog_tickle(void)
{
- nrf_drv_wdt_feed();
+ nrf_wdt_reload_request_set(NRF_WDT_RR0);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca65261b/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c b/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
index 7c6ba38..1bdf7ee 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
@@ -24,10 +24,8 @@
#include "app_util_platform.h"
#include "nrf.h"
+#include "nrf_drv_common.h"
#include "nrf_wdt.h"
-#include "nrf_drv_wdt.h"
-
-extern void WDT_IRQHandler(void);
static void
nrf52_hal_wdt_default_handler(void)
@@ -35,43 +33,41 @@ nrf52_hal_wdt_default_handler(void)
assert(0);
}
-int
-hal_watchdog_init(int expire_msecs)
+/**@brief WDT interrupt handler. */
+static void
+WDT_IRQHandler(void)
{
- nrf_drv_wdt_config_t cfg;
- nrf_drv_wdt_channel_id cid;
- int rc;
+ if (nrf_wdt_int_enable_check(NRF_WDT_INT_TIMEOUT_MASK) == true) {
+ nrf_wdt_event_clear(NRF_WDT_EVENT_TIMEOUT);
+ nrf52_hal_wdt_default_handler();
+ }
+}
+int
+hal_watchdog_init(uint32_t expire_msecs)
+{
NVIC_SetVector(WDT_IRQn, (uint32_t) WDT_IRQHandler);
- cfg.behaviour = NRF_WDT_BEHAVIOUR_RUN_SLEEP;
- cfg.interrupt_priority = WDT_CONFIG_IRQ_PRIORITY;
- cfg.reload_value = (uint32_t) expire_msecs;
+ nrf_wdt_behaviour_set(NRF_WDT_BEHAVIOUR_RUN_SLEEP);
- rc = nrf_drv_wdt_init(&cfg, nrf52_hal_wdt_default_handler);
- if (rc != 0) {
- goto err;
- }
-
- rc = nrf_drv_wdt_channel_alloc(&cid);
- if (rc != 0) {
- goto err;
- }
+ /* Program in timeout in msecs */
+ nrf_wdt_reload_value_set((expire_msecs * 32768ULL) / 1000);
+ nrf_drv_common_irq_enable(WDT_IRQn, APP_IRQ_PRIORITY_HIGH);
+ nrf_wdt_reload_request_enable(NRF_WDT_RR0);
return (0);
-err:
- return (rc);
}
void
hal_watchdog_enable(void)
{
- nrf_drv_wdt_enable();
+ nrf_wdt_int_enable(NRF_WDT_INT_TIMEOUT_MASK);
+ nrf_wdt_task_trigger(NRF_WDT_TASK_START);
}
void
hal_watchdog_tickle(void)
{
- nrf_drv_wdt_feed();
+ nrf_wdt_reload_request_set(NRF_WDT_RR0);
}