1721 views|4 replies

155

Posts

1

Resources
The OP
 

[RVB2601 Creative Application Development] User Experience 02 -- KV Storage [Copy link]

 

After a period of modular development of the RVB2601 creative project, I am ready to start integrating the modules into a complete system. I will record the integration process in separate chapters. This chapter records the KV component.

1. Introduction to KV storage system

KV , or " Key-Value ", is a lightweight component for persistent storage in YoC ( Yun on Chip ), mainly used for Nor Flash . The API description from the README.md of the SDK ( kv v7.4.3 ) is shown in the figure below.

Figure 2-1 KV interface description

KV storage must be built on the basis of Flash partitions, so the partitions must be created first. In the " Hello World " case, the partition initialization code is commented out, so you need to remove the comments - this is also a pitfall, which troubled me for a long time at the time (actually, it was also due to carelessness).

Figure 2-2 Partition initialization is commented out by default

2. KV persistence of project parameters

In my project, I need to store some configuration parameters. It is unnecessary to set up a file system for these parameters, and the KV component can meet the needs.

Here we import “ Hello World Demo ” and add KV initialization code in “ app/src/init.c ” .

#include <stdbool.h>
#include <aos/aos.h>
#include <yoc/yoc.h>
#include <yoc/partition.h>
#include <devices/devicelist.h>

#include "board.h"
#include "app_init.h"
#include "drv/pin.h"

const char *TAG = "INIT";

#ifndef CONSOLE_UART_IDX
#define CONSOLE_UART_IDX 0
#endif

/* --------------------by AITA Mr.Fei, global variables--------------------- */
#define ENDIAN_LIMIT   32 //endian counts limit
char GID[9];              //gateway id
char EID[ENDIAN_LIMIT][9];//endians' id
int  endian_count = 1;    //actually endian counts
int  period = 10;         //polling period -- minutes
int  timeout = 15;        //timeout of waiting USR220 resp -- seconds
int  repeat = 3;          //repeat times when timeout

int aita_InitKV(void) {
	char buf[10] = {0}; 
	int ret = -1;
	
	ret = partition_init();
	if (ret > 0) {
		LOGI(TAG, "find %d partitions\n", ret);
	} else {		 
		LOGE(TAG, "partition init failed\n");
		return ret;
	}
	
	ret = aos_kv_init("kv");
	if(ret == 0) {
		LOGE(TAG, "kv init done\n");
	} else {
		LOGE(TAG, "kv init failed\n");
		return -1;
	}
		
	ret = aos_kv_getstring("endian_count", &buf, 10);
	if(ret > 0) {
		endian_count = atoi(buf);
		endian_count = (endian_count<ENDIAN_LIMIT) ? endian_count : ENDIAN_LIMIT;
		printf("endian_count: %d\n", endian_count);
		char eid[5] = "EIDx";
		for(int i=0; i<endian_count; i++) {
			eid[3] = i+0x30;
			aos_kv_getstring(eid, EID[i], 9);
			printf("EID No.%d : %s\n", i, EID[i]);
		}	
	} else {
		LOGE(TAG, "Endian Count load failed\n");
		return ret;
	}
	
	ret = aos_kv_getstring("period", &buf, 10);
	if(ret > 0) {
		period = atoi(buf);
		printf("period: %d\n", period);
	} else {
		LOGE(TAG, "period load failed\n");
		return ret;
	}
	ret = aos_kv_getstring("timeout", &buf, 10);
	if(ret > 0) {
		timeout = atoi(buf);
		printf("timeout: %d\n", timeout);
	} else {
		LOGE(TAG, "timeout load failed\n");
		return ret;
	}
	ret = aos_kv_getstring("repeat", &buf, 10);
	if(ret > 0) {
		repeat = atoi(buf);
		printf("repeat: %d\n", repeat);
	} else {
		LOGE(TAG, "repeat load failed\n");
		return ret;
	}
	return 0;
}

void board_yoc_init()
{
    board_init();
    // uart_csky_register(CONSOLE_UART_IDX);
    console_init(CONSOLE_UART_IDX, 115200, 128);

    ulog_init();
    aos_set_log_level(AOS_LL_DEBUG);
    
    LOGI(TAG, "Build:%s,%s",__DATE__, __TIME__);
    
	aita_InitKV();

    board_cli_init();
}

main.c first tests the KV component and outputs the KV value in the console when the system starts. In order not to be affected by the timed output of " Hello World ", the code is changed to a running light function. For specific implementation, you can refer to the blog post of blogger TL-LED "【Flathead RVB2601 Development Board Trial Experience】GPIO Output Test ( https://en.eeworld.com/bbs/thread-1197715-1-1.html )".

#include <stdlib.h>
#include <string.h>
#include <aos/aos.h>
#include "aos/cli.h"
#include "main.h"
#include "app_init.h"
#include "oled.h"

#define TAG "app"

int main(void) {
    board_yoc_init();
    LOGD(TAG, "%s\n", aos_get_app_version());
    aita_InitBSP();
    while (1) {
        aita_FlashLED();
    }
    return 0;
}

void aita_InitBSP(void) {
	oled_init();
	aita_InitLED();
}

Here is my own code for LED GPIO initialization and running light implementation.

#include <aos/aos.h>
#include <drv/pin.h>
#include <drv/gpio_pin.h>

csi_gpio_pin_t aita_led_red_pin;
csi_gpio_pin_t aita_led_green_pin;
csi_gpio_pin_t aita_led_blue_pin;

