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-sd-card by
HeapBlockDevice.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_MEM_BLOCK_DEVICE_H 00023 #define MBED_MEM_BLOCK_DEVICE_H 00024 00025 #include "BlockDevice.h" 00026 #include "mbed.h" 00027 00028 00029 /** Lazily allocated heap-backed block device 00030 * 00031 * Useful for simulating a block device and tests 00032 * 00033 * @code 00034 * #include "mbed.h" 00035 * #include "HeapBlockDevice.h" 00036 * 00037 * HeapBlockDevice bd(2048, 512); // 2048 bytes with a block size of 512 bytes 00038 * uint8_t block[512] = "Hello World!\n"; 00039 * 00040 * int main() { 00041 * bd.init(); 00042 * bd.program(block, 0); 00043 * bd.read(block, 0); 00044 * printf("%s", block); 00045 * bd.deinit(); 00046 * } 00047 */ 00048 class HeapBlockDevice : public BlockDevice 00049 { 00050 public: 00051 00052 /** Lifetime of the memory block device 00053 */ 00054 HeapBlockDevice(bd_size_t size, bd_size_t block=512); 00055 HeapBlockDevice(bd_size_t size, bd_size_t read, bd_size_t program, bd_size_t erase); 00056 virtual ~HeapBlockDevice(); 00057 00058 /** Initialize a block device 00059 * 00060 * @return 0 on success or a negative error code on failure 00061 */ 00062 virtual int init(); 00063 00064 /** Deinitialize a block device 00065 * 00066 * @return 0 on success or a negative error code on failure 00067 */ 00068 virtual int deinit(); 00069 00070 /** Read blocks from a block device 00071 * 00072 * @param buffer Buffer to read blocks into 00073 * @param addr Address of block to begin reading from 00074 * @param size Size to read in bytes, must be a multiple of read block size 00075 * @return 0 on success, negative error code on failure 00076 */ 00077 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); 00078 00079 /** Program blocks to a block device 00080 * 00081 * The blocks must have been erased prior to being programmed 00082 * 00083 * @param buffer Buffer of data to write to blocks 00084 * @param addr Address of block to begin writing to 00085 * @param size Size to write in bytes, must be a multiple of program block size 00086 * @return 0 on success, negative error code on failure 00087 */ 00088 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); 00089 00090 /** Erase blocks on a block device 00091 * 00092 * The state of an erased block is undefined until it has been programmed 00093 * 00094 * @param addr Address of block to begin erasing 00095 * @param size Size to erase in bytes, must be a multiple of erase block size 00096 * @return 0 on success, negative error code on failure 00097 */ 00098 virtual int erase(bd_addr_t addr, bd_size_t size); 00099 00100 /** Get the size of a readable block 00101 * 00102 * @return Size of a readable block in bytes 00103 */ 00104 virtual bd_size_t get_read_size() const; 00105 00106 /** Get the size of a programable block 00107 * 00108 * @return Size of a programable block in bytes 00109 */ 00110 virtual bd_size_t get_program_size() const; 00111 00112 /** Get the size of a eraseable block 00113 * 00114 * @return Size of a eraseable block in bytes 00115 */ 00116 virtual bd_size_t get_erase_size() const; 00117 00118 /** Get the total size of the underlying device 00119 * 00120 * @return Size of the underlying device in bytes 00121 */ 00122 virtual bd_size_t size() const; 00123 00124 private: 00125 bd_size_t _read_size; 00126 bd_size_t _program_size; 00127 bd_size_t _erase_size; 00128 bd_size_t _count; 00129 uint8_t **_blocks; 00130 }; 00131 00132 00133 #endif 00134
Generated on Tue Jul 12 2022 14:46:47 by
1.7.2
