2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
70 #include "FreeRTOSConfig.h"
72 #define portCONTEXT_SIZE 132
73 #define portEPC_STACK_LOCATION 124
74 #define portSTATUS_STACK_LOCATION 128
76 #ifdef __LANGUAGE_ASSEMBLY__
78 /******************************************************************/
79 .macro portSAVE_CONTEXT
81 /* Make room for the context. First save the current status so it can be
82 manipulated, and the cause and EPC registers so their original values are
85 addiu sp, sp, -portCONTEXT_SIZE
88 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
89 maintain the values of these registers across the ISR. */
92 sw k1, portSTATUS_STACK_LOCATION(sp)
94 /* Prepare to enable interrupts above the current priority.
95 k0 = k0 >> 10. Moves RIPL[17:10] to [7:0] */
98 /* Insert bit field. 7 bits k0[6:0] to k1[16:10] */
101 /* Sets CP0.Status.IPL = CP0.Cause.RIPL
102 Copy the MSB of the IPL, but it would be an error if it was set anyway. */
105 /* MSB of IPL is bit[18] of CP0.Status */
108 /* CP0.Status[5:1] = 0 b[5]=Rsvd, b[4]=UM,
109 b[3]=Rsvd, b[2]=ERL, b[1]=EXL
110 Setting EXL=0 allows higher priority interrupts
111 to preempt this handler */
115 /* s5 is used as the frame pointer. */
118 /* Check the nesting count value. */
119 la k0, uxInterruptNesting
122 /* If the nesting count is 0 then swap to the the system stack, otherwise
123 the system stack is already being used. */
127 /* Swap to the system stack. */
131 /* Increment and save the nesting count. */
135 /* s6 holds the EPC value, this is saved after interrupts are re-enabled. */
138 /* Re-enable interrupts. */
141 /* Save the context into the space just created. s6 is saved again
142 here as it now contains the EPC value. No other s registers need be
144 sw ra, 120(s5) /* Return address (RA=R31) */
145 sw s8, 116(s5) /* Frame Pointer (FP=R30) */
162 sw s6, portEPC_STACK_LOCATION(s5)
165 /* MEC14xx does not have DSP, removed 7 words */
171 /* Update the task stack pointer value if nesting is zero. */
172 la s6, uxInterruptNesting
178 /* Save the stack pointer. */
179 la s6, uxSavedTaskStackPointer
184 /******************************************************************/
185 .macro portRESTORE_CONTEXT
187 /* Restore the stack pointer from the TCB. This is only done if the
188 nesting count is 1. */
189 la s6, uxInterruptNesting
194 la s6, uxSavedTaskStackPointer
197 /* Restore the context.
198 MCHP MEC14xx does not include DSP */
206 /* s6 is loaded as it was used as a scratch register and therefore saved
207 as part of the interrupt context. */
228 /* Protect access to the k registers, and others. */
232 /* Decrement the nesting count. */
233 la k0, uxInterruptNesting
238 lw k0, portSTATUS_STACK_LOCATION(s5)
239 lw k1, portEPC_STACK_LOCATION(s5)
241 /* Leave the stack in its original state. First load sp from s5, then
242 restore s5 from the stack. */
245 addiu sp, sp, portCONTEXT_SIZE
255 #endif /* #ifdef __LANGUAGE_ASSEMBLY__ */