Mbed OS Reference
Loading...
Searching...
No Matches
ProfilingBlockDevice.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2017-2020 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
19#ifndef MBED_PROFILING_BLOCK_DEVICE_H
20#define MBED_PROFILING_BLOCK_DEVICE_H
21
22#include "BlockDevice.h"
23
24namespace mbed {
25
26/** \addtogroup storage-blockdevice */
27/** @{*/
28
29/** Block device for measuring storage operations of another block device
30 */
32public:
33 /** Lifetime of the memory block device
34 *
35 * @param bd Block device to back the ProfilingBlockDevice
36 */
38
39 /** Lifetime of a block device
40 */
42
43 /** Initialize a block device
44 *
45 * @return 0 on success or a negative error code on failure
46 * @note The init and deinit functions do not effect profile counts
47 */
48 virtual int init();
49
50 /** Deinitialize a block device
51 *
52 * @return 0 on success or a negative error code on failure
53 * @note The init and deinit functions do not effect profile counts
54 */
55 virtual int deinit();
56
57 /** Ensure data on storage is in sync with the driver
58 *
59 * @return 0 on success or a negative error code on failure
60 */
61 virtual int sync();
62
63 /** Read blocks from a block device
64 *
65 * @param buffer Buffer to read blocks into
66 * @param addr Address of block to begin reading from
67 * @param size Size to read in bytes, must be a multiple of read block size
68 * @return 0 on success or a negative error code on failure
69 */
70 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
71
72 /** Program blocks to a block device
73 *
74 * The blocks must have been erased prior to being programmed
75 *
76 * @param buffer Buffer of data to write to blocks
77 * @param addr Address of block to begin writing to
78 * @param size Size to write in bytes, must be a multiple of program block size
79 * @return 0 on success or a negative error code on failure
80 */
81 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
82
83 /** Erase blocks on a block device
84 *
85 * The state of an erased block is undefined until it has been programmed,
86 * unless get_erase_value returns a non-negative byte value
87 *
88 * @param addr Address of block to begin erasing
89 * @param size Size to erase in bytes, must be a multiple of erase block size
90 * @return 0 on success or a negative error code on failure
91 */
92 virtual int erase(bd_addr_t addr, bd_size_t size);
93
94 /** Get the size of a readable block
95 *
96 * @return Size of a readable block in bytes
97 */
98 virtual bd_size_t get_read_size() const;
99
100 /** Get the size of a programmable block
101 *
102 * @return Size of a programmable block in bytes
103 * @note Must be a multiple of the read size
104 */
106
107 /** Get the size of an erasable block
108 *
109 * @return Size of an erasable block in bytes
110 * @note Must be a multiple of the program size
111 */
112 virtual bd_size_t get_erase_size() const;
113
114 /** Get the size of an erasable block given address
115 *
116 * @param addr Address within the erasable block
117 * @return Size of an erasable block in bytes
118 * @note Must be a multiple of the program size
119 */
120 virtual bd_size_t get_erase_size(bd_addr_t addr) const;
121
122 /** Get the value of storage when erased
123 *
124 * If get_erase_value returns a non-negative byte value, the underlying
125 * storage is set to that value when erased, and you can program storage
126 * containing that value without another erase.
127 *
128 * @return The value of storage when erased, or -1 if you can't
129 * rely on the value of erased storage
130 */
131 virtual int get_erase_value() const;
132
133 /** Get the total size of the underlying device
134 *
135 * @return Size of the underlying device in bytes
136 */
137 virtual bd_size_t size() const;
138
139 /** Reset the current profile counts to zero
140 */
141 void reset();
142
143 /** Get number of bytes that have been read from the block device
144 *
145 * @return The number of bytes that have been read from the block device
146 */
148
149 /** Get number of bytes that have been programed to the block device
150 *
151 * @return The number of bytes that have been programed to the block device
152 */
154
155 /** Get number of bytes that have been erased from the block device
156 *
157 * @return The number of bytes that have been erased from the block device
158 */
160
161 /** Get the BlockDevice class type.
162 *
163 * @return A string represent the BlockDevice class type.
164 */
165 virtual const char *get_type() const;
166
167private:
168 BlockDevice *_bd;
169 bd_size_t _read_count;
170 bd_size_t _program_count;
171 bd_size_t _erase_count;
172};
173
174/** @}*/
175
176} // namespace mbed
177
178// Added "using" for backwards compatibility
179#ifndef MBED_NO_GLOBAL_USING_DIRECTIVE
181#endif
182
183#endif
184
A hardware device capable of writing and reading blocks.
Definition: BlockDevice.h:53
Block device for measuring storage operations of another block device.
bd_size_t get_program_count() const
Get number of bytes that have been programed to the block device.
virtual const char * get_type() const
Get the BlockDevice class type.
ProfilingBlockDevice(BlockDevice *bd)
Lifetime of the memory block device.
virtual int erase(bd_addr_t addr, bd_size_t size)
Erase blocks on a block device.
virtual bd_size_t get_program_size() const
Get the size of a programmable block.
virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size)
Program blocks to a block device.
virtual int sync()
Ensure data on storage is in sync with the driver.
virtual bd_size_t get_erase_size() const
Get the size of an erasable block.
virtual int deinit()
Deinitialize a block device.
virtual bd_size_t get_read_size() const
Get the size of a readable block.
virtual bd_size_t size() const
Get the total size of the underlying device.
bd_size_t get_erase_count() const
Get number of bytes that have been erased from the block device.
virtual ~ProfilingBlockDevice()
Lifetime of a block device.
virtual int read(void *buffer, bd_addr_t addr, bd_size_t size)
Read blocks from a block device.
void reset()
Reset the current profile counts to zero.
virtual int init()
Initialize a block device.
bd_size_t get_read_count() const
Get number of bytes that have been read from the block device.
virtual int get_erase_value() const
Get the value of storage when erased.
virtual bd_size_t get_erase_size(bd_addr_t addr) const
Get the size of an erasable block given address.
uint64_t bd_size_t
Type representing a quantity of 8-bit bytes.
Definition: BlockDevice.h:48
uint64_t bd_addr_t
Type representing the address of a specific block.
Definition: BlockDevice.h:44