]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c
Update PIC32 demo application to remove reliance on PLIB functions.
[freertos] / FreeRTOS / Source / portable / RVDS / ARM_CM4F / port.c
index 147ebcbdff3d3d69c9a180b5a455085d2830e85c..592fc25996c9fca315e4c25eacf70ae728fb67d8 100644 (file)
@@ -426,19 +426,28 @@ void xPortSysTickHandler( void )
                kernel with respect to calendar time. */\r
                portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT;\r
 \r
-               /* If a context switch is pending then abandon the low power entry as\r
-               the context switch might have been pended by an external interrupt that\r
-               requires processing. */\r
-               if( ( portNVIC_INT_CTRL_REG & portNVIC_PENDSVSET_BIT ) != 0 )\r
+               /* Adjust the reload value to take into account that the current\r
+               time slice is already partially complete. */\r
+               ulReloadValue += ( portNVIC_SYSTICK_LOAD_REG - ( portNVIC_SYSTICK_LOAD_REG - portNVIC_SYSTICK_CURRENT_VALUE_REG ) );\r
+\r
+               /* Enter a critical section but don't use the taskENTER_CRITICAL()\r
+               method as that will mask interrupts that should exit sleep mode. */\r
+               __disable_irq();\r
+               \r
+               /* If a context switch is pending or a task is waiting for the scheduler\r
+               to be unsuspended then abandon the low power entry. */\r
+               if( eTaskConfirmSleepModeStatus() == eAbortSleep )\r
                {\r
                        /* Restart SysTick. */\r
                        portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+\r
+                       /* Re-enable interrupts - see comments above __disable_irq() call \r
+                       above. */\r
+                       __enable_irq();\r
                }\r
                else\r
                {\r
-                       /* Adjust the reload value to take into account that the current\r
-                       time slice is already partially complete. */\r
-                       ulReloadValue += ( portNVIC_SYSTICK_LOAD_REG - ( portNVIC_SYSTICK_LOAD_REG - portNVIC_SYSTICK_CURRENT_VALUE_REG ) );\r
+                       /* Set the new reload value. */\r
                        portNVIC_SYSTICK_LOAD_REG = ulReloadValue;\r
 \r
                        /* Clear the SysTick count flag and set the count value back to\r
@@ -467,6 +476,10 @@ void xPortSysTickHandler( void )
                        kernel with respect to calendar time. */\r
                        portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT;\r
 \r
+                       /* Re-enable interrupts - see comments above __disable_irq() call \r
+                       above. */\r
+                       __enable_irq();\r
+\r
                        if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )\r
                        {\r
                                /* The tick interrupt has already executed, and the SysTick\r