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

drivers/mtd_flashpage: define mtd_flash_aux_slot device

This commit is contained in:
Benjamin Valentin 2022-09-17 18:09:58 +02:00 committed by Benjamin Valentin
parent a417a3e72c
commit e3819ca960
3 changed files with 66 additions and 1 deletions

View File

@ -136,6 +136,10 @@ ifneq (,$(filter pcf857%,$(USEMODULE)))
USEMODULE += pcf857x
endif
ifneq (,$(filter periph_flashpage_aux,$(FEATURES_USED)))
FEATURES_REQUIRED += periph_flashpage_pagewise
endif
ifneq (,$(filter periph_ptp_timer periph_ptp_speed_adjustment,$(FEATURES_USED)))
FEATURES_REQUIRED += periph_ptp
endif

View File

@ -35,7 +35,7 @@ extern "C"
#endif
/**
* @brief Macro helper to initialize a mtd_t with flash-age driver
* @brief Macro helper to initialize a mtd_t with flashpage driver
*/
#define MTD_FLASHPAGE_INIT_VAL(_pages_per_sector) { \
.base = { \
@ -47,6 +47,23 @@ extern "C"
}, \
}
/**
* @brief Macro helper to initialize a mtd_t with a portion of the flash
*
* @param[in] start Start address of the flash section
* @param[in] len Size of the flash section in bytes
*/
#define MTD_FLASHPAGE_AUX_INIT_VAL(start, len) { \
.base = { \
.driver = &mtd_flashpage_driver, \
.sector_count = len / FLASHPAGE_SIZE, \
.pages_per_sector = 1, \
.page_size = FLASHPAGE_SIZE, \
.write_size = 1, \
}, \
.offset = start / FLASHPAGE_SIZE, \
}
/**
* @brief Flashpage MTD device operations table
*/
@ -62,6 +79,40 @@ typedef struct {
flash */
} mtd_flashpage_t;
#if CONFIG_SLOT_AUX_LEN || DOXYGEN
/**
* @brief MTD device representing the auxiliary flash slot
*/
extern mtd_flashpage_t mtd_flash_aux_slot;
/**
* @brief Generic MTD device backed by the auxiliary flash slot
*/
extern mtd_dev_t *mtd_aux;
#endif
/**
* @brief Size of the auxiliary slot on the internal flash
* Must align with the flash page size.
*
* @note Don't set this config value directly!
* Instead set `SLOT_AUX_LEN` in the board's `Makefile.include`
*
* This value is fixed and can not be changed in the field / via firmware
* updates. Changing this value requires re-flashing of riotboot.
*
*/
#ifndef CONFIG_SLOT_AUX_LEN
#define CONFIG_SLOT_AUX_LEN 0
#endif
/**
* @brief Default MTD offset for the AUX slot
*/
#ifndef CONFIG_SLOT_AUX_MTD_OFFSET
#define CONFIG_SLOT_AUX_MTD_OFFSET 1
#endif
#ifdef __cplusplus
}
#endif

View File

@ -159,3 +159,13 @@ const mtd_desc_t mtd_flashpage_driver = {
.write_page = _write_page,
.erase_sector = _erase_sector,
};
#if CONFIG_SLOT_AUX_LEN
mtd_flashpage_t mtd_flash_aux_slot = MTD_FLASHPAGE_AUX_INIT_VAL(CONFIG_SLOT_AUX_OFFSET,
CONFIG_SLOT_AUX_LEN);
MTD_XFA_ADD(mtd_flash_aux_slot, CONFIG_SLOT_AUX_MTD_OFFSET);
mtd_dev_t *mtd_aux = &mtd_flash_aux_slot.base;
static_assert(CONFIG_SLOT_AUX_OFFSET % FLASHPAGE_SIZE == 0, "AUX slot must align with page");
static_assert(CONFIG_SLOT_AUX_LEN % FLASHPAGE_SIZE == 0, "AUX slot must align with page");
#endif