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_WRITE_BLOCK_SIZE
74 #endif
75 
84 #ifdef DOXYGEN
85 #define FLASHPAGE_WRITE_BLOCK_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(unsigned page)
118 {
119  return (void *)(CPU_FLASH_BASE + (page * FLASHPAGE_SIZE));
120 }
121 
133 static inline unsigned flashpage_page(void *addr)
134 {
135  return (((intptr_t)addr - CPU_FLASH_BASE) / FLASHPAGE_SIZE);
136 }
137 
143 void flashpage_erase(unsigned page);
144 
152 void flashpage_write_page(unsigned page, const void *data);
153 
175 void flashpage_write(void *target_addr, const void *data, size_t len);
176 
184 void flashpage_read(unsigned page, void *data);
185 
196 int flashpage_verify(unsigned page, const void *data);
197 
210 int flashpage_write_and_verify(unsigned page, const void *data);
211 
225 #ifdef FLASHPAGE_RWWEE_NUMOF
226 
237 static inline void *flashpage_rwwee_addr(unsigned page)
238 {
239  return (void *)(CPU_FLASH_RWWEE_BASE + (page * FLASHPAGE_SIZE));
240 }
241 
253 static inline int flashpage_rwwee_page(void *addr)
254 {
255  return (int)(((int)addr - CPU_FLASH_RWWEE_BASE) / FLASHPAGE_SIZE);
256 }
257 
265 void flashpage_rwwee_write_page(unsigned page, const void *data);
266 
288 void flashpage_rwwee_write(void *target_addr, const void *data, size_t len);
289 
297 void flashpage_rwwee_read(unsigned page, void *data);
298 
309 int flashpage_rwwee_verify(unsigned page, const void *data);
310 
324 int flashpage_rwwee_write_and_verify(unsigned page, const void *data);
325 
326 #endif /* FLASHPAGE_RWWEE_NUMOF */
327 
328 #ifdef __cplusplus
329 }
330 #endif
331 
332 #endif /* PERIPH_FLASHPAGE_H */
333 
FLASHPAGE_OK
@ FLASHPAGE_OK
everything succeeded
Definition: flashpage.h:103
flashpage_write_page
void flashpage_write_page(unsigned page, const void *data)
Write the given page with the given data.
flashpage_write
void flashpage_write(void *target_addr, const void *data, size_t len)
Write any number of data bytes to a given location in the flash memory.
flashpage_verify
int flashpage_verify(unsigned page, const void *data)
Verify the given page against the given data.
flashpage_write_and_verify
int flashpage_write_and_verify(unsigned page, const void *data)
Write the given page and verify the results.
flashpage_page
static unsigned flashpage_page(void *addr)
Translate the given address into the corresponding page number.
Definition: flashpage.h:133
FLASHPAGE_SIZE
#define FLASHPAGE_SIZE
Flash page configuration.
Definition: cpu_conf.h:51
flashpage_erase
void flashpage_erase(unsigned page)
Erase the given page.
FLASHPAGE_NOMATCH
@ FLASHPAGE_NOMATCH
page differs from target data
Definition: flashpage.h:104
flashpage_addr
static void * flashpage_addr(unsigned page)
Translate the given page number into the page's starting address.
Definition: flashpage.h:117
CPU_FLASH_BASE
#define CPU_FLASH_BASE
Per default, we expect the internal flash to start at address 0.
Definition: flashpage.h:64
flashpage_read
void flashpage_read(unsigned page, void *data)
Read the given page into the given memory location.