CI130X SDK API手册  2.2.0
本手册用于描述CI130X SDK各个组件和驱动API
结构体 | 宏定义 | 类型定义 | 枚举 | 函数 | 变量
ci_nvdata_manage.c 文件参考
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "ci_log.h"
#include "ci_nvdata_manage.h"
#include "ci_nvdata_port.h"
#include "ci130x_uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "sdk_default_config.h"
#include "romlib_runtime.h"

结构体

struct  cinv_hotid_node_st
 
struct  cinv_hotid_mang_t
 
struct  cinv_mang_rec_t
 
struct  cinv_feb_head_t
 
struct  cinv_data_item_header_t
 

宏定义

#define MEMORY_COPY_USED   (1)
 
#define CINV_IO_BUFFER_SIZE   (256)
 
#define CINV_DATA_ITEM_MAX_LEN   (CINV_IO_BUFFER_SIZE - sizeof(cinv_data_item_header_t))
 
#define CINV_FEB_HEADER_MAGIC_ERASED   (0xFFFFFFFF)
 
#define CINV_FEB_HEADER_OFFSET   (0)
 
#define CINV_FEB_HEADER_SIZE   (sizeof(cinv_feb_head_t))
 
#define CINV_DATA_ITEM_START_OFF   (CINV_FEB_HEADER_OFFSET+CINV_FEB_HEADER_SIZE)
 
#define CINV_DATA_ITEM_STATUS_OFF   (0)
 
#define CINV_FEB_NUM_TO_ADDR(blk_num, offset)   (g_flash_base_addr + CINV_FLASH_ERASE_BLOCK_SIZE*(blk_num) + (offset))
 
#define CINV_FEB_NO_USED   (0xffffu)
 
#define CINV_ITEM_NO_USED   (0xffffu)
 
#define CINV_ITEM_LEN_ACTUAL_USED(len)   (((len)+3)/4*4)
 
#define POWEROFF_TEST(pos)   do{}while(0) /*no test and save code size*/
 
#define PFT_POS_RECLAIM_BEFORE_ERASE1   0
 
#define PFT_POS_BEFORE_WRITING_NEW   1
 
#define PFT_POS_BEFORE_WRITING_START   2
 
#define PFT_POS_BEFORE_WRITING_DONE   3
 
#define PFT_POS_AFTER_MARK_TARNS   4
 
#define PFT_POS_RECLAIM_BEFORE_ERASE2   5
 
#define PFT_POS_DELETE_ITEM   6
 
#define PFT_POS_SET_TRANSFERING   7
 

类型定义

typedef struct cinv_hotid_node_st cinv_hotid_node_t
 

枚举

enum  cinv_feb_status_t {
  CINV_FEB_STATUS_ERASED = 0xFFFFFFFF,
  CINV_FEB_STATUS_EMPTY = 0xFFFFFEFE,
  CINV_FEB_STATUS_ACTIVED = 0xFFFFF8F8,
  CINV_FEB_STATUS_TRANSFERING = 0xFFFFF0F0
}
 
enum  cinv_data_item_status_t {
  CINV_DATA_ITEM_STATUS_EMPTY = 0xFFFFFFFF,
  CINV_DATA_ITEM_STATUS_WRITING = 0xFEFEFEFE,
  CINV_DATA_ITEM_STATUS_VALID = 0xFCFCFCFC,
  CINV_DATA_ITEM_STATUS_TRANS = 0xF8F8F8F8,
  CINV_DATA_ITEM_STATUS_DELETE = 0xF0F0F0F0,
  CINV_DATA_ITEM_STATUS_ERROR = 0x00000000
}
 
enum  item_deal_status_t {
  ITEM_DEAL_SUCESS,
  ITEM_DEAL_ERROR,
  ITEM_DEAL_FIND_ID_DONE
}
 
enum  item_buf_deal_status_t {
  ITEM_BUF_DEAL_SUCESS,
  ITEM_BUF_DEAL_ERROR,
  ITEM_BUF_DEAL_END
}
 

函数

static void poweroff_random_test (uint32_t pos)
 
static bool check_erased (const void *buf, int32_t len)
 check current buffer data is erased 更多...
 
static void erase_feb (uint16_t blk_num)
 erased flash block, no check, 更多...
 
static void check_and_erase_feb (uint16_t blk_num)
 first read,if already is erased, do nothing, else erase it 更多...
 
static cinv_hotid_node_tfind_hotid_node (uint32_t id)
 
static void hotid_init (void)
 
cinv_item_ret_t cinv_register_hotid (uint32_t hot_id)
 register hotid. 更多...
 
static void hotid_update (uint16_t blk_num, uint16_t off, uint32_t id)
 if nvdata item id in hot id array, update item address 更多...
 
