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.
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 #ifdef DEVICE_FLASH 00021 00022 #include "FlashIAP.h" 00023 #include "BlockDevice.h" 00024 #include "platform/mbed_toolchain.h" 00025 00026 /** BlockDevice using the FlashIAP API 00027 * 00028 */ 00029 class FlashIAPBlockDevice : public BlockDevice { 00030 public: 00031 /** Creates a FlashIAPBlockDevice **/ 00032 FlashIAPBlockDevice(); 00033 00034 MBED_DEPRECATED("Please use default constructor instead") 00035 FlashIAPBlockDevice(uint32_t address, uint32_t size = 0); 00036 00037 virtual ~FlashIAPBlockDevice(); 00038 00039 /** Initialize a block device 00040 * 00041 * @return 0 on success or a negative error code on failure 00042 */ 00043 virtual int init(); 00044 00045 /** Deinitialize a block device 00046 * 00047 * @return 0 on success or a negative error code on failure 00048 */ 00049 virtual int deinit(); 00050 00051 /** Read blocks from a block device 00052 * 00053 * @param buffer Buffer to write blocks to 00054 * @param addr Address of block to begin reading from 00055 * @param size Size to read in bytes, must be a multiple of read block size 00056 * @return 0 on success, negative error code on failure 00057 */ 00058 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); 00059 00060 /** Program blocks to a block device 00061 * 00062 * The blocks must have been erased prior to being programmed 00063 * 00064 * @param buffer Buffer of data to write to blocks 00065 * @param addr Address of block to begin writing to 00066 * @param size Size to write in bytes, must be a multiple of program block size 00067 * @return 0 on success, negative error code on failure 00068 */ 00069 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); 00070 00071 /** Erase blocks on a block device 00072 * 00073 * The state of an erased block is undefined until it has been programmed 00074 * 00075 * @param addr Address of block to begin erasing 00076 * @param size Size to erase in bytes, must be a multiple of erase block size 00077 * @return 0 on success, negative error code on failure 00078 */ 00079 virtual int erase(bd_addr_t addr, bd_size_t size); 00080 00081 /** Get the size of a readable block 00082 * 00083 * @return Size of a readable block in bytes 00084 */ 00085 virtual bd_size_t get_read_size() const; 00086 00087 /** Get the size of a programable block 00088 * 00089 * @return Size of a programable block in bytes 00090 * @note Must be a multiple of the read size 00091 */ 00092 virtual bd_size_t get_program_size() const; 00093 00094 /** Get the size of a eraseable block 00095 * 00096 * @return Size of a eraseable block in bytes 00097 * @note Must be a multiple of the program size 00098 */ 00099 virtual bd_size_t get_erase_size() const; 00100 00101 /** Get the size of an erasable block given address 00102 * 00103 * @param addr Address within the erasable block 00104 * @return Size of an erasable block in bytes 00105 * @note Must be a multiple of the program size 00106 */ 00107 virtual bd_size_t get_erase_size(bd_addr_t addr) const; 00108 00109 /** Get the total size of the underlying device 00110 * 00111 * @return Size of the underlying device in bytes 00112 */ 00113 virtual bd_size_t size() const; 00114 00115 private: 00116 // Device configuration 00117 mbed::FlashIAP _flash; 00118 bd_addr_t _base; 00119 bd_size_t _size; 00120 bool _is_initialized; 00121 uint32_t _init_ref_count; 00122 }; 00123 00124 #endif /* DEVICE_FLASH */ 00125 #endif /* MBED_FLASHIAP_BLOCK_DEVICE_H */
Generated on Tue Aug 9 2022 00:37:07 by
