2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:
\r
6 Atollic AB - Atollic provides professional embedded systems development
\r
7 tools for C/C++ development, code analysis and test automation.
\r
8 See http://www.atollic.com
\r
11 ***************************************************************************
\r
13 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
14 * Complete, revised, and edited pdf reference manuals are also *
\r
17 * Purchasing FreeRTOS documentation will not only help you, by *
\r
18 * ensuring you get running as quickly as possible and with an *
\r
19 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
20 * the FreeRTOS project to continue with its mission of providing *
\r
21 * professional grade, cross platform, de facto standard solutions *
\r
22 * for microcontrollers - completely free of charge! *
\r
24 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
26 * Thank you for using FreeRTOS, and thank you for your support! *
\r
28 ***************************************************************************
\r
31 This file is part of the FreeRTOS distribution.
\r
33 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
34 the terms of the GNU General Public License (version 2) as published by the
\r
35 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
36 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
37 distribute a combined work that includes FreeRTOS without being obliged to
\r
38 provide the source code for proprietary components outside of the FreeRTOS
\r
39 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
40 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
41 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
42 more details. You should have received a copy of the GNU General Public
\r
43 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
44 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
45 by writing to Richard Barry, contact details for whom are available on the
\r
50 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
53 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
56 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
57 licensing and training services.
\r
60 #include "FreeRTOSConfig.h"
\r
61 #include "microblaze_exceptions_g.h"
\r
62 #include "xparameters.h"
\r
64 /* The context is oversized to allow functions called from the ISR to write
\r
65 back into the caller stack. */
\r
66 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
67 #define portCONTEXT_SIZE 136
\r
69 #define portCONTEXT_SIZE 132
\r
72 /* Offsets from the stack pointer at which saved registers are placed. */
\r
73 #define portR31_OFFSET 4
\r
74 #define portR30_OFFSET 8
\r
75 #define portR29_OFFSET 12
\r
76 #define portR28_OFFSET 16
\r
77 #define portR27_OFFSET 20
\r
78 #define portR26_OFFSET 24
\r
79 #define portR25_OFFSET 28
\r
80 #define portR24_OFFSET 32
\r
81 #define portR23_OFFSET 36
\r
82 #define portR22_OFFSET 40
\r
83 #define portR21_OFFSET 44
\r
84 #define portR20_OFFSET 48
\r
85 #define portR19_OFFSET 52
\r
86 #define portR18_OFFSET 56
\r
87 #define portR17_OFFSET 60
\r
88 #define portR16_OFFSET 64
\r
89 #define portR15_OFFSET 68
\r
90 #define portR14_OFFSET 72
\r
91 #define portR13_OFFSET 76
\r
92 #define portR12_OFFSET 80
\r
93 #define portR11_OFFSET 84
\r
94 #define portR10_OFFSET 88
\r
95 #define portR9_OFFSET 92
\r
96 #define portR8_OFFSET 96
\r
97 #define portR7_OFFSET 100
\r
98 #define portR6_OFFSET 104
\r
99 #define portR5_OFFSET 108
\r
100 #define portR4_OFFSET 112
\r
101 #define portR3_OFFSET 116
\r
102 #define portR2_OFFSET 120
\r
103 #define portCRITICAL_NESTING_OFFSET 124
\r
104 #define portMSR_OFFSET 128
\r
105 #define portFSR_OFFSET 132
\r
107 .extern pxCurrentTCB
\r
108 .extern XIntc_DeviceInterruptHandler
\r
109 .extern vTaskSwitchContext
\r
110 .extern uxCriticalNesting
\r
111 .extern pulISRStack
\r
112 .extern ulTaskSwitchRequested
\r
113 .extern vPortExceptionHandler
\r
114 .extern pulStackPointerOnFunctionEntry
\r
115 .extern ulBTROnFunctionEntry
\r
117 .global _interrupt_handler
\r
118 .global VPortYieldASM
\r
119 .global vPortStartFirstTask
\r
120 .global vPortExceptionHandlerEntry
\r
123 .macro portSAVE_CONTEXT
\r
125 /* Make room for the context on the stack. */
\r
126 addik r1, r1, -portCONTEXT_SIZE
\r
128 /* Stack general registers. */
\r
129 swi r31, r1, portR31_OFFSET
\r
130 swi r30, r1, portR30_OFFSET
\r
131 swi r29, r1, portR29_OFFSET
\r
132 swi r28, r1, portR28_OFFSET
\r
133 swi r27, r1, portR27_OFFSET
\r
134 swi r26, r1, portR26_OFFSET
\r
135 swi r25, r1, portR25_OFFSET
\r
136 swi r24, r1, portR24_OFFSET
\r
137 swi r23, r1, portR23_OFFSET
\r
138 swi r22, r1, portR22_OFFSET
\r
139 swi r21, r1, portR21_OFFSET
\r
140 swi r20, r1, portR20_OFFSET
\r
141 swi r19, r1, portR19_OFFSET
\r
142 swi r18, r1, portR18_OFFSET
\r
143 swi r17, r1, portR17_OFFSET
\r
144 swi r16, r1, portR16_OFFSET
\r
145 swi r15, r1, portR15_OFFSET
\r
146 /* R14 is saved later as it needs adjustment if a yield is performed. */
\r
147 swi r13, r1, portR13_OFFSET
\r
148 swi r12, r1, portR12_OFFSET
\r
149 swi r11, r1, portR11_OFFSET
\r
150 swi r10, r1, portR10_OFFSET
\r
151 swi r9, r1, portR9_OFFSET
\r
152 swi r8, r1, portR8_OFFSET
\r
153 swi r7, r1, portR7_OFFSET
\r
154 swi r6, r1, portR6_OFFSET
\r
155 swi r5, r1, portR5_OFFSET
\r
156 swi r4, r1, portR4_OFFSET
\r
157 swi r3, r1, portR3_OFFSET
\r
158 swi r2, r1, portR2_OFFSET
\r
160 /* Stack the critical section nesting value. */
\r
161 lwi r18, r0, uxCriticalNesting
\r
162 swi r18, r1, portCRITICAL_NESTING_OFFSET
\r
166 swi r18, r1, portMSR_OFFSET
\r
168 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
171 swi r18, r1, portFSR_OFFSET
\r
174 /* Save the top of stack value to the TCB. */
\r
175 lwi r3, r0, pxCurrentTCB
\r
180 .macro portRESTORE_CONTEXT
\r
182 /* Load the top of stack value from the TCB. */
\r
183 lwi r18, r0, pxCurrentTCB
\r
186 /* Restore the general registers. */
\r
187 lwi r31, r1, portR31_OFFSET
\r
188 lwi r30, r1, portR30_OFFSET
\r
189 lwi r29, r1, portR29_OFFSET
\r
190 lwi r28, r1, portR28_OFFSET
\r
191 lwi r27, r1, portR27_OFFSET
\r
192 lwi r26, r1, portR26_OFFSET
\r
193 lwi r25, r1, portR25_OFFSET
\r
194 lwi r24, r1, portR24_OFFSET
\r
195 lwi r23, r1, portR23_OFFSET
\r
196 lwi r22, r1, portR22_OFFSET
\r
197 lwi r21, r1, portR21_OFFSET
\r
198 lwi r20, r1, portR20_OFFSET
\r
199 lwi r19, r1, portR19_OFFSET
\r
200 lwi r17, r1, portR17_OFFSET
\r
201 lwi r16, r1, portR16_OFFSET
\r
202 lwi r15, r1, portR15_OFFSET
\r
203 lwi r14, r1, portR14_OFFSET
\r
204 lwi r13, r1, portR13_OFFSET
\r
205 lwi r12, r1, portR12_OFFSET
\r
206 lwi r11, r1, portR11_OFFSET
\r
207 lwi r10, r1, portR10_OFFSET
\r
208 lwi r9, r1, portR9_OFFSET
\r
209 lwi r8, r1, portR8_OFFSET
\r
210 lwi r7, r1, portR7_OFFSET
\r
211 lwi r6, r1, portR6_OFFSET
\r
212 lwi r5, r1, portR5_OFFSET
\r
213 lwi r4, r1, portR4_OFFSET
\r
214 lwi r3, r1, portR3_OFFSET
\r
215 lwi r2, r1, portR2_OFFSET
\r
217 /* Reload the rmsr from the stack. */
\r
218 lwi r18, r1, portMSR_OFFSET
\r
221 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
222 /* Reload the FSR from the stack. */
\r
223 lwi r18, r1, portFSR_OFFSET
\r
227 /* Load the critical nesting value. */
\r
228 lwi r18, r1, portCRITICAL_NESTING_OFFSET
\r
229 swi r18, r0, uxCriticalNesting
\r
231 /* Test the critical nesting value. If it is non zero then the task last
\r
232 exited the running state using a yield. If it is zero, then the task
\r
233 last exited the running state through an interrupt. */
\r
235 bnei r18, exit_from_yield
\r
237 /* r18 was being used as a temporary. Now restore its true value from the
\r
239 lwi r18, r1, portR18_OFFSET
\r
241 /* Remove the stack frame. */
\r
242 addik r1, r1, portCONTEXT_SIZE
\r
244 /* Return using rtid so interrupts are re-enabled as this function is
\r
251 /* This function is used to exit portRESTORE_CONTEXT() if the task being
\r
252 returned to last left the Running state by calling taskYIELD() (rather than
\r
253 being preempted by an interrupt. */
\r
258 /* r18 was being used as a temporary. Now restore its true value from the
\r
260 lwi r18, r1, portR18_OFFSET
\r
262 /* Remove the stack frame. */
\r
263 addik r1, r1, portCONTEXT_SIZE
\r
265 /* Return to the task. */
\r
272 _interrupt_handler:
\r
276 /* Stack the return address. */
\r
277 swi r14, r1, portR14_OFFSET
\r
279 /* Switch to the ISR stack. The pulISRStack value has already been set to
\r
280 leave space for the caller function to write back into the stack of this
\r
282 lwi r1, r0, pulISRStack
\r
284 /* The parameter to the interrupt handler. */
\r
285 ori r5, r0, configINTERRUPT_CONTROLLER_TO_USE
\r
287 /* Execute any pending interrupts. */
\r
288 bralid r15, XIntc_DeviceInterruptHandler
\r
291 /* See if a new task should be selected to execute. */
\r
292 lwi r18, r0, ulTaskSwitchRequested
\r
295 /* If ulTaskSwitchRequested is already zero, then jump straight to
\r
296 restoring the task that is already in the Running state. */
\r
297 beqi r18, task_switch_not_requested
\r
299 /* Set ulTaskSwitchRequested back to zero as a task switch is about to be
\r
301 swi r0, r0, ulTaskSwitchRequested
\r
303 /* ulTaskSwitchRequested was not 0 when tested. Select the next task to
\r
305 bralid r15, vTaskSwitchContext
\r
308 task_switch_not_requested:
\r
310 /* Restore the context of the next task scheduled to execute. */
\r
311 portRESTORE_CONTEXT
\r
320 /* Modify the return address so a return is done to the instruction after
\r
321 the call to VPortYieldASM. */
\r
323 swi r14, r1, portR14_OFFSET
\r
325 /* Switch to use the ISR stack. */
\r
326 lwi r1, r0, pulISRStack
\r
328 /* Select the next task to execute. */
\r
329 bralid r15, vTaskSwitchContext
\r
332 /* Restore the context of the next task scheduled to execute. */
\r
333 portRESTORE_CONTEXT
\r
337 vPortStartFirstTask:
\r
339 portRESTORE_CONTEXT
\r
343 #if MICROBLAZE_EXCEPTIONS_ENABLED == 1
\r
347 vPortExceptionHandlerEntry:
\r
349 /* Take a copy of the stack pointer before vPortExecptionHandler is called,
\r
350 storing its value prior to the function stack frame being created. */
\r
351 swi r1, r0, pulStackPointerOnFunctionEntry
\r
353 swi r18, r0, ulBTROnFunctionEntry
\r
354 bralid r15, vPortExceptionHandler
\r
357 #endif /* MICROBLAZE_EXCEPTIONS_ENABLED */
\r