Opencv 3.1 project on GR-PEACH board
Fork of gr-peach-opencv-project by
features/filesystem/bd/HeapBlockDevice.h@170:54ff26da7eb6, 2017-07-04 (annotated)
- Committer:
- thedo
- Date:
- Tue Jul 04 06:23:13 2017 +0000
- Revision:
- 170:54ff26da7eb6
- Parent:
- 166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.
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_MEM_BLOCK_DEVICE_H |
thedo | 166:3a9487d57a5c | 23 | #define MBED_MEM_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 | /** Lazily allocated heap-backed block device |
thedo | 166:3a9487d57a5c | 30 | * |
thedo | 166:3a9487d57a5c | 31 | * Useful for simulating a block device and tests |
thedo | 166:3a9487d57a5c | 32 | * |
thedo | 166:3a9487d57a5c | 33 | * @code |
thedo | 166:3a9487d57a5c | 34 | * #include "mbed.h" |
thedo | 166:3a9487d57a5c | 35 | * #include "HeapBlockDevice.h" |
thedo | 166:3a9487d57a5c | 36 | * |
thedo | 166:3a9487d57a5c | 37 | * HeapBlockDevice bd(2048, 512); // 2048 bytes with a block size of 512 bytes |
thedo | 166:3a9487d57a5c | 38 | * uint8_t block[512] = "Hello World!\n"; |
thedo | 166:3a9487d57a5c | 39 | * |
thedo | 166:3a9487d57a5c | 40 | * int main() { |
thedo | 166:3a9487d57a5c | 41 | * bd.init(); |
thedo | 166:3a9487d57a5c | 42 | * bd.program(block, 0); |
thedo | 166:3a9487d57a5c | 43 | * bd.read(block, 0); |
thedo | 166:3a9487d57a5c | 44 | * printf("%s", block); |
thedo | 166:3a9487d57a5c | 45 | * bd.deinit(); |
thedo | 166:3a9487d57a5c | 46 | * } |
thedo | 166:3a9487d57a5c | 47 | */ |
thedo | 166:3a9487d57a5c | 48 | class HeapBlockDevice : public BlockDevice |
thedo | 166:3a9487d57a5c | 49 | { |
thedo | 166:3a9487d57a5c | 50 | public: |
thedo | 166:3a9487d57a5c | 51 | |
thedo | 166:3a9487d57a5c | 52 | /** Lifetime of the memory block device |
thedo | 166:3a9487d57a5c | 53 | */ |
thedo | 166:3a9487d57a5c | 54 | HeapBlockDevice(bd_size_t size, bd_size_t block=512); |
thedo | 166:3a9487d57a5c | 55 | HeapBlockDevice(bd_size_t size, bd_size_t read, bd_size_t program, bd_size_t erase); |
thedo | 166:3a9487d57a5c | 56 | virtual ~HeapBlockDevice(); |
thedo | 166:3a9487d57a5c | 57 | |
thedo | 166:3a9487d57a5c | 58 | /** Initialize a block device |
thedo | 166:3a9487d57a5c | 59 | * |
thedo | 166:3a9487d57a5c | 60 | * @return 0 on success or a negative error code on failure |
thedo | 166:3a9487d57a5c | 61 | */ |
thedo | 166:3a9487d57a5c | 62 | virtual int init(); |
thedo | 166:3a9487d57a5c | 63 | |
thedo | 166:3a9487d57a5c | 64 | /** Deinitialize a block device |
thedo | 166:3a9487d57a5c | 65 | * |
thedo | 166:3a9487d57a5c | 66 | * @return 0 on success or a negative error code on failure |
thedo | 166:3a9487d57a5c | 67 | */ |
thedo | 166:3a9487d57a5c | 68 | virtual int deinit(); |
thedo | 166:3a9487d57a5c | 69 | |
thedo | 166:3a9487d57a5c | 70 | /** Read blocks from a block device |
thedo | 166:3a9487d57a5c | 71 | * |
thedo | 166:3a9487d57a5c | 72 | * @param buffer Buffer to read blocks into |
thedo | 166:3a9487d57a5c | 73 | * @param addr Address of block to begin reading from |
thedo | 166:3a9487d57a5c | 74 | * @param size Size to read in bytes, must be a multiple of read block size |
thedo | 166:3a9487d57a5c | 75 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 76 | */ |
thedo | 166:3a9487d57a5c | 77 | virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 78 | |
thedo | 166:3a9487d57a5c | 79 | /** Program blocks to a block device |
thedo | 166:3a9487d57a5c | 80 | * |
thedo | 166:3a9487d57a5c | 81 | * The blocks must have been erased prior to being programmed |
thedo | 166:3a9487d57a5c | 82 | * |
thedo | 166:3a9487d57a5c | 83 | * @param buffer Buffer of data to write to blocks |
thedo | 166:3a9487d57a5c | 84 | * @param addr Address of block to begin writing to |
thedo | 166:3a9487d57a5c | 85 | * @param size Size to write in bytes, must be a multiple of program block size |
thedo | 166:3a9487d57a5c | 86 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 87 | */ |
thedo | 166:3a9487d57a5c | 88 | virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 89 | |
thedo | 166:3a9487d57a5c | 90 | /** Erase blocks on a block device |
thedo | 166:3a9487d57a5c | 91 | * |
thedo | 166:3a9487d57a5c | 92 | * The state of an erased block is undefined until it has been programmed |
thedo | 166:3a9487d57a5c | 93 | * |
thedo | 166:3a9487d57a5c | 94 | * @param addr Address of block to begin erasing |
thedo | 166:3a9487d57a5c | 95 | * @param size Size to erase in bytes, must be a multiple of erase block size |
thedo | 166:3a9487d57a5c | 96 | * @return 0 on success, negative error code on failure |
thedo | 166:3a9487d57a5c | 97 | */ |
thedo | 166:3a9487d57a5c | 98 | virtual int erase(bd_addr_t addr, bd_size_t size); |
thedo | 166:3a9487d57a5c | 99 | |
thedo | 166:3a9487d57a5c | 100 | /** Get the size of a readable block |
thedo | 166:3a9487d57a5c | 101 | * |
thedo | 166:3a9487d57a5c | 102 | * @return Size of a readable block in bytes |
thedo | 166:3a9487d57a5c | 103 | */ |
thedo | 166:3a9487d57a5c | 104 | virtual bd_size_t get_read_size() const; |
thedo | 166:3a9487d57a5c | 105 | |
thedo | 166:3a9487d57a5c | 106 | /** Get the size of a programable block |
thedo | 166:3a9487d57a5c | 107 | * |
thedo | 166:3a9487d57a5c | 108 | * @return Size of a programable block in bytes |
thedo | 166:3a9487d57a5c | 109 | */ |
thedo | 166:3a9487d57a5c | 110 | virtual bd_size_t get_program_size() const; |
thedo | 166:3a9487d57a5c | 111 | |
thedo | 166:3a9487d57a5c | 112 | /** Get the size of a eraseable block |
thedo | 166:3a9487d57a5c | 113 | * |
thedo | 166:3a9487d57a5c | 114 | * @return Size of a eraseable block in bytes |
thedo | 166:3a9487d57a5c | 115 | */ |
thedo | 166:3a9487d57a5c | 116 | virtual bd_size_t get_erase_size() const; |
thedo | 166:3a9487d57a5c | 117 | |
thedo | 166:3a9487d57a5c | 118 | /** Get the total size of the underlying device |
thedo | 166:3a9487d57a5c | 119 | * |
thedo | 166:3a9487d57a5c | 120 | * @return Size of the underlying device in bytes |
thedo | 166:3a9487d57a5c | 121 | */ |
thedo | 166:3a9487d57a5c | 122 | virtual bd_size_t size() const; |
thedo | 166:3a9487d57a5c | 123 | |
thedo | 166:3a9487d57a5c | 124 | private: |
thedo | 166:3a9487d57a5c | 125 | bd_size_t _read_size; |
thedo | 166:3a9487d57a5c | 126 | bd_size_t _program_size; |
thedo | 166:3a9487d57a5c | 127 | bd_size_t _erase_size; |
thedo | 166:3a9487d57a5c | 128 | bd_size_t _count; |
thedo | 166:3a9487d57a5c | 129 | uint8_t **_blocks; |
thedo | 166:3a9487d57a5c | 130 | }; |
thedo | 166:3a9487d57a5c | 131 | |
thedo | 166:3a9487d57a5c | 132 | |
thedo | 166:3a9487d57a5c | 133 | #endif |
thedo | 166:3a9487d57a5c | 134 |