官方文档翻译-ESP32-Wear Levelling APIs

损耗均衡API

概述

Most of the flash devices and specially SPI flash devices that are used in ESP32 have sector based organization and have limited amount of erase/modification cycles per memory sector. To avoid situation when one sector reach the limit of erases when other sectors was used not often, we have made a component that avoid this situation. The wear levelling component share the amount of erases between all sectors in the memory without user interaction. The wear_levelling component contains APIs related to reading, writing, erasing, memory mapping data in the external SPI flash through the partition component. It also has higher-level APIs which work with FAT filesystem defined in the FAT filesystem.

大多数在ESP32中使用的闪存器件和特别的SPI闪存器件都具有基于扇区的组织结构,并且每个存储器扇区的擦除/修改次数是有限的。为了避免过度使用单一扇区,我们提供了相应的组件。损耗组件共享内存中所有扇区的擦除次数,无需用户介入。wear_levelling组件包含了通过分区组件(partition component)对外部SPI闪存进行读取,写入,擦除和存储器映射相关的API。它还具有更高级别的API,它们与FAT文件系统中定义的FAT文件系统协同工作。

The wear levelling component, together with FAT FS component, works with FAT FS sector size 4096 bytes which is standard size of the flash devices. In this mode the component has best performance, but needs additional memoty in the RAM. To save internal memory the component has two additional modes to work with sector size 512 bytes: Performance and Safety modes. In Performance mode by erase sector operation data will be stored to the RAM, sector will be erased and then data will be stored back to the flash. If by this operation power off situation will occur, the complete 4096 bytes will be lost. To prevent this the Safety mode was implemented. In safety mode the data will be first stored to the flash and after sector will be erased, will be stored back. If power off situation will occur, after power on, the data will be recovered. By default defined the sector size 512 bytes and Performance mode. To change these values please use the configuration menu.
损耗均衡组件与FAT FS组件一起使用,FAT FAT扇区大小为4096字节,这是闪存设备的标准大小。在这种模式下,组件具有最佳性能,但需要在RAM中增加额外的内存。为了节省内部存储器,该组件有两个额外的模式可用于512字节的扇区大小:性能(Performance)和安全(Safety)模式。在性能模式下,擦除扇区的操作会将先将数据存储到RAM中,然后擦除扇区,最后将数据存储回闪存。如果操作过程中断电,那么整个扇区(4096字节)数据将会丢失。为了防止这种情况,可以使用安全模式。在安全模式下,数据将首先存储到闪存中(先存储到空闲的扇区?),在扇区被擦除后,数据将被存储回去。如果发生断电情况,上电后数据会被恢复。默认情况下,定义扇区大小为512字节并使用性能模式。要更改这些值,请使用配置菜单。

The wear levelling component does not cache data in RAM. Write and erase functions modify flash directly, and flash contents is consistent when the function returns.
损耗均衡组件不会将数据缓存在RAM中。写入和擦除功能直接修改闪存,并且在函数返回时闪存内容一致(意思是函数返回时完成?)。

损耗均衡访问API

This is the set of APIs for working with data in flash:
这是用于处理Flash中数据的一组API:

  • wl_mount mount wear levelling module for defined partition
  • wl_unmount used to unmount levelling module
  • wl_erase_range used to erase range of addresses in flash
  • wl_write used to write data to the partition
  • wl_read used to read data from the partition
  • wl_size return size of avalible memory in bytes
  • wl_sector_size returns size of one sector

  • wl_mount 为指定的分区挂载损耗均衡模块

  • wl_unmount 用于卸载损耗均衡模块
  • wl_erase_range 用于擦除闪存中(指定的)的地址范围
  • wl_write 用于将数据写入分区
  • wl_read 用于从分区读取数据
  • wl_size 以字节为单位返回可用内存的大小
  • wl_sector_size 返回一个扇区的大小

Generally, try to avoid using the raw wear levelling functions in favor of filesystem-specific functions.
通常,尽量避免使用原始损耗均衡功能,利用文件系统特定的功能。

内存大小

The memory size calculated in the wear Levelling module based on parameters of partition. The module use few sectors of flash for internal data.
根据分区参数在损耗均衡模块中计算的内存大小。该模块使用少量的闪存部分作为内部数据。

See also

  • FAT文件系统
  • 分区表文档

应用示例

An example which combines wear levelling driver with FATFS library is provided in examples/storage/wear_levelling directory. This example initializes the wear levelling driver, mounts FATFS partition, and writes and reads data from it using POSIX and C library APIs. See README.md file in the example directory for more information.
examples/storage/wear_levelling目录中提供了一个将损耗均衡驱动程序与FATFS库相结合的示例。本示例初始化损耗均衡驱动程序,安装FATFS分区,并使用POSIX和C库API写入和读取数据。请参阅示例目录中的README.md文件以获取更多信息。

高级API参考

头文件

  • fatfs/src/esp_vfs_fat.h

本文翻译自:https://esp-idf.readthedocs.io/en/latest/api-reference/storage/wear-levelling.html

翻译水平有限,如有错误欢迎指正

你可能感兴趣的:(嵌入式,esp32,单片机)