This is an automated email from the ASF dual-hosted git repository.

wes3 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 7bea0ed29a1514f8ddaf1d8460b6d2a7cb0eac59
Author: Will San Filippo <william.sanfili...@juul.com>
AuthorDate: Mon Jan 31 10:32:06 2022 -0800

    hal: Modify hal_system_restart
    
    Two changes to the code: clear ICPR register (to
    clear any pending interrupts) and also leave global
    interrupts enabled when calling hal_system_start.
    The idea behind this change is that the cortex-M
    has global interrupts enabled on reset and that
    this should be the state when the system is
    restarted.
---
 hw/mcu/nordic/nrf51xxx/src/hal_system_start.c    | 15 ++++++++++-----
 hw/mcu/nordic/nrf52xxx/src/hal_system_start.c    | 15 ++++++++++-----
 hw/mcu/nordic/nrf5340/src/hal_system_start.c     | 15 ++++++++++-----
 hw/mcu/nordic/nrf5340_net/src/hal_system_start.c | 15 ++++++++++-----
 hw/mcu/nordic/nrf91xx/src/hal_system_start.c     | 15 ++++++++++-----
 5 files changed, 50 insertions(+), 25 deletions(-)

diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c 
b/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c
index d4581fe..93e0a7e 100644
--- a/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c
+++ b/hw/mcu/nordic/nrf51xxx/src/hal_system_start.c
@@ -52,17 +52,22 @@ void
 hal_system_restart(void *img_start)
 {
     int i;
-    int sr;
 
     /*
-     * Disable interrupts, and leave the disabled.
-     * They get re-enabled when system starts coming back again.
+     * NOTE: on reset, PRIMASK should have global interrupts enabled so
+     * the code disables interrupts, clears the interrupt enable bits,
+     * clears any pending interrupts, then enables global interrupts
+     * so processor looks like state it would be in if it reset.
      */
-    __HAL_DISABLE_INTERRUPTS(sr);
+    __disable_irq();
     for (i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) {
         NVIC->ICER[i] = 0xffffffff;
     }
-    (void)sr;
+
+    for (i = 0; i < sizeof(NVIC->ICPR) / sizeof(NVIC->ICPR[0]); i++) {
+        NVIC->ICPR[i] = 0xffffffff;
+    }
+    __enable_irq();
 
     hal_system_start(img_start);
 }
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c 
b/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c
index 123353f..25e35b1 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_system_start.c
@@ -52,17 +52,22 @@ void
 hal_system_restart(void *img_start)
 {
     int i;
-    int sr;
 
     /*
-     * Disable interrupts, and leave the disabled.
-     * They get re-enabled when system starts coming back again.
+     * NOTE: on reset, PRIMASK should have global interrupts enabled so
+     * the code disables interrupts, clears the interrupt enable bits,
+     * clears any pending interrupts, then enables global interrupts
+     * so processor looks like state it would be in if it reset.
      */
-    __HAL_DISABLE_INTERRUPTS(sr);
+    __disable_irq();
     for (i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) {
         NVIC->ICER[i] = 0xffffffff;
     }
-    (void)sr;
+
+    for (i = 0; i < sizeof(NVIC->ICPR) / sizeof(NVIC->ICPR[0]); i++) {
+        NVIC->ICPR[i] = 0xffffffff;
+    }
+    __enable_irq();
 
     hal_system_start(img_start);
 }
diff --git a/hw/mcu/nordic/nrf5340/src/hal_system_start.c 
b/hw/mcu/nordic/nrf5340/src/hal_system_start.c
index 89f3f51..ecb3cf1 100644
--- a/hw/mcu/nordic/nrf5340/src/hal_system_start.c
+++ b/hw/mcu/nordic/nrf5340/src/hal_system_start.c
@@ -193,17 +193,22 @@ void
 hal_system_restart(void *img_start)
 {
     int i;
-    int sr;
 
     /*
-     * Disable interrupts, and leave the disabled.
-     * They get re-enabled when system starts coming back again.
+     * NOTE: on reset, PRIMASK should have global interrupts enabled so
+     * the code disables interrupts, clears the interrupt enable bits,
+     * clears any pending interrupts, then enables global interrupts
+     * so processor looks like state it would be in if it reset.
      */
-    __HAL_DISABLE_INTERRUPTS(sr);
+    __disable_irq();
     for (i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) {
         NVIC->ICER[i] = 0xffffffff;
     }
-    (void)sr;
+
+    for (i = 0; i < sizeof(NVIC->ICPR) / sizeof(NVIC->ICPR[0]); i++) {
+        NVIC->ICPR[i] = 0xffffffff;
+    }
+    __enable_irq();
 
     hal_system_start(img_start);
 }
diff --git a/hw/mcu/nordic/nrf5340_net/src/hal_system_start.c 
b/hw/mcu/nordic/nrf5340_net/src/hal_system_start.c
index a1dc5e0..f34f0f6 100644
--- a/hw/mcu/nordic/nrf5340_net/src/hal_system_start.c
+++ b/hw/mcu/nordic/nrf5340_net/src/hal_system_start.c
@@ -52,17 +52,22 @@ void
 hal_system_restart(void *img_start)
 {
     int i;
-    int sr;
 
     /*
-     * Disable interrupts, and leave the disabled.
-     * They get re-enabled when system starts coming back again.
+     * NOTE: on reset, PRIMASK should have global interrupts enabled so
+     * the code disables interrupts, clears the interrupt enable bits,
+     * clears any pending interrupts, then enables global interrupts
+     * so processor looks like state it would be in if it reset.
      */
-    __HAL_DISABLE_INTERRUPTS(sr);
+    __disable_irq();
     for (i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) {
         NVIC->ICER[i] = 0xffffffff;
     }
-    (void)sr;
+
+    for (i = 0; i < sizeof(NVIC->ICPR) / sizeof(NVIC->ICPR[0]); i++) {
+        NVIC->ICPR[i] = 0xffffffff;
+    }
+    __enable_irq();
 
     hal_system_start(img_start);
 }
diff --git a/hw/mcu/nordic/nrf91xx/src/hal_system_start.c 
b/hw/mcu/nordic/nrf91xx/src/hal_system_start.c
index 43b4389..e8b86b7 100644
--- a/hw/mcu/nordic/nrf91xx/src/hal_system_start.c
+++ b/hw/mcu/nordic/nrf91xx/src/hal_system_start.c
@@ -52,17 +52,22 @@ void
 hal_system_restart(void *img_start)
 {
     int i;
-    int sr;
 
     /*
-     * Disable interrupts, and leave the disabled.
-     * They get re-enabled when system starts coming back again.
+     * NOTE: on reset, PRIMASK should have global interrupts enabled so
+     * the code disables interrupts, clears the interrupt enable bits,
+     * clears any pending interrupts, then enables global interrupts
+     * so processor looks like state it would be in if it reset.
      */
-    __HAL_DISABLE_INTERRUPTS(sr);
+    __disable_irq();
     for (i = 0; i < sizeof(NVIC->ICER) / sizeof(NVIC->ICER[0]); i++) {
         NVIC->ICER[i] = 0xffffffff;
     }
-    (void)sr;
+
+    for (i = 0; i < sizeof(NVIC->ICPR) / sizeof(NVIC->ICPR[0]); i++) {
+        NVIC->ICPR[i] = 0xffffffff;
+    }
+    __enable_irq();
 
     hal_system_start(img_start);
 }

Reply via email to