]> begriffs open source - freertos/blob - Source/portable/IAR/78K0R/portmacro.s26
Renamed to remove the Fx3 from the directory name.
[freertos] / Source / portable / IAR / 78K0R / portmacro.s26
1 ;       FreeRTOS.org V5.1.1 - Copyright (C) 2003-2008 Richard Barry.\r
2 ;\r
3 ;       This file is part of the FreeRTOS.org distribution.\r
4 ;\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
9 ;\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
14 ;\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
18 ;\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
23 ;       can be applied.\r
24 ;\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
30 ;\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
35 \r
36 #if __CORE__ != __78K0R__\r
37         #error "This file is only for 78K0R Devices"\r
38 #endif\r
39 \r
40 #define CS                    0xFFFFC\r
41 #define ES                    0xFFFFD\r
42 \r
43 ; Functions implemented in this file\r
44 ;------------------------------------------------------------------------------\r
45 \r
46         PUBLIC    vPortYield\r
47         PUBLIC    vPortStart\r
48 \r
49 ; Functions used by scheduler\r
50 ;------------------------------------------------------------------------------ \r
51         EXTERN    vTaskSwitchContext\r
52         EXTERN    vTaskIncrementTick\r
53 \r
54 ; Variables used by scheduler\r
55 ;------------------------------------------------------------------------------ \r
56         EXTERN    pxCurrentTCB\r
57         EXTERN    usCriticalNesting\r
58  \r
59  \r
60 ; Tick ISR Prototype\r
61 ;------------------------------------------------------------------------------\r
62         EXTERN    ?CL78K0R_V2_L00 \r
63 \r
64         PUBWEAK   `??MD_INTTM05??INTVEC 68`\r
65         PUBLIC    MD_INTTM05\r
66 \r
67 MD_INTTM05    SYMBOL "MD_INTTM05"\r
68 `??MD_INTTM05??INTVEC 68` SYMBOL "??INTVEC 68", MD_INTTM05\r
69 \r
70 \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
79 \r
80         PUSH      HL\r
81 #if configMEMORY_MODE == 1         \r
82         MOV       A, CS                 ; save CS register\r
83         XCH       A, X\r
84         MOV       A, ES                 ; save ES register\r
85         PUSH      AX\r
86 #else                               \r
87         MOV       A, CS                 ; save CS register\r
88         PUSH      AX\r
89 #endif                              \r
90         PUSH      DE                    ; save the  remaining general purpose registers\r
91         PUSH      BC\r
92         MOVW      AX, usCriticalNesting ; save the usCriticalNesting value      \r
93         PUSH      AX    \r
94         MOVW      AX, pxCurrentTCB          ; save the Stack pointer    \r
95         MOVW      HL, AX                                        \r
96         MOVW      AX, SP                                        \r
97         MOVW      [HL], AX                                      \r
98         ENDM\r
99 ;------------------------------------------------------------------------------\r
100 \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
107 \r
108 portRESTORE_CONTEXT MACRO\r
109         MOVW      AX, pxCurrentTCB          ; restore the Stack pointer\r
110         MOVW      HL, AX\r
111         MOVW      AX, [HL]\r
112         MOVW      SP, AX\r
113         POP           AX                    ; restore usCriticalNesting value\r
114         MOVW      usCriticalNesting, AX\r
115         POP           BC                    ; restore the necessary general purpose registers\r
116         POP           DE\r
117 #if configMEMORY_MODE == 1        \r
118         POP       AX                    ; restore the ES register\r
119         MOV       ES, A    \r
120         XCH       A, X                  ; restore the CS register\r
121         MOV       CS, A\r
122 #else                               \r
123         POP       AX\r
124         MOV       CS, A                 ; restore CS register\r
125 #endif                              \r
126         POP       HL                    ; restore general purpose register HL\r
127         ENDM\r
128 ;------------------------------------------------------------------------------\r
129 \r
130 ;------------------------------------------------------------------------------\r
131 ;   Port Yield function to check for a Task switch in the cooperative mode\r
132 ;\r
133 ;   Input:  NONE\r
134 ;\r
135 ;   Call:   CALL    vPortYield\r
136 ;\r
137 ;   Output: NONE\r
138 ;\r
139 ;------------------------------------------------------------------------------\r
140     RSEG CODE:CODE\r
141 vPortYield:\r
142         PUSH      PSW                   ; save Task PSW (Program Status Word)\r
143         DI                              ; global disable interrupt\r
144         PUSH      AX\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
148         POP       AX\r
149         EI                              ; (re-)enable global interrupts\r
150         POP       PSW                   ; restore active task PSW \r
151         RET                                             ; ... scheduler decided should run.\r
152 \r
153         \r
154 ;------------------------------------------------------------------------------\r
155 ;   Restore the context of the first task that is going to run.\r
156 ;\r
157 ;   Input:  NONE\r
158 ;\r
159 ;   Call:   CALL    vPortStart\r
160 ;\r
161 ;   Output: NONE\r
162 ;\r
163 ;------------------------------------------------------------------------------ \r
164     RSEG CODE:CODE\r
165 vPortStart:\r
166         portRESTORE_CONTEXT                 ; Restore the context of whichever task the ...\r
167         POP       AX\r
168         EI                              ; enable global interrupts \r
169         POP       PSW                   ; restore active task PSW\r
170         ret                                                 ; ... scheduler decided should run.\r
171 \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
175 ;\r
176 ;   Input:  NONE\r
177 ;\r
178 ;   Call:   ISR \r
179 ;\r
180 ;   Output: NONE\r
181 ;\r
182 ;------------------------------------------------------------------------------ \r
183 #if configUSE_PREEMPTION == 1\r
184 \r
185 MD_INTTM05:\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
190 \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
196 \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
201         POP       AX                \r
202         RETI      \r
203 #else\r
204 \r
205 MD_INTTM05:\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
209         PUSH        AX\r
210         CALL        vTaskIncrementTick  ; Call the timer tick function.\r
211         POP         AX\r
212         MOVW        CS, AX              ; restore CS register\r
213         POP         HL                  ; restore used general purpose registers\r
214         POP         AX\r
215         RETI      \r
216 #endif\r
217 \r
218         REQUIRE ?CL78K0R_V2_L00\r
219         COMMON INTVEC:CODE:ROOT(1)      ; set ISR location to the Interrupt vector table\r
220         ORG 68\r
221 `??MD_INTTM05??INTVEC 68`:\r
222         DW MD_INTTM05\r
223                                     ; set value for the usCriticalNesting\r
224         RSEG NEAR_ID:CONST:SORT:NOROOT(1)\r
225 `?<Initializer for usCriticalNesting>`:\r
226         DW 10\r
227         \r
228 ;#endif\r
229 \r
230       END