MYNEWT-403; nrf52x - clean up reset reg after reading it.
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/615f00c5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/615f00c5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/615f00c5 Branch: refs/heads/develop Commit: 615f00c52fed0cda8c2251c2c0ef1d53ac38f969 Parents: 1191f1e Author: Marko Kiiskila <ma...@runtime.io> Authored: Fri Nov 4 16:36:37 2016 -0700 Committer: Marko Kiiskila <ma...@runtime.io> Committed: Fri Nov 4 16:44:53 2016 -0700 ---------------------------------------------------------------------- hw/mcu/nordic/nrf52xxx/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/615f00c5/hw/mcu/nordic/nrf52xxx/src/hal_reset_cause.c ---------------------------------------------------------------------- diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_reset_cause.c b/hw/mcu/nordic/nrf52xxx/src/hal_reset_cause.c index 66e53c2..b55f7ab 100644 --- a/hw/mcu/nordic/nrf52xxx/src/hal_reset_cause.c +++ b/hw/mcu/nordic/nrf52xxx/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 = NRF_POWER->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; }