diff options
| author | Bernard Xiong <[email protected]> | 2018-07-28 08:03:22 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-07-28 08:03:22 +0800 |
| commit | 46acbb8dc591e5e01da1299c5f1ac00f1ea334ed (patch) | |
| tree | dcd59f7c79e05d9f0299f2dbabe977273d299d35 /components | |
| parent | cfce8815fb5c962997828a06c17a7981c439b1e2 (diff) | |
| parent | ccfde36b4d7dce674eb5bc99c406e583afd6fd90 (diff) | |
Merge pull request #1669 from armink/at
[net][at] Using DMA mode first when device is supported.
Diffstat (limited to 'components')
| -rw-r--r-- | components/net/at/include/at.h | 2 | ||||
| -rw-r--r-- | components/net/at/src/at_client.c | 19 | ||||
| -rw-r--r-- | 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 <rtthread.h> -#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); } |
