うおーるぼっとを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
USBHost/mbed-rtos/rtx/rt_MemBox.c@0:fccb789424fc, 2013-06-10 (annotated)
- Committer:
- jksoft
- Date:
- Mon Jun 10 16:01:50 2013 +0000
- Revision:
- 0:fccb789424fc
1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:fccb789424fc | 1 | /*---------------------------------------------------------------------------- |
jksoft | 0:fccb789424fc | 2 | * RL-ARM - RTX |
jksoft | 0:fccb789424fc | 3 | *---------------------------------------------------------------------------- |
jksoft | 0:fccb789424fc | 4 | * Name: RT_MEMBOX.C |
jksoft | 0:fccb789424fc | 5 | * Purpose: Interface functions for fixed memory block management system |
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_MemBox.h" |
jksoft | 0:fccb789424fc | 39 | #include "rt_HAL_CM.h" |
jksoft | 0:fccb789424fc | 40 | |
jksoft | 0:fccb789424fc | 41 | /*---------------------------------------------------------------------------- |
jksoft | 0:fccb789424fc | 42 | * Global Functions |
jksoft | 0:fccb789424fc | 43 | *---------------------------------------------------------------------------*/ |
jksoft | 0:fccb789424fc | 44 | |
jksoft | 0:fccb789424fc | 45 | |
jksoft | 0:fccb789424fc | 46 | /*--------------------------- _init_box -------------------------------------*/ |
jksoft | 0:fccb789424fc | 47 | |
jksoft | 0:fccb789424fc | 48 | int _init_box (void *box_mem, U32 box_size, U32 blk_size) { |
jksoft | 0:fccb789424fc | 49 | /* Initialize memory block system, returns 0 if OK, 1 if fails. */ |
jksoft | 0:fccb789424fc | 50 | void *end; |
jksoft | 0:fccb789424fc | 51 | void *blk; |
jksoft | 0:fccb789424fc | 52 | void *next; |
jksoft | 0:fccb789424fc | 53 | U32 sizeof_bm; |
jksoft | 0:fccb789424fc | 54 | |
jksoft | 0:fccb789424fc | 55 | /* Create memory structure. */ |
jksoft | 0:fccb789424fc | 56 | if (blk_size & BOX_ALIGN_8) { |
jksoft | 0:fccb789424fc | 57 | /* Memory blocks 8-byte aligned. */ |
jksoft | 0:fccb789424fc | 58 | blk_size = ((blk_size & ~BOX_ALIGN_8) + 7) & ~7; |
jksoft | 0:fccb789424fc | 59 | sizeof_bm = (sizeof (struct OS_BM) + 7) & ~7; |
jksoft | 0:fccb789424fc | 60 | } |
jksoft | 0:fccb789424fc | 61 | else { |
jksoft | 0:fccb789424fc | 62 | /* Memory blocks 4-byte aligned. */ |
jksoft | 0:fccb789424fc | 63 | blk_size = (blk_size + 3) & ~3; |
jksoft | 0:fccb789424fc | 64 | sizeof_bm = sizeof (struct OS_BM); |
jksoft | 0:fccb789424fc | 65 | } |
jksoft | 0:fccb789424fc | 66 | if (blk_size == 0) { |
jksoft | 0:fccb789424fc | 67 | return (1); |
jksoft | 0:fccb789424fc | 68 | } |
jksoft | 0:fccb789424fc | 69 | if ((blk_size + sizeof_bm) > box_size) { |
jksoft | 0:fccb789424fc | 70 | return (1); |
jksoft | 0:fccb789424fc | 71 | } |
jksoft | 0:fccb789424fc | 72 | /* Create a Memory structure. */ |
jksoft | 0:fccb789424fc | 73 | blk = ((U8 *) box_mem) + sizeof_bm; |
jksoft | 0:fccb789424fc | 74 | ((P_BM) box_mem)->free = blk; |
jksoft | 0:fccb789424fc | 75 | end = ((U8 *) box_mem) + box_size; |
jksoft | 0:fccb789424fc | 76 | ((P_BM) box_mem)->end = end; |
jksoft | 0:fccb789424fc | 77 | ((P_BM) box_mem)->blk_size = blk_size; |
jksoft | 0:fccb789424fc | 78 | |
jksoft | 0:fccb789424fc | 79 | /* Link all free blocks using offsets. */ |
jksoft | 0:fccb789424fc | 80 | end = ((U8 *) end) - blk_size; |
jksoft | 0:fccb789424fc | 81 | while (1) { |
jksoft | 0:fccb789424fc | 82 | next = ((U8 *) blk) + blk_size; |
jksoft | 0:fccb789424fc | 83 | if (next > end) break; |
jksoft | 0:fccb789424fc | 84 | *((void **)blk) = next; |
jksoft | 0:fccb789424fc | 85 | blk = next; |
jksoft | 0:fccb789424fc | 86 | } |
jksoft | 0:fccb789424fc | 87 | /* end marker */ |
jksoft | 0:fccb789424fc | 88 | *((void **)blk) = 0; |
jksoft | 0:fccb789424fc | 89 | return (0); |
jksoft | 0:fccb789424fc | 90 | } |
jksoft | 0:fccb789424fc | 91 | |
jksoft | 0:fccb789424fc | 92 | /*--------------------------- rt_alloc_box ----------------------------------*/ |
jksoft | 0:fccb789424fc | 93 | |
jksoft | 0:fccb789424fc | 94 | void *rt_alloc_box (void *box_mem) { |
jksoft | 0:fccb789424fc | 95 | /* Allocate a memory block and return start address. */ |
jksoft | 0:fccb789424fc | 96 | void **free; |
jksoft | 0:fccb789424fc | 97 | #ifndef __USE_EXCLUSIVE_ACCESS |
jksoft | 0:fccb789424fc | 98 | int irq_dis; |
jksoft | 0:fccb789424fc | 99 | |
jksoft | 0:fccb789424fc | 100 | irq_dis = __disable_irq (); |
jksoft | 0:fccb789424fc | 101 | free = ((P_BM) box_mem)->free; |
jksoft | 0:fccb789424fc | 102 | if (free) { |
jksoft | 0:fccb789424fc | 103 | ((P_BM) box_mem)->free = *free; |
jksoft | 0:fccb789424fc | 104 | } |
jksoft | 0:fccb789424fc | 105 | if (!irq_dis) __enable_irq (); |
jksoft | 0:fccb789424fc | 106 | #else |
jksoft | 0:fccb789424fc | 107 | do { |
jksoft | 0:fccb789424fc | 108 | if ((free = (void **)__ldrex(&((P_BM) box_mem)->free)) == 0) { |
jksoft | 0:fccb789424fc | 109 | __clrex(); |
jksoft | 0:fccb789424fc | 110 | break; |
jksoft | 0:fccb789424fc | 111 | } |
jksoft | 0:fccb789424fc | 112 | } while (__strex((U32)*free, &((P_BM) box_mem)->free)); |
jksoft | 0:fccb789424fc | 113 | #endif |
jksoft | 0:fccb789424fc | 114 | return (free); |
jksoft | 0:fccb789424fc | 115 | } |
jksoft | 0:fccb789424fc | 116 | |
jksoft | 0:fccb789424fc | 117 | |
jksoft | 0:fccb789424fc | 118 | /*--------------------------- _calloc_box -----------------------------------*/ |
jksoft | 0:fccb789424fc | 119 | |
jksoft | 0:fccb789424fc | 120 | void *_calloc_box (void *box_mem) { |
jksoft | 0:fccb789424fc | 121 | /* Allocate a 0-initialized memory block and return start address. */ |
jksoft | 0:fccb789424fc | 122 | void *free; |
jksoft | 0:fccb789424fc | 123 | U32 *p; |
jksoft | 0:fccb789424fc | 124 | U32 i; |
jksoft | 0:fccb789424fc | 125 | |
jksoft | 0:fccb789424fc | 126 | free = _alloc_box (box_mem); |
jksoft | 0:fccb789424fc | 127 | if (free) { |
jksoft | 0:fccb789424fc | 128 | p = free; |
jksoft | 0:fccb789424fc | 129 | for (i = ((P_BM) box_mem)->blk_size; i; i -= 4) { |
jksoft | 0:fccb789424fc | 130 | *p = 0; |
jksoft | 0:fccb789424fc | 131 | p++; |
jksoft | 0:fccb789424fc | 132 | } |
jksoft | 0:fccb789424fc | 133 | } |
jksoft | 0:fccb789424fc | 134 | return (free); |
jksoft | 0:fccb789424fc | 135 | } |
jksoft | 0:fccb789424fc | 136 | |
jksoft | 0:fccb789424fc | 137 | |
jksoft | 0:fccb789424fc | 138 | /*--------------------------- rt_free_box -----------------------------------*/ |
jksoft | 0:fccb789424fc | 139 | |
jksoft | 0:fccb789424fc | 140 | int rt_free_box (void *box_mem, void *box) { |
jksoft | 0:fccb789424fc | 141 | /* Free a memory block, returns 0 if OK, 1 if box does not belong to box_mem */ |
jksoft | 0:fccb789424fc | 142 | #ifndef __USE_EXCLUSIVE_ACCESS |
jksoft | 0:fccb789424fc | 143 | int irq_dis; |
jksoft | 0:fccb789424fc | 144 | #endif |
jksoft | 0:fccb789424fc | 145 | |
jksoft | 0:fccb789424fc | 146 | if (box < box_mem || box >= ((P_BM) box_mem)->end) { |
jksoft | 0:fccb789424fc | 147 | return (1); |
jksoft | 0:fccb789424fc | 148 | } |
jksoft | 0:fccb789424fc | 149 | |
jksoft | 0:fccb789424fc | 150 | #ifndef __USE_EXCLUSIVE_ACCESS |
jksoft | 0:fccb789424fc | 151 | irq_dis = __disable_irq (); |
jksoft | 0:fccb789424fc | 152 | *((void **)box) = ((P_BM) box_mem)->free; |
jksoft | 0:fccb789424fc | 153 | ((P_BM) box_mem)->free = box; |
jksoft | 0:fccb789424fc | 154 | if (!irq_dis) __enable_irq (); |
jksoft | 0:fccb789424fc | 155 | #else |
jksoft | 0:fccb789424fc | 156 | do { |
jksoft | 0:fccb789424fc | 157 | *((void **)box) = (void *)__ldrex(&((P_BM) box_mem)->free); |
jksoft | 0:fccb789424fc | 158 | } while (__strex ((U32)box, &((P_BM) box_mem)->free)); |
jksoft | 0:fccb789424fc | 159 | #endif |
jksoft | 0:fccb789424fc | 160 | return (0); |
jksoft | 0:fccb789424fc | 161 | } |
jksoft | 0:fccb789424fc | 162 | |
jksoft | 0:fccb789424fc | 163 | /*---------------------------------------------------------------------------- |
jksoft | 0:fccb789424fc | 164 | * end of file |
jksoft | 0:fccb789424fc | 165 | *---------------------------------------------------------------------------*/ |
jksoft | 0:fccb789424fc | 166 |