Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
features/filesystem/bd/SlicingBlockDevice.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_SLICING_BLOCK_DEVICE_H |
thedo | 166:3a9487d57a5c | 23 | #define MBED_SLICING_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 mapping to a slice of another block device |
thedo | 166:3a9487d57a5c | 30 | * |
thedo | 166:3a9487d57a5c | 31 | * @code |
thedo | 166:3a9487d57a5c | 32 | * #include "mbed.h" |
thedo | 166:3a9487d57a5c | 33 | * #include "HeapBlockDevice.h" |
thedo | 166:3a9487d57a5c | 34 | * #include "SlicingBlockDevice.h" |
thedo | 166:3a9487d57a5c | 35 | * |
thedo | 166:3a9487d57a5c | 36 | * // Create a block device with 64 blocks of size 512 |
thedo | 166:3a9487d57a5c | 37 | * HeapBlockDevice mem(64*512, 512); |
thedo | 166:3a9487d57a5c | 38 | * |
thedo | 166:3a9487d57a5c | 39 | * // Create a block device that maps to the first 32 blocks |
thedo | 166:3a9487d57a5c | 40 | * SlicingBlockDevice slice1(&mem, 0*512, 32*512); |
thedo | 166:3a9487d57a5c | 41 | * |
thedo | 166:3a9487d57a5c | 42 | * // Create a block device that maps to the last 32 blocks |
thedo | 166:3a9487d57a5c | 43 | * SlicingBlockDevice slice2(&mem, 32*512); |
thedo | 166:3a9487d57a5c | 44 | * |
thedo | 166:3a9487d57a5c | 45 | * // Create a block device that maps to the middle 32 blocks |
thedo | 166:3a9487d57a5c | 46 | * SlicingBlockDevice slice3(&mem, 16*512, -16*512); |
thedo | 166:3a9487d57a5c | 47 | */ |
thedo | 166:3a9487d57a5c | 48 | class SlicingBlockDevice : public BlockDevice |
thedo | 166:3a9487d57a5c | 49 | { |
thedo | 166:3a9487d57a5c | 50 | public: |
thedo | 166:3a9487d57a5c | 51 | /** Lifetime of the memory block device |
thedo | 166:3a9487d57a5c | 52 | * |
thedo | 166:3a9487d57a5c | 53 | * @param bd Block device to back the SlicingBlockDevice |
thedo | 166:3a9487d57a5c | 54 | * @param start Start block address to map to block 0, negative addresses |
thedo | 166:3a9487d57a5c | 55 | * are calculated from the end of the underlying block device |
thedo | 166:3a9487d57a5c | 56 | * @note This is the same as SlicingBlockDevice(bd, start, bd->size()) |
thedo | 166:3a9487d57a5c | 57 | */ |
thedo | 166:3a9487d57a5c | 58 | SlicingBlockDevice(BlockDevice *bd, bd_addr_t start); |
thedo | 166:3a9487d57a5c | 59 | |
thedo | 166:3a9487d57a5c | 60 | /** Lifetime of the memory block device |
thedo | 166:3a9487d57a5c | 61 | * |
thedo | 166:3a9487d57a5c | 62 | * @param bd Block device to back the SlicingBlockDevice |
thedo | 166:3a9487d57a5c | 63 | * @param start Start block address to map to block 0, negative addresses |
thedo | 166:3a9487d57a5c | 64 | * are calculated from the end of the underlying block device |
thedo | 166:3a9487d57a5c | 65 | * @param stop End block address to mark the end of the block device, |
thedo | 166:3a9487d57a5c | 66 | * this block is not mapped, negative addresses are |
thedo | 166:3a9487d57a5c | 67 | * calculated from the end of the underlying block device |
thedo | 166:3a9487d57a5c | 68 | */ |
thedo | 166:3a9487d57a5c | 69 | SlicingBlockDevice(BlockDevice *bd, bd_addr_t start, bd_addr_t end); |
thedo | 166:3a9487d57a5c | 70 | |
thedo | 166:3a9487d57a5c | 71 | /** Lifetime of a block device |
thedo | 166:3a9487d57a5c | 72 | */ |
thedo | 166:3a9487d57a5c | 73 | virtual ~SlicingBlockDevice() {}; |
thedo | 166:3a9487d57a5c | 74 | |
thedo | 166:3a9487d57a5c | 75 | /** Initialize a block device |
thedo | 166:3a9487d57a5c | 76 | * |
thedo | 166:3a9487d57a5c | 77 | * @return 0 on success or a negative error code on failure |
thedo | 166:3a9487d57a5c | 78 | */ |
thedo | 166:3a9487d57a5c | 79 | virtual int init(); |
thedo | 166:3a9487d57a5c | 80 | |
thedo | 166:3a9487d57a5c | 81 | /** Deinitialize a block device |
thedo | 166:3a9487d57a5c | 82 | * |
thedo | 166:3a9487d57a5c | 83 | * @return 0 on success or a negative error code on failure |
thedo | 166:3a9487d57a5c | 84 | */ |
thedo | 166:3a9487d57a5c | 85 | virtual int deinit(); |
thedo | 166:3a9487d57a5c | 86 | |
thedo | 166:3a9487d57a5c | 87 | /** Read blocks from a block device |
thedo | 166:3a9487d57a5c | 88 | * |
thedo | 166:3a9487d57a5c | 89 | * @param buffer Buffer to read blocks into |
thedo | 166:3a9487d57a5c | 90 | * @param addr Address of block to begin reading from |
thedo | 166:3a9487d57a5c | 91 | * @param size Size to read in bytes, must be a multiple of read block size |
thedo | 166:3a9487d57a5c | 92 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 93 | */ |
thedo | 166:3a9487d57a5c | 94 | virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 95 | |
thedo | 166:3a9487d57a5c | 96 | /** Program blocks to a block device |
thedo | 166:3a9487d57a5c | 97 | * |
thedo | 166:3a9487d57a5c | 98 | * The blocks must have been erased prior to being programmed |
thedo | 166:3a9487d57a5c | 99 | * |
thedo | 166:3a9487d57a5c | 100 | * @param buffer Buffer of data to write to blocks |
thedo | 166:3a9487d57a5c | 101 | * @param addr Address of block to begin writing to |
thedo | 166:3a9487d57a5c | 102 | * @param size Size to write in bytes, must be a multiple of program block size |
thedo | 166:3a9487d57a5c | 103 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 104 | */ |
thedo | 166:3a9487d57a5c | 105 | virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 106 | |
thedo | 166:3a9487d57a5c | 107 | /** Erase blocks on a block device |
thedo | 166:3a9487d57a5c | 108 | * |
thedo | 166:3a9487d57a5c | 109 | * The state of an erased block is undefined until it has been programmed |
thedo | 166:3a9487d57a5c | 110 | * |
thedo | 166:3a9487d57a5c | 111 | * @param addr Address of block to begin erasing |
thedo | 166:3a9487d57a5c | 112 | * @param size Size to erase in bytes, must be a multiple of erase block size |
thedo | 166:3a9487d57a5c | 113 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 114 | */ |
thedo | 166:3a9487d57a5c | 115 | virtual int erase(bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 116 | |
thedo | 166:3a9487d57a5c | 117 | /** Get the size of a readable block |
thedo | 166:3a9487d57a5c | 118 | * |
thedo | 166:3a9487d57a5c | 119 | * @return Size of a readable block in bytes |
thedo | 166:3a9487d57a5c | 120 | */ |
thedo | 166:3a9487d57a5c | 121 | virtual bd_size_t get_read_size() const; |
thedo | 166:3a9487d57a5c | 122 | |
thedo | 166:3a9487d57a5c | 123 | /** Get the size of a programable block |
thedo | 166:3a9487d57a5c | 124 | * |
thedo | 166:3a9487d57a5c | 125 | * @return Size of a programable block in bytes |
thedo | 166:3a9487d57a5c | 126 | * @note Must be a multiple of the read size |
thedo | 166:3a9487d57a5c | 127 | */ |
thedo | 166:3a9487d57a5c | 128 | virtual bd_size_t get_program_size() const; |
thedo | 166:3a9487d57a5c | 129 | |
thedo | 166:3a9487d57a5c | 130 | /** Get the size of a eraseable block |
thedo | 166:3a9487d57a5c | 131 | * |
thedo | 166:3a9487d57a5c | 132 | * @return Size of a eraseable block in bytes |
thedo | 166:3a9487d57a5c | 133 | * @note Must be a multiple of the program size |
thedo | 166:3a9487d57a5c | 134 | */ |
thedo | 166:3a9487d57a5c | 135 | virtual bd_size_t get_erase_size() const; |
thedo | 166:3a9487d57a5c | 136 | |
thedo | 166:3a9487d57a5c | 137 | /** Get the total size of the underlying device |
thedo | 166:3a9487d57a5c | 138 | * |
thedo | 166:3a9487d57a5c | 139 | * @return Size of the underlying device in bytes |
thedo | 166:3a9487d57a5c | 140 | */ |
thedo | 166:3a9487d57a5c | 141 | virtual bd_size_t size() const; |
thedo | 166:3a9487d57a5c | 142 | |
thedo | 166:3a9487d57a5c | 143 | protected: |
thedo | 166:3a9487d57a5c | 144 | BlockDevice *_bd; |
thedo | 166:3a9487d57a5c | 145 | bool _start_from_end; |
thedo | 166:3a9487d57a5c | 146 | bd_size_t _start; |
thedo | 166:3a9487d57a5c | 147 | bool _stop_from_end; |
thedo | 166:3a9487d57a5c | 148 | bd_size_t _stop; |
thedo | 166:3a9487d57a5c | 149 | }; |
thedo | 166:3a9487d57a5c | 150 | |
thedo | 166:3a9487d57a5c | 151 | |
thedo | 166:3a9487d57a5c | 152 | #endif |
thedo | 166:3a9487d57a5c | 153 |