diff options
-rw-r--r-- | os/ports/GCC/ARMCMx/chcore.c | 5 | ||||
-rw-r--r-- | os/ports/GCC/ARMCMx/chcore.h | 15 |
2 files changed, 15 insertions, 5 deletions
diff --git a/os/ports/GCC/ARMCMx/chcore.c b/os/ports/GCC/ARMCMx/chcore.c index 9d0f6b060..f547ea60c 100644 --- a/os/ports/GCC/ARMCMx/chcore.c +++ b/os/ports/GCC/ARMCMx/chcore.c @@ -34,6 +34,11 @@ regarm_t _port_saved_pc;
/**
+ * @brief IRQ nesting counter. + */
+unsigned _port_irq_nesting;
+
+/**
* @brief Halts the system.
* @note The function is declared as a weak symbol, it is possible
* to redefine it in your application code.
diff --git a/os/ports/GCC/ARMCMx/chcore.h b/os/ports/GCC/ARMCMx/chcore.h index 5a8d3c9ad..80266c79b 100644 --- a/os/ports/GCC/ARMCMx/chcore.h +++ b/os/ports/GCC/ARMCMx/chcore.h @@ -202,7 +202,11 @@ struct context { * @details This macro must be inserted at the start of all IRQ handlers
* enabled to invoke system APIs.
*/
-#define PORT_IRQ_PROLOGUE()
+#define PORT_IRQ_PROLOGUE() { \
+ chSysLockFromIsr(); \
+ _port_irq_nesting++; \
+ chSysUnlockFromIsr(); \
+}
/**
* @brief IRQ epilogue code.
@@ -211,8 +215,7 @@ struct context { */
#define PORT_IRQ_EPILOGUE() { \
chSysLockFromIsr(); \
- if (((SCB_ICSR & ICSR_VECTPENDING_MASK) == 0) && \
- chSchIsRescRequiredExI()) { \
+ if ((--_port_irq_nesting == 0) && chSchIsRescRequiredExI()) { \
register struct cmxctx *ctxp asm ("r3"); \
\
asm volatile ("mrs %0, PSP" : "=r" (ctxp) : "r" (ctxp)); \
@@ -232,9 +235,10 @@ struct context { /**
* @brief Port-related initialization code.
- * @note This function is empty in this port.
*/
-#define port_init()
+#define port_init() { \
+ _port_irq_nesting = 0; \
+}
/**
* @brief Kernel-lock action.
@@ -306,6 +310,7 @@ struct context { #if !defined(__DOXYGEN__)
extern regarm_t _port_saved_pc;
+extern unsigned _port_irq_nesting;
#endif
#ifdef __cplusplus
|