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:
@@ -1,6 +1,7 @@
|
||||
#include "mqtt_wrapper.h"
|
||||
|
||||
#define BUFFER_LEN 256
|
||||
static unsigned char buffer[BUFFER_LEN];
|
||||
|
||||
static MQTTPacket_connectData mqtt_form_connect_packet(mqtt_con_opt_t *opt)
|
||||
{
|
||||
@@ -20,7 +21,6 @@ int tos_mqtt_connect(char *host, const char *port, mqtt_con_opt_t *opt)
|
||||
int sock = 0;
|
||||
int serialize_len = 0;
|
||||
unsigned char session_present, connack_rc;
|
||||
unsigned char buffer[BUFFER_LEN];
|
||||
MQTTPacket_connectData connect_packet;
|
||||
|
||||
sock = transport_open(host, port);
|
||||
@@ -61,7 +61,6 @@ errout:
|
||||
int tos_mqtt_publish(int sock, mqtt_pub_opt_t*opt)
|
||||
{
|
||||
int serialize_len;
|
||||
unsigned char buffer[BUFFER_LEN];
|
||||
MQTTString pub_topic;
|
||||
|
||||
pub_topic.cstring = opt->topic;
|
||||
@@ -93,7 +92,6 @@ int tos_mqtt_subscribe(int sock, mqtt_sub_opt_t *opt)
|
||||
unsigned short packet_id;
|
||||
int max_count, granted_qos;
|
||||
int serialize_len;
|
||||
unsigned char buffer[BUFFER_LEN];
|
||||
MQTTString sub_topic;
|
||||
|
||||
sub_topic.cstring = opt->topic;
|
||||
@@ -129,7 +127,6 @@ int tos_mqtt_receive(char *topic, int topic_len, unsigned char *payload, int pay
|
||||
unsigned char *incoming_data;
|
||||
int incoming_data_len, payload_copy_len;
|
||||
MQTTString incoming_topic;
|
||||
unsigned char buffer[BUFFER_LEN];
|
||||
|
||||
if (MQTTPacket_read(buffer, sizeof(buffer), transport_getdata) != PUBLISH) {
|
||||
return -1;
|
||||
@@ -151,7 +148,7 @@ int tos_mqtt_receive(char *topic, int topic_len, unsigned char *payload, int pay
|
||||
strncpy(topic, incoming_topic.lenstring.data, topic_copy_len);
|
||||
if (topic_copy_len <= topic_len - 1) {
|
||||
topic[topic_copy_len] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return incoming_data_len;
|
||||
|
@@ -14,6 +14,10 @@ void *salof_alloc(unsigned int size)
|
||||
return tos_mmheap_alloc(size);
|
||||
}
|
||||
|
||||
void *salof_calloc(size_t num, size_t size)
|
||||
{
|
||||
return tos_mmheap_calloc(num, size);
|
||||
}
|
||||
|
||||
void salof_free(void *mem)
|
||||
{
|
||||
@@ -30,13 +34,13 @@ salof_tcb salof_task_create(const char *name,
|
||||
salof_tcb task;
|
||||
k_err_t err;
|
||||
k_stack_t *task_stack;
|
||||
task = salof_alloc(sizeof(k_task_t));
|
||||
task = salof_calloc(1, sizeof(k_task_t));
|
||||
task_stack = salof_alloc(stack_size);
|
||||
err = tos_task_create(task,
|
||||
(char*)name,
|
||||
err = tos_task_create(task,
|
||||
(char*)name,
|
||||
task_entry,
|
||||
param,
|
||||
priority,
|
||||
param,
|
||||
priority,
|
||||
task_stack,
|
||||
stack_size,
|
||||
tick);
|
||||
@@ -53,7 +57,7 @@ salof_mutex salof_mutex_create(void)
|
||||
{
|
||||
salof_mutex mutex;
|
||||
mutex = salof_alloc(sizeof(k_mutex_t));
|
||||
tos_mutex_create((salof_mutex)mutex);
|
||||
tos_mutex_create((salof_mutex)mutex);
|
||||
return mutex;
|
||||
}
|
||||
|
||||
@@ -83,7 +87,7 @@ salof_sem salof_sem_create(void)
|
||||
{
|
||||
salof_sem sem;
|
||||
sem = salof_alloc(sizeof(k_sem_t));
|
||||
tos_sem_create((salof_sem)sem, 0);
|
||||
tos_sem_create((salof_sem)sem, 0);
|
||||
return sem;
|
||||
}
|
||||
|
||||
@@ -120,4 +124,4 @@ char *salof_get_task_name(void)
|
||||
return k_curr_task->name;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@@ -18,18 +18,18 @@ platform_thread_t *platform_thread_init( const char *name,
|
||||
platform_thread_t *thread;
|
||||
k_err_t err;
|
||||
k_stack_t *thread_stack;
|
||||
thread = platform_memory_alloc(sizeof(platform_thread_t));
|
||||
thread = platform_memory_calloc(1, sizeof(platform_thread_t));
|
||||
thread_stack = (k_stack_t*) platform_memory_alloc(stack_size);
|
||||
|
||||
err = tos_task_create(&(thread->thread),
|
||||
(char*)name,
|
||||
|
||||
err = tos_task_create(&(thread->thread),
|
||||
(char*)name,
|
||||
entry,
|
||||
param,
|
||||
priority,
|
||||
param,
|
||||
priority,
|
||||
thread_stack,
|
||||
stack_size,
|
||||
tick);
|
||||
|
||||
|
||||
if(err != K_ERR_NONE) {
|
||||
platform_memory_free(thread);
|
||||
platform_memory_free(thread_stack);
|
||||
|
@@ -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