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

Merge pull request #15908 from benpicco/drivers/periph_common-flashpage

drivers/periph: flashpage: add common helper functions
This commit is contained in:
benpicco 2021-04-27 18:54:10 +02:00 committed by GitHub
commit 0493292ef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 15 deletions

View File

@ -130,6 +130,7 @@ extern "C" {
#if defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4) || \
defined(CPU_FAM_STM32F7)
#define PERIPH_FLASHPAGE_CUSTOM_PAGESIZES
#define PERIPH_FLASHPAGE_NEEDS_FLASHPAGE_ADDR
/**
* @brief stm32 dual bank configuration

View File

@ -328,16 +328,6 @@ size_t flashpage_size(unsigned page)
}
}
void *flashpage_addr(unsigned page)
{
uintptr_t addr = CPU_FLASH_BASE;
while (page) {
addr += flashpage_size(--page);
}
return (void*)addr;
}
unsigned flashpage_page(void *addr)
{
/* Calculates the flashpage number based on the address for the

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 */