Lab Checkoff

Dependencies:   SDFileSystem TextLCD mbed-rtos mbed wave_player FATFileSystem

Committer:
doubster
Date:
Wed Nov 13 20:00:28 2013 +0000
Revision:
0:67dbd54e60d4
Lab Checkoff

Who changed what in which revision?

UserRevisionLine numberNew contents of line
doubster 0:67dbd54e60d4 1 /*----------------------------------------------------------------------------
doubster 0:67dbd54e60d4 2 * RL-ARM - RTX
doubster 0:67dbd54e60d4 3 *----------------------------------------------------------------------------
doubster 0:67dbd54e60d4 4 * Name: HAL_CM3.S
doubster 0:67dbd54e60d4 5 * Purpose: Hardware Abstraction Layer for Cortex-M3
doubster 0:67dbd54e60d4 6 * Rev.: V4.60
doubster 0:67dbd54e60d4 7 *----------------------------------------------------------------------------
doubster 0:67dbd54e60d4 8 *
doubster 0:67dbd54e60d4 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
doubster 0:67dbd54e60d4 10 * All rights reserved.
doubster 0:67dbd54e60d4 11 * Redistribution and use in source and binary forms, with or without
doubster 0:67dbd54e60d4 12 * modification, are permitted provided that the following conditions are met:
doubster 0:67dbd54e60d4 13 * - Redistributions of source code must retain the above copyright
doubster 0:67dbd54e60d4 14 * notice, this list of conditions and the following disclaimer.
doubster 0:67dbd54e60d4 15 * - Redistributions in binary form must reproduce the above copyright
doubster 0:67dbd54e60d4 16 * notice, this list of conditions and the following disclaimer in the
doubster 0:67dbd54e60d4 17 * documentation and/or other materials provided with the distribution.
doubster 0:67dbd54e60d4 18 * - Neither the name of ARM nor the names of its contributors may be used
doubster 0:67dbd54e60d4 19 * to endorse or promote products derived from this software without
doubster 0:67dbd54e60d4 20 * specific prior written permission.
doubster 0:67dbd54e60d4 21 *
doubster 0:67dbd54e60d4 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
doubster 0:67dbd54e60d4 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
doubster 0:67dbd54e60d4 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
doubster 0:67dbd54e60d4 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
doubster 0:67dbd54e60d4 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
doubster 0:67dbd54e60d4 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
doubster 0:67dbd54e60d4 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
doubster 0:67dbd54e60d4 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
doubster 0:67dbd54e60d4 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
doubster 0:67dbd54e60d4 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
doubster 0:67dbd54e60d4 32 * POSSIBILITY OF SUCH DAMAGE.
doubster 0:67dbd54e60d4 33 *---------------------------------------------------------------------------*/
doubster 0:67dbd54e60d4 34
doubster 0:67dbd54e60d4 35 .file "HAL_CM3.S"
doubster 0:67dbd54e60d4 36 .syntax unified
doubster 0:67dbd54e60d4 37
doubster 0:67dbd54e60d4 38 .equ TCB_TSTACK, 36
doubster 0:67dbd54e60d4 39
doubster 0:67dbd54e60d4 40
doubster 0:67dbd54e60d4 41 /*----------------------------------------------------------------------------
doubster 0:67dbd54e60d4 42 * Functions
doubster 0:67dbd54e60d4 43 *---------------------------------------------------------------------------*/
doubster 0:67dbd54e60d4 44
doubster 0:67dbd54e60d4 45 .thumb
doubster 0:67dbd54e60d4 46
doubster 0:67dbd54e60d4 47 .section ".text"
doubster 0:67dbd54e60d4 48 .align 2
doubster 0:67dbd54e60d4 49
doubster 0:67dbd54e60d4 50
doubster 0:67dbd54e60d4 51 /*--------------------------- rt_set_PSP ------------------------------------*/
doubster 0:67dbd54e60d4 52
doubster 0:67dbd54e60d4 53 # void rt_set_PSP (U32 stack);
doubster 0:67dbd54e60d4 54
doubster 0:67dbd54e60d4 55 .thumb_func
doubster 0:67dbd54e60d4 56 .type rt_set_PSP, %function
doubster 0:67dbd54e60d4 57 .global rt_set_PSP
doubster 0:67dbd54e60d4 58 rt_set_PSP:
doubster 0:67dbd54e60d4 59 .fnstart
doubster 0:67dbd54e60d4 60 .cantunwind
doubster 0:67dbd54e60d4 61
doubster 0:67dbd54e60d4 62 MSR PSP,R0
doubster 0:67dbd54e60d4 63 BX LR
doubster 0:67dbd54e60d4 64
doubster 0:67dbd54e60d4 65 .fnend
doubster 0:67dbd54e60d4 66 .size rt_set_PSP, .-rt_set_PSP
doubster 0:67dbd54e60d4 67
doubster 0:67dbd54e60d4 68
doubster 0:67dbd54e60d4 69 /*--------------------------- rt_get_PSP ------------------------------------*/
doubster 0:67dbd54e60d4 70
doubster 0:67dbd54e60d4 71 # U32 rt_get_PSP (void);
doubster 0:67dbd54e60d4 72
doubster 0:67dbd54e60d4 73 .thumb_func
doubster 0:67dbd54e60d4 74 .type rt_get_PSP, %function
doubster 0:67dbd54e60d4 75 .global rt_get_PSP
doubster 0:67dbd54e60d4 76 rt_get_PSP:
doubster 0:67dbd54e60d4 77 .fnstart
doubster 0:67dbd54e60d4 78 .cantunwind
doubster 0:67dbd54e60d4 79
doubster 0:67dbd54e60d4 80 MRS R0,PSP
doubster 0:67dbd54e60d4 81 BX LR
doubster 0:67dbd54e60d4 82
doubster 0:67dbd54e60d4 83 .fnend
doubster 0:67dbd54e60d4 84 .size rt_get_PSP, .-rt_get_PSP
doubster 0:67dbd54e60d4 85
doubster 0:67dbd54e60d4 86
doubster 0:67dbd54e60d4 87 /*--------------------------- os_set_env ------------------------------------*/
doubster 0:67dbd54e60d4 88
doubster 0:67dbd54e60d4 89 # void os_set_env (void);
doubster 0:67dbd54e60d4 90 /* Switch to Unprivileged/Privileged Thread mode, use PSP. */
doubster 0:67dbd54e60d4 91
doubster 0:67dbd54e60d4 92 .thumb_func
doubster 0:67dbd54e60d4 93 .type os_set_env, %function
doubster 0:67dbd54e60d4 94 .global os_set_env
doubster 0:67dbd54e60d4 95 os_set_env:
doubster 0:67dbd54e60d4 96 .fnstart
doubster 0:67dbd54e60d4 97 .cantunwind
doubster 0:67dbd54e60d4 98
doubster 0:67dbd54e60d4 99 MOV R0,SP /* PSP = MSP */
doubster 0:67dbd54e60d4 100 MSR PSP,R0
doubster 0:67dbd54e60d4 101 LDR R0,=os_flags
doubster 0:67dbd54e60d4 102 LDRB R0,[R0]
doubster 0:67dbd54e60d4 103 LSLS R0,#31
doubster 0:67dbd54e60d4 104 ITE NE
doubster 0:67dbd54e60d4 105 MOVNE R0,#0x02 /* Privileged Thread mode, use PSP */
doubster 0:67dbd54e60d4 106 MOVEQ R0,#0x03 /* Unprivileged Thread mode, use PSP */
doubster 0:67dbd54e60d4 107 MSR CONTROL,R0
doubster 0:67dbd54e60d4 108 BX LR
doubster 0:67dbd54e60d4 109
doubster 0:67dbd54e60d4 110 .fnend
doubster 0:67dbd54e60d4 111 .size os_set_env, .-os_set_env
doubster 0:67dbd54e60d4 112
doubster 0:67dbd54e60d4 113
doubster 0:67dbd54e60d4 114 /*--------------------------- _alloc_box ------------------------------------*/
doubster 0:67dbd54e60d4 115
doubster 0:67dbd54e60d4 116 # void *_alloc_box (void *box_mem);
doubster 0:67dbd54e60d4 117 /* Function wrapper for Unprivileged/Privileged mode. */
doubster 0:67dbd54e60d4 118
doubster 0:67dbd54e60d4 119 .thumb_func
doubster 0:67dbd54e60d4 120 .type _alloc_box, %function
doubster 0:67dbd54e60d4 121 .global _alloc_box
doubster 0:67dbd54e60d4 122 _alloc_box:
doubster 0:67dbd54e60d4 123 .fnstart
doubster 0:67dbd54e60d4 124 .cantunwind
doubster 0:67dbd54e60d4 125
doubster 0:67dbd54e60d4 126 LDR R12,=rt_alloc_box
doubster 0:67dbd54e60d4 127 MRS R3,IPSR
doubster 0:67dbd54e60d4 128 LSLS R3,#24
doubster 0:67dbd54e60d4 129 IT NE
doubster 0:67dbd54e60d4 130 BXNE R12
doubster 0:67dbd54e60d4 131 MRS R3,CONTROL
doubster 0:67dbd54e60d4 132 LSLS R3,#31
doubster 0:67dbd54e60d4 133 IT EQ
doubster 0:67dbd54e60d4 134 BXEQ R12
doubster 0:67dbd54e60d4 135 SVC 0
doubster 0:67dbd54e60d4 136 BX LR
doubster 0:67dbd54e60d4 137
doubster 0:67dbd54e60d4 138 .fnend
doubster 0:67dbd54e60d4 139 .size _alloc_box, .-_alloc_box
doubster 0:67dbd54e60d4 140
doubster 0:67dbd54e60d4 141
doubster 0:67dbd54e60d4 142 /*--------------------------- _free_box -------------------------------------*/
doubster 0:67dbd54e60d4 143
doubster 0:67dbd54e60d4 144 # int _free_box (void *box_mem, void *box);
doubster 0:67dbd54e60d4 145 /* Function wrapper for Unprivileged/Privileged mode. */
doubster 0:67dbd54e60d4 146
doubster 0:67dbd54e60d4 147 .thumb_func
doubster 0:67dbd54e60d4 148 .type _free_box, %function
doubster 0:67dbd54e60d4 149 .global _free_box
doubster 0:67dbd54e60d4 150 _free_box:
doubster 0:67dbd54e60d4 151 .fnstart
doubster 0:67dbd54e60d4 152 .cantunwind
doubster 0:67dbd54e60d4 153
doubster 0:67dbd54e60d4 154 LDR R12,=rt_free_box
doubster 0:67dbd54e60d4 155 MRS R3,IPSR
doubster 0:67dbd54e60d4 156 LSLS R3,#24
doubster 0:67dbd54e60d4 157 IT NE
doubster 0:67dbd54e60d4 158 BXNE R12
doubster 0:67dbd54e60d4 159 MRS R3,CONTROL
doubster 0:67dbd54e60d4 160 LSLS R3,#31
doubster 0:67dbd54e60d4 161 IT EQ
doubster 0:67dbd54e60d4 162 BXEQ R12
doubster 0:67dbd54e60d4 163 SVC 0
doubster 0:67dbd54e60d4 164 BX LR
doubster 0:67dbd54e60d4 165
doubster 0:67dbd54e60d4 166 .fnend
doubster 0:67dbd54e60d4 167 .size _free_box, .-_free_box
doubster 0:67dbd54e60d4 168
doubster 0:67dbd54e60d4 169
doubster 0:67dbd54e60d4 170 /*-------------------------- SVC_Handler ------------------------------------*/
doubster 0:67dbd54e60d4 171
doubster 0:67dbd54e60d4 172 # void SVC_Handler (void);
doubster 0:67dbd54e60d4 173
doubster 0:67dbd54e60d4 174 .thumb_func
doubster 0:67dbd54e60d4 175 .type SVC_Handler, %function
doubster 0:67dbd54e60d4 176 .global SVC_Handler
doubster 0:67dbd54e60d4 177 SVC_Handler:
doubster 0:67dbd54e60d4 178 .fnstart
doubster 0:67dbd54e60d4 179 .cantunwind
doubster 0:67dbd54e60d4 180
doubster 0:67dbd54e60d4 181 MRS R0,PSP /* Read PSP */
doubster 0:67dbd54e60d4 182 LDR R1,[R0,#24] /* Read Saved PC from Stack */
doubster 0:67dbd54e60d4 183 LDRB R1,[R1,#-2] /* Load SVC Number */
doubster 0:67dbd54e60d4 184 CBNZ R1,SVC_User
doubster 0:67dbd54e60d4 185
doubster 0:67dbd54e60d4 186 LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
doubster 0:67dbd54e60d4 187 BLX R12 /* Call SVC Function */
doubster 0:67dbd54e60d4 188
doubster 0:67dbd54e60d4 189 MRS R12,PSP /* Read PSP */
doubster 0:67dbd54e60d4 190 STM R12,{R0-R2} /* Store return values */
doubster 0:67dbd54e60d4 191
doubster 0:67dbd54e60d4 192 LDR R3,=os_tsk
doubster 0:67dbd54e60d4 193 LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
doubster 0:67dbd54e60d4 194 CMP R1,R2
doubster 0:67dbd54e60d4 195 BEQ SVC_Exit /* no task switch */
doubster 0:67dbd54e60d4 196
doubster 0:67dbd54e60d4 197 CBZ R1,SVC_Next /* Runtask deleted? */
doubster 0:67dbd54e60d4 198 STMDB R12!,{R4-R11} /* Save Old context */
doubster 0:67dbd54e60d4 199 STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
doubster 0:67dbd54e60d4 200
doubster 0:67dbd54e60d4 201 PUSH {R2,R3}
doubster 0:67dbd54e60d4 202 BL rt_stk_check /* Check for Stack overflow */
doubster 0:67dbd54e60d4 203 POP {R2,R3}
doubster 0:67dbd54e60d4 204
doubster 0:67dbd54e60d4 205 SVC_Next:
doubster 0:67dbd54e60d4 206 STR R2,[R3] /* os_tsk.run = os_tsk.new */
doubster 0:67dbd54e60d4 207
doubster 0:67dbd54e60d4 208 LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
doubster 0:67dbd54e60d4 209 LDMIA R12!,{R4-R11} /* Restore New Context */
doubster 0:67dbd54e60d4 210 MSR PSP,R12 /* Write PSP */
doubster 0:67dbd54e60d4 211
doubster 0:67dbd54e60d4 212 SVC_Exit:
doubster 0:67dbd54e60d4 213 MVN LR,#~0xFFFFFFFD /* set EXC_RETURN value */
doubster 0:67dbd54e60d4 214 BX LR
doubster 0:67dbd54e60d4 215
doubster 0:67dbd54e60d4 216 /*------------------- User SVC ------------------------------*/
doubster 0:67dbd54e60d4 217
doubster 0:67dbd54e60d4 218 SVC_User:
doubster 0:67dbd54e60d4 219 PUSH {R4,LR} /* Save Registers */
doubster 0:67dbd54e60d4 220 LDR R2,=SVC_Count
doubster 0:67dbd54e60d4 221 LDR R2,[R2]
doubster 0:67dbd54e60d4 222 CMP R1,R2
doubster 0:67dbd54e60d4 223 BHI SVC_Done /* Overflow */
doubster 0:67dbd54e60d4 224
doubster 0:67dbd54e60d4 225 LDR R4,=SVC_Table-4
doubster 0:67dbd54e60d4 226 LDR R4,[R4,R1,LSL #2] /* Load SVC Function Address */
doubster 0:67dbd54e60d4 227
doubster 0:67dbd54e60d4 228 LDM R0,{R0-R3,R12} /* Read R0-R3,R12 from stack */
doubster 0:67dbd54e60d4 229 BLX R4 /* Call SVC Function */
doubster 0:67dbd54e60d4 230
doubster 0:67dbd54e60d4 231 MRS R12,PSP
doubster 0:67dbd54e60d4 232 STM R12,{R0-R3} /* Function return values */
doubster 0:67dbd54e60d4 233 SVC_Done:
doubster 0:67dbd54e60d4 234 POP {R4,PC} /* RETI */
doubster 0:67dbd54e60d4 235
doubster 0:67dbd54e60d4 236 .fnend
doubster 0:67dbd54e60d4 237 .size SVC_Handler, .-SVC_Handler
doubster 0:67dbd54e60d4 238
doubster 0:67dbd54e60d4 239
doubster 0:67dbd54e60d4 240 /*-------------------------- PendSV_Handler ---------------------------------*/
doubster 0:67dbd54e60d4 241
doubster 0:67dbd54e60d4 242 # void PendSV_Handler (void);
doubster 0:67dbd54e60d4 243
doubster 0:67dbd54e60d4 244 .thumb_func
doubster 0:67dbd54e60d4 245 .type PendSV_Handler, %function
doubster 0:67dbd54e60d4 246 .global PendSV_Handler
doubster 0:67dbd54e60d4 247 .global Sys_Switch
doubster 0:67dbd54e60d4 248 PendSV_Handler:
doubster 0:67dbd54e60d4 249 .fnstart
doubster 0:67dbd54e60d4 250 .cantunwind
doubster 0:67dbd54e60d4 251
doubster 0:67dbd54e60d4 252 BL rt_pop_req
doubster 0:67dbd54e60d4 253
doubster 0:67dbd54e60d4 254 Sys_Switch:
doubster 0:67dbd54e60d4 255 LDR R3,=os_tsk
doubster 0:67dbd54e60d4 256 LDM R3,{R1,R2} /* os_tsk.run, os_tsk.new */
doubster 0:67dbd54e60d4 257 CMP R1,R2
doubster 0:67dbd54e60d4 258 BEQ Sys_Exit
doubster 0:67dbd54e60d4 259
doubster 0:67dbd54e60d4 260 MRS R12,PSP /* Read PSP */
doubster 0:67dbd54e60d4 261 STMDB R12!,{R4-R11} /* Save Old context */
doubster 0:67dbd54e60d4 262 STR R12,[R1,#TCB_TSTACK] /* Update os_tsk.run->tsk_stack */
doubster 0:67dbd54e60d4 263
doubster 0:67dbd54e60d4 264 PUSH {R2,R3}
doubster 0:67dbd54e60d4 265 BL rt_stk_check /* Check for Stack overflow */
doubster 0:67dbd54e60d4 266 POP {R2,R3}
doubster 0:67dbd54e60d4 267
doubster 0:67dbd54e60d4 268 STR R2,[R3] /* os_tsk.run = os_tsk.new */
doubster 0:67dbd54e60d4 269
doubster 0:67dbd54e60d4 270 LDR R12,[R2,#TCB_TSTACK] /* os_tsk.new->tsk_stack */
doubster 0:67dbd54e60d4 271 LDMIA R12!,{R4-R11} /* Restore New Context */
doubster 0:67dbd54e60d4 272 MSR PSP,R12 /* Write PSP */
doubster 0:67dbd54e60d4 273
doubster 0:67dbd54e60d4 274 Sys_Exit:
doubster 0:67dbd54e60d4 275 MVN LR,#~0xFFFFFFFD /* set EXC_RETURN value */
doubster 0:67dbd54e60d4 276 BX LR /* Return to Thread Mode */
doubster 0:67dbd54e60d4 277
doubster 0:67dbd54e60d4 278 .fnend
doubster 0:67dbd54e60d4 279 .size PendSV_Handler, .-PendSV_Handler
doubster 0:67dbd54e60d4 280
doubster 0:67dbd54e60d4 281
doubster 0:67dbd54e60d4 282 /*-------------------------- SysTick_Handler --------------------------------*/
doubster 0:67dbd54e60d4 283
doubster 0:67dbd54e60d4 284 # void SysTick_Handler (void);
doubster 0:67dbd54e60d4 285
doubster 0:67dbd54e60d4 286 .thumb_func
doubster 0:67dbd54e60d4 287 .type SysTick_Handler, %function
doubster 0:67dbd54e60d4 288 .global SysTick_Handler
doubster 0:67dbd54e60d4 289 SysTick_Handler:
doubster 0:67dbd54e60d4 290 .fnstart
doubster 0:67dbd54e60d4 291 .cantunwind
doubster 0:67dbd54e60d4 292
doubster 0:67dbd54e60d4 293 BL rt_systick
doubster 0:67dbd54e60d4 294 B Sys_Switch
doubster 0:67dbd54e60d4 295
doubster 0:67dbd54e60d4 296 .fnend
doubster 0:67dbd54e60d4 297 .size SysTick_Handler, .-SysTick_Handler
doubster 0:67dbd54e60d4 298
doubster 0:67dbd54e60d4 299
doubster 0:67dbd54e60d4 300 /*-------------------------- OS_Tick_Handler --------------------------------*/
doubster 0:67dbd54e60d4 301
doubster 0:67dbd54e60d4 302 # void OS_Tick_Handler (void);
doubster 0:67dbd54e60d4 303
doubster 0:67dbd54e60d4 304 .thumb_func
doubster 0:67dbd54e60d4 305 .type OS_Tick_Handler, %function
doubster 0:67dbd54e60d4 306 .global OS_Tick_Handler
doubster 0:67dbd54e60d4 307 OS_Tick_Handler:
doubster 0:67dbd54e60d4 308 .fnstart
doubster 0:67dbd54e60d4 309 .cantunwind
doubster 0:67dbd54e60d4 310
doubster 0:67dbd54e60d4 311 BL os_tick_irqack
doubster 0:67dbd54e60d4 312 BL rt_systick
doubster 0:67dbd54e60d4 313 B Sys_Switch
doubster 0:67dbd54e60d4 314
doubster 0:67dbd54e60d4 315 .fnend
doubster 0:67dbd54e60d4 316 .size OS_Tick_Handler, .-OS_Tick_Handler
doubster 0:67dbd54e60d4 317
doubster 0:67dbd54e60d4 318
doubster 0:67dbd54e60d4 319 .end
doubster 0:67dbd54e60d4 320
doubster 0:67dbd54e60d4 321 /*----------------------------------------------------------------------------
doubster 0:67dbd54e60d4 322 * end of file
doubster 0:67dbd54e60d4 323 *---------------------------------------------------------------------------*/
doubster 0:67dbd54e60d4 324