From 6838f43e99626466b6537e886088f681e853eef8 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 27 Oct 2025 13:47:11 -0700 Subject: [PATCH 1/6] Prefer xTaskDelayUntil in config template xTaskDelayUntil is more featured and should be preferred by new users. This change was inspired by https://forums.freertos.org/t/include-xtaskdelayuntil-vs-include-vtaskdelayuntil/24656. --- examples/template_configuration/FreeRTOSConfig.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/template_configuration/FreeRTOSConfig.h b/examples/template_configuration/FreeRTOSConfig.h index 5521adb4d3..da1ad8a286 100644 --- a/examples/template_configuration/FreeRTOSConfig.h +++ b/examples/template_configuration/FreeRTOSConfig.h @@ -653,7 +653,7 @@ #define INCLUDE_uxTaskPriorityGet 1 #define INCLUDE_vTaskDelete 1 #define INCLUDE_vTaskSuspend 1 -#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_xTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 #define INCLUDE_xTaskGetSchedulerState 1 #define INCLUDE_xTaskGetCurrentTaskHandle 1 From c1d93c7cdd4973735dfffda19c4251e0349f7c9a Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Fri, 25 Jul 2025 16:55:00 -0700 Subject: [PATCH 2/6] [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 4af1fb832c..4a51f6c7fc 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 8b04970865..a76099e185 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 45d332f972347df422a0557ed85642eaaad92d48 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 11 Aug 2025 13:22:43 -0700 Subject: [PATCH 3/6] 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 4a51f6c7fc..56099800ce 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 d82e32d25a24144633654343080be76014f84c80 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 11 Aug 2025 14:04:33 -0700 Subject: [PATCH 4/6] 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 56099800ce..5d827c0453 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 40f51fd08f01d417e4072d1762694b9aeff94b0d Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Mon, 11 Aug 2025 14:12:43 -0700 Subject: [PATCH 5/6] 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 5d827c0453..f9a88fb60f 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 a76099e185..6401739429 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 } From 3bfd03b2011b17a29988b1d06591fe395dce81a5 Mon Sep 17 00:00:00 2001 From: Kody Stribrny Date: Wed, 26 Nov 2025 13:20:37 -0800 Subject: [PATCH 6/6] Verify EXL bit only --- portable/MPLAB/PIC32MZ/port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portable/MPLAB/PIC32MZ/port.c b/portable/MPLAB/PIC32MZ/port.c index f9a88fb60f..9d179335e3 100644 --- a/portable/MPLAB/PIC32MZ/port.c +++ b/portable/MPLAB/PIC32MZ/port.c @@ -382,7 +382,7 @@ portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void ) /* Obtain the number of the currently executing interrupt. */ __asm volatile("mfc0 %0, $12" : "=r" (ulCurrentInterrupt)); - if( ulCurrentInterrupt == 0 ) + if( ( ulCurrentInterrupt && portEXL_BIT ) != 0U ) { xReturn = pdFALSE; }