You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/10/09 17:01:23 UTC

(nuttx) branch master updated (89c49c53a7 -> c00d477671)

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

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


    from 89c49c53a7 virtio-mmio/pci: add alloc_buf/free_buf for mmio and pci transport layer
     new f20ae064b0 armv7/8m: unmask all the IRQ when thread start
     new f221c9ecb4 armv6m: add up_trigger_irq() support
     new 780acd7827 armv6/7/8m: use pendsv to handle context switch
     new a9da6ab4b5 arm-M: set current regs for crash dump
     new ff99745b22 arm-m: support zero interrupt back to game
     new c00d477671 Doc: add maskable nested interrupt description

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Documentation/guides/zerolatencyinterrupts.rst     |  62 +++++++++++-
 arch/arm/Kconfig                                   |   1 +
 arch/arm/include/armv7-m/irq.h                     |   2 +-
 arch/arm/include/armv8-m/irq.h                     |   2 +-
 arch/arm/src/armv6-m/CMakeLists.txt                |   1 +
 arch/arm/src/armv6-m/Make.defs                     |   1 +
 arch/arm/src/armv6-m/arm_doirq.c                   |  76 +++++++++-----
 arch/arm/src/armv6-m/arm_svcall.c                  |   1 -
 .../arm/src/{armv8-m => armv6-m}/arm_trigger_irq.c |  12 +--
 arch/arm/src/armv6-m/arm_vectors.c                 |   9 +-
 arch/arm/src/armv6-m/nvic.h                        |  25 +++++
 arch/arm/src/armv7-m/arm_doirq.c                   |  76 +++++++++-----
 arch/arm/src/armv7-m/arm_initialstate.c            |   2 +-
 arch/arm/src/armv7-m/arm_svcall.c                  |   6 +-
 arch/arm/src/armv7-m/arm_vectors.c                 |   6 +-
 arch/arm/src/armv8-m/arm_doirq.c                   | 112 ++++++++-------------
 arch/arm/src/armv8-m/arm_initialstate.c            |   2 +-
 arch/arm/src/armv8-m/arm_svcall.c                  |   5 +-
 arch/arm/src/armv8-m/arm_vectors.c                 |   9 +-
 arch/arm/src/lpc17xx_40xx/lpc17_40_irq.c           |   2 +
 arch/arm/src/mps/mps_irq.c                         |   2 +
 arch/arm/src/nrf52/nrf52_irq.c                     |   2 +
 arch/arm/src/stm32/stm32_irq.c                     |   2 +
 arch/arm/src/stm32l4/stm32l4_irq.c                 |   2 +
 24 files changed, 271 insertions(+), 149 deletions(-)
 copy arch/arm/src/{armv8-m => armv6-m}/arm_trigger_irq.c (88%)


(nuttx) 03/06: armv6/7/8m: use pendsv to handle context switch

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 780acd78271a986a571429a7609411e526ac7621
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Jul 18 21:22:27 2024 +0800

    armv6/7/8m: use pendsv to handle context switch
    
    This PR support Nested interrupt in armv6/7/8m:
    
    There are two types of nested interrupt model:
    
    Zero latency nested interrupt
    Interrupt           Priority            Note
    Data abort          Highest
    SVC                 0x50
    High irq1           0x60             ISR can't access system API
    irq_save()          0x70
    High irq2           0x80             ISR can't access system API
    normal irq3         0xB0
    We have already support this mode before this PR
    
    Nested interrupt which interrupt level lower than up_irq_save()
    Interrupt           Priority            Note
    Data abort          Highest
    SVC                 0x70
    irq_save()          0x80
    High irq1           0x90              ISR can access system API
    High irq2           0xA0              ISR can access system API
    normal irq3         0xB0
    Now, this PR can support this mode
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 arch/arm/src/armv6-m/arm_doirq.c   |  63 ++++++++++++-----------
 arch/arm/src/armv6-m/arm_svcall.c  |   1 -
 arch/arm/src/armv6-m/arm_vectors.c |   9 +++-
 arch/arm/src/armv7-m/arm_doirq.c   |  63 ++++++++++++-----------
 arch/arm/src/armv7-m/arm_svcall.c  |   6 +--
 arch/arm/src/armv7-m/arm_vectors.c |   6 ++-
 arch/arm/src/armv8-m/arm_doirq.c   | 100 +++++++++++--------------------------
 arch/arm/src/armv8-m/arm_svcall.c  |   5 +-
 arch/arm/src/armv8-m/arm_vectors.c |   9 +++-
 9 files changed, 120 insertions(+), 142 deletions(-)

diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c
index 3065a4f4da..93703b4512 100644
--- a/arch/arm/src/armv6-m/arm_doirq.c
+++ b/arch/arm/src/armv6-m/arm_doirq.c
@@ -35,11 +35,25 @@
 
 #include "arm_internal.h"
 #include "exc_return.h"