static uint32_t find_hotid (uint32_t id, uint16_t *blk_num)
 find hot id address 更多...
 
static uint32_t calc_chk_sum (uint8_t *buf, uint16_t len)
 calculate the data checksum 更多...
 
static bool write_item_status (uint16_t blk_num, uint16_t offset, cinv_data_item_status_t status)
 write nvdata item header status to flash, and verify 更多...
 
static bool write_feb_status (uint16_t blk_num, cinv_feb_status_t status)
 write feb header status to flash, and verify 更多...
 
static bool write_item (uint16_t blk_num, uint32_t id, uint16_t len, void *buf)
 writes an item to nvdata region 更多...
 
item_deal_status_t reclaim_block_deal_flow (cinv_data_item_header_t *di_hdr, uint16_t *write_off, uint32_t old_id)
 
item_deal_status_t init_page_deal_flow (cinv_data_item_header_t *di_hdr, uint32_t blk_num, uint16_t off, uint16_t *lost)
 
item_deal_status_t init_page_id_deal_flow (cinv_data_item_header_t *di_hdr, uint32_t id, bool transid_valid, uint16_t *lost)
 
static int32_t traverse_feb (uint32_t func, uint32_t blk_num, uint32_t id, bool transid_valid)
 
static int32_t init_page_id (uint32_t blk_num, uint32_t id, bool transid_valid)
 
static int32_t init_page (uint32_t blk_num)
 
static bool reclaim_block (uint32_t blk_num, uint32_t old_id)
 reclaim a feb, valid item of this feb copy to reserved feb, then erased it and set this to reserved 更多...
 
static int32_t init_item (uint32_t id, uint16_t len, void *buf)
 
static uint16_t find_item (uint32_t id, uint16_t *ret_blk, bool transid_valid)
 find a nvdata item, and return address 更多...
 
static uint16_t find_id (uint32_t id, uint16_t *blk)
 
void cinv_init (uint32_t flash_addr, uint32_t size)
 初始化nvdata管理信息和nvdata区域 更多...
 
cinv_item_ret_t cinv_item_init (uint32_t id, uint16_t len, void *buf)
 如果nvdata 项不存在,会创建和初始化传入的id参数项,在调用cinv_item_read()或cinv_item_write()函数前,必须先调用该函数。 更多...
 
cinv_item_ret_t cinv_item_write (uint32_t id, uint16_t len, void *buf)
 将数据项写到nvdata中 更多...
 
cinv_item_ret_t cinv_item_read (uint32_t id, uint16_t len, void *buf, uint16_t *real_len)
 从nvdata里读数据。该函数可以读nvdata项的全部内容或一部分。数据会拷贝到*buf数据指针,如果传入的长度大于实际长度,只会将实际长度的数据拷贝到*buf数据指针。 更多...
 
cinv_item_ret_t cinv_item_delete (uint32_t id)
 删除nvdata里的数据项. 更多...
 

变量

static uint8_t cinv_rd_io_buf [(256)]
 
static uint8_t cinv_wr_io_buf [(256)]
 
static cinv_hotid_mang_t cinv_hotid_m = {NULL}
 
static cinv_mang_rec_t cinv_mang_r
 
static uint32_t g_flash_base_addr
 
static uint16_t g_feb_total_count
 
static uint16_t trans_blk = (0xffffu)
 
static uint16_t trans_off = (0xffffu)
 
static uint32_t trans_id
 

详细描述

版本
0.1
日期
2019-04-30

结构体说明

◆ cinv_hotid_node_st

struct cinv_hotid_node_st
成员变量
uint32_t hot_id
uint16_t id_blk
uint16_t id_off
struct cinv_hotid_node_st * next

◆ cinv_hotid_mang_t

struct cinv_hotid_mang_t
成员变量
cinv_hotid_node_t * head

◆ cinv_mang_rec_t

struct cinv_mang_rec_t
成员变量
uint16_t feb_rev
uint16_t * p_feb_lost
uint16_t * p_feb_off

◆ cinv_feb_head_t

struct cinv_feb_head_t
成员变量
uint32_t is_rev
uint32_t magic
cinv_feb_status_t status

◆ cinv_data_item_header_t

struct cinv_data_item_header_t
成员变量
uint8_t buf[0]
uint32_t chk_sum
uint32_t id
uint32_t len
cinv_data_item_status_t status

宏定义说明

◆ CINV_DATA_ITEM_MAX_LEN

#define CINV_DATA_ITEM_MAX_LEN   (CINV_IO_BUFFER_SIZE - sizeof(cinv_data_item_header_t))

◆ CINV_DATA_ITEM_START_OFF

