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