void aita_InitLED(void) {
//set pin gpio function
    csi_pin_set_mux(PA7,  PIN_FUNC_GPIO);
    csi_pin_set_mux(PA25, PIN_FUNC_GPIO);
    csi_pin_set_mux(PA4,  PIN_FUNC_GPIO);

//init pin device & set direction
	csi_gpio_pin_init(&aita_led_red_pin,   PA7);
    csi_gpio_pin_dir(&aita_led_red_pin,    GPIO_DIRECTION_OUTPUT);
	csi_gpio_pin_init(&aita_led_green_pin, PA25);
    csi_gpio_pin_dir(&aita_led_green_pin,  GPIO_DIRECTION_OUTPUT);
	csi_gpio_pin_init(&aita_led_blue_pin,  PA4);
    csi_gpio_pin_dir(&aita_led_blue_pin,   GPIO_DIRECTION_OUTPUT);
	
//set leds' state at startup
	csi_gpio_pin_write(&aita_led_red_pin,   GPIO_PIN_HIGH);
	csi_gpio_pin_write(&aita_led_green_pin, GPIO_PIN_HIGH);
	csi_gpio_pin_write(&aita_led_blue_pin,  GPIO_PIN_HIGH);
}

void aita_FlashLED(void) {
	csi_gpio_pin_write(&aita_led_red_pin,   GPIO_PIN_LOW);
	csi_gpio_pin_write(&aita_led_green_pin, GPIO_PIN_HIGH);
	csi_gpio_pin_write(&aita_led_blue_pin,  GPIO_PIN_HIGH);
	aos_msleep(1000);

	csi_gpio_pin_write(&aita_led_red_pin,   GPIO_PIN_HIGH);
	csi_gpio_pin_write(&aita_led_green_pin, GPIO_PIN_LOW);
	csi_gpio_pin_write(&aita_led_blue_pin,  GPIO_PIN_HIGH);
	aos_msleep(1000);
	
	csi_gpio_pin_write(&aita_led_red_pin,   GPIO_PIN_HIGH);
	csi_gpio_pin_write(&aita_led_green_pin, GPIO_PIN_HIGH);
	csi_gpio_pin_write(&aita_led_blue_pin,  GPIO_PIN_LOW);
	aos_msleep(1000);
	
	csi_gpio_pin_write(&aita_led_red_pin,   GPIO_PIN_HIGH);
	csi_gpio_pin_write(&aita_led_green_pin, GPIO_PIN_HIGH);
	csi_gpio_pin_write(&aita_led_blue_pin,  GPIO_PIN_HIGH);
	aos_msleep(1000);
}

Figure 2-3 Console output of KV storage value at startup

Of course, these KV values are written in advance. The project has enabled the KV console command, so that the project parameters can be modified at any time. Considering that in actual application, the serial port can also be connected for debugging on site, so the console is used as a way to configure parameters. To enable the console KV command, just call the api , which is written in the board_cli_init() function in this example .

#include <aos/debug.h>
#include <aos/cli.h>

void board_cli_init()
{
    aos_cli_init();

    extern void cli_reg_cmd_ps(void);
    cli_reg_cmd_ps();

    extern void cli_reg_cmd_free(void);
    cli_reg_cmd_free();
//cli command of kv func	
	extern void cli_reg_cmd_kvtool(void);
	cli_reg_cmd_kvtool();
}

Latest reply

Is there any source code for KV that can be used independently?   Details Published on 2022-4-12 17:16
 
 

6555

Posts

0

Resources
2
 

Storing several configuration parameters to make the project parameters KV persistent seems to be very meaningful.

 
 
 

6818

Posts

11

Resources
3
 
Thanks for sharing. All three of you are my teachers. Everything is new knowledge!
 
 
 

7422

Posts

2

Resources
4
 

Is there any source code for KV that can be used independently?

Comments

There are just a few APIs. Console commands are added here to facilitate editing KV values.  Details Published on 2022-4-12 19:09
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

155

Posts

1

Resources
5
 
freebsder posted on 2022-4-12 17:16 Is there any source code for KV that can be used independently?

There are just a few APIs. Console commands are added here to facilitate editing KV values.

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
Studying Things to Gain Knowledge 05: Dimensions and Elementary Functions

What is dimension? It is usually taught in middle school physics courses and again in university physics courses. Howev ...

【McQueen Trial】Comparison of the accuracy of several ultrasonic sensor programs of McQueen

Purpose Compare the test accuracy of several ultrasonic sensors to provide a reference for everyone's use. Methods Write ...

[Project source code] Digital tube companion - binary to BCD

This article and design code were written by FPGA enthusiast Xiao Meige. Without the author's permission, this article ...

Design of real-time image test device based on LVDS technology

Design of real-time image test device based on LVDS technology

C language uses binary tree to parse polynomials and evaluate

It mainly realizes the analysis of polynomial data calculation. If there is a need to make a simple calculator based on ...

LPS27HHTW MEMS Pressure Sensor

The LPS27HHTW MEMS pressure sensor is an ultra-compact piezoresistive absolute pressure sensor that can be used as a dig ...

Raspberry Pi Bluetooth Basics - Use of bluezero library

This post was last edited by lb8820265 on 2021-8-8 22:50 There are many libraries for operating Bluetooth in Linux s ...

CC2500 Migration Instructions

Be applicable : Applicable to TI chip CC2500 full series modules How to transplant ? The parts to be ported are in rf_ ...

Embedded Qt-Make a stopwatch

This post was last edited by DDZZ669 on 2022-8-7 15:55 Previous article: Embedded Qt - Write and run your first ARM-Qt ...

Successfully deployed deep learning gait recognition algorithm on Allwinner V853 platform

Xin Zhe, a student from the Communication Research Group of Beijing Institute of Technology, successfully transplanted t ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list