aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-06-20 17:16:33 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-09-24 16:02:26 -0400
commit37c7929637c7047955ddacfb70a5868dcbae7160 (patch)
tree19f60c69b6fd7f45f9de42bfa6558a0980e5d01d /libmaple
parente0c7ac23ec37b80a3cddd8782d5e41eb7b639937 (diff)
downloadlibrambutan-37c7929637c7047955ddacfb70a5868dcbae7160.tar.gz
librambutan-37c7929637c7047955ddacfb70a5868dcbae7160.zip
nvic: Add nvic_sys_reset().
This uses the SCB_AIRCR register to force a system reset. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple')
-rw-r--r--libmaple/nvic.c13
-rw-r--r--libmaple/nvic.h2
2 files changed, 14 insertions, 1 deletions
diff --git a/libmaple/nvic.c b/libmaple/nvic.c
index 3be5a5a..345c850 100644
--- a/libmaple/nvic.c
+++ b/libmaple/nvic.c
@@ -83,3 +83,16 @@ void nvic_init(uint32 vector_table_address, uint32 offset) {
void nvic_set_vector_table(uint32 addr, uint32 offset) {
SCB_BASE->VTOR = addr | (offset & 0x1FFFFF80);
}
+
+/**
+ * @brief Force a system reset.
+ *
+ * Resets all major system components, excluding debug.
+ */
+void nvic_sys_reset() {
+ uint32 prigroup = SCB_BASE->AIRCR & SCB_AIRCR_PRIGROUP;
+ SCB_BASE->AIRCR = SCB_AIRCR_VECTKEY | SCB_AIRCR_SYSRESETREQ | prigroup;
+ asm volatile("dsb");
+ while (1)
+ ;
+}
diff --git a/libmaple/nvic.h b/libmaple/nvic.h
index e3b052d..feb7335 100644
--- a/libmaple/nvic.h
+++ b/libmaple/nvic.h
@@ -177,6 +177,7 @@ void nvic_init(uint32 vector_table_address, uint32 offset);
void nvic_set_vector_table(uint32 address, uint32 offset);
void nvic_irq_set_priority(nvic_irq_num irqn, uint8 priority);
+void nvic_sys_reset();
/**
* Enables interrupts and configurable fault handlers (clear PRIMASK).
@@ -238,4 +239,3 @@ static inline void nvic_irq_disable_all(void) {
#endif
#endif
-