|
| 1 | +/* |
| 2 | + * Copyright (c) 2018 ARM Limited. All rights reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * Licensed under the Apache License, Version 2.0 (the License); you may |
| 5 | + * not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +#ifndef EMULATEDSD_H |
| 17 | +#define EMULATEDSD_H |
| 18 | + |
| 19 | +#include "features/storage/blockdevice/BlockDevice.h" |
| 20 | + |
| 21 | +class EmulatedSD_Private; |
| 22 | + |
| 23 | +class EmulatedSD : public mbed::BlockDevice { |
| 24 | +public: |
| 25 | + EmulatedSD(const char *path); |
| 26 | + ~EmulatedSD(); |
| 27 | + |
| 28 | + /** Initialize a block device |
| 29 | + * |
| 30 | + * @return 0 on success or a negative error code on failure |
| 31 | + */ |
| 32 | + virtual int init(); |
| 33 | + |
| 34 | + /** Deinitialize a block device |
| 35 | + * |
| 36 | + * @return 0 on success or a negative error code on failure |
| 37 | + */ |
| 38 | + virtual int deinit(); |
| 39 | + |
| 40 | + /** Read blocks from a block device |
| 41 | + * |
| 42 | + * If a failure occurs, it is not possible to determine how many bytes succeeded |
| 43 | + * |
| 44 | + * @param buffer Buffer to write blocks to |
| 45 | + * @param addr Address of block to begin reading from |
| 46 | + * @param size Size to read in bytes, must be a multiple of the read block size |
| 47 | + * @return 0 on success or a negative error code on failure |
| 48 | + */ |
| 49 | + virtual int read(void *buffer, bd_addr_t addr, bd_size_t size); |
| 50 | + |
| 51 | + /** Program blocks to a block device |
| 52 | + * |
| 53 | + * The blocks must have been erased prior to being programmed |
| 54 | + * |
| 55 | + * If a failure occurs, it is not possible to determine how many bytes succeeded |
| 56 | + * |
| 57 | + * @param buffer Buffer of data to write to blocks |
| 58 | + * @param addr Address of block to begin writing to |
| 59 | + * @param size Size to write in bytes, must be a multiple of the program block size |
| 60 | + * @return 0 on success or a negative error code on failure |
| 61 | + */ |
| 62 | + virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size); |
| 63 | + |
| 64 | + /** Get the size of a readable block |
| 65 | + * |
| 66 | + * @return Size of a readable block in bytes |
| 67 | + */ |
| 68 | + virtual bd_size_t get_read_size() const; |
| 69 | + |
| 70 | + /** Get the size of a programmable block |
| 71 | + * |
| 72 | + * @return Size of a programmable block in bytes |
| 73 | + * @note Must be a multiple of the read size |
| 74 | + */ |
| 75 | + virtual bd_size_t get_program_size() const; |
| 76 | + |
| 77 | + /** Get the total size of the underlying device |
| 78 | + * |
| 79 | + * @return Size of the underlying device in bytes |
| 80 | + */ |
| 81 | + virtual bd_size_t size() const; |
| 82 | + |
| 83 | + /** Get the BlockDevice class type. |
| 84 | + * |
| 85 | + * @return A string represent the BlockDevice class type. |
| 86 | + */ |
| 87 | + virtual const char *get_type() const; |
| 88 | +private: |
| 89 | + EmulatedSD_Private *_p; |
| 90 | +}; |
| 91 | + |
| 92 | +#endif // EMULATEDSD_H |
0 commit comments