]> git.sur5r.net Git - freertos/commitdiff
Implement portASSERT_IF_INTERRUPT_PRIORITY_INVALID() for PIC32.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 12 Jul 2013 19:25:21 +0000 (19:25 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 12 Jul 2013 19:25:21 +0000 (19:25 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1974 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h

index cdc532d2b15c2a93371b4ea9205b21c7b9552624..c8a07856d3b15d0f2c9b41ffd21523ff0fc78f41 100644 (file)
@@ -122,20 +122,40 @@ extern "C" {
 #define portSW0_BIT                                    ( 0x01 << 8 )\r
 \r
 /* This clears the IPL bits, then sets them to \r
-configMAX_SYSCALL_INTERRUPT_PRIORITY.  This function should not be called\r
-from an interrupt, so therefore will not be called with an IPL setting\r
-above configMAX_SYSCALL_INTERRUPT_PRIORITY.  Therefore, when used correctly, the \r
-instructions in this macro can only result in the IPL being raised, and \r
-therefore never lowered. */\r
-#define portDISABLE_INTERRUPTS()                                                                               \\r
-{                                                                                                                                              \\r
-unsigned long ulStatus;                                                                                                        \\r
-                                                                                                                                               \\r
-       /* Mask interrupts at and below the kernel interrupt priority. */       \\r
-       ulStatus = _CP0_GET_STATUS();                                                                           \\r
-       ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
-       _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \\r
-}\r
+configMAX_SYSCALL_INTERRUPT_PRIORITY.          An extra check is performed if \r
+configASSERT() is defined to ensure an assertion handler does not inadvertently \r
+attempt to lower the IPL when the call to assert was triggered because the IPL \r
+value was found to be above    configMAX_SYSCALL_INTERRUPT_PRIORITY when an ISR\r
+safe FreeRTOS API function was executed.  ISR safe FreeRTOS API functions are\r
+those that end in FromISR.  FreeRTOS maintains a separate interrupt API to\r
+ensure API function and interrupt entry is as fast and as simple as possible. */\r
+\r
+#ifdef configASSERT\r
+       #define portDISABLE_INTERRUPTS()                                                                                        \\r
+       {                                                                                                                                                       \\r
+       unsigned long ulStatus;                                                                                                         \\r
+                                                                                                                                                               \\r
+               /* Mask interrupts at and below the kernel interrupt priority. */               \\r
+               ulStatus = _CP0_GET_STATUS();                                                                                   \\r
+                                                                                                                                                               \\r
+               /* Is the current IPL below configMAX_SYSCALL_INTERRUPT_PRIORITY? */    \\r
+               if( ( ( ulStatus & portALL_IPL_BITS ) >> portIPL_SHIFT ) < configMAX_SYSCALL_INTERRUPT_PRIORITY )       \\r
+               {                                                                                                                                               \\r
+                       ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
+                       _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \\r
+               }                                                                                                                                               \\r
+       }\r
+#else\r
+       #define portDISABLE_INTERRUPTS()                                                                                \\r
+       {                                                                                                                                               \\r
+       unsigned long ulStatus;                                                                                                 \\r
+                                                                                                                                                       \\r
+               /* Mask interrupts at and below the kernel interrupt priority. */       \\r
+               ulStatus = _CP0_GET_STATUS();                                                                           \\r
+               ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
+               _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \\r
+       }\r
+#endif /* configASSERT */\r
 \r
 #define portENABLE_INTERRUPTS()                                                                                        \\r
 {                                                                                                                                              \\r
@@ -190,6 +210,11 @@ unsigned long ulStatus;                                                    \
        _CP0_SET_CAUSE( ulStatus );                                     \\r
 }\r
 \r
+#ifdef configASSERT\r
+       #define portCURRENT_INTERRUPT_PRIORITY ( ( _CP0_GET_STATUS() & portALL_IPL_BITS ) >> portIPL_SHIFT )\r
+       #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() configASSERT( portCURRENT_INTERRUPT_PRIORITY <= configMAX_SYSCALL_INTERRUPT_PRIORITY )\r
+#endif /* configASSERT */\r
+\r
 \r
 #define portNOP()      asm volatile (  "nop" )\r
 \r