第 4 章 - Azure RTOS LevelX NAND API

lx_nand_flash_close

关闭 NAND 闪存实例

原型

UINT lx_nand_flash_close(LX_NAND_FLASH *nand_flash);

说明

此服务关闭先前打开的 NAND 闪存实例。

输入参数

  • nand_flash:NAND 闪存实例指针。

返回值

  • LX_SUCCESS:(0X00) 成功的请求。
  • LX_ERROR:(0x01) 关闭闪存实例时出错。

允许来自

线程数

示例

/* Close NAND flash instance "my_nand_flash". */
status = lx_nand_flash_close(&my_nand_flash);  
  
/* If status is LX_SUCCESS the request was successful. */

另请参阅

  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_defragment

对 NAND 闪存实例进行碎片整理

原型

UINT lx_nand_flash_defragment(LX_NAND_FLASH *nand_flash);

说明

此服务已弃用且不受支持。

输入参数

  • nand_flash:NAND 闪存实例指针。

返回值

  • LX_NOT_SUPPORTED:不支持 (0x0C) 。

允许调用自

线程数

示例

/* Defragment NAND flash instance "my_nand_flash". */  
status = lx_nand_flash_defragment(&my_nand_flash);  
  
/* If status is LX_SUCCESS the request was successful. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_extended_cache_enable

启用/禁用扩展 NAND 缓存

原型

UINT lx_nand_flash_extended_cache_enable(
    LX_NAND_FLASH
    *nand_flash,  
    VOID *memory, 
    ULONG size);

说明

此服务已弃用且不受支持。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • memory:缓存内存的起始地址,为 ULONG 访问而对齐。 LX_NULL 值禁用缓存。
  • size:提供的内存大小(以字节为单位)。

返回值

  • LX_NOT_SUPPORTED:不支持 (0x0C) 。

允许调用自

线程数

示例

/* Enable the NAND flash cache for the instance "my_nand_flash". */
status = lx_nand_flash_extended_cache_enable(&my_nand_flash,  
    &my_memory, sizeof(my_memory));  
  
/* If status is LX_SUCCESS the request was successful. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_format

格式化 NAND 闪存实例

原型

UINT  _lx_nand_flash_format(LX_NAND_FLASH* nand_flash, CHAR* name,
                            UINT(*nand_driver_initialize)(LX_NAND_FLASH*),
                            ULONG* memory_ptr, UINT memory_size);

说明

此服务擦除 NAND 闪存,并使用指定的名称、驱动程序初始化函数格式化 NAND 闪存实例。 请注意,驱动程序初始化函数负责安装各种函数指针,用于读取、写入和擦除与此 NAND 闪存实例相关联的 NAND 硬件的块/页。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • name:NAND 闪存实例的名称。
  • nand_driver_initialize:指向 NAND 闪存驱动程序初始化函数的函数指针。 有关 NAND 闪存驱动程序责任的详细信息,请参阅本指南的第 3 章。
  • memory_ptr:指向 LevelX 的工作内存的指针。
  • memory_size:LevelX 的工作内存大小。 大小必须至少为 7 * 总块计数 + 2 * 页大小。

返回值

  • LX_SUCCESS:(0X00) 成功的请求。
  • LX_ERROR: (0x01) 格式化 NAND 闪存实例时出错。
  • LX_NO_BLOCKS: (0x0B) 块不足,无法格式化 NAND 闪存实例。

允许来自

线程数

示例

/* Format NAND flash instance "my_nand_flash". */
status = lx_nand_flash_format(&my_nand_flash, "my nand flash",  
    my_nand_driver_initialize, &my_memory, sizeof(my_memory));

/* If status is LX_SUCCESS the NAND is erased and initial format is built, it can be opened later by calling lx_nand_flash_open. */

另请参阅

  • lx_nand_flash_open
  • lx_nand_flash_close
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_initialize

初始化 NAND 闪存支持

原型

UINT lx_nand_flash_initialize(void);

说明

此服务初始化 LevelX NAND 闪存支持。 必须在任何其他 LevelX NAND API 之前调用它。

输入参数

