Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
ObservingBlockDevice.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2017-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_OBSERVING_BLOCK_DEVICE_H 00027 #define MBED_OBSERVING_BLOCK_DEVICE_H 00028 00029 #include "BlockDevice.h" 00030 #include "platform/PlatformMutex.h" 00031 #include "platform/Callback.h" 00032 00033 namespace mbed { 00034 00035 class ObservingBlockDevice : public BlockDevice { 00036 public: 00037 00038 /** Lifetime of the block device 00039 * 00040 * @param bd Block device to observe 00041 */ 00042 ObservingBlockDevice(BlockDevice *bd); 00043 virtual ~ObservingBlockDevice(); 00044 00045 /** Attach a callback which is called on change 00046 * 00047 * @param cb Function to call on filesystem change (erase or program) 00048 */ 00049 void attach(mbed::Callback<void(BlockDevice *)> cb); 00050 00051 /** Initialize a block device 00052 * 00053 * @return 0 on success or a negative error code on failure 00054 */ 00055 virtual int init(); 00056 00057 /** Deinitialize a block device 00058 * 00059 * @return 0 on success or a negative error code on failure 00060 */ 00061 virtual int deinit(); 00062 00063 /** Ensure data on storage is in sync with the driver 00064 * 00065 * @return 0 on success or a negative error code on failure 00066 */ 00067 virtual int sync(); 00068 00069 /** Read blocks from a block device 00070 * 00071 * @param buffer Buffer to read blocks into 00072 * @param addr Address of block to begin reading from 00073 * @param size Size to read in bytes, must be a multiple of read block size 00074 * @return 0 on success, negative error code on failure 00075 */ 00076 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); 00077 00078 /** Program blocks to a block device 00079 * 00080 * The blocks must have been erased prior to being programmed 00081 * 00082 * @param buffer Buffer of data to write to blocks 00083 * @param addr Address of block to begin writing to 00084 * @param size Size to write in bytes, must be a multiple of program block size 00085 * @return 0 on success, negative error code on failure 00086 */ 00087 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); 00088 00089 /** Erase blocks on a block device 00090 * 00091 * The state of an erased block is undefined until it has been programmed, 00092 * unless get_erase_value returns a non-negative byte value 00093 * 00094 * @param addr Address of block to begin erasing 00095 * @param size Size to erase in bytes, must be a multiple of erase block size 00096 * @return 0 on success, negative error code on failure 00097 */ 00098 virtual int erase(bd_addr_t addr, bd_size_t size); 00099 00100 /** Get the size of a readable block 00101 * 00102 * @return Size of a readable block in bytes 00103 */ 00104 virtual bd_size_t get_read_size() const; 00105 00106 /** Get the size of a programmable block 00107 * 00108 * @return Size of a programmable block in bytes 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 */ 00116 virtual bd_size_t get_erase_size() const; 00117 00118 /** Get the size of an erasable block given address 00119 * 00120 * @param addr Address within the erasable block 00121 * @return Size of an erasable block in bytes 00122 * @note Must be a multiple of the program size 00123 */ 00124 virtual bd_size_t get_erase_size(bd_addr_t addr) const; 00125 00126 /** Get the value of storage when erased 00127 * 00128 * If get_erase_value returns a non-negative byte value, the underlying 00129 * storage is set to that value when erased, and storage containing 00130 * that value can be programmed without another erase. 00131 * 00132 * @return The value of storage when erased, or -1 if you can't 00133 * rely on the value of erased storage 00134 */ 00135 virtual int get_erase_value() const; 00136 00137 /** Get the total size of the underlying device 00138 * 00139 * @return Size of the underlying device in bytes 00140 */ 00141 virtual bd_size_t size() const; 00142 00143 /** Get the BlockDevice class type. 00144 * 00145 * @return A string represent the BlockDevice class type. 00146 */ 00147 virtual const char *get_type() const; 00148 00149 private: 00150 BlockDevice *_bd; 00151 mbed::Callback<void(BlockDevice *)> _change; 00152 }; 00153 00154 } // namespace mbed 00155 00156 // Added "using" for backwards compatibility 00157 #ifndef MBED_NO_GLOBAL_USING_DIRECTIVE 00158 using mbed::ObservingBlockDevice; 00159 #endif 00160 00161 #endif 00162 00163 /** @}*/
Generated on Tue Jul 12 2022 13:54:39 by
