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 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, bd_addr_t addr, 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, bd_addr_t addr, 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(bd_addr_t addr, 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 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 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 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 bd_size_t get_erase_size(bd_addr_t addr) const; 00111 00112 /** Get the total size of the underlying device 00113 * 00114 * @return Size of the underlying device in bytes 00115 */ 00116 virtual bd_size_t size() const; 00117 00118 private: 00119 // Device configuration 00120 mbed::FlashIAP _flash; 00121 bd_addr_t _base; 00122 bd_size_t _size; 00123 bool _is_initialized; 00124 uint32_t _init_ref_count; 00125 }; 00126 00127 #endif /* DEVICE_FLASH */ 00128 #endif /* MBED_FLASHIAP_BLOCK_DEVICE_H */
Generated on Tue Jul 12 2022 20:52:43 by
1.7.2