返回值

  • LX_SUCCESS:(0x00) 成功的请求。
  • LX_ERROR:(0x01) 初始化 NAND 闪存支持时出错。

允许来自

初始化、线程

示例

/* Initialize NAND flash support. */
status = lx_nand_flash_initialize();  
  
/* If status is LX_SUCCESS the request was successful. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_open

打开 NAND 闪存实例

原型

UINT lx_nand_flash_open(
    LX_NAND_FLASH *nand_flash, 
    CHAR *name,  
    UINT (*nand_driver_initialize) (LX_NAND_FLASH *),
    ULONG* memory_ptr, 
    UINT memory_size);

说明

此服务使用指定的 NAND 闪存控制块和驱动程序初始化函数打开一个 NAND 闪存实例。 请注意,驱动程序初始化函数负责安装各种函数指针,用于读取、写入和擦除与此 NAND 闪存实例相关联的 NAND 硬件的块/页。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • name:NAND 闪存实例的名称。
  • nand_driver_initialize:指向 NAND 闪存驱动程序初始化函数的函数指针。 有关 NAND 闪存驱动程序责任的详细信息,请参阅本指南的第 3 章。
  • memory_ptr:指向 LevelX 的工作内存的指针。
  • memory_size:LevelX 的工作内存大小。 大小必须至少为 7 * 总块计数 + 2 * 页大小。

返回值

  • LX_SUCCESS:(0x00) 成功的请求。
  • LX_ERROR:(0x01) 打开 NAND 闪存实例时出错。
  • LX_NO_MEMORY:(0x08) 驱动程序未提供用于将页读取到 RAM 的缓冲区。

允许来自

线程数

示例

/* Open NAND flash instance "my_nand_flash" with the driver "my_nand_driver_initialize". */ 
status = lx_nand_flash_open(&my_nand_flash,"my nand flash",  
    my_nand_driver_initialize, &my_memory, sizeof(my_memory));  
  
/* If status is LX_SUCCESS the request was successful. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_page_ecc_check

检查页是否有 ECC 错误和更正

原型

UINT lx_nand_flash_page_ecc_check(
    LX_NAND_FLASH *nand_flash,  
    UCHAR *page_buffer, 
    UCHAR *ecc_buffer);

说明

此服务通过提供的 ECC 验证所提供的 NAND 页缓冲区的完整性。 页大小(在 NAND 闪存实例指针中定义)假定为 256 字节的倍数,提供的 ECC 代码能够在页的每 256 字节部分纠正 1 位错误。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • page_buffer:指向 NAND 闪存页缓冲区的指针。
  • ecc_buffer:指向 NAND 闪存页的 ECC 的指针。 请注意,页的每 256 字节部分有 3 个 ECC 字节。

返回值

  • LX_SUCCESS:(0x00) NAND 页没有错误。
  • LX_NAND_ERROR_CORRECTED:(0x06) 在 NAND 页中更正了一个或多个 1 位错误(更正位于页缓冲区)。
  • LX_NAND_ERROR_NOT_CORRECTED:(0x07) NAND 页上有太多错误,无法更正。

允许来自

LevelX 驱动程序

示例

/* Check the NAND page pointed to by "page_pointer" of the NAND flash instance "my_nand_flash" . */
status = lx_nand_flash_page_ecc_check(&my_nand_flash, page_pointer, ecc_pointer);  
  
/* If status is LX_SUCCESS the page is valid. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_page_ecc_compute

计算页的 ECC

原型

UINT lx_nand_flash_page_ecc_compute(
    LX_NAND_FLASH *nand_flash,  
    UCHAR *page_buffer, 
    UCHAR *ecc_buffer);

说明

此服务计算提供的 NAND 页缓冲区的 ECC,并返回提供的 ECC 缓冲区中的 ECC。 页面大小假设为 256 字节的倍数(在 NAND 闪存实例指针中定义)。 ECC 代码用于在稍后读取页时验证页的完整性。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • page_buffer:指向 NAND 闪存页缓冲区的指针。
  • ecc_buffer:指向 NAND 闪存页 ECC 的目标的指针。 请注意,页的每 256 字节部分必须有 3 字节的 ECC 存储。 例如,2048 字节页需要 24 字节的 ECC。

返回值

  • LX_SUCCESS:(0x00) 已成功计算 ECC。
  • LX_ERROR:(0x01) 计算 ECC 时出错。

允许来自

LevelX 驱动程序

示例

/* Compute ECC for the NAND page pointed to by "page_pointer" of the NAND flash instance "my_nand_flash". */  
status = lx_nand_flash_page_ecc_compute(&my_nand_flash, page_pointer, ecc_pointer);  
  
