2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* FreeRTOS includes. */
\r
30 #include "FreeRTOSConfig.h"
\r
31 #include "ISR_Support.h"
\r
33 /* Microchip includes. */
\r
35 #include <sys/asm.h>
\r
37 .extern pxCurrentTCB
\r
38 .extern vTaskSwitchContext
\r
39 .extern vPortIncrementTick
\r
40 .extern xISRStackTop
\r
42 PORT_CPP_JTVIC_BASE = 0xBFFFC000
\r
43 PORT_CCP_JTVIC_GIRQ24_SRC = 0xBFFFC100
\r
45 .global vPortStartFirstTask .text
\r
46 .global vPortYieldISR .text
\r
47 .global vPortTickInterruptHandler .text
\r
50 /******************************************************************/
\r
53 /***************************************************************
\r
54 * The following is needed to locate the
\r
55 * vPortTickInterruptHandler function into the correct vector
\r
56 * MEC14xx - This ISR will only be used if HW timers' interrupts
\r
57 * in GIRQ23 are disaggregated.
\r
59 ***************************************************************/
\r
65 .section .text, code
\r
66 .ent vPortTickInterruptHandler
\r
68 #if configTIMERS_DISAGGREGATED_ISRS == 0
\r
73 vPortTickInterruptHandler:
\r
82 .end vPortTickInterruptHandler
\r
89 vPortTickInterruptHandler:
\r
93 jal vPortIncrementTick
\r
98 .end vPortTickInterruptHandler
\r
100 #endif /* #if configTIMERS_DISAGGREGATED_ISRS == 0 */
\r
102 /******************************************************************/
\r
108 .section .text, code
\r
109 .ent vPortStartFirstTask
\r
111 vPortStartFirstTask:
\r
113 /* Simply restore the context of the highest priority task that has
\r
114 been created so far. */
\r
115 portRESTORE_CONTEXT
\r
117 .end vPortStartFirstTask
\r
121 /*******************************************************************/
\r
123 /***************************************************************
\r
124 * The following is needed to locate the vPortYieldISR function into the correct
\r
126 ***************************************************************/
\r
132 .section .text, code
\r
134 .global vPortYieldISR
\r
137 #if configCPU_DISAGGREGATED_ISRS == 0
\r
141 la k0, PORT_CPP_JTVIC_BASE
\r
144 bgtz k1, vPortYieldISR
\r
151 portRESTORE_CONTEXT
\r
162 /* Make room for the context. First save the current status so it can be
\r
163 manipulated, and the cause and EPC registers so thier original values
\r
165 addiu sp, sp, -portCONTEXT_SIZE
\r
166 mfc0 k1, _CP0_STATUS
\r
168 /* Also save s6 and s5 so they can be used. Any nesting interrupts should
\r
169 maintain the values of these registers across the ISR. */
\r
172 sw k1, portSTATUS_STACK_LOCATION(sp)
\r
174 /* Prepare to re-enable interrupts above the kernel priority. */
\r
175 ins k1, zero, 10, 7 /* Clear IPL bits 0:6. */
\r
176 ins k1, zero, 18, 1 /* Clear IPL bit 7 */
\r
177 ori k1, k1, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 )
\r
178 ins k1, zero, 1, 4 /* Clear EXL, ERL and UM. */
\r
180 /* s5 is used as the frame pointer. */
\r
183 /* Swap to the system stack. This is not conditional on the nesting
\r
184 count as this interrupt is always the lowest priority and therefore
\r
185 the nesting is always 0. */
\r
186 la sp, xISRStackTop
\r
189 /* Set the nesting count. */
\r
190 la k0, uxInterruptNesting
\r
194 /* s6 holds the EPC value, this is saved with the rest of the context
\r
195 after interrupts are enabled. */
\r
198 /* Re-enable interrupts above configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
199 mtc0 k1, _CP0_STATUS
\r
201 /* Save the context into the space just created. s6 is saved again
\r
202 here as it now contains the EPC value. */
\r
222 sw s6, portEPC_STACK_LOCATION(s5)
\r
223 /* s5 and s6 has already been saved. */
\r
231 /* s7 is used as a scratch register as this should always be saved acro ss
\r
232 nesting interrupts. */
\r
238 /* Save the stack pointer to the task. */
\r
239 la s7, pxCurrentTCB
\r
243 /* Set the interrupt mask to the max priority that can use the API.
\r
244 The yield handler will only be called at configKERNEL_INTERRUPT_PRIORITY
\r
245 which is below configMAX_SYSCALL_INTERRUPT_PRIORITY - so this can only
\r
246 ever raise the IPL value and never lower it. */
\r
249 mfc0 s7, _CP0_STATUS
\r
250 ins s7, zero, 10, 7
\r
251 ins s7, zero, 18, 1
\r
252 ori s6, s7, ( configMAX_SYSCALL_INTERRUPT_PRIORITY << 10 ) | 1
\r
254 /* This mtc0 re-enables interrupts, but only above
\r
255 configMAX_SYSCALL_INTERRUPT_PRIORITY. */
\r
256 mtc0 s6, _CP0_STATUS
\r
259 /* Clear the software interrupt in the core. */
\r
260 mfc0 s6, _CP0_CAUSE
\r
262 mtc0 s6, _CP0_CAUSE
\r
265 /* Clear the interrupt in the interrupt controller.
\r
266 MEC14xx GIRQ24 Source bit[1] = 1 to clear */
\r
267 la s6, PORT_CCP_JTVIC_GIRQ24_SRC
\r
270 jal vTaskSwitchContext
\r
273 /* Clear the interrupt mask again. The saved status value is still in s7 */
\r
274 mtc0 s7, _CP0_STATUS
\r
277 /* Restore the stack pointer from the TCB. */
\r
278 la s0, pxCurrentTCB
\r
282 /* Restore the rest of the context. */
\r
295 /* s5 is loaded later. */
\r
317 /* Protect access to the k registers, and others. */
\r
321 /* Set nesting back to zero. As the lowest priority interrupt this
\r
322 interrupt cannot have nested. */
\r
323 la k0, uxInterruptNesting
\r
326 /* Switch back to use the real stack pointer. */
\r
329 /* Restore the real s5 value. */
\r
332 /* Pop the status and epc values. */
\r
333 lw k1, portSTATUS_STACK_LOCATION(sp)
\r
334 lw k0, portEPC_STACK_LOCATION(sp)
\r
336 /* Remove stack frame. */
\r
337 addiu sp, sp, portCONTEXT_SIZE
\r
339 mtc0 k1, _CP0_STATUS
\r