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