• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
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  */
15 
16 /**
17  ****************************************************************************************
18  *
19  * @file duet_flash_kv.h
20  *
21  * @brief this module is based on classical key/value(KV) store system for flash storage.
22  *        provide method to access flash memory by using key/value pairs.
23  *        internal algorithm could balance frequency of flash utilization on different areas
24  *        to improve flash using life.
25  *
26  ****************************************************************************************
27  */
28 #ifndef _DUET_FLASH_KV_H_
29 #define _DUET_FLASH_KV_H_
30 #include "stdint.h"
31 /**
32  * Init the flash kv module.
33  *
34  * @retrun 0 on success, otherwise will be failed.
35  */
36 int32_t duet_flash_kv_init(void);
37 
38 /**
39  * Deinit the kv module.
40  *
41  * @retrun none
42  */
43 void duet_flash_kv_deinit(void);
44 
45 /**
46  * Add a new flash KV pair.
47  *
48  * @param[in]  key    the key of the KV pair.
49  * @param[in]  value  the value of the KV pair.
50  * @param[in]  len    the length of the value.
51  * @param[in]  sync   save the KV pair to flash right now (should always be 1).
52  *
53  * @return  0 on success, negative error on failure.
54  */
55 int32_t duet_flash_kv_set(const char *key, const void *value, int32_t len, int32_t sync);
56 
57 /**
58  * Get the flash KV pair's value stored in buffer by its key.
59  *
60  * @note: the buffer_len should be larger than the real length of the value,
61  *        otherwise buffer would be NULL.
62  *
63  * @param[in]      key         the key of the KV pair to get.
64  * @param[out]     buffer      the memory to store the value.
65  * @param[in-out]  buffer_len  in: the length of the input buffer.
66  *                             out: the real length of the value.
67  *
68  * @return  0 on success, negative error on failure.
69  */
70 int32_t duet_flash_kv_get(const char *key, void *buffer, int32_t *buffer_len);
71 
72 /**
73  * Delete the flash KV pair by its key.
74  *
75  * @param[in]  key  the key of the KV pair to delete.
76  *
77  * @return  0 on success, negative error on failure.
78  */
79 int32_t duet_flash_kv_del(const char *key);
80 
81 #endif  /* _DUET_FLASH_KV_H_ */
82 
83