/* 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
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
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
*/\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
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
}\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
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
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
*/\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
#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
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
}\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
(\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
" 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
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
#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
*/\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
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
}\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
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
/*-----------------------------------------------------------*/\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
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
mov r1, #configMAX_SYSCALL_INTERRUPT_PRIORITY\r
msr basepri, r1\r
bx r14\r
- \r
+\r
/*-----------------------------------------------------------*/\r
\r
vPortClearInterruptMask:\r
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
/* 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
*/\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
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
}\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
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
* 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
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
}\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
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
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