\r
/* Each task maintains its own interrupt status in the critical nesting\r
variable. */\r
-unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;\r
+static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa;\r
\r
/* \r
* Setup the timer to generate the tick interrupts.\r
*pxTopOfStack = 0; /* LR */\r
pxTopOfStack -= 5; /* R12, R3, R2 and R1. */\r
*pxTopOfStack = ( portSTACK_TYPE ) pvParameters; /* R0 */\r
- pxTopOfStack -= 9; /* R11, R10, R9, R8, R7, R6, R5 and R4. */\r
- *pxTopOfStack = 0x00000000; /* uxCriticalNesting. */\r
+ pxTopOfStack -= 8; /* R11, R10, R9, R8, R7, R6, R5 and R4. */\r
\r
return pxTopOfStack;\r
}\r
ldr r3, =pxCurrentTCB /* Restore the context. */\r
ldr r1, [r3] /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */\r
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */\r
- ldmia r0!, {r1, r4-r11} /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */\r
- ldr r2, =uxCriticalNesting /* Restore the critical nesting count used by the task. */\r
- str r1, [r2] \r
+ ldmia r0!, {r4-r11} /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */\r
msr psp, r0 /* Restore the task stack pointer. */\r
mov r0, #0\r
msr basepri, r0\r
{\r
PRESERVE8\r
\r
- msr msp, r0 /* Set the msp back to the start of the stack. */\r
- svc 0 /* System call to start first task. */\r
+ /* Use the NVIC offset register to locate the stack. */\r
+ ldr r0, =0xE000ED08\r
+ ldr r0, [r0]\r
+ ldr r0, [r0]\r
+ /* Set the msp back to the start of the stack. */\r
+ msr msp, r0\r
+ /* Call SVC to start the first task. */\r
+ svc 0\r
}\r
/*-----------------------------------------------------------*/\r
\r
here already. */\r
prvSetupTimerInterrupt();\r
\r
+ /* Initialise the critical nesting count ready for the first task. */\r
+ uxCriticalNesting = 0;\r
+\r
/* Start the first task. */\r
vPortStartFirstTask( *((unsigned portLONG *) 0 ) );\r
\r
{\r
/* Set a PendSV to request a context switch. */\r
*(portNVIC_INT_CTRL) |= portNVIC_PENDSVSET;\r
-\r
- /* This function is also called in response to a Yield(), so we want\r
- the yield to occur immediately. */\r
- portENABLE_INTERRUPTS();\r
}\r
/*-----------------------------------------------------------*/\r
\r
\r
mrs r0, psp \r
\r
- ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */\r
+ ldr r3, =pxCurrentTCB /* Get the location of the current TCB. */\r
ldr r2, [r3] \r
\r
- ldr r1, =uxCriticalNesting /* Save the remaining registers and the critical nesting count onto the task stack. */\r
- ldr r1, [r1] \r
- stmdb r0!, {r1,r4-r11} \r
+ stmdb r0!, {r4-r11} /* Save the remaining registers. */\r
str r0, [r2] /* Save the new top of stack into the first member of the TCB. */\r
\r
- stmdb sp!, {r3, r14} \r
- bl vTaskSwitchContext \r
+ stmdb sp!, {r3, r14} \r
+ mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY\r
+ msr basepri, r0 \r
+ bl vTaskSwitchContext\r
+ mov r0, #0\r
+ msr basepri, r0\r
ldmia sp!, {r3, r14} \r
\r
ldr r1, [r3] \r
- ldr r2, =uxCriticalNesting\r
ldr r0, [r1] /* The first item in pxCurrentTCB is the task top of stack. */\r
- ldmia r0!, {r1, r4-r11} /* Pop the registers and the critical nesting count. */\r
+ ldmia r0!, {r4-r11} /* Pop the registers and the critical nesting count. */\r
str r1, [r2] /* Save the new critical nesting value into ulCriticalNesting. */ \r
msr psp, r0 \r
- orr r14, #0xd \r
-\r
- cbnz r1, sv_disable_interrupts /* If the nesting count is greater than 0 we need to exit with interrupts masked. */\r
bx r14\r
-\r
-sv_disable_interrupts\r
- mov r1, #configKERNEL_INTERRUPT_PRIORITY\r
- msr basepri, r1 \r
- bx r14 \r
}\r
/*-----------------------------------------------------------*/\r
\r
void xPortSysTickHandler( void )\r
{\r
+unsigned portLONG ulDummy;\r
+\r
/* If using preemption, also force a context switch. */\r
#if configUSE_PREEMPTION == 1\r
*(portNVIC_INT_CTRL) |= portNVIC_PENDSVSET; \r
#endif\r
\r
- vTaskIncrementTick();\r
+ ulDummy = portSET_INTERRUPT_MASK_FROM_ISR();\r
+ {\r
+ vTaskIncrementTick();\r
+ }\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR();\r
}\r
/*-----------------------------------------------------------*/\r
\r
PRESERVE8\r
\r
push { r0 }\r
- mov r0, #configKERNEL_INTERRUPT_PRIORITY\r
+ mov r0, #configMAX_SYSCALL_INTERRUPT_PRIORITY\r
msr basepri, r0\r
pop { r0 }\r
bx r14\r