FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- more details. You should have received a copy of the GNU General Public
- License and the FreeRTOS license exception along with FreeRTOS; if not it
- can be viewed here: http://www.freertos.org/a00114.html and also obtained
+ more details. You should have received a copy of the GNU General Public
+ License and the FreeRTOS license exception along with FreeRTOS; if not it
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained
by writing to Richard Barry, contact details for whom are available on the
FreeRTOS WEB site.
/*-----------------------------------------------------------*/
/* The initial PSR has the Previous Interrupt Enabled (PIEN) flag set. */
-#define portINITIAL_PSR ( 0x00020000 )
+#define portINITIAL_PSR ( 0x00020000 )
/*-----------------------------------------------------------*/
/*
* Perform any hardware configuration necessary to generate the tick interrupt.
*/
-static void prvSetupTickInterrupt( void );
-/*-----------------------------------------------------------*/
-
-/* Variables used to hold interrupt and critical nesting depths, with variables
-that provide a convenient method of obtaining their addresses. */
-volatile unsigned portBASE_TYPE uxInterruptNestingCount = 999UL;
-const volatile unsigned portBASE_TYPE *puxInterruptNestingCount = &uxInterruptNestingCount;
-volatile unsigned portBASE_TYPE uxInterruptStack[ configMINIMAL_STACK_SIZE ];
-const volatile unsigned portBASE_TYPE *puxTopOfInterruptStack = &( uxInterruptStack[ configMINIMAL_STACK_SIZE - 1 ] );
+static void prvSetupTimerInterrupt( void );
/*-----------------------------------------------------------*/
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
{
- /* For the time being, mimic the stack when using the
+ /* For the time being, mimic the stack when using the
__attribute__((interrupt)) plus the extra caller saved registers. */
- pxTopOfStack -= 17;
-
+ This leaves a buffer of two works unused. */
+ pxTopOfStack -= 18;
+
/* RTT */
pxTopOfStack[ 16 ] = ( portSTACK_TYPE )pxCode;
-
+
/* PSR */
pxTopOfStack[ 15 ] = portINITIAL_PSR;
-
+
/* R14 and R15 aka FuncSP and LR, respectively */
pxTopOfStack[ 14 ] = 0x00000000;
pxTopOfStack[ 13 ] = ( portSTACK_TYPE )( pxTopOfStack + 17 );
-
+
/* R7 to R2 */
pxTopOfStack[ 12 ] = 0x07070707;
pxTopOfStack[ 11 ] = 0x06060606;
pxTopOfStack[ 9 ] = 0x04040404;
pxTopOfStack[ 8 ] = 0x03030303;
pxTopOfStack[ 7 ] = ( portSTACK_TYPE )pvParameters;
-
+
/* Set the Interrupt Priority on Task entry. */
pxTopOfStack[ 6 ] = portKERNEL_INTERRUPT_PRIORITY_LEVEL;
-
+
/* R13 to R8. */
pxTopOfStack[ 5 ] = 0x0D0D0D0D;
pxTopOfStack[ 4 ] = 0x0C0C0C0C;
portBASE_TYPE xPortStartScheduler( void )
{
- /* Set-up the Tick Interrupt. */
- prvSetupTickInterrupt();
+ /* Set-up the timer interrupt. */
+ prvSetupTimerInterrupt();
/* Enable the TRAP yield. */
irq[ portIRQ_TRAP_YIELD ].ien = 1;
/* Integrated Interrupt Controller: Enable all interrupts. */
ic->ien = 1;
- uxInterruptNestingCount = 1UL;
- /* Restore calleree saved registers. */
- portRESTORE_CONTEXT_REDUCED();
+ /* Restore callee saved registers. */
+ portRESTORE_CONTEXT();
- /* Mimic an ISR epiplogue to start the task executing. */
+ /* Mimic an ISR epilogue to start the task executing. */
asm __volatile__( \
- "mov r1, r14 \n" \
"ldd r6, [r1]+0x20 \n" \
"mov psr, r6 \n" \
"mov rtt, r7 \n" \
}
/*-----------------------------------------------------------*/
-static void prvSetupTickInterrupt( void )
+static void prvSetupTimerInterrupt( void )
{
/* Enable timer interrupts */
counter1->reload = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1;
void interrupt_handler( portIRQ_TRAP_YIELD )
{
/* Save remaining registers. */
- portSAVE_CONTEXT_REDUCED();
+ portSAVE_CONTEXT();
- /* Perform the actual Yield. */
- portYIELD_FROM_ISR();
+ vTaskSwitchContext();
- /* Restore the first lot of registers, the remains will be resotred when
+ /* Restore the first lot of registers, the remains will be restored when
this function exits. */
- portRESTORE_CONTEXT_REDUCED();
+ portRESTORE_CONTEXT();
}
/*-----------------------------------------------------------*/
/* Timer tick interrupt handler */
void interrupt_handler( IRQ_COUNTER1 )
{
- portSAVE_CONTEXT_REDUCED();
-
- asm __volatile__(
- " sub r1, #4 \n" /* Make space on the stack. r1 is stack pointer. */
- " movhi r2, #16384 \n" /* Load the pointer to the IC. */
- " ldub r3, [r2]+2 \n" /* Copy the Current Priority Level. */
- " st r3, [r1] \n" /* Store it on the stack. */
- " mov r3, #%0 \n" /* Load the highest priority level. */
- " stb r3, [r2]+2 \n" /* Set the CPL to the highest level. */
- " call vTaskIncrementTick \n" /* Increment the tick. */
- " ld r3, [r1] \n" /* Load the previous CPL from the stack. */
- " movhi r2, #16384 \n" /* Load the pointer to the IC. */
- " stb r3, [r2]+2 \n" /* Set the CPL to the previous CPL. */
- " add r1, #4 "
- :
- :"i"(PORT_SYSTEM_INTERRUPT_PRIORITY_LEVEL+1)
- :"r2","r3" /* Fix the stack. */
- );
+ portSAVE_CONTEXT();
+
+ vTaskIncrementTick();
#if configUSE_PREEMPTION == 1
- portYIELD_FROM_ISR();
+ vTaskSwitchContext();
#endif
- {
- /* Clear the Tick Interrupt. */
- counter1->expired = 0;
- }
+ /* Clear the Tick Interrupt. */
+ counter1->expired = 0;
- portRESTORE_CONTEXT_REDUCED();
+ portRESTORE_CONTEXT();
}
/*-----------------------------------------------------------*/