From 7389f68fb4172b9e1df73c52d061e95733b6b031 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Fri, 25 Jul 2025 16:55:00 -0700 Subject: [PATCH 1/4] [Work In Progress] Adding the xPortIsInsideInterrupt to the PIC32MZ port --- portable/MPLAB/PIC32MZ/port.c | 22 ++++++++++++++++++++++ portable/MPLAB/PIC32MZ/portmacro.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/portable/MPLAB/PIC32MZ/port.c b/portable/MPLAB/PIC32MZ/port.c index 4af1fb832c1..4a51f6c7fc5 100644 --- a/portable/MPLAB/PIC32MZ/port.c +++ b/portable/MPLAB/PIC32MZ/port.c @@ -372,3 +372,25 @@ void vPortClearInterruptMaskFromISR( UBaseType_t uxSavedStatusRegister ) #endif /* __mips_hard_float == 1 */ /*-----------------------------------------------------------*/ + +__attribute__((always_inline)) static BaseType_t xPortIsInsideInterrupt( void ) +{ + uint32_t ulCurrentInterrupt; + BaseType_t xReturn; + + /* Obtain the number of the currently executing interrupt. */ + __asm volatile("mfc0 %0, $12" : "=r" (ulCurrentInterrupt)); + + if( ulCurrentInterrupt == 0 ) + { + xReturn = pdFALSE; + } + else + { + xReturn = pdTRUE; + } + + return xReturn; +} + +/*-----------------------------------------------------------*/ diff --git a/portable/MPLAB/PIC32MZ/portmacro.h b/portable/MPLAB/PIC32MZ/portmacro.h index 8b049708652..a76099e1855 100644 --- a/portable/MPLAB/PIC32MZ/portmacro.h +++ b/portable/MPLAB/PIC32MZ/portmacro.h @@ -146,6 +146,8 @@ extern void vPortClearInterruptMaskFromISR( UBaseType_t ); #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR() #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusRegister ) vPortClearInterruptMaskFromISR( uxSavedStatusRegister ) +extern BaseType_t xPortIsInsideInterrupt( void ); + #if ( __mips_hard_float == 0 ) && ( configUSE_TASK_FPU_SUPPORT == 1 ) #error configUSE_TASK_FPU_SUPPORT can only be set to 1 when the part supports a hardware FPU module. #endif From d78094f2810841f1d035eb5f4cdb2a3410a89f03 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 11 Aug 2025 13:22:43 -0700 Subject: [PATCH 2/4] Add declaration before definition --- portable/MPLAB/PIC32MZ/port.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/portable/MPLAB/PIC32MZ/port.c b/portable/MPLAB/PIC32MZ/port.c index 4a51f6c7fc5..56099800ce8 100644 --- a/portable/MPLAB/PIC32MZ/port.c +++ b/portable/MPLAB/PIC32MZ/port.c @@ -144,6 +144,14 @@ static void prvTaskExitError( void ); /*-----------------------------------------------------------*/ + +/* + * Used to determine if the port is in an interrupt. + */ +__attribute__((always_inline)) static BaseType_t xPortIsInsideInterrupt( void ); + +/*-----------------------------------------------------------*/ + /* Records the interrupt nesting depth. This is initialised to one as it is decremented to 0 when the first task starts. */ volatile UBaseType_t uxInterruptNesting = 0x01; @@ -219,6 +227,7 @@ static void prvTaskExitError( void ) portDISABLE_INTERRUPTS(); for( ;; ); } + /*-----------------------------------------------------------*/ /* From 268f8fca88a3c1661c6cf286597272db6db79c24 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 11 Aug 2025 14:04:33 -0700 Subject: [PATCH 3/4] Further clean up --- portable/MPLAB/PIC32MZ/port.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/portable/MPLAB/PIC32MZ/port.c b/portable/MPLAB/PIC32MZ/port.c index 56099800ce8..5d827c0453c 100644 --- a/portable/MPLAB/PIC32MZ/port.c +++ b/portable/MPLAB/PIC32MZ/port.c @@ -144,14 +144,6 @@ static void prvTaskExitError( void ); /*-----------------------------------------------------------*/ - -/* - * Used to determine if the port is in an interrupt. - */ -__attribute__((always_inline)) static BaseType_t xPortIsInsideInterrupt( void ); - -/*-----------------------------------------------------------*/ - /* Records the interrupt nesting depth. This is initialised to one as it is decremented to 0 when the first task starts. */ volatile UBaseType_t uxInterruptNesting = 0x01; @@ -382,7 +374,7 @@ void vPortClearInterruptMaskFromISR( UBaseType_t uxSavedStatusRegister ) /*-----------------------------------------------------------*/ -__attribute__((always_inline)) static BaseType_t xPortIsInsideInterrupt( void ) +__attribute__((always_inline)) BaseType_t xPortIsInsideInterrupt( void ) { uint32_t ulCurrentInterrupt; BaseType_t xReturn; From 1143e6ce6ed771952e2867876a4ed28d5387d98c Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 11 Aug 2025 14:12:43 -0700 Subject: [PATCH 4/4] Inline as a macro --- portable/MPLAB/PIC32MZ/port.c | 2 +- portable/MPLAB/PIC32MZ/portmacro.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/portable/MPLAB/PIC32MZ/port.c b/portable/MPLAB/PIC32MZ/port.c index 5d827c0453c..f9a88fb60ff 100644 --- a/portable/MPLAB/PIC32MZ/port.c +++ b/portable/MPLAB/PIC32MZ/port.c @@ -374,7 +374,7 @@ void vPortClearInterruptMaskFromISR( UBaseType_t uxSavedStatusRegister ) /*-----------------------------------------------------------*/ -__attribute__((always_inline)) BaseType_t xPortIsInsideInterrupt( void ) +portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void ) { uint32_t ulCurrentInterrupt; BaseType_t xReturn; diff --git a/portable/MPLAB/PIC32MZ/portmacro.h b/portable/MPLAB/PIC32MZ/portmacro.h index a76099e1855..64017394292 100644 --- a/portable/MPLAB/PIC32MZ/portmacro.h +++ b/portable/MPLAB/PIC32MZ/portmacro.h @@ -223,6 +223,10 @@ extern volatile UBaseType_t uxInterruptNesting; #define portREMOVE_STATIC_QUALIFIER #endif +#ifndef portFORCE_INLINE + #define portFORCE_INLINE __attribute__( ( always_inline ) ) +#endif + /* *INDENT-OFF* */ #ifdef __cplusplus }