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 ; Tick ISR Prototype
\r
61 ;------------------------------------------------------------------------------
\r
62 PUBWEAK `??MD_INTTM0EQ0??INTVEC 544`
\r
65 MD_INTTM0EQ0 SYMBOL "MD_INTTM0EQ0"
\r
66 `??MD_INTTM0EQ0??INTVEC 544` SYMBOL "??INTVEC 544", MD_INTTM0EQ0
\r
68 ;------------------------------------------------------------------------------
\r
69 ; portSAVE_CONTEXT MACRO
\r
70 ; Saves the context of the remaining general purpose registers
\r
71 ; and the usCriticalNesting Value of the active Task onto the task stack
\r
72 ; saves stack pointer to the TCB
\r
73 ;------------------------------------------------------------------------------
\r
74 portSAVE_CONTEXT MACRO
\r
75 #if configDATA_MODE == 1 ; Using the Tiny data model
\r
76 prepare {r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30},76,sp ; save general purpose registers
\r
93 #else ; Using the Small/Large data model
\r
94 prepare {r20,r21,r22,r23,r24,r26,r27,r28,r29,r30},72,sp ; save general purpose registers
\r
110 #endif /* configDATA_MODE */
\r
113 MOVHI hi1(usCriticalNesting),r0,r1 ; save usCriticalNesting value to stack
\r
114 ld.w lw1(usCriticalNesting)[r1],r2
\r
116 MOVHI hi1(pxCurrentTCB),r0,r1 ; save SP to top of current TCB
\r
117 ld.w lw1(pxCurrentTCB)[r1],r2
\r
120 ;------------------------------------------------------------------------------
\r
122 ;------------------------------------------------------------------------------
\r
123 ; portRESTORE_CONTEXT MACRO
\r
124 ; Gets stack pointer from the current TCB
\r
125 ; Restores the context of the usCriticalNesting value and general purpose
\r
126 ; registers of the selected task from the task stack
\r
127 ;------------------------------------------------------------------------------
\r
128 portRESTORE_CONTEXT MACRO
\r
129 MOVHI hi1(pxCurrentTCB),r0,r1 ; get Stackpointer address
\r
130 ld.w lw1(pxCurrentTCB)[r1],sp
\r
132 ld.w 0[r1],sp ; load stackpointer
\r
133 MOV sp,ep ; set stack pointer to element pointer
\r
134 sld.w 0[ep],r1 ; load usCriticalNesting value from stack
\r
135 MOVHI hi1(usCriticalNesting),r0,r2
\r
136 st.w r1,lw1(usCriticalNesting)[r2]
\r
137 sld.w 4[ep],r1 ; restore general purpose registers
\r
139 #if configDATA_MODE == 1 ; Using Tiny data model
\r
156 dispose 76,{r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30}
\r
157 #else ; Using Small/Large data model
\r
173 dispose 72,{r20,r21,r22,r23,r24,r26,r27,r28,r29,r30}
\r
174 #endif /* configDATA_MODE */
\r
176 ;------------------------------------------------------------------------------
\r
178 ;------------------------------------------------------------------------------
\r
179 ; Restore the context of the first task that is going to run.
\r
183 ; Call: CALL vPortStart
\r
186 ;------------------------------------------------------------------------------
\r
189 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
191 ldsr lp,5 ; restore PSW
\r
193 ld.w 4[sp],lp ; restore LP
\r
194 ld.w 8[sp],lp ; restore LP
\r
195 ADD 0x0C,sp ; set SP to right position
\r
198 ;------------------------------------------------------------------------------
\r
200 ;------------------------------------------------------------------------------
\r
201 ; Port Yield function to check for a Task switch in the cooperative and
\r
206 ; Call: CALL vPortYield
\r
209 ;------------------------------------------------------------------------------
\r
214 add -0x0C,sp ; prepare stack to save necessary values
\r
215 st.w lp,8[sp] ; store LP to stack
\r
217 st.w lp,4[sp] ; store EIPC to stack
\r
219 st.w lp,0[sp] ; store EIPSW to stack
\r
220 portSAVE_CONTEXT ; Save the context of the current task.
\r
221 jarl vTaskSwitchContext,lp ; Call the scheduler.
\r
222 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
223 ; ... scheduler decided should run.
\r
224 ld.w 0[sp],lp ; restore EIPSW from stack
\r
226 ld.w 4[sp],lp ; restore EIPC from stack
\r
228 ld.w 8[sp],lp ; restore LP from stack
\r
229 add 0x0C,sp ; set SP to right position
\r
233 ;------------------------------------------------------------------------------
\r
235 ;------------------------------------------------------------------------------
\r
236 ; Perform the necessary steps of the Tick Count Increment and Task Switch
\r
237 ; depending on the chosen kernel configuration
\r
244 ;------------------------------------------------------------------------------
\r
245 #if configUSE_PREEMPTION == 1 ; use preemptive kernel mode
\r
249 add -0x0C,sp ; prepare stack to save necessary values
\r
250 st.w lp,8[sp] ; store LP to stack
\r
252 st.w lp,4[sp] ; store EIPC to stack
\r
254 st.w lp,0[sp] ; store EIPSW to stack
\r
255 portSAVE_CONTEXT ; Save the context of the current task.
\r
256 jarl xTaskIncrementTick,lp ; Call the timer tick function.
\r
257 jarl vTaskSwitchContext,lp ; Call the scheduler.
\r
258 portRESTORE_CONTEXT ; Restore the context of whichever task the ...
\r
259 ; ... scheduler decided should run.
\r
260 ld.w 0[sp],lp ; restore EIPSW from stack
\r
262 ld.w 4[sp],lp ; restore EIPC from stack
\r
264 ld.w 8[sp],lp ; restore LP from stack
\r
265 add 0x0C,sp ; set SP to right position
\r
268 ;------------------------------------------------------------------------------
\r
269 #else ; use cooperative kernel mode
\r
272 prepare {lp,ep},8,sp
\r
275 jarl xTaskIncrementTick,lp ; Call the timer tick function.
\r
280 #endif /* configUSE_PREEMPTION */
\r
282 ;------------------------------------------------------------------------------
\r
283 COMMON INTVEC:CODE:ROOT(2)
\r
285 `??MD_INTTM0EQ0??INTVEC 544`:
\r
288 RSEG NEAR_ID:CONST:SORT:NOROOT(2)
\r
289 `?<Initializer for usCriticalNesting>`:
\r
292 COMMON INTVEC:CODE:ROOT(2)
\r
294 `??vPortYield??INTVEC 40`:
\r
297 ;------------------------------------------------------------------------------
\r
298 ; set microcontroller security ID
\r
300 COMMON INTVEC:CODE:ROOT(2)
\r
315 ; set microcontroller Option bytes
\r
317 COMMON INTVEC:CODE:ROOT(2)
\r
327 #if configOCD_USAGE == 1
\r
329 COMMON INTVEC:CODE:ROOT(4)
\r
333 DB 0xff, 0xff, 0xff, 0xff
\r
334 DB 0xff, 0xff, 0xff, 0xff
\r
335 DB 0xff, 0xff, 0xff, 0xff
\r
336 DB 0xff, 0xff, 0xff, 0xff
\r
339 COMMON INTVEC:CODE:ROOT(4)
\r
343 DB 0xff, 0xff, 0xff, 0xff
\r
344 DB 0xff, 0xff, 0xff, 0xff
\r
345 DB 0xff, 0xff, 0xff, 0xff
\r
346 DB 0xff, 0xff, 0xff, 0xff
\r
348 #endif /* configOCD_USAGE */
\r