From: richardbarry Date: Fri, 12 Jul 2013 19:25:21 +0000 (+0000) Subject: Implement portASSERT_IF_INTERRUPT_PRIORITY_INVALID() for PIC32. X-Git-Tag: V7.5.0~16 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b79dede09518fcb743df77a0ddd8f27ab73b4bfa;p=freertos Implement portASSERT_IF_INTERRUPT_PRIORITY_INVALID() for PIC32. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1974 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h b/FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h index cdc532d2b..c8a07856d 100644 --- a/FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h +++ b/FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h @@ -122,20 +122,40 @@ extern "C" { #define portSW0_BIT ( 0x01 << 8 ) /* This clears the IPL bits, then sets them to -configMAX_SYSCALL_INTERRUPT_PRIORITY. This function should not be called -from an interrupt, so therefore will not be called with an IPL setting -above configMAX_SYSCALL_INTERRUPT_PRIORITY. Therefore, when used correctly, the -instructions in this macro can only result in the IPL being raised, and -therefore never lowered. */ -#define portDISABLE_INTERRUPTS() \ -{ \ -unsigned long ulStatus; \ - \ - /* Mask interrupts at and below the kernel interrupt priority. */ \ - ulStatus = _CP0_GET_STATUS(); \ - ulStatus &= ~portALL_IPL_BITS; \ - _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \ -} +configMAX_SYSCALL_INTERRUPT_PRIORITY. An extra check is performed if +configASSERT() is defined to ensure an assertion handler does not inadvertently +attempt to lower the IPL when the call to assert was triggered because the IPL +value was found to be above configMAX_SYSCALL_INTERRUPT_PRIORITY when an ISR +safe FreeRTOS API function was executed. ISR safe FreeRTOS API functions are +those that end in FromISR. FreeRTOS maintains a separate interrupt API to +ensure API function and interrupt entry is as fast and as simple as possible. */ + +#ifdef configASSERT + #define portDISABLE_INTERRUPTS() \ + { \ + unsigned long ulStatus; \ + \ + /* Mask interrupts at and below the kernel interrupt priority. */ \ + ulStatus = _CP0_GET_STATUS(); \ + \ + /* Is the current IPL below configMAX_SYSCALL_INTERRUPT_PRIORITY? */ \ + if( ( ( ulStatus & portALL_IPL_BITS ) >> portIPL_SHIFT ) < configMAX_SYSCALL_INTERRUPT_PRIORITY ) \ + { \ + ulStatus &= ~portALL_IPL_BITS; \ + _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \ + } \ + } +#else + #define portDISABLE_INTERRUPTS() \ + { \ + unsigned long ulStatus; \ + \ + /* Mask interrupts at and below the kernel interrupt priority. */ \ + ulStatus = _CP0_GET_STATUS(); \ + ulStatus &= ~portALL_IPL_BITS; \ + _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \ + } +#endif /* configASSERT */ #define portENABLE_INTERRUPTS() \ { \ @@ -190,6 +210,11 @@ unsigned long ulStatus; \ _CP0_SET_CAUSE( ulStatus ); \ } +#ifdef configASSERT + #define portCURRENT_INTERRUPT_PRIORITY ( ( _CP0_GET_STATUS() & portALL_IPL_BITS ) >> portIPL_SHIFT ) + #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() configASSERT( portCURRENT_INTERRUPT_PRIORITY <= configMAX_SYSCALL_INTERRUPT_PRIORITY ) +#endif /* configASSERT */ + #define portNOP() asm volatile ( "nop" )