2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
97 #include <sys/asm.h>
\r
98 #include "FreeRTOSConfig.h"
\r
99 #include "ISR_Support.h"
\r
102 .extern pxCurrentTCB
\r
103 .extern vTaskSwitchContext
\r
104 .extern vPortIncrementTick
\r
105 .extern xISRStackTop
\r
107 .global vPortStartFirstTask
\r
108 .global vPortYieldISR
\r
109 .global vPortTickInterruptHandler
\r
112 /******************************************************************/
\r
119 /***************************************************************
\r
120 * The following is needed to locate the
\r
121 * vPortTickInterruptHandler function into the correct vector
\r
122 ***************************************************************/
\r
123 #ifdef configTICK_INTERRUPT_VECTOR
\r
124 #if (configTICK_INTERRUPT_VECTOR == _CORE_TIMER_VECTOR)
\r
125 .equ __vector_dispatch_0, vPortTickInterruptHandler
\r
126 .global __vector_dispatch_0
\r
127 .section .vector_0, code, keep
\r
128 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_1_VECTOR)
\r
129 .equ __vector_dispatch_4, vPortTickInterruptHandler
\r
130 .global __vector_dispatch_4
\r
131 .section .vector_4, code, keep
\r
132 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_2_VECTOR)
\r
133 .equ __vector_dispatch_9, vPortTickInterruptHandler
\r
134 .global __vector_dispatch_9
\r
135 .section .vector_9, code, keep
\r
136 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_3_VECTOR)
\r
137 .equ __vector_dispatch_14, vPortTickInterruptHandler
\r
138 .global __vector_dispatch_14
\r
139 .section .vector_14, code, keep
\r
140 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_4_VECTOR)
\r
141 .equ __vector_dispatch_19, vPortTickInterruptHandler
\r
142 .global __vector_dispatch_19
\r
143 .section .vector_19, code, keep
\r
144 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_5_VECTOR)
\r
145 .equ __vector_dispatch_24, vPortTickInterruptHandler
\r
146 .global __vector_dispatch_24
\r
147 .section .vector_24, code, keep
\r
148 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_6_VECTOR)
\r
149 .equ __vector_dispatch_28, vPortTickInterruptHandler
\r
150 .global __vector_dispatch_28
\r
151 .section .vector_28, code, keep
\r
152 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_7_VECTOR)
\r
153 .equ __vector_dispatch_32, vPortTickInterruptHandler
\r
154 .global __vector_dispatch_32
\r
155 .section .vector_32, code, keep
\r
156 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_8_VECTOR)
\r
157 .equ __vector_dispatch_36, vPortTickInterruptHandler
\r
158 .global __vector_dispatch_36
\r
159 .section .vector_36, code, keep
\r
160 #elif (configTICK_INTERRUPT_VECTOR == _TIMER_9_VECTOR)
\r
161 .equ __vector_dispatch_40, vPortTickInterruptHandler
\r
162 .global __vector_dispatch_40
\r
163 .section .vector_40, code, keep
\r
166 .equ __vector_dispatch_4, vPortTickInterruptHandler
\r
167 .global __vector_dispatch_4
\r
168 .section .vector_4, code, keep
\r
171 .ent vPortTickInterruptHandler
\r
173 vPortTickInterruptHandler:
\r
177 jal vPortIncrementTick
\r
180 portRESTORE_CONTEXT
\r
182 .end vPortTickInterruptHandler
\r
184 /******************************************************************/
\r
188 .section .text, code
\r
189 .ent vPortStartFirstTask
\r
191 vPortStartFirstTask:
\r
193 /* Simply restore the context of the highest priority task that has been
\r
195 portRESTORE_CONTEXT
\r
197 .end vPortStartFirstTask
\r
201 /*******************************************************************/
\r
207 /***************************************************************
\r
208 * The following is needed to locate the vPortYieldISR function
\r
209 * into the correct vector
\r
210 ***************************************************************/
\r
211 .equ __vector_dispatch_1, vPortYieldISR
\r
212 .global __vector_dispatch_1
\r
213 .section .vector_1, code
\r
218 /* Make room for the context. First save the current status so it can be
\r
219 manipulated, and the cause and EPC registers so thier original values are
\r
221 addiu sp, sp, -portCONTEXT_SIZE
\r
222 mfc0 k1, _CP0_STATUS
\r
224 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
\r
225 maintain the values of these registers across the ISR. */
\r
228 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
230 /* Prepare to re-enabled interrupts above the kernel priority. */
\r
231 ins k1, zero, 10, 7 /* Clear IPL bits 0:6. */
\r
232 ins k1, zero, 18, 1 /* Clear IPL bit 7. It would be an error here if this bit were set anyway. */
\r
233 ori k1, k1, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 )
\r
234 ins k1, zero, 1, 4 /* Clear EXL, ERL and UM. */
\r
236 /* s5 is used as the frame pointer. */
\r
239 /* Swap to the system stack. This is not conditional on the nesting
\r
240 count as this interrupt is always the lowest priority and therefore
\r
241 the nesting is always 0. */
\r
242 la sp, xISRStackTop
\r
245 /* Set the nesting count. */
\r
246 la k0, uxInterruptNesting
\r
250 /* s6 holds the EPC value, this is saved with the rest of the context
\r
251 after interrupts are enabled. */
\r
254 /* Re-enable interrupts above configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
255 mtc0 k1, _CP0_STATUS
\r
257 /* Save the context into the space just created. s6 is saved again
\r
258 here as it now contains the EPC value. */
\r
278 sw s6, portEPC_STACK_LOCATION(s5)
\r
279 /* s5 and s6 has already been saved. */
\r
287 /* s7 is used as a scratch register as this should always be saved across
\r
288 nesting interrupts. */
\r
290 /* Save the AC0, AC1, AC2 and AC3. */
\r
314 /* Save the stack pointer to the task. */
\r
315 la s7, pxCurrentTCB
\r
319 /* Set the interrupt mask to the max priority that can use the API. The
\r
320 yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY which
\r
321 is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only ever
\r
322 raise the IPL value and never lower it. */
\r
325 mfc0 s7, _CP0_STATUS
\r
326 ins s7, zero, 10, 7
\r
327 ins s7, zero, 18, 1
\r
328 ori s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1
\r
330 /* This mtc0 re-enables interrupts, but only above
\r
331 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
332 mtc0 s6, _CP0_STATUS
\r
335 /* Clear the software interrupt in the core. */
\r
336 mfc0 s6, _CP0_CAUSE
\r
338 mtc0 s6, _CP0_CAUSE
\r
341 /* Clear the interrupt in the interrupt controller. */
\r
346 jal vTaskSwitchContext
\r
349 /* Clear the interrupt mask again. The saved status value is still in s7. */
\r
350 mtc0 s7, _CP0_STATUS
\r
353 /* Restore the stack pointer from the TCB. */
\r
354 la s0, pxCurrentTCB
\r
358 /* Restore the rest of the context. */
\r
389 /* s5 is loaded later. */
\r
411 /* Protect access to the k registers, and others. */
\r
415 /* Set nesting back to zero. As the lowest priority interrupt this
\r
416 interrupt cannot have nested. */
\r
417 la k0, uxInterruptNesting
\r
420 /* Switch back to use the real stack pointer. */
\r
423 /* Restore the real s5 value. */
\r
426 /* Pop the status and epc values. */
\r
427 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
428 lw k0, portEPC_STACK_LOCATION(sp)
\r
430 /* Remove stack frame. */
\r
431 addiu sp, sp, portCONTEXT_SIZE
\r
433 mtc0 k1, _CP0_STATUS
\r