b_mod_kv
数据结构
typedef struct
{
uint8_t init_f;
const uint32_t dev;
const uint32_t address;
const uint32_t total_size;
const uint32_t erase_size;
int32_t write_index;
uint32_t write_offset;
uint32_t empty_count;
} bKVStruct_t;
typedef bKVStruct_t bKVInstance_t;
接口介绍
// 定义实例,如果存储器不需要擦除,则e_size为0
#define bKV_INSTANCE(name, dev_no, addr, size, e_size) \
bKVInstance_t name = { \
.init_f = 0, .dev = dev_no, .address = addr, .total_size = size, .erase_size = e_size};
int bKVInit(bKVInstance_t *pinstance);
int bKVGetValue(bKVInstance_t *pinstance, const char *key, uint8_t *pbuf, uint32_t len,
uint32_t *prlen);
int bKVSetValue(bKVInstance_t *pinstance, const char *key, uint8_t *pbuf, uint32_t len);
int bKVDeleteValue(bKVInstance_t *pinstance, const char *key);
int bKVGetValueLength(bKVInstance_t *pinstance, const char *key);
使用例子
bKV_INSTANCE(gKVInstance, bTESTFLASH, 0, 4096 * 2, 4096);
int main()
{
...
bInit();
bKVInit(&gKVInstance);
bKVGetValue(&gKVInstance, "boot", (uint8_t *)&boot_count), sizeof(boot_count), NULL);
b_log("boot : %d\r\n", boot_count);
boot_count += 1;
bKVSetValue(&gKVInstance, "boot", (uint8_t *)&boot_count), sizeof(boot_count));
...
}