Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2017 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
borlanic 0:380207fcb5c1 5 * of this software and associated documentation files (the "Software"), to deal
borlanic 0:380207fcb5c1 6 * in the Software without restriction, including without limitation the rights
borlanic 0:380207fcb5c1 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
borlanic 0:380207fcb5c1 8 * copies of the Software, and to permit persons to whom the Software is
borlanic 0:380207fcb5c1 9 * furnished to do so, subject to the following conditions:
borlanic 0:380207fcb5c1 10 *
borlanic 0:380207fcb5c1 11 * The above copyright notice and this permission notice shall be included in
borlanic 0:380207fcb5c1 12 * all copies or substantial portions of the Software.
borlanic 0:380207fcb5c1 13 *
borlanic 0:380207fcb5c1 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
borlanic 0:380207fcb5c1 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
borlanic 0:380207fcb5c1 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
borlanic 0:380207fcb5c1 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
borlanic 0:380207fcb5c1 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
borlanic 0:380207fcb5c1 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
borlanic 0:380207fcb5c1 20 * SOFTWARE.
borlanic 0:380207fcb5c1 21 */
borlanic 0:380207fcb5c1 22 #ifndef MBED_EXHAUSTIBLE_BLOCK_DEVICE_H
borlanic 0:380207fcb5c1 23 #define MBED_EXHAUSTIBLE_BLOCK_DEVICE_H
borlanic 0:380207fcb5c1 24
borlanic 0:380207fcb5c1 25 #include "BlockDevice.h"
borlanic 0:380207fcb5c1 26
borlanic 0:380207fcb5c1 27
borlanic 0:380207fcb5c1 28 /** Heap backed block device which simulates failures
borlanic 0:380207fcb5c1 29 *
borlanic 0:380207fcb5c1 30 * Similar to heap block device but sectors wear out and are no longer programmable
borlanic 0:380207fcb5c1 31 * after a configurable number of cycles.
borlanic 0:380207fcb5c1 32 *
borlanic 0:380207fcb5c1 33 */
borlanic 0:380207fcb5c1 34 class ExhaustibleBlockDevice : public BlockDevice
borlanic 0:380207fcb5c1 35 {
borlanic 0:380207fcb5c1 36 public:
borlanic 0:380207fcb5c1 37 /** Lifetime of the block device
borlanic 0:380207fcb5c1 38 *
borlanic 0:380207fcb5c1 39 * @param bd Block device to back the ExhaustibleBlockDevice
borlanic 0:380207fcb5c1 40 * @param erase_cycles Number of erase cycles before failure
borlanic 0:380207fcb5c1 41 */
borlanic 0:380207fcb5c1 42 ExhaustibleBlockDevice(BlockDevice *bd, uint32_t erase_cycles);
borlanic 0:380207fcb5c1 43 virtual ~ExhaustibleBlockDevice();
borlanic 0:380207fcb5c1 44
borlanic 0:380207fcb5c1 45 /**
borlanic 0:380207fcb5c1 46 * Get the number of erase cycles remaining on a block
borlanic 0:380207fcb5c1 47 *
borlanic 0:380207fcb5c1 48 * @param addr Any address in the block being queried for erase cycles
borlanic 0:380207fcb5c1 49 * @return Number of erase cycles remaining
borlanic 0:380207fcb5c1 50 */
borlanic 0:380207fcb5c1 51 uint32_t get_erase_cycles(bd_addr_t addr) const;
borlanic 0:380207fcb5c1 52
borlanic 0:380207fcb5c1 53 /**
borlanic 0:380207fcb5c1 54 * Set the number of erase cycles before failure
borlanic 0:380207fcb5c1 55 *
borlanic 0:380207fcb5c1 56 * @param addr Any address in the block being queried for erase cycles
borlanic 0:380207fcb5c1 57 * @param cycles Erase cycles before the block malfunctions
borlanic 0:380207fcb5c1 58 */
borlanic 0:380207fcb5c1 59 void set_erase_cycles(bd_addr_t addr, uint32_t cycles);
borlanic 0:380207fcb5c1 60
borlanic 0:380207fcb5c1 61 /** Initialize a block device
borlanic 0:380207fcb5c1 62 *
borlanic 0:380207fcb5c1 63 * @return 0 on success or a negative error code on failure
borlanic 0:380207fcb5c1 64 */
borlanic 0:380207fcb5c1 65 virtual int init();
borlanic 0:380207fcb5c1 66
borlanic 0:380207fcb5c1 67 /** Deinitialize a block device
borlanic 0:380207fcb5c1 68 *
borlanic 0:380207fcb5c1 69 * @return 0 on success or a negative error code on failure
borlanic 0:380207fcb5c1 70 */
borlanic 0:380207fcb5c1 71 virtual int deinit();
borlanic 0:380207fcb5c1 72
borlanic 0:380207fcb5c1 73 /** Ensure data on storage is in sync with the driver
borlanic 0:380207fcb5c1 74 *
borlanic 0:380207fcb5c1 75 * @return 0 on success or a negative error code on failure
borlanic 0:380207fcb5c1 76 */
borlanic 0:380207fcb5c1 77 virtual int sync();
borlanic 0:380207fcb5c1 78
borlanic 0:380207fcb5c1 79 /** Read blocks from a block device
borlanic 0:380207fcb5c1 80 *
borlanic 0:380207fcb5c1 81 * @param buffer Buffer to read blocks into
borlanic 0:380207fcb5c1 82 * @param addr Address of block to begin reading from
borlanic 0:380207fcb5c1 83 * @param size Size to read in bytes, must be a multiple of read block size
borlanic 0:380207fcb5c1 84 * @return 0 on success, negative error code on failure
borlanic 0:380207fcb5c1 85 */
borlanic 0:380207fcb5c1 86 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
borlanic 0:380207fcb5c1 87
borlanic 0:380207fcb5c1 88 /** Program blocks to a block device
borlanic 0:380207fcb5c1 89 *
borlanic 0:380207fcb5c1 90 * The blocks must have been erased prior to being programmed
borlanic 0:380207fcb5c1 91 *
borlanic 0:380207fcb5c1 92 * @param buffer Buffer of data to write to blocks
borlanic 0:380207fcb5c1 93 * @param addr Address of block to begin writing to
borlanic 0:380207fcb5c1 94 * @param size Size to write in bytes, must be a multiple of program block size
borlanic 0:380207fcb5c1 95 * @return 0 on success, negative error code on failure
borlanic 0:380207fcb5c1 96 */
borlanic 0:380207fcb5c1 97 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
borlanic 0:380207fcb5c1 98
borlanic 0:380207fcb5c1 99 /** Erase blocks on a block device
borlanic 0:380207fcb5c1 100 *
borlanic 0:380207fcb5c1 101 * The state of an erased block is undefined until it has been programmed,
borlanic 0:380207fcb5c1 102 * unless get_erase_value returns a non-negative byte value
borlanic 0:380207fcb5c1 103 *
borlanic 0:380207fcb5c1 104 * @param addr Address of block to begin erasing
borlanic 0:380207fcb5c1 105 * @param size Size to erase in bytes, must be a multiple of erase block size
borlanic 0:380207fcb5c1 106 * @return 0 on success, negative error code on failure
borlanic 0:380207fcb5c1 107 */
borlanic 0:380207fcb5c1 108 virtual int erase(bd_addr_t addr, bd_size_t size);
borlanic 0:380207fcb5c1 109
borlanic 0:380207fcb5c1 110 /** Get the size of a readable block
borlanic 0:380207fcb5c1 111 *
borlanic 0:380207fcb5c1 112 * @return Size of a readable block in bytes
borlanic 0:380207fcb5c1 113 */
borlanic 0:380207fcb5c1 114 virtual bd_size_t get_read_size() const;
borlanic 0:380207fcb5c1 115
borlanic 0:380207fcb5c1 116 /** Get the size of a programmable block
borlanic 0:380207fcb5c1 117 *
borlanic 0:380207fcb5c1 118 * @return Size of a programmable block in bytes
borlanic 0:380207fcb5c1 119 */
borlanic 0:380207fcb5c1 120 virtual bd_size_t get_program_size() const;
borlanic 0:380207fcb5c1 121
borlanic 4:75df35ef4fb6 122 /** Get the size of an erasable block
borlanic 0:380207fcb5c1 123 *
borlanic 4:75df35ef4fb6 124 * @return Size of an erasable block in bytes
borlanic 0:380207fcb5c1 125 */
borlanic 0:380207fcb5c1 126 virtual bd_size_t get_erase_size() const;
borlanic 0:380207fcb5c1 127
borlanic 4:75df35ef4fb6 128 /** Get the size of an erasable block given address
borlanic 4:75df35ef4fb6 129 *
borlanic 4:75df35ef4fb6 130 * @param addr Address within the erasable block
borlanic 4:75df35ef4fb6 131 * @return Size of an erasable block in bytes
borlanic 4:75df35ef4fb6 132 * @note Must be a multiple of the program size
borlanic 4:75df35ef4fb6 133 */
borlanic 4:75df35ef4fb6 134 virtual bd_size_t get_erase_size(bd_addr_t addr) const;
borlanic 4:75df35ef4fb6 135
borlanic 0:380207fcb5c1 136 /** Get the value of storage when erased
borlanic 0:380207fcb5c1 137 *
borlanic 0:380207fcb5c1 138 * If get_erase_value returns a non-negative byte value, the underlying
borlanic 0:380207fcb5c1 139 * storage is set to that value when erased, and storage containing
borlanic 0:380207fcb5c1 140 * that value can be programmed without another erase.
borlanic 0:380207fcb5c1 141 *
borlanic 0:380207fcb5c1 142 * @return The value of storage when erased, or -1 if you can't
borlanic 0:380207fcb5c1 143 * rely on the value of erased storage
borlanic 0:380207fcb5c1 144 */
borlanic 0:380207fcb5c1 145 virtual int get_erase_value() const;
borlanic 0:380207fcb5c1 146
borlanic 0:380207fcb5c1 147 /** Get the total size of the underlying device
borlanic 0:380207fcb5c1 148 *
borlanic 0:380207fcb5c1 149 * @return Size of the underlying device in bytes
borlanic 0:380207fcb5c1 150 */
borlanic 0:380207fcb5c1 151 virtual bd_size_t size() const;
borlanic 0:380207fcb5c1 152
borlanic 0:380207fcb5c1 153 private:
borlanic 0:380207fcb5c1 154 BlockDevice *_bd;
borlanic 0:380207fcb5c1 155 uint32_t *_erase_array;
borlanic 0:380207fcb5c1 156 uint32_t _erase_cycles;
borlanic 0:380207fcb5c1 157 };
borlanic 0:380207fcb5c1 158
borlanic 0:380207fcb5c1 159
borlanic 0:380207fcb5c1 160 #endif