#define CINV_DATA_ITEM_START_OFF   (CINV_FEB_HEADER_OFFSET+CINV_FEB_HEADER_SIZE)

◆ CINV_DATA_ITEM_STATUS_OFF

#define CINV_DATA_ITEM_STATUS_OFF   (0)

◆ CINV_FEB_HEADER_MAGIC_ERASED

#define CINV_FEB_HEADER_MAGIC_ERASED   (0xFFFFFFFF)

◆ CINV_FEB_HEADER_OFFSET

#define CINV_FEB_HEADER_OFFSET   (0)

◆ CINV_FEB_HEADER_SIZE

#define CINV_FEB_HEADER_SIZE   (sizeof(cinv_feb_head_t))

◆ CINV_FEB_NO_USED

#define CINV_FEB_NO_USED   (0xffffu)

◆ CINV_FEB_NUM_TO_ADDR

#define CINV_FEB_NUM_TO_ADDR (   blk_num,
  offset 
)    (g_flash_base_addr + CINV_FLASH_ERASE_BLOCK_SIZE*(blk_num) + (offset))

◆ CINV_IO_BUFFER_SIZE

#define CINV_IO_BUFFER_SIZE   (256)

◆ CINV_ITEM_LEN_ACTUAL_USED

#define CINV_ITEM_LEN_ACTUAL_USED (   len)    (((len)+3)/4*4)

◆ CINV_ITEM_NO_USED

#define CINV_ITEM_NO_USED   (0xffffu)

◆ MEMORY_COPY_USED

#define MEMORY_COPY_USED   (1)

◆ PFT_POS_AFTER_MARK_TARNS

#define PFT_POS_AFTER_MARK_TARNS   4

◆ PFT_POS_BEFORE_WRITING_DONE

#define PFT_POS_BEFORE_WRITING_DONE   3

◆ PFT_POS_BEFORE_WRITING_NEW

#define PFT_POS_BEFORE_WRITING_NEW   1

◆ PFT_POS_BEFORE_WRITING_START

#define PFT_POS_BEFORE_WRITING_START   2

◆ PFT_POS_DELETE_ITEM

#define PFT_POS_DELETE_ITEM   6

◆ PFT_POS_RECLAIM_BEFORE_ERASE1

#define PFT_POS_RECLAIM_BEFORE_ERASE1   0

◆ PFT_POS_RECLAIM_BEFORE_ERASE2

#define PFT_POS_RECLAIM_BEFORE_ERASE2   5

◆ PFT_POS_SET_TRANSFERING

#define PFT_POS_SET_TRANSFERING   7

◆ POWEROFF_TEST

#define POWEROFF_TEST (   pos)    do{}while(0) /*no test and save code size*/

类型定义说明

◆ cinv_hotid_node_t

枚举类型说明

◆ cinv_data_item_status_t

枚举值
CINV_DATA_ITEM_STATUS_EMPTY 
CINV_DATA_ITEM_STATUS_WRITING 
CINV_DATA_ITEM_STATUS_VALID 
CINV_DATA_ITEM_STATUS_TRANS 
CINV_DATA_ITEM_STATUS_DELETE 
CINV_DATA_ITEM_STATUS_ERROR 

◆ cinv_feb_status_t

枚举值
CINV_FEB_STATUS_ERASED 
CINV_FEB_STATUS_EMPTY 
CINV_FEB_STATUS_ACTIVED 
CINV_FEB_STATUS_TRANSFERING 

◆ item_buf_deal_status_t

枚举值
ITEM_BUF_DEAL_SUCESS 
ITEM_BUF_DEAL_ERROR 
ITEM_BUF_DEAL_END 

◆ item_deal_status_t

枚举值
ITEM_DEAL_SUCESS 
ITEM_DEAL_ERROR 
ITEM_DEAL_FIND_ID_DONE 

函数说明

◆ calc_chk_sum()

static uint32_t calc_chk_sum ( uint8_t *  buf,
uint16_t  len 
)
static

calculate the data checksum

参数
buf: data buffer pointer
len: buffer lens
返回
uint32_t : checksum value

◆ check_and_erase_feb()

static void check_and_erase_feb ( uint16_t  blk_num)
static

first read,if already is erased, do nothing, else erase it

参数
blk_num: feb number

◆ check_erased()

static bool check_erased ( const void *  buf,
int32_t  len 
)
static

check current buffer data is erased

参数
buf: data buffer pointer
len: data buffer length
返回
true : erased
false : wrong, have no erased data

◆ cinv_register_hotid()

cinv_item_ret_t cinv_register_hotid ( uint32_t  hot_id)

register hotid.

参数
idNvdata item id
返回值
CINV_OPER_SUCCESSId already existed, no action taken.
CINV_OPER_FAILEDFailure to find or create id.

