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
FlashIAPBlockDevice.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2016 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef MBED_FLASHIAP_BLOCK_DEVICE_H 00018 #define MBED_FLASHIAP_BLOCK_DEVICE_H 00019 00020 #if DEVICE_FLASH 00021 00022 #include "FlashIAP.h" 00023 #include "features/storage/blockdevice/BlockDevice.h" 00024 #include "platform/mbed_toolchain.h" 00025 00026 /** BlockDevice using the FlashIAP API 00027 * 00028 */ 00029 class FlashIAPBlockDevice : public mbed::BlockDevice { 00030 public: 00031 00032 /** Creates a FlashIAPBlockDevice 00033 * 00034 * @param address Physical address where the block device start 00035 * @param size The block device size 00036 */ 00037 FlashIAPBlockDevice(uint32_t address = MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS, 00038 uint32_t size = MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE); 00039 00040 virtual ~FlashIAPBlockDevice(); 00041 00042 /** Initialize a block device 00043 * 00044 * @return 0 on success or a negative error code on failure 00045 */ 00046 virtual int init(); 00047 00048 /** Deinitialize a block device 00049 * 00050 * @return 0 on success or a negative error code on failure 00051 */ 00052 virtual int deinit(); 00053 00054 /** Read blocks from a block device 00055 * 00056 * @param buffer Buffer to write blocks to 00057 * @param addr Address of block to begin reading from 00058 * @param size Size to read in bytes, must be a multiple of read block size 00059 * @return 0 on success, negative error code on failure 00060 */ 00061 virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size); 00062 00063 /** Program blocks to a block device 00064 * 00065 * The blocks must have been erased prior to being programmed 00066 * 00067 * @param buffer Buffer of data to write to blocks 00068 * @param addr Address of block to begin writing to 00069 * @param size Size to write in bytes, must be a multiple of program block size 00070 * @return 0 on success, negative error code on failure 00071 */ 00072 virtual int program(const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size); 00073 00074 /** Erase blocks on a block device 00075 * 00076 * The state of an erased block is undefined until it has been programmed 00077 * 00078 * @param addr Address of block to begin erasing 00079 * @param size Size to erase in bytes, must be a multiple of erase block size 00080 * @return 0 on success, negative error code on failure 00081 */ 00082 virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size); 00083 00084 /** Get the size of a readable block 00085 * 00086 * @return Size of a readable block in bytes 00087 */ 00088 virtual mbed::bd_size_t get_read_size() const; 00089 00090 /** Get the size of a programable block 00091 * 00092 * @return Size of a programable block in bytes 00093 * @note Must be a multiple of the read size 00094 */ 00095 virtual mbed::bd_size_t get_program_size() const; 00096 00097 /** Get the size of a eraseable block 00098 * 00099 * @return Size of a eraseable block in bytes 00100 * @note Must be a multiple of the program size 00101 */ 00102 virtual mbed::bd_size_t get_erase_size() const; 00103 00104 /** Get the size of an erasable block given address 00105 * 00106 * @param addr Address within the erasable block 00107 * @return Size of an erasable block in bytes 00108 * @note Must be a multiple of the program size 00109 */ 00110 virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr) const; 00111 00112 /** Get the value of storage when erased 00113 * 00114 * @return The value of storage when erased 00115 */ 00116 virtual int get_erase_value() const; 00117 00118 /** Get the total size of the underlying device 00119 * 00120 * @return Size of the underlying device in bytes 00121 */ 00122 virtual mbed::bd_size_t size() const; 00123 00124 /** Get the BlockDevice class type. 00125 * 00126 * @return A string represent the BlockDevice class type. 00127 */ 00128 virtual const char *get_type() const; 00129 00130 /** Convenience function for checking block erase validity 00131 * 00132 * @param addr Address of block to begin erasing 00133 * @param size Size to erase in bytes 00134 * @return True if erase is valid for underlying block device 00135 */ 00136 virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const; 00137 00138 00139 private: 00140 // Device configuration 00141 mbed::FlashIAP _flash; 00142 mbed::bd_addr_t _base; 00143 mbed::bd_size_t _size; 00144 bool _is_initialized; 00145 uint32_t _init_ref_count; 00146 }; 00147 00148 #endif /* DEVICE_FLASH */ 00149 #endif /* MBED_FLASHIAP_BLOCK_DEVICE_H */
Generated on Tue Jul 12 2022 13:54:22 by
1.7.2