Repository: incubator-mynewt-core Updated Branches: refs/heads/develop 1191f1e52 -> d4632c29e
MYNEWT-403; nrf51 - fill in hal_reset_cause(). 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/d4632c29 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d4632c29 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d4632c29 Branch: refs/heads/develop Commit: d4632c29e1a4ff699496740f215051a02b281707 Parents: f9a452a Author: Marko Kiiskila <ma...@runtime.io> Authored: Fri Nov 4 16:43:38 2016 -0700 Committer: Marko Kiiskila <ma...@runtime.io> Committed: Fri Nov 4 16:44:53 2016 -0700 ---------------------------------------------------------------------- hw/mcu/nordic/nrf51xxx/src/hal_reset_cause.c | 27 ++++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d4632c29/hw/mcu/nordic/nrf51xxx/src/hal_reset_cause.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_reset_cause.c b/hw/mcu/nordic/nrf51xxx/src/hal_reset_cause.c index 087ea08..b55f7ab 100644 --- a/hw/mcu/nordic/nrf51xxx/src/hal_reset_cause.c +++ b/hw/mcu/nordic/nrf51xxx/src/hal_reset_cause.c @@ -23,18 +23,23 @@ enum hal_reset_reason hal_reset_cause(void) { - uint32_t reason; + static enum hal_reset_reason reason; + uint32_t reg; - reason = PWR->RESETREAS; - - if (reason & (POWER_RESETREAS_RESETPIN_Msk | POWER_RESETREAS_LOCKUP_Msk)) { - return HAL_RESET_WATCHDOG; - } - if (reason & POWER_RESETREAS_SREQ_Msk) { - return HAL_RESET_SOFT; + if (reason) { + return reason; } - if (reason & POWER_RESETREAS_RESETPIN_Msk) { - return HAL_RESET_PIN; + reg = NRF_POWER->RESETREAS; + + if (reg & (POWER_RESETREAS_DOG_Msk | POWER_RESETREAS_LOCKUP_Msk)) { + reason = HAL_RESET_WATCHDOG; + } else if (reg & POWER_RESETREAS_SREQ_Msk) { + reason = HAL_RESET_SOFT; + } else if (reg & POWER_RESETREAS_RESETPIN_Msk) { + reason = HAL_RESET_PIN; + } else { + reason = HAL_RESET_POR; /* could also be brownout */ } - return HAL_RESET_POR; + NRF_POWER->RESETREAS = reg; + return reason; }