2 FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
77 /* Hardware registers. */
\r
82 /* Variables and functions. */
\r
83 .extern ulMaxAPIPriorityMask
\r
84 .extern _freertos_vector_table
\r
85 .extern pxCurrentTCB
\r
86 .extern vTaskSwitchContext
\r
87 .extern vApplicationIRQHandler
\r
88 .extern ulPortInterruptNesting
\r
89 .extern ulPortTaskHasFPUContext
\r
91 .global FreeRTOS_IRQ_Handler
\r
92 .global FreeRTOS_SWI_Handler
\r
93 .global vPortRestoreTaskContext
\r
94 .global vPortInstallFreeRTOSVectorTable
\r
99 .macro portSAVE_CONTEXT
\r
101 /* Save the LR and SPSR onto the system mode stack before switching to
\r
102 system mode to save the remaining system mode registers. */
\r
103 SRSDB sp!, #SYS_MODE
\r
107 /* Push the critical nesting count. */
\r
108 LDR R2, ulCriticalNestingConst
\r
112 /* Does the task have a floating point context that needs saving? If
\r
113 ulPortTaskHasFPUContext is 0 then no. */
\r
114 LDR R2, ulPortTaskHasFPUContextConst
\r
118 /* Save the floating point context, if any. */
\r
121 /*VPUSHNE {D16-D31}*/
\r
124 /* Save ulPortTaskHasFPUContext itself. */
\r
127 /* Save the stack pointer in the TCB. */
\r
128 LDR R0, pxCurrentTCBConst
\r
134 ; /**********************************************************************/
\r
136 .macro portRESTORE_CONTEXT
\r
138 /* Set the SP to point to the stack of the task being restored. */
\r
139 LDR R0, pxCurrentTCBConst
\r
143 /* Is there a floating point context to restore? If the restored
\r
144 ulPortTaskHasFPUContext is zero then no. */
\r
145 LDR R0, ulPortTaskHasFPUContextConst
\r
150 /* Restore the floating point context, if any. */
\r
152 /*VPOPNE {D16-D31}*/
\r
156 /* Restore the critical section nesting depth. */
\r
157 LDR R0, ulCriticalNestingConst
\r
161 /* Ensure the priority mask is correct for the critical nesting depth. */
\r
162 LDR R2, ulICCPMRConst
\r
166 LDRNE R4, ulMaxAPIPriorityMaskConst
\r
170 /* Restore all system mode registers other than the SP (which is already
\r
174 /* Return to the task code, loading CPSR on the way. */
\r
182 /******************************************************************************
\r
183 * SVC handler is used to start the scheduler.
\r
184 *****************************************************************************/
\r
186 .type FreeRTOS_SWI_Handler, %function
\r
187 FreeRTOS_SWI_Handler:
\r
188 /* Save the context of the current task and select a new task to run. */
\r
190 LDR R0, vTaskSwitchContextConst
\r
192 portRESTORE_CONTEXT
\r
195 /******************************************************************************
\r
196 * vPortRestoreTaskContext is used to start the scheduler.
\r
197 *****************************************************************************/
\r
198 .type vPortRestoreTaskContext, %function
\r
199 vPortRestoreTaskContext:
\r
200 /* Switch to system mode. */
\r
202 portRESTORE_CONTEXT
\r
205 .type FreeRTOS_IRQ_Handler, %function
\r
206 FreeRTOS_IRQ_Handler:
\r
208 /* Return to the interrupted instruction. */
\r
211 /* Push the return address and SPSR. */
\r
216 /* Change to supervisor mode to allow reentry. */
\r
219 /* Push used registers. */
\r
222 /* Increment nesting count. r3 holds the address of ulPortInterruptNesting
\r
223 for future use. r1 holds the original ulPortInterruptNesting value for
\r
225 LDR r3, ulPortInterruptNestingConst
\r
230 /* Read value from the interrupt acknowledge register, which is stored in r0
\r
231 for future parameter and interrupt clearing use. */
\r
232 LDR r2, ulICCIARConst
\r
236 /* Ensure bit 2 of the stack pointer is clear. r2 holds the bit 2 value for
\r
242 /* Call the interrupt handler. */
\r
244 LDR r1, vApplicationIRQHandlerConst
\r
253 /* Write the value read from ICCIAR to ICCEOIR. */
\r
254 LDR r4, ulICCEOIRConst
\r
258 /* Restore the old nesting count. */
\r
261 /* A context switch is never performed if the nesting count is not 0. */
\r
263 BNE exit_without_switch
\r
265 /* Did the interrupt request a context switch? r1 holds the address of
\r
266 ulPortYieldRequired and r0 the value of ulPortYieldRequired for future
\r
268 LDR r1, =ulPortYieldRequired
\r
271 BNE switch_before_exit
\r
273 exit_without_switch:
\r
274 /* No context switch. Restore used registers, LR_irq and SPSR before
\r
283 switch_before_exit:
\r
284 /* A context swtich is to be performed. Clear the context switch pending
\r
289 /* Restore used registers, LR-irq and SPSR before saving the context
\r
290 to the task stack. */
\r
298 /* Call the function that selects the new task to execute.
\r
299 vTaskSwitchContext() if vTaskSwitchContext() uses LDRD or STRD
\r
300 instructions, or 8 byte aligned stack allocated data. LR does not need
\r
301 saving as a new LR will be loaded by portRESTORE_CONTEXT anyway. */
\r
302 LDR R0, vTaskSwitchContextConst
\r
305 /* Restore the context of, and branch to, the task selected to execute
\r
307 portRESTORE_CONTEXT
\r
309 ulICCIARConst: .word ulICCIAR
\r
310 ulICCEOIRConst: .word ulICCEOIR
\r
311 ulICCPMRConst: .word ulICCPMR
\r
312 pxCurrentTCBConst: .word pxCurrentTCB
\r
313 ulCriticalNestingConst: .word ulCriticalNesting
\r
314 ulPortTaskHasFPUContextConst: .word ulPortTaskHasFPUContext
\r
315 ulMaxAPIPriorityMaskConst: .word ulMaxAPIPriorityMask
\r
316 vTaskSwitchContextConst: .word vTaskSwitchContext
\r
317 vApplicationIRQHandlerConst: .word vApplicationIRQHandler
\r
318 ulPortInterruptNestingConst: .word ulPortInterruptNesting
\r