nRF5的Flash操作扩展

/ 0评 / 0

FDS是一个Flash操作组件,实际上,nRF的很多操作都依赖这个组件.虽然他归类成Experimental,具体文档链接:

https://www.lijingquan.net/nrf5/nrf5/lib_fds.html#lib_fds_example (这个页面似乎有点慢)

https://www.lijingquan.net/nrf5/nrf5/lib_fds_functionality.html (可以直接查看这个)

首先,数据无非就是增删查改,文档里描述东西还挺多,什么文件,描述什么的,其实管不着,不如直接来仿真学习快.

看到一开始进入fds_record_find,查找到的会填入desc和tok结构体.

跟踪发现,定义了一个文件F010,定义一个记录地址7010,可见这个是

#define CONFIG_FILE (0xF010)

#define CONFIG_REC_KEY (0x7010)

但是其实文件ID是有限制的,官方描述如下:

Record keys should be in the range 0x0001 - 0xBFFF. The value 0x0000 is reserved by the system. The values from 0xC000 to 0xFFFF are reserved for use by the Peer Manager module and can only be used in applications that do not include Peer Manager.

File IDs should be in the range 0x0000 - 0xBFFF. The value 0xFFFF is used by the system. The values from 0xC000 to 0xFFFE are reserved for use by the Peer Manager module and can only be used in applications that do not include Peer Manager.

接下来fds_record_open读取数据会存到config.p_data,这个data可以是任意数据哦,比如例程是个结构体.

为了更方便理解,还有cli.c,里面有很多单一的操作方法.总结起来很简单,就是file下有key,key下有内容,内容可以有很多,一样有CURD.

有这样的库和例子,储存什么操作什么,简直太方便了.