◆ erase_feb()

static void erase_feb ( uint16_t  blk_num)
static

erased flash block, no check,

参数
blk_num: feb number

◆ find_hotid()

static uint32_t find_hotid ( uint32_t  id,
uint16_t *  blk_num 
)
static

find hot id address

参数
id:nvdata item id
blk_num:return value feb number
返回
uint32_t CINV_ITEM_NO_USED : no find, other: offset of feb

◆ find_hotid_node()

static cinv_hotid_node_t* find_hotid_node ( uint32_t  id)
static

◆ find_id()

static uint16_t find_id ( uint32_t  id,
uint16_t *  blk 
)
static

◆ find_item()

static uint16_t find_item ( uint32_t  id,
uint16_t *  ret_blk,
bool  transid_valid 
)
static

find a nvdata item, and return address

参数
id: nvdata item id
ret_blk: return value feb number of address
transid_valid: if CINV_DATA_ITEM_STATUS_TRANS item used as valid item
返回
uint16_t : offset in feb of address or CINV_FEB_NO_USED if not find

◆ hotid_init()

static void hotid_init ( void  )
static

◆ hotid_update()

static void hotid_update ( uint16_t  blk_num,
uint16_t  off,
uint32_t  id 
)
static

if nvdata item id in hot id array, update item address

参数
blk_num: feb number of item address
off: offset in feb of item address
id: nvdata item id

◆ init_item()

static int32_t init_item ( uint32_t  id,
uint16_t  len,
void *  buf 
)
static
参数
id
len
buf
返回
int32_t

◆ init_page()

static int32_t init_page ( uint32_t  blk_num)
static

◆ init_page_deal_flow()

item_deal_status_t init_page_deal_flow ( cinv_data_item_header_t di_hdr,
uint32_t  blk_num,
uint16_t  off,
uint16_t *  lost 
)

◆ init_page_id()

static int32_t init_page_id ( uint32_t  blk_num,
uint32_t  id,
bool  transid_valid 
)
static

◆ init_page_id_deal_flow()

item_deal_status_t init_page_id_deal_flow ( cinv_data_item_header_t di_hdr,
uint32_t  id,
bool  transid_valid,
uint16_t *  lost 
)

◆ poweroff_random_test()

static void poweroff_random_test ( uint32_t  pos)
static

◆ reclaim_block()

static bool reclaim_block ( uint32_t  blk_num,
uint32_t  old_id 
)
static

reclaim a feb, valid item of this feb copy to reserved feb, then erased it and set this to reserved

参数
blk_num: feb number
old_id: item id don't copy, this id will write a new , so old don't copy
返回
true : relaim ok
false

◆ reclaim_block_deal_flow()

item_deal_status_t reclaim_block_deal_flow ( cinv_data_item_header_t di_hdr,
uint16_t *  write_off,
uint32_t  old_id 
)

◆ traverse_feb()

static int32_t traverse_feb ( uint32_t  func,
uint32_t  blk_num,
uint32_t  id,
bool  transid_valid 
)
static

◆ write_feb_status()

static bool write_feb_status ( uint16_t  blk_num,
cinv_feb_status_t  status 
)
static

write feb header status to flash, and verify

参数
blk_num: feb number
status: feb status
返回
true : write ok
false : write error

◆ write_item()

static bool write_item ( uint16_t  blk_num,
uint32_t  id,
uint16_t  len,
void *  buf 
)
static

writes an item to nvdata region

参数
blk_num: feb number
id: nvdata item id
len: byte count of data to write
buf: data buffer
返回
true : write ok
false : have some error

◆ write_item_status()

static bool write_item_status ( uint16_t  blk_num,
uint16_t  offset,
cinv_data_item_status_t  status 
)
static

write nvdata item header status to flash, and verify

参数
blk_num: feb number of item address
offset: offset in feb of item address
status: data item status
返回
true : write ok
false : write error

变量说明

◆ cinv_hotid_m

cinv_hotid_mang_t cinv_hotid_m = {NULL}
static

◆ cinv_mang_r

cinv_mang_rec_t cinv_mang_r
static

◆ cinv_rd_io_buf

uint8_t cinv_rd_io_buf[(256)]
static

◆ cinv_wr_io_buf

uint8_t cinv_wr_io_buf[(256)]
static

◆ g_feb_total_count

uint16_t g_feb_total_count
static

◆ g_flash_base_addr

uint32_t g_flash_base_addr
static

◆ trans_blk

uint16_t trans_blk = (0xffffu)
static

◆ trans_id

uint32_t trans_id
static

◆ trans_off

uint16_t trans_off = (0xffffu)
static