2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /* FreeRTOS includes. */
\r
66 #include "FreeRTOSConfig.h"
\r
68 /* Xilinx library includes. */
\r
69 #include "microblaze_exceptions_g.h"
\r
70 #include "xparameters.h"
\r
72 /* The context is oversized to allow functions called from the ISR to write
\r
73 back into the caller stack. */
\r
74 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
75 #define portCONTEXT_SIZE 136
\r
76 #define portMINUS_CONTEXT_SIZE -136
\r
78 #define portCONTEXT_SIZE 132
\r
79 #define portMINUS_CONTEXT_SIZE -132
\r
82 /* Offsets from the stack pointer at which saved registers are placed. */
\r
83 #define portR31_OFFSET 4
\r
84 #define portR30_OFFSET 8
\r
85 #define portR29_OFFSET 12
\r
86 #define portR28_OFFSET 16
\r
87 #define portR27_OFFSET 20
\r
88 #define portR26_OFFSET 24
\r
89 #define portR25_OFFSET 28
\r
90 #define portR24_OFFSET 32
\r
91 #define portR23_OFFSET 36
\r
92 #define portR22_OFFSET 40
\r
93 #define portR21_OFFSET 44
\r
94 #define portR20_OFFSET 48
\r
95 #define portR19_OFFSET 52
\r
96 #define portR18_OFFSET 56
\r
97 #define portR17_OFFSET 60
\r
98 #define portR16_OFFSET 64
\r
99 #define portR15_OFFSET 68
\r
100 #define portR14_OFFSET 72
\r
101 #define portR13_OFFSET 76
\r
102 #define portR12_OFFSET 80
\r
103 #define portR11_OFFSET 84
\r
104 #define portR10_OFFSET 88
\r
105 #define portR9_OFFSET 92
\r
106 #define portR8_OFFSET 96
\r
107 #define portR7_OFFSET 100
\r
108 #define portR6_OFFSET 104
\r
109 #define portR5_OFFSET 108
\r
110 #define portR4_OFFSET 112
\r
111 #define portR3_OFFSET 116
\r
112 #define portR2_OFFSET 120
\r
113 #define portCRITICAL_NESTING_OFFSET 124
\r
114 #define portMSR_OFFSET 128
\r
115 #define portFSR_OFFSET 132
\r
117 .extern pxCurrentTCB
\r
118 .extern XIntc_DeviceInterruptHandler
\r
119 .extern vTaskSwitchContext
\r
120 .extern uxCriticalNesting
\r
121 .extern pulISRStack
\r
122 .extern ulTaskSwitchRequested
\r
123 .extern vPortExceptionHandler
\r
124 .extern pulStackPointerOnFunctionEntry
\r
126 .global _interrupt_handler
\r
127 .global VPortYieldASM
\r
128 .global vPortStartFirstTask
\r
129 .global vPortExceptionHandlerEntry
\r
132 .macro portSAVE_CONTEXT
\r
134 /* Make room for the context on the stack. */
\r
135 addik r1, r1, portMINUS_CONTEXT_SIZE
\r
137 /* Stack general registers. */
\r
138 swi r31, r1, portR31_OFFSET
\r
139 swi r30, r1, portR30_OFFSET
\r
140 swi r29, r1, portR29_OFFSET
\r
141 swi r28, r1, portR28_OFFSET
\r
142 swi r27, r1, portR27_OFFSET
\r
143 swi r26, r1, portR26_OFFSET
\r
144 swi r25, r1, portR25_OFFSET
\r
145 swi r24, r1, portR24_OFFSET
\r
146 swi r23, r1, portR23_OFFSET
\r
147 swi r22, r1, portR22_OFFSET
\r
148 swi r21, r1, portR21_OFFSET
\r
149 swi r20, r1, portR20_OFFSET
\r
150 swi r19, r1, portR19_OFFSET
\r
151 swi r18, r1, portR18_OFFSET
\r
152 swi r17, r1, portR17_OFFSET
\r
153 swi r16, r1, portR16_OFFSET
\r
154 swi r15, r1, portR15_OFFSET
\r
155 /* R14 is saved later as it needs adjustment if a yield is performed. */
\r
156 swi r13, r1, portR13_OFFSET
\r
157 swi r12, r1, portR12_OFFSET
\r
158 swi r11, r1, portR11_OFFSET
\r
159 swi r10, r1, portR10_OFFSET
\r
160 swi r9, r1, portR9_OFFSET
\r
161 swi r8, r1, portR8_OFFSET
\r
162 swi r7, r1, portR7_OFFSET
\r
163 swi r6, r1, portR6_OFFSET
\r
164 swi r5, r1, portR5_OFFSET
\r
165 swi r4, r1, portR4_OFFSET
\r
166 swi r3, r1, portR3_OFFSET
\r
167 swi r2, r1, portR2_OFFSET
\r
169 /* Stack the critical section nesting value. */
\r
170 lwi r18, r0, uxCriticalNesting
\r
171 swi r18, r1, portCRITICAL_NESTING_OFFSET
\r
175 swi r18, r1, portMSR_OFFSET
\r
177 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
180 swi r18, r1, portFSR_OFFSET
\r
183 /* Save the top of stack value to the TCB. */
\r
184 lwi r3, r0, pxCurrentTCB
\r
189 .macro portRESTORE_CONTEXT
\r
191 /* Load the top of stack value from the TCB. */
\r
192 lwi r18, r0, pxCurrentTCB
\r
195 /* Restore the general registers. */
\r
196 lwi r31, r1, portR31_OFFSET
\r
197 lwi r30, r1, portR30_OFFSET
\r
198 lwi r29, r1, portR29_OFFSET
\r
199 lwi r28, r1, portR28_OFFSET
\r
200 lwi r27, r1, portR27_OFFSET
\r
201 lwi r26, r1, portR26_OFFSET
\r
202 lwi r25, r1, portR25_OFFSET
\r
203 lwi r24, r1, portR24_OFFSET
\r
204 lwi r23, r1, portR23_OFFSET
\r
205 lwi r22, r1, portR22_OFFSET
\r
206 lwi r21, r1, portR21_OFFSET
\r
207 lwi r20, r1, portR20_OFFSET
\r
208 lwi r19, r1, portR19_OFFSET
\r
209 lwi r17, r1, portR17_OFFSET
\r
210 lwi r16, r1, portR16_OFFSET
\r
211 lwi r15, r1, portR15_OFFSET
\r
212 lwi r14, r1, portR14_OFFSET
\r
213 lwi r13, r1, portR13_OFFSET
\r
214 lwi r12, r1, portR12_OFFSET
\r
215 lwi r11, r1, portR11_OFFSET
\r
216 lwi r10, r1, portR10_OFFSET
\r
217 lwi r9, r1, portR9_OFFSET
\r
218 lwi r8, r1, portR8_OFFSET
\r
219 lwi r7, r1, portR7_OFFSET
\r
220 lwi r6, r1, portR6_OFFSET
\r
221 lwi r5, r1, portR5_OFFSET
\r
222 lwi r4, r1, portR4_OFFSET
\r
223 lwi r3, r1, portR3_OFFSET
\r
224 lwi r2, r1, portR2_OFFSET
\r
226 /* Reload the rmsr from the stack. */
\r
227 lwi r18, r1, portMSR_OFFSET
\r
230 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
231 /* Reload the FSR from the stack. */
\r
232 lwi r18, r1, portFSR_OFFSET
\r
236 /* Load the critical nesting value. */
\r
237 lwi r18, r1, portCRITICAL_NESTING_OFFSET
\r
238 swi r18, r0, uxCriticalNesting
\r
240 /* Test the critical nesting value. If it is non zero then the task last
\r
241 exited the running state using a yield. If it is zero, then the task
\r
242 last exited the running state through an interrupt. */
\r
244 bnei r18, exit_from_yield
\r
246 /* r18 was being used as a temporary. Now restore its true value from the
\r
248 lwi r18, r1, portR18_OFFSET
\r
250 /* Remove the stack frame. */
\r
251 addik r1, r1, portCONTEXT_SIZE
\r
253 /* Return using rtid so interrupts are re-enabled as this function is
\r
260 /* This function is used to exit portRESTORE_CONTEXT() if the task being
\r
261 returned to last left the Running state by calling taskYIELD() (rather than
\r
262 being preempted by an interrupt). */
\r
267 /* r18 was being used as a temporary. Now restore its true value from the
\r
269 lwi r18, r1, portR18_OFFSET
\r
271 /* Remove the stack frame. */
\r
272 addik r1, r1, portCONTEXT_SIZE
\r
274 /* Return to the task. */
\r
281 _interrupt_handler:
\r
285 /* Stack the return address. */
\r
286 swi r14, r1, portR14_OFFSET
\r
288 /* Switch to the ISR stack. */
\r
289 lwi r1, r0, pulISRStack
\r
291 /* The parameter to the interrupt handler. */
\r
292 ori r5, r0, configINTERRUPT_CONTROLLER_TO_USE
\r
294 /* Execute any pending interrupts. */
\r
295 bralid r15, XIntc_DeviceInterruptHandler
\r
298 /* See if a new task should be selected to execute. */
\r
299 lwi r18, r0, ulTaskSwitchRequested
\r
302 /* If ulTaskSwitchRequested is already zero, then jump straight to
\r
303 restoring the task that is already in the Running state. */
\r
304 beqi r18, task_switch_not_requested
\r
306 /* Set ulTaskSwitchRequested back to zero as a task switch is about to be
\r
308 swi r0, r0, ulTaskSwitchRequested
\r
310 /* ulTaskSwitchRequested was not 0 when tested. Select the next task to
\r
312 bralid r15, vTaskSwitchContext
\r
315 task_switch_not_requested:
\r
317 /* Restore the context of the next task scheduled to execute. */
\r
318 portRESTORE_CONTEXT
\r
327 /* Modify the return address so a return is done to the instruction after
\r
328 the call to VPortYieldASM. */
\r
330 swi r14, r1, portR14_OFFSET
\r
332 /* Switch to use the ISR stack. */
\r
333 lwi r1, r0, pulISRStack
\r
335 /* Select the next task to execute. */
\r
336 bralid r15, vTaskSwitchContext
\r
339 /* Restore the context of the next task scheduled to execute. */
\r
340 portRESTORE_CONTEXT
\r
344 vPortStartFirstTask:
\r
346 portRESTORE_CONTEXT
\r
350 #if MICROBLAZE_EXCEPTIONS_ENABLED == 1
\r
354 vPortExceptionHandlerEntry:
\r
356 /* Take a copy of the stack pointer before vPortExecptionHandler is called,
\r
357 storing its value prior to the function stack frame being created. */
\r
358 swi r1, r0, pulStackPointerOnFunctionEntry
\r
359 bralid r15, vPortExceptionHandler
\r
362 #endif /* MICROBLAZE_EXCEPTIONS_ENABLED */
\r