Loading...
Searching...
No Matches
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 <stddef.h>
52#include <stdint.h>
53
54#include "cpu_conf.h"
55#include "periph_cpu.h"
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
64#ifndef CPU_FLASH_BASE
65#define CPU_FLASH_BASE (0)
66#endif
73#ifdef DOXYGEN
74#define FLASHPAGE_WRITE_BLOCK_SIZE
75#endif
76
85#ifdef DOXYGEN
86#define FLASHPAGE_WRITE_BLOCK_ALIGNMENT
87#endif
88
94#if defined(DOXYGEN) || !defined(FLASHPAGE_ERASE_STATE)
95#define FLASHPAGE_ERASE_STATE (0xFFU)
96#endif
97
105#ifdef DOXYGEN
106#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES
107#endif
108
117#ifdef DOXYGEN
118#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
119#endif
120
129#ifdef DOXYGEN
130#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE
131#endif
132
136enum {
140
141#if !defined(PERIPH_FLASHPAGE_CUSTOM_PAGESIZES) || defined(DOXYGEN)
147#ifndef FLASHPAGE_SIZE
148#error "periph/flashpage: FLASHPAGE_SIZE not defined"
149#endif
150#ifndef FLASHPAGE_NUMOF
151#error "periph/flashpage: FLASHPAGE_NUMOF not defined"
152#endif
153
154#if defined(MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE) || defined(DOXYGEN)
173#define FLASH_WRITABLE_INIT(name, size) \
174 __attribute__((aligned(FLASHPAGE_SIZE))) \
175 __attribute__((section(".flash_writable." #name))) \
176 static const uint8_t name [size * FLASHPAGE_SIZE]
177#endif
178
186static inline size_t flashpage_size(unsigned page)
187{
188 (void)page;
189 return FLASHPAGE_SIZE;
190}
191
202static inline void *flashpage_addr(unsigned page)
203{
204 return (void *)(CPU_FLASH_BASE + (page * FLASHPAGE_SIZE));
205}
206
218static inline unsigned flashpage_page(const void *addr)
219{
220 return (((intptr_t)addr - CPU_FLASH_BASE) / FLASHPAGE_SIZE);
221}
222
223#else
224
225/* Bare prototypes for the above functions. See above for the documentation */
226size_t flashpage_size(unsigned page);
227void *flashpage_addr(unsigned page);
228unsigned flashpage_page(const void *addr);
229
230#endif
231
237void flashpage_erase(unsigned page);
238
246void flashpage_write_page(unsigned page, const void *data);
247
269void flashpage_write(void *target_addr, const void *data, size_t len);
270
278void flashpage_read(unsigned page, void *data);
279
290int flashpage_verify(unsigned page, const void *data);
291
304int flashpage_write_and_verify(unsigned page, const void *data);
305
319#ifdef FLASHPAGE_RWWEE_NUMOF
320
331static inline void *flashpage_rwwee_addr(unsigned page)
332{
333 return (void *)(CPU_FLASH_RWWEE_BASE + (page * FLASHPAGE_SIZE));
334}
335
347static inline int flashpage_rwwee_page(const void *addr)
348{
349 return (int)(((int)addr - CPU_FLASH_RWWEE_BASE) / FLASHPAGE_SIZE);
350}
351
359void flashpage_rwwee_write_page(unsigned page, const void *data);
360
382void flashpage_rwwee_write(void *target_addr, const void *data, size_t len);
383
391void flashpage_rwwee_read(unsigned page, void *data);
392
403int flashpage_rwwee_verify(unsigned page, const void *data);
404
418int flashpage_rwwee_write_and_verify(unsigned page, const void *data);
419
420#endif /* FLASHPAGE_RWWEE_NUMOF */
421
422#ifdef __cplusplus
423}
424#endif
425
426#endif /* PERIPH_FLASHPAGE_H */
#define FLASHPAGE_SIZE
Flash page configuration.
Definition cpu_conf.h:50
int flashpage_write_and_verify(unsigned page, const void *data)
Write the given page and verify the results.
int flashpage_verify(unsigned page, const void *data)
Verify the given page against the given data.
void flashpage_erase(unsigned page)
Erase the given page.
static void * flashpage_addr(unsigned page)
Translate the given page number into the page's starting address.
Definition flashpage.h:202
static size_t flashpage_size(unsigned page)
Get the page size of the given page number.
Definition flashpage.h:186
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.
static unsigned flashpage_page(const void *addr)
Translate the given address into the corresponding page number.
Definition flashpage.h:218
#define CPU_FLASH_BASE
Per default, we expect the internal flash to start at address 0.
Definition flashpage.h:65
void flashpage_read(unsigned page, void *data)
Read the given page into the given memory location.
void flashpage_write_page(unsigned page, const void *data)
Write the given page with the given data.
@ FLASHPAGE_NOMATCH
page differs from target data
Definition flashpage.h:138
@ FLASHPAGE_OK
everything succeeded
Definition flashpage.h:137