summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMyles Watson <mylesgw@chromium.org>2015-01-22 09:49:23 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-24 00:32:25 +0000
commit4ada7739f96152ca688617c291c572417e34240c (patch)
treee0a940db8b7bec54a579b89b57297b877b7ec3a7
parentad06ead062967be31d9474e202263bffe792dee6 (diff)
downloadchrome-ec-4ada7739f96152ca688617c291c572417e34240c.tar.gz
nrf51: implement soft reset and hard reset
TEST=manual test with the console command. Reset flags are set correctly. BRANCH=NONE BUG=None Change-Id: I3ea4301206be6fe4e79a4b49c002c020980c516d Signed-off-by: Myles Watson <mylesgw@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/242901 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--chip/nrf51/system.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/chip/nrf51/system.c b/chip/nrf51/system.c
index 293911ca28..687b889a69 100644
--- a/chip/nrf51/system.c
+++ b/chip/nrf51/system.c
@@ -9,6 +9,8 @@
#include "console.h"
#include "registers.h"
#include "system.h"
+#include "task.h"
+#include "cpu.h"
/* Console output macros */
#define CPUTS(outstr) cputs(CC_SYSTEM, outstr)
@@ -67,10 +69,36 @@ static void check_reset_cause(void)
NRF51_POWER_RESETREAS = raw_cause;
}
+static void system_watchdog_reset(void)
+{
+ if (NRF51_WDT_TIMEOUT != 0) {
+ /* Hard reset the WDT */
+ NRF51_WDT_POWER = 0;
+ NRF51_WDT_POWER = 1;
+ }
+
+ /* NRF51_WDT_CONFIG_HALT_RUN breaks this */
+ NRF51_WDT_CONFIG = NRF51_WDT_CONFIG_SLEEP_RUN;
+
+ NRF51_WDT_RREN = NRF51_WDT_RREN_BIT(0);
+ NRF51_WDT_CRV = 3; /* @32KHz */
+ NRF51_WDT_START = 1;
+}
void system_reset(int flags)
{
- CPRINTS("TODO: implement %s(). Infinite loop.", __func__);
+ /* Disable interrupts to avoid task swaps during reboot */
+ interrupt_disable();
+
+ if (flags & SYSTEM_RESET_HARD)
+ /* Ask the watchdog to trigger a hard reboot */
+ system_watchdog_reset();
+ else {
+ /* Use SYSRESETREQ to trigger a soft reboot */
+ CPU_NVIC_APINT = 0x05fa0004;
+ }
+
+ /* Spin and wait for reboot; should never return */
while (1)
;
}