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 
37 #ifndef PERIPH_FLASHPAGE_H
38 #define PERIPH_FLASHPAGE_H
39 
40 #include <stdint.h>
41 
42 #include "periph_cpu.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
51 #ifndef CPU_FLASH_BASE
52 #define CPU_FLASH_BASE (0)
53 #endif
54 
60 #ifdef DOXYGEN
61 #define FLASHPAGE_RAW_BLOCKSIZE
62 #endif
63 
72 #ifdef DOXYGEN
73 #define FLASHPAGE_RAW_ALIGNMENT
74 #endif
75 
80 #ifndef FLASHPAGE_SIZE
81 #error "periph/flashpage: FLASHPAGE_SIZE not defined"
82 #endif
83 #ifndef FLASHPAGE_NUMOF
84 #error "periph/flashpage: FLASHPAGE_NUMOF not defined"
85 #endif
86 
90 enum {
93 };
94 
105 static inline void *flashpage_addr(int page)
106 {
107  return (void *)(CPU_FLASH_BASE + (page * FLASHPAGE_SIZE));
108 }
109 
121 static inline int flashpage_page(void *addr)
122 {
123  return (int)(((int)addr - CPU_FLASH_BASE) / FLASHPAGE_SIZE);
124 }
125 
133 void flashpage_write(int page, void *data);
134 
156 void flashpage_write_raw(void *target_addr, void *data, size_t len);
157 
165 void flashpage_read(int page, void *data);
166 
177 int flashpage_verify(int page, void *data);
178 
191 int flashpage_write_and_verify(int page, void *data);
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 #endif /* PERIPH_FLASHPAGE_H */
198 
#define CPU_FLASH_BASE
Per default, we expect the internal flash to start at address 0.
Definition: flashpage.h:52
int flashpage_verify(int page, void *data)
Verify the given page against the given data.
void flashpage_write_raw(void *target_addr, void *data, size_t len)
Write any number of data bytes to a given location in the flash memory.
int flashpage_write_and_verify(int page, void *data)
Write the given page and verify the results.
static void * flashpage_addr(int page)
Translate the given page number into the page&#39;s starting address.
Definition: flashpage.h:105
static int flashpage_page(void *addr)
Translate the given address into the corresponding page number.
Definition: flashpage.h:121
page differs from target data
Definition: flashpage.h:92
void flashpage_read(int page, void *data)
Read the given page into the given memory location.
#define FLASHPAGE_SIZE
Flash page configuration.
everything succeeded
Definition: flashpage.h:91
void flashpage_write(int page, void *data)
Write the given page with the given data.