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 
38 #ifndef PERIPH_FLASHPAGE_H
39 #define PERIPH_FLASHPAGE_H
40 
41 #include <stdint.h>
42 
43 #include "cpu_conf.h"
44 #include "periph_cpu.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
53 #ifndef CPU_FLASH_BASE
54 #define CPU_FLASH_BASE (0)
55 #endif
56 
62 #ifdef DOXYGEN
63 #define FLASHPAGE_RAW_BLOCKSIZE
64 #endif
65 
74 #ifdef DOXYGEN
75 #define FLASHPAGE_RAW_ALIGNMENT
76 #endif
77 
82 #ifndef FLASHPAGE_SIZE
83 #error "periph/flashpage: FLASHPAGE_SIZE not defined"
84 #endif
85 #ifndef FLASHPAGE_NUMOF
86 #error "periph/flashpage: FLASHPAGE_NUMOF not defined"
87 #endif
88 
92 enum {
95 };
96 
107 static inline void *flashpage_addr(int page)
108 {
109  return (void *)(CPU_FLASH_BASE + (page * FLASHPAGE_SIZE));
110 }
111 
123 static inline int flashpage_page(void *addr)
124 {
125  return (int)(((int)addr - CPU_FLASH_BASE) / FLASHPAGE_SIZE);
126 }
127 
135 void flashpage_write(int page, const void *data);
136 
158 void flashpage_write_raw(void *target_addr, const void *data, size_t len);
159 
167 void flashpage_read(int page, void *data);
168 
179 int flashpage_verify(int page, const void *data);
180 
193 int flashpage_write_and_verify(int page, const void *data);
194 
208 #ifdef FLASHPAGE_RWWEE_NUMOF
209 
220 static inline void *flashpage_rwwee_addr(int page)
221 {
222  return (void *)(CPU_FLASH_RWWEE_BASE + (page * FLASHPAGE_SIZE));
223 }
224 
236 static inline int flashpage_rwwee_page(void *addr)
237 {
238  return (int)(((int)addr - CPU_FLASH_RWWEE_BASE) / FLASHPAGE_SIZE);
239 }
240 
248 void flashpage_rwwee_write(int page, const void *data);
249 
271 void flashpage_rwwee_write_raw(void *target_addr, const void *data, size_t len);
272 
280 void flashpage_rwwee_read(int page, void *data);
281 
292 int flashpage_rwwee_verify(int page, const void *data);
293 
307 int flashpage_rwwee_write_and_verify(int page, const void *data);
308 
309 #endif /* FLASHPAGE_RWWEE_NUMOF */
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 
315 #endif /* PERIPH_FLASHPAGE_H */
316 
#define CPU_FLASH_BASE
Per default, we expect the internal flash to start at address 0.
Definition: flashpage.h:54
page differs from target data
Definition: flashpage.h:94
static void * flashpage_addr(int page)
Translate the given page number into the page&#39;s starting address.
Definition: flashpage.h:107
static int flashpage_page(void *addr)
Translate the given address into the corresponding page number.
Definition: flashpage.h:123
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.
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.
everything succeeded
Definition: flashpage.h:93