1 /*This file has been prepared for Doxygen automatic documentation generation.*/
\r
2 /*! \file *********************************************************************
\r
4 * \brief FreeRTOS port header for AVR32 UC3.
\r
6 * - Compiler: IAR EWAVR32
\r
7 * - Supported devices: All AVR32 devices can be used.
\r
10 * \author Atmel Corporation: http://www.atmel.com \n
\r
11 * Support and FAQ: http://support.atmel.no/
\r
13 *****************************************************************************/
\r
16 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
18 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
19 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
21 ***************************************************************************
\r
23 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
24 * Complete, revised, and edited pdf reference manuals are also *
\r
27 * Purchasing FreeRTOS documentation will not only help you, by *
\r
28 * ensuring you get running as quickly as possible and with an *
\r
29 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
30 * the FreeRTOS project to continue with its mission of providing *
\r
31 * professional grade, cross platform, de facto standard solutions *
\r
32 * for microcontrollers - completely free of charge! *
\r
34 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
36 * Thank you for using FreeRTOS, and thank you for your support! *
\r
38 ***************************************************************************
\r
41 This file is part of the FreeRTOS distribution.
\r
43 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
44 the terms of the GNU General Public License (version 2) as published by the
\r
45 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
47 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
48 distribute a combined work that includes FreeRTOS without being obliged to
\r
49 provide the source code for proprietary components outside of the FreeRTOS
\r
52 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
53 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
54 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
55 details. You should have received a copy of the GNU General Public License
\r
56 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
57 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
58 writing to Real Time Engineers Ltd., contact details for whom are available
\r
59 on the FreeRTOS WEB site.
\r
63 ***************************************************************************
\r
65 * Having a problem? Start by reading the FAQ "My application does *
\r
66 * not run, what could be wrong?" *
\r
68 * http://www.FreeRTOS.org/FAQHelp.html *
\r
70 ***************************************************************************
\r
73 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
74 license and Real Time Engineers Ltd. contact details.
\r
76 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
77 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
78 fully thread aware and reentrant UDP/IP stack.
\r
80 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
81 Integrity Systems, who sell the code with commercial support,
\r
82 indemnification and middleware, under the OpenRTOS brand.
\r
84 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
85 engineered and independently SIL3 certified version for use in safety and
\r
86 mission critical applications that require provable dependability.
\r
94 /*-----------------------------------------------------------
\r
95 * Port specific definitions.
\r
97 * The settings in this file configure FreeRTOS correctly for the
\r
98 * given hardware and compiler.
\r
100 * These settings should not be altered.
\r
101 *-----------------------------------------------------------
\r
103 #include <avr32/io.h>
\r
105 #include "compiler.h"
\r
112 /* Type definitions. */
\r
113 #define portCHAR char
\r
114 #define portFLOAT float
\r
115 #define portDOUBLE double
\r
116 #define portLONG long
\r
117 #define portSHORT short
\r
118 #define portSTACK_TYPE unsigned portLONG
\r
119 #define portBASE_TYPE portLONG
\r
121 #define TASK_DELAY_MS(x) ( (x) /portTICK_RATE_MS )
\r
122 #define TASK_DELAY_S(x) ( (x)*1000 /portTICK_RATE_MS )
\r
123 #define TASK_DELAY_MIN(x) ( (x)*60*1000/portTICK_RATE_MS )
\r
125 #define configTICK_TC_IRQ ATPASTE2(AVR32_TC_IRQ, configTICK_TC_CHANNEL)
\r
127 #if( configUSE_16_BIT_TICKS == 1 )
\r
128 typedef unsigned portSHORT portTickType;
\r
129 #define portMAX_DELAY ( portTickType ) 0xffff
\r
131 typedef unsigned portLONG portTickType;
\r
132 #define portMAX_DELAY ( portTickType ) 0xffffffff
\r
134 /*-----------------------------------------------------------*/
\r
136 /* Architecture specifics. */
\r
137 #define portSTACK_GROWTH ( -1 )
\r
138 #define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
\r
139 #define portBYTE_ALIGNMENT 4
\r
140 #define portNOP() {__asm__ __volatile__ ("nop");}
\r
141 /*-----------------------------------------------------------*/
\r
144 /*-----------------------------------------------------------*/
\r
146 /* INTC-specific. */
\r
147 #define DISABLE_ALL_EXCEPTIONS() Disable_global_exception()
\r
148 #define ENABLE_ALL_EXCEPTIONS() Enable_global_exception()
\r
150 #define DISABLE_ALL_INTERRUPTS() Disable_global_interrupt()
\r
151 #define ENABLE_ALL_INTERRUPTS() Enable_global_interrupt()
\r
153 #define DISABLE_INT_LEVEL(int_lev) Disable_interrupt_level(int_lev)
\r
154 #define ENABLE_INT_LEVEL(int_lev) Enable_interrupt_level(int_lev)
\r
159 * Activated if and only if configDBG is nonzero.
\r
160 * Prints a formatted string to stdout.
\r
161 * The current source file name and line number are output with a colon before
\r
162 * the formatted string.
\r
163 * A carriage return and a linefeed are appended to the output.
\r
164 * stdout is redirected to the USART configured by configDBG_USART.
\r
165 * The parameters are the same as for the standard printf function.
\r
166 * There is no return value.
\r
167 * SHALL NOT BE CALLED FROM WITHIN AN INTERRUPT as fputs and printf use malloc,
\r
168 * which is interrupt-unsafe with the current __malloc_lock and __malloc_unlock.
\r
171 #define portDBG_TRACE(...) \
\r
173 fputs(__FILE__ ":" ASTRINGZ(__LINE__) ": ", stdout); \
\r
174 printf(__VA_ARGS__); \
\r
175 fputs("\r\n", stdout); \
\r
178 #define portDBG_TRACE(...)
\r
182 /* Critical section management. */
\r
183 #define portDISABLE_INTERRUPTS() DISABLE_ALL_INTERRUPTS()
\r
184 #define portENABLE_INTERRUPTS() ENABLE_ALL_INTERRUPTS()
\r
187 extern void vPortEnterCritical( void );
\r
188 extern void vPortExitCritical( void );
\r
190 #define portENTER_CRITICAL() vPortEnterCritical();
\r
191 #define portEXIT_CRITICAL() vPortExitCritical();
\r
194 /* Added as there is no such function in FreeRTOS. */
\r
195 extern void *pvPortRealloc( void *pv, size_t xSize );
\r
196 /*-----------------------------------------------------------*/
\r
199 /*=============================================================================================*/
\r
202 * Restore Context for cases other than INTi.
\r
204 #define portRESTORE_CONTEXT() \
\r
206 extern volatile unsigned portLONG ulCriticalNesting; \
\r
207 extern volatile void *volatile pxCurrentTCB; \
\r
209 __asm__ __volatile__ ( \
\r
210 /* Set SP to point to new stack */ \
\r
211 "mov r8, LWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
212 "orh r8, HWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
213 "ld.w r0, r8[0] \n\t"\
\r
214 "ld.w sp, r0[0] \n\t"\
\r
216 /* Restore ulCriticalNesting variable */ \
\r
217 "ld.w r0, sp++ \n\t"\
\r
218 "mov r8, LWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
219 "orh r8, HWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
220 "st.w r8[0], r0 \n\t"\
\r
222 /* Restore R0..R7 */ \
\r
223 "ldm sp++, r0-r7 \n\t"\
\r
224 /* R0-R7 should not be used below this line */ \
\r
225 /* Skip PC and SR (will do it at the end) */ \
\r
226 "sub sp, -2*4 \n\t"\
\r
227 /* Restore R8..R12 and LR */ \
\r
228 "ldm sp++, r8-r12, lr \n\t"\
\r
230 "ld.w r0, sp[-8*4] \n\t" /* R0 is modified, is restored later. */\
\r
231 "mtsr "ASTRINGZ(AVR32_SR)", r0 \n\t"\
\r
233 "ld.w r0, sp[-9*4] \n\t"\
\r
235 "ld.w pc, sp[-7*4]" /* Get PC from stack - PC is the 7th register saved */ \
\r
238 /* Force import of global symbols from assembly */ \
\r
239 ulCriticalNesting; \
\r
245 * portSAVE_CONTEXT_INT() and portRESTORE_CONTEXT_INT(): for INT0..3 exceptions.
\r
246 * portSAVE_CONTEXT_SCALL() and portRESTORE_CONTEXT_SCALL(): for the scall exception.
\r
248 * Had to make different versions because registers saved on the system stack
\r
249 * are not the same between INT0..3 exceptions and the scall exception.
\r
252 // Task context stack layout:
\r
269 // ulCriticalNesting
\r
270 // (*) automatically done for INT0..INT3, but not for SCALL
\r
273 * The ISR used for the scheduler tick depends on whether the cooperative or
\r
274 * the preemptive scheduler is being used.
\r
276 #if configUSE_PREEMPTION == 0
\r
279 * portSAVE_CONTEXT_OS_INT() for OS Tick exception.
\r
281 #define portSAVE_CONTEXT_OS_INT() \
\r
283 /* Save R0..R7 */ \
\r
284 __asm__ __volatile__ ("stm --sp, r0-r7"); \
\r
286 /* With the cooperative scheduler, as there is no context switch by interrupt, */ \
\r
287 /* there is also no context save. */ \
\r
291 * portRESTORE_CONTEXT_OS_INT() for Tick exception.
\r
293 #define portRESTORE_CONTEXT_OS_INT() \
\r
295 __asm__ __volatile__ ( \
\r
296 /* Restore R0..R7 */ \
\r
297 "ldm sp++, r0-r7 \n\t"\
\r
299 /* With the cooperative scheduler, as there is no context switch by interrupt, */ \
\r
300 /* there is also no context restore. */ \
\r
308 * portSAVE_CONTEXT_OS_INT() for OS Tick exception.
\r
310 #define portSAVE_CONTEXT_OS_INT() \
\r
312 extern volatile unsigned portLONG ulCriticalNesting; \
\r
313 extern volatile void *volatile pxCurrentTCB; \
\r
315 /* When we come here */ \
\r
316 /* Registers R8..R12, LR, PC and SR had already been pushed to system stack */ \
\r
318 __asm__ __volatile__ ( \
\r
319 /* Save R0..R7 */ \
\r
320 "stm --sp, r0-r7 \n\t"\
\r
322 /* Save ulCriticalNesting variable - R0 is overwritten */ \
\r
323 "mov r8, LWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
324 "orh r8, HWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
325 "ld.w r0, r8[0] \n\t"\
\r
326 "st.w --sp, r0 \n\t"\
\r
328 /* Check if INT0 or higher were being handled (case where the OS tick interrupted another */ \
\r
329 /* interrupt handler (which was of a higher priority level but decided to lower its priority */ \
\r
330 /* level and allow other lower interrupt level to occur). */ \
\r
331 /* In this case we don't want to do a task switch because we don't know what the stack */ \
\r
332 /* currently looks like (we don't know what the interrupted interrupt handler was doing). */ \
\r
333 /* Saving SP in pxCurrentTCB and then later restoring it (thinking restoring the task) */ \
\r
334 /* will just be restoring the interrupt handler, no way!!! */ \
\r
335 /* So, since we won't do a vTaskSwitchContext(), it's of no use to save SP. */ \
\r
336 "ld.w r0, sp[9*4] \n\t" /* Read SR in stack */\
\r
337 "bfextu r0, r0, 22, 3 \n\t" /* Extract the mode bits to R0. */\
\r
338 "cp.w r0, 1 \n\t" /* Compare the mode bits with supervisor mode(b'001) */\
\r
339 "brhi LABEL_INT_SKIP_SAVE_CONTEXT_"ASTRINGZ(__LINE__)" \n\t"\
\r
341 /* Store SP in the first member of the structure pointed to by pxCurrentTCB */ \
\r
342 /* NOTE: we don't enter a critical section here because all interrupt handlers */ \
\r
343 /* MUST perform a SAVE_CONTEXT/RESTORE_CONTEXT in the same way as */ \
\r
344 /* portSAVE_CONTEXT_OS_INT/port_RESTORE_CONTEXT_OS_INT if they call OS functions. */ \
\r
345 /* => all interrupt handlers must use portENTER_SWITCHING_ISR/portEXIT_SWITCHING_ISR. */ \
\r
346 "mov r8, LWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
347 "orh r8, HWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
348 "ld.w r0, r8[0] \n\t"\
\r
349 "st.w r0[0], sp \n"\
\r
351 "LABEL_INT_SKIP_SAVE_CONTEXT_"ASTRINGZ(__LINE__)":" \
\r
356 * portRESTORE_CONTEXT_OS_INT() for Tick exception.
\r
358 #define portRESTORE_CONTEXT_OS_INT() \
\r
360 extern volatile unsigned portLONG ulCriticalNesting; \
\r
361 extern volatile void *volatile pxCurrentTCB; \
\r
363 /* Check if INT0 or higher were being handled (case where the OS tick interrupted another */ \
\r
364 /* interrupt handler (which was of a higher priority level but decided to lower its priority */ \
\r
365 /* level and allow other lower interrupt level to occur). */ \
\r
366 /* In this case we don't want to do a task switch because we don't know what the stack */ \
\r
367 /* currently looks like (we don't know what the interrupted interrupt handler was doing). */ \
\r
368 /* Saving SP in pxCurrentTCB and then later restoring it (thinking restoring the task) */ \
\r
369 /* will just be restoring the interrupt handler, no way!!! */ \
\r
370 __asm__ __volatile__ ( \
\r
371 "ld.w r0, sp[9*4] \n\t" /* Read SR in stack */\
\r
372 "bfextu r0, r0, 22, 3 \n\t" /* Extract the mode bits to R0. */\
\r
373 "cp.w r0, 1 \n\t" /* Compare the mode bits with supervisor mode(b'001) */\
\r
374 "brhi LABEL_INT_SKIP_RESTORE_CONTEXT_"ASTRINGZ(__LINE__) \
\r
378 /* because it is here safe, always call vTaskSwitchContext() since an OS tick occurred. */ \
\r
379 /* A critical section has to be used here because vTaskSwitchContext handles FreeRTOS linked lists. */\
\r
380 portENTER_CRITICAL(); \
\r
381 vTaskSwitchContext(); \
\r
382 portEXIT_CRITICAL(); \
\r
384 /* Restore all registers */ \
\r
386 __asm__ __volatile__ ( \
\r
387 /* Set SP to point to new stack */ \
\r
388 "mov r8, LWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
389 "orh r8, HWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
390 "ld.w r0, r8[0] \n\t"\
\r
391 "ld.w sp, r0[0] \n"\
\r
393 "LABEL_INT_SKIP_RESTORE_CONTEXT_"ASTRINGZ(__LINE__)": \n\t"\
\r
395 /* Restore ulCriticalNesting variable */ \
\r
396 "ld.w r0, sp++ \n\t"\
\r
397 "mov r8, LWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
398 "orh r8, HWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
399 "st.w r8[0], r0 \n\t"\
\r
401 /* Restore R0..R7 */ \
\r
402 "ldm sp++, r0-r7 \n\t"\
\r
404 /* Now, the stack should be R8..R12, LR, PC and SR */ \
\r
408 /* Force import of global symbols from assembly */ \
\r
409 ulCriticalNesting; \
\r
417 * portSAVE_CONTEXT_SCALL() for SupervisorCALL exception.
\r
419 * NOTE: taskYIELD()(== SCALL) MUST NOT be called in a mode > supervisor mode.
\r
422 #define portSAVE_CONTEXT_SCALL() \
\r
424 extern volatile unsigned portLONG ulCriticalNesting; \
\r
425 extern volatile void *volatile pxCurrentTCB; \
\r
427 /* Warning: the stack layout after SCALL doesn't match the one after an interrupt. */ \
\r
428 /* If SR[M2:M0] == 001 */ \
\r
429 /* PC and SR are on the stack. */ \
\r
430 /* Else (other modes) */ \
\r
431 /* Nothing on the stack. */ \
\r
433 /* WARNING NOTE: the else case cannot happen as it is strictly forbidden to call */ \
\r
434 /* vTaskDelay() and vTaskDelayUntil() OS functions (that result in a taskYield()) */ \
\r
435 /* in an interrupt|exception handler. */ \
\r
437 __asm__ __volatile__ ( \
\r
438 /* in order to save R0-R7 */ \
\r
439 "sub sp, 6*4 \n\t"\
\r
440 /* Save R0..R7 */ \
\r
441 "stm --sp, r0-r7 \n\t"\
\r
443 /* in order to save R8-R12 and LR */ \
\r
444 /* do not use SP if interrupts occurs, SP must be left at bottom of stack */ \
\r
445 "sub r7, sp,-16*4 \n\t"\
\r
446 /* Copy PC and SR in other places in the stack. */ \
\r
447 "ld.w r0, r7[-2*4] \n\t" /* Read SR */\
\r
448 "st.w r7[-8*4], r0 \n\t" /* Copy SR */\
\r
449 "ld.w r0, r7[-1*4] \n\t" /* Read PC */\
\r
450 "st.w r7[-7*4], r0 \n\t" /* Copy PC */\
\r
452 /* Save R8..R12 and LR on the stack. */ \
\r
453 "stm --r7, r8-r12, lr \n\t"\
\r
455 /* Arriving here we have the following stack organizations: */ \
\r
456 /* R8..R12, LR, PC, SR, R0..R7. */ \
\r
458 /* Now we can finalize the save. */ \
\r
460 /* Save ulCriticalNesting variable - R0 is overwritten */ \
\r
461 "mov r8, LWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
462 "orh r8, HWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
463 "ld.w r0, r8[0] \n\t"\
\r
467 /* Disable the its which may cause a context switch (i.e. cause a change of */ \
\r
468 /* pxCurrentTCB). */ \
\r
469 /* Basically, all accesses to the pxCurrentTCB structure should be put in a */ \
\r
470 /* critical section because it is a global structure. */ \
\r
471 portENTER_CRITICAL(); \
\r
473 /* Store SP in the first member of the structure pointed to by pxCurrentTCB */ \
\r
474 __asm__ __volatile__ ( \
\r
475 "mov r8, LWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
476 "orh r8, HWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
477 "ld.w r0, r8[0] \n\t"\
\r
483 * portRESTORE_CONTEXT() for SupervisorCALL exception.
\r
485 #define portRESTORE_CONTEXT_SCALL() \
\r
487 extern volatile unsigned portLONG ulCriticalNesting; \
\r
488 extern volatile void *volatile pxCurrentTCB; \
\r
490 /* Restore all registers */ \
\r
492 /* Set SP to point to new stack */ \
\r
493 __asm__ __volatile__ ( \
\r
494 "mov r8, LWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
495 "orh r8, HWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
496 "ld.w r0, r8[0] \n\t"\
\r
500 /* Leave pxCurrentTCB variable access critical section */ \
\r
501 portEXIT_CRITICAL(); \
\r
503 __asm__ __volatile__ ( \
\r
504 /* Restore ulCriticalNesting variable */ \
\r
505 "ld.w r0, sp++ \n\t"\
\r
506 "mov r8, LWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
507 "orh r8, HWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
508 "st.w r8[0], r0 \n\t"\
\r
510 /* skip PC and SR */ \
\r
511 /* do not use SP if interrupts occurs, SP must be left at bottom of stack */ \
\r
512 "sub r7, sp, -10*4 \n\t"\
\r
513 /* Restore r8-r12 and LR */ \
\r
514 "ldm r7++, r8-r12, lr \n\t"\
\r
516 /* RETS will take care of the extra PC and SR restore. */ \
\r
517 /* So, we have to prepare the stack for this. */ \
\r
518 "ld.w r0, r7[-8*4] \n\t" /* Read SR */\
\r
519 "st.w r7[-2*4], r0 \n\t" /* Copy SR */\
\r
520 "ld.w r0, r7[-7*4] \n\t" /* Read PC */\
\r
521 "st.w r7[-1*4], r0 \n\t" /* Copy PC */\
\r
523 /* Restore R0..R7 */ \
\r
524 "ldm sp++, r0-r7 \n\t"\
\r
526 "sub sp, -6*4 \n\t"\
\r
531 /* Force import of global symbols from assembly */ \
\r
532 ulCriticalNesting; \
\r
538 * The ISR used depends on whether the cooperative or
\r
539 * the preemptive scheduler is being used.
\r
541 #if configUSE_PREEMPTION == 0
\r
544 * ISR entry and exit macros. These are only required if a task switch
\r
545 * is required from the ISR.
\r
547 #define portENTER_SWITCHING_ISR() \
\r
549 /* Save R0..R7 */ \
\r
550 __asm__ __volatile__ ("stm --sp, r0-r7"); \
\r
552 /* With the cooperative scheduler, as there is no context switch by interrupt, */ \
\r
553 /* there is also no context save. */ \
\r
557 * Input parameter: in R12, boolean. Perform a vTaskSwitchContext() if 1
\r
559 #define portEXIT_SWITCHING_ISR() \
\r
561 __asm__ __volatile__ ( \
\r
562 /* Restore R0..R7 */ \
\r
563 "ldm sp++, r0-r7 \n\t"\
\r
565 /* With the cooperative scheduler, as there is no context switch by interrupt, */ \
\r
566 /* there is also no context restore. */ \
\r
574 * ISR entry and exit macros. These are only required if a task switch
\r
575 * is required from the ISR.
\r
577 #define portENTER_SWITCHING_ISR() \
\r
579 extern volatile unsigned portLONG ulCriticalNesting; \
\r
580 extern volatile void *volatile pxCurrentTCB; \
\r
582 /* When we come here */ \
\r
583 /* Registers R8..R12, LR, PC and SR had already been pushed to system stack */ \
\r
585 __asm__ __volatile__ ( \
\r
586 /* Save R0..R7 */ \
\r
587 "stm --sp, r0-r7 \n\t"\
\r
589 /* Save ulCriticalNesting variable - R0 is overwritten */ \
\r
590 "mov r8, LWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
591 "orh r8, HWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
592 "ld.w r0, r8[0] \n\t"\
\r
593 "st.w --sp, r0 \n\t"\
\r
595 /* Check if INT0 or higher were being handled (case where the OS tick interrupted another */ \
\r
596 /* interrupt handler (which was of a higher priority level but decided to lower its priority */ \
\r
597 /* level and allow other lower interrupt level to occur). */ \
\r
598 /* In this case we don't want to do a task switch because we don't know what the stack */ \
\r
599 /* currently looks like (we don't know what the interrupted interrupt handler was doing). */ \
\r
600 /* Saving SP in pxCurrentTCB and then later restoring it (thinking restoring the task) */ \
\r
601 /* will just be restoring the interrupt handler, no way!!! */ \
\r
602 /* So, since we won't do a vTaskSwitchContext(), it's of no use to save SP. */ \
\r
603 "ld.w r0, sp[9*4] \n\t" /* Read SR in stack */\
\r
604 "bfextu r0, r0, 22, 3 \n\t" /* Extract the mode bits to R0. */\
\r
605 "cp.w r0, 1 \n\t" /* Compare the mode bits with supervisor mode(b'001) */\
\r
606 "brhi LABEL_ISR_SKIP_SAVE_CONTEXT_"ASTRINGZ(__LINE__)" \n\t"\
\r
608 /* Store SP in the first member of the structure pointed to by pxCurrentTCB */ \
\r
609 "mov r8, LWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
610 "orh r8, HWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
611 "ld.w r0, r8[0] \n\t"\
\r
612 "st.w r0[0], sp \n"\
\r
614 "LABEL_ISR_SKIP_SAVE_CONTEXT_"ASTRINGZ(__LINE__)":" \
\r
620 * Input parameter: in R12, boolean. Perform a vTaskSwitchContext() if 1
\r
622 #define portEXIT_SWITCHING_ISR() \
\r
624 extern volatile unsigned portLONG ulCriticalNesting; \
\r
625 extern volatile void *volatile pxCurrentTCB; \
\r
627 __asm__ __volatile__ ( \
\r
628 /* Check if INT0 or higher were being handled (case where the OS tick interrupted another */ \
\r
629 /* interrupt handler (which was of a higher priority level but decided to lower its priority */ \
\r
630 /* level and allow other lower interrupt level to occur). */ \
\r
631 /* In this case it's of no use to switch context and restore a new SP because we purposedly */ \
\r
632 /* did not previously save SP in its TCB. */ \
\r
633 "ld.w r0, sp[9*4] \n\t" /* Read SR in stack */\
\r
634 "bfextu r0, r0, 22, 3 \n\t" /* Extract the mode bits to R0. */\
\r
635 "cp.w r0, 1 \n\t" /* Compare the mode bits with supervisor mode(b'001) */\
\r
636 "brhi LABEL_ISR_SKIP_RESTORE_CONTEXT_"ASTRINGZ(__LINE__)" \n\t"\
\r
638 /* If a switch is required then we just need to call */ \
\r
639 /* vTaskSwitchContext() as the context has already been */ \
\r
641 "cp.w r12, 1 \n\t" /* Check if Switch context is required. */\
\r
642 "brne LABEL_ISR_RESTORE_CONTEXT_"ASTRINGZ(__LINE__)":C" \
\r
645 /* A critical section has to be used here because vTaskSwitchContext handles FreeRTOS linked lists. */\
\r
646 portENTER_CRITICAL(); \
\r
647 vTaskSwitchContext(); \
\r
648 portEXIT_CRITICAL(); \
\r
650 __asm__ __volatile__ ( \
\r
651 "LABEL_ISR_RESTORE_CONTEXT_"ASTRINGZ(__LINE__)": \n\t"\
\r
652 /* Restore the context of which ever task is now the highest */ \
\r
653 /* priority that is ready to run. */ \
\r
655 /* Restore all registers */ \
\r
657 /* Set SP to point to new stack */ \
\r
658 "mov r8, LWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
659 "orh r8, HWRD("ASTRINGZ(pxCurrentTCB)") \n\t"\
\r
660 "ld.w r0, r8[0] \n\t"\
\r
661 "ld.w sp, r0[0] \n"\
\r
663 "LABEL_ISR_SKIP_RESTORE_CONTEXT_"ASTRINGZ(__LINE__)": \n\t"\
\r
665 /* Restore ulCriticalNesting variable */ \
\r
666 "ld.w r0, sp++ \n\t"\
\r
667 "mov r8, LWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
668 "orh r8, HWRD("ASTRINGZ(ulCriticalNesting)") \n\t"\
\r
669 "st.w r8[0], r0 \n\t"\
\r
671 /* Restore R0..R7 */ \
\r
672 "ldm sp++, r0-r7 \n\t"\
\r
674 /* Now, the stack should be R8..R12, LR, PC and SR */ \
\r
678 /* Force import of global symbols from assembly */ \
\r
679 ulCriticalNesting; \
\r
686 #define portYIELD() {__asm__ __volatile__ ("scall");}
\r
688 /* Task function macros as described on the FreeRTOS.org WEB site. */
\r
689 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
690 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
\r
696 #endif /* PORTMACRO_H */
\r