fix some calloc bug
1. some calloc fix 2. fix some document error 3. refactor kv API, to be compatible with ota API
This commit is contained in:
@@ -53,8 +53,8 @@ typedef uint64_t kv_dword_t; // double word
|
||||
#define KV_BLK_FLAG_HANGING 0x10 /* index building failed, we mark a hanging flag here, and will give another chance to do a retry */
|
||||
|
||||
#define KV_FLASH_START (kv_ctl.flash_ctl.flash_start)
|
||||
#define KV_FLASH_SIZE (kv_ctl.flash_ctl.flash_size)
|
||||
#define KV_FLASH_END (KV_FLASH_START + KV_FLASH_SIZE)
|
||||
#define KV_FLASH_END (kv_ctl.flash_ctl.flash_end)
|
||||
#define KV_FLASH_SIZE (KV_FLASH_END - KV_FLASH_START)
|
||||
#define KV_FLASH_SECTOR_SIZE_LOG2 (kv_ctl.flash_ctl.sector_size_log2)
|
||||
#define KV_FLASH_SECTOR_SIZE (1 << KV_FLASH_SECTOR_SIZE_LOG2)
|
||||
#define KV_FLASH_WRITE_ALIGN (kv_ctl.flash_ctl.flash_write_align)
|
||||
@@ -126,7 +126,7 @@ typedef struct kv_flash_control_st {
|
||||
uint8_t sector_size_log2;
|
||||
uint8_t flash_write_align;
|
||||
uint32_t flash_start;
|
||||
uint32_t flash_size;
|
||||
uint32_t flash_end;
|
||||
|
||||
kv_flash_drv_t flash_drv;
|
||||
} kv_flash_ctl_t;
|
||||
@@ -313,7 +313,7 @@ __STATIC_INLINE__ void kv_blk_reset_hanging(uint32_t blk_start)
|
||||
|
||||
typedef kv_err_t (*kv_item_walker_t)(kv_item_t *item, const void *patten);
|
||||
|
||||
__API__ kv_err_t tos_kv_init(kv_flash_drv_t *flash_drv, kv_flash_prop_t *flash_prop);
|
||||
__API__ kv_err_t tos_kv_init(uint32_t flash_start, uint32_t flash_end, kv_flash_drv_t *flash_drv, kv_flash_prop_t *flash_prop);
|
||||
|
||||
__API__ kv_err_t tos_kv_deinit(void);
|
||||
|
||||
|
@@ -38,8 +38,6 @@ typedef struct kv_flash_drv_st {
|
||||
typedef struct kv_flash_property_st {
|
||||
uint8_t sector_size_log2;
|
||||
kv_flash_pgm_type_t pgm_type;
|
||||
uint32_t flash_start;
|
||||
uint32_t flash_size;
|
||||
} kv_flash_prop_t;
|
||||
|
||||
#endif /* _TOS_KV_FLASH_H_ */
|
||||
|
@@ -91,12 +91,12 @@ __STATIC__ kv_err_t kv_flash_blk_erase(uint32_t blk_start)
|
||||
return kv_flash_erase(blk_start, KV_BLK_SIZE);
|
||||
}
|
||||
|
||||
__STATIC__ void kv_flash_ctl_init(kv_flash_drv_t *flash_drv, kv_flash_prop_t *flash_prop)
|
||||
__STATIC__ void kv_flash_ctl_init(uint32_t flash_start, uint32_t flash_end, kv_flash_drv_t *flash_drv, kv_flash_prop_t *flash_prop)
|
||||
{
|
||||
memcpy(&kv_ctl.flash_ctl.flash_drv, flash_drv, sizeof(kv_flash_drv_t));
|
||||
|
||||
KV_FLASH_START = flash_prop->flash_start;
|
||||
KV_FLASH_SIZE = flash_prop->flash_size;
|
||||
KV_FLASH_START = flash_start;
|
||||
KV_FLASH_END = flash_end;
|
||||
KV_FLASH_SECTOR_SIZE_LOG2 = flash_prop->sector_size_log2;
|
||||
|
||||
if (flash_prop->pgm_type == KV_FLASH_PROGRAM_TYPE_BYTE) {
|
||||
@@ -866,17 +866,17 @@ __STATIC__ kv_err_t kv_item_update(kv_item_t *item, const char *key, const void
|
||||
return kv_item_delete(item);
|
||||
}
|
||||
|
||||
__STATIC__ kv_err_t kv_param_verify(kv_flash_drv_t *flash_drv, kv_flash_prop_t *flash_prop)
|
||||
__STATIC__ kv_err_t kv_param_verify(uint32_t flash_start, uint32_t flash_end, kv_flash_drv_t *flash_drv, kv_flash_prop_t *flash_prop)
|
||||
{
|
||||
if (!flash_drv || !flash_prop) {
|
||||
return KV_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!KV_IS_ALINGED_LOG2(flash_prop->flash_start, flash_prop->sector_size_log2)) {
|
||||
if (!KV_IS_ALINGED_LOG2(flash_start, flash_prop->sector_size_log2)) {
|
||||
return KV_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!KV_IS_ALINGED_LOG2(flash_prop->flash_size, flash_prop->sector_size_log2)) {
|
||||
if (!KV_IS_ALINGED_LOG2(flash_end, flash_prop->sector_size_log2)) {
|
||||
return KV_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
@@ -1196,17 +1196,17 @@ __DEBUG__ kv_err_t tos_kv_walkthru(void)
|
||||
return KV_ERR_NONE;
|
||||
}
|
||||
|
||||
__API__ kv_err_t tos_kv_init(kv_flash_drv_t *flash_drv, kv_flash_prop_t *flash_prop)
|
||||
__API__ kv_err_t tos_kv_init(uint32_t flash_start, uint32_t flash_end, kv_flash_drv_t *flash_drv, kv_flash_prop_t *flash_prop)
|
||||
{
|
||||
kv_err_t err;
|
||||
|
||||
if (kv_param_verify(flash_drv, flash_prop) != KV_ERR_NONE) {
|
||||
if (kv_param_verify(flash_start, flash_end, flash_drv, flash_prop) != KV_ERR_NONE) {
|
||||
return KV_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
memset(&kv_ctl, 0, sizeof(kv_ctl));
|
||||
|
||||
kv_flash_ctl_init(flash_drv, flash_prop);
|
||||
kv_flash_ctl_init(flash_start, flash_end, flash_drv, flash_prop);
|
||||
|
||||
err = kv_mgr_ctl_init();
|
||||
if (err != KV_ERR_NONE) {
|
||||
|
Reference in New Issue
Block a user