2 ; * FreeRTOS Kernel V10.0.0
\r
3 ; * Copyright (C) 2017 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. If you wish to use our Amazon
\r
14 ; * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 ; * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 ; * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 ; * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 ; * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 ; * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 ; * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 ; * http://www.FreeRTOS.org
\r
24 ; * http://aws.amazon.com/freertos
\r
26 ; * 1 tab == 4 spaces!
\r
28 ; Note: Select the correct include files for the device used by the application.
\r
29 #include "FreeRTOSConfig.h"
\r
30 ;------------------------------------------------------------------------------
\r
32 ; Functions used by scheduler
\r
33 ;------------------------------------------------------------------------------
\r
34 EXTERN vTaskSwitchContext
\r
35 EXTERN xTaskIncrementTick
\r
37 ; Variables used by scheduler
\r
38 ;------------------------------------------------------------------------------
\r
40 EXTERN usCriticalNesting
\r
42 ; Functions implemented in this file
\r
43 ;------------------------------------------------------------------------------
\r
47 ; Security ID definition
\r
48 ;------------------------------------------------------------------------------
\r
49 #define CG_SECURITY0 0FFH
\r
50 #define CG_SECURITY1 0FFH
\r
51 #define CG_SECURITY2 0FFH
\r
52 #define CG_SECURITY3 0FFH
\r
53 #define CG_SECURITY4 0FFH
\r
54 #define CG_SECURITY5 0FFH
\r
55 #define CG_SECURITY6 0FFH
\r
56 #define CG_SECURITY7 0FFH
\r
57 #define CG_SECURITY8 0FFH
\r
58 #define CG_SECURITY9 0FFH
\r
60 ; Option Byte definitions
\r
61 ;------------------------------------------------------------------------------
\r
62 #define CG_OPTION7A 0x00
\r
63 #define CG_OPTION7B 0x04
\r
69 ; Tick ISR Prototype
\r
70 ;------------------------------------------------------------------------------
\r
71 PUBWEAK `??MD_INTTM0EQ0??INTVEC 608`
\r
74 MD_INTTM0EQ0 SYMBOL "MD_INTTM0EQ0"
\r
75 `??MD_INTTM0EQ0??INTVEC 608` SYMBOL "??INTVEC 608", MD_INTTM0EQ0
\r
77 ;------------------------------------------------------------------------------
\r
78 ; portSAVE_CONTEXT MACRO
\r
79 ; Saves the context of the remaining general purpose registers
\r
80 ; and the usCriticalNesting Value of the active Task onto the task stack
\r
81 ; saves stack pointer to the TCB
\r
82 ;------------------------------------------------------------------------------
\r
83 portSAVE_CONTEXT MACRO
\r
84 #if configDATA_MODE == 1 ; Using the Tiny data model
\r
85 prepare {r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30},76,sp ; save general purpose registers
\r
102 #else ; Using the Small/Large data model
\r
103 prepare {r20,r21,r22,r23,r24,r26,r27,r28,r29,r30},72,sp ; save general purpose registers
\r
119 #endif /* configDATA_MODE */
\r
122 MOVHI hi1(usCriticalNesting),r0,r1 ; save usCriticalNesting value to stack
\r
123 ld.w lw1(usCriticalNesting)[r1],r2
\r
125 MOVHI hi1(pxCurrentTCB),r0,r1 ; save SP to top of current TCB
\r
126 ld.w lw1(pxCurrentTCB)[r1],r2
\r
129 ;------------------------------------------------------------------------------
\r
131 ;------------------------------------------------------------------------------
\r
132 ; portRESTORE_CONTEXT MACRO
\r
133 ; Gets stack pointer from the current TCB
\r
134 ; Restores the context of the usCriticalNesting value and general purpose
\r
135 ; registers of the selected task from the task stack
\r
136 ;------------------------------------------------------------------------------
\r
137 portRESTORE_CONTEXT MACRO
\r
138 MOVHI hi1(pxCurrentTCB),r0,r1 ; get Stackpointer address
\r
139 ld.w lw1(pxCurrentTCB)[r1],sp
\r
141 ld.w 0[r1],sp ; load stackpointer
\r
142 MOV sp,ep ; set stack pointer to element pointer
\r
143 sld.w 0[ep],r1 ; load usCriticalNesting value from stack
\r
144 MOVHI hi1(usCriticalNesting),r0,r2
\r
145 st.w r1,lw1(usCriticalNesting)[r2]
\r
146 sld.w 4[ep],r1 ; restore general purpose registers
\r
148 #if configDATA_MODE == 1 ; Using Tiny data model
\r
165 dispose 76,{r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30}
\r
166 #else ; Using Small/Large data model
\r
182 dispose 72,{r20,r21,r22,r23,r24,r26,r27,r28,r29,r30}
\r
183 #endif /* configDATA_MODE */
\r
185 ;------------------------------------------------------------------------------
\r
187 ;------------------------------------------------------------------------------
\r
188 ; Restore the context of the first task that is going to run.
\r
192 ; Call: CALL vPortStart
\r
195 ;------------------------------------------------------------------------------
\r
198 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
200 ldsr lp,5 ; restore PSW
\r
202 ld.w 4[sp],lp ; restore LP
\r
203 ld.w 8[sp],lp ; restore LP
\r
204 ADD 0x0C,sp ; set SP to right position
\r
207 ;------------------------------------------------------------------------------
\r
209 ;------------------------------------------------------------------------------
\r
210 ; Port Yield function to check for a Task switch in the cooperative and
\r
215 ; Call: CALL vPortYield
\r
218 ;------------------------------------------------------------------------------
\r
223 add -0x0C,sp ; prepare stack to save necessary values
\r
224 st.w lp,8[sp] ; store LP to stack
\r
226 st.w lp,4[sp] ; store EIPC to stack
\r
228 st.w lp,0[sp] ; store EIPSW to stack
\r
229 portSAVE_CONTEXT ; Save the context of the current task.
\r
230 jarl vTaskSwitchContext,lp ; Call the scheduler.
\r
231 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
232 ; ... scheduler decided should run.
\r
233 ld.w 0[sp],lp ; restore EIPSW from stack
\r
235 ld.w 4[sp],lp ; restore EIPC from stack
\r
237 ld.w 8[sp],lp ; restore LP from stack
\r
238 add 0x0C,sp ; set SP to right position
\r
242 ;------------------------------------------------------------------------------
\r
244 ;------------------------------------------------------------------------------
\r
245 ; Perform the necessary steps of the Tick Count Increment and Task Switch
\r
246 ; depending on the chosen kernel configuration
\r
253 ;------------------------------------------------------------------------------
\r
254 #if configUSE_PREEMPTION == 1 ; use preemptive kernel mode
\r
258 add -0x0C,sp ; prepare stack to save necessary values
\r
259 st.w lp,8[sp] ; store LP to stack
\r
261 st.w lp,4[sp] ; store EIPC to stack
\r
263 st.w lp,0[sp] ; store EIPSW to stack
\r
264 portSAVE_CONTEXT ; Save the context of the current task.
\r
265 jarl xTaskIncrementTick,lp ; Call the timer tick function.
\r
266 jarl vTaskSwitchContext,lp ; Call the scheduler.
\r
267 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
268 ; ... scheduler decided should run.
\r
269 ld.w 0[sp],lp ; restore EIPSW from stack
\r
271 ld.w 4[sp],lp ; restore EIPC from stack
\r
273 ld.w 8[sp],lp ; restore LP from stack
\r
274 add 0x0C,sp ; set SP to right position
\r
277 ;------------------------------------------------------------------------------
\r
278 #else ; use cooperative kernel mode
\r
281 prepare {lp,ep},8,sp
\r
284 jarl xTaskIncrementTick,lp ; Call the timer tick function.
\r
289 #endif /* configUSE_PREEMPTION */
\r
291 ;------------------------------------------------------------------------------
\r
292 COMMON INTVEC:CODE:ROOT(2)
\r
294 `??MD_INTTM0EQ0??INTVEC 608`:
\r
297 RSEG NEAR_ID:CONST:SORT:NOROOT(2)
\r
298 `?<Initializer for usCriticalNesting>`:
\r
301 COMMON INTVEC:CODE:ROOT(2)
\r
303 `??vPortYield??INTVEC 40`:
\r
306 ;------------------------------------------------------------------------------
\r
307 ; set microcontroller security ID
\r
309 COMMON INTVEC:CODE:ROOT(2)
\r
323 ;------------------------------------------------------------------------------
\r
324 ; set microcontroller option bytes
\r
326 COMMON INTVEC:CODE:ROOT(2)
\r