| 1 |
572 |
jeremybenn |
;/*
|
| 2 |
|
|
; FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
|
| 3 |
|
|
;
|
| 4 |
|
|
; ***************************************************************************
|
| 5 |
|
|
; * *
|
| 6 |
|
|
; * If you are: *
|
| 7 |
|
|
; * *
|
| 8 |
|
|
; * + New to FreeRTOS, *
|
| 9 |
|
|
; * + Wanting to learn FreeRTOS or multitasking in general quickly *
|
| 10 |
|
|
; * + Looking for basic training, *
|
| 11 |
|
|
; * + Wanting to improve your FreeRTOS skills and productivity *
|
| 12 |
|
|
; * *
|
| 13 |
|
|
; * then take a look at the FreeRTOS books - available as PDF or paperback *
|
| 14 |
|
|
; * *
|
| 15 |
|
|
; * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
|
| 16 |
|
|
; * http://www.FreeRTOS.org/Documentation *
|
| 17 |
|
|
; * *
|
| 18 |
|
|
; * A pdf reference manual is also available. Both are usually delivered *
|
| 19 |
|
|
; * to your inbox within 20 minutes to two hours when purchased between 8am *
|
| 20 |
|
|
; * and 8pm GMT (although please allow up to 24 hours in case of *
|
| 21 |
|
|
; * exceptional circumstances). Thank you for your support! *
|
| 22 |
|
|
; * *
|
| 23 |
|
|
; ***************************************************************************
|
| 24 |
|
|
;
|
| 25 |
|
|
; This file is part of the FreeRTOS distribution.
|
| 26 |
|
|
;
|
| 27 |
|
|
; FreeRTOS is free software; you can redistribute it and/or modify it under
|
| 28 |
|
|
; the terms of the GNU General Public License (version 2) as published by the
|
| 29 |
|
|
; Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
| 30 |
|
|
; ***NOTE*** The exception to the GPL is included to allow you to distribute
|
| 31 |
|
|
; a combined work that includes FreeRTOS without being obliged to provide the
|
| 32 |
|
|
; source code for proprietary components outside of the FreeRTOS kernel.
|
| 33 |
|
|
; FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
|
| 34 |
|
|
; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 35 |
|
|
; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
| 36 |
|
|
; more details. You should have received a copy of the GNU General Public
|
| 37 |
|
|
; License and the FreeRTOS license exception along with FreeRTOS; if not it
|
| 38 |
|
|
; can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
| 39 |
|
|
; by writing to Richard Barry, contact details for whom are available on the
|
| 40 |
|
|
; FreeRTOS WEB site.
|
| 41 |
|
|
;
|
| 42 |
|
|
; 1 tab == 4 spaces!
|
| 43 |
|
|
;
|
| 44 |
|
|
; http://www.FreeRTOS.org - Documentation, latest information, license and
|
| 45 |
|
|
; contact details.
|
| 46 |
|
|
;
|
| 47 |
|
|
; http://www.SafeRTOS.com - A version that is certified for use in safety
|
| 48 |
|
|
; critical systems.
|
| 49 |
|
|
;
|
| 50 |
|
|
; http://www.OpenRTOS.com - Commercial support, development, porting,
|
| 51 |
|
|
; licensing and training services.
|
| 52 |
|
|
;*/
|
| 53 |
|
|
; Note: Select the correct include files for the device used by the application.
|
| 54 |
|
|
#include "FreeRTOSConfig.h"
|
| 55 |
|
|
;------------------------------------------------------------------------------
|
| 56 |
|
|
|
| 57 |
|
|
; Functions used by scheduler
|
| 58 |
|
|
;------------------------------------------------------------------------------
|
| 59 |
|
|
EXTERN vTaskSwitchContext
|
| 60 |
|
|
EXTERN vTaskIncrementTick
|
| 61 |
|
|
|
| 62 |
|
|
; Variables used by scheduler
|
| 63 |
|
|
;------------------------------------------------------------------------------
|
| 64 |
|
|
EXTERN pxCurrentTCB
|
| 65 |
|
|
EXTERN usCriticalNesting
|
| 66 |
|
|
|
| 67 |
|
|
; Functions implemented in this file
|
| 68 |
|
|
;------------------------------------------------------------------------------
|
| 69 |
|
|
PUBLIC vPortYield
|
| 70 |
|
|
PUBLIC vPortStart
|
| 71 |
|
|
|
| 72 |
|
|
; Security ID definition
|
| 73 |
|
|
;------------------------------------------------------------------------------
|
| 74 |
|
|
#define CG_SECURITY0 0FFH
|
| 75 |
|
|
#define CG_SECURITY1 0FFH
|
| 76 |
|
|
#define CG_SECURITY2 0FFH
|
| 77 |
|
|
#define CG_SECURITY3 0FFH
|
| 78 |
|
|
#define CG_SECURITY4 0FFH
|
| 79 |
|
|
#define CG_SECURITY5 0FFH
|
| 80 |
|
|
#define CG_SECURITY6 0FFH
|
| 81 |
|
|
#define CG_SECURITY7 0FFH
|
| 82 |
|
|
#define CG_SECURITY8 0FFH
|
| 83 |
|
|
#define CG_SECURITY9 0FFH
|
| 84 |
|
|
|
| 85 |
|
|
; Option Byte definitions
|
| 86 |
|
|
;------------------------------------------------------------------------------
|
| 87 |
|
|
#define CG_OPTION7A 0x00
|
| 88 |
|
|
#define CG_OPTION7B 0x04
|
| 89 |
|
|
#define OPT7C 0x00
|
| 90 |
|
|
#define OPT7D 0x00
|
| 91 |
|
|
#define OPT7E 0x00
|
| 92 |
|
|
#define OPT7F 0x00
|
| 93 |
|
|
|
| 94 |
|
|
; Tick ISR Prototype
|
| 95 |
|
|
;------------------------------------------------------------------------------
|
| 96 |
|
|
PUBWEAK `??MD_INTTM0EQ0??INTVEC 608`
|
| 97 |
|
|
PUBLIC MD_INTTM0EQ0
|
| 98 |
|
|
|
| 99 |
|
|
MD_INTTM0EQ0 SYMBOL "MD_INTTM0EQ0"
|
| 100 |
|
|
`??MD_INTTM0EQ0??INTVEC 608` SYMBOL "??INTVEC 608", MD_INTTM0EQ0
|
| 101 |
|
|
|
| 102 |
|
|
;------------------------------------------------------------------------------
|
| 103 |
|
|
; portSAVE_CONTEXT MACRO
|
| 104 |
|
|
; Saves the context of the remaining general purpose registers
|
| 105 |
|
|
; and the usCriticalNesting Value of the active Task onto the task stack
|
| 106 |
|
|
; saves stack pointer to the TCB
|
| 107 |
|
|
;------------------------------------------------------------------------------
|
| 108 |
|
|
portSAVE_CONTEXT MACRO
|
| 109 |
|
|
#if configDATA_MODE == 1 ; Using the Tiny data model
|
| 110 |
|
|
prepare {r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30},76,sp ; save general purpose registers
|
| 111 |
|
|
sst.w r19,72[ep]
|
| 112 |
|
|
sst.w r18,68[ep]
|
| 113 |
|
|
sst.w r17,64[ep]
|
| 114 |
|
|
sst.w r16,60[ep]
|
| 115 |
|
|
sst.w r15,56[ep]
|
| 116 |
|
|
sst.w r14,52[ep]
|
| 117 |
|
|
sst.w r13,48[ep]
|
| 118 |
|
|
sst.w r12,44[ep]
|
| 119 |
|
|
sst.w r11,40[ep]
|
| 120 |
|
|
sst.w r10,36[ep]
|
| 121 |
|
|
sst.w r9,32[ep]
|
| 122 |
|
|
sst.w r8,28[ep]
|
| 123 |
|
|
sst.w r7,24[ep]
|
| 124 |
|
|
sst.w r6,20[ep]
|
| 125 |
|
|
sst.w r5,16[ep]
|
| 126 |
|
|
sst.w r4,12[ep]
|
| 127 |
|
|
#else ; Using the Small/Large data model
|
| 128 |
|
|
prepare {r20,r21,r22,r23,r24,r26,r27,r28,r29,r30},72,sp ; save general purpose registers
|
| 129 |
|
|
sst.w r19,68[ep]
|
| 130 |
|
|
sst.w r18,64[ep]
|
| 131 |
|
|
sst.w r17,60[ep]
|
| 132 |
|
|
sst.w r16,56[ep]
|
| 133 |
|
|
sst.w r15,52[ep]
|
| 134 |
|
|
sst.w r14,48[ep]
|
| 135 |
|
|
sst.w r13,44[ep]
|
| 136 |
|
|
sst.w r12,40[ep]
|
| 137 |
|
|
sst.w r11,36[ep]
|
| 138 |
|
|
sst.w r10,32[ep]
|
| 139 |
|
|
sst.w r9,28[ep]
|
| 140 |
|
|
sst.w r8,24[ep]
|
| 141 |
|
|
sst.w r7,20[ep]
|
| 142 |
|
|
sst.w r6,16[ep]
|
| 143 |
|
|
sst.w r5,12[ep]
|
| 144 |
|
|
#endif /* configDATA_MODE */
|
| 145 |
|
|
sst.w r2,8[ep]
|
| 146 |
|
|
sst.w r1,4[ep]
|
| 147 |
|
|
MOVHI hi1(usCriticalNesting),r0,r1 ; save usCriticalNesting value to stack
|
| 148 |
|
|
ld.w lw1(usCriticalNesting)[r1],r2
|
| 149 |
|
|
sst.w r2,0[ep]
|
| 150 |
|
|
MOVHI hi1(pxCurrentTCB),r0,r1 ; save SP to top of current TCB
|
| 151 |
|
|
ld.w lw1(pxCurrentTCB)[r1],r2
|
| 152 |
|
|
st.w sp,0[r2]
|
| 153 |
|
|
ENDM
|
| 154 |
|
|
;------------------------------------------------------------------------------
|
| 155 |
|
|
|
| 156 |
|
|
;------------------------------------------------------------------------------
|
| 157 |
|
|
; portRESTORE_CONTEXT MACRO
|
| 158 |
|
|
; Gets stack pointer from the current TCB
|
| 159 |
|
|
; Restores the context of the usCriticalNesting value and general purpose
|
| 160 |
|
|
; registers of the selected task from the task stack
|
| 161 |
|
|
;------------------------------------------------------------------------------
|
| 162 |
|
|
portRESTORE_CONTEXT MACRO
|
| 163 |
|
|
MOVHI hi1(pxCurrentTCB),r0,r1 ; get Stackpointer address
|
| 164 |
|
|
ld.w lw1(pxCurrentTCB)[r1],sp
|
| 165 |
|
|
MOV sp,r1
|
| 166 |
|
|
ld.w 0[r1],sp ; load stackpointer
|
| 167 |
|
|
MOV sp,ep ; set stack pointer to element pointer
|
| 168 |
|
|
sld.w 0[ep],r1 ; load usCriticalNesting value from stack
|
| 169 |
|
|
MOVHI hi1(usCriticalNesting),r0,r2
|
| 170 |
|
|
st.w r1,lw1(usCriticalNesting)[r2]
|
| 171 |
|
|
sld.w 4[ep],r1 ; restore general purpose registers
|
| 172 |
|
|
sld.w 8[ep],r2
|
| 173 |
|
|
#if configDATA_MODE == 1 ; Using Tiny data model
|
| 174 |
|
|
sld.w 12[ep],r4
|
| 175 |
|
|
sld.w 16[ep],r5
|
| 176 |
|
|
sld.w 20[ep],r6
|
| 177 |
|
|
sld.w 24[ep],r7
|
| 178 |
|
|
sld.w 28[ep],r8
|
| 179 |
|
|
sld.w 32[ep],r9
|
| 180 |
|
|
sld.w 36[ep],r10
|
| 181 |
|
|
sld.w 40[ep],r11
|
| 182 |
|
|
sld.w 44[ep],r12
|
| 183 |
|
|
sld.w 48[ep],r13
|
| 184 |
|
|
sld.w 52[ep],r14
|
| 185 |
|
|
sld.w 56[ep],r15
|
| 186 |
|
|
sld.w 60[ep],r16
|
| 187 |
|
|
sld.w 64[ep],r17
|
| 188 |
|
|
sld.w 68[ep],r18
|
| 189 |
|
|
sld.w 72[ep],r19
|
| 190 |
|
|
dispose 76,{r20,r21,r22,r23,r24,r25,r26,r27,r28,r29,r30}
|
| 191 |
|
|
#else ; Using Small/Large data model
|
| 192 |
|
|
sld.w 12[ep],r5
|
| 193 |
|
|
sld.w 16[ep],r6
|
| 194 |
|
|
sld.w 20[ep],r7
|
| 195 |
|
|
sld.w 24[ep],r8
|
| 196 |
|
|
sld.w 28[ep],r9
|
| 197 |
|
|
sld.w 32[ep],r10
|
| 198 |
|
|
sld.w 36[ep],r11
|
| 199 |
|
|
sld.w 40[ep],r12
|
| 200 |
|
|
sld.w 44[ep],r13
|
| 201 |
|
|
sld.w 48[ep],r14
|
| 202 |
|
|
sld.w 52[ep],r15
|
| 203 |
|
|
sld.w 56[ep],r16
|
| 204 |
|
|
sld.w 60[ep],r17
|
| 205 |
|
|
sld.w 64[ep],r18
|
| 206 |
|
|
sld.w 68[ep],r19
|
| 207 |
|
|
dispose 72,{r20,r21,r22,r23,r24,r26,r27,r28,r29,r30}
|
| 208 |
|
|
#endif /* configDATA_MODE */
|
| 209 |
|
|
ENDM
|
| 210 |
|
|
;------------------------------------------------------------------------------
|
| 211 |
|
|
|
| 212 |
|
|
;------------------------------------------------------------------------------
|
| 213 |
|
|
; Restore the context of the first task that is going to run.
|
| 214 |
|
|
;
|
| 215 |
|
|
; Input: NONE
|
| 216 |
|
|
;
|
| 217 |
|
|
; Call: CALL vPortStart
|
| 218 |
|
|
;
|
| 219 |
|
|
; Output: NONE
|
| 220 |
|
|
;------------------------------------------------------------------------------
|
| 221 |
|
|
RSEG CODE:CODE
|
| 222 |
|
|
vPortStart:
|
| 223 |
|
|
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
|
| 224 |
|
|
ld.w 0[sp],lp
|
| 225 |
|
|
ldsr lp,5 ; restore PSW
|
| 226 |
|
|
DI
|
| 227 |
|
|
ld.w 4[sp],lp ; restore LP
|
| 228 |
|
|
ld.w 8[sp],lp ; restore LP
|
| 229 |
|
|
ADD 0x0C,sp ; set SP to right position
|
| 230 |
|
|
EI
|
| 231 |
|
|
jmp [lp]
|
| 232 |
|
|
;------------------------------------------------------------------------------
|
| 233 |
|
|
|
| 234 |
|
|
;------------------------------------------------------------------------------
|
| 235 |
|
|
; Port Yield function to check for a Task switch in the cooperative and
|
| 236 |
|
|
; preemptive mode
|
| 237 |
|
|
;
|
| 238 |
|
|
; Input: NONE
|
| 239 |
|
|
;
|
| 240 |
|
|
; Call: CALL vPortYield
|
| 241 |
|
|
;
|
| 242 |
|
|
; Output: NONE
|
| 243 |
|
|
;------------------------------------------------------------------------------
|
| 244 |
|
|
|
| 245 |
|
|
RSEG CODE:CODE
|
| 246 |
|
|
vPortYield:
|
| 247 |
|
|
|
| 248 |
|
|
add -0x0C,sp ; prepare stack to save necessary values
|
| 249 |
|
|
st.w lp,8[sp] ; store LP to stack
|
| 250 |
|
|
stsr 0,r31
|
| 251 |
|
|
st.w lp,4[sp] ; store EIPC to stack
|
| 252 |
|
|
stsr 1,lp
|
| 253 |
|
|
st.w lp,0[sp] ; store EIPSW to stack
|
| 254 |
|
|
portSAVE_CONTEXT ; Save the context of the current task.
|
| 255 |
|
|
jarl vTaskSwitchContext,lp ; Call the scheduler.
|
| 256 |
|
|
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
|
| 257 |
|
|
; ... scheduler decided should run.
|
| 258 |
|
|
ld.w 0[sp],lp ; restore EIPSW from stack
|
| 259 |
|
|
ldsr lp,1
|
| 260 |
|
|
ld.w 4[sp],lp ; restore EIPC from stack
|
| 261 |
|
|
ldsr lp,0
|
| 262 |
|
|
ld.w 8[sp],lp ; restore LP from stack
|
| 263 |
|
|
add 0x0C,sp ; set SP to right position
|
| 264 |
|
|
|
| 265 |
|
|
RETI
|
| 266 |
|
|
|
| 267 |
|
|
;------------------------------------------------------------------------------
|
| 268 |
|
|
|
| 269 |
|
|
;------------------------------------------------------------------------------
|
| 270 |
|
|
; Perform the necessary steps of the Tick Count Increment and Task Switch
|
| 271 |
|
|
; depending on the chosen kernel configuration
|
| 272 |
|
|
;
|
| 273 |
|
|
; Input: NONE
|
| 274 |
|
|
;
|
| 275 |
|
|
; Call: ISR
|
| 276 |
|
|
;
|
| 277 |
|
|
; Output: NONE
|
| 278 |
|
|
;------------------------------------------------------------------------------
|
| 279 |
|
|
#if configUSE_PREEMPTION == 1 ; use preemptive kernel mode
|
| 280 |
|
|
|
| 281 |
|
|
MD_INTTM0EQ0:
|
| 282 |
|
|
|
| 283 |
|
|
add -0x0C,sp ; prepare stack to save necessary values
|
| 284 |
|
|
st.w lp,8[sp] ; store LP to stack
|
| 285 |
|
|
stsr 0,r31
|
| 286 |
|
|
st.w lp,4[sp] ; store EIPC to stack
|
| 287 |
|
|
stsr 1,lp
|
| 288 |
|
|
st.w lp,0[sp] ; store EIPSW to stack
|
| 289 |
|
|
portSAVE_CONTEXT ; Save the context of the current task.
|
| 290 |
|
|
jarl vTaskIncrementTick,lp ; Call the timer tick function.
|
| 291 |
|
|
jarl vTaskSwitchContext,lp ; Call the scheduler.
|
| 292 |
|
|
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
|
| 293 |
|
|
; ... scheduler decided should run.
|
| 294 |
|
|
ld.w 0[sp],lp ; restore EIPSW from stack
|
| 295 |
|
|
ldsr lp,1
|
| 296 |
|
|
ld.w 4[sp],lp ; restore EIPC from stack
|
| 297 |
|
|
ldsr lp,0
|
| 298 |
|
|
ld.w 8[sp],lp ; restore LP from stack
|
| 299 |
|
|
add 0x0C,sp ; set SP to right position
|
| 300 |
|
|
|
| 301 |
|
|
RETI
|
| 302 |
|
|
;------------------------------------------------------------------------------
|
| 303 |
|
|
#else ; use cooperative kernel mode
|
| 304 |
|
|
|
| 305 |
|
|
MD_INTTM0EQ0:
|
| 306 |
|
|
prepare {lp,ep},8,sp
|
| 307 |
|
|
sst.w r1,4[ep]
|
| 308 |
|
|
sst.w r5,0[ep]
|
| 309 |
|
|
jarl vTaskIncrementTick,lp ; Call the timer tick function.
|
| 310 |
|
|
sld.w 0[ep],r5
|
| 311 |
|
|
sld.w 4[ep],r1
|
| 312 |
|
|
dispose 8,{lp,ep}
|
| 313 |
|
|
RETI
|
| 314 |
|
|
#endif /* configUSE_PREEMPTION */
|
| 315 |
|
|
|
| 316 |
|
|
;------------------------------------------------------------------------------
|
| 317 |
|
|
COMMON INTVEC:CODE:ROOT(2)
|
| 318 |
|
|
ORG 608
|
| 319 |
|
|
`??MD_INTTM0EQ0??INTVEC 608`:
|
| 320 |
|
|
JR MD_INTTM0EQ0
|
| 321 |
|
|
|
| 322 |
|
|
RSEG NEAR_ID:CONST:SORT:NOROOT(2)
|
| 323 |
|
|
`?`:
|
| 324 |
|
|
DW 10
|
| 325 |
|
|
|
| 326 |
|
|
COMMON INTVEC:CODE:ROOT(2)
|
| 327 |
|
|
ORG 40H
|
| 328 |
|
|
`??vPortYield??INTVEC 40`:
|
| 329 |
|
|
JR vPortYield
|
| 330 |
|
|
|
| 331 |
|
|
;------------------------------------------------------------------------------
|
| 332 |
|
|
; set microcontroller security ID
|
| 333 |
|
|
|
| 334 |
|
|
COMMON INTVEC:CODE:ROOT(2)
|
| 335 |
|
|
ORG 70H
|
| 336 |
|
|
`SECUID`:
|
| 337 |
|
|
DB CG_SECURITY0
|
| 338 |
|
|
DB CG_SECURITY1
|
| 339 |
|
|
DB CG_SECURITY2
|
| 340 |
|
|
DB CG_SECURITY3
|
| 341 |
|
|
DB CG_SECURITY4
|
| 342 |
|
|
DB CG_SECURITY5
|
| 343 |
|
|
DB CG_SECURITY6
|
| 344 |
|
|
DB CG_SECURITY7
|
| 345 |
|
|
DB CG_SECURITY8
|
| 346 |
|
|
DB CG_SECURITY9
|
| 347 |
|
|
|
| 348 |
|
|
;------------------------------------------------------------------------------
|
| 349 |
|
|
; set microcontroller option bytes
|
| 350 |
|
|
|
| 351 |
|
|
COMMON INTVEC:CODE:ROOT(2)
|
| 352 |
|
|
ORG 7AH
|
| 353 |
|
|
`OPTBYTES`:
|
| 354 |
|
|
DB CG_OPTION7A
|
| 355 |
|
|
DB CG_OPTION7B
|
| 356 |
|
|
DB OPT7C
|
| 357 |
|
|
DB OPT7D
|
| 358 |
|
|
DB OPT7E
|
| 359 |
|
|
DB OPT7F
|
| 360 |
|
|
|
| 361 |
|
|
END
|