From ccfde36b4d7dce674eb5bc99c406e583afd6fd90 Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 27 Jul 2018 18:29:20 +0800 Subject: [PATCH] [net][at] Using DMA mode first when device is supported. --- components/net/at/include/at.h | 2 +- components/net/at/src/at_client.c | 19 ++++++++++++++----- components/net/at/src/at_server.c | 18 ++++++++++++++---- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/components/net/at/include/at.h b/components/net/at/include/at.h index 2c866891d2..76e952944f 100644 --- a/components/net/at/include/at.h +++ b/components/net/at/include/at.h @@ -27,7 +27,7 @@ #include -#define AT_SW_VERSION "0.2.1" +#define AT_SW_VERSION "0.2.2" #define DBG_ENABLE #define DBG_SECTION_NAME "AT" diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c index f6145232b3..c2002d8094 100644 --- a/components/net/at/src/at_client.c +++ b/components/net/at/src/at_client.c @@ -354,11 +354,12 @@ rt_size_t at_client_send(const char *buf, rt_size_t size) static char at_client_getchar(void) { char ch; - at_client_t client = at_client_local; - rt_sem_take(client->rx_notice, RT_WAITING_FOREVER); - - rt_device_read(client->device, 0, &ch, 1); + if (rt_device_read(at_client_local->device, 0, &ch, 1) == 0) + { + rt_sem_take(at_client_local->rx_notice, RT_WAITING_FOREVER); + rt_device_read(at_client_local->device, 0, &ch, 1); + } return ch; } @@ -604,6 +605,7 @@ void at_set_urc_table(const struct at_urc *table, rt_size_t size) int at_client_init(void) { int result = RT_EOK; + rt_err_t open_result = RT_EOK; if (at_client_local) { @@ -651,7 +653,14 @@ int at_client_init(void) { RT_ASSERT(at_client_local->device->type == RT_Device_Class_Char); - rt_device_open(at_client_local->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX); + /* using DMA mode first */ + open_result = rt_device_open(at_client_local->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_DMA_RX); + /* using interrupt mode when DMA mode not supported */ + if (open_result == -RT_EIO) + { + open_result = rt_device_open(at_client_local->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX); + } + RT_ASSERT(open_result == RT_EOK); rt_device_set_rx_indicate(at_client_local->device, at_client_rx_ind); } diff --git a/components/net/at/src/at_server.c b/components/net/at/src/at_server.c index a2ff765ee8..639739d9c2 100644 --- a/components/net/at/src/at_server.c +++ b/components/net/at/src/at_server.c @@ -352,9 +352,11 @@ static char at_server_gerchar(void) { char ch; - rt_sem_take(at_server_local->rx_notice, RT_WAITING_FOREVER); - - rt_device_read(at_server_local->device, 0, &ch, 1); + if (rt_device_read(at_server_local->device, 0, &ch, 1) == 0) + { + rt_sem_take(at_server_local->rx_notice, RT_WAITING_FOREVER); + rt_device_read(at_server_local->device, 0, &ch, 1); + } return ch; } @@ -443,6 +445,7 @@ static rt_err_t at_rx_ind(rt_device_t dev, rt_size_t size) int at_server_init(void) { rt_err_t result = RT_EOK; + rt_err_t open_result = RT_EOK; if (at_server_local) { @@ -493,7 +496,14 @@ int at_server_init(void) { RT_ASSERT(at_server_local->device->type == RT_Device_Class_Char); - rt_device_open(at_server_local->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX); + /* 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 */ + if (open_result == -RT_EIO) + { + open_result = rt_device_open(at_server_local->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX); + } + RT_ASSERT(open_result == RT_EOK); rt_device_set_rx_indicate(at_server_local->device, at_rx_ind); }