2 * FreeRTOS Kernel V10.1.0
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* FreeRTOS includes. */
\r
29 #include "FreeRTOSConfig.h"
\r
30 #include "ISR_Support.h"
\r
32 /* Microchip includes. */
\r
34 #include <sys/asm.h>
\r
36 .extern pxCurrentTCB
\r
37 .extern vTaskSwitchContext
\r
38 .extern vPortIncrementTick
\r
39 .extern xISRStackTop
\r
41 PORT_CPP_JTVIC_BASE = 0xBFFFC000
\r
42 PORT_CCP_JTVIC_GIRQ24_SRC = 0xBFFFC100
\r
44 .global vPortStartFirstTask .text
\r
45 .global vPortYieldISR .text
\r
46 .global vPortTickInterruptHandler .text
\r
49 /******************************************************************/
\r
52 /***************************************************************
\r
53 * The following is needed to locate the
\r
54 * vPortTickInterruptHandler function into the correct vector
\r
55 * MEC14xx - This ISR will only be used if HW timers' interrupts
\r
56 * in GIRQ23 are disaggregated.
\r
58 ***************************************************************/
\r
64 .section .text, code
\r
65 .ent vPortTickInterruptHandler
\r
67 #if configTIMERS_DISAGGREGATED_ISRS == 0
\r
72 vPortTickInterruptHandler:
\r
81 .end vPortTickInterruptHandler
\r
88 vPortTickInterruptHandler:
\r
92 jal vPortIncrementTick
\r
97 .end vPortTickInterruptHandler
\r
99 #endif /* #if configTIMERS_DISAGGREGATED_ISRS == 0 */
\r
101 /******************************************************************/
\r
107 .section .text, code
\r
108 .ent vPortStartFirstTask
\r
110 vPortStartFirstTask:
\r
112 /* Simply restore the context of the highest priority task that has
\r
113 been created so far. */
\r
114 portRESTORE_CONTEXT
\r
116 .end vPortStartFirstTask
\r
120 /*******************************************************************/
\r
122 /***************************************************************
\r
123 * The following is needed to locate the vPortYieldISR function into the correct
\r
125 ***************************************************************/
\r
131 .section .text, code
\r
133 .global vPortYieldISR
\r
136 #if configCPU_DISAGGREGATED_ISRS == 0
\r
140 la k0, PORT_CPP_JTVIC_BASE
\r
143 bgtz k1, vPortYieldISR
\r
150 portRESTORE_CONTEXT
\r
161 /* Make room for the context. First save the current status so it can be
\r
162 manipulated, and the cause and EPC registers so thier original values
\r
164 addiu sp, sp, -portCONTEXT_SIZE
\r
165 mfc0 k1, _CP0_STATUS
\r
167 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
\r
168 maintain the values of these registers across the ISR. */
\r
171 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
173 /* Prepare to re-enable interrupts above the kernel priority. */
\r
174 ins k1, zero, 10, 7 /* Clear IPL bits 0:6. */
\r
175 ins k1, zero, 18, 1 /* Clear IPL bit 7 */
\r
176 ori k1, k1, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 )
\r
177 ins k1, zero, 1, 4 /* Clear EXL, ERL and UM. */
\r
179 /* s5 is used as the frame pointer. */
\r
182 /* Swap to the system stack. This is not conditional on the nesting
\r
183 count as this interrupt is always the lowest priority and therefore
\r
184 the nesting is always 0. */
\r
185 la sp, xISRStackTop
\r
188 /* Set the nesting count. */
\r
189 la k0, uxInterruptNesting
\r
193 /* s6 holds the EPC value, this is saved with the rest of the context
\r
194 after interrupts are enabled. */
\r
197 /* Re-enable interrupts above configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
198 mtc0 k1, _CP0_STATUS
\r
200 /* Save the context into the space just created. s6 is saved again
\r
201 here as it now contains the EPC value. */
\r
221 sw s6, portEPC_STACK_LOCATION(s5)
\r
222 /* s5 and s6 has already been saved. */
\r
230 /* s7 is used as a scratch register as this should always be saved acro ss
\r
231 nesting interrupts. */
\r
237 /* Save the stack pointer to the task. */
\r
238 la s7, pxCurrentTCB
\r
242 /* Set the interrupt mask to the max priority that can use the API.
\r
243 The yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY
\r
244 which is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only
\r
245 ever raise the IPL value and never lower it. */
\r
248 mfc0 s7, _CP0_STATUS
\r
249 ins s7, zero, 10, 7
\r
250 ins s7, zero, 18, 1
\r
251 ori s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1
\r
253 /* This mtc0 re-enables interrupts, but only above
\r
254 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
255 mtc0 s6, _CP0_STATUS
\r
258 /* Clear the software interrupt in the core. */
\r
259 mfc0 s6, _CP0_CAUSE
\r
261 mtc0 s6, _CP0_CAUSE
\r
264 /* Clear the interrupt in the interrupt controller.
\r
265 MEC14xx GIRQ24 Source bit[1] = 1 to clear */
\r
266 la s6, PORT_CCP_JTVIC_GIRQ24_SRC
\r
269 jal vTaskSwitchContext
\r
272 /* Clear the interrupt mask again. The saved status value is still in s7 */
\r
273 mtc0 s7, _CP0_STATUS
\r
276 /* Restore the stack pointer from the TCB. */
\r
277 la s0, pxCurrentTCB
\r
281 /* Restore the rest of the context. */
\r
294 /* s5 is loaded later. */
\r
316 /* Protect access to the k registers, and others. */
\r
320 /* Set nesting back to zero. As the lowest priority interrupt this
\r
321 interrupt cannot have nested. */
\r
322 la k0, uxInterruptNesting
\r
325 /* Switch back to use the real stack pointer. */
\r
328 /* Restore the real s5 value. */
\r
331 /* Pop the status and epc values. */
\r
332 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
333 lw k0, portEPC_STACK_LOCATION(sp)
\r
335 /* Remove stack frame. */
\r
336 addiu sp, sp, portCONTEXT_SIZE
\r
338 mtc0 k1, _CP0_STATUS
\r