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.
Fork of gr-peach-opencv-project by
BlockDevice.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2017 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_BLOCK_DEVICE_H 00018 #define MBED_BLOCK_DEVICE_H 00019 00020 #include <stdint.h> 00021 00022 00023 /** Enum of standard error codes 00024 * 00025 * @enum bd_error 00026 */ 00027 enum bd_error { 00028 BD_ERROR_OK = 0, /*!< no error */ 00029 BD_ERROR_DEVICE_ERROR = -4001, /*!< device specific error */ 00030 }; 00031 00032 /** Type representing the address of a specific block 00033 */ 00034 typedef uint64_t bd_addr_t; 00035 00036 /** Type representing a quantity of 8-bit bytes 00037 */ 00038 typedef uint64_t bd_size_t; 00039 00040 00041 /** A hardware device capable of writing and reading blocks 00042 */ 00043 class BlockDevice 00044 { 00045 public: 00046 /** Lifetime of a block device 00047 */ 00048 virtual ~BlockDevice() {}; 00049 00050 /** Initialize a block device 00051 * 00052 * @return 0 on success or a negative error code on failure 00053 */ 00054 virtual int init() = 0; 00055 00056 /** Deinitialize a block device 00057 * 00058 * @return 0 on success or a negative error code on failure 00059 */ 00060 virtual int deinit() = 0; 00061 00062 /** Read blocks from a block device 00063 * 00064 * If a failure occurs, it is not possible to determine how many bytes succeeded 00065 * 00066 * @param buffer Buffer to write blocks to 00067 * @param addr Address of block to begin reading from 00068 * @param size Size to read in bytes, must be a multiple of read block size 00069 * @return 0 on success, negative error code on failure 00070 */ 00071 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size) = 0; 00072 00073 /** Program blocks to a block device 00074 * 00075 * The blocks must have been erased prior to being programmed 00076 * 00077 * If a failure occurs, it is not possible to determine how many bytes succeeded 00078 * 00079 * @param buffer Buffer of data to write to blocks 00080 * @param addr Address of block to begin writing to 00081 * @param size Size to write in bytes, must be a multiple of program block size 00082 * @return 0 on success, negative error code on failure 00083 */ 00084 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size) = 0; 00085 00086 /** Erase blocks on a block device 00087 * 00088 * The state of an erased block is undefined until it has been programmed 00089 * 00090 * @param addr Address of block to begin erasing 00091 * @param size Size to erase in bytes, must be a multiple of erase block size 00092 * @return 0 on success, negative error code on failure 00093 */ 00094 virtual int erase(bd_addr_t addr, bd_size_t size) = 0; 00095 00096 /** Get the size of a readable block 00097 * 00098 * @return Size of a readable block in bytes 00099 */ 00100 virtual bd_size_t get_read_size() const = 0; 00101 00102 /** Get the size of a programable block 00103 * 00104 * @return Size of a programable block in bytes 00105 * @note Must be a multiple of the read size 00106 */ 00107 virtual bd_size_t get_program_size() const = 0; 00108 00109 /** Get the size of a eraseable block 00110 * 00111 * @return Size of a eraseable block in bytes 00112 * @note Must be a multiple of the program size 00113 */ 00114 virtual bd_size_t get_erase_size() const = 0; 00115 00116 /** Get the total size of the underlying device 00117 * 00118 * @return Size of the underlying device in bytes 00119 */ 00120 virtual bd_size_t size() const = 0; 00121 00122 /** Convenience function for checking block read validity 00123 * 00124 * @param addr Address of block to begin reading from 00125 * @param size Size to read in bytes 00126 * @return True if read is valid for underlying block device 00127 */ 00128 bool is_valid_read(bd_addr_t addr, bd_size_t size) const 00129 { 00130 return ( 00131 addr % get_read_size() == 0 && 00132 size % get_read_size() == 0 && 00133 addr + size <= this->size()); 00134 } 00135 00136 /** Convenience function for checking block program validity 00137 * 00138 * @param addr Address of block to begin writing to 00139 * @param size Size to write in bytes 00140 * @return True if program is valid for underlying block device 00141 */ 00142 bool is_valid_program(bd_addr_t addr, bd_size_t size) const 00143 { 00144 return ( 00145 addr % get_program_size() == 0 && 00146 size % get_program_size() == 0 && 00147 addr + size <= this->size()); 00148 } 00149 00150 /** Convenience function for checking block erase validity 00151 * 00152 * @param addr Address of block to begin erasing 00153 * @param size Size to erase in bytes 00154 * @return True if erase is valid for underlying block device 00155 */ 00156 bool is_valid_erase(bd_addr_t addr, bd_size_t size) const 00157 { 00158 return ( 00159 addr % get_erase_size() == 0 && 00160 size % get_erase_size() == 0 && 00161 addr + size <= this->size()); 00162 } 00163 }; 00164 00165 00166 #endif 00167
Generated on Tue Jul 12 2022 15:17:18 by
1.7.2
