損耗均衡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:
-
mount wear levelling module for defined partitionwl_mount
-
used to unmount levelling modulewl_unmount
-
used to erase range of addresses in flashwl_erase_range
-
used to write data to the partitionwl_write
-
used to read data from the partitionwl_read
-
return size of avalible memory in byteswl_size
-
returns size of one sectorwl_sector_size
-
為指定的分區挂載損耗均衡子產品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
翻譯水準有限,如有錯誤歡迎指正