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