Skip to content

Commit 15511d2

Browse files
authored
Merge pull request #328 from cruise2018/iot_link
fix:lwm2m:fix the oberve mutex created and delete
2 parents cd5e561 + 9061610 commit 15511d2

File tree

5 files changed

+78
-12
lines changed

5 files changed

+78
-12
lines changed

iot_link/link_misc/link_misc.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ char *osal_strdup(const char *ch);
7171

7272

7373

74+
/**
75+
*
76+
* dataoff
77+
* ring buffer map: | ----datalen-------
78+
* | / \
79+
* |/ \
80+
* ----------------------------------------------------------
81+
* | empty space |//////valid data///////| |
82+
* ----------------------------------------------------------
83+
* | \ /
84+
* | \ /
85+
* | \ /
86+
* | ---------------buflen--------------------------
87+
* buf
88+
*
89+
* attention that do dump read or write means no data will really write or read,
90+
* it only changed the dataoff or datalen, and you make sure that the dump read
91+
* or write length is legal
92+
*
93+
* */
7494

7595
/**
7696
* @brief: this is the ring buffer data structure, implement as the common function
@@ -84,6 +104,7 @@ typedef struct
84104
int dataoff; ///< which means the valid data offset in the buffer
85105
}tag_ring_buffer_t;
86106

107+
typedef tag_ring_buffer_t ring_buffer_t;
87108

88109
/**
89110
* @brief:use this function to make a new ring handle
@@ -136,6 +157,16 @@ int ring_buffer_write(tag_ring_buffer_t *ring,unsigned char *buf, int len);
136157

137158
int ring_buffer_read(tag_ring_buffer_t *ring,unsigned char *buf, int len);
138159

160+
#define ring_buffer_buf(x) (x->buf)
161+
#define ring_buffer_buflen(x) (x->buflen)
162+
#define ring_buffer_data(x) (x->buf + x->dataoff)
163+
//#define ring_buffer_datalen(x) (x->datalen)
164+
//#define ring_buffer_freespace(x) (x->buflen - x->datalen)
165+
166+
#define ring_buffer_dataoff(x) (x->dataoff)
167+
#define ring_buffer_dumpread(x,y) do{x->dataoff = (x->dataoff + y)%x->buflen; x->datalen -= y;}while(0)
168+
#define ring_buffer_dumpwrite(x,y) do{x->datalen += y;)while(0)
169+
139170
/**
140171
* @brief:use this function check out how many data in the ring buffer
141172
*

iot_link/network/lwm2m/wakaama_lwm2m/port/lwm2m_port.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ int lwm2m_destroy(void *handle)
466466

467467
if (NULL != handle_data->lwm2m_context)
468468
{
469+
470+
#ifdef LWM2M_CLIENT_MODE
471+
osal_mutex_del(handle_data->lwm2m_context->observe_mutex);
472+
#endif
473+
469474
lwm2m_close(handle_data->lwm2m_context);
470475
}
471476

@@ -668,6 +673,20 @@ static int __config(void **handle, lwm2m_al_init_param_t *init_param)
668673
osal_semp_del(hd->quit_sem);
669674
return LWM2M_MALLOC_FAILED;
670675
}
676+
#ifdef LWM2M_CLIENT_MODE
677+
678+
if(false == osal_mutex_create(&lwm2m_context->observe_mutex))
679+
{
680+
ATINY_LOG(LOG_FATAL, "memory not enough");
681+
lwm2m_free(lwm2m_context->endpointName);
682+
lwm2m_free(lwm2m_context);
683+
osal_mutex_del(g_data_mutex);
684+
osal_semp_del(hd->quit_sem);
685+
osal_free(hd->recv_buffer);
686+
return LWM2M_MALLOC_FAILED;
687+
}
688+
#endif
689+
671690

672691
#ifdef CONFIG_FEATURE_FOTA
673692
result = lwm2m_fota_manager_set_storage_device(lwm2m_fota_manager_get_instance());
@@ -684,6 +703,9 @@ static int __config(void **handle, lwm2m_al_init_param_t *init_param)
684703

685704
(void)lwm2m_fota_manager_set_lwm2m_context(lwm2m_fota_manager_get_instance(), lwm2m_context);
686705
#endif
706+
707+
708+
687709
hd->client_data.lwm2mH = lwm2m_context;
688710
hd->lwm2m_context = lwm2m_context;
689711
*handle = hd;

iot_link/os/novaos/novaos_imp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void *__task_create(const char *name,int (*task_entry)(void *args),\
6262

6363
if((stack_size > 0) && (NULL == stack))
6464
{
65-
ret = task_spawn(name,prior, 0,stack_size + 0x1000,task_entry,(uintptr_t)args);
65+
ret = task_spawn(name,prior, 0,stack_size ,task_entry,(uintptr_t)args);
6666
}
6767

6868
return ret;

iot_link/shell/shell_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ this file implement the shell for the system.the following instruction you must
8686
//DEFINES FOR THE SHELL SERVER TASK STACK SIZE
8787

8888
#ifndef CONFIG_SHELL_TASKSTACK
89-
#define CONFIG_SHELL_TASKSTACK 0x400
89+
#define CONFIG_SHELL_TASKSTACK 0x800
9090
#endif
9191

9292

iot_link/stimer/stimer.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@
4444
#include <stdio.h>
4545

4646

47-
#if CONFIG_STIMER_ENABLE
48-
49-
5047
#include <osal.h>
5148
#include <stimer.h>
5249

@@ -55,7 +52,7 @@
5552

5653
typedef struct timer_item
5754
{
58-
const char *name; ///< verify the timer, will be used in the debug
55+
char *name; ///< verify the timer, will be used in the debug
5956
uint32_t cycle; ///< timer cycle
6057
uint32_t flag; ///< timer flag
6158
fn_stimer_handler handler; ///< timer handler
@@ -269,18 +266,31 @@ int32_t stimer_init()
269266
stimer_t stimer_create(const char *name,fn_stimer_handler handler, void *arg,uint32_t cycle,uint32_t flag)
270267
{
271268
stimer_item_t *item;
269+
int mem_len;
270+
271+
mem_len = sizeof(stimer_item_t);
272+
273+
if(NULL != name)
274+
{
275+
mem_len += strlen(name) + 1;
276+
}
272277

273-
item = osal_malloc(sizeof(stimer_item_t));
278+
item = osal_malloc( mem_len);
274279
if(NULL == item)
275280
{
276281
return item;
277282
}
278283
memset(item,0,sizeof(stimer_item_t));
279-
item->name = name;
280284
item->cycle = cycle;
281285
item->flag = flag;
282286
item->handler = handler;
283287
item->args = arg;
288+
if(NULL != name)
289+
{
290+
item->name = (char *)item +sizeof(stimer_item_t);
291+
strcpy(item->name, name);
292+
}
293+
284294

285295
if(item->flag & cn_stimer_flag_start)
286296
{
@@ -386,6 +396,7 @@ int32_t stimer_ioctl(stimer_t timer,en_stimer_opt_t opt, void *arg)
386396
}
387397

388398

399+
#if CONFIG_SHELL_ENABLE
389400
#include <shell.h>
390401
static int32_t stimer_print(int32_t argc, const char *argv[])
391402
{
@@ -394,14 +405,15 @@ static int32_t stimer_print(int32_t argc, const char *argv[])
394405

395406
if(true == osal_mutex_lock(s_stimer_cb.mutex))
396407
{
397-
printf("%-8s %-8s %-8s %-8s %-5s %-5s %s\n\r",\
398-
"TimerNo","Cycle","Handler","Arg","Start","Once","DeadTime");
408+
printf("%-12s %-8s %-8s %-8s %-5s %-5s %s\n\r",\
409+
"Timer-Name","Cycle","Handler","Arg","Start","Once","DeadTime");
399410

400411
item = s_stimer_cb.lst;
401412
while(NULL != item)
402413
{
403-
printf("%-8d %08x %08x %08x %-5s %-5s %x\n\r",\
404-
timer_number++,(unsigned int)item->cycle,(unsigned int)item->handler,(unsigned int)(uintptr_t)item->args,\
414+
printf("%-12s %08x %08x %08x %-5s %-5s %x\n\r",\
415+
(NULL==item->name)?"UNKONW":item->name,\
416+
(unsigned int)item->cycle,(unsigned int)item->handler,(unsigned int)(uintptr_t)item->args,\
405417
item->flag&cn_stimer_flag_start?"Yes":"No",item->flag&cn_stimer_flag_once?"Yes":"No",\
406418
(unsigned int)item->dead_time);
407419
item = item->nxt;
@@ -415,5 +427,6 @@ static int32_t stimer_print(int32_t argc, const char *argv[])
415427
}
416428
OSSHELL_EXPORT_CMD(stimer_print,"stimer","stimer");
417429

430+
418431
#endif
419432

0 commit comments

Comments
 (0)