• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: KV Storage Library store access interface
15  */
16 
17 #ifndef NV_STORE_H
18 #define NV_STORE_H
19 
20 #include "nv_page.h"
21 #include "platform_types.h"
22 #include "nv.h"
23 #include "errcode.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29 #endif /* __cplusplus */
30 
31 /** Store ids for each core, with a minimum hamming distance of 10 between each value */
32 #define KV_STORE_ID_SCPU    0xCB7E
33 #define KV_STORE_ID_ACPU    0x254D
34 #define KV_STORE_ID_BACKUP  0x34B2
35 
36 typedef enum {
37     KV_STORE_APPLICATION,
38     KV_STORE_MAX_NUM,
39 } kv_store_t;
40 
41 typedef struct {
42     uint16_t kvalue_max_length;
43     uint16_t kvalue_actual_length;
44     uint8_t *kvalue;
45 } kv_store_key_data_t;
46 
47 cores_t kv_store_to_core(kv_store_t store);
48 kv_store_t kv_store_from_core(cores_t core);
49 uint16_t kv_store_get_id(kv_store_t store);
50 uint8_t kv_store_get_page_count(kv_store_t store);
51 errcode_t kv_store_get_page_handle(kv_store_t store, uint32_t page_index, kv_page_handle_t *page);
52 errcode_t kv_store_find_valid_key(kv_store_t store, kv_key_id key_id, kv_key_handle_t *key);
53 errcode_t kv_store_get_backup_key(kv_key_id key_id, kv_store_key_data_t *key_data, kv_attributes_t *attributes,
54     kv_page_location page_location);
55 errcode_t kv_store_get_key_attr(kv_store_t store, kv_key_id key_id, uint16_t *len, kv_attributes_t *attributes);
56 errcode_t kv_store_get_key(kv_store_t store, kv_key_id key_id, kv_store_key_data_t *key_data,
57                            kv_attributes_t *attributes);
58 errcode_t kv_store_get_status(kv_store_t store, nv_store_status_t *store_status);
59 errcode_t kv_store_find_write_page(kv_store_t store, uint32_t required_space, kv_page_handle_t *page,
60                                    kv_page_status_t *page_status);
61 errcode_t kv_store_read_backup_key(kv_key_id key_id, kv_store_key_data_t *key_data, kv_attributes_t *attributes);
62 errcode_t kv_store_get_backup_key_attr(kv_key_id key_id, uint16_t *len,
63     kv_attributes_t *attributes, kv_key_handle_t *backup_key);
64 
65 #ifdef __cplusplus
66 #if __cplusplus
67 }
68 #endif /* __cplusplus */
69 #endif /* __cplusplus */
70 
71 #endif /* NV_STORE_H_ */
72