1 ; FreeRTOS.org V5.1.1 - Copyright (C) 2003-2008 Richard Barry.
\r
3 ; This file is part of the FreeRTOS.org distribution.
\r
5 ; FreeRTOS.org is free software; you can redistribute it and/or modify
\r
6 ; it under the terms of the GNU General Public License as published by
\r
7 ; the Free Software Foundation; either version 2 of the License, or
\r
8 ; (at your option) any later version.
\r
10 ; FreeRTOS.org is distributed in the hope that it will be useful,
\r
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 ; GNU General Public License for more details.
\r
15 ; You should have received a copy of the GNU General Public License
\r
16 ; along with FreeRTOS.org; if not, write to the Free Software
\r
17 ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
19 ; A special exception to the GPL can be applied should you wish to distribute
\r
20 ; a combined work that includes FreeRTOS.org, without being obliged to provide
\r
21 ; the source code for any proprietary components. See the licensing section
\r
22 ; of http://www.FreeRTOS.org for full details of how and when the exception
\r
25 ; ***************************************************************************
\r
26 ; See http://www.FreeRTOS.org for documentation, latest information, license
\r
27 ; and contact details. Please ensure to read the configuration and relevant
\r
28 ; port sections of the online documentation.
\r
29 ; ***************************************************************************
\r
31 ;------------------------------------------------------------------------------
\r
32 ; Note: Select the correct include files for the device used by the application.
\r
33 #include "FreeRTOSConfig.h"
\r
34 ;------------------------------------------------------------------------------
\r
36 #if __CORE__ != __78K0R__
\r
37 #error "This file is only for 78K0R Devices"
\r
43 ; Functions implemented in this file
\r
44 ;------------------------------------------------------------------------------
\r
49 ; Functions used by scheduler
\r
50 ;------------------------------------------------------------------------------
\r
51 EXTERN vTaskSwitchContext
\r
52 EXTERN vTaskIncrementTick
\r
54 ; Variables used by scheduler
\r
55 ;------------------------------------------------------------------------------
\r
57 EXTERN usCriticalNesting
\r
60 ; Tick ISR Prototype
\r
61 ;------------------------------------------------------------------------------
\r
62 EXTERN ?CL78K0R_V2_L00
\r
64 PUBWEAK `??MD_INTTM05??INTVEC 68`
\r
67 MD_INTTM05 SYMBOL "MD_INTTM05"
\r
68 `??MD_INTTM05??INTVEC 68` SYMBOL "??INTVEC 68", MD_INTTM05
\r
71 ;------------------------------------------------------------------------------
\r
72 ; portSAVE_CONTEXT MACRO
\r
73 ; Saves the context of the remaining general purpose registers, CS and ES
\r
74 ; (only in far memory mode) registers
\r
75 ; the usCriticalNesting Value and the Stack Pointer
\r
76 ; of the active Task onto the task stack
\r
77 ;------------------------------------------------------------------------------
\r
78 portSAVE_CONTEXT MACRO
\r
81 #if configMEMORY_MODE == 1
\r
82 MOV A, CS ; save CS register
\r
84 MOV A, ES ; save ES register
\r
87 MOV A, CS ; save CS register
\r
90 PUSH DE ; save the remaining general purpose registers
\r
92 MOVW AX, usCriticalNesting ; save the usCriticalNesting value
\r
94 MOVW AX, pxCurrentTCB ; save the Stack pointer
\r
99 ;------------------------------------------------------------------------------
\r
101 ;------------------------------------------------------------------------------
\r
102 ; portRESTORE_CONTEXT MACRO
\r
103 ; Restores the context of the Stack Pointer, usCriticalNesting
\r
104 ; value, general purpose registers and the CS and ES (only in far memory mode)
\r
105 ; of the selected task from the task stack
\r
106 ;------------------------------------------------------------------------------
\r
108 portRESTORE_CONTEXT MACRO
\r
109 MOVW AX, pxCurrentTCB ; restore the Stack pointer
\r
113 POP AX ; restore usCriticalNesting value
\r
114 MOVW usCriticalNesting, AX
\r
115 POP BC ; restore the necessary general purpose registers
\r
117 #if configMEMORY_MODE == 1
\r
118 POP AX ; restore the ES register
\r
120 XCH A, X ; restore the CS register
\r
124 MOV CS, A ; restore CS register
\r
126 POP HL ; restore general purpose register HL
\r
128 ;------------------------------------------------------------------------------
\r
130 ;------------------------------------------------------------------------------
\r
131 ; Port Yield function to check for a Task switch in the cooperative mode
\r
135 ; Call: CALL vPortYield
\r
139 ;------------------------------------------------------------------------------
\r
142 PUSH PSW ; save Task PSW (Program Status Word)
\r
143 DI ; global disable interrupt
\r
145 portSAVE_CONTEXT ; Save the context of the current task.
\r
146 CALL vTaskSwitchContext ; Call the scheduler.
\r
147 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
149 EI ; (re-)enable global interrupts
\r
150 POP PSW ; restore active task PSW
\r
151 RET ; ... scheduler decided should run.
\r
154 ;------------------------------------------------------------------------------
\r
155 ; Restore the context of the first task that is going to run.
\r
159 ; Call: CALL vPortStart
\r
163 ;------------------------------------------------------------------------------
\r
166 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
168 EI ; enable global interrupts
\r
169 POP PSW ; restore active task PSW
\r
170 ret ; ... scheduler decided should run.
\r
172 ;------------------------------------------------------------------------------
\r
173 ; Perform the necessary steps of the Tick Count Increment and Task Switch
\r
174 ; depending on the chosen kernel configuration
\r
182 ;------------------------------------------------------------------------------
\r
183 #if configUSE_PREEMPTION == 1
\r
186 PUSH AX ; create temporary dummy area on stack
\r
187 PUSH AX ; save AX Register to stack
\r
188 MOVW AX, [SP+6] ; get PSW
\r
189 MOVW [SP+2], AX ; write PSW into dummy area on the stack
\r
191 portSAVE_CONTEXT ; Save the context of the current task.
\r
192 call vTaskIncrementTick ; Call the timer tick function.
\r
193 call vTaskSwitchContext ; Call the scheduler.
\r
194 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
195 ; ... scheduler decided should run.
\r
197 MOVW AX, [SP+2] ; get PSW from stack
\r
198 MOVW [SP+6], AX ; write PSW to expected location for reti
\r
199 POP AX ; restore AX
\r
200 MOVW [SP+0], AX ; rewrite dummy stack area to expected value
\r
206 PUSH AX ; save necessary general purpose register...
\r
207 PUSH HL ; ...used by the ISR
\r
208 MOVW AX, CS ; save CS register
\r
210 CALL vTaskIncrementTick ; Call the timer tick function.
\r
212 MOVW CS, AX ; restore CS register
\r
213 POP HL ; restore used general purpose registers
\r
218 REQUIRE ?CL78K0R_V2_L00
\r
219 COMMON INTVEC:CODE:ROOT(1) ; set ISR location to the Interrupt vector table
\r
221 `??MD_INTTM05??INTVEC 68`:
\r
223 ; set value for the usCriticalNesting
\r
224 RSEG NEAR_ID:CONST:SORT:NOROOT(1)
\r
225 `?<Initializer for usCriticalNesting>`:
\r