Mistake on this page?
Report an issue in GitHub or email us
FlashSimBlockDevice.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2018-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 /** \addtogroup storage */
19 /** @{*/
20 
21 #ifndef MBED_FLASH_SIM_BLOCK_DEVICE_H
22 #define MBED_FLASH_SIM_BLOCK_DEVICE_H
23 
24 #include "BlockDevice.h"
25 
26 namespace mbed {
27 
28 enum {
29  BD_ERROR_NOT_ERASED = -3201,
30 };
31 
32 /** Flash simulating block device
33  *
34  * Flash simulation BD adaptor
35  *
36  */
38 public:
39 
40  /** Constructor
41  *
42  * @param bd Block device to back the FlashSimBlockDevice
43  * @param erase_value Value stored in a block after it's erased
44  */
45  FlashSimBlockDevice(BlockDevice *bd, uint8_t erase_value = 0xFF);
46  virtual ~FlashSimBlockDevice();
47 
48  /** Initialize a block device
49  *
50  * @return 0 on success or a negative error code on failure
51  */
52  virtual int init();
53 
54  /** Deinitialize the block device
55  *
56  * @return 0 on success or a negative error code on failure
57  */
58  virtual int deinit();
59 
60  /** Ensure data on storage is in sync with the driver
61  *
62  * @return 0 on success or a negative error code on failure
63  */
64  virtual int sync();
65 
66  /** Read blocks from the block device
67  *
68  * @param buffer Buffer to read blocks into
69  * @param addr Address of block to begin reading from
70  * @param size Size to read in bytes, must be a multiple of read block size
71  * @return 0 on success, negative error code on failure
72  */
73  virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
74 
75  /** Program blocks to the block device
76  *
77  * The blocks must have been erased prior to being programmed
78  *
79  * @param buffer Buffer of data to write to blocks
80  * @param addr Address of block to begin writing to
81  * @param size Size to write in bytes, must be a multiple of program block size
82  * @return 0 on success, negative error code on failure
83  */
84  virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
85 
86  /** Erase blocks on the block device
87  *
88  * Required before any write to these addresses
89  *
90  * @param addr Address of block to begin erasing
91  * @param size Size to erase in bytes, must be a multiple of erase block size
92  * @return 0 on success, negative error code on failure
93  */
94  virtual int erase(bd_addr_t addr, bd_size_t size);
95 
96  /** Get the size of a readable block
97  *
98  * @return Size of a readable block in bytes
99  */
100  virtual bd_size_t get_read_size() const;
101 
102  /** Get the size of a programmable block
103  *
104  * @return Size of a programmable block in bytes
105  */
106  virtual bd_size_t get_program_size() const;
107 
108  /** Get the size of an erasable block
109  *
110  * @return Size of an erasable block in bytes
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  * @return The value of storage when erased
125  */
126  virtual int get_erase_value() const;
127 
128  /** Get the total size of the underlying device
129  *
130  * @return Size of the underlying device in bytes
131  */
132  virtual bd_size_t size() const;
133 
134  /** Get the BlockDevice class type.
135  *
136  * @return A string represent the BlockDevice class type.
137  */
138  virtual const char *get_type() const;
139 
140 private:
141  uint8_t _erase_value;
142  bd_size_t _blank_buf_size;
143  uint8_t *_blank_buf;
144  BlockDevice *_bd;
145  uint32_t _init_ref_count;
146  bool _is_initialized;
147 };
148 
149 } // namespace mbed
150 
151 // Added "using" for backwards compatibility
152 #ifndef MBED_NO_GLOBAL_USING_DIRECTIVE
154 #endif
155 
156 #endif
157 
158 /** @}*/
virtual int read(void *buffer, bd_addr_t addr, bd_size_t size)
Read blocks from the block device.
virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size)
Program blocks to the block device.
virtual bd_size_t get_erase_size() const
Get the size of an erasable block.
A hardware device capable of writing and reading blocks.
Definition: BlockDevice.h:48
Flash simulating block device.
virtual bd_size_t size() const
Get the total size of the underlying device.
virtual int deinit()
Deinitialize the block device.
FlashSimBlockDevice(BlockDevice *bd, uint8_t erase_value=0xFF)
Constructor.
virtual const char * get_type() const
Get the BlockDevice class type.
virtual int erase(bd_addr_t addr, bd_size_t size)
Erase blocks on the block device.
virtual int get_erase_value() const
Get the value of storage when erased.
virtual int init()
Initialize a block device.
virtual bd_size_t get_read_size() const
Get the size of a readable block.
Definition: ATHandler.h:46
virtual int sync()
Ensure data on storage is in sync with the driver.
virtual bd_size_t get_program_size() const
Get the size of a programmable block.
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.