MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / at_client_init

Function at_client_init

components/net/at/src/at_client.c:989–1082  ·  view source on GitHub ↗

* AT client initialize. * * @param dev_name AT client device name * @param recv_bufsz the maximum number of receive buffer length * @param send_bufsz the maximum number of send command length * * @return 0 : initialize success * -1 : initialize failed * -5 : no memory */

Source from the content-addressed store, hash-verified

987 * -5 : no memory
988 */
989int at_client_init(const char *dev_name, rt_size_t recv_bufsz, rt_size_t send_bufsz)
990{
991 int result = RT_EOK;
992 rt_err_t open_result = RT_EOK;
993 at_client_t client = RT_NULL;
994
995 RT_ASSERT(dev_name);
996 RT_ASSERT(recv_bufsz > 0);
997 RT_ASSERT(send_bufsz > 0);
998
999 if (at_client_get(dev_name) != RT_NULL)
1000 {
1001 return result;
1002 }
1003
1004 client = rt_malloc(sizeof(struct at_client) + recv_bufsz + send_bufsz);
1005 if (client == RT_NULL)
1006 {
1007 result = -RT_ENOMEM;
1008 goto __exit;
1009 }
1010 rt_memset(client, 0, sizeof(struct at_client) + recv_bufsz + send_bufsz);
1011 client->status = AT_STATUS_UNINITIALIZED;
1012
1013 client->recv_bufsz = recv_bufsz;
1014 client->recv_line_buf = ((char *)client) + sizeof(struct at_client);
1015
1016 client->send_bufsz = send_bufsz;
1017 client->send_buf = ((char *)client) + sizeof(struct at_client) + client->recv_bufsz;
1018
1019 result = at_client_para_init(client);
1020 if (result != RT_EOK)
1021 {
1022 goto __exit;
1023 }
1024
1025 /* find and open command device */
1026 client->device = rt_device_find(dev_name);
1027 if (client->device)
1028 {
1029 RT_ASSERT(client->device->type == RT_Device_Class_Char);
1030#ifndef RT_USING_SERIAL_V2
1031 /* using DMA mode first */
1032 open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_DMA_RX);
1033 /* using interrupt mode when DMA mode not supported */
1034 if (open_result == -RT_EIO)
1035 {
1036 open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
1037 }
1038 RT_ASSERT(open_result == RT_EOK);
1039#else
1040 open_result = rt_device_open(client->device, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
1041 RT_ASSERT(open_result == RT_EOK);
1042 rt_int32_t rx_timeout = RT_WAITING_NO;
1043 rt_device_control(client->device, RT_SERIAL_CTRL_SET_RX_TIMEOUT, (void *)&rx_timeout);
1044#endif
1045 }
1046 else

Callers

nothing calls this directly

Calls 15

at_client_getFunction · 0.85
rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
at_client_para_initFunction · 0.85
rt_device_findFunction · 0.85
rt_device_openFunction · 0.85
rt_device_controlFunction · 0.85
rt_slist_initFunction · 0.85
rt_slist_appendFunction · 0.85
rt_thread_startupFunction · 0.85
rt_thread_deleteFunction · 0.85

Tested by

no test coverage detected