炬芯(Actions)BLE ATB110X NVRAM config驱动程序

NVRAM

NVRAM 是一块掉电后数据仍然保持的存储设备,可以是电池供电的 RAM 设备,也 可以是 NOR/NAND Flash 这种非易失存储设备。常用来永久保存用户配置信息和数据 等内容。
NVRAM 配置分为两种:一种是出厂预置的配置,放在 factory 区域;一种是用户动态 写入的配置,放在 user 区域。在读取一个指定配置项时,默认会先从 user 区查找读取 用户写入的配置,如果不存在则去 factory 区域去读取。

驱动接口说明
下面介绍一下 NVRAM config 的具体接口和参数说明
NVRAM config driver interface.

Functions
int nvram_config_get(const char *name, void *data, int max_len)
Read config from NVRAM user region.

Parameters
• name: Config name
• data: Pointer to data buffer
• max_len: Maximum number of bytes to be read Return Value
• 0: If successful, negative errno code otherwise.

int nvram_config_set(const char *name, const void *data, int len)
    Write config to NVRAM user region.

Parameters
• name: Config name
• data: Pointer to data buffer
• len: number of bytes to be write
Return Value
• 0: If successful, negative errno code otherwise.

int nvram_config_clear_all(void)
Write config to NVRAM.
Return Value
• 0: If successful, negative errno code otherwise.
void nvram_config_dump(void)
print all configs in NVRAM

int nvram_config_get_factory(const char *name, void *data, int max_len)
Read config from NVRAM factory region.

Parameters
• name: Config name
• data: Pointer to data buffer
• max_len: Maximum number of bytes to be read


Return Value
• 0: If successful, negative errno code otherwise.

int nvram_config_set_factory(const char *name, const void *data, int len)
Write config to NVRAM factory region.

Parameters
• name: Config name
• data: Pointer to data buffer
• len: number of bytes to be write

 Return Value

      0: If successful, negative errno code otherwise.

驱动使用示例
下面以一个示例介绍一下 NVRAM config 接口的使用

#include

static unsigned char test_nvram_buf[256];
int test_nvram(void)
{
int data_len, i;
printk("\nNVRAM testing\n");
printk("==========================\n");

nvram_config_set("ucfg", "udata", 6);
nvram_config_set_factory("fcfg", "fdata", 6);

data_len = nvram_config_get("ucfg", test_nvram_buf,sizeof(test_nvram_buf));
if (data_len < 0)
{
printk("cannot find config ucfg\n");
return -EIO;
}

printk("nvram user: ucfg: %s\n", test_nvram_buf);

data_len = nvram_config_get_factory("fcfg", test_nvram_ buf, sizeof(test_nvram_buf));
if (data_len < 0)
{
printk("cannot find config fcfg\n", name);
return -EIO;
}

printk("nvram user: fcfg: %s\n", test_nvram_buf);

nvram_config_dump();
}



 

★博文内容均由个人提供,与平台无关,如有违法或侵权,请与网站管理员联系。

★文明上网,请理性发言。内容一周内被举报5次,发文人进小黑屋喔~

评论