2 ; * FreeRTOS Kernel V10.1.0
\r
3 ; * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 ; * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 ; * this software and associated documentation files (the "Software"), to deal in
\r
7 ; * the Software without restriction, including without limitation the rights to
\r
8 ; * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 ; * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 ; * subject to the following conditions:
\r
12 ; * The above copyright notice and this permission notice shall be included in all
\r
13 ; * copies or substantial portions of the Software.
\r
15 ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 ; * http://www.FreeRTOS.org
\r
23 ; * http://aws.amazon.com/freertos
\r
25 ; * 1 tab == 4 spaces!
\r
27 ; Note: Select the correct include files for the device used by the application.
\r
28 #include "FreeRTOSConfig.h"
\r
29 ;------------------------------------------------------------------------------
\r
31 ; Functions used by scheduler
\r
32 ;------------------------------------------------------------------------------
\r
33 EXTERN vTaskSwitchContext
\r
34 EXTERN xTaskIncrementTick
\r
36 ; Variables used by scheduler
\r
37 ;------------------------------------------------------------------------------
\r
39 EXTERN usCriticalNesting
\r
41 ; Functions implemented in this file
\r
42 ;------------------------------------------------------------------------------
\r
46 ; Security ID definition
\r
47 ;------------------------------------------------------------------------------
\r
48 #define CG_SECURITY0 0FFH
\r
49 #define CG_SECURITY1 0FFH
\r
50 #define CG_SECURITY2 0FFH
\r
51 #define CG_SECURITY3 0FFH
\r
52 #define CG_SECURITY4 0FFH
\r
53 #define CG_SECURITY5 0FFH
\r
54 #define CG_SECURITY6 0FFH
\r
55 #define CG_SECURITY7 0FFH
\r
56 #define CG_SECURITY8 0FFH
\r
57 #define CG_SECURITY9 0FFH
\r
59 ; Option Byte definitions
\r
60 ;------------------------------------------------------------------------------
\r
61 #define CG_OPTION7A 0x00
\r
62 #define CG_OPTION7B 0x04
\r
68 ; Tick ISR Prototype
\r
69 ;------------------------------------------------------------------------------
\r
70 PUBWEAK `??MD_INTTM0EQ0??INTVEC 608`
\r
73 MD_INTTM0EQ0 SYMBOL "MD_INTTM0EQ0"
\r
74 `??MD_INTTM0EQ0??INTVEC 608` SYMBOL "??INTVEC 608", MD_INTTM0EQ0
\r
76 ;------------------------------------------------------------------------------
\r
77 ; portSAVE_CONTEXT MACRO
\r
78 ; Saves the context of the remaining general purpose registers
\r
79 ; and the usCriticalNesting Value of the active Task onto the task stack
\r
80 ; saves stack pointer to the TCB
\r
81 ;------------------------------------------------------------------------------
\r
82 portSAVE_CONTEXT MACRO
\r
83 #if configDATA_MODE == 1 ; Using the Tiny data model
\r
84 prepare {r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30},76,sp ; save general purpose registers
\r
101 #else ; Using the Small/Large data model
\r
102 prepare {r20,r21,r22,r23,r24,r26,r27,r28,r29,r30},72,sp ; save general purpose registers
\r
118 #endif /* configDATA_MODE */
\r
121 MOVHI hi1(usCriticalNesting),r0,r1 ; save usCriticalNesting value to stack
\r
122 ld.w lw1(usCriticalNesting)[r1],r2
\r
124 MOVHI hi1(pxCurrentTCB),r0,r1 ; save SP to top of current TCB
\r
125 ld.w lw1(pxCurrentTCB)[r1],r2
\r
128 ;------------------------------------------------------------------------------
\r
130 ;------------------------------------------------------------------------------
\r
131 ; portRESTORE_CONTEXT MACRO
\r
132 ; Gets stack pointer from the current TCB
\r
133 ; Restores the context of the usCriticalNesting value and general purpose
\r
134 ; registers of the selected task from the task stack
\r
135 ;------------------------------------------------------------------------------
\r
136 portRESTORE_CONTEXT MACRO
\r
137 MOVHI hi1(pxCurrentTCB),r0,r1 ; get Stackpointer address
\r
138 ld.w lw1(pxCurrentTCB)[r1],sp
\r
140 ld.w 0[r1],sp ; load stackpointer
\r
141 MOV sp,ep ; set stack pointer to element pointer
\r
142 sld.w 0[ep],r1 ; load usCriticalNesting value from stack
\r
143 MOVHI hi1(usCriticalNesting),r0,r2
\r
144 st.w r1,lw1(usCriticalNesting)[r2]
\r
145 sld.w 4[ep],r1 ; restore general purpose registers
\r
147 #if configDATA_MODE == 1 ; Using Tiny data model
\r
164 dispose 76,{r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30}
\r
165 #else ; Using Small/Large data model
\r
181 dispose 72,{r20,r21,r22,r23,r24,r26,r27,r28,r29,r30}
\r
182 #endif /* configDATA_MODE */
\r
184 ;------------------------------------------------------------------------------
\r
186 ;------------------------------------------------------------------------------
\r
187 ; Restore the context of the first task that is going to run.
\r
191 ; Call: CALL vPortStart
\r
194 ;------------------------------------------------------------------------------
\r
197 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
199 ldsr lp,5 ; restore PSW
\r
201 ld.w 4[sp],lp ; restore LP
\r
202 ld.w 8[sp],lp ; restore LP
\r
203 ADD 0x0C,sp ; set SP to right position
\r
206 ;------------------------------------------------------------------------------
\r
208 ;------------------------------------------------------------------------------
\r
209 ; Port Yield function to check for a Task switch in the cooperative and
\r
214 ; Call: CALL vPortYield
\r
217 ;------------------------------------------------------------------------------
\r
222 add -0x0C,sp ; prepare stack to save necessary values
\r
223 st.w lp,8[sp] ; store LP to stack
\r
225 st.w lp,4[sp] ; store EIPC to stack
\r
227 st.w lp,0[sp] ; store EIPSW to stack
\r
228 portSAVE_CONTEXT ; Save the context of the current task.
\r
229 jarl vTaskSwitchContext,lp ; Call the scheduler.
\r
230 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
231 ; ... scheduler decided should run.
\r
232 ld.w 0[sp],lp ; restore EIPSW from stack
\r
234 ld.w 4[sp],lp ; restore EIPC from stack
\r
236 ld.w 8[sp],lp ; restore LP from stack
\r
237 add 0x0C,sp ; set SP to right position
\r
241 ;------------------------------------------------------------------------------
\r
243 ;------------------------------------------------------------------------------
\r
244 ; Perform the necessary steps of the Tick Count Increment and Task Switch
\r
245 ; depending on the chosen kernel configuration
\r
252 ;------------------------------------------------------------------------------
\r
253 #if configUSE_PREEMPTION == 1 ; use preemptive kernel mode
\r
257 add -0x0C,sp ; prepare stack to save necessary values
\r
258 st.w lp,8[sp] ; store LP to stack
\r
260 st.w lp,4[sp] ; store EIPC to stack
\r
262 st.w lp,0[sp] ; store EIPSW to stack
\r
263 portSAVE_CONTEXT ; Save the context of the current task.
\r
264 jarl xTaskIncrementTick,lp ; Call the timer tick function.
\r
265 jarl vTaskSwitchContext,lp ; Call the scheduler.
\r
266 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
267 ; ... scheduler decided should run.
\r
268 ld.w 0[sp],lp ; restore EIPSW from stack
\r
270 ld.w 4[sp],lp ; restore EIPC from stack
\r
272 ld.w 8[sp],lp ; restore LP from stack
\r
273 add 0x0C,sp ; set SP to right position
\r
276 ;------------------------------------------------------------------------------
\r
277 #else ; use cooperative kernel mode
\r
280 prepare {lp,ep},8,sp
\r
283 jarl xTaskIncrementTick,lp ; Call the timer tick function.
\r
288 #endif /* configUSE_PREEMPTION */
\r
290 ;------------------------------------------------------------------------------
\r
291 COMMON INTVEC:CODE:ROOT(2)
\r
293 `??MD_INTTM0EQ0??INTVEC 608`:
\r
296 RSEG NEAR_ID:CONST:SORT:NOROOT(2)
\r
297 `?<Initializer for usCriticalNesting>`:
\r
300 COMMON INTVEC:CODE:ROOT(2)
\r
302 `??vPortYield??INTVEC 40`:
\r
305 ;------------------------------------------------------------------------------
\r
306 ; set microcontroller security ID
\r
308 COMMON INTVEC:CODE:ROOT(2)
\r
322 ;------------------------------------------------------------------------------
\r
323 ; set microcontroller option bytes
\r
325 COMMON INTVEC:CODE:ROOT(2)
\r