Nicolas Borla
/
BBR_1Ebene
BBR 1 Ebene
mbed-os/features/filesystem/bd/ProfilingBlockDevice.h@0:fbdae7e6d805, 2018-05-14 (annotated)
- Committer:
- borlanic
- Date:
- Mon May 14 11:29:06 2018 +0000
- Revision:
- 0:fbdae7e6d805
BBR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:fbdae7e6d805 | 1 | /* mbed Microcontroller Library |
borlanic | 0:fbdae7e6d805 | 2 | * Copyright (c) 2017 ARM Limited |
borlanic | 0:fbdae7e6d805 | 3 | * |
borlanic | 0:fbdae7e6d805 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
borlanic | 0:fbdae7e6d805 | 5 | * of this software and associated documentation files (the "Software"), to deal |
borlanic | 0:fbdae7e6d805 | 6 | * in the Software without restriction, including without limitation the rights |
borlanic | 0:fbdae7e6d805 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
borlanic | 0:fbdae7e6d805 | 8 | * copies of the Software, and to permit persons to whom the Software is |
borlanic | 0:fbdae7e6d805 | 9 | * furnished to do so, subject to the following conditions: |
borlanic | 0:fbdae7e6d805 | 10 | * |
borlanic | 0:fbdae7e6d805 | 11 | * The above copyright notice and this permission notice shall be included in |
borlanic | 0:fbdae7e6d805 | 12 | * all copies or substantial portions of the Software. |
borlanic | 0:fbdae7e6d805 | 13 | * |
borlanic | 0:fbdae7e6d805 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
borlanic | 0:fbdae7e6d805 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
borlanic | 0:fbdae7e6d805 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
borlanic | 0:fbdae7e6d805 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
borlanic | 0:fbdae7e6d805 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
borlanic | 0:fbdae7e6d805 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
borlanic | 0:fbdae7e6d805 | 20 | * SOFTWARE. |
borlanic | 0:fbdae7e6d805 | 21 | */ |
borlanic | 0:fbdae7e6d805 | 22 | #ifndef MBED_PROFILING_BLOCK_DEVICE_H |
borlanic | 0:fbdae7e6d805 | 23 | #define MBED_PROFILING_BLOCK_DEVICE_H |
borlanic | 0:fbdae7e6d805 | 24 | |
borlanic | 0:fbdae7e6d805 | 25 | #include "BlockDevice.h" |
borlanic | 0:fbdae7e6d805 | 26 | #include "mbed.h" |
borlanic | 0:fbdae7e6d805 | 27 | |
borlanic | 0:fbdae7e6d805 | 28 | |
borlanic | 0:fbdae7e6d805 | 29 | /** Block device for measuring storage operations of another block device |
borlanic | 0:fbdae7e6d805 | 30 | * |
borlanic | 0:fbdae7e6d805 | 31 | * @code |
borlanic | 0:fbdae7e6d805 | 32 | * #include "mbed.h" |
borlanic | 0:fbdae7e6d805 | 33 | * #include "HeapBlockDevice.h" |
borlanic | 0:fbdae7e6d805 | 34 | * #include "ProfilingBlockDevice.h" |
borlanic | 0:fbdae7e6d805 | 35 | * |
borlanic | 0:fbdae7e6d805 | 36 | * // Create a heap block device and profiling block device |
borlanic | 0:fbdae7e6d805 | 37 | * HeapBlockDevice mem(64*512, 512); |
borlanic | 0:fbdae7e6d805 | 38 | * ProfilingBlockDevice profiler(&mem); |
borlanic | 0:fbdae7e6d805 | 39 | * |
borlanic | 0:fbdae7e6d805 | 40 | * // do block device work.... |
borlanic | 0:fbdae7e6d805 | 41 | * |
borlanic | 0:fbdae7e6d805 | 42 | * printf("read count: %lld\n", profiler.get_read_count()); |
borlanic | 0:fbdae7e6d805 | 43 | * printf("program count: %lld\n", profiler.get_program_count()); |
borlanic | 0:fbdae7e6d805 | 44 | * printf("erase count: %lld\n", profiler.get_erase_count()); |
borlanic | 0:fbdae7e6d805 | 45 | * @endcode |
borlanic | 0:fbdae7e6d805 | 46 | */ |
borlanic | 0:fbdae7e6d805 | 47 | class ProfilingBlockDevice : public BlockDevice |
borlanic | 0:fbdae7e6d805 | 48 | { |
borlanic | 0:fbdae7e6d805 | 49 | public: |
borlanic | 0:fbdae7e6d805 | 50 | /** Lifetime of the memory block device |
borlanic | 0:fbdae7e6d805 | 51 | * |
borlanic | 0:fbdae7e6d805 | 52 | * @param bd Block device to back the ProfilingBlockDevice |
borlanic | 0:fbdae7e6d805 | 53 | */ |
borlanic | 0:fbdae7e6d805 | 54 | ProfilingBlockDevice(BlockDevice *bd); |
borlanic | 0:fbdae7e6d805 | 55 | |
borlanic | 0:fbdae7e6d805 | 56 | /** Lifetime of a block device |
borlanic | 0:fbdae7e6d805 | 57 | */ |
borlanic | 0:fbdae7e6d805 | 58 | virtual ~ProfilingBlockDevice() {}; |
borlanic | 0:fbdae7e6d805 | 59 | |
borlanic | 0:fbdae7e6d805 | 60 | /** Initialize a block device |
borlanic | 0:fbdae7e6d805 | 61 | * |
borlanic | 0:fbdae7e6d805 | 62 | * @return 0 on success or a negative error code on failure |
borlanic | 0:fbdae7e6d805 | 63 | * @note The init and deinit functions do not effect profile counts |
borlanic | 0:fbdae7e6d805 | 64 | */ |
borlanic | 0:fbdae7e6d805 | 65 | virtual int init(); |
borlanic | 0:fbdae7e6d805 | 66 | |
borlanic | 0:fbdae7e6d805 | 67 | /** Deinitialize a block device |
borlanic | 0:fbdae7e6d805 | 68 | * |
borlanic | 0:fbdae7e6d805 | 69 | * @return 0 on success or a negative error code on failure |
borlanic | 0:fbdae7e6d805 | 70 | * @note The init and deinit functions do not effect profile counts |
borlanic | 0:fbdae7e6d805 | 71 | */ |
borlanic | 0:fbdae7e6d805 | 72 | virtual int deinit(); |
borlanic | 0:fbdae7e6d805 | 73 | |
borlanic | 0:fbdae7e6d805 | 74 | /** Ensure data on storage is in sync with the driver |
borlanic | 0:fbdae7e6d805 | 75 | * |
borlanic | 0:fbdae7e6d805 | 76 | * @return 0 on success or a negative error code on failure |
borlanic | 0:fbdae7e6d805 | 77 | */ |
borlanic | 0:fbdae7e6d805 | 78 | virtual int sync(); |
borlanic | 0:fbdae7e6d805 | 79 | |
borlanic | 0:fbdae7e6d805 | 80 | /** Read blocks from a block device |
borlanic | 0:fbdae7e6d805 | 81 | * |
borlanic | 0:fbdae7e6d805 | 82 | * @param buffer Buffer to read blocks into |
borlanic | 0:fbdae7e6d805 | 83 | * @param addr Address of block to begin reading from |
borlanic | 0:fbdae7e6d805 | 84 | * @param size Size to read in bytes, must be a multiple of read block size |
borlanic | 0:fbdae7e6d805 | 85 | * @return 0 on success, negative error code on failure |
borlanic | 0:fbdae7e6d805 | 86 | */ |
borlanic | 0:fbdae7e6d805 | 87 | virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); |
borlanic | 0:fbdae7e6d805 | 88 | |
borlanic | 0:fbdae7e6d805 | 89 | /** Program blocks to a block device |
borlanic | 0:fbdae7e6d805 | 90 | * |
borlanic | 0:fbdae7e6d805 | 91 | * The blocks must have been erased prior to being programmed |
borlanic | 0:fbdae7e6d805 | 92 | * |
borlanic | 0:fbdae7e6d805 | 93 | * @param buffer Buffer of data to write to blocks |
borlanic | 0:fbdae7e6d805 | 94 | * @param addr Address of block to begin writing to |
borlanic | 0:fbdae7e6d805 | 95 | * @param size Size to write in bytes, must be a multiple of program block size |
borlanic | 0:fbdae7e6d805 | 96 | * @return 0 on success, negative error code on failure |
borlanic | 0:fbdae7e6d805 | 97 | */ |
borlanic | 0:fbdae7e6d805 | 98 | virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); |
borlanic | 0:fbdae7e6d805 | 99 | |
borlanic | 0:fbdae7e6d805 | 100 | /** Erase blocks on a block device |
borlanic | 0:fbdae7e6d805 | 101 | * |
borlanic | 0:fbdae7e6d805 | 102 | * The state of an erased block is undefined until it has been programmed, |
borlanic | 0:fbdae7e6d805 | 103 | * unless get_erase_value returns a non-negative byte value |
borlanic | 0:fbdae7e6d805 | 104 | * |
borlanic | 0:fbdae7e6d805 | 105 | * @param addr Address of block to begin erasing |
borlanic | 0:fbdae7e6d805 | 106 | * @param size Size to erase in bytes, must be a multiple of erase block size |
borlanic | 0:fbdae7e6d805 | 107 | * @return 0 on success, negative error code on failure |
borlanic | 0:fbdae7e6d805 | 108 | */ |
borlanic | 0:fbdae7e6d805 | 109 | virtual int erase(bd_addr_t addr, bd_size_t size); |
borlanic | 0:fbdae7e6d805 | 110 | |
borlanic | 0:fbdae7e6d805 | 111 | /** Get the size of a readable block |
borlanic | 0:fbdae7e6d805 | 112 | * |
borlanic | 0:fbdae7e6d805 | 113 | * @return Size of a readable block in bytes |
borlanic | 0:fbdae7e6d805 | 114 | */ |
borlanic | 0:fbdae7e6d805 | 115 | virtual bd_size_t get_read_size() const; |
borlanic | 0:fbdae7e6d805 | 116 | |
borlanic | 0:fbdae7e6d805 | 117 | /** Get the size of a programmable block |
borlanic | 0:fbdae7e6d805 | 118 | * |
borlanic | 0:fbdae7e6d805 | 119 | * @return Size of a programmable block in bytes |
borlanic | 0:fbdae7e6d805 | 120 | * @note Must be a multiple of the read size |
borlanic | 0:fbdae7e6d805 | 121 | */ |
borlanic | 0:fbdae7e6d805 | 122 | virtual bd_size_t get_program_size() const; |
borlanic | 0:fbdae7e6d805 | 123 | |
borlanic | 0:fbdae7e6d805 | 124 | /** Get the size of an erasable block |
borlanic | 0:fbdae7e6d805 | 125 | * |
borlanic | 0:fbdae7e6d805 | 126 | * @return Size of an erasable block in bytes |
borlanic | 0:fbdae7e6d805 | 127 | * @note Must be a multiple of the program size |
borlanic | 0:fbdae7e6d805 | 128 | */ |
borlanic | 0:fbdae7e6d805 | 129 | virtual bd_size_t get_erase_size() const; |
borlanic | 0:fbdae7e6d805 | 130 | |
borlanic | 0:fbdae7e6d805 | 131 | /** Get the size of an erasable block given address |
borlanic | 0:fbdae7e6d805 | 132 | * |
borlanic | 0:fbdae7e6d805 | 133 | * @param addr Address within the erasable block |
borlanic | 0:fbdae7e6d805 | 134 | * @return Size of an erasable block in bytes |
borlanic | 0:fbdae7e6d805 | 135 | * @note Must be a multiple of the program size |
borlanic | 0:fbdae7e6d805 | 136 | */ |
borlanic | 0:fbdae7e6d805 | 137 | virtual bd_size_t get_erase_size(bd_addr_t addr) const; |
borlanic | 0:fbdae7e6d805 | 138 | |
borlanic | 0:fbdae7e6d805 | 139 | /** Get the value of storage when erased |
borlanic | 0:fbdae7e6d805 | 140 | * |
borlanic | 0:fbdae7e6d805 | 141 | * If get_erase_value returns a non-negative byte value, the underlying |
borlanic | 0:fbdae7e6d805 | 142 | * storage is set to that value when erased, and you can program storage |
borlanic | 0:fbdae7e6d805 | 143 | * containing that value without another erase. |
borlanic | 0:fbdae7e6d805 | 144 | * |
borlanic | 0:fbdae7e6d805 | 145 | * @return The value of storage when erased, or -1 if you can't |
borlanic | 0:fbdae7e6d805 | 146 | * rely on the value of erased storage |
borlanic | 0:fbdae7e6d805 | 147 | */ |
borlanic | 0:fbdae7e6d805 | 148 | virtual int get_erase_value() const; |
borlanic | 0:fbdae7e6d805 | 149 | |
borlanic | 0:fbdae7e6d805 | 150 | /** Get the total size of the underlying device |
borlanic | 0:fbdae7e6d805 | 151 | * |
borlanic | 0:fbdae7e6d805 | 152 | * @return Size of the underlying device in bytes |
borlanic | 0:fbdae7e6d805 | 153 | */ |
borlanic | 0:fbdae7e6d805 | 154 | virtual bd_size_t size() const; |
borlanic | 0:fbdae7e6d805 | 155 | |
borlanic | 0:fbdae7e6d805 | 156 | /** Reset the current profile counts to zero |
borlanic | 0:fbdae7e6d805 | 157 | */ |
borlanic | 0:fbdae7e6d805 | 158 | void reset(); |
borlanic | 0:fbdae7e6d805 | 159 | |
borlanic | 0:fbdae7e6d805 | 160 | /** Get number of bytes that have been read from the block device |
borlanic | 0:fbdae7e6d805 | 161 | * |
borlanic | 0:fbdae7e6d805 | 162 | * @return The number of bytes that have been read from the block device |
borlanic | 0:fbdae7e6d805 | 163 | */ |
borlanic | 0:fbdae7e6d805 | 164 | bd_size_t get_read_count() const; |
borlanic | 0:fbdae7e6d805 | 165 | |
borlanic | 0:fbdae7e6d805 | 166 | /** Get number of bytes that have been programed to the block device |
borlanic | 0:fbdae7e6d805 | 167 | * |
borlanic | 0:fbdae7e6d805 | 168 | * @return The number of bytes that have been programed to the block device |
borlanic | 0:fbdae7e6d805 | 169 | */ |
borlanic | 0:fbdae7e6d805 | 170 | bd_size_t get_program_count() const; |
borlanic | 0:fbdae7e6d805 | 171 | |
borlanic | 0:fbdae7e6d805 | 172 | /** Get number of bytes that have been erased from the block device |
borlanic | 0:fbdae7e6d805 | 173 | * |
borlanic | 0:fbdae7e6d805 | 174 | * @return The number of bytes that have been erased from the block device |
borlanic | 0:fbdae7e6d805 | 175 | */ |
borlanic | 0:fbdae7e6d805 | 176 | bd_size_t get_erase_count() const; |
borlanic | 0:fbdae7e6d805 | 177 | |
borlanic | 0:fbdae7e6d805 | 178 | private: |
borlanic | 0:fbdae7e6d805 | 179 | BlockDevice *_bd; |
borlanic | 0:fbdae7e6d805 | 180 | bd_size_t _read_count; |
borlanic | 0:fbdae7e6d805 | 181 | bd_size_t _program_count; |
borlanic | 0:fbdae7e6d805 | 182 | bd_size_t _erase_count; |
borlanic | 0:fbdae7e6d805 | 183 | }; |
borlanic | 0:fbdae7e6d805 | 184 | |
borlanic | 0:fbdae7e6d805 | 185 | |
borlanic | 0:fbdae7e6d805 | 186 | #endif |