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: KEY VALUE STORAGE INTERNAL INTERFACE 15 */ 16 17 #ifndef NV_STORAGE_H 18 #define NV_STORAGE_H 19 20 #include "nv_notify.h" 21 #include "nv.h" 22 23 #include "errcode.h" 24 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif /* __cplusplus */ 29 #endif /* __cplusplus */ 30 31 /** 32 * KV key attribute flags 33 * A key with a normal or encrypted attribute can be set to a permanent attribute again. 34 * A key with a permanent attribute cannot be set to another attribute. 35 * Attribute 3 is considered to be both encrypted and permanent. 36 */ 37 typedef enum { 38 NV_ATTRIBUTE_NORMAL = 0x0, /* Default type, no special attribute */ 39 NV_ATTRIBUTE_PERMANENT = 0x1, /* Key is permanent and can't be deleted or modified */ 40 NV_ATTRIBUTE_ENCRYPTED = 0x2, /* Key is encrypted in flash, The key can be encrypted permanently */ 41 NV_ATTRIBUTE_NON_UPGRADE = 0x4 42 } nv_attributes_t; 43 44 nv_direct_ctrl_t *nv_direct_get_nv_ctrl(void); 45 46 /** 47 * Force store a key value pair, even if the key has been set to permanent. 48 * @param key key to associate kvalue to 49 * @param kvalue value to store 50 * @param kvalue_length length in bytes of kvalue 51 * @return SOC_ERR_SUCCESS or an error code 52 */ 53 errcode_t uapi_nv_write_force(uint16_t key, const uint8_t *kvalue, uint16_t kvalue_length); 54 55 /** 56 * Erase an stored value given its key 57 * @param key key of the key to erase 58 * @return SOC_ERR_SUCCESS or an error code 59 */ 60 errcode_t uapi_nv_delete_key(uint16_t key); 61 62 /** 63 * Update the attributes of an existing key. 64 * @param key key to associate make permanent 65 * @param attr Sets the storage attributes of a key. 66 * @return SOC_ERR_SUCCESS or an error code 67 * @note This key can not then be deleted or overwitten, and there is no mechanism to undo this 68 */ 69 errcode_t uapi_nv_update_key_attr(uint16_t key, nv_key_attr_t *attr, nv_storage_completed_callback func); 70 71 /** 72 * Get key information associated with a specific key 73 * @param key key of the value to get 74 * @param length length of the current key 75 * @param attr The storage attributes of a key. 76 * @return SOC_ERR_SUCCESS or an error code 77 */ 78 errcode_t uapi_nv_get_key_attr(uint16_t key, uint16_t *length, nv_key_attr_t *attr); 79 80 /** 81 * @ingroup iot_nv 82 * @brief compare a value associated with a specific key. 83 * CNcomment:检验特定NV的值 CNend 84 * 85 * @par 描述: 86 * Check whether NV data has been stored. If the stored data is the same 87 * as the input parameter data,a success message is returned. 88 * CNcomment:检查NV数据是否已存储。如果存储的数据与入参数据相同,则返回成功 CNend 89 * @attention None. 90 * 91 * @param key [IN] The key to which the kvalue is associated. 92 * CNcomment:要检验的NV ID CNend 93 * @param kvalue_length [IN] Length of kvalue in bytes. 94 * CNcomment:要检验的NV长度 CNend 95 * @param kvalue [IN] The value to store.CNcomment:待进行对比的NV值 CNend 96 * 97 * @retval #true Success 98 * @retval #false Failure 99 * 100 * @par 依赖: 101 * @li nv 102 * @li nv.h 103 * @see None 104 */ 105 bool uapi_nv_is_stored(uint16_t key, uint16_t kvalue_length, const uint8_t *kvalue); 106 107 #ifdef __cplusplus 108 #if __cplusplus 109 } 110 #endif /* __cplusplus */ 111 #endif /* __cplusplus */ 112 113 #endif /* NV_STORAGE_H */ 114