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
10#pragma once
11
49
50#include <stddef.h>
51#include <stdint.h>
52
53#include "cpu_conf.h"
54#include "periph_cpu.h"
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
63#ifndef CPU_FLASH_BASE
64#define CPU_FLASH_BASE (0)
65#endif
72#ifdef DOXYGEN
73#define FLASHPAGE_WRITE_BLOCK_SIZE
74#endif
75
84#ifdef DOXYGEN
85#define FLASHPAGE_WRITE_BLOCK_ALIGNMENT
86#endif
87
93#if defined(DOXYGEN) || !defined(FLASHPAGE_ERASE_STATE)
94#define FLASHPAGE_ERASE_STATE (0xFFU)
95#endif
96
104#ifdef DOXYGEN
105#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES
106#endif
107
116#ifdef DOXYGEN
117#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
118#endif
119
128#ifdef DOXYGEN
129#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE
130#endif
131
135enum {
138};
139
140#if !defined(PERIPH_FLASHPAGE_CUSTOM_PAGESIZES) || defined(DOXYGEN)
146#ifndef FLASHPAGE_SIZE
147#error "periph/flashpage: FLASHPAGE_SIZE not defined"
148#endif
149#ifndef FLASHPAGE_NUMOF
150#error "periph/flashpage: FLASHPAGE_NUMOF not defined"
151#endif
152
153#if defined(MODULE_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE) || defined(DOXYGEN)
172#define FLASH_WRITABLE_INIT(name, size) \
173 __attribute__((aligned(FLASHPAGE_SIZE))) \
174 __attribute__((section(".flash_writable." #name))) \
175 static const uint8_t name [size * FLASHPAGE_SIZE]
176#endif
177
185static inline size_t flashpage_size(unsigned page)
186{
187 (void)page;
188 return FLASHPAGE_SIZE;
189}
190
201static inline void *flashpage_addr(unsigned page)
202{
203 return (void *)(CPU_FLASH_BASE + (page * FLASHPAGE_SIZE));
204}
205
217static inline unsigned flashpage_page(const void *addr)
218{
219 return (((intptr_t)addr - CPU_FLASH_BASE) / FLASHPAGE_SIZE);
220}
221
222#else
223
224/* Bare prototypes for the above functions. See above for the documentation */
225size_t flashpage_size(unsigned page);
226void *flashpage_addr(unsigned page);
227unsigned flashpage_page(const void *addr);
228
229#endif
230
236void flashpage_erase(unsigned page);
237
245void flashpage_write_page(unsigned page, const void *data);
246
268void flashpage_write(void *target_addr, const void *data, size_t len);
269
277void flashpage_read(unsigned page, void *data);
278
289int flashpage_verify(unsigned page, const void *data);
290
303int flashpage_write_and_verify(unsigned page, const void *data);
304
318#ifdef FLASHPAGE_RWWEE_NUMOF
319
330static inline void *flashpage_rwwee_addr(unsigned page)
331{
332 return (void *)(CPU_FLASH_RWWEE_BASE + (page * FLASHPAGE_SIZE));
333}
334
346static inline int flashpage_rwwee_page(const void *addr)
347{
348 return (int)(((int)addr - CPU_FLASH_RWWEE_BASE) / FLASHPAGE_SIZE);
349}
350
358void flashpage_rwwee_write_page(unsigned page, const void *data);
359
381void flashpage_rwwee_write(void *target_addr, const void *data, size_t len);
382
390void flashpage_rwwee_read(unsigned page, void *data);
391
402int flashpage_rwwee_verify(unsigned page, const void *data);
403
417int flashpage_rwwee_write_and_verify(unsigned page, const void *data);
418
419#endif /* FLASHPAGE_RWWEE_NUMOF */
420
421#ifdef __cplusplus
422}
423#endif
424
#define FLASHPAGE_SIZE
Flash page configuration.
Definition cpu_conf.h:49
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:201
static size_t flashpage_size(unsigned page)
Get the page size of the given page number.
Definition flashpage.h:185
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:217
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:137
@ FLASHPAGE_OK
everything succeeded
Definition flashpage.h:136