Rtos code cntains bug possible incompatability with I2C
Fork of mbed-rtos by
rtx/TARGET_CORTEX_A/rt_MemBox.c@49:77c8e4604045, 2014-11-06 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Nov 06 13:00:11 2014 +0000
- Revision:
- 49:77c8e4604045
- Parent:
- rtx_ca/rt_MemBox.c@48:e9a2c7cb57a4
- Child:
- 68:d3d0e710b443
Synchronized with git revision 7b90c2ba137baaf9769219e0e8a7b8e8d1299c4f
Full URL: https://github.com/mbedmicro/mbed/commit/7b90c2ba137baaf9769219e0e8a7b8e8d1299c4f/
This target is not yet tested, so it can't be released as part of the official
SDK build for now.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 48:e9a2c7cb57a4 | 1 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 2 | * RL-ARM - RTX |
mbed_official | 48:e9a2c7cb57a4 | 3 | *---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 4 | * Name: RT_MEMBOX.C |
mbed_official | 48:e9a2c7cb57a4 | 5 | * Purpose: Interface functions for fixed memory block management system |
mbed_official | 48:e9a2c7cb57a4 | 6 | * Rev.: V4.60 |
mbed_official | 48:e9a2c7cb57a4 | 7 | *---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 8 | * |
mbed_official | 48:e9a2c7cb57a4 | 9 | * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH |
mbed_official | 48:e9a2c7cb57a4 | 10 | * All rights reserved. |
mbed_official | 48:e9a2c7cb57a4 | 11 | * Redistribution and use in source and binary forms, with or without |
mbed_official | 48:e9a2c7cb57a4 | 12 | * modification, are permitted provided that the following conditions are met: |
mbed_official | 48:e9a2c7cb57a4 | 13 | * - Redistributions of source code must retain the above copyright |
mbed_official | 48:e9a2c7cb57a4 | 14 | * notice, this list of conditions and the following disclaimer. |
mbed_official | 48:e9a2c7cb57a4 | 15 | * - Redistributions in binary form must reproduce the above copyright |
mbed_official | 48:e9a2c7cb57a4 | 16 | * notice, this list of conditions and the following disclaimer in the |
mbed_official | 48:e9a2c7cb57a4 | 17 | * documentation and/or other materials provided with the distribution. |
mbed_official | 48:e9a2c7cb57a4 | 18 | * - Neither the name of ARM nor the names of its contributors may be used |
mbed_official | 48:e9a2c7cb57a4 | 19 | * to endorse or promote products derived from this software without |
mbed_official | 48:e9a2c7cb57a4 | 20 | * specific prior written permission. |
mbed_official | 48:e9a2c7cb57a4 | 21 | * |
mbed_official | 48:e9a2c7cb57a4 | 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 48:e9a2c7cb57a4 | 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 48:e9a2c7cb57a4 | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
mbed_official | 48:e9a2c7cb57a4 | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
mbed_official | 48:e9a2c7cb57a4 | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
mbed_official | 48:e9a2c7cb57a4 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
mbed_official | 48:e9a2c7cb57a4 | 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
mbed_official | 48:e9a2c7cb57a4 | 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
mbed_official | 48:e9a2c7cb57a4 | 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
mbed_official | 48:e9a2c7cb57a4 | 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
mbed_official | 48:e9a2c7cb57a4 | 32 | * POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 48:e9a2c7cb57a4 | 33 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 34 | |
mbed_official | 48:e9a2c7cb57a4 | 35 | #include "rt_TypeDef.h" |
mbed_official | 48:e9a2c7cb57a4 | 36 | #include "RTX_Config.h" |
mbed_official | 48:e9a2c7cb57a4 | 37 | #include "rt_System.h" |
mbed_official | 48:e9a2c7cb57a4 | 38 | #include "rt_MemBox.h" |
mbed_official | 48:e9a2c7cb57a4 | 39 | #ifdef __CORTEX_A9 |
mbed_official | 48:e9a2c7cb57a4 | 40 | #include "rt_HAL_CA.h" |
mbed_official | 48:e9a2c7cb57a4 | 41 | #else |
mbed_official | 48:e9a2c7cb57a4 | 42 | #include "rt_HAL_CM.h" |
mbed_official | 48:e9a2c7cb57a4 | 43 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 44 | |
mbed_official | 48:e9a2c7cb57a4 | 45 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 46 | * Global Functions |
mbed_official | 48:e9a2c7cb57a4 | 47 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 48 | |
mbed_official | 48:e9a2c7cb57a4 | 49 | |
mbed_official | 48:e9a2c7cb57a4 | 50 | /*--------------------------- _init_box -------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 51 | |
mbed_official | 48:e9a2c7cb57a4 | 52 | int _init_box (void *box_mem, U32 box_size, U32 blk_size) { |
mbed_official | 48:e9a2c7cb57a4 | 53 | /* Initialize memory block system, returns 0 if OK, 1 if fails. */ |
mbed_official | 48:e9a2c7cb57a4 | 54 | void *end; |
mbed_official | 48:e9a2c7cb57a4 | 55 | void *blk; |
mbed_official | 48:e9a2c7cb57a4 | 56 | void *next; |
mbed_official | 48:e9a2c7cb57a4 | 57 | U32 sizeof_bm; |
mbed_official | 48:e9a2c7cb57a4 | 58 | |
mbed_official | 48:e9a2c7cb57a4 | 59 | /* Create memory structure. */ |
mbed_official | 48:e9a2c7cb57a4 | 60 | if (blk_size & BOX_ALIGN_8) { |
mbed_official | 48:e9a2c7cb57a4 | 61 | /* Memory blocks 8-byte aligned. */ |
mbed_official | 48:e9a2c7cb57a4 | 62 | blk_size = ((blk_size & ~BOX_ALIGN_8) + 7) & ~7; |
mbed_official | 48:e9a2c7cb57a4 | 63 | sizeof_bm = (sizeof (struct OS_BM) + 7) & ~7; |
mbed_official | 48:e9a2c7cb57a4 | 64 | } |
mbed_official | 48:e9a2c7cb57a4 | 65 | else { |
mbed_official | 48:e9a2c7cb57a4 | 66 | /* Memory blocks 4-byte aligned. */ |
mbed_official | 48:e9a2c7cb57a4 | 67 | blk_size = (blk_size + 3) & ~3; |
mbed_official | 48:e9a2c7cb57a4 | 68 | sizeof_bm = sizeof (struct OS_BM); |
mbed_official | 48:e9a2c7cb57a4 | 69 | } |
mbed_official | 48:e9a2c7cb57a4 | 70 | if (blk_size == 0) { |
mbed_official | 48:e9a2c7cb57a4 | 71 | return (1); |
mbed_official | 48:e9a2c7cb57a4 | 72 | } |
mbed_official | 48:e9a2c7cb57a4 | 73 | if ((blk_size + sizeof_bm) > box_size) { |
mbed_official | 48:e9a2c7cb57a4 | 74 | return (1); |
mbed_official | 48:e9a2c7cb57a4 | 75 | } |
mbed_official | 48:e9a2c7cb57a4 | 76 | /* Create a Memory structure. */ |
mbed_official | 48:e9a2c7cb57a4 | 77 | blk = ((U8 *) box_mem) + sizeof_bm; |
mbed_official | 48:e9a2c7cb57a4 | 78 | ((P_BM) box_mem)->free = blk; |
mbed_official | 48:e9a2c7cb57a4 | 79 | end = ((U8 *) box_mem) + box_size; |
mbed_official | 48:e9a2c7cb57a4 | 80 | ((P_BM) box_mem)->end = end; |
mbed_official | 48:e9a2c7cb57a4 | 81 | ((P_BM) box_mem)->blk_size = blk_size; |
mbed_official | 48:e9a2c7cb57a4 | 82 | |
mbed_official | 48:e9a2c7cb57a4 | 83 | /* Link all free blocks using offsets. */ |
mbed_official | 48:e9a2c7cb57a4 | 84 | end = ((U8 *) end) - blk_size; |
mbed_official | 48:e9a2c7cb57a4 | 85 | while (1) { |
mbed_official | 48:e9a2c7cb57a4 | 86 | next = ((U8 *) blk) + blk_size; |
mbed_official | 48:e9a2c7cb57a4 | 87 | if (next > end) break; |
mbed_official | 48:e9a2c7cb57a4 | 88 | *((void **)blk) = next; |
mbed_official | 48:e9a2c7cb57a4 | 89 | blk = next; |
mbed_official | 48:e9a2c7cb57a4 | 90 | } |
mbed_official | 48:e9a2c7cb57a4 | 91 | /* end marker */ |
mbed_official | 48:e9a2c7cb57a4 | 92 | *((void **)blk) = 0; |
mbed_official | 48:e9a2c7cb57a4 | 93 | return (0); |
mbed_official | 48:e9a2c7cb57a4 | 94 | } |
mbed_official | 48:e9a2c7cb57a4 | 95 | |
mbed_official | 48:e9a2c7cb57a4 | 96 | /*--------------------------- rt_alloc_box ----------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 97 | |
mbed_official | 48:e9a2c7cb57a4 | 98 | void *rt_alloc_box (void *box_mem) { |
mbed_official | 48:e9a2c7cb57a4 | 99 | /* Allocate a memory block and return start address. */ |
mbed_official | 48:e9a2c7cb57a4 | 100 | void **free; |
mbed_official | 48:e9a2c7cb57a4 | 101 | #ifndef __USE_EXCLUSIVE_ACCESS |
mbed_official | 48:e9a2c7cb57a4 | 102 | int irq_dis; |
mbed_official | 48:e9a2c7cb57a4 | 103 | |
mbed_official | 48:e9a2c7cb57a4 | 104 | irq_dis = __disable_irq (); |
mbed_official | 48:e9a2c7cb57a4 | 105 | free = ((P_BM) box_mem)->free; |
mbed_official | 48:e9a2c7cb57a4 | 106 | if (free) { |
mbed_official | 48:e9a2c7cb57a4 | 107 | ((P_BM) box_mem)->free = *free; |
mbed_official | 48:e9a2c7cb57a4 | 108 | } |
mbed_official | 48:e9a2c7cb57a4 | 109 | if (!irq_dis) __enable_irq (); |
mbed_official | 48:e9a2c7cb57a4 | 110 | #else |
mbed_official | 48:e9a2c7cb57a4 | 111 | do { |
mbed_official | 48:e9a2c7cb57a4 | 112 | if ((free = (void **)__ldrex(&((P_BM) box_mem)->free)) == 0) { |
mbed_official | 48:e9a2c7cb57a4 | 113 | __clrex(); |
mbed_official | 48:e9a2c7cb57a4 | 114 | break; |
mbed_official | 48:e9a2c7cb57a4 | 115 | } |
mbed_official | 48:e9a2c7cb57a4 | 116 | } while (__strex((U32)*free, &((P_BM) box_mem)->free)); |
mbed_official | 48:e9a2c7cb57a4 | 117 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 118 | return (free); |
mbed_official | 48:e9a2c7cb57a4 | 119 | } |
mbed_official | 48:e9a2c7cb57a4 | 120 | |
mbed_official | 48:e9a2c7cb57a4 | 121 | |
mbed_official | 48:e9a2c7cb57a4 | 122 | /*--------------------------- _calloc_box -----------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 123 | |
mbed_official | 48:e9a2c7cb57a4 | 124 | void *_calloc_box (void *box_mem) { |
mbed_official | 48:e9a2c7cb57a4 | 125 | /* Allocate a 0-initialized memory block and return start address. */ |
mbed_official | 48:e9a2c7cb57a4 | 126 | void *free; |
mbed_official | 48:e9a2c7cb57a4 | 127 | U32 *p; |
mbed_official | 48:e9a2c7cb57a4 | 128 | U32 i; |
mbed_official | 48:e9a2c7cb57a4 | 129 | |
mbed_official | 48:e9a2c7cb57a4 | 130 | free = _alloc_box (box_mem); |
mbed_official | 48:e9a2c7cb57a4 | 131 | if (free) { |
mbed_official | 48:e9a2c7cb57a4 | 132 | p = free; |
mbed_official | 48:e9a2c7cb57a4 | 133 | for (i = ((P_BM) box_mem)->blk_size; i; i -= 4) { |
mbed_official | 48:e9a2c7cb57a4 | 134 | *p = 0; |
mbed_official | 48:e9a2c7cb57a4 | 135 | p++; |
mbed_official | 48:e9a2c7cb57a4 | 136 | } |
mbed_official | 48:e9a2c7cb57a4 | 137 | } |
mbed_official | 48:e9a2c7cb57a4 | 138 | return (free); |
mbed_official | 48:e9a2c7cb57a4 | 139 | } |
mbed_official | 48:e9a2c7cb57a4 | 140 | |
mbed_official | 48:e9a2c7cb57a4 | 141 | |
mbed_official | 48:e9a2c7cb57a4 | 142 | /*--------------------------- rt_free_box -----------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 143 | |
mbed_official | 48:e9a2c7cb57a4 | 144 | int rt_free_box (void *box_mem, void *box) { |
mbed_official | 48:e9a2c7cb57a4 | 145 | /* Free a memory block, returns 0 if OK, 1 if box does not belong to box_mem */ |
mbed_official | 48:e9a2c7cb57a4 | 146 | #ifndef __USE_EXCLUSIVE_ACCESS |
mbed_official | 48:e9a2c7cb57a4 | 147 | int irq_dis; |
mbed_official | 48:e9a2c7cb57a4 | 148 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 149 | |
mbed_official | 48:e9a2c7cb57a4 | 150 | if (box < box_mem || box >= ((P_BM) box_mem)->end) { |
mbed_official | 48:e9a2c7cb57a4 | 151 | return (1); |
mbed_official | 48:e9a2c7cb57a4 | 152 | } |
mbed_official | 48:e9a2c7cb57a4 | 153 | |
mbed_official | 48:e9a2c7cb57a4 | 154 | #ifndef __USE_EXCLUSIVE_ACCESS |
mbed_official | 48:e9a2c7cb57a4 | 155 | irq_dis = __disable_irq (); |
mbed_official | 48:e9a2c7cb57a4 | 156 | *((void **)box) = ((P_BM) box_mem)->free; |
mbed_official | 48:e9a2c7cb57a4 | 157 | ((P_BM) box_mem)->free = box; |
mbed_official | 48:e9a2c7cb57a4 | 158 | if (!irq_dis) __enable_irq (); |
mbed_official | 48:e9a2c7cb57a4 | 159 | #else |
mbed_official | 48:e9a2c7cb57a4 | 160 | do { |
mbed_official | 48:e9a2c7cb57a4 | 161 | *((void **)box) = (void *)__ldrex(&((P_BM) box_mem)->free); |
mbed_official | 48:e9a2c7cb57a4 | 162 | } while (__strex ((U32)box, &((P_BM) box_mem)->free)); |
mbed_official | 48:e9a2c7cb57a4 | 163 | #endif |
mbed_official | 48:e9a2c7cb57a4 | 164 | return (0); |
mbed_official | 48:e9a2c7cb57a4 | 165 | } |
mbed_official | 48:e9a2c7cb57a4 | 166 | |
mbed_official | 48:e9a2c7cb57a4 | 167 | /*---------------------------------------------------------------------------- |
mbed_official | 48:e9a2c7cb57a4 | 168 | * end of file |
mbed_official | 48:e9a2c7cb57a4 | 169 | *---------------------------------------------------------------------------*/ |
mbed_official | 48:e9a2c7cb57a4 | 170 |