うおーるぼっとをWiiリモコンでコントロールする新しいプログラムです。 以前のものより、Wiiリモコンが早く繋がる様になりました。 It is a program which controls A with the Wii remote. ※ A Bluetooth dongle and a Wii remote control are needed.

Dependencies:   USBHost mbed FATFileSystem mbed-rtos

Committer:
jksoft
Date:
Mon Jun 10 16:01:50 2013 +0000
Revision:
0:fccb789424fc
1.0

Who changed what in which revision?

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