1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/periph: flashpage: add common helper functions

This commit is contained in:
Benjamin Valentin 2021-02-01 22:02:30 +01:00 committed by Benjamin Valentin
parent 52314cece8
commit 917cf85225
2 changed files with 51 additions and 5 deletions

View File

@ -105,6 +105,30 @@ extern "C" {
#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES
#endif
/**
* @def PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
*
* @brief If non-uniform flash page sizes are required, defined to signal
* that the peripheral does not implement a custom @ref flashpage_addr
* function and instead relies on the generic helper function that
* relies on @ref flashpage_size.
*/
#ifdef DOXYGEN
#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
#endif
/**
* @def PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE
*
* @brief If non-uniform flash page sizes are required, defined to signal
* that the peripheral does not implement a custom @ref flashpage_page
* function and instead relies on the generic helper function that
* relies on @ref flashpage_size.
*/
#ifdef DOXYGEN
#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE
#endif
/**
* @brief Return values used in this interface
*/

View File

@ -24,9 +24,9 @@
/* guard this file, must be done before including periph/flashpage.h
* TODO: remove as soon as periph drivers can be build selectively */
#if defined(FLASHPAGE_NUMOF) && defined(FLASHPAGE_SIZE)
#if defined(FLASHPAGE_SIZE) || defined(PERIPH_FLASHPAGE_CUSTOM_PAGESIZES)
#include "periph/flashpage.h"
#endif
#ifdef MODULE_PERIPH_FLASHPAGE_PAGEWISE
void flashpage_read(unsigned page, void *data)
@ -76,7 +76,6 @@ void flashpage_write_page(unsigned page, const void *data)
#endif /* MODULE_PERIPH_FLASHPAGE_PAGEWISE */
#if defined(FLASHPAGE_RWWEE_NUMOF)
void flashpage_rwwee_read(unsigned page, void *data)
{
assert(page < (int)FLASHPAGE_RWWEE_NUMOF);
@ -101,7 +100,30 @@ int flashpage_rwwee_write_and_verify(unsigned page, const void *data)
flashpage_rwwee_write_page(page, data);
return flashpage_rwwee_verify(page, data);
}
#endif /* FLASHPAGE_RWWEE_NUMOF */
#endif
#ifdef PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
void *flashpage_addr(unsigned page)
{
uintptr_t addr = CPU_FLASH_BASE;
#endif
while (page) {
addr += flashpage_size(--page);
}
return (void*)addr;
}
#endif /* PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR */
#ifdef PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE
unsigned flashpage_page(void *addr)
{
unsigned page = 0;
for (uintptr_t pos = CPU_FLASH_BASE; addr >= pos; ++page) {
pos += flashpage_size(page);
}
return page - 1;
}
#endif /* PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_PAGE */