Fork of gr-peach-opencv-project by
features/filesystem/bd/ChainingBlockDevice.h@166:3a9487d57a5c, 2017-06-29 (annotated)
- Committer:
- thedo
- Date:
- Thu Jun 29 11:00:41 2017 +0000
- Revision:
- 166:3a9487d57a5c
This is Opencv 3.1 project on GR-PEACH board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thedo | 166:3a9487d57a5c | 1 | /* mbed Microcontroller Library |
thedo | 166:3a9487d57a5c | 2 | * Copyright (c) 2017 ARM Limited |
thedo | 166:3a9487d57a5c | 3 | * |
thedo | 166:3a9487d57a5c | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
thedo | 166:3a9487d57a5c | 5 | * of this software and associated documentation files (the "Software"), to deal |
thedo | 166:3a9487d57a5c | 6 | * in the Software without restriction, including without limitation the rights |
thedo | 166:3a9487d57a5c | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
thedo | 166:3a9487d57a5c | 8 | * copies of the Software, and to permit persons to whom the Software is |
thedo | 166:3a9487d57a5c | 9 | * furnished to do so, subject to the following conditions: |
thedo | 166:3a9487d57a5c | 10 | * |
thedo | 166:3a9487d57a5c | 11 | * The above copyright notice and this permission notice shall be included in |
thedo | 166:3a9487d57a5c | 12 | * all copies or substantial portions of the Software. |
thedo | 166:3a9487d57a5c | 13 | * |
thedo | 166:3a9487d57a5c | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
thedo | 166:3a9487d57a5c | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
thedo | 166:3a9487d57a5c | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
thedo | 166:3a9487d57a5c | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
thedo | 166:3a9487d57a5c | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
thedo | 166:3a9487d57a5c | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
thedo | 166:3a9487d57a5c | 20 | * SOFTWARE. |
thedo | 166:3a9487d57a5c | 21 | */ |
thedo | 166:3a9487d57a5c | 22 | #ifndef MBED_CHAINING_BLOCK_DEVICE_H |
thedo | 166:3a9487d57a5c | 23 | #define MBED_CHAINING_BLOCK_DEVICE_H |
thedo | 166:3a9487d57a5c | 24 | |
thedo | 166:3a9487d57a5c | 25 | #include "BlockDevice.h" |
thedo | 166:3a9487d57a5c | 26 | #include "mbed.h" |
thedo | 166:3a9487d57a5c | 27 | |
thedo | 166:3a9487d57a5c | 28 | |
thedo | 166:3a9487d57a5c | 29 | /** Block device for chaining multiple block devices |
thedo | 166:3a9487d57a5c | 30 | * with the similar block sizes at sequential addresses |
thedo | 166:3a9487d57a5c | 31 | * |
thedo | 166:3a9487d57a5c | 32 | * @code |
thedo | 166:3a9487d57a5c | 33 | * #include "mbed.h" |
thedo | 166:3a9487d57a5c | 34 | * #include "HeapBlockDevice.h" |
thedo | 166:3a9487d57a5c | 35 | * #include "ChainingBlockDevice.h" |
thedo | 166:3a9487d57a5c | 36 | * |
thedo | 166:3a9487d57a5c | 37 | * // Create two smaller block devices with |
thedo | 166:3a9487d57a5c | 38 | * // 64 and 32 blocks of size 512 bytes |
thedo | 166:3a9487d57a5c | 39 | * HeapBlockDevice mem1(64*512, 512); |
thedo | 166:3a9487d57a5c | 40 | * HeapBlockDevice mem2(32*512, 512); |
thedo | 166:3a9487d57a5c | 41 | * |
thedo | 166:3a9487d57a5c | 42 | * // Create a block device backed by mem1 and mem2 |
thedo | 166:3a9487d57a5c | 43 | * // contains 96 blocks of size 512 bytes |
thedo | 166:3a9487d57a5c | 44 | * BlockDevice *bds[] = {&mem1, &mem2}; |
thedo | 166:3a9487d57a5c | 45 | * ChainingBlockDevice chainmem(bds); |
thedo | 166:3a9487d57a5c | 46 | */ |
thedo | 166:3a9487d57a5c | 47 | class ChainingBlockDevice : public BlockDevice |
thedo | 166:3a9487d57a5c | 48 | { |
thedo | 166:3a9487d57a5c | 49 | public: |
thedo | 166:3a9487d57a5c | 50 | /** Lifetime of the memory block device |
thedo | 166:3a9487d57a5c | 51 | * |
thedo | 166:3a9487d57a5c | 52 | * @param bds Array of block devices to chain with sequential block addresses |
thedo | 166:3a9487d57a5c | 53 | * @param count Number of block devices to chain |
thedo | 166:3a9487d57a5c | 54 | * @note All block devices must have the same block size |
thedo | 166:3a9487d57a5c | 55 | */ |
thedo | 166:3a9487d57a5c | 56 | ChainingBlockDevice(BlockDevice **bds, size_t bd_count); |
thedo | 166:3a9487d57a5c | 57 | |
thedo | 166:3a9487d57a5c | 58 | /** Lifetime of the memory block device |
thedo | 166:3a9487d57a5c | 59 | * |
thedo | 166:3a9487d57a5c | 60 | * @param bds Array of block devices to chain with sequential block addresses |
thedo | 166:3a9487d57a5c | 61 | * @note All block devices must have the same block size |
thedo | 166:3a9487d57a5c | 62 | */ |
thedo | 166:3a9487d57a5c | 63 | template <size_t Size> |
thedo | 166:3a9487d57a5c | 64 | ChainingBlockDevice(BlockDevice *(&bds)[Size]) |
thedo | 166:3a9487d57a5c | 65 | : _bds(bds), _bd_count(sizeof(bds) / sizeof(bds[0])) |
thedo | 166:3a9487d57a5c | 66 | , _read_size(0), _program_size(0), _erase_size(0), _size(0) |
thedo | 166:3a9487d57a5c | 67 | { |
thedo | 166:3a9487d57a5c | 68 | } |
thedo | 166:3a9487d57a5c | 69 | |
thedo | 166:3a9487d57a5c | 70 | /** Lifetime of the memory block device |
thedo | 166:3a9487d57a5c | 71 | * |
thedo | 166:3a9487d57a5c | 72 | * @param bds Array of block devices to chain with sequential block addresses |
thedo | 166:3a9487d57a5c | 73 | * @note All block devices must have the same block size |
thedo | 166:3a9487d57a5c | 74 | */ |
thedo | 166:3a9487d57a5c | 75 | virtual ~ChainingBlockDevice() {} |
thedo | 166:3a9487d57a5c | 76 | |
thedo | 166:3a9487d57a5c | 77 | /** Initialize a block device |
thedo | 166:3a9487d57a5c | 78 | * |
thedo | 166:3a9487d57a5c | 79 | * @return 0 on success or a negative error code on failure |
thedo | 166:3a9487d57a5c | 80 | */ |
thedo | 166:3a9487d57a5c | 81 | virtual int init(); |
thedo | 166:3a9487d57a5c | 82 | |
thedo | 166:3a9487d57a5c | 83 | /** Deinitialize a block device |
thedo | 166:3a9487d57a5c | 84 | * |
thedo | 166:3a9487d57a5c | 85 | * @return 0 on success or a negative error code on failure |
thedo | 166:3a9487d57a5c | 86 | */ |
thedo | 166:3a9487d57a5c | 87 | virtual int deinit(); |
thedo | 166:3a9487d57a5c | 88 | |
thedo | 166:3a9487d57a5c | 89 | /** Read blocks from a block device |
thedo | 166:3a9487d57a5c | 90 | * |
thedo | 166:3a9487d57a5c | 91 | * @param buffer Buffer to write blocks to |
thedo | 166:3a9487d57a5c | 92 | * @param addr Address of block to begin reading from |
thedo | 166:3a9487d57a5c | 93 | * @param size Size to read in bytes, must be a multiple of read block size |
thedo | 166:3a9487d57a5c | 94 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 95 | */ |
thedo | 166:3a9487d57a5c | 96 | virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 97 | |
thedo | 166:3a9487d57a5c | 98 | /** Program blocks to a block device |
thedo | 166:3a9487d57a5c | 99 | * |
thedo | 166:3a9487d57a5c | 100 | * The blocks must have been erased prior to being programmed |
thedo | 166:3a9487d57a5c | 101 | * |
thedo | 166:3a9487d57a5c | 102 | * @param buffer Buffer of data to write to blocks |
thedo | 166:3a9487d57a5c | 103 | * @param addr Address of block to begin writing to |
thedo | 166:3a9487d57a5c | 104 | * @param size Size to write in bytes, must be a multiple of program block size |
thedo | 166:3a9487d57a5c | 105 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 106 | */ |
thedo | 166:3a9487d57a5c | 107 | virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 108 | |
thedo | 166:3a9487d57a5c | 109 | /** Erase blocks on a block device |
thedo | 166:3a9487d57a5c | 110 | * |
thedo | 166:3a9487d57a5c | 111 | * The state of an erased block is undefined until it has been programmed |
thedo | 166:3a9487d57a5c | 112 | * |
thedo | 166:3a9487d57a5c | 113 | * @param addr Address of block to begin erasing |
thedo | 166:3a9487d57a5c | 114 | * @param size Size to erase in bytes, must be a multiple of erase block size |
thedo | 166:3a9487d57a5c | 115 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 116 | */ |
thedo | 166:3a9487d57a5c | 117 | virtual int erase(bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 118 | |
thedo | 166:3a9487d57a5c | 119 | /** Get the size of a readable block |
thedo | 166:3a9487d57a5c | 120 | * |
thedo | 166:3a9487d57a5c | 121 | * @return Size of a readable block in bytes |
thedo | 166:3a9487d57a5c | 122 | */ |
thedo | 166:3a9487d57a5c | 123 | virtual bd_size_t get_read_size() const; |
thedo | 166:3a9487d57a5c | 124 | |
thedo | 166:3a9487d57a5c | 125 | /** Get the size of a programable block |
thedo | 166:3a9487d57a5c | 126 | * |
thedo | 166:3a9487d57a5c | 127 | * @return Size of a programable block in bytes |
thedo | 166:3a9487d57a5c | 128 | * @note Must be a multiple of the read size |
thedo | 166:3a9487d57a5c | 129 | */ |
thedo | 166:3a9487d57a5c | 130 | virtual bd_size_t get_program_size() const; |
thedo | 166:3a9487d57a5c | 131 | |
thedo | 166:3a9487d57a5c | 132 | /** Get the size of a eraseable block |
thedo | 166:3a9487d57a5c | 133 | * |
thedo | 166:3a9487d57a5c | 134 | * @return Size of a eraseable block in bytes |
thedo | 166:3a9487d57a5c | 135 | * @note Must be a multiple of the program size |
thedo | 166:3a9487d57a5c | 136 | */ |
thedo | 166:3a9487d57a5c | 137 | virtual bd_size_t get_erase_size() const; |
thedo | 166:3a9487d57a5c | 138 | |
thedo | 166:3a9487d57a5c | 139 | /** Get the total size of the underlying device |
thedo | 166:3a9487d57a5c | 140 | * |
thedo | 166:3a9487d57a5c | 141 | * @return Size of the underlying device in bytes |
thedo | 166:3a9487d57a5c | 142 | */ |
thedo | 166:3a9487d57a5c | 143 | virtual bd_size_t size() const; |
thedo | 166:3a9487d57a5c | 144 | |
thedo | 166:3a9487d57a5c | 145 | protected: |
thedo | 166:3a9487d57a5c | 146 | BlockDevice **_bds; |
thedo | 166:3a9487d57a5c | 147 | size_t _bd_count; |
thedo | 166:3a9487d57a5c | 148 | bd_size_t _read_size; |
thedo | 166:3a9487d57a5c | 149 | bd_size_t _program_size; |
thedo | 166:3a9487d57a5c | 150 | bd_size_t _erase_size; |
thedo | 166:3a9487d57a5c | 151 | bd_size_t _size; |
thedo | 166:3a9487d57a5c | 152 | }; |
thedo | 166:3a9487d57a5c | 153 | |
thedo | 166:3a9487d57a5c | 154 | |
thedo | 166:3a9487d57a5c | 155 | #endif |
thedo | 166:3a9487d57a5c | 156 |