+#include "nvic.h"
 
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
+void exception_direct(void)
+{
+  int irq = getipsr();
+
+  arm_ack_irq(irq);
+  irq_dispatch(irq, NULL);
+
+  if (g_running_tasks[this_cpu()] != this_task())
+    {
+      up_trigger_irq(NVIC_IRQ_PENDSV, 0);
+    }
+}
+
 uint32_t *arm_doirq(int irq, uint32_t *regs)
 {
   struct tcb_s *tcb = this_task();
@@ -49,19 +63,20 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
   PANIC();
 #else
 
-  if (regs[REG_EXC_RETURN] & EXC_RETURN_THREAD_MODE)
-    {
-      tcb->xcp.regs = regs;
-      up_set_current_regs(regs);
-    }
-
   /* Acknowledge the interrupt */
 
   arm_ack_irq(irq);
 
-  /* Deliver the IRQ */
-
-  irq_dispatch(irq, regs);
+  if (irq == NVIC_IRQ_PENDSV)
+    {
+      up_irq_save();
+      g_running_tasks[this_cpu()]->xcp.regs = regs;
+    }
+  else
+    {
+      tcb->xcp.regs = regs;
+      irq_dispatch(irq, regs);
+    }
 
   /* If a context switch occurred while processing the interrupt then
    * current_regs may have change value.  If we return any value different
@@ -69,30 +84,20 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
    * switch occurred during interrupt processing.
    */
 
-  if (regs[REG_EXC_RETURN] & EXC_RETURN_THREAD_MODE)
-    {
-      tcb = this_task();
-
-      if (regs != tcb->xcp.regs)
-        {
-          /* Update scheduler parameters */
-
-          nxsched_suspend_scheduler(g_running_tasks[this_cpu()]);
-          nxsched_resume_scheduler(tcb);
+  tcb = this_task();
 
-          /* Record the new "running" task when context switch occurred.
-           * g_running_tasks[] is only used by assertion logic for reporting
-           * crashes.
-           */
+  /* Update scheduler parameters */
 
-          g_running_tasks[this_cpu()] = tcb;
-          regs = tcb->xcp.regs;
-        }
+  nxsched_suspend_scheduler(g_running_tasks[this_cpu()]);
+  nxsched_resume_scheduler(tcb);
 
-      /* Update the current_regs to NULL. */
+  /* Record the new "running" task when context switch occurred.
+   * g_running_tasks[] is only used by assertion logic for reporting
+   * crashes.
+   */
 
-      up_set_current_regs(NULL);
-    }
+  g_running_tasks[this_cpu()] = tcb;
+  regs = tcb->xcp.regs;
 #endif
 
   board_autoled_off(LED_INIRQ);
diff --git a/arch/arm/src/armv6-m/arm_svcall.c b/arch/arm/src/armv6-m/arm_svcall.c
index 4bda7e1ad6..820a18ff83 100644
--- a/arch/arm/src/armv6-m/arm_svcall.c
+++ b/arch/arm/src/armv6-m/arm_svcall.c
@@ -121,7 +121,6 @@ int arm_svcall(int irq, void *context, void *arg)
   uint32_t *regs = (uint32_t *)context;
   uint32_t cmd;
 
-  DEBUGASSERT(regs && regs == up_current_regs());
   cmd = regs[REG_R0];
 
   /* The SVCall software interrupt is called with R0 = system call command
diff --git a/arch/arm/src/armv6-m/arm_vectors.c b/arch/arm/src/armv6-m/arm_vectors.c
index 8beb9443c1..dbb336ae15 100644
--- a/arch/arm/src/armv6-m/arm_vectors.c
+++ b/arch/arm/src/armv6-m/arm_vectors.c
@@ -45,6 +45,8 @@
 
 #include "chip.h"
 #include "arm_internal.h"
+#include "ram_vectors.h"
+#include "nvic.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -81,6 +83,7 @@ static void start(void)
 /* Common exception entrypoint */
 
 extern void exception_common(void);
+extern void exception_direct(void);
 
 /****************************************************************************
  * Public data
@@ -92,7 +95,7 @@ extern void exception_common(void);
  * As all exceptions (interrupts) are routed via exception_common, we just
  * need to fill this array with pointers to it.
  *
- * Note that the [ ... ] designated initialiser is a GCC extension.
+ * Note that the [ ... ] designated initializer is a GCC extension.
  */
 
 const void * const _vectors[] locate_data(".vectors") =
@@ -107,5 +110,7 @@ const void * const _vectors[] locate_data(".vectors") =
 
   /* Vectors 2 - n point directly at the generic handler */
 
-  [2 ... (15 + ARMV6M_PERIPHERAL_INTERRUPTS)] = exception_common
+  [2 ... NVIC_IRQ_PENDSV] = &exception_common,
+  [(NVIC_IRQ_PENDSV + 1) ... (15 + ARMV6M_PERIPHERAL_INTERRUPTS)]
+                          = &exception_direct
 };
diff --git a/arch/arm/src/armv7-m/arm_doirq.c b/arch/arm/src/armv7-m/arm_doirq.c
index 5c31de792e..b74414c59a 100644
--- a/arch/arm/src/armv7-m/arm_doirq.c
+++ b/arch/arm/src/armv7-m/arm_doirq.c
@@ -35,11 +35,25 @@
 
 #include "arm_internal.h"
 #include "exc_return.h"
