Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ProfilingBlockDevice.h Source File

ProfilingBlockDevice.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017 ARM Limited
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy
00005  * of this software and associated documentation files (the "Software"), to deal
00006  * in the Software without restriction, including without limitation the rights
00007  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008  * copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in
00012  * all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00020  * SOFTWARE.
00021  */
00022 #ifndef MBED_PROFILING_BLOCK_DEVICE_H
00023 #define MBED_PROFILING_BLOCK_DEVICE_H
00024 
00025 #include "BlockDevice.h"
00026 #include "mbed.h"
00027 
00028 
00029 /** Block device for measuring storage operations of another block device
00030  *
00031  *  @code
00032  *  #include "mbed.h"
00033  *  #include "HeapBlockDevice.h"
00034  *  #include "ProfilingBlockDevice.h"
00035  *
00036  *  // Create a heap block device and profiling block device
00037  *  HeapBlockDevice mem(64*512, 512);
00038  *  ProfilingBlockDevice profiler(&mem);
00039  *
00040  *  // do block device work....
00041  *
00042  *  printf("read count: %lld\n", profiler.get_read_count());
00043  *  printf("program count: %lld\n", profiler.get_program_count());
00044  *  printf("erase count: %lld\n", profiler.get_erase_count());
00045  *  @endcode
00046  */
00047 class ProfilingBlockDevice : public BlockDevice
00048 {
00049 public:
00050     /** Lifetime of the memory block device
00051      *
00052      *  @param bd       Block device to back the ProfilingBlockDevice
00053      */
00054     ProfilingBlockDevice(BlockDevice *bd);
00055 
00056     /** Lifetime of a block device
00057      */
00058     virtual ~ProfilingBlockDevice() {};
00059 
00060     /** Initialize a block device
00061      *
00062      *  @return         0 on success or a negative error code on failure
00063      *  @note The init and deinit functions do not effect profile counts
00064      */
00065     virtual int init();
00066 
00067     /** Deinitialize a block device
00068      *
00069      *  @return         0 on success or a negative error code on failure
00070      *  @note The init and deinit functions do not effect profile counts
00071      */
00072     virtual int deinit();
00073 
00074     /** Ensure data on storage is in sync with the driver
00075      *
00076      *  @return         0 on success or a negative error code on failure
00077      */
00078     virtual int sync();
00079 
00080     /** Read blocks from a block device
00081      *
00082      *  @param buffer   Buffer to read blocks into
00083      *  @param addr     Address of block to begin reading from
00084      *  @param size     Size to read in bytes, must be a multiple of read block size
00085      *  @return         0 on success, negative error code on failure
00086      */
00087     virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
00088 
00089     /** Program blocks to a block device
00090      *
00091      *  The blocks must have been erased prior to being programmed
00092      *
00093      *  @param buffer   Buffer of data to write to blocks
00094      *  @param addr     Address of block to begin writing to
00095      *  @param size     Size to write in bytes, must be a multiple of program block size
00096      *  @return         0 on success, negative error code on failure
00097      */
00098     virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
00099 
00100     /** Erase blocks on a block device
00101      *
00102      *  The state of an erased block is undefined until it has been programmed,
00103      *  unless get_erase_value returns a non-negative byte value
00104      *
00105      *  @param addr     Address of block to begin erasing
00106      *  @param size     Size to erase in bytes, must be a multiple of erase block size
00107      *  @return         0 on success, negative error code on failure
00108      */
00109     virtual int erase(bd_addr_t addr, bd_size_t size);
00110 
00111     /** Get the size of a readable block
00112      *
00113      *  @return         Size of a readable block in bytes
00114      */
00115     virtual bd_size_t get_read_size() const;
00116 
00117     /** Get the size of a programmable block
00118      *
00119      *  @return         Size of a programmable block in bytes
00120      *  @note Must be a multiple of the read size
00121      */
00122     virtual bd_size_t get_program_size() const;
00123 
00124     /** Get the size of an erasable block
00125      *
00126      *  @return         Size of an erasable block in bytes
00127      *  @note Must be a multiple of the program size
00128      */
00129     virtual bd_size_t get_erase_size() const;
00130 
00131     /** Get the size of an erasable block given address
00132      *
00133      *  @param addr     Address within the erasable block
00134      *  @return         Size of an erasable block in bytes
00135      *  @note Must be a multiple of the program size
00136      */
00137     virtual bd_size_t get_erase_size(bd_addr_t addr) const;
00138 
00139     /** Get the value of storage when erased
00140      *
00141      *  If get_erase_value returns a non-negative byte value, the underlying
00142      *  storage is set to that value when erased, and you can program storage
00143      *  containing that value without another erase.
00144      *
00145      *  @return         The value of storage when erased, or -1 if you can't
00146      *                  rely on the value of erased storage
00147      */
00148     virtual int get_erase_value() const;
00149 
00150     /** Get the total size of the underlying device
00151      *
00152      *  @return         Size of the underlying device in bytes
00153      */
00154     virtual bd_size_t size() const;
00155 
00156     /** Reset the current profile counts to zero
00157      */
00158     void reset();
00159 
00160     /** Get number of bytes that have been read from the block device
00161      *
00162      *  @return The number of bytes that have been read from the block device
00163      */
00164     bd_size_t get_read_count() const;
00165 
00166     /** Get number of bytes that have been programed to the block device
00167      *
00168      *  @return The number of bytes that have been programed to the block device
00169      */
00170     bd_size_t get_program_count() const;
00171 
00172     /** Get number of bytes that have been erased from the block device
00173      *
00174      *  @return The number of bytes that have been erased from the block device
00175      */
00176     bd_size_t get_erase_count() const;
00177 
00178 private:
00179     BlockDevice *_bd;
00180     bd_size_t _read_count;
00181     bd_size_t _program_count;
00182     bd_size_t _erase_count;
00183 };
00184 
00185 
00186 #endif