Mistake on this page?
Report an issue in GitHub or email us
ProfilingBlockDevice.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2017 ARM Limited
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 
23 /** \addtogroup storage */
24 /** @{*/
25 
26 #ifndef MBED_PROFILING_BLOCK_DEVICE_H
27 #define MBED_PROFILING_BLOCK_DEVICE_H
28 
29 #include "BlockDevice.h"
30 
31 namespace mbed {
32 
33 
34 /** Block device for measuring storage operations of another block device
35  */
37 public:
38  /** Lifetime of the memory block device
39  *
40  * @param bd Block device to back the ProfilingBlockDevice
41  */
43 
44  /** Lifetime of a block device
45  */
46  virtual ~ProfilingBlockDevice() {};
47 
48  /** Initialize a block device
49  *
50  * @return 0 on success or a negative error code on failure
51  * @note The init and deinit functions do not effect profile counts
52  */
53  virtual int init();
54 
55  /** Deinitialize a block device
56  *
57  * @return 0 on success or a negative error code on failure
58  * @note The init and deinit functions do not effect profile counts
59  */
60  virtual int deinit();
61 
62  /** Ensure data on storage is in sync with the driver
63  *
64  * @return 0 on success or a negative error code on failure
65  */
66  virtual int sync();
67 
68  /** Read blocks from a block device
69  *
70  * @param buffer Buffer to read blocks into
71  * @param addr Address of block to begin reading from
72  * @param size Size to read in bytes, must be a multiple of read block size
73  * @return 0 on success or a negative error code on failure
74  */
75  virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
76 
77  /** Program blocks to a block device
78  *
79  * The blocks must have been erased prior to being programmed
80  *
81  * @param buffer Buffer of data to write to blocks
82  * @param addr Address of block to begin writing to
83  * @param size Size to write in bytes, must be a multiple of program block size
84  * @return 0 on success or a negative error code on failure
85  */
86  virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
87 
88  /** Erase blocks on a block device
89  *
90  * The state of an erased block is undefined until it has been programmed,
91  * unless get_erase_value returns a non-negative byte value
92  *
93  * @param addr Address of block to begin erasing
94  * @param size Size to erase in bytes, must be a multiple of erase block size
95  * @return 0 on success or a negative error code on failure
96  */
97  virtual int erase(bd_addr_t addr, bd_size_t size);
98 
99  /** Get the size of a readable block
100  *
101  * @return Size of a readable block in bytes
102  */
103  virtual bd_size_t get_read_size() const;
104 
105  /** Get the size of a programmable block
106  *
107  * @return Size of a programmable block in bytes
108  * @note Must be a multiple of the read size
109  */
110  virtual bd_size_t get_program_size() const;
111 
112  /** Get the size of an erasable block
113  *
114  * @return Size of an erasable block in bytes
115  * @note Must be a multiple of the program size
116  */
117  virtual bd_size_t get_erase_size() const;
118 
119  /** Get the size of an erasable block given address
120  *
121  * @param addr Address within the erasable block
122  * @return Size of an erasable block in bytes
123  * @note Must be a multiple of the program size
124  */
125  virtual bd_size_t get_erase_size(bd_addr_t addr) const;
126 
127  /** Get the value of storage when erased
128  *
129  * If get_erase_value returns a non-negative byte value, the underlying
130  * storage is set to that value when erased, and you can program storage
131  * containing that value without another erase.
132  *
133  * @return The value of storage when erased, or -1 if you can't
134  * rely on the value of erased storage
135  */
136  virtual int get_erase_value() const;
137 
138  /** Get the total size of the underlying device
139  *
140  * @return Size of the underlying device in bytes
141  */
142  virtual bd_size_t size() const;
143 
144  /** Reset the current profile counts to zero
145  */
146  void reset();
147 
148  /** Get number of bytes that have been read from the block device
149  *
150  * @return The number of bytes that have been read from the block device
151  */
152  bd_size_t get_read_count() const;
153 
154  /** Get number of bytes that have been programed to the block device
155  *
156  * @return The number of bytes that have been programed to the block device
157  */
158  bd_size_t get_program_count() const;
159 
160  /** Get number of bytes that have been erased from the block device
161  *
162  * @return The number of bytes that have been erased from the block device
163  */
164  bd_size_t get_erase_count() const;
165 
166  /** Get the BlockDevice class type.
167  *
168  * @return A string represent the BlockDevice class type.
169  */
170  virtual const char *get_type() const;
171 
172 private:
173  BlockDevice *_bd;
174  bd_size_t _read_count;
175  bd_size_t _program_count;
176  bd_size_t _erase_count;
177 };
178 
179 } // namespace mbed
180 
181 // Added "using" for backwards compatibility
182 #ifndef MBED_NO_GLOBAL_USING_DIRECTIVE
184 #endif
185 
186 #endif
187 
188 /** @}*/
virtual int read(void *buffer, bd_addr_t addr, bd_size_t size)
Read blocks from a block device.
A hardware device capable of writing and reading blocks.
Definition: BlockDevice.h:48
void reset()
Reset the current profile counts to zero.
virtual bd_size_t size() const
Get the total size of the underlying device.
virtual bd_size_t get_program_size() const
Get the size of a programmable block.
virtual bd_size_t get_read_size() const
Get the size of a readable block.
virtual int sync()
Ensure data on storage is in sync with the driver.
ProfilingBlockDevice(BlockDevice *bd)
Lifetime of the memory block device.
virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size)
Program blocks to a block device.
virtual ~ProfilingBlockDevice()
Lifetime of a block device.
bd_size_t get_program_count() const
Get number of bytes that have been programed to the block device.
bd_size_t get_erase_count() const
Get number of bytes that have been erased from the block device.
virtual int init()
Initialize a block device.
Block device for measuring storage operations of another block device.
virtual bd_size_t get_erase_size() const
Get the size of an erasable block.
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 const char * get_type() const
Get the BlockDevice class type.
Definition: ATHandler.h:46
virtual int deinit()
Deinitialize a block device.
virtual int erase(bd_addr_t addr, bd_size_t size)
Erase blocks on a block device.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.