Merge pull request #4998 from loogg/mlw

修复 ringblk_buf 在不使用动态内存时报错的问题以及 AT 组件优化
This commit is contained in:
guo 2021-09-04 18:11:30 +08:00 committed by GitHub
commit 233b90a3ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 21 deletions

View File

@ -76,9 +76,12 @@ typedef struct rt_rbb *rt_rbb_t;
/* rbb (ring block buffer) API */ /* rbb (ring block buffer) API */
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); 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);
rt_size_t rt_rbb_get_buf_size(rt_rbb_t rbb);
#ifdef RT_USING_HEAP
rt_rbb_t rt_rbb_create(rt_size_t buf_size, rt_size_t blk_max_num); rt_rbb_t rt_rbb_create(rt_size_t buf_size, rt_size_t blk_max_num);
void rt_rbb_destroy(rt_rbb_t rbb); void rt_rbb_destroy(rt_rbb_t rbb);
rt_size_t rt_rbb_get_buf_size(rt_rbb_t rbb); #endif
/* rbb block API */ /* rbb block API */
rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size); rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size);

View File

@ -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
} }
RTM_EXPORT(rt_rbb_init); RTM_EXPORT(rt_rbb_init);
#ifdef RT_USING_HEAP
/** /**
* ring block buffer object create * ring block buffer object create
* *
@ -102,6 +104,8 @@ void rt_rbb_destroy(rt_rbb_t rbb)
} }
RTM_EXPORT(rt_rbb_destroy); RTM_EXPORT(rt_rbb_destroy);
#endif
static rt_rbb_blk_t find_empty_blk_in_set(rt_rbb_t rbb) static rt_rbb_blk_t find_empty_blk_in_set(rt_rbb_t rbb)
{ {
rt_size_t i; rt_size_t i;

View File

@ -310,7 +310,6 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
rt_mutex_take(client->lock, RT_WAITING_FOREVER); rt_mutex_take(client->lock, RT_WAITING_FOREVER);
client->resp_status = AT_RESP_OK; client->resp_status = AT_RESP_OK;
client->resp = resp;
if (resp != RT_NULL) if (resp != RT_NULL)
{ {
@ -318,6 +317,9 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
resp->line_counts = 0; resp->line_counts = 0;
} }
client->resp = resp;
rt_sem_control(client->resp_notice, RT_IPC_CMD_RESET, RT_NULL);
va_start(args, cmd_expr); va_start(args, cmd_expr);
at_vprintfln(client->device, cmd_expr, args); at_vprintfln(client->device, cmd_expr, args);
va_end(args); va_end(args);
@ -327,7 +329,7 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
if (rt_sem_take(client->resp_notice, resp->timeout) != RT_EOK) if (rt_sem_take(client->resp_notice, resp->timeout) != RT_EOK)
{ {
cmd = at_get_last_cmd(&cmd_size); cmd = at_get_last_cmd(&cmd_size);
LOG_D("execute command (%.*s) timeout (%d ticks)!", cmd_size, cmd, resp->timeout); LOG_W("execute command (%.*s) timeout (%d ticks)!", cmd_size, cmd, resp->timeout);
client->resp_status = AT_RESP_TIMEOUT; client->resp_status = AT_RESP_TIMEOUT;
result = -RT_ETIMEOUT; result = -RT_ETIMEOUT;
goto __exit; goto __exit;
@ -381,6 +383,7 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
rt_mutex_take(client->lock, RT_WAITING_FOREVER); rt_mutex_take(client->lock, RT_WAITING_FOREVER);
client->resp = resp; client->resp = resp;
rt_sem_control(client->resp_notice, RT_IPC_CMD_RESET, RT_NULL);
start_time = rt_tick_get(); start_time = rt_tick_get();
@ -426,6 +429,8 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
*/ */
rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size) rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size)
{ {
rt_size_t len;
RT_ASSERT(buf); RT_ASSERT(buf);
if (client == RT_NULL) 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
rt_mutex_take(client->lock, RT_WAITING_FOREVER); rt_mutex_take(client->lock, RT_WAITING_FOREVER);
rt_size_t len = at_utils_send(client->device, 0, buf, size); len = at_utils_send(client->device, 0, buf, size);
rt_mutex_release(client->lock); rt_mutex_release(client->lock);
@ -480,9 +485,7 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
*/ */
rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_int32_t timeout) rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_int32_t timeout)
{ {
rt_size_t read_idx = 0; rt_size_t len = 0;
rt_err_t result = RT_EOK;
char ch;
RT_ASSERT(buf); RT_ASSERT(buf);
@ -494,28 +497,30 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
while (1) while (1)
{ {
if (read_idx < size) rt_size_t read_len;
{
result = at_client_getchar(client, &ch, timeout);
if (result != RT_EOK)
{
LOG_E("AT Client receive failed, uart device get data error(%d)", result);
return 0;
}
buf[read_idx++] = ch; rt_sem_control(client->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
}
else read_len = rt_device_read(client->device, 0, buf + len, size);
if(read_len > 0)
{ {
break; len += read_len;
size -= read_len;
if(size == 0)
break;
continue;
} }
if(rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout)) != RT_EOK)
break;
} }
#ifdef AT_PRINT_RAW_CMD #ifdef AT_PRINT_RAW_CMD
at_print_raw_cmd("urc_recv", buf, size); at_print_raw_cmd("urc_recv", buf, len);
#endif #endif
return read_idx; return len;
} }
/** /**