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: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
ExhaustibleBlockDevice.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_EXHAUSTIBLE_BLOCK_DEVICE_H 00023 #define MBED_EXHAUSTIBLE_BLOCK_DEVICE_H 00024 00025 #include "BlockDevice.h" 00026 00027 00028 /** Heap backed block device which simulates failures 00029 * 00030 * Similar to heap block device but sectors wear out and are no longer programmable 00031 * after a configurable number of cycles. 00032 * 00033 */ 00034 class ExhaustibleBlockDevice : public BlockDevice 00035 { 00036 public: 00037 /** Lifetime of the block device 00038 * 00039 * @param bd Block device to back the ExhaustibleBlockDevice 00040 * @param erase_cycles Number of erase cycles before failure 00041 */ 00042 ExhaustibleBlockDevice(BlockDevice *bd, uint32_t erase_cycles); 00043 virtual ~ExhaustibleBlockDevice(); 00044 00045 /** 00046 * Get the number of erase cycles remaining on a block 00047 * 00048 * @param addr Any address in the block being queried for erase cycles 00049 * @return Number of erase cycles remaining 00050 */ 00051 uint32_t get_erase_cycles(bd_addr_t addr) const; 00052 00053 /** 00054 * Set the number of erase cycles before failure 00055 * 00056 * @param addr Any address in the block being queried for erase cycles 00057 * @param cycles Erase cycles before the block malfunctions 00058 */ 00059 void set_erase_cycles(bd_addr_t addr, uint32_t cycles); 00060 00061 /** Initialize a block device 00062 * 00063 * @return 0 on success or a negative error code on failure 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 */ 00071 virtual int deinit(); 00072 00073 /** Read blocks from a block device 00074 * 00075 * @param buffer Buffer to read blocks into 00076 * @param addr Address of block to begin reading from 00077 * @param size Size to read in bytes, must be a multiple of read block size 00078 * @return 0 on success, negative error code on failure 00079 */ 00080 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); 00081 00082 /** Program blocks to a block device 00083 * 00084 * The blocks must have been erased prior to being programmed 00085 * 00086 * @param buffer Buffer of data to write to blocks 00087 * @param addr Address of block to begin writing to 00088 * @param size Size to write in bytes, must be a multiple of program block size 00089 * @return 0 on success, negative error code on failure 00090 */ 00091 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); 00092 00093 /** Erase blocks on a block device 00094 * 00095 * The state of an erased block is undefined until it has been programmed 00096 * 00097 * @param addr Address of block to begin erasing 00098 * @param size Size to erase in bytes, must be a multiple of erase block size 00099 * @return 0 on success, negative error code on failure 00100 */ 00101 virtual int erase(bd_addr_t addr, bd_size_t size); 00102 00103 /** Get the size of a readable block 00104 * 00105 * @return Size of a readable block in bytes 00106 */ 00107 virtual bd_size_t get_read_size() const; 00108 00109 /** Get the size of a programmable block 00110 * 00111 * @return Size of a programmable block in bytes 00112 */ 00113 virtual bd_size_t get_program_size() const; 00114 00115 /** Get the size of a erasable block 00116 * 00117 * @return Size of a erasable block in bytes 00118 */ 00119 virtual bd_size_t get_erase_size() const; 00120 00121 /** Get the total size of the underlying device 00122 * 00123 * @return Size of the underlying device in bytes 00124 */ 00125 virtual bd_size_t size() const; 00126 00127 private: 00128 BlockDevice *_bd; 00129 uint32_t *_erase_array; 00130 uint32_t _erase_cycles; 00131 }; 00132 00133 00134 #endif
Generated on Tue Jul 12 2022 13:02:52 by
