码迷,mamicode.com
首页 > 其他好文 > 详细

ESP NVS

时间:2019-03-02 23:40:28      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:pre   assign   values   键值对   names   字节   not   ssi   cte   

简介: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_tint8_tuint16_tint16_tuint32_tint32_tuint64_tint64_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更新对应的数据,如果更新的数据和老数据是同一个类型,那么数据会更新,如果新数据老数据是不同类型,报错;

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_write_*, 和 nvs_commit 这些API中都有用到,句柄和名空间的名字之间存在对应关系。不同名空间下即使存在同名的key值也是不冲突的。请注意不同的NVS存储空间内同名的名空间是相互独立的,没有任何互相影响;

 

ESP NVS

标签:pre   assign   values   键值对   names   字节   not   ssi   cte   

原文地址:https://www.cnblogs.com/braveheart007/p/10463562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!