Mistake on this page?
Report an issue in GitHub or email us
FlashIAPBlockDevice.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2016 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 #ifndef MBED_FLASHIAP_BLOCK_DEVICE_H
19 #define MBED_FLASHIAP_BLOCK_DEVICE_H
20 
21 #if DEVICE_FLASH
22 
23 #include "FlashIAP.h"
24 #include "blockdevice/BlockDevice.h"
25 #include "platform/mbed_toolchain.h"
26 
27 /** BlockDevice using the FlashIAP API
28  *
29  */
31 public:
32 
33  /** Creates a FlashIAPBlockDevice
34  *
35  * @param address Physical address where the block device start
36  * @param size The block device size
37  */
38  FlashIAPBlockDevice(uint32_t address = MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS,
39  uint32_t size = MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE);
40 
41  virtual ~FlashIAPBlockDevice();
42 
43  /** Initialize a block device
44  *
45  * @return 0 on success or a negative error code on failure
46  */
47  virtual int init();
48 
49  /** Deinitialize a block device
50  *
51  * @return 0 on success or a negative error code on failure
52  */
53  virtual int deinit();
54 
55  /** Read blocks from a block device
56  *
57  * @param buffer Buffer to write blocks to
58  * @param addr Address of block to begin reading from
59  * @param size Size to read in bytes, must be a multiple of read block size
60  * @return 0 on success, negative error code on failure
61  */
62  virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
63 
64  /** Program blocks to a block device
65  *
66  * The blocks must have been erased prior to being programmed
67  *
68  * @param buffer Buffer of data to write to blocks
69  * @param addr Address of block to begin writing to
70  * @param size Size to write in bytes, must be a multiple of program block size
71  * @return 0 on success, negative error code on failure
72  */
73  virtual int program(const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
74 
75  /** Erase blocks on a block device
76  *
77  * The state of an erased block is undefined until it has been programmed
78  *
79  * @param addr Address of block to begin erasing
80  * @param size Size to erase in bytes, must be a multiple of erase block size
81  * @return 0 on success, negative error code on failure
82  */
83  virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size);
84 
85  /** Get the size of a readable block
86  *
87  * @return Size of a readable block in bytes
88  */
89  virtual mbed::bd_size_t get_read_size() const;
90 
91  /** Get the size of a programable block
92  *
93  * @return Size of a programable block in bytes
94  * @note Must be a multiple of the read size
95  */
96  virtual mbed::bd_size_t get_program_size() const;
97 
98  /** Get the size of a eraseable block
99  *
100  * @return Size of a eraseable block in bytes
101  * @note Must be a multiple of the program size
102  */
103  virtual mbed::bd_size_t get_erase_size() const;
104 
105  /** Get the size of an erasable block given address
106  *
107  * @param addr Address within the erasable block
108  * @return Size of an erasable block in bytes
109  * @note Must be a multiple of the program size
110  */
111  virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr) const;
112 
113  /** Get the value of storage when erased
114  *
115  * @return The value of storage when erased
116  */
117  virtual int get_erase_value() const;
118 
119  /** Get the total size of the underlying device
120  *
121  * @return Size of the underlying device in bytes
122  */
123  virtual mbed::bd_size_t size() const;
124 
125  /** Get the BlockDevice class type.
126  *
127  * @return A string represent the BlockDevice class type.
128  */
129  virtual const char *get_type() const;
130 
131  /** Convenience function for checking block erase validity
132  *
133  * @param addr Address of block to begin erasing
134  * @param size Size to erase in bytes
135  * @return True if erase is valid for underlying block device
136  */
137  virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const;
138 
139 
140 private:
141  // Device configuration
142  mbed::FlashIAP _flash;
143  mbed::bd_addr_t _base;
144  mbed::bd_size_t _size;
145  bool _is_initialized;
146  uint32_t _init_ref_count;
147 };
148 
149 #endif /* DEVICE_FLASH */
150 #endif /* MBED_FLASHIAP_BLOCK_DEVICE_H */
virtual mbed::bd_size_t get_erase_size() const
Get the size of a eraseable block.
virtual int program(const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Program blocks to a block device.
A hardware device capable of writing and reading blocks.
Definition: BlockDevice.h:47
virtual int init()
Initialize a block device.
virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
Read blocks from a block device.
BlockDevice using the FlashIAP API.
virtual mbed::bd_size_t size() const
Get the total size of the underlying device.
FlashIAPBlockDevice(uint32_t address=MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS, uint32_t size=MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE)
Creates a FlashIAPBlockDevice.
virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size)
Erase blocks on a block device.
virtual mbed::bd_size_t get_read_size() const
Get the size of a readable block.
Flash IAP driver.
Definition: FlashIAP.h:66
virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const
Convenience function for checking block erase validity.
virtual int deinit()
Deinitialize a block device.
virtual const char * get_type() const
Get the BlockDevice class type.
virtual int get_erase_value() const
Get the value of storage when erased.
virtual mbed::bd_size_t get_program_size() const
Get the size of a programable 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.