/* If status is LX_SUCCESS the ECC was calculated and Can be found in the memory pointed to by "ecc_pointer." */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_partial_defragment

NAND 闪存实例的部分碎片整理

原型

UINT lx_nand_flash_partial_defragment(
    LX_NAND_FLASH *nand_flash,  
    UINT max_blocks);

说明

此服务已弃用且不受支持。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • max_blocks:最大块数。

返回值

  • LX_NOT_SUPPORTED:不支持 (0x0C) 。

允许来自

线程数

示例

/* Defragment 1 block of NAND flash instance "my_nand_flash". */  
status = lx_nand_flash_partial_defragment(&my_nand_flash, 1);  
  
/* If status is LX_SUCCESS the request was successful. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_sector_read

读取 NAND 闪存扇区

原型

UINT lx_nand_flash_sector_read(
    LX_NAND_FLASH *nand_flash,  
    ULONG logical_sector, 
    VOID *buffer);

说明

此服务从 NAND 闪存实例读取逻辑扇区,如果成功,则返回所提供的缓冲区中的内容。 请注意,NAND 扇区大小始终是基础 NAND 硬件的页大小。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • logical_sector:要读取的逻辑扇区。
  • buffer:指向逻辑扇区内容的目标的指针。 请注意,缓冲区的大小假定为 NAND 闪存页大小,并为 ULONG 访问而对齐。

返回值

  • LX_SUCCESS:(0x00) 成功的请求。
  • LX_ERROR:(0x01) 读取 NAND 闪存扇区时出错。

允许来自

线程数

示例

/* Read logical sector 20 of the NAND flash instance "my_nand_flash" and place contents in "buffer". */
status = lx_nand_flash_sector_read(&my_nand_flash, 20, buffer);  
  
/* If status is LX_SUCCESS, "buffer" contains the contentsnof logical sector 20. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_release
  • lx_nand_flash_sectors_write

lx_nand_flash_sectors_read

读取多个 NAND 闪存扇区

原型

UINT lx_nand_flash_sectors_read(
    LX_NAND_FLASH *nand_flash,  
    ULONG logical_sector, 
    VOID *buffer, 
    ULONG sector_count);

说明

此服务从 NAND 闪存实例读取指定数量的逻辑扇区,如果成功,则返回提供的缓冲区中的内容。 请注意,NAND 扇区大小始终是基础 NAND 硬件的页大小。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • logical_sector:要读取的逻辑扇区。
  • buffer:指向逻辑扇区内容的目标的指针。 请注意,逻辑扇区大小与 NAND 闪存页大小相同,并且假定缓冲区足够大,足以容纳所有扇区以读取和对齐 ULONG 访问。
  • sector_count:要读取的逻辑扇区数。

返回值

  • LX_SUCCESS:(0x00) 成功的请求。
  • LX_ERROR:(0x01) 读取 NAND 闪存扇区时出错。

允许来自

线程数

示例

/* Read 10 logical sectors starting at logical sector 20 of the NAND flash instance "my_nand_flash" and place contents in "buffer". */
status = lx_nand_flash_sectors_read(&my_nand_flash, 20, buffer, 10);

/* If status is LX_SUCCESS, "buffer" contains the contents of logical sectors 20 through 29. */

lx_nand_flash_sector_release

释放 NAND 闪存扇区

原型

UINT lx_nand_flash_sector_release(
    LX_NAND_FLASH *nand_flash,
    ULONG logical_sector);

说明

此服务在 NAND 闪存实例中释放逻辑扇区映射。 在未使用时释放逻辑扇区会使 LevelX 的损耗均衡更有效率。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • logical_sector:要释放的逻辑扇区。

