Kenji Arai / TYBLE16_mbedlized_os5_several_examples_1st

Dependencies:   nRF51_Vdd TextLCD BME280

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 
00027 
00028 /** Block device for measuring storage operations of another block device
00029  *
00030  *  @code
00031  *  #include "mbed.h"
00032  *  #include "HeapBlockDevice.h"
00033  *  #include "ProfilingBlockDevice.h"
00034  *
00035  *  // Create a heap block device and profiling block device
00036  *  HeapBlockDevice mem(64*512, 512);
00037  *  ProfilingBlockDevice profiler(&mem);
00038  *
00039  *  // do block device work....
00040  *
00041  *  printf("read count: %lld\n", profiler.get_read_count());
00042  *  printf("program count: %lld\n", profiler.get_program_count());
00043  *  printf("erase count: %lld\n", profiler.get_erase_count());
00044  *  @endcode
00045  */
00046 class ProfilingBlockDevice : public BlockDevice
00047 {
00048 public:
00049     /** Lifetime of the memory block device
00050      *
00051      *  @param bd       Block device to back the ProfilingBlockDevice
00052      */
00053     ProfilingBlockDevice(BlockDevice *bd);
00054 
00055     /** Lifetime of a block device
00056      */
00057     virtual ~ProfilingBlockDevice() {};
00058 
00059     /** Initialize a block device
00060      *
00061      *  @return         0 on success or a negative error code on failure
00062      *  @note The init and deinit functions do not effect profile counts
00063      */
00064     virtual int init();
00065 
00066     /** Deinitialize a block device
00067      *
00068      *  @return         0 on success or a negative error code on failure
00069      *  @note The init and deinit functions do not effect profile counts
00070      */
00071     virtual int deinit();
00072 
00073     /** Ensure data on storage is in sync with the driver
00074      *
00075      *  @return         0 on success or a negative error code on failure
00076      */
00077     virtual int sync();
00078 
00079     /** Read blocks from a block device
00080      *
00081      *  @param buffer   Buffer to read blocks into
00082      *  @param addr     Address of block to begin reading from
00083      *  @param size     Size to read in bytes, must be a multiple of read block size
00084      *  @return         0 on success, negative error code on failure
00085      */
00086     virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
00087 
00088     /** Program blocks to a block device
00089      *
00090      *  The blocks must have been erased prior to being programmed
00091      *
00092      *  @param buffer   Buffer of data to write to blocks
00093      *  @param addr     Address of block to begin writing to
00094      *  @param size     Size to write in bytes, must be a multiple of program block size
00095      *  @return         0 on success, negative error code on failure
00096      */
00097     virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
00098 
00099     /** Erase blocks on a block device
00100      *
00101      *  The state of an erased block is undefined until it has been programmed,
00102      *  unless get_erase_value returns a non-negative byte value
00103      *
00104      *  @param addr     Address of block to begin erasing
00105      *  @param size     Size to erase in bytes, must be a multiple of erase block size
00106      *  @return         0 on success, negative error code on failure
00107      */
00108     virtual int erase(bd_addr_t addr, bd_size_t size);
00109 
00110     /** Get the size of a readable block
00111      *
00112      *  @return         Size of a readable block in bytes
00113      */
00114     virtual bd_size_t get_read_size() const;
00115 
00116     /** Get the size of a programmable block
00117      *
00118      *  @return         Size of a programmable block in bytes
00119      *  @note Must be a multiple of the read size
00120      */
00121     virtual bd_size_t get_program_size() const;
00122 
00123     /** Get the size of an erasable block
00124      *
00125      *  @return         Size of an erasable block in bytes
00126      *  @note Must be a multiple of the program size
00127      */
00128     virtual bd_size_t get_erase_size() const;
00129 
00130     /** Get the size of an erasable block given address
00131      *
00132      *  @param addr     Address within the erasable block
00133      *  @return         Size of an erasable block in bytes
00134      *  @note Must be a multiple of the program size
00135      */
00136     virtual bd_size_t get_erase_size(bd_addr_t addr) const;
00137 
00138     /** Get the value of storage when erased
00139      *
00140      *  If get_erase_value returns a non-negative byte value, the underlying
00141      *  storage is set to that value when erased, and you can program storage
00142      *  containing that value without another erase.
00143      *
00144      *  @return         The value of storage when erased, or -1 if you can't
00145      *                  rely on the value of erased storage
00146      */
00147     virtual int get_erase_value() const;
00148 
00149     /** Get the total size of the underlying device
00150      *
00151      *  @return         Size of the underlying device in bytes
00152      */
00153     virtual bd_size_t size() const;
00154 
00155     /** Reset the current profile counts to zero
00156      */
00157     void reset();
00158 
00159     /** Get number of bytes that have been read from the block device
00160      *
00161      *  @return The number of bytes that have been read from the block device
00162      */
00163     bd_size_t get_read_count() const;
00164 
00165     /** Get number of bytes that have been programed to the block device
00166      *
00167      *  @return The number of bytes that have been programed to the block device
00168      */
00169     bd_size_t get_program_count() const;
00170 
00171     /** Get number of bytes that have been erased from the block device
00172      *
00173      *  @return The number of bytes that have been erased from the block device
00174      */
00175     bd_size_t get_erase_count() const;
00176 
00177 private:
00178     BlockDevice *_bd;
00179     bd_size_t _read_count;
00180     bd_size_t _program_count;
00181     bd_size_t _erase_count;
00182 };
00183 
00184 
00185 #endif