2 FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
67 #include <p32xxxx.h>
\r
68 #include <sys/asm.h>
\r
69 #include "ISR_Support.h"
\r
75 .extern pxCurrentTCB
\r
76 .extern vTaskSwitchContext
\r
77 .extern vPortIncrementTick
\r
78 .extern xISRStackTop
\r
80 .global vPortStartFirstTask
\r
81 .global vPortYieldISR
\r
82 .global vT1InterruptHandler
\r
85 /******************************************************************/
\r
89 .ent vT1InterruptHandler
\r
91 vT1InterruptHandler:
\r
95 jal vPortIncrementTick
\r
100 .end vT1InterruptHandler
\r
102 /******************************************************************/
\r
106 .ent xPortStartScheduler
\r
108 vPortStartFirstTask:
\r
110 /* Simply restore the context of the highest priority task that has been
\r
112 portRESTORE_CONTEXT
\r
114 .end xPortStartScheduler
\r
118 /*******************************************************************/
\r
126 /* Make room for the context. First save the current status so we can
\r
127 manipulate it, and the cause and EPC registers so we capture their
\r
128 original values in case of interrupt nesting. */
\r
129 mfc0 k0, _CP0_CAUSE
\r
130 addiu sp, sp, -portCONTEXT_SIZE
\r
131 mfc0 k1, _CP0_STATUS
\r
133 /* Also save s6 and s5 so we can use them during this interrupt. Any
\r
134 nesting interrupts should maintain the values of these registers
\r
138 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
140 /* Enable interrupts above the current priority. */
\r
145 /* s5 is used as the frame pointer. */
\r
148 /* Swap to the system stack. This is not conditional on the nesting
\r
149 count as this interrupt is always the lowest priority and therefore
\r
150 the nesting is always 0. */
\r
151 la sp, xISRStackTop
\r
154 /* Set the nesting count. */
\r
155 la k0, uxInterruptNesting
\r
159 /* s6 holds the EPC value, this is saved with the rest of the context
\r
160 after interrupts are enabled. */
\r
163 /* Re-enable interrupts. */
\r
164 mtc0 k1, _CP0_STATUS
\r
166 /* Save the context into the space just created. s6 is saved again
\r
167 here as it now contains the EPC value. */
\r
187 sw s6, portEPC_STACK_LOCATION(s5)
\r
188 /* s5 and s6 has already been saved. */
\r
196 /* s7 is used as a scratch register as this should always be saved across
\r
197 nesting interrupts. */
\r
203 /* Save the stack pointer to the task. */
\r
204 la s7, pxCurrentTCB
\r
208 /* Set the interrupt mask to the max priority that can use the API. The
\r
209 yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY which
\r
210 is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only ever
\r
211 raise the IPL value and never lower it. */
\r
213 mfc0 s7, _CP0_STATUS
\r
215 ori s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1
\r
217 /* This mtc0 re-enables interrupts, but only above
\r
218 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
219 mtc0 s6, _CP0_STATUS
\r
221 /* Clear the software interrupt in the core. */
\r
222 mfc0 s6, _CP0_CAUSE
\r
225 mtc0 s6, _CP0_CAUSE
\r
227 /* Clear the interrupt in the interrupt controller. */
\r
232 jal vTaskSwitchContext
\r
235 /* Clear the interrupt mask again. The saved status value is still in s7. */
\r
236 mtc0 s7, _CP0_STATUS
\r
238 /* Restore the stack pointer from the TCB. */
\r
239 la s0, pxCurrentTCB
\r
243 /* Restore the rest of the context. */
\r
254 /* s5 is loaded later. */
\r
276 /* Protect access to the k registers, and others. */
\r
279 /* Set nesting back to zero. As the lowest priority interrupt this
\r
280 interrupt cannot have nested. */
\r
281 la k0, uxInterruptNesting
\r
284 /* Switch back to use the real stack pointer. */
\r
287 /* Restore the real s5 value. */
\r
290 /* Pop the status and epc values. */
\r
291 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
292 lw k0, portEPC_STACK_LOCATION(sp)
\r
294 /* Remove stack frame. */
\r
295 addiu sp, sp, portCONTEXT_SIZE
\r
297 mtc0 k1, _CP0_STATUS
\r