+#include "nvic.h"
 
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
+void exception_direct(void)
+{
+  int irq = getipsr();
+
+  arm_ack_irq(irq);
+  irq_dispatch(irq, NULL);
+
+  if (g_running_tasks[this_cpu()] != this_task())
+    {
+      up_trigger_irq(NVIC_IRQ_PENDSV, 0);
+    }
+}
+
 uint32_t *arm_doirq(int irq, uint32_t *regs)
 {
   struct tcb_s *tcb = this_task();
@@ -49,19 +63,20 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
   PANIC();
 #else
 
-  if (regs[REG_EXC_RETURN] & EXC_RETURN_THREAD_MODE)
-    {
-      tcb->xcp.regs = regs;
-      up_set_current_regs(regs);
-    }
-
   /* Acknowledge the interrupt */
 
   arm_ack_irq(irq);
 
-  /* Deliver the IRQ */
-
-  irq_dispatch(irq, regs);
+  if (irq == NVIC_IRQ_PENDSV)
+    {
+      up_irq_save();
+      g_running_tasks[this_cpu()]->xcp.regs = regs;
+    }
+  else
+    {
+      tcb->xcp.regs = regs;
+      irq_dispatch(irq, regs);
+    }
 
   /* If a context switch occurred while processing the interrupt then
    * current_regs may have change value.  If we return any value different
@@ -69,30 +84,20 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
    * switch occurred during interrupt processing.
    */
 
-  if (regs[REG_EXC_RETURN] & EXC_RETURN_THREAD_MODE)
-    {
-      tcb = this_task();
-
-      if (regs != tcb->xcp.regs)
-        {
-          /* Update scheduler parameters */
-
-          nxsched_suspend_scheduler(g_running_tasks[this_cpu()]);
-          nxsched_resume_scheduler(tcb);
+  tcb = this_task();
 
-          /* Record the new "running" task when context switch occurred.
-           * g_running_tasks[] is only used by assertion logic for reporting
-           * crashes.
-           */
+  /* Update scheduler parameters */
 
-          g_running_tasks[this_cpu()] = tcb;
-          regs = tcb->xcp.regs;
-        }
+  nxsched_suspend_scheduler(g_running_tasks[this_cpu()]);
+  nxsched_resume_scheduler(tcb);
 
-      /* Update the current_regs to NULL. */
+  /* Record the new "running" task when context switch occurred.
+   * g_running_tasks[] is only used by assertion logic for reporting
+   * crashes.
+   */
 
-      up_set_current_regs(NULL);
-    }
+  g_running_tasks[this_cpu()] = tcb;
+  regs = tcb->xcp.regs;
 #endif
 
   board_autoled_off(LED_INIRQ);
diff --git a/arch/arm/src/armv7-m/arm_svcall.c b/arch/arm/src/armv7-m/arm_svcall.c
index 1ccd70650d..d00c394c82 100644
--- a/arch/arm/src/armv7-m/arm_svcall.c
+++ b/arch/arm/src/armv7-m/arm_svcall.c
@@ -129,7 +129,6 @@ int arm_svcall(int irq, void *context, void *arg)
   uint32_t *regs = (uint32_t *)context;
   uint32_t cmd;
 
-  DEBUGASSERT(regs && regs == up_current_regs());
   cmd = regs[REG_R0];
 
   /* The SVCall software interrupt is called with R0 = system call command
@@ -299,8 +298,9 @@ int arm_svcall(int irq, void *context, void *arg)
        * At this point, the following values are saved in context:
        *
        *   R0 = SYS_pthread_start
-       *   R1 = entrypt
-       *   R2 = arg
+       *   R1 = startup (trampoline)
+       *   R2 = entrypt
+       *   R3 = arg
        */
 
 #if !defined(CONFIG_BUILD_FLAT) && !defined(CONFIG_DISABLE_PTHREAD)
diff --git a/arch/arm/src/armv7-m/arm_vectors.c b/arch/arm/src/armv7-m/arm_vectors.c
index c4674ab20f..f007d021f0 100644
--- a/arch/arm/src/armv7-m/arm_vectors.c
+++ b/arch/arm/src/armv7-m/arm_vectors.c
@@ -41,6 +41,7 @@
 #include "chip.h"
 #include "arm_internal.h"
 #include "ram_vectors.h"
+#include "nvic.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -71,6 +72,7 @@ static void start(void)
 /* Common exception entrypoint */
 
 extern void exception_common(void);
+extern void exception_direct(void);
 
 /****************************************************************************
  * Public data
@@ -98,5 +100,7 @@ const void * const _vectors[] locate_data(".vectors")
 
   /* Vectors 2 - n point directly at the generic handler */
 
-  [2 ... (15 + ARMV7M_PERIPHERAL_INTERRUPTS)] = exception_common
+  [2 ... NVIC_IRQ_PENDSV] = &exception_common,
+  [(NVIC_IRQ_PENDSV + 1) ... (15 + ARMV7M_PERIPHERAL_INTERRUPTS)]
+                          = &exception_direct
 };
diff --git a/arch/arm/src/armv8-m/arm_doirq.c b/arch/arm/src/armv8-m/arm_doirq.c
index 3e2fe2e961..536d7c4e75 100644
--- a/arch/arm/src/armv8-m/arm_doirq.c
+++ b/arch/arm/src/armv8-m/arm_doirq.c
@@ -35,60 +35,25 @@
 
 #include "arm_internal.h"
 #include "exc_return.h"
+#include "nvic.h"
 
 /****************************************************************************
- * Inline Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: arm_from_thread
- *
- * Description:
- *   If not defined CONFIG_ARCH_HAVE_TRUSTZONE
- *   Return true if interrupt return to thread mode, false otherwise.
- *
- *   If defined CONFIG_ARCH_HAVE_TRUSTZONE
- *   Return true if interrupt return to thread mode, or if it is the first
- *   interrupt from TEE to REE, or REE to TEE, false otherwise.
- *
- *   Interrupt nesting between TEE and REE can be determined based
- *   on the S and ES bits of EXC_RETURN
- *   If TEE interrupts REE, then EXC_RETURN.S=0, EXC_RETURN.ES=1;
- *   Conversely, EXC_RETURN.S=1, EXC_RETURN.ES=0.
- *
- *   But only one level nesting between TEE and REE is supported, and
- *   recursive nesting between TEE and REE is not supported.
- *
+ * Public Functions
  ****************************************************************************/
 
