2 FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
6 ***************************************************************************
\r
8 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
9 * Complete, revised, and edited pdf reference manuals are also *
\r
12 * Purchasing FreeRTOS documentation will not only help you, by *
\r
13 * ensuring you get running as quickly as possible and with an *
\r
14 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
15 * the FreeRTOS project to continue with its mission of providing *
\r
16 * professional grade, cross platform, de facto standard solutions *
\r
17 * for microcontrollers - completely free of charge! *
\r
19 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
21 * Thank you for using FreeRTOS, and thank you for your support! *
\r
23 ***************************************************************************
\r
26 This file is part of the FreeRTOS distribution.
\r
28 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
29 the terms of the GNU General Public License (version 2) as published by the
\r
30 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
31 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
32 distribute a combined work that includes FreeRTOS without being obliged to
\r
33 provide the source code for proprietary components outside of the FreeRTOS
\r
34 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
35 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
36 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
37 more details. You should have received a copy of the GNU General Public
\r
38 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
39 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
40 by writing to Richard Barry, contact details for whom are available on the
\r
45 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
48 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
51 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
52 licensing and training services.
\r
61 /* Hardware registers. */
\r
66 /* Variables and functions. */
\r
67 .extern ulMaxAPIPriorityMask
\r
68 .extern _freertos_vector_table
\r
69 .extern pxCurrentTCB
\r
70 .extern vTaskSwitchContext
\r
71 .extern vApplicationIRQHandler
\r
72 .extern ulPortInterruptNesting
\r
74 .global FreeRTOS_IRQ_Handler
\r
75 .global FreeRTOS_SWI_Handler
\r
76 .global vPortRestoreTaskContext
\r
77 .global vPortInstallFreeRTOSVectorTable
\r
82 .macro portSAVE_CONTEXT
\r
84 /* Save the LR and SPSR onto the system mode stack before switching to
\r
85 system mode to save the remaining system mode registers. */
\r
86 SRSDB sp!, #SYS_MODE
\r
90 /* Push the critical nesting count. */
\r
91 LDR R2, ulCriticalNestingConst
\r
95 /* Does the task have a floating point context that needs saving? If
\r
96 ulPortTaskHasFPUContext is 0 then no. */
\r
97 LDR R2, ulPortTaskHasFPUContextConst
\r
101 /* Save the floating point context, if any. */
\r
107 /* Save ulPortTaskHasFPUContext itself. */
\r
110 /* Save the stack pointer in the TCB. */
\r
111 LDR R0, pxCurrentTCBConst
\r
117 ; /**********************************************************************/
\r
119 .macro portRESTORE_CONTEXT
\r
121 /* Switch to system mode. */
\r
124 /* Set the SP to point to the stack of the task being restored. */
\r
125 LDR R0, pxCurrentTCBConst
\r
129 /* Is there a floating point context to restore? If the restored
\r
130 ulPortTaskHasFPUContext is zero then no. */
\r
131 LDR R0, ulPortTaskHasFPUContextConst
\r
136 /* Restore the floating point context, if any. */
\r
142 /* Restore the critical section nesting depth. */
\r
143 LDR R0, ulCriticalNestingConst
\r
147 /* Ensure the priority mask is correct for the critical nesting depth. */
\r
148 LDR R2, ulICCPMRConst
\r
152 LDRNE R4, ulMaxAPIPriorityMaskConst
\r
156 /* Restore all system mode registers other than the SP (which is already
\r
160 /* Return to the task code, loading CPSR on the way. */
\r
168 /******************************************************************************
\r
169 * SVC handler is used to start the scheduler and yield a task.
\r
170 *****************************************************************************/
\r
171 FreeRTOS_SWI_Handler:
\r
172 /* Save the context of the current task and select a new task to run. */
\r
174 LDR R0, vTaskSwitchContextConst
\r
177 vPortRestoreTaskContext:
\r
178 portRESTORE_CONTEXT
\r
180 FreeRTOS_IRQ_Handler:
\r
181 /* Return to the interrupted instruction. */
\r
184 /* Push the return address and SPSR. */
\r
189 /* Change to supervisor mode to allow reentry. */
\r
192 /* Push used registers. */
\r
195 /* Increment nesting count. r3 holds the address of ulPortInterruptNesting
\r
196 for future use. r1 holds the original ulPortInterruptNesting value for
\r
198 LDR r3, ulPortInterruptNestingConst
\r
203 /* Read value from the interrupt acknowledge register, which is stored in r0
\r
204 for future parameter and interrupt clearing use. */
\r
205 LDR r2, ulICCIARConst
\r
209 /* Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for
\r
215 /* Call the interrupt handler. */
\r
217 LDR r1, vApplicationIRQHandlerConst
\r
226 /* Write the value read from ICCIAR to ICCEOIR. */
\r
227 LDR r4, ulICCEOIRConst
\r
231 /* Restore the old nesting count. */
\r
234 /* A context switch is never performed if the nesting count is not 0. */
\r
236 BNE exit_without_switch
\r
238 /* Did the interrupt request a context switch? r1 holds the address of
\r
239 ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
\r
241 LDR r1, =ulPortYieldRequired
\r
244 BNE switch_before_exit
\r
246 exit_without_switch:
\r
247 /* No context switch. Restore used registers, LR_irq and SPSR before
\r
256 switch_before_exit:
\r
257 /* A context swtich is to be performed. Clear the context switch pending
\r
262 /* Restore used registers, LR-irq and SPSR before saving the context
\r
263 to the task stack. */
\r
271 /* Call the function that selects the new task to execute.
\r
272 vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
\r
273 instructions, or 8 byte aligned stack allocated data. LR does not need
\r
274 saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */
\r
275 LDR R0, vTaskSwitchContextConst
\r
278 /* Restore the context of, and branch to, the task selected to execute
\r
280 portRESTORE_CONTEXT
\r
282 vPortInstallFreeRTOSVectorTable:
\r
283 /* Set VBAR to the vector table that contains the FreeRTOS handlers. */
\r
284 ldr r0, =_freertos_vector_table
\r
285 mcr p15, 0, r0, c12, c0, 0
\r
290 ulICCIARConst: .word ulICCIAR
\r
291 ulICCEOIRConst: .word ulICCEOIR
\r
292 ulICCPMRConst: .word ulICCPMR
\r
293 pxCurrentTCBConst: .word pxCurrentTCB
\r
294 ulCriticalNestingConst: .word ulCriticalNesting
\r
295 ulPortTaskHasFPUContextConst: .word ulPortTaskHasFPUContext
\r
296 ulMaxAPIPriorityMaskConst: .word ulMaxAPIPriorityMask
\r
297 vTaskSwitchContextConst: .word vTaskSwitchContext
\r
298 vApplicationIRQHandlerConst: .word vApplicationIRQHandler
\r
299 ulPortInterruptNestingConst: .word ulPortInterruptNesting
\r