From 88654ec90fc20b24bbb3efa146d80c622defa5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Desbiens?= Date: Wed, 30 Sep 2026 14:07:21 -0400 Subject: [PATCH] Added page-named NAND APIs with compatible sector aliases Fixes #67 The NAND application API calls page-sized logical units sectors, which can be confused with FileX sectors. Add page and pages names for read, write, and release. Keep sector names as aliases to the same symbols, and name public parameters logical_page and page_count. GCC 14.3 NAND regression passed (1/1). The test exercised all six page names, and existing sector calls compiled. Assisted-by: Codex (GPT-6-Sol) --- common/inc/lx_api.h | 32 +++++++++++++++--------- test/regression/levelx_nand_flash_test.c | 22 +++++++++++++--- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/common/inc/lx_api.h b/common/inc/lx_api.h index 1a51b17..3a5c466 100644 --- a/common/inc/lx_api.h +++ b/common/inc/lx_api.h @@ -706,12 +706,20 @@ extern ULONG _lx_nor_flash_opened_cou #define lx_nand_flash_open_extended _lx_nand_flash_open_extended #define lx_nand_flash_page_ecc_check _lx_nand_flash_page_ecc_check #define lx_nand_flash_page_ecc_compute _lx_nand_flash_page_ecc_compute -#define lx_nand_flash_sector_read _lx_nand_flash_sector_read -#define lx_nand_flash_sector_release _lx_nand_flash_sector_release -#define lx_nand_flash_sector_write _lx_nand_flash_sector_write -#define lx_nand_flash_sectors_read _lx_nand_flash_sectors_read -#define lx_nand_flash_sectors_release _lx_nand_flash_sectors_release -#define lx_nand_flash_sectors_write _lx_nand_flash_sectors_write +#define lx_nand_flash_page_read _lx_nand_flash_sector_read +#define lx_nand_flash_page_release _lx_nand_flash_sector_release +#define lx_nand_flash_page_write _lx_nand_flash_sector_write +#define lx_nand_flash_pages_read _lx_nand_flash_sectors_read +#define lx_nand_flash_pages_release _lx_nand_flash_sectors_release +#define lx_nand_flash_pages_write _lx_nand_flash_sectors_write + +/* Both NAND API spellings use the same entry points. */ +#define lx_nand_flash_sector_read lx_nand_flash_page_read +#define lx_nand_flash_sector_release lx_nand_flash_page_release +#define lx_nand_flash_sector_write lx_nand_flash_page_write +#define lx_nand_flash_sectors_read lx_nand_flash_pages_read +#define lx_nand_flash_sectors_release lx_nand_flash_pages_release +#define lx_nand_flash_sectors_write lx_nand_flash_pages_write #define lx_nand_flash_256byte_ecc_check _lx_nand_flash_256byte_ecc_check #define lx_nand_flash_256byte_ecc_compute _lx_nand_flash_256byte_ecc_compute @@ -748,12 +756,12 @@ UINT _lx_nand_flash_open_extended(LX_NAND_FLASH *nand_flash, CHAR *name, UINT _lx_nand_flash_page_ecc_check(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer); UINT _lx_nand_flash_page_ecc_compute(LX_NAND_FLASH *nand_flash, UCHAR *page_buffer, UCHAR *ecc_buffer); UINT _lx_nand_flash_partial_defragment(LX_NAND_FLASH *nand_flash, UINT max_blocks); -UINT _lx_nand_flash_sector_read(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer); -UINT _lx_nand_flash_sector_release(LX_NAND_FLASH *nand_flash, ULONG logical_sector); -UINT _lx_nand_flash_sector_write(LX_NAND_FLASH *nand_flash, ULONG logical_sector, VOID *buffer); -UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH* nand_flash, ULONG logical_sector, VOID* buffer, ULONG sector_count); -UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH* nand_flash, ULONG logical_sector, ULONG sector_count); -UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH* nand_flash, ULONG logical_sector, VOID* buffer, ULONG sector_count); +UINT _lx_nand_flash_sector_read(LX_NAND_FLASH *nand_flash, ULONG logical_page, VOID *buffer); +UINT _lx_nand_flash_sector_release(LX_NAND_FLASH *nand_flash, ULONG logical_page); +UINT _lx_nand_flash_sector_write(LX_NAND_FLASH *nand_flash, ULONG logical_page, VOID *buffer); +UINT _lx_nand_flash_sectors_read(LX_NAND_FLASH* nand_flash, ULONG logical_page, VOID* buffer, ULONG page_count); +UINT _lx_nand_flash_sectors_release(LX_NAND_FLASH* nand_flash, ULONG logical_page, ULONG page_count); +UINT _lx_nand_flash_sectors_write(LX_NAND_FLASH* nand_flash, ULONG logical_page, VOID* buffer, ULONG page_count); UINT _lx_nor_flash_close(LX_NOR_FLASH *nor_flash); UINT _lx_nor_flash_defragment(LX_NOR_FLASH *nor_flash); diff --git a/test/regression/levelx_nand_flash_test.c b/test/regression/levelx_nand_flash_test.c index d9c1e4c..2c15f62 100644 --- a/test/regression/levelx_nand_flash_test.c +++ b/test/regression/levelx_nand_flash_test.c @@ -9,6 +9,8 @@ /* SPDX-License-Identifier: MIT */ /***************************************************************************/ +/* Portions of this file were generated with AI assistance. */ + /* Basic NOR flash tests... */ #include @@ -163,7 +165,21 @@ UCHAR *byte_ptr; for (j = 0; j < 512; j++) buffer[j] = i; - status = lx_nand_flash_sector_write(&nand_sim_flash, i, buffer); + status = lx_nand_flash_page_write(&nand_sim_flash, i, buffer); + + /* Check the multi-page API with two pages outside this range. */ + if ((i == 0) && (status == LX_SUCCESS)) + { + LX_MEMSET(buffer, 0x5A, 2 * nand_sim_flash.lx_nand_flash_bytes_per_page); + status = lx_nand_flash_pages_write(&nand_sim_flash, 600, buffer, 2); + if (status == LX_SUCCESS) + status = lx_nand_flash_pages_read(&nand_sim_flash, 600, readbuffer, 2); + if ((status == LX_SUCCESS) && + (memcmp(buffer, readbuffer, 2 * nand_sim_flash.lx_nand_flash_bytes_per_page) != 0)) + status = LX_ERROR; + if (status == LX_SUCCESS) + status = lx_nand_flash_pages_release(&nand_sim_flash, 600, 2); + } if (status != LX_SUCCESS) { @@ -199,7 +215,7 @@ UCHAR *byte_ptr; for (i = 0; i < 520; i++) { - status = lx_nand_flash_sector_read(&nand_sim_flash, i, buffer); + status = lx_nand_flash_page_read(&nand_sim_flash, i, buffer); if (status != LX_SUCCESS) { @@ -1624,7 +1640,7 @@ UCHAR *byte_ptr; } } - status = lx_nand_flash_sector_release(&nand_sim_flash, 7); + status = lx_nand_flash_page_release(&nand_sim_flash, 7); if (status != LX_SUCCESS) { printf("FAILED!\n");