Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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