1
+ /* mbed Microcontroller Library
2
+ * Copyright (c) 2006-2019 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
+
1
17
#include "flash_api.h"
2
18
#include "nvm.h"
3
19
6
22
* @param obj The flash object
7
23
* @return 0 for success, -1 for error
8
24
*/
9
- int32_t flash_init (flash_t * obj ) {
25
+ int32_t flash_init (flash_t * obj )
26
+ {
10
27
nvm_get_parameters (& obj -> params );
11
28
12
29
const struct nvm_config config = {
@@ -29,7 +46,8 @@ int32_t flash_init(flash_t *obj) {
29
46
* @param obj The flash object
30
47
* @return 0 for success, -1 for error
31
48
*/
32
- int32_t flash_free (flash_t * obj ) {
49
+ int32_t flash_free (flash_t * obj )
50
+ {
33
51
// no-op
34
52
return 0 ;
35
53
}
@@ -41,7 +59,8 @@ int32_t flash_free(flash_t *obj) {
41
59
* @param address The sector starting address
42
60
* @return 0 for success, -1 for error
43
61
*/
44
- int32_t flash_erase_sector (flash_t * obj , uint32_t address ) {
62
+ int32_t flash_erase_sector (flash_t * obj , uint32_t address )
63
+ {
45
64
enum status_code status = nvm_erase_row (address );
46
65
47
66
return status == STATUS_OK ? 0 : -1 ;
@@ -56,7 +75,8 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address) {
56
75
* @param size The number of bytes to read
57
76
* @return 0 for success, -1 for error
58
77
*/
59
- int32_t flash_read (flash_t * obj , uint32_t address , uint8_t * data , uint32_t size ) {
78
+ int32_t flash_read (flash_t * obj , uint32_t address , uint8_t * data , uint32_t size )
79
+ {
60
80
// apparently you can read / write multiple pages...
61
81
uint32_t page_size = flash_get_page_size (obj );
62
82
if (size % page_size != 0 ) return -1 ;
@@ -91,7 +111,8 @@ int32_t flash_read(flash_t *obj, uint32_t address, uint8_t *data, uint32_t size)
91
111
* @param size The number of bytes to program
92
112
* @return 0 for success, -1 for error
93
113
*/
94
- int32_t flash_program_page (flash_t * obj , uint32_t address , const uint8_t * data , uint32_t size ) {
114
+ int32_t flash_program_page (flash_t * obj , uint32_t address , const uint8_t * data , uint32_t size )
115
+ {
95
116
// apparently you can read / write multiple pages...
96
117
uint32_t page_size = flash_get_page_size (obj );
97
118
if (size % page_size != 0 ) return -1 ;
@@ -122,7 +143,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
122
143
* @param address The sector starting address
123
144
* @return The size of a sector
124
145
*/
125
- uint32_t flash_get_sector_size (const flash_t * obj , uint32_t address ) {
146
+ uint32_t flash_get_sector_size (const flash_t * obj , uint32_t address )
147
+ {
126
148
if (address < flash_get_start_address (obj )) {
127
149
return MBED_FLASH_INVALID_SIZE ;
128
150
}
@@ -140,7 +162,8 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) {
140
162
* @param obj The flash object
141
163
* @return The size of a page
142
164
*/
143
- uint32_t flash_get_page_size (const flash_t * obj ) {
165
+ uint32_t flash_get_page_size (const flash_t * obj )
166
+ {
144
167
return obj -> params .page_size ;
145
168
}
146
169
@@ -149,7 +172,8 @@ uint32_t flash_get_page_size(const flash_t *obj) {
149
172
* @param obj The flash object
150
173
* @return The start address for the flash region
151
174
*/
152
- uint32_t flash_get_start_address (const flash_t * obj ) {
175
+ uint32_t flash_get_start_address (const flash_t * obj )
176
+ {
153
177
return FLASH_ADDR ;
154
178
}
155
179
@@ -158,7 +182,8 @@ uint32_t flash_get_start_address(const flash_t *obj) {
158
182
* @param obj The flash object
159
183
* @return The flash region size
160
184
*/
161
- uint32_t flash_get_size (const flash_t * obj ) {
185
+ uint32_t flash_get_size (const flash_t * obj )
186
+ {
162
187
return FLASH_SIZE ;
163
188
}
164
189
@@ -167,6 +192,7 @@ uint32_t flash_get_size(const flash_t *obj) {
167
192
* @param obj The flash object
168
193
* @return The flash erase value
169
194
*/
170
- uint8_t flash_get_erase_value (const flash_t * obj ) {
195
+ uint8_t flash_get_erase_value (const flash_t * obj )
196
+ {
171
197
return 0xff ;
172
198
}
0 commit comments