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  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MBED_FLASHIAP_BLOCK_DEVICE_H
18 #define MBED_FLASHIAP_BLOCK_DEVICE_H
19 
20 #if DEVICE_FLASH
21 
22 #include "FlashIAP.h"
23 #include "BlockDevice.h"
24 #include "platform/mbed_toolchain.h"
25 
26 /** BlockDevice using the FlashIAP API
27  *
28  */
30 public:
31 
32  /** Creates a FlashIAPBlockDevice
33  *
34  * @param address Physical address where the block device start
35  * @param size The block device size
36  */
37  FlashIAPBlockDevice(uint32_t address = MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS,
38  uint32_t size = MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE);
39 
40  virtual ~FlashIAPBlockDevice();
41 
42  /** Initialize a block device
43  *
44  * @return 0 on success or a negative error code on failure
45  */
46  virtual int init();
47 
48  /** Deinitialize a block device
49  *
50  * @return 0 on success or a negative error code on failure
51  */
52  virtual int deinit();
53 
54  /** Read blocks from a block device
55  *
56  * @param buffer Buffer to write blocks to
57  * @param addr Address of block to begin reading from
58  * @param size Size to read in bytes, must be a multiple of read block size
59  * @return 0 on success, negative error code on failure
60  */
61  virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
62 
63  /** Program blocks to a block device
64  *
65  * The blocks must have been erased prior to being programmed
66  *
67  * @param buffer Buffer of data to write to blocks
68  * @param addr Address of block to begin writing to
69  * @param size Size to write in bytes, must be a multiple of program block size
70  * @return 0 on success, negative error code on failure
71  */
72  virtual int program(const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
73 
74  /** Erase blocks on a block device
75  *
76  * The state of an erased block is undefined until it has been programmed
77  *
78  * @param addr Address of block to begin erasing
79  * @param size Size to erase in bytes, must be a multiple of erase block size
80  * @return 0 on success, negative error code on failure
81  */
82  virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size);
83 
84  /** Get the size of a readable block
85  *
86  * @return Size of a readable block in bytes
87  */
88  virtual mbed::bd_size_t get_read_size() const;
89 
90  /** Get the size of a programable block
91  *
92  * @return Size of a programable block in bytes
93  * @note Must be a multiple of the read size
94  */
95  virtual mbed::bd_size_t get_program_size() const;
96 
97  /** Get the size of a eraseable block
98  *
99  * @return Size of a eraseable block in bytes
100  * @note Must be a multiple of the program size
101  */
102  virtual mbed::bd_size_t get_erase_size() const;
103 
104  /** Get the size of an erasable block given address
105  *
106  * @param addr Address within the erasable block
107  * @return Size of an erasable block in bytes
108  * @note Must be a multiple of the program size
109  */
110  virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr) const;
111 
112  /** Get the value of storage when erased
113  *
114  * @return The value of storage when erased
115  */
116  virtual int get_erase_value() const;
117 
118  /** Get the total size of the underlying device
119  *
120  * @return Size of the underlying device in bytes
121  */
122  virtual mbed::bd_size_t size() const;
123 
124  /** Get the BlockDevice class type.
125  *
126  * @return A string represent the BlockDevice class type.
127  */
128  virtual const char *get_type() const;
129 
130  /** Convenience function for checking block erase validity
131  *
132  * @param addr Address of block to begin erasing
133  * @param size Size to erase in bytes
134  * @return True if erase is valid for underlying block device
135  */
136  virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const;
137 
138 
139 private:
140  // Device configuration
141  mbed::FlashIAP _flash;
142  mbed::bd_addr_t _base;
143  mbed::bd_size_t _size;
144  bool _is_initialized;
145  uint32_t _init_ref_count;
146 };
147 
148 #endif /* DEVICE_FLASH */
149 #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:59
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.