Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/mtd_flashpage: add mtd_flashpage_t type #17627

Merged
merged 3 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions drivers/include/mtd_flashpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,26 @@ extern "C"
* @brief Macro helper to initialize a mtd_t with flash-age driver
*/
#define MTD_FLASHPAGE_INIT_VAL(_pages_per_sector) { \
.driver = &mtd_flashpage_driver, \
.sector_count = FLASHPAGE_NUMOF, \
.pages_per_sector = _pages_per_sector,\
.page_size = FLASHPAGE_SIZE / _pages_per_sector,\
.base = { \
.driver = &mtd_flashpage_driver, \
.sector_count = FLASHPAGE_NUMOF, \
.pages_per_sector = _pages_per_sector, \
.page_size = FLASHPAGE_SIZE / _pages_per_sector, \
}, \
}

/**
* @brief Flashpage MTD device operations table
*/
extern const mtd_desc_t mtd_flashpage_driver;

/**
* @brief MTD flashpage descriptor
*/
typedef struct {
mtd_dev_t base; /**< MTD generic device */
} mtd_flashpage_t;

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 7 additions & 6 deletions sys/fido2/ctap/ctap_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
/**
* @brief MTD device descriptor initialized with flash-page driver
*/
static mtd_dev_t _mtd_dev = MTD_FLASHPAGE_INIT_VAL(CTAP_FLASH_PAGES_PER_SECTOR);
static mtd_flashpage_t _mtd_flash_dev = MTD_FLASHPAGE_INIT_VAL(CTAP_FLASH_PAGES_PER_SECTOR);
static mtd_dev_t *_mtd_dev = &_mtd_flash_dev.base;

/**
* @brief Max amount of resident keys that can be stored
Expand All @@ -49,7 +50,7 @@ int fido2_ctap_mem_init(void)
{
int ret;

ret = mtd_init(&_mtd_dev);
ret = mtd_init(_mtd_dev);

if (ret < 0) {
return ret;
Expand All @@ -64,7 +65,7 @@ int fido2_ctap_mem_init(void)

static unsigned _amount_of_flashpages(void)
{
return _mtd_dev.sector_count * _mtd_dev.pages_per_sector;
return _mtd_dev->sector_count * _mtd_dev->pages_per_sector;
}

int fido2_ctap_mem_read(void *buf, uint32_t page, uint32_t offset, uint32_t len)
Expand All @@ -73,7 +74,7 @@ int fido2_ctap_mem_read(void *buf, uint32_t page, uint32_t offset, uint32_t len)

int ret;

ret = mtd_read_page(&_mtd_dev, buf, page, offset, len);
ret = mtd_read_page(_mtd_dev, buf, page, offset, len);

if (ret < 0) {
return CTAP1_ERR_OTHER;
Expand All @@ -89,14 +90,14 @@ int fido2_ctap_mem_write(const void *buf, uint32_t page, uint32_t offset, uint32
int ret;

if (!_flash_is_erased(page, offset, len)) {
ret = mtd_write_page(&_mtd_dev, buf, page, offset, len);
ret = mtd_write_page(_mtd_dev, buf, page, offset, len);

if (ret < 0) {
return CTAP1_ERR_OTHER;
}
}
else {
ret = mtd_write_page_raw(&_mtd_dev, buf, page, offset, len);
ret = mtd_write_page_raw(_mtd_dev, buf, page, offset, len);

if (ret < 0) {
return CTAP1_ERR_OTHER;
Expand Down
4 changes: 2 additions & 2 deletions tests/mtd_flashpage/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#endif
#define TEST_ADDRESS0 (FLASHPAGE_NUMOF - 1)

static mtd_dev_t _dev = MTD_FLASHPAGE_INIT_VAL(8);
static mtd_dev_t *dev = &_dev;
static mtd_flashpage_t _dev = MTD_FLASHPAGE_INIT_VAL(8);
static mtd_dev_t *dev = &_dev.base;

static void setup(void)
{
Expand Down