加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ESP NVS

发布时间:2020-12-15 07:30:15 所属栏目:百科 来源:网络整理
导读:简介:NVS的主要功能是:存储键值(存在flash上面); NVS利用spi_flash_{read|write|erase}这些API来操作数据在内存上的删改写,内存上data类型nvs子类型所代表的空间全部是NVS使用的; NVS操作?数据的删改些运用一些API,就像是在电脑上打开文件,写文件,

简介:NVS的主要功能是:存储键值(存在flash上面);

NVS利用spi_flash_{read|write|erase}这些API来操作数据在内存上的删改写,内存上data类型nvs子类型所代表的空间全部是NVS使用的;

NVS操作?数据的删改些运用一些API,就像是在电脑上打开文件,写文件,关闭文件一样。如nvs_open,nvs_close,nvs_write;

NVS一般存储一下比较小的数据还是很好使用的,如果要存储比较大的内容,还是用FAT更合适;

NVS操作的数据为键值对,key是ASCII字符串,最大长度是15个字符,数值的话可以包含下列类型:uint8_t,?int8_t,?uint16_t,?int16_t,?uint32_t,?int32_t,?uint64_t,?int64_t;数据类型还包括以0结尾的字符串,可变长度的二进制数据;String values are currently limited to 4000 bytes. This includes the null terminator. Blob values are limited to 508000 bytes or (97.6% of the partition size - 4000) bytes whichever is lower.字符串数据当前限制为4000字节,这4000自己包括NULL,BLOB数据限制为508000字节

key值要求是唯一的,如果给存在的key更新对应的数据,如果更新的数据和老数据是同一个类型,那么数据会更新,如果新数据老数据是不同类型,报错;

Currently NVS uses a portion of main flash memory through?spi_flash_{read|write|erase}?APIs. The library uses the all the partitions with?data?type and?nvs?subtype. The application can choose to use the partition with label?nvs?through?nvs_open?API or any of the other partition by specifying its name through?nvs_open_from_part?API.

上面这段英文翻译:NVS通过spi_flash_{read|write|erase}?API来使用内存上指定的分区,data类型,nvs分类型分区的存储都可以被NVS使用,可以用nvs_open这个API打开,或者用nvs_open_from_part?这个API打开指定类型和分类型名称的内存分区;

将来NVS可能会支持将数据存储在另外的存储上(比如SPI或者I2C)

如果NVS存储被破坏了,那么就会被整体清楚掉,make?erase_flash就是用来干这个事情的;

?

To mitigate potential conflicts in key names between different components,NVS assigns each key-value pair to one of namespaces. Namespace names follow the same rules as key names,i.e. 15 character maximum length. Namespace name is specified in the?nvs_open?or?nvs_open_from_partcall. This call returns an opaque handle,which is used in subsequent calls to?nvs_read_*,?nvs_write_*,and?nvs_commit?functions. This way,handle is associated with a namespace,and key names will not collide with same names in other namespaces. Please note that the namespaces with same name in different NVS partitions are considered as separate namespaces.

上面英文的翻译如下:为了减少不同组件之间键名之间的冲突(至于什么组件,这段英文没有提),NVS给每个键值对分配了一个名空间(这段英文的意思是名空间有很多),名空间的命名规则和键的命名规则是相同的,比如说最多允许15个字符的字符串。名空间的名字在nvs_open?或者nvs_open_from_part这两个API中都有明确写出。这两个API都会返回句柄,返回的句柄在?nvs_read_*,?和?nvs_commit?这些API中都有用到,句柄和名空间的名字之间存在对应关系。不同名空间下即使存在同名的key值也是不冲突的。请注意不同的NVS存储空间内同名的名空间是相互独立的,没有任何互相影响;

?

NVS stores key-value pairs sequentially,with new key-value pairs being added at the end. When a value of any given key has to be updated,new key-value pair is added at the end of the log and old key-value pair is marked as erased.

上面这段翻译:NVS存储键值对在内存中是连续的,新存储的键值对?放在最后头,当更新一个已经存在的键值对时,也是放在最后头,原先的键值对就标记删除。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读