flashpage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freie Universit├Ąt Berlin
3  * 2017 Inria
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
48 #ifndef PERIPH_FLASHPAGE_H
49 #define PERIPH_FLASHPAGE_H
50 
51 #include <stdint.h>
52 
53 #include "cpu_conf.h"
54 #include "periph_cpu.h"
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
63 #ifndef CPU_FLASH_BASE
64 #define CPU_FLASH_BASE (0)
65 #endif
66 
72 #ifdef DOXYGEN
73 #define FLASHPAGE_RAW_BLOCKSIZE
74 #endif
75 
84 #ifdef DOXYGEN
85 #define FLASHPAGE_RAW_ALIGNMENT
86 #endif
87 
92 #ifndef FLASHPAGE_SIZE
93 #error "periph/flashpage: FLASHPAGE_SIZE not defined"
94 #endif
95 #ifndef FLASHPAGE_NUMOF
96 #error "periph/flashpage: FLASHPAGE_NUMOF not defined"
97 #endif
98 
102 enum {
105 };
106 
117 static inline void *flashpage_addr(int page)
118 {
119  return (void *)(CPU_FLASH_BASE + (page * FLASHPAGE_SIZE));
120 }
121 
133 static inline int flashpage_page(void *addr)
134 {
135  return (int)(((int)addr - CPU_FLASH_BASE) / FLASHPAGE_SIZE);
136 }
137 
145 void flashpage_write(int page, const void *data);
146 
168 void flashpage_write_raw(void *target_addr, const void *data, size_t len);
169 
177 void flashpage_read(int page, void *data);
178 
189 int flashpage_verify(int page, const void *data);
190 
203 int flashpage_write_and_verify(int page, const void *data);
204 
218 #ifdef FLASHPAGE_RWWEE_NUMOF
219 
230 static inline void *flashpage_rwwee_addr(int page)
231 {
232  return (void *)(CPU_FLASH_RWWEE_BASE + (page * FLASHPAGE_SIZE));
233 }
234 
246 static inline int flashpage_rwwee_page(void *addr)
247 {
248  return (int)(((int)addr - CPU_FLASH_RWWEE_BASE) / FLASHPAGE_SIZE);
249 }
250 
258 void flashpage_rwwee_write(int page, const void *data);
259 
281 void flashpage_rwwee_write_raw(void *target_addr, const void *data, size_t len);
282 
290 void flashpage_rwwee_read(int page, void *data);
291 
302 int flashpage_rwwee_verify(int page, const void *data);
303 
317 int flashpage_rwwee_write_and_verify(int page, const void *data);
318 
319 #endif /* FLASHPAGE_RWWEE_NUMOF */
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 
325 #endif /* PERIPH_FLASHPAGE_H */
326 
#define CPU_FLASH_BASE
Per default, we expect the internal flash to start at address 0.
Definition: flashpage.h:64
everything succeeded
Definition: flashpage.h:103
static void * flashpage_addr(int page)
Translate the given page number into the page&#39;s starting address.
Definition: flashpage.h:117
static int flashpage_page(void *addr)
Translate the given address into the corresponding page number.
Definition: flashpage.h:133
int flashpage_write_and_verify(int page, const void *data)
Write the given page and verify the results.
#define FLASHPAGE_SIZE
Flash page configuration.
Definition: cpu_conf.h:44
int flashpage_verify(int page, const void *data)
Verify the given page against the given data.
page differs from target data
Definition: flashpage.h:104
void flashpage_read(int page, void *data)
Read the given page into the given memory location.
void flashpage_write_raw(void *target_addr, const void *data, size_t len)
Write any number of data bytes to a given location in the flash memory.
void flashpage_write(int page, const void *data)
Write the given page with the given data.