From 9863019a0baf040f3e5abf11023d4cc4711ec202 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Fri, 25 Jul 2025 16:55:00 -0700 Subject: [PATCH] [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 4af1fb832..4a51f6c7f 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 8b0497086..a76099e18 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