]> git.sur5r.net Git - freertos/commitdiff
Introduce the prvTaskExitError() function for all ARM_CMn ports.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Tue, 8 Oct 2013 11:30:40 +0000 (11:30 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Tue, 8 Oct 2013 11:30:40 +0000 (11:30 +0000)
Introduce the configTASK_RETURN_ADDRESS macro for the GCC ARM_CMn ports.
Improve time slippage penalty when entering tickless mode is abandoned.

git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2056 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Source/portable/GCC/ARM_CM0/port.c
FreeRTOS/Source/portable/GCC/ARM_CM3/port.c
FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
FreeRTOS/Source/portable/IAR/ARM_CM3/port.c
FreeRTOS/Source/portable/IAR/ARM_CM4F/portasm.s
FreeRTOS/Source/portable/RVDS/ARM_CM3/port.c
FreeRTOS/Source/portable/RVDS/ARM_CM4F/port.c

index 5aef176cf8abd3d5b80d796fa9e618dc50a2c573..acbe363bd282bbfe2305f05f20c41de197f1cde0 100644 (file)
 /* Constants required to set up the initial stack. */\r
 #define portINITIAL_XPSR                       ( 0x01000000 )\r
 \r
+/* Let the user override the pre-loading of the initial LR with the address of\r
+prvTaskExitError() in case is messes up unwinding of the stack in the\r
+debugger. */\r
+#ifdef configTASK_RETURN_ADDRESS\r
+       #define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS\r
+#else\r
+       #define portTASK_RETURN_ADDRESS prvTaskExitError\r
+#endif\r
+\r
 /* Each task maintains its own interrupt status in the critical nesting\r
 variable. */\r
 static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;\r
@@ -126,7 +135,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
        pxTopOfStack--;\r
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode;      /* PC */\r
        pxTopOfStack--;\r
-       *pxTopOfStack = ( portSTACK_TYPE ) prvTaskExitError;    /* LR */\r
+       *pxTopOfStack = ( portSTACK_TYPE ) portTASK_RETURN_ADDRESS;     /* LR */\r
        pxTopOfStack -= 5;      /* R12, R3, R2 and R1. */\r
        *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;        /* R0 */\r
        pxTopOfStack -= 8; /* R11..R4. */\r
index 741fb64b5f6aae8bd14b0fb2912f05ae04158b7e..ed7b4e5e1318ec97c35a87b108b848c8269b6512 100644 (file)
@@ -118,6 +118,15 @@ occurred while the SysTick counter is stopped during tickless idle
 calculations. */\r
 #define portMISSED_COUNTS_FACTOR                       ( 45UL )\r
 \r
+/* Let the user override the pre-loading of the initial LR with the address of\r
+prvTaskExitError() in case is messes up unwinding of the stack in the\r
+debugger. */\r
+#ifdef configTASK_RETURN_ADDRESS\r
+       #define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS\r
+#else\r
+       #define portTASK_RETURN_ADDRESS prvTaskExitError\r
+#endif\r
+\r
 /* Each task maintains its own interrupt status in the critical nesting\r
 variable. */\r
 static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;\r
@@ -141,6 +150,11 @@ void vPortSVCHandler( void ) __attribute__ (( naked ));
  */\r
 static void prvPortStartFirstTask( void ) __attribute__ (( naked ));\r
 \r
+/*\r
+ * Used to catch tasks that attempt to return from their implementing function.\r
+ */\r
+static void prvTaskExitError( void );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -191,7 +205,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
        pxTopOfStack--;\r
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode;      /* PC */\r
        pxTopOfStack--;\r
-       *pxTopOfStack = 0;      /* LR */\r
+       *pxTopOfStack = ( portSTACK_TYPE ) portTASK_RETURN_ADDRESS;     /* LR */\r
        pxTopOfStack -= 5;      /* R12, R3, R2 and R1. */\r
        *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;        /* R0 */\r
        pxTopOfStack -= 8;      /* R11, R10, R9, R8, R7, R6, R5 and R4. */\r
@@ -200,6 +214,20 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvTaskExitError( void )\r
+{\r
+       /* A function that implements a task must not exit or attempt to return to\r
+       its caller as there is nothing to return to.  If a task wants to exit it \r
+       should instead call vTaskDelete( NULL ).\r
+       \r
+       Artificially force an assert() to be triggered if configASSERT() is \r
+       defined, then stop here so application writers can catch the error. */\r
+       configASSERT( uxCriticalNesting == ~0UL );\r
+       portDISABLE_INTERRUPTS();       \r
+       for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 void vPortSVCHandler( void )\r
 {\r
        __asm volatile (\r
@@ -465,8 +493,16 @@ void xPortSysTickHandler( void )
                to be unsuspended then abandon the low power entry. */\r
                if( eTaskConfirmSleepModeStatus() == eAbortSleep )\r
                {\r
+                       /* Restart from whatever is left in the count register to complete\r
+                       this tick period. */\r
+                       portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;\r
+                       \r
                        /* Restart SysTick. */\r
                        portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+                       \r
+                       /* Reset the reload register to the value required for normal tick\r
+                       periods. */\r
+                       portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;\r
 \r
                        /* Re-enable interrupts - see comments above the cpsid instruction()\r
                        above. */\r
index e7e503f6116af76ec13632e00089da917947c8c6..0579ae92909f8f2439df40bee0cbfeb3199c3447 100644 (file)
@@ -120,6 +120,15 @@ occurred while the SysTick counter is stopped during tickless idle
 calculations. */\r
 #define portMISSED_COUNTS_FACTOR                       ( 45UL )\r
 \r
+/* Let the user override the pre-loading of the initial LR with the address of\r
+prvTaskExitError() in case is messes up unwinding of the stack in the\r
+debugger. */\r
+#ifdef configTASK_RETURN_ADDRESS\r
+       #define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS\r
+#else\r
+       #define portTASK_RETURN_ADDRESS prvTaskExitError\r
+#endif\r
+\r
 /* Each task maintains its own interrupt status in the critical nesting\r
 variable. */\r
 static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;\r
@@ -148,6 +157,11 @@ static void prvPortStartFirstTask( void ) __attribute__ (( naked ));
  */\r
  static void vPortEnableVFP( void ) __attribute__ (( naked ));\r
 \r
+/*\r
+ * Used to catch tasks that attempt to return from their implementing function.\r
+ */\r
+static void prvTaskExitError( void );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -174,7 +188,7 @@ static void prvPortStartFirstTask( void ) __attribute__ (( naked ));
 #endif /* configUSE_TICKLESS_IDLE */\r
 \r
 /*\r
- * Used by the portASSERT_IF_INTERRUPT_PRIORITY_INVALID() macro to ensure \r
+ * Used by the portASSERT_IF_INTERRUPT_PRIORITY_INVALID() macro to ensure\r
  * FreeRTOS API functions are not called from interrupts that have been assigned\r
  * a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
  */\r
@@ -202,7 +216,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
        pxTopOfStack--;\r
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode;      /* PC */\r
        pxTopOfStack--;\r
-       *pxTopOfStack = 0;      /* LR */\r
+       *pxTopOfStack = ( portSTACK_TYPE ) portTASK_RETURN_ADDRESS;     /* LR */\r
 \r
        /* Save code space by skipping register initialisation. */\r
        pxTopOfStack -= 5;      /* R12, R3, R2 and R1. */\r
@@ -219,6 +233,20 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvTaskExitError( void )\r
+{\r
+       /* A function that implements a task must not exit or attempt to return to\r
+       its caller as there is nothing to return to.  If a task wants to exit it\r
+       should instead call vTaskDelete( NULL ).\r
+\r
+       Artificially force an assert() to be triggered if configASSERT() is\r
+       defined, then stop here so application writers can catch the error. */\r
+       configASSERT( uxCriticalNesting == ~0UL );\r
+       portDISABLE_INTERRUPTS();\r
+       for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 void vPortSVCHandler( void )\r
 {\r
        __asm volatile (\r
@@ -406,7 +434,7 @@ void xPortPendSVHandler( void )
        (\r
        "       mrs r0, psp                                                     \n"\r
        "                                                                               \n"\r
-       "       ldr     r3, pxCurrentTCBConst                           \n" /* Get the location of the current TCB. */\r
+       "       ldr     r3, pxCurrentTCBConst                   \n" /* Get the location of the current TCB. */\r
        "       ldr     r2, [r3]                                                \n"\r
        "                                                                               \n"\r
        "       tst r14, #0x10                                          \n" /* Is the task using the FPU context?  If so, push high vfp registers. */\r
@@ -435,6 +463,14 @@ void xPortPendSVHandler( void )
        "       vldmiaeq r0!, {s16-s31}                         \n"\r
        "                                                                               \n"\r
        "       msr psp, r0                                                     \n"\r
+       "                                                                               \n"\r
+       #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata workaround. */\r
+               #if WORKAROUND_PMU_CM001 == 1\r
+       "                       push { r14 }                            \n"\r
+       "                       pop { pc }                                      \n"\r
+               #endif\r
+       #endif\r
+       "                                                                               \n"\r
        "       bx r14                                                          \n"\r
        "                                                                               \n"\r
        "       .align 2                                                        \n"\r
@@ -500,9 +536,17 @@ void xPortSysTickHandler( void )
                to be unsuspended then abandon the low power entry. */\r
                if( eTaskConfirmSleepModeStatus() == eAbortSleep )\r
                {\r
+                       /* Restart from whatever is left in the count register to complete\r
+                       this tick period. */\r
+                       portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;\r
+\r
                        /* Restart SysTick. */\r
                        portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
 \r
+                       /* Reset the reload register to the value required for normal tick\r
+                       periods. */\r
+                       portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;\r
+\r
                        /* Re-enable interrupts - see comments above the cpsid instruction()\r
                        above. */\r
                        __asm volatile( "cpsie i" );\r
index 981715943fd6a84402e1ec61b873c5800fbe7049..3ed02de16f265a2b43470254af73674353786b9b 100644 (file)
@@ -97,7 +97,7 @@
 #define portNVIC_PENDSV_PRI                                    ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 16UL )\r
 #define portNVIC_SYSTICK_PRI                           ( ( ( unsigned long ) configKERNEL_INTERRUPT_PRIORITY ) << 24UL )\r
 \r
-/* Constants required to check the validity of an interrupt prority. */\r
+/* Constants required to check the validity of an interrupt priority. */\r
 #define portFIRST_USER_INTERRUPT_NUMBER                ( 16 )\r
 #define portNVIC_IP_REGISTERS_OFFSET_16        ( 0xE000E3F0 )\r
 #define portAIRCR_REG                                          ( * ( ( volatile unsigned long * ) 0xE000ED0C ) )\r
@@ -146,6 +146,11 @@ void xPortSysTickHandler( void );
  */\r
 extern void vPortStartFirstTask( void );\r
 \r
+/*\r
+ * Used to catch tasks that attempt to return from their implementing function.\r
+ */\r
+static void prvTaskExitError( void );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -196,7 +201,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
        pxTopOfStack--;\r
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode;      /* PC */\r
        pxTopOfStack--;\r
-       *pxTopOfStack = 0;      /* LR */\r
+       *pxTopOfStack = ( portSTACK_TYPE ) prvTaskExitError;    /* LR */\r
        pxTopOfStack -= 5;      /* R12, R3, R2 and R1. */\r
        *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;        /* R0 */\r
        pxTopOfStack -= 8;      /* R11, R10, R9, R8, R7, R6, R5 and R4. */\r
@@ -205,6 +210,20 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvTaskExitError( void )\r
+{\r
+       /* A function that implements a task must not exit or attempt to return to\r
+       its caller as there is nothing to return to.  If a task wants to exit it \r
+       should instead call vTaskDelete( NULL ).\r
+       \r
+       Artificially force an assert() to be triggered if configASSERT() is \r
+       defined, then stop here so application writers can catch the error. */\r
+       configASSERT( uxCriticalNesting == ~0UL );\r
+       portDISABLE_INTERRUPTS();       \r
+       for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 /*\r
  * See header file for description.\r
  */\r
@@ -367,8 +386,16 @@ void xPortSysTickHandler( void )
                to be unsuspended then abandon the low power entry. */\r
                if( eTaskConfirmSleepModeStatus() == eAbortSleep )\r
                {\r
+                       /* Restart from whatever is left in the count register to complete\r
+                       this tick period. */\r
+                       portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;\r
+                       \r
                        /* Restart SysTick. */\r
                        portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+                       \r
+                       /* Reset the reload register to the value required for normal tick\r
+                       periods. */\r
+                       portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;\r
 \r
                        /* Re-enable interrupts - see comments above __disable_interrupt()\r
                        call above. */\r
index d6296e440a3e9f6f7f8f557cd88f7d5b8ebefa85..cabefbd73efcaf7aac49ccbf1cf5f639d4ebf188 100644 (file)
 /*-----------------------------------------------------------*/\r
 \r
 xPortPendSVHandler:\r
-       mrs r0, psp                                             \r
-       \r
+       mrs r0, psp\r
+\r
        /* Get the location of the current TCB. */\r
-       ldr     r3, =pxCurrentTCB                       \r
-       ldr     r2, [r3]                                                \r
+       ldr     r3, =pxCurrentTCB\r
+       ldr     r2, [r3]\r
 \r
        /* Is the task using the FPU context?  If so, push high vfp registers. */\r
        tst r14, #0x10\r
@@ -93,34 +93,42 @@ xPortPendSVHandler:
        vstmdbeq r0!, {s16-s31}\r
 \r
        /* Save the core registers. */\r
-       stmdb r0!, {r4-r11, r14}                                \r
-       \r
+       stmdb r0!, {r4-r11, r14}\r
+\r
        /* Save the new top of stack into the first member of the TCB. */\r
        str r0, [r2]\r
-       \r
+\r
        stmdb sp!, {r3, r14}\r
        mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY\r
        msr basepri, r0\r
-       bl vTaskSwitchContext                   \r
+       bl vTaskSwitchContext\r
        mov r0, #0\r
        msr basepri, r0\r
        ldmia sp!, {r3, r14}\r
 \r
        /* The first item in pxCurrentTCB is the task top of stack. */\r
-       ldr r1, [r3]    \r
+       ldr r1, [r3]\r
        ldr r0, [r1]\r
-       \r
+\r
        /* Pop the core registers. */\r
        ldmia r0!, {r4-r11, r14}\r
 \r
-       /* Is the task using the FPU context?  If so, pop the high vfp registers \r
+       /* Is the task using the FPU context?  If so, pop the high vfp registers\r
        too. */\r
        tst r14, #0x10\r
        it eq\r
        vldmiaeq r0!, {s16-s31}\r
-       \r
-       msr psp, r0                                             \r
-       bx r14                                                  \r
+\r
+       msr psp, r0\r
+\r
+       #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata */\r
+               #if WORKAROUND_PMU_CM001 == 1\r
+                       push { r14 }\r
+                       pop { pc }\r
+               #endif\r
+       #endif\r
+\r
+       bx r14\r
 \r
 \r
 /*-----------------------------------------------------------*/\r
@@ -130,7 +138,7 @@ ulPortSetInterruptMask:
        mov r1, #configMAX_SYSCALL_INTERRUPT_PRIORITY\r
        msr basepri, r1\r
        bx r14\r
-       \r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 vPortClearInterruptMask:\r
@@ -148,7 +156,7 @@ vPortSVCHandler:
        ldmia r0!, {r4-r11, r14}\r
        msr psp, r0\r
        mov r0, #0\r
-       msr     basepri, r0     \r
+       msr     basepri, r0\r
        bx r14\r
 \r
 /*-----------------------------------------------------------*/\r
@@ -170,13 +178,13 @@ vPortEnableVFP:
        /* The FPU enable bits are in the CPACR. */\r
        ldr.w r0, =0xE000ED88\r
        ldr     r1, [r0]\r
-       \r
+\r
        /* Enable CP10 and CP11 coprocessors, then save back. */\r
        orr     r1, r1, #( 0xf << 20 )\r
        str r1, [r0]\r
-       bx      r14     \r
-       \r
+       bx      r14\r
+\r
 \r
 \r
        END\r
-       \r
+\r
index e37830a5558fc488c78b2d8ef4bfaaa035de6dd1..9d1e53e677a8c7cde5e70c9323000e46bcf9e8e5 100644 (file)
@@ -154,6 +154,11 @@ void vPortSVCHandler( void );
  */\r
 static void prvStartFirstTask( void );\r
 \r
+/*\r
+ * Used to catch tasks that attempt to return from their implementing function.\r
+ */\r
+static void prvTaskExitError( void );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -204,7 +209,8 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
        pxTopOfStack--;\r
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode;      /* PC */\r
        pxTopOfStack--;\r
-       *pxTopOfStack = 0;      /* LR */\r
+       *pxTopOfStack = ( portSTACK_TYPE ) prvTaskExitError;    /* LR */\r
+\r
        pxTopOfStack -= 5;      /* R12, R3, R2 and R1. */\r
        *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;        /* R0 */\r
        pxTopOfStack -= 8;      /* R11, R10, R9, R8, R7, R6, R5 and R4. */\r
@@ -213,6 +219,20 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvTaskExitError( void )\r
+{\r
+       /* A function that implements a task must not exit or attempt to return to\r
+       its caller as there is nothing to return to.  If a task wants to exit it \r
+       should instead call vTaskDelete( NULL ).\r
+       \r
+       Artificially force an assert() to be triggered if configASSERT() is \r
+       defined, then stop here so application writers can catch the error. */\r
+       configASSERT( uxCriticalNesting == ~0UL );\r
+       portDISABLE_INTERRUPTS();       \r
+       for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 __asm void vPortSVCHandler( void )\r
 {\r
        PRESERVE8\r
@@ -442,8 +462,16 @@ void xPortSysTickHandler( void )
                to be unsuspended then abandon the low power entry. */\r
                if( eTaskConfirmSleepModeStatus() == eAbortSleep )\r
                {\r
+                       /* Restart from whatever is left in the count register to complete\r
+                       this tick period. */\r
+                       portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;\r
+                       \r
                        /* Restart SysTick. */\r
                        portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+                       \r
+                       /* Reset the reload register to the value required for normal tick\r
+                       periods. */\r
+                       portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;\r
 \r
                        /* Re-enable interrupts - see comments above __disable_irq() call\r
                        above. */\r
index eb536a209692a130ea23f1f5a98e005282fb738e..a5b81f7bc1208521e806352923f032ec2d8a9b00 100644 (file)
@@ -163,6 +163,12 @@ static void prvStartFirstTask( void );
  * Functions defined in portasm.s to enable the VFP.\r
  */\r
 static void prvEnableVFP( void );\r
+\r
+/*\r
+ * Used to catch tasks that attempt to return from their implementing function.\r
+ */\r
+static void prvTaskExitError( void );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -217,7 +223,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
        pxTopOfStack--;\r
        *pxTopOfStack = ( portSTACK_TYPE ) pxCode;      /* PC */\r
        pxTopOfStack--;\r
-       *pxTopOfStack = 0;      /* LR */\r
+       *pxTopOfStack = ( portSTACK_TYPE ) prvTaskExitError;    /* LR */\r
 \r
        /* Save code space by skipping register initialisation. */\r
        pxTopOfStack -= 5;      /* R12, R3, R2 and R1. */\r
@@ -234,6 +240,20 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvTaskExitError( void )\r
+{\r
+       /* A function that implements a task must not exit or attempt to return to\r
+       its caller as there is nothing to return to.  If a task wants to exit it \r
+       should instead call vTaskDelete( NULL ).\r
+       \r
+       Artificially force an assert() to be triggered if configASSERT() is \r
+       defined, then stop here so application writers can catch the error. */\r
+       configASSERT( uxCriticalNesting == ~0UL );\r
+       portDISABLE_INTERRUPTS();       \r
+       for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 __asm void vPortSVCHandler( void )\r
 {\r
        PRESERVE8\r
@@ -444,6 +464,14 @@ __asm void xPortPendSVHandler( void )
        vldmiaeq r0!, {s16-s31}\r
 \r
        msr psp, r0\r
+       \r
+       #ifdef WORKAROUND_PMU_CM001 /* XMC4000 specific errata */\r
+               #if WORKAROUND_PMU_CM001 == 1\r
+                       push { r14 }\r
+                       pop { pc }\r
+               #endif\r
+       #endif\r
+       \r
        bx r14\r
        nop\r
 }\r
@@ -505,8 +533,16 @@ void xPortSysTickHandler( void )
                to be unsuspended then abandon the low power entry. */\r
                if( eTaskConfirmSleepModeStatus() == eAbortSleep )\r
                {\r
+                       /* Restart from whatever is left in the count register to complete\r
+                       this tick period. */\r
+                       portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;\r
+                       \r
                        /* Restart SysTick. */\r
                        portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;\r
+                       \r
+                       /* Reset the reload register to the value required for normal tick\r
+                       periods. */\r
+                       portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;\r
 \r
                        /* Re-enable interrupts - see comments above __disable_irq() call\r
                        above. */\r