You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ut...@apache.org on 2018/07/30 11:31:51 UTC
[mynewt-core] branch master updated: [NRF52] Remove uint64_t div in
watchdog init
This is an automated email from the ASF dual-hosted git repository.
utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new 0003fd9 [NRF52] Remove uint64_t div in watchdog init
0003fd9 is described below
commit 0003fd9f4d999bd2f28cec3219fa6f371629d3aa
Author: Fabio Utzig <ut...@apache.org>
AuthorDate: Fri Jul 27 10:08:00 2018 -0300
[NRF52] Remove uint64_t div in watchdog init
Because of precision requirements the watchdog was using a uint64_t
division cause it allowed any possible timeout to be used. This updates the
code to rely only on uint32_t division with the limitation of a maximum
timeout of slightly more than 12 hours. It shrinks the code due to not
linking in the div emulation code.
---
hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c b/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
index 6248dbe..cfbaff6 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c
@@ -44,13 +44,14 @@ nrf52_wdt_irq_handler(void)
int
hal_watchdog_init(uint32_t expire_msecs)
{
- uint64_t expiration;
-
NRF_WDT->CONFIG = WDT_CONFIG_SLEEP_Msk;
- /* Convert msec timeout to counts of a 32768 crystal */
- expiration = ((uint64_t)expire_msecs * 32768) / 1000;
- NRF_WDT->CRV = (uint32_t)expiration;
+ if (expire_msecs >= 44739243) {
+ /* maximum allowed time is near 12.5 hours! */
+ assert(0);
+ } else {
+ NRF_WDT->CRV = (expire_msecs * 32) + ((expire_msecs * 96) / 125);
+ }
NVIC_SetVector(WDT_IRQn, (uint32_t) nrf52_wdt_irq_handler);
NVIC_SetPriority(WDT_IRQn, (1 << __NVIC_PRIO_BITS) - 1);