-static inline bool arm_from_thread(uint32_t excret)
+void exception_direct(void)
 {
-  if (excret & EXC_RETURN_THREAD_MODE)
-    {
-      return true;
-    }
+  int irq = getipsr();
 
-#if defined(CONFIG_ARCH_TRUSTZONE_SECURE)
-  if (!(excret & EXC_RETURN_SECURE_STACK) &&
-      (excret & EXC_RETURN_EXC_SECURE))
-    {
-      return true;
-    }
+  arm_ack_irq(irq);
+  irq_dispatch(irq, NULL);
 
-  if (!(excret & EXC_RETURN_EXC_SECURE) &&
-      (excret & EXC_RETURN_SECURE_STACK))
+  if (g_running_tasks[this_cpu()] != this_task())
     {
-      return true;
+      up_trigger_irq(NVIC_IRQ_PENDSV, 0);
     }
-#endif
-
-  return false;
 }
 
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
 uint32_t *arm_doirq(int irq, uint32_t *regs)
 {
   struct tcb_s *tcb = this_task();
@@ -98,19 +63,20 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
   PANIC();
 #else
 
-  if (arm_from_thread(regs[REG_EXC_RETURN]))
-    {
-      tcb->xcp.regs = regs;
-      up_set_current_regs(regs);
-    }
-
   /* Acknowledge the interrupt */
 
   arm_ack_irq(irq);
 
-  /* Deliver the IRQ */
-
-  irq_dispatch(irq, regs);
+  if (irq == NVIC_IRQ_PENDSV)
+    {
+      up_irq_save();
+      g_running_tasks[this_cpu()]->xcp.regs = regs;
+    }
+  else
+    {
+      tcb->xcp.regs = regs;
+      irq_dispatch(irq, regs);
+    }
 
   /* If a context switch occurred while processing the interrupt then
    * current_regs may have change value.  If we return any value different
@@ -118,30 +84,20 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
    * switch occurred during interrupt processing.
    */
 
-  if (arm_from_thread(regs[REG_EXC_RETURN]))
-    {
-      tcb = this_task();
+  tcb = this_task();
 
-      if (regs != tcb->xcp.regs)
-        {
-          /* Update scheduler parameters */
+  /* Update scheduler parameters */
 
-          nxsched_suspend_scheduler(g_running_tasks[this_cpu()]);
-          nxsched_resume_scheduler(tcb);
+  nxsched_suspend_scheduler(g_running_tasks[this_cpu()]);
+  nxsched_resume_scheduler(tcb);
 
-          /* Record the new "running" task when context switch occurred.
-           * g_running_tasks[] is only used by assertion logic for reporting
-           * crashes.
-           */
-
-          g_running_tasks[this_cpu()] = tcb;
-          regs = tcb->xcp.regs;
-        }
-
-      /* Update the current_regs to NULL. */
+  /* Record the new "running" task when context switch occurred.
+   * g_running_tasks[] is only used by assertion logic for reporting
+   * crashes.
+   */
 
-      up_set_current_regs(NULL);
-    }
+  g_running_tasks[this_cpu()] = tcb;
+  regs = tcb->xcp.regs;
 #endif
 
   board_autoled_off(LED_INIRQ);
diff --git a/arch/arm/src/armv8-m/arm_svcall.c b/arch/arm/src/armv8-m/arm_svcall.c
index f364767c40..3af74d1ac0 100644
--- a/arch/arm/src/armv8-m/arm_svcall.c
+++ b/arch/arm/src/armv8-m/arm_svcall.c
@@ -24,6 +24,7 @@
 
 #include <nuttx/config.h>
 
+#include <inttypes.h>
 #include <stdint.h>
 #include <string.h>
 #include <assert.h>
@@ -128,7 +129,6 @@ int arm_svcall(int irq, void *context, void *arg)
   uint32_t *regs = (uint32_t *)context;
   uint32_t cmd;
 
-  DEBUGASSERT(regs && regs == up_current_regs());
   cmd = regs[REG_R0];
 
   /* The SVCall software interrupt is called with R0 = system call command
@@ -398,7 +398,6 @@ int arm_svcall(int irq, void *context, void *arg)
           /* Return privileged mode */
 
           regs[REG_CONTROL]    = getcontrol() & ~CONTROL_NPRIV;
-
           rtcb->xcp.sigreturn  = 0;
         }
         break;
@@ -447,7 +446,7 @@ int arm_svcall(int irq, void *context, void *arg)
 
           rtcb->flags         |= TCB_FLAG_SYSCALL;
 #else
-          svcerr("ERROR: Bad SYS call: %d\n", (int)regs[REG_R0]);
+          svcerr("ERROR: Bad SYS call: %" PRId32 "\n", regs[REG_R0]);
 #endif
         }
         break;
diff --git a/arch/arm/src/armv8-m/arm_vectors.c b/arch/arm/src/armv8-m/arm_vectors.c
index 75308996e1..5f83341c1b 100644
--- a/arch/arm/src/armv8-m/arm_vectors.c
+++ b/arch/arm/src/armv8-m/arm_vectors.c
@@ -40,6 +40,8 @@
 
 #include "chip.h"
 #include "arm_internal.h"
+#include "ram_vectors.h"
+#include "nvic.h"
 
 /****************************************************************************
  * Pre-processor Definitions
@@ -74,12 +76,13 @@ static void start(void)
 /* Common exception entrypoint */
 
 extern void exception_common(void);
+extern void exception_direct(void);
 
 /****************************************************************************
  * Public data
  ****************************************************************************/
 
-/* The v7m vector table consists of an array of function pointers, with the
+/* The v8m vector table consists of an array of function pointers, with the
  * first slot (vector zero) used to hold the initial stack pointer.
  *
  * As all exceptions (interrupts) are routed via exception_common, we just
@@ -100,5 +103,7 @@ const void * const _vectors[] locate_data(".vectors") =
 
   /* Vectors 2 - n point directly at the generic handler */
 
-  [2 ... (15 + ARMV8M_PERIPHERAL_INTERRUPTS)] = &exception_common
+  [2 ... NVIC_IRQ_PENDSV] = &exception_common,
+  [(NVIC_IRQ_PENDSV + 1) ... (15 + ARMV8M_PERIPHERAL_INTERRUPTS)]
+                          = &exception_direct
 };


(nuttx) 04/06: arm-M: set current regs for crash dump

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a9da6ab4b558b2a4de195d3b1991c84e04f95416
Author: ligd <li...@xiaomi.com>
AuthorDate: Tue Aug 13 18:34:16 2024 +0800

    arm-M: set current regs for crash dump
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 arch/arm/src/armv6-m/arm_doirq.c | 10 ++++++++++
 arch/arm/src/armv7-m/arm_doirq.c | 10 ++++++++++
 arch/arm/src/armv8-m/arm_doirq.c | 10 ++++++++++
 3 files changed, 30 insertions(+)

diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c
index 93703b4512..b9683a5708 100644
--- a/arch/arm/src/armv6-m/arm_doirq.c
+++ b/arch/arm/src/armv6-m/arm_doirq.c
@@ -74,8 +74,18 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
     }
   else
     {
+      /* Set current regs for crash dump */
+
+      up_set_current_regs(regs);
+
+      /* Dispatch irq */
+
       tcb->xcp.regs = regs;
       irq_dispatch(irq, regs);
+
+      /* Clear current regs */
+
+      up_set_current_regs(NULL);
     }
 
   /* If a context switch occurred while processing the interrupt then
diff --git a/arch/arm/src/armv7-m/arm_doirq.c b/arch/arm/src/armv7-m/arm_doirq.c
index b74414c59a..2f532969a5 100644
--- a/arch/arm/src/armv7-m/arm_doirq.c
+++ b/arch/arm/src/armv7-m/arm_doirq.c
@@ -74,8 +74,18 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
     }
   else
     {
+      /* Set current regs for crash dump */
+
+      up_set_current_regs(regs);
+
+      /* Dispatch irq */
+
       tcb->xcp.regs = regs;
       irq_dispatch(irq, regs);
+
+      /* Clear current regs */
+
+      up_set_current_regs(NULL);
     }
 
   /* If a context switch occurred while processing the interrupt then
diff --git a/arch/arm/src/armv8-m/arm_doirq.c b/arch/arm/src/armv8-m/arm_doirq.c
index 536d7c4e75..d024d1ebad 100644
--- a/arch/arm/src/armv8-m/arm_doirq.c
+++ b/arch/arm/src/armv8-m/arm_doirq.c
@@ -74,8 +74,18 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
     }
   else
     {
+      /* Set current regs for crash dump */
+
+      up_set_current_regs(regs);
+
+      /* Dispatch irq */
+
       tcb->xcp.regs = regs;
       irq_dispatch(irq, regs);
+
+      /* Clear current regs */
+
+      up_set_current_regs(NULL);
     }
 
   /* If a context switch occurred while processing the interrupt then


(nuttx) 06/06: Doc: add maskable nested interrupt description

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit c00d47767118785eec1aab2433ec87229af6a489
Author: ligd <li...@xiaomi.com>
AuthorDate: Wed Oct 9 21:47:43 2024 +0800

    Doc: add maskable nested interrupt description
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 Documentation/guides/zerolatencyinterrupts.rst | 62 ++++++++++++++++++++++++--
 1 file changed, 59 insertions(+), 3 deletions(-)

diff --git a/Documentation/guides/zerolatencyinterrupts.rst b/Documentation/guides/zerolatencyinterrupts.rst
index c44a0ce23b..bd0781f75f 100644
--- a/Documentation/guides/zerolatencyinterrupts.rst
+++ b/Documentation/guides/zerolatencyinterrupts.rst
@@ -1,6 +1,6 @@
-=========================================
-High Performance, Zero Latency Interrupts
-=========================================
+=====================================================================
+High Performance: Zero Latency Interrupts, Maskable nested interrupts
+=====================================================================
 
 Generic Interrupt Handling
 ==========================
@@ -111,6 +111,62 @@ between the high priority interrupt handler and *PendSV* interrupt
 handler. A detailed discussion of that custom logic is beyond the
 scope of this Wiki page.
 
+The following table shows the priority levels of the Cortex-M family:
+
+.. code-block::
+
+  IRQ type               Priority
+  Dataabort              0x00
+  High prio IRQ1         0x20	(Zero-latency interrupt)
+  High prio IRQ2         0x30	(Can't call OS API in ISR)
+  SVC                    0x70
+  Disable IRQ            0x80
+  (critical-section)
+  Low  prio IRQ          0xB0
+  PendSV                 0xE0
+
+As you can see, the priority levels of the zero-latency interrupts can
+beyond the critical section and SVC.
+But High prio IRQ can't call OS API.
+
+
+Maskable Nested Interrupts
+==========================
+
+The ARM Cortex-M family supports a feature called *BASEPRI* that can be
+used to disable interrupts at a priority level below a certain level.
+This feature can be used to support maskable nested interrupts.
+
+Maskable nested interrupts differ from zero-latency interrupts in
+that they obey the interrupt masking mechanisms of the system.
+For example, setting the BASEPRI register to a specific threshold will
+block all interrupts of a lower or equal priority.
+However, high-priority interrupts (such as Non-Maskable Interrupts
+or zero-latency interrupts) are unaffected by these masks.
+
+This is useful when you have a high-priority interrupt that needs to
+be able to interrupt the system, but you also have lower-priority
+interrupts that you want to be able to mask.
+
+The following table shows the priority levels of the Cortex-M family:
+
+.. code-block::
+
+  IRQ type                Priority
+  Dataabort               0x00
+  SVC                     0x70
+  Disable IRQ             0x80
+  (critical-section)
+  High prio IRQ1          0x90    (Maskable nested interrupt)
+  High prio IRQ2          0xA0    (Can call OS API in ISR)
+  Low  prio IRQ           0xB0
+  PendSV                  0xE0
+
+As you can see, the priority levels of the maskable nested interrupts
+are between the critical section and the low-priority interrupts.
+And High prio IRQ can call OS API in ISR.
+
+
 Nested Interrupt Handling
 =========================
 


(nuttx) 01/06: armv7/8m: unmask all the IRQ when thread start

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f20ae064b0bfe91c13140497ddbd65ece6562363
Author: ligd <li...@xiaomi.com>
AuthorDate: Wed Apr 24 15:39:18 2024 +0800

    armv7/8m: unmask all the IRQ when thread start
    
    NVIC_SYSH_PRIORITY_MIN not the basepri loweest prio
    spec says:
    basepri 0 - Disables masking by BASEPRI
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 arch/arm/include/armv7-m/irq.h          | 2 +-
 arch/arm/include/armv8-m/irq.h          | 2 +-
 arch/arm/src/armv7-m/arm_initialstate.c | 2 +-
 arch/arm/src/armv8-m/arm_initialstate.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/include/armv7-m/irq.h b/arch/arm/include/armv7-m/irq.h
index c387899f60..87cf6e0acf 100644
--- a/arch/arm/include/armv7-m/irq.h
+++ b/arch/arm/include/armv7-m/irq.h
@@ -440,7 +440,7 @@ static inline void up_irq_enable(void)
 {
   /* In this case, we are always retaining or lowering the priority value */
 