返回值

  • LX_SUCCESS:(0x00) 成功的请求。
  • LX_ERROR:(0x01) 写入 NAND 闪存扇区时出错。

允许来自

线程数

示例

/* Release logical sector 20 of the NAND flash instance "my_nand_flash". */  
status = lx_nand_flash_sector_release(&my_nand_flash, 20);  
  
/* If status is LX_SUCCESS, logical sector 20 has been released. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_write

lx_nand_flash_sectors_release

发布多个 NAND 闪存扇区

原型

UINT lx_nand_flash_sectors_release(
    LX_NAND_FLASH *nand_flash,
    ULONG logical_sector,
    ULONG sector_count);

说明

此服务在 NAND 闪存实例中释放指定数量的逻辑扇区。 在未使用时释放逻辑扇区会使 LevelX 的损耗均衡更有效率。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • logical_sector:要释放的逻辑扇区。
  • sector_count:要发布的逻辑扇区数。

返回值

  • LX_SUCCESS:(0x00) 成功的请求。
  • LX_ERROR:(0x01) 写入 NAND 闪存扇区时出错。

允许来自

线程数

示例

/* Release 10 logical sectors starting at logical sector 20 of the NAND flash instance "my_nand_flash". */
status = lx_nand_flash_sectors_release(&my_nand_flash, 20, 10);

/* If status is LX_SUCCESS, logical sectors 20 through 29 have been released. */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_write

lx_nand_flash_sector_write

写入 NAND 闪存扇区

原型

UINT lx_nand_flash_sector_write(
    LX_NAND_FLASH *nand_flash,
    ULONG logical_sector, 
    VOID *buffer);

说明

此服务在 NAND 闪存实例中写入指定的逻辑扇区。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • logical_sector:要写入的逻辑扇区。
  • buffer:指向逻辑扇区内容的指针。 请注意,缓冲区的大小假定为 NAND 闪存页大小,并为 ULONG 访问而对齐。

返回值

  • LX_SUCCESS:(0X00) 成功的请求。
  • LX_NO_SECTORS:(0x02) 没有更多可用扇区来执行写入操作。
  • LX_ERROR:写入 NAND 闪存扇区时 (0x01) 错误。

允许调用自

线程数

示例

/* Write logical sector 20 of the NAND flash instance "my_nand_flash" with the contents pointed to by "buffer". */  
status = lx_nand_flash_sector_write(&my_nand_flash, 20, buffer);  
  
/* If status is LX_SUCCESS, logical sector 20 has been written with the contents of "buffer". */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release

lx_nand_flash_sectors_write

写入多个 NAND 闪存扇区

原型

UINT lx_nand_flash_sectors_write(
    LX_NAND_FLASH *nand_flash,
    ULONG logical_sector, 
    VOID *buffer, 
    ULONG sector_count);

说明

此服务在 NAND 闪存实例中写入指定数量的逻辑扇区。

输入参数

  • nand_flash:NAND 闪存实例指针。
  • logical_sector:要写入的逻辑扇区。
  • buffer:指向逻辑扇区内容的指针。 请注意,逻辑扇区大小与 NAND 闪存页大小相同,并且假定缓冲区足够大,足以容纳所有要写入的扇区,并对齐 ULONG 访问。
  • sector_count:要写入的逻辑扇区数。

返回值

  • LX_SUCCESS:(0X00) 成功的请求。
  • LX_NO_SECTORS:(0x02) 没有更多可用扇区来执行写入操作。
  • LX_ERROR:写入 NAND 闪存扇区时 (0x01) 错误。

允许调用自

线程数

示例

/* Write 10 logical sectors starting at logical sector 20 of the NAND flash instance "my_nand_flash" with the contents pointed to by "buffer". */
status = lx_nand_flash_sectors_write(&my_nand_flash, 20, buffer, 10);

/* If status is LX_SUCCESS, logical sectors 20 through 29 have been written with the contents of "buffer". */

另请参阅

  • lx_nand_flash_close
  • lx_nand_flash_initialize
  • lx_nand_flash_open
  • lx_nand_flash_page_ecc_check
  • lx_nand_flash_page_ecc_compute
  • lx_nand_flash_sectors_read
  • lx_nand_flash_sectors_release