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
FlashSimBlockDevice.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2018 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_FLASH_SIM_BLOCK_DEVICE_H 00027 #define MBED_FLASH_SIM_BLOCK_DEVICE_H 00028 00029 #include "BlockDevice.h" 00030 00031 namespace mbed { 00032 00033 enum { 00034 BD_ERROR_NOT_ERASED = -3201, 00035 }; 00036 00037 /** Flash simulating block device 00038 * 00039 * Flash simulation BD adaptor 00040 * 00041 */ 00042 class FlashSimBlockDevice : public BlockDevice { 00043 public: 00044 00045 /** Constructor 00046 * 00047 * @param bd Block device to back the FlashSimBlockDevice 00048 * @param erase_value Value stored in a block after it's erased 00049 */ 00050 FlashSimBlockDevice(BlockDevice *bd, uint8_t erase_value = 0xFF); 00051 virtual ~FlashSimBlockDevice(); 00052 00053 /** Initialize a block device 00054 * 00055 * @return 0 on success or a negative error code on failure 00056 */ 00057 virtual int init(); 00058 00059 /** Deinitialize the block device 00060 * 00061 * @return 0 on success or a negative error code on failure 00062 */ 00063 virtual int deinit(); 00064 00065 /** Ensure data on storage is in sync with the driver 00066 * 00067 * @return 0 on success or a negative error code on failure 00068 */ 00069 virtual int sync(); 00070 00071 /** Read blocks from the block device 00072 * 00073 * @param buffer Buffer to read blocks into 00074 * @param addr Address of block to begin reading from 00075 * @param size Size to read in bytes, must be a multiple of read block size 00076 * @return 0 on success, negative error code on failure 00077 */ 00078 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); 00079 00080 /** Program blocks to the block device 00081 * 00082 * The blocks must have been erased prior to being programmed 00083 * 00084 * @param buffer Buffer of data to write to blocks 00085 * @param addr Address of block to begin writing to 00086 * @param size Size to write in bytes, must be a multiple of program block size 00087 * @return 0 on success, negative error code on failure 00088 */ 00089 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); 00090 00091 /** Erase blocks on the block device 00092 * 00093 * Required before any write to these addresses 00094 * 00095 * @param addr Address of block to begin erasing 00096 * @param size Size to erase in bytes, must be a multiple of erase block size 00097 * @return 0 on success, negative error code on failure 00098 */ 00099 virtual int erase(bd_addr_t addr, bd_size_t size); 00100 00101 /** Get the size of a readable block 00102 * 00103 * @return Size of a readable block in bytes 00104 */ 00105 virtual bd_size_t get_read_size() const; 00106 00107 /** Get the size of a programmable block 00108 * 00109 * @return Size of a programmable block in bytes 00110 */ 00111 virtual bd_size_t get_program_size() const; 00112 00113 /** Get the size of an erasable block 00114 * 00115 * @return Size of an erasable block in bytes 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 * @return The value of storage when erased 00130 */ 00131 virtual int get_erase_value() const; 00132 00133 /** Get the total size of the underlying device 00134 * 00135 * @return Size of the underlying device in bytes 00136 */ 00137 virtual bd_size_t size() const; 00138 00139 /** Get the BlockDevice class type. 00140 * 00141 * @return A string represent the BlockDevice class type. 00142 */ 00143 virtual const char *get_type() const; 00144 00145 private: 00146 uint8_t _erase_value; 00147 bd_size_t _blank_buf_size; 00148 uint8_t *_blank_buf; 00149 BlockDevice *_bd; 00150 uint32_t _init_ref_count; 00151 bool _is_initialized; 00152 }; 00153 00154 } // namespace mbed 00155 00156 // Added "using" for backwards compatibility 00157 #ifndef MBED_NO_GLOBAL_USING_DIRECTIVE 00158 using mbed::FlashSimBlockDevice; 00159 #endif 00160 00161 #endif 00162 00163 /** @}*/
Generated on Tue Jul 12 2022 13:54:22 by