-  setbasepri(NVIC_SYSH_PRIORITY_MIN);
+  setbasepri(0);
   __asm__ __volatile__ ("\tcpsie  i\n");
 }
 
diff --git a/arch/arm/include/armv8-m/irq.h b/arch/arm/include/armv8-m/irq.h
index fb23d569b7..0860ae960c 100644
--- a/arch/arm/include/armv8-m/irq.h
+++ b/arch/arm/include/armv8-m/irq.h
@@ -413,7 +413,7 @@ static inline void up_irq_enable(void)
 {
   /* In this case, we are always retaining or lowering the priority value */
 
-  setbasepri(NVIC_SYSH_PRIORITY_MIN);
+  setbasepri(0);
   __asm__ __volatile__ ("\tcpsie  i\n");
 }
 
diff --git a/arch/arm/src/armv7-m/arm_initialstate.c b/arch/arm/src/armv7-m/arm_initialstate.c
index 4e6127ff81..4baec4aee4 100644
--- a/arch/arm/src/armv7-m/arm_initialstate.c
+++ b/arch/arm/src/armv7-m/arm_initialstate.c
@@ -163,7 +163,7 @@ void up_initial_state(struct tcb_s *tcb)
 #else /* CONFIG_SUPPRESS_INTERRUPTS */
 
 #ifdef CONFIG_ARMV7M_USEBASEPRI
-  xcp->regs[REG_BASEPRI] = NVIC_SYSH_PRIORITY_MIN;
+  xcp->regs[REG_BASEPRI] = 0;
 #endif
 
 #endif /* CONFIG_SUPPRESS_INTERRUPTS */
diff --git a/arch/arm/src/armv8-m/arm_initialstate.c b/arch/arm/src/armv8-m/arm_initialstate.c
index fa2cf96718..4916fc36ea 100644
--- a/arch/arm/src/armv8-m/arm_initialstate.c
+++ b/arch/arm/src/armv8-m/arm_initialstate.c
@@ -169,7 +169,7 @@ void up_initial_state(struct tcb_s *tcb)
 #else /* CONFIG_SUPPRESS_INTERRUPTS */
 
 #ifdef CONFIG_ARMV8M_USEBASEPRI
-  xcp->regs[REG_BASEPRI] = NVIC_SYSH_PRIORITY_MIN;
+  xcp->regs[REG_BASEPRI] = 0;
 #endif
 
 #endif /* CONFIG_SUPPRESS_INTERRUPTS */


(nuttx) 02/06: armv6m: add up_trigger_irq() support

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f221c9ecb436a32ecd14f54053d241722a1816a9
Author: ligd <li...@xiaomi.com>
AuthorDate: Fri Aug 9 22:33:40 2024 +0800

    armv6m: add up_trigger_irq() support
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 arch/arm/Kconfig                       |  1 +
 arch/arm/src/armv6-m/CMakeLists.txt    |  1 +
 arch/arm/src/armv6-m/Make.defs         |  1 +
 arch/arm/src/armv6-m/arm_trigger_irq.c | 87 ++++++++++++++++++++++++++++++++++
 arch/arm/src/armv6-m/nvic.h            | 25 ++++++++++
 5 files changed, 115 insertions(+)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 51e51207e5..605824ddb4 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -819,6 +819,7 @@ config ARCH_CORTEXM0
 	select ARM_THUMB
 	select ARCH_ARMV6M
 	select ARCH_HAVE_IRQPRIO
+	select ARCH_HAVE_IRQTRIGGER
 	select ARCH_HAVE_RAMVECTORS
 	select ARCH_HAVE_RESET
 	select ARCH_HAVE_HARDFAULT_DEBUG
diff --git a/arch/arm/src/armv6-m/CMakeLists.txt b/arch/arm/src/armv6-m/CMakeLists.txt
index deffc19040..6bfb544929 100644
--- a/arch/arm/src/armv6-m/CMakeLists.txt
+++ b/arch/arm/src/armv6-m/CMakeLists.txt
@@ -29,6 +29,7 @@ set(SRCS
     arm_svcall.c
     arm_systemreset.c
     arm_tcbinfo.c
+    arm_trigger_irq.c
     arm_vectors.c)
 
 if(CONFIG_DEBUG_FEATURES)
diff --git a/arch/arm/src/armv6-m/Make.defs b/arch/arm/src/armv6-m/Make.defs
index 669a586cef..9a39ab04bf 100644
--- a/arch/arm/src/armv6-m/Make.defs
+++ b/arch/arm/src/armv6-m/Make.defs
@@ -27,6 +27,7 @@ CMN_ASRCS += arm_exception.S arm_saveusercontext.S
 CMN_CSRCS += arm_cpuinfo.c arm_doirq.c arm_hardfault.c arm_initialstate.c
 CMN_CSRCS += arm_schedulesigaction.c arm_sigdeliver.c arm_svcall.c
 CMN_CSRCS += arm_systemreset.c arm_tcbinfo.c arm_vectors.c
+CMN_CSRCS += arm_trigger_irq.c
 
 ifeq ($(CONFIG_DEBUG_FEATURES),y)
   CMN_CSRCS += arm_dumpnvic.c
