mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-22 19:44:24 +08:00
[drivers][serial_v2]允许阻塞接收超过rx缓冲区大小的数据、增加超时时间、flush、获取缓冲区数据长度命令、数据溢出逻辑修复、稳定性细节优化、添加更多serial_v2测试用例
[components][serial_v2] 优化txflush逻辑、对tx的activated做中断保护 [components][at] at_client适配新版serial_v2 [components][at] at_server适配新版serial_v2 [components][serial_v2] 测试用例增加循环调用,format测试用例 [components][serial_v2] poll模式判断逻辑错误 [components][serial_v2] 测试用例去掉一些非必要延时 [components][serial_v2] 测试例程使用menuconfig进行配置,更新readme [components][at_client] at_client_getchar返回值错误、at_client解析线程优先级错误设置 [components][at] 错误码应该返回负值 [components][serial_v2] TCFLSH和FIONREAD完善、control函数增加错误返回值 [components][serial_v2] RT_SERIAL_CTRL_GET_RX_DATA_LEN更改为RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT [utest][serial_v2] TC_UART_SEND_TIMES替换为RT_SERIAL_TC_SEND_ITERATIONS [components][serial_v2] FIONREAD参数应该是无符号类型 [utest][serial_v2] 完善测试用例 [components][serial_v2] 避免使用三目运算符 [components][serial_v2] 使用clang-format格式化代码 [components][serial_v2] 添加get超时时间命令 [components][serial_v2] 完善posix接口 [components][serial_v2] 阻塞接口添加阻塞时间为0时的处理逻辑、优化RX阻塞接收逻辑 [components][serial_v2] 设置超时时间命令的参数改为指针形式 [components][serial_v2] nbuf发送添加超时时间为0时的逻辑 [components][serial_v2] 完善添加测试用例 [utest][serial_v2] 修复依赖关系 [components][serial_v2] 非阻塞模式下tx_flush错误修复 [components][serial_v2] activated使用原子API [components][serial_v2] 优化DMA逻辑、没使能DMA时屏蔽DMA逻辑节约资源 [components][serial_v2] 提供写满时丢弃新数据和覆盖旧数据策略,写满丢弃策略效率更高 [components][serial_v2] 部分平台适配写满时两种策略功能 [components][serial_v2] DMA模式暂不支持丢弃新数据策略 [utest][serial_v2] 优化测试代码 [components][serial_v2] DMA模式下使用乒乓缓冲、DMA模式支持丢弃新数据策略 [utest][serial_v2] 适配DMA乒乓缓冲 [bsp][serial_v2] 部分bsp适配DMA下乒乓缓冲 [components][serial_v2] 使用spinlock替换中断,对部分结构体变量使用原子操作 [utest][serial_v2] 更新测试用例 [components][at] 适配new serialv2不再判断RTT版本号 [components][at] 删除多余的中文注释 [utest][serial_v2] 添加交叉echo示例,qemu环境下专用 [bsp][qemu] 适配串口v2并开启fifo [components][at] 修复合并导致的错误 [bsp][n32] 适配serial_v2,没有经过测试 [components][serial_v2] 格式化代码 [utest][serial_v2] 删除无意义的打印
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@@ -12,8 +12,7 @@
|
||||
#define __DEV_SERIAL_V2_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
|
||||
#include <rtdevice.h>
|
||||
/**
|
||||
* @addtogroup group_Drivers RTTHREAD Driver
|
||||
* @defgroup group_Serial_v2 Serial v2
|
||||
@@ -169,6 +168,9 @@
|
||||
#define NRZ_NORMAL 0 /* Non Return to Zero : normal mode */
|
||||
#define NRZ_INVERTED 1 /* Non Return to Zero : inverted mode */
|
||||
|
||||
/**
|
||||
* device flag
|
||||
*/
|
||||
#define RT_DEVICE_FLAG_RX_BLOCKING 0x1000
|
||||
#define RT_DEVICE_FLAG_RX_NON_BLOCKING 0x2000
|
||||
|
||||
@@ -180,21 +182,42 @@
|
||||
#define RT_SERIAL_TX_BLOCKING RT_DEVICE_FLAG_TX_BLOCKING
|
||||
#define RT_SERIAL_TX_NON_BLOCKING RT_DEVICE_FLAG_TX_NON_BLOCKING
|
||||
|
||||
/**
|
||||
* hw device control commands
|
||||
*/
|
||||
#define RT_DEVICE_CHECK_OPTMODE 0x20
|
||||
|
||||
/**
|
||||
* hw serial control commands
|
||||
*/
|
||||
#define RT_HW_SERIAL_CTRL_GETC 0x01 /* Tx irq get char */
|
||||
#define RT_HW_SERIAL_CTRL_PUTC 0x02 /* Rx irq put char */
|
||||
#define RT_HW_SERIAL_CTRL_GET_DMA_PING_BUF 0x03 /* Get DMA ping-pong buffer */
|
||||
|
||||
/**
|
||||
* hw isr event
|
||||
*/
|
||||
#define RT_SERIAL_EVENT_RX_IND 0x01 /* Rx indication */
|
||||
#define RT_SERIAL_EVENT_TX_DONE 0x02 /* Tx complete */
|
||||
#define RT_SERIAL_EVENT_RX_DMADONE 0x03 /* Rx DMA transfer done */
|
||||
#define RT_SERIAL_EVENT_TX_DMADONE 0x04 /* Tx DMA transfer done */
|
||||
#define RT_SERIAL_EVENT_RX_TIMEOUT 0x05 /* Rx timeout */
|
||||
|
||||
/**
|
||||
* device commands
|
||||
* 0x40 - special device control commands
|
||||
*/
|
||||
#define RT_SERIAL_CTRL_SET_RX_TIMEOUT 0x41 /* set Rx timeout. Call before rt_device_read. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_SET_TX_TIMEOUT 0x42 /* set Tx timeout. Call before rt_device_write. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_GET_RX_TIMEOUT 0x43 /* get Rx timeout. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_GET_TX_TIMEOUT 0x44 /* get Tx timeout. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_RX_FLUSH 0x45 /* clear rx buffer. Discard all data */
|
||||
#define RT_SERIAL_CTRL_TX_FLUSH 0x46 /* clear tx buffer. Blocking and wait for the send buffer data to be sent. not supported in poll mode */
|
||||
#define RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT 0x47 /* get unread bytes count. not supported in poll mode */
|
||||
|
||||
#define RT_SERIAL_ERR_OVERRUN 0x01
|
||||
#define RT_SERIAL_ERR_FRAMING 0x02
|
||||
#define RT_SERIAL_ERR_PARITY 0x03
|
||||
|
||||
#define RT_SERIAL_TX_DATAQUEUE_SIZE 2048
|
||||
#define RT_SERIAL_TX_DATAQUEUE_LWM 30
|
||||
|
||||
#define RT_SERIAL_RX_MINBUFSZ 64
|
||||
#define RT_SERIAL_TX_MINBUFSZ 64
|
||||
|
||||
@@ -216,7 +239,8 @@
|
||||
RT_SERIAL_RX_MINBUFSZ, /* rxBuf size */ \
|
||||
RT_SERIAL_TX_MINBUFSZ, /* txBuf size */ \
|
||||
RT_SERIAL_FLOWCONTROL_NONE, /* Off flowcontrol */ \
|
||||
0 \
|
||||
0, /* reserved */ \
|
||||
0, /* dma_ping_bufsz */ \
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,6 +263,10 @@ struct serial_configure
|
||||
rt_uint32_t tx_bufsz :16;
|
||||
rt_uint32_t flowcontrol :1;
|
||||
rt_uint32_t reserved :5;
|
||||
|
||||
#ifdef RT_SERIAL_USING_DMA
|
||||
rt_uint32_t dma_ping_bufsz :16;
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -248,12 +276,15 @@ struct rt_serial_rx_fifo
|
||||
{
|
||||
struct rt_ringbuffer rb;
|
||||
|
||||
#ifdef RT_SERIAL_USING_DMA
|
||||
struct rt_ringbuffer dma_ping_rb;
|
||||
#endif
|
||||
|
||||
struct rt_completion rx_cpt;
|
||||
|
||||
rt_uint16_t rx_cpt_index;
|
||||
rt_size_t rx_cpt_index;
|
||||
|
||||
/* software fifo */
|
||||
rt_uint8_t buffer[];
|
||||
rt_atomic_t rx_timeout;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -264,14 +295,13 @@ struct rt_serial_tx_fifo
|
||||
{
|
||||
struct rt_ringbuffer rb;
|
||||
|
||||
rt_size_t put_size;
|
||||
|
||||
rt_bool_t activated;
|
||||
|
||||
struct rt_completion tx_cpt;
|
||||
|
||||
/* software fifo */
|
||||
rt_uint8_t buffer[];
|
||||
rt_size_t put_size;
|
||||
|
||||
rt_atomic_t tx_timeout;
|
||||
|
||||
rt_atomic_t activated;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -288,6 +318,8 @@ struct rt_serial_device
|
||||
void *serial_rx;
|
||||
void *serial_tx;
|
||||
|
||||
struct rt_spinlock spinlock;
|
||||
|
||||
struct rt_device_notify rx_notify;
|
||||
};
|
||||
|
||||
@@ -321,6 +353,7 @@ struct rt_uart_ops
|
||||
*/
|
||||
void rt_hw_serial_isr(struct rt_serial_device *serial, int event);
|
||||
|
||||
rt_err_t rt_hw_serial_control_isr(struct rt_serial_device *serial, int cmd, void *args);
|
||||
|
||||
/**
|
||||
* @brief Register a serial device to device list
|
||||
|
||||
@@ -13,6 +13,17 @@ menuconfig RT_USING_SERIAL
|
||||
config RT_USING_SERIAL_V2
|
||||
bool "RT_USING_SERIAL_V2"
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Choice Serial version"
|
||||
depends on RT_USING_SERIAL_V2
|
||||
default RT_SERIAL_BUF_STRATEGY_OVERWRITE
|
||||
config RT_SERIAL_BUF_STRATEGY_DROP
|
||||
bool "drop new incoming data when the buffer is full"
|
||||
config RT_SERIAL_BUF_STRATEGY_OVERWRITE
|
||||
bool "overwrite old data when the buffer is full"
|
||||
endchoice
|
||||
|
||||
config RT_SERIAL_USING_DMA
|
||||
bool "Enable serial DMA mode"
|
||||
default y
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2025 RT-Thread Development Team
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@@ -90,7 +90,10 @@ struct at_server
|
||||
char send_buffer[AT_SERVER_SEND_BUFF_LEN];
|
||||
char recv_buffer[AT_SERVER_RECV_BUFF_LEN];
|
||||
rt_size_t cur_recv_len;
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
rt_sem_t rx_notice;
|
||||
#endif
|
||||
|
||||
rt_thread_t parser;
|
||||
void (*parser_entry)(struct at_server *server);
|
||||
@@ -165,7 +168,11 @@ struct at_client
|
||||
rt_size_t recv_line_len;
|
||||
/* The maximum supported receive data length */
|
||||
rt_size_t recv_bufsz;
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
rt_sem_t rx_notice;
|
||||
#endif
|
||||
|
||||
rt_mutex_t lock;
|
||||
|
||||
at_response_t resp;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
* 2021-03-17 Meco Man fix a buf of leaking memory
|
||||
* 2021-07-14 Sszl fix a buf of leaking memory
|
||||
* 2025-01-02 dongly support SERIAL_V2
|
||||
* 2025-04-18 RyanCw support New SERIAL_V2
|
||||
*/
|
||||
|
||||
#include <at.h>
|
||||
@@ -225,7 +226,8 @@ int at_resp_parse_line_args(at_response_t resp, rt_size_t resp_line, const char
|
||||
RT_ASSERT(resp);
|
||||
RT_ASSERT(resp_expr);
|
||||
|
||||
if ((resp_line_buf = at_resp_get_line(resp, resp_line)) == RT_NULL)
|
||||
resp_line_buf = at_resp_get_line(resp, resp_line);
|
||||
if (resp_line_buf == RT_NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -259,7 +261,8 @@ int at_resp_parse_line_args_by_kw(at_response_t resp, const char *keyword, const
|
||||
RT_ASSERT(resp);
|
||||
RT_ASSERT(resp_expr);
|
||||
|
||||
if ((resp_line_buf = at_resp_get_line_by_kw(resp, keyword)) == RT_NULL)
|
||||
resp_line_buf = at_resp_get_line_by_kw(resp, keyword);
|
||||
if (resp_line_buf == RT_NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -541,6 +544,7 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
while (rt_device_read(client->device, 0, ch, 1) == 0)
|
||||
{
|
||||
result = rt_sem_take(client->rx_notice, rt_tick_from_millisecond(timeout));
|
||||
@@ -551,8 +555,19 @@ static rt_err_t at_client_getchar(at_client_t client, char *ch, rt_int32_t timeo
|
||||
|
||||
rt_sem_control(client->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
|
||||
}
|
||||
#else
|
||||
rt_int32_t rx_timeout = rt_tick_from_millisecond(timeout);
|
||||
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
|
||||
result = rt_device_read(client->device, 0, ch, 1);
|
||||
if(result <= 0)
|
||||
{
|
||||
result = -RT_ERROR;
|
||||
}
|
||||
rx_timeout = RT_WAITING_FOREVER;
|
||||
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void*)&rx_timeout);
|
||||
#endif
|
||||
|
||||
return RT_EOK;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -570,7 +585,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 len = 0;
|
||||
rt_size_t read_idx = 0;
|
||||
|
||||
RT_ASSERT(buf);
|
||||
|
||||
@@ -580,16 +595,17 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
while (size)
|
||||
{
|
||||
rt_size_t read_len;
|
||||
|
||||
rt_sem_control(client->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
|
||||
|
||||
read_len = rt_device_read(client->device, 0, buf + len, size);
|
||||
read_len = rt_device_read(client->device, 0, buf + read_idx, size);
|
||||
if (read_len > 0)
|
||||
{
|
||||
len += read_len;
|
||||
read_idx += read_len;
|
||||
size -= read_len;
|
||||
}
|
||||
else
|
||||
@@ -598,12 +614,19 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size, rt_i
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef AT_PRINT_RAW_CMD
|
||||
at_print_raw_cmd("urc_recv", buf, len);
|
||||
#else
|
||||
rt_int32_t rx_timeout = rt_tick_from_millisecond(timeout);
|
||||
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
|
||||
read_idx = rt_device_read(client->device, 0, buf, size);
|
||||
rx_timeout = RT_WAITING_FOREVER;
|
||||
rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void*)&rx_timeout);
|
||||
#endif
|
||||
|
||||
return len;
|
||||
#ifdef AT_PRINT_RAW_CMD
|
||||
at_print_raw_cmd("urc_recv", buf, read_idx);
|
||||
#endif
|
||||
|
||||
return read_idx;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -780,7 +803,8 @@ static int at_recv_readline(at_client_t client)
|
||||
}
|
||||
|
||||
/* is newline or URC data */
|
||||
if ((client->urc = get_urc_obj(client)) != RT_NULL || (ch == '\n' && last_ch == '\r')
|
||||
client->urc = get_urc_obj(client);
|
||||
if (client->urc != RT_NULL || (ch == '\n' && last_ch == '\r')
|
||||
|| (client->end_sign != 0 && ch == client->end_sign))
|
||||
{
|
||||
if (is_full)
|
||||
@@ -877,6 +901,7 @@ static void client_parser(at_client_t client)
|
||||
}
|
||||
}
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
static rt_err_t at_client_rx_ind(rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
int idx = 0;
|
||||
@@ -891,6 +916,7 @@ static rt_err_t at_client_rx_ind(rt_device_t dev, rt_size_t size)
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* initialize the client object parameters */
|
||||
static int at_client_para_init(at_client_t client)
|
||||
@@ -933,6 +959,7 @@ static int at_client_para_init(at_client_t client)
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
rt_snprintf(name, RT_NAME_MAX, "%s%d", AT_CLIENT_SEM_NAME, at_client_num);
|
||||
client->rx_notice = rt_sem_create(name, 0, RT_IPC_FLAG_FIFO);
|
||||
if (client->rx_notice == RT_NULL)
|
||||
@@ -941,6 +968,7 @@ static int at_client_para_init(at_client_t client)
|
||||
result = -RT_ENOMEM;
|
||||
goto __exit;
|
||||
}
|
||||
#endif
|
||||
|
||||
rt_snprintf(name, RT_NAME_MAX, "%s%d", AT_CLIENT_RESP_NAME, at_client_num);
|
||||
client->resp_notice = rt_sem_create(name, 0, RT_IPC_FLAG_FIFO);
|
||||
@@ -974,10 +1002,12 @@ __exit:
|
||||
rt_mutex_delete(client->lock);
|
||||
}
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
if (client->rx_notice)
|
||||
{
|
||||
rt_sem_delete(client->rx_notice);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (client->resp_notice)
|
||||
{
|
||||
@@ -1055,12 +1085,8 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bu
|
||||
if (client->device)
|
||||
{
|
||||
RT_ASSERT(client->device->type == RT_Device_Class_Char);
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
rt_device_set_rx_indicate(client->device, at_client_rx_ind);
|
||||
|
||||
#ifdef RT_USING_SERIAL_V2
|
||||
open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_NON_BLOCKING);
|
||||
#else
|
||||
/* using DMA mode first */
|
||||
open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_DMA_RX);
|
||||
/* using interrupt mode when DMA mode not supported */
|
||||
@@ -1068,8 +1094,11 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bu
|
||||
{
|
||||
open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
|
||||
}
|
||||
#endif /* RT_USING_SERIAL_V2 */
|
||||
RT_ASSERT(open_result == RT_EOK);
|
||||
#else
|
||||
open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
|
||||
RT_ASSERT(open_result == RT_EOK);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* 2018-03-30 chenyong first version
|
||||
* 2018-04-14 chenyong modify parse arguments
|
||||
* 2025-01-02 dongly support SERIAL_V2
|
||||
* 2025-04-18 RyanCw support New SERIAL_V2
|
||||
*/
|
||||
|
||||
#include <at.h>
|
||||
@@ -223,6 +224,7 @@ rt_size_t at_server_recv(at_server_t server, char *buf, rt_size_t size, rt_int32
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
while (1)
|
||||
{
|
||||
if (read_idx < size)
|
||||
@@ -242,6 +244,13 @@ rt_size_t at_server_recv(at_server_t server, char *buf, rt_size_t size, rt_int32
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
rt_int32_t rx_timout = rt_tick_from_millisecond(timeout);
|
||||
rt_device_control(server->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void*)&rx_timout);
|
||||
read_idx = rt_device_read(server->device, 0, buf, size);
|
||||
rx_timeout = RT_WAITING_FOREVER;
|
||||
rt_device_control(server->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void*)&rx_timeout);
|
||||
#endif
|
||||
|
||||
return read_idx;
|
||||
}
|
||||
@@ -411,15 +420,27 @@ static rt_err_t at_server_getchar(at_server_t server, char *ch, rt_int32_t timeo
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
while (rt_device_read(at_server_local->device, 0, ch, 1) == 0)
|
||||
{
|
||||
rt_sem_control(at_server_local->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
|
||||
result = rt_sem_take(at_server_local->rx_notice, rt_tick_from_millisecond(timeout));
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
rt_sem_control(at_server_local->rx_notice, RT_IPC_CMD_RESET, RT_NULL);
|
||||
}
|
||||
#else
|
||||
rt_int32_t rx_timout = rt_tick_from_millisecond(timeout);
|
||||
rt_device_control(server->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void*)&rx_timout);
|
||||
result = rt_device_read(server->device, 0, ch, 1);
|
||||
if(result <= 0)
|
||||
{
|
||||
result = -RT_ERROR;
|
||||
}
|
||||
rx_timeout = RT_WAITING_FOREVER;
|
||||
rt_device_control(server->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void*)&rx_timeout);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -497,6 +518,7 @@ static void server_parser(at_server_t server)
|
||||
}
|
||||
}
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
static rt_err_t at_rx_ind(rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
if (size > 0)
|
||||
@@ -506,6 +528,7 @@ static rt_err_t at_rx_ind(rt_device_t dev, rt_size_t size)
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
|
||||
#pragma section="RtAtCmdTab"
|
||||
@@ -551,6 +574,7 @@ int at_server_init(void)
|
||||
rt_memset(at_server_local->recv_buffer, 0x00, AT_SERVER_RECV_BUFF_LEN);
|
||||
at_server_local->cur_recv_len = 0;
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
at_server_local->rx_notice = rt_sem_create("at_svr", 0, RT_IPC_FLAG_FIFO);
|
||||
if (!at_server_local->rx_notice)
|
||||
{
|
||||
@@ -558,18 +582,15 @@ int at_server_init(void)
|
||||
result = -RT_ENOMEM;
|
||||
goto __exit;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Find and open command device */
|
||||
at_server_local->device = rt_device_find(AT_SERVER_DEVICE);
|
||||
if (at_server_local->device)
|
||||
{
|
||||
RT_ASSERT(at_server_local->device->type == RT_Device_Class_Char);
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
rt_device_set_rx_indicate(at_server_local->device, at_rx_ind);
|
||||
|
||||
#ifdef RT_USING_SERIAL_V2
|
||||
open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_NON_BLOCKING);
|
||||
#else
|
||||
/* using DMA mode first */
|
||||
open_result = rt_device_open(at_server_local->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_DMA_RX);
|
||||
/* using interrupt mode when DMA mode not supported */
|
||||
@@ -577,8 +598,11 @@ int at_server_init(void)
|
||||
{
|
||||
open_result = rt_device_open(at_server_local->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
|
||||
}
|
||||
#endif /* RT_USING_SERIAL_V2 */
|
||||
RT_ASSERT(open_result == RT_EOK);
|
||||
#else
|
||||
open_result = rt_device_open(at_server_local->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
|
||||
RT_ASSERT(open_result == RT_EOK);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -614,10 +638,14 @@ __exit:
|
||||
{
|
||||
if (at_server_local)
|
||||
{
|
||||
|
||||
#if (!defined(RT_USING_SERIAL_V2))
|
||||
if (at_server_local->rx_notice)
|
||||
{
|
||||
rt_sem_delete(at_server_local->rx_notice);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (at_server_local->device)
|
||||
{
|
||||
rt_device_close(at_server_local->device);
|
||||
|
||||
Reference in New Issue
Block a user