Skip to content

Commit 233b90a

Browse files
authored
Merge pull request #4998 from loogg/mlw
修复 ringblk_buf 在不使用动态内存时报错的问题以及 AT 组件优化
2 parents 40df71e + f1e1b6b commit 233b90a

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

components/drivers/include/ipc/ringblk_buf.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ typedef struct rt_rbb *rt_rbb_t;
7676

7777
/* rbb (ring block buffer) API */
7878
void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t block_set, rt_size_t blk_max_num);
79+
rt_size_t rt_rbb_get_buf_size(rt_rbb_t rbb);
80+
81+
#ifdef RT_USING_HEAP
7982
rt_rbb_t rt_rbb_create(rt_size_t buf_size, rt_size_t blk_max_num);
8083
void rt_rbb_destroy(rt_rbb_t rbb);
81-
rt_size_t rt_rbb_get_buf_size(rt_rbb_t rbb);
84+
#endif
8285

8386
/* rbb block API */
8487
rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size);

components/drivers/src/ringblk_buf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t
4444
}
4545
RTM_EXPORT(rt_rbb_init);
4646

47+
#ifdef RT_USING_HEAP
48+
4749
/**
4850
* ring block buffer object create
4951
*
@@ -102,6 +104,8 @@ void rt_rbb_destroy(rt_rbb_t rbb)
102104
}
103105
RTM_EXPORT(rt_rbb_destroy);
104106

107+
#endif
108+
105109
static rt_rbb_blk_t find_empty_blk_in_set(rt_rbb_t rbb)
106110
{
107111
rt_size_t i;

components/net/at/src/at_client.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,16 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
310310
rt_mutex_take(client->lock, RT_WAITING_FOREVER);
311311

312312
client->resp_status = AT_RESP_OK;
313-
client->resp = resp;
314313

315314
if (resp != RT_NULL)
316315
{
317316
resp->buf_len = 0;
318317
resp->line_counts = 0;
319318
}
320319

320+
client->resp = resp;
321+
rt_sem_control(client->resp_notice, RT_IPC_CMD_RESET, RT_NULL);
322+
321323
va_start(args, cmd_expr);
322324
at_vprintfln(client->device, cmd_expr, args);
323325
va_end(args);
@@ -327,7 +329,7 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
327329
if (rt_sem_take(client->resp_notice, resp->timeout) != RT_EOK)
328330
{
329331
cmd = at_get_last_cmd(&cmd_size);
330-
LOG_D("execute command (%.*s) timeout (%d ticks)!", cmd_size, cmd, resp->timeout);
332+
LOG_W("execute command (%.*s) timeout (%d ticks)!", cmd_size, cmd, resp->timeout);
331333
client->resp_status = AT_RESP_TIMEOUT;
332334
result = -RT_ETIMEOUT;
333335
goto __exit;
@@ -381,6 +383,7 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
381383

382384
rt_mutex_take(client->lock, RT_WAITING_FOREVER);
383385
client->resp = resp;
386+
rt_sem_control(client->resp_notice, RT_IPC_CMD_RESET, RT_NULL);
384387

385388
start_time = rt_tick_get();
386389

@@ -426,6 +429,8 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
426429
*/
427430
rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size)
428431
{
432+
rt_size_t len;
433+
429434
RT_ASSERT(buf);
430435

431436
if (client == RT_NULL)
@@ -440,7 +445,7 @@ rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size
440445

441446
rt_mutex_take(client->lock, RT_WAITING_FOREVER);
442447

443-
rt_size_t len = at_utils_send(client->device, 0, buf, size);
448+
len = at_utils_send(client->device, 0, buf, size);
444449

445450
rt_mutex_release(client->lock);
446451

@@ -480,9 +485,7 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
480485
*/
481486
rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_int32_t timeout)
482487
{
483-
rt_size_t read_idx = 0;
484-
rt_err_t result = RT_EOK;
485-
char ch;
488+
rt_size_t len = 0;
486489

487490
RT_ASSERT(buf);
488491

@@ -494,28 +497,30 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
494497

495498
while (1)
496499
{
497-
if (read_idx < size)
500+
rt_size_t read_len;
501+
502+
rt_sem_control(client->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
503+
504+
read_len = rt_device_read(client->device, 0, buf + len, size);
505+
if(read_len > 0)
498506
{
499-
result = at_client_getchar(client, &ch, timeout);
500-
if (result != RT_EOK)
501-
{
502-
LOG_E("AT Client receive failed, uart device get data error(%d)", result);
503-
return 0;
504-
}
507+
len += read_len;
508+
size -= read_len;
509+
if(size == 0)
510+
break;
505511

506-
buf[read_idx++] = ch;
512+
continue;
507513
}
508-
else
509-
{
514+
515+
if(rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout)) != RT_EOK)
510516
break;
511-
}
512517
}
513518

514519
#ifdef AT_PRINT_RAW_CMD
515-
at_print_raw_cmd("urc_recv", buf, size);
520+
at_print_raw_cmd("urc_recv", buf, len);
516521
#endif
517522

518-
return read_idx;
523+
return len;
519524
}
520525

521526
/**

0 commit comments

Comments
 (0)