Mistake on this page?
Report an issue in GitHub or email us
ReadOnlyBlockDevice.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2017-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_READ_ONLY_BLOCK_DEVICE_H
27 #define MBED_READ_ONLY_BLOCK_DEVICE_H
28 
29 #include "BlockDevice.h"
30 #include "PlatformMutex.h"
31 
32 namespace mbed {
33 
35 public:
36 
37  /** Lifetime of the block device
38  *
39  * @param bd Block device to wrap as read only
40  */
42  virtual ~ReadOnlyBlockDevice();
43 
44  /** Initialize a block device
45  *
46  * @return 0 on success or a negative error code on failure
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  */
54  virtual int deinit();
55 
56  /** Ensure data on storage is in sync with the driver
57  *
58  * @return 0 on success or a negative error code on failure
59  */
60  virtual int sync();
61 
62  /** Read blocks from a block device
63  *
64  * @param buffer Buffer to read blocks into
65  * @param addr Address of block to begin reading from
66  * @param size Size to read in bytes, must be a multiple of read block size
67  * @return 0 on success, negative error code on failure
68  */
69  virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
70 
71  /** Program blocks to a block device
72  *
73  * The blocks must have been erased prior to being programmed
74  *
75  * @param buffer Buffer of data to write to blocks
76  * @param addr Address of block to begin writing to
77  * @param size Size to write in bytes, must be a multiple of program block size
78  * @return 0 on success, negative error code on failure
79  */
80  virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
81 
82  /** Erase blocks on a block device
83  *
84  * The state of an erased block is undefined until it has been programmed,
85  * unless get_erase_value returns a non-negative byte value
86  *
87  * @param addr Address of block to begin erasing
88  * @param size Size to erase in bytes, must be a multiple of erase block size
89  * @return 0 on success, negative error code on failure
90  */
91  virtual int erase(bd_addr_t addr, bd_size_t size);
92 
93  /** Get the size of a readable block
94  *
95  * @return Size of a readable block in bytes
96  */
97  virtual bd_size_t get_read_size() const;
98 
99  /** Get the size of a programmable block
100  *
101  * @return Size of a programmable block in bytes
102  */
103  virtual bd_size_t get_program_size() const;
104 
105  /** Get the size of an erasable block
106  *
107  * @return Size of an erasable block in bytes
108  */
109  virtual bd_size_t get_erase_size() const;
110 
111  /** Get the size of an erasable block given address
112  *
113  * @param addr Address within the erasable block
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(bd_addr_t addr) const;
118 
119  /** Get the value of storage when erased
120  *
121  * If get_erase_value returns a non-negative byte value, the underlying
122  * storage is set to that value when erased, and storage containing
123  * that value can be programmed without another erase.
124  *
125  * @return The value of storage when erased, or -1 if you can't
126  * rely on the value of erased storage
127  */
128  virtual int get_erase_value() const;
129 
130  /** Get the total size of the underlying device
131  *
132  * @return Size of the underlying device in bytes
133  */
134  virtual bd_size_t size() const;
135 
136  /** Get the BlockDevice class type.
137  *
138  * @return A string represent the BlockDevice class type.
139  */
140  virtual const char *get_type() const;
141 
142 private:
143  BlockDevice *_bd;
144 };
145 
146 } // namespace mbed
147 
148 // Added "using" for backwards compatibility
149 #ifndef MBED_NO_GLOBAL_USING_DIRECTIVE
151 #endif
152 
153 #endif
154 
155 /** @}*/
virtual bd_size_t get_program_size() const
Get the size of a programmable block.
virtual int erase(bd_addr_t addr, bd_size_t size)
Erase blocks on a block device.
virtual bd_size_t get_read_size() const
Get the size of a readable block.
A hardware device capable of writing and reading blocks.
Definition: BlockDevice.h:47
virtual int read(void *buffer, bd_addr_t addr, bd_size_t size)
Read blocks from a block device.
virtual int sync()
Ensure data on storage is in sync with the driver.
virtual int init()
Initialize a block device.
virtual bd_size_t get_erase_size() const
Get the size of an erasable block.
virtual int deinit()
Deinitialize a block device.
virtual const char * get_type() const
Get the BlockDevice class type.
ReadOnlyBlockDevice(BlockDevice *bd)
Lifetime of the block device.
virtual bd_size_t size() const
Get the total size of the underlying device.
virtual int get_erase_value() const
Get the value of storage when erased.
Definition: ATHandler.h:46
virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size)
Program blocks to 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.