2 ; FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 ; ***************************************************************************
\r
7 ; * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 ; * Complete, revised, and edited pdf reference manuals are also *
\r
11 ; * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 ; * ensuring you get running as quickly as possible and with an *
\r
13 ; * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 ; * the FreeRTOS project to continue with its mission of providing *
\r
15 ; * professional grade, cross platform, de facto standard solutions *
\r
16 ; * for microcontrollers - completely free of charge! *
\r
18 ; * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 ; * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ; ***************************************************************************
\r
25 ; This file is part of the FreeRTOS distribution.
\r
27 ; FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 ; the terms of the GNU General Public License (version 2) as published by the
\r
29 ; Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ; >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 ; distribute a combined work that includes FreeRTOS without being obliged to
\r
32 ; provide the source code for proprietary components outside of the FreeRTOS
\r
33 ; kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 ; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 ; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 ; more details. You should have received a copy of the GNU General Public
\r
37 ; License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 ; can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 ; by writing to Richard Barry, contact details for whom are available on the
\r
40 ; FreeRTOS WEB site.
\r
42 ; 1 tab == 4 spaces!
\r
44 ; http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 ; http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 ; http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 ; licensing and training services.
\r
56 ; Declare all extern symbols here - including any ISRs that are referenced in
\r
61 EXTERN SIG_OUTPUT_COMPARE1A
\r
62 EXTERN SIG_UART_RECV
\r
63 EXTERN SIG_UART_DATA
\r
66 ; Functions used by scheduler
\r
67 ; ---------------------------
\r
68 EXTERN vTaskSwitchContext
\r
70 EXTERN xTaskIncrementTick
\r
71 EXTERN uxCriticalNesting
\r
73 ; Functions implemented in this file
\r
74 ; ----------------------------------
\r
76 PUBLIC vPortYieldFromTick
\r
80 ; Interrupt vector table.
\r
81 ; -----------------------
\r
83 ; For simplicity the RTOS tick interrupt routine uses the __task keyword.
\r
84 ; As the IAR compiler does not permit a function to be declared using both
\r
85 ; __task and __interrupt, the use of __task necessitates that the interrupt
\r
86 ; vector table be setup manually.
\r
88 ; To write an ISR, implement the ISR function using the __interrupt keyword
\r
89 ; but do not install the interrupt using the "#pragma vector=ABC" method.
\r
90 ; Instead manually place the name of the ISR in the vector table using an
\r
91 ; ORG and jmp instruction as demonstrated below.
\r
92 ; You will also have to add an EXTERN statement at the top of the file.
\r
97 ORG TIMER1_COMPA_vect ; Vector address
\r
98 jmp SIG_OUTPUT_COMPARE1A ; ISR
\r
100 ORG USART_RXC_vect ; Vector address
\r
101 jmp SIG_UART_RECV ; ISR
\r
103 ORG USART_UDRE_vect ; Vector address
\r
104 jmp SIG_UART_DATA ; ISR
\r
111 ; Saving and Restoring a Task Context and Task Switching
\r
112 ; ------------------------------------------------------
\r
114 ; The IAR compiler does not fully support inline assembler, so saving and
\r
115 ; restoring a task context has to be written in an asm file.
\r
117 ; vPortYield() and vPortYieldFromTick() are usually written in C. Doing
\r
118 ; so in this case would required calls to be made to portSAVE_CONTEXT() and
\r
119 ; portRESTORE_CONTEXT(). This is dis-advantageous as the context switch
\r
120 ; function would require two extra jump and return instructions over the
\r
121 ; WinAVR equivalent.
\r
123 ; To avoid this I have opted to implement both vPortYield() and
\r
124 ; vPortYieldFromTick() in this assembly file. For convenience
\r
125 ; portSAVE_CONTEXT and portRESTORE_CONTEXT are implemented as macros.
\r
127 portSAVE_CONTEXT MACRO
\r
128 st -y, r0 ; First save the r0 register - we need to use this.
\r
129 in r0, SREG ; Obtain the SREG value so we can disable interrupts...
\r
130 cli ; ... as soon as possible.
\r
131 st -y, r0 ; Store the SREG as it was before we disabled interrupts.
\r
133 in r0, SPL ; Next store the hardware stack pointer. The IAR...
\r
134 st -y, r0 ; ... compiler uses the hardware stack as a call stack ...
\r
135 in r0, SPH ; ... only.
\r
138 st -y, r1 ; Now store the rest of the registers. Dont store the ...
\r
139 st -y, r2 ; ... the Y register here as it is used as the software
\r
140 st -y, r3 ; stack pointer and will get saved into the TCB.
\r
167 lds r0, uxCriticalNesting
\r
168 st -y, r0 ; Store the critical nesting counter.
\r
170 lds r26, pxCurrentTCB ; Finally save the software stack pointer (Y ...
\r
171 lds r27, pxCurrentTCB + 1 ; ... register) into the TCB.
\r
178 portRESTORE_CONTEXT MACRO
\r
179 lds r26, pxCurrentTCB
\r
180 lds r27, pxCurrentTCB + 1 ; Restore the software stack pointer from ...
\r
181 ld r28, x+ ; the TCB into the software stack pointer (...
\r
182 ld r29, x+ ; ... the Y register).
\r
185 sts uxCriticalNesting, r0
\r
186 ld r31, y+ ; Restore the registers down to R0. The Y
\r
187 ld r30, y+ ; register is missing from this list as it
\r
188 ld r27, y+ ; has already been restored.
\r
216 ld r0, y+ ; The next thing on the stack is the ...
\r
217 out SPH, r0 ; ... hardware stack pointer.
\r
221 ld r0, y+ ; Next there is the SREG register.
\r
224 ld r0, y+ ; Finally we have finished with r0, so restore r0.
\r
230 ; vPortYield() and vPortYieldFromTick()
\r
231 ; -------------------------------------
\r
233 ; Manual and preemptive context switch functions respectively.
\r
234 ; The IAR compiler does not fully support inline assembler,
\r
235 ; so these are implemented here rather than the more usually
\r
236 ; place of within port.c.
\r
239 portSAVE_CONTEXT ; Save the context of the current task.
\r
240 call vTaskSwitchContext ; Call the scheduler.
\r
241 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
242 ret ; ... scheduler decided should run.
\r
244 vPortYieldFromTick:
\r
245 portSAVE_CONTEXT ; Save the context of the current task.
\r
246 call xTaskIncrementTick ; Call the timer tick function.
\r
247 call vTaskSwitchContext ; Call the scheduler.
\r
248 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
249 ret ; ... scheduler decided should run.
\r
254 ; Again due to the lack of inline assembler, this is required
\r
255 ; to get access to the portRESTORE_CONTEXT macro.
\r
258 portRESTORE_CONTEXT
\r
262 ; Just a filler for unused interrupt vectors.
\r