From e475309b5c1e6ccb76c59e19b04085526a6e8e5e Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 29 Mar 2010 20:58:35 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1806 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/ports/GCC/ARMCMx/chcore.c | 5 +++++ os/ports/GCC/ARMCMx/chcore.h | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'os/ports') 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 @@ -33,6 +33,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 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 -- cgit v1.2.3