flashpage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freie Universit├Ąt Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
33 #ifndef FLASHPAGE_H
34 #define FLASHPAGE_H
35 
36 #include <stdint.h>
37 
38 #include "periph_cpu.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
47 #ifndef CPU_FLASH_BASE
48 #define CPU_FLASH_BASE (0)
49 #endif
50 
54 #ifndef FLASHPAGE_SIZE
55 #error "periph/flashpage: FLASHPAGE_SIZE not defined"
56 #endif
57 #ifndef FLASHPAGE_NUMOF
58 #error "periph/flashpage: FLASHPAGE_NUMOF not defined"
59 #endif
60 
64 enum {
67 };
68 
79 static inline void *flashpage_addr(int page)
80 {
81  return (void *)(CPU_FLASH_BASE + (page * FLASHPAGE_SIZE));
82 }
83 
95 static inline int flashpage_page(void *addr)
96 {
97  return (int)(((int)addr - CPU_FLASH_BASE) / FLASHPAGE_SIZE);
98 }
99 
107 void flashpage_write(int page, void *data);
108 
116 void flashpage_read(int page, void *data);
117 
128 int flashpage_verify(int page, void *data);
129 
142 int flashpage_write_and_verify(int page, void *data);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif /* FLASHPAGE_H */
149 
#define CPU_FLASH_BASE
Per default, we expect the internal flash to start at address 0.
Definition: flashpage.h:48
int flashpage_verify(int page, void *data)
Verify the given page against the given data.
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's starting address.
Definition: flashpage.h:79
static int flashpage_page(void *addr)
Translate the given address into the corresponding page number.
Definition: flashpage.h:95
page differs from target data
Definition: flashpage.h:66
everything succeeded
Definition: flashpage.h:65
void flashpage_read(int page, void *data)
Read the given page into the given memory location.
void flashpage_write(int page, void *data)
Write the given page with the given data.
#define FLASHPAGE_SIZE
Flash page configuration.