diff --git a/arch/arm/src/armv6-m/arm_trigger_irq.c b/arch/arm/src/armv6-m/arm_trigger_irq.c
new file mode 100644
index 0000000000..397a18705d
--- /dev/null
+++ b/arch/arm/src/armv6-m/arm_trigger_irq.c
@@ -0,0 +1,87 @@
+/****************************************************************************
+ * arch/arm/src/armv6-m/arm_trigger_irq.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <assert.h>
+
+#include <nuttx/arch.h>
+#include <arch/irq.h>
+
+#include "arm_internal.h"
+#include "nvic.h"
+
+#ifdef CONFIG_ARCH_HAVE_IRQTRIGGER
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_trigger_irq
+ *
+ * Description:
+ *   Trigger an IRQ by software.
+ *
+ ****************************************************************************/
+
+void up_trigger_irq(int irq, cpu_set_t cpuset)
+{
+  uint32_t pend_bit = 0;
+
+  DEBUGASSERT(irq >= NVIC_IRQ_NMI && irq < NR_IRQS);
+
+  if (irq >= NVIC_IRQ_FIRST)
+    {
+      putreg32(irq - NVIC_IRQ_FIRST, ARMV6M_NVIC2_BASE);
+    }
+  else
+    {
+      switch (irq)
+        {
+          case NVIC_IRQ_PENDSV:
+            pend_bit = SYSCON_ICSR_PENDSVSET;
+            break;
+
+          case NVIC_IRQ_NMI:
+            pend_bit = SYSCON_ICSR_NMIPENDSET;
+            break;
+
+          case NVIC_IRQ_SYSTICK:
+            pend_bit = SYSCON_ICSR_PENDSTSET;
+            break;
+
+          default:
+            break;
+        }
+
+      if (pend_bit)
+        {
+          modifyreg32(ARMV6M_SYSCON_ICSR, 0, pend_bit);
+        }
+    }
+}
+
+#endif /* CONFIG_ARCH_HAVE_IRQTRIGGER */
diff --git a/arch/arm/src/armv6-m/nvic.h b/arch/arm/src/armv6-m/nvic.h
index 62be901b69..3296006884 100644
--- a/arch/arm/src/armv6-m/nvic.h
+++ b/arch/arm/src/armv6-m/nvic.h
@@ -32,6 +32,31 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Exception/interrupt vector numbers ***************************************/
+
+                                              /* Vector  0: Reset stack
+                                               *            pointer value
+                                               */
+
+                                               /* Vector  1: Reset */
+#define NVIC_IRQ_NMI                    (2)    /* Vector  2: Non-Maskable Interrupt (NMI) */
+#define NVIC_IRQ_HARDFAULT              (3)    /* Vector  3: Hard fault */
+#define NVIC_IRQ_MEMFAULT               (4)    /* Vector  4: Memory management (MPU) */
+#define NVIC_IRQ_BUSFAULT               (5)    /* Vector  5: Bus fault */
+#define NVIC_IRQ_USAGEFAULT             (6)    /* Vector  6: Usage fault */
+                                               /* Vectors 7-10: Reserved */
+#define NVIC_IRQ_SVCALL                 (11)   /* Vector 11: SVC call */
+#define NVIC_IRQ_DBGMONITOR             (12)   /* Vector 12: Debug Monitor */
+                                               /* Vector 13: Reserved */
+#define NVIC_IRQ_PENDSV                 (14)   /* Vector 14: Pendable system service request */
+#define NVIC_IRQ_SYSTICK                (15)   /* Vector 15: System tick */
+
+/* External interrupts (vectors >= 16).
+ * These definitions are chip-specific
+ */
+
+#define NVIC_IRQ_FIRST                  (16)    /* Vector number of the first interrupt */
+
 /* Base addresses ***********************************************************/
 
 #define ARMV6M_SYSCON1_BASE            0xe000e008 /* 0xe000e008-0xe000e00f System Control Block */


(nuttx) 05/06: arm-m: support zero interrupt back to game

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ff99745b2212fb20705ac93c787e1c5409eda465
Author: ligd <li...@xiaomi.com>
AuthorDate: Fri Sep 27 18:48:47 2024 +0800

    arm-m: support zero interrupt back to game
    
    Signed-off-by: ligd <li...@xiaomi.com>
---
 arch/arm/src/armv6-m/arm_doirq.c         | 23 +++++++++++++++--------
 arch/arm/src/armv7-m/arm_doirq.c         | 23 +++++++++++++++--------
 arch/arm/src/armv8-m/arm_doirq.c         | 22 ++++++++++++++--------
 arch/arm/src/lpc17xx_40xx/lpc17_40_irq.c |  2 ++
 arch/arm/src/mps/mps_irq.c               |  2 ++
 arch/arm/src/nrf52/nrf52_irq.c           |  2 ++
 arch/arm/src/stm32/stm32_irq.c           |  2 ++
 arch/arm/src/stm32l4/stm32l4_irq.c       |  2 ++
 8 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/arch/arm/src/armv6-m/arm_doirq.c b/arch/arm/src/armv6-m/arm_doirq.c
index b9683a5708..fea1620bd2 100644
--- a/arch/arm/src/armv6-m/arm_doirq.c
+++ b/arch/arm/src/armv6-m/arm_doirq.c
@@ -67,25 +67,27 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
 
   arm_ack_irq(irq);
 
+  /* Set current regs for crash dump */
+
+  up_set_current_regs(regs);
+
   if (irq == NVIC_IRQ_PENDSV)
     {
+#ifdef CONFIG_ARCH_HIPRI_INTERRUPT
+      /* Dispatch the PendSV interrupt */
+
+      irq_dispatch(irq, regs);
+#endif
+
       up_irq_save();
       g_running_tasks[this_cpu()]->xcp.regs = regs;
     }
   else
     {
-      /* Set current regs for crash dump */
-
-      up_set_current_regs(regs);
-
       /* Dispatch irq */
 
       tcb->xcp.regs = regs;
       irq_dispatch(irq, regs);
-
-      /* Clear current regs */
-
-      up_set_current_regs(NULL);
     }
 
   /* If a context switch occurred while processing the interrupt then
@@ -110,6 +112,11 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
   regs = tcb->xcp.regs;
 #endif
 
+  /* Clear current regs */
+
+  up_set_current_regs(NULL);
+
   board_autoled_off(LED_INIRQ);
+
   return regs;
 }
diff --git a/arch/arm/src/armv7-m/arm_doirq.c b/arch/arm/src/armv7-m/arm_doirq.c
index 2f532969a5..a14b24e6a4 100644
--- a/arch/arm/src/armv7-m/arm_doirq.c
+++ b/arch/arm/src/armv7-m/arm_doirq.c
@@ -67,25 +67,27 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
 
   arm_ack_irq(irq);
 
+  /* Set current regs for crash dump */
+
+  up_set_current_regs(regs);
+
   if (irq == NVIC_IRQ_PENDSV)
     {
+#ifdef CONFIG_ARCH_HIPRI_INTERRUPT
+      /* Dispatch the PendSV interrupt */
+
+      irq_dispatch(irq, regs);
+#endif
+
       up_irq_save();
       g_running_tasks[this_cpu()]->xcp.regs = regs;
     }
   else
     {
-      /* Set current regs for crash dump */
-
-      up_set_current_regs(regs);
-
       /* Dispatch irq */
 
       tcb->xcp.regs = regs;
       irq_dispatch(irq, regs);
-
-      /* Clear current regs */
-
-      up_set_current_regs(NULL);
     }
 
   /* If a context switch occurred while processing the interrupt then
@@ -110,6 +112,11 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
   regs = tcb->xcp.regs;
 #endif
 
+  /* Clear current regs */
+
+  up_set_current_regs(NULL);
+
   board_autoled_off(LED_INIRQ);
+
   return regs;
 }
diff --git a/arch/arm/src/armv8-m/arm_doirq.c b/arch/arm/src/armv8-m/arm_doirq.c
index d024d1ebad..0f3fad50bb 100644
--- a/arch/arm/src/armv8-m/arm_doirq.c
+++ b/arch/arm/src/armv8-m/arm_doirq.c
@@ -67,25 +67,27 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
 
   arm_ack_irq(irq);
 
+  /* Set current regs for crash dump */
+
+  up_set_current_regs(regs);
+
   if (irq == NVIC_IRQ_PENDSV)
     {
+#ifdef CONFIG_ARCH_HIPRI_INTERRUPT
+      /* Dispatch the PendSV interrupt */
+
+      irq_dispatch(irq, regs);
+#endif
+
       up_irq_save();
       g_running_tasks[this_cpu()]->xcp.regs = regs;
     }
   else
     {
-      /* Set current regs for crash dump */
-
-      up_set_current_regs(regs);
-
       /* Dispatch irq */
 
       tcb->xcp.regs = regs;
       irq_dispatch(irq, regs);
-
-      /* Clear current regs */
-
-      up_set_current_regs(NULL);
     }
 
   /* If a context switch occurred while processing the interrupt then
@@ -110,6 +112,10 @@ uint32_t *arm_doirq(int irq, uint32_t *regs)
   regs = tcb->xcp.regs;
 #endif
 
+  /* Clear current regs */
+
+  up_set_current_regs(NULL);
+
   board_autoled_off(LED_INIRQ);
 
 #ifdef CONFIG_ARMV8M_TRUSTZONE_HYBRID
diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_irq.c b/arch/arm/src/lpc17xx_40xx/lpc17_40_irq.c
index d0f1316568..7c971c81fb 100644
--- a/arch/arm/src/lpc17xx_40xx/lpc17_40_irq.c
+++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_irq.c
@@ -137,9 +137,11 @@ static int lpc17_40_nmi(int irq, void *context, void *arg)
 
 static int lpc17_40_pendsv(int irq, void *context, void *arg)
 {
+#ifndef CONFIG_ARCH_HIPRI_INTERRUPT
   up_irq_save();
   _err("PANIC!!! PendSV received\n");
   PANIC();
+#endif
   return 0;
 }
 
diff --git a/arch/arm/src/mps/mps_irq.c b/arch/arm/src/mps/mps_irq.c
index c6091959ee..1e882bbafa 100644
--- a/arch/arm/src/mps/mps_irq.c
+++ b/arch/arm/src/mps/mps_irq.c
@@ -61,9 +61,11 @@ static int mps_nmi(int irq, void *context, void *arg)
 
 static int mps_pendsv(int irq, void *context, void *arg)
 {
+#ifndef CONFIG_ARCH_HIPRI_INTERRUPT
   up_irq_save();
   _err("PANIC!!! PendSV received\n");
   PANIC();
+#endif
   return 0;
 }
 
diff --git a/arch/arm/src/nrf52/nrf52_irq.c b/arch/arm/src/nrf52/nrf52_irq.c
index 7c400bbf9c..2e916afc72 100644
--- a/arch/arm/src/nrf52/nrf52_irq.c
+++ b/arch/arm/src/nrf52/nrf52_irq.c
@@ -143,9 +143,11 @@ static int nrf52_nmi(int irq, void *context, void *arg)
 
 static int nrf52_pendsv(int irq, void *context, void *arg)
 {
+#ifndef CONFIG_ARCH_HIPRI_INTERRUPT
   up_irq_save();
   _err("PANIC!!! PendSV received\n");
   PANIC();
+#endif
   return 0;
 }
 
diff --git a/arch/arm/src/stm32/stm32_irq.c b/arch/arm/src/stm32/stm32_irq.c
index 99374e5db7..7a63323a37 100644
--- a/arch/arm/src/stm32/stm32_irq.c
+++ b/arch/arm/src/stm32/stm32_irq.c
@@ -148,9 +148,11 @@ static int stm32_nmi(int irq, void *context, void *arg)
 
 static int stm32_pendsv(int irq, void *context, void *arg)
 {
+#ifndef CONFIG_ARCH_HIPRI_INTERRUPT
   up_irq_save();
   _err("PANIC!!! PendSV received\n");
   PANIC();
+#endif
   return 0;
 }
 
diff --git a/arch/arm/src/stm32l4/stm32l4_irq.c b/arch/arm/src/stm32l4/stm32l4_irq.c
index e8c0031550..8499204741 100644
--- a/arch/arm/src/stm32l4/stm32l4_irq.c
+++ b/arch/arm/src/stm32l4/stm32l4_irq.c
@@ -145,9 +145,11 @@ static int stm32l4_nmi(int irq, void *context, void *arg)
 
 static int stm32l4_pendsv(int irq, void *context, void *arg)
 {
+#ifndef CONFIG_ARCH_HIPRI_INTERRUPT
   up_irq_save();
   _err("PANIC!!! PendSV received\n");
   PANIC();
+#endif
   return 0;
 }