【RT-Thread】AT组件源代码解析
【RT-Thread】AT组件源代码解析RTThread物联网操作系统 2022-03-21 18:33收录于话题##论坛精选#4个
AT组件的核心处理逻辑是将收到的 AT 模组的应答信息放到一个环形缓冲区中,然后从这个环形缓冲区中每次读一行数据("rn")进行处理,然后判断属于哪一类的消息,调用不同的函数。
本文以 EC200x 模组为例,详细分析了 AT 组件的实现过程和代码的调用逻辑,帮助在使用 AT 组件过程中遇到问题的开发者快速定位问题出现的位置。
1 、AT 组件
1.1 AT 组件调试信息级别设置
可以通过修改 env 中的如下内容来控制是否启用 AT 组件的 debug log 功能,开启后可以看到日志级别为 debug 的相关日志。使能该选项后将在 rtconfig.h 中生成 #define AT_DEBUG,AT 组件日志级别的控制是在 rt-thread/components/net/at/include/at_log.h 文件中实现的1RT-Thread Components
2-> Network
3 -> AT commands
4 -> [*] Enable debug log output/* 选中表示修改日志级别为 debug */
特别注意:打开上述功能后,ec200x 线程(在 packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c 文件中由 ec200x_netdev_check_link_status() 函数创建)会提示栈溢出,使用的栈空间约为 1598Bytes,建议将 ec200x_netdev_check_link_status() 函数中的 EC200X_LINK_THREAD_STACK_SIZE 宏更改为 1024 +1024 即 2048 个字节,以解决栈溢出的问题。1.2 AT 命令打印使能设置在调试时可以通过修改 env 中的如下内容来控制是否使能 AT 组件的收发 AT 指令的显示,开启后可以看到每次执行的 AT 指令以及返回的执行结果。1RT-Thread Components
2-> Network
3 -> AT commands
4 -> [*] Enable print RAW format AT command communication data /* 选中表示打印执行的AT指令 */
上述选项选中后,在执行测试时,打印的 AT 指令示例如下 1 recvline: 0000-0020: 41 54 0D 0D 0A AT...
2 recvline: 0000-0020: 4F 4B 0D 0A OK..
3 sendline: 0000-0020: 41 54 45 30 ATE0
4 recvline: 0000-0020: 41 54 45 30 0D 0D 0A ATE0...
5 recvline: 0000-0020: 4F 4B 0D 0A OK..
6 sendline: 0000-0020: 41 54 2B 49 50 52 3F AT+IPR?
701-01 00:40:19 D/at.clnt: execute command (AT+IPR?) timeout (300 ticks)!
8 recvline: 0000-0020: 0D 0A ..
9 recvline: 0000-0020: 2B 49 50 52 3A 20 31 3135 32 30 30 0D 0A +IPR: 115200..
10 recvline: 0000-0020: 0D 0A ..
11 recvline: 0000-0020: 4F 4B 0D 0A OK..
12 recvline: 0000-0020: 0D 0A ..
13 recvline: 0000-0020: 52 44 59 0D 0A RDY..
1401-01 00:40:22 I/at.dev.ec200x: ec200x device initialize retry...
15 sendline: 0000-0020: 41 54 45 30 ATE0
1601-01 00:40:24 D/at.clnt: execute command (ATE0) timeout (300 ticks)!
17 recvline: 0000-0020: 0D 0A ..
18 recvline: 0000-0020: 4F 4B 0D 0A OK..
19 recvline: 0000-0020: 0D 0A ..
20 recvline: 0000-0020: 4F 4B 0D 0A OK..
211.3 GPRS 网络注册状态检查AT组件中会自动创建一个 GPRS 网络注册状态检查的线程,使用 "AT+CGREG?" 指令进行 GPRS 网络注册状态的检查,并根据指令返回的结果修改网卡设备的标志位,该指令返回结果中的 <stat> 等于 1 或者 5,表示模块已在 UMTS/LTE 网络注册上 PS 业务。
GPRS 网络注册状态检查线程的名字是模拟网卡的名字,在本例中为 "ec200x",线程的入口函数是 ec200x_check_link_status_entry(packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c),该线程没间隔 60s 发送一条 AT 指令进行 GPRS 网络注册状态的检查,并根据返回的结果在函数 netdev_low_level_set_link_status 中修改 netdev->flags。各种情况的执行结果分析如下所示
特别注意:GPRS 网络注册状态检查线程会检查模组的 power_status,power_status 在 ec200x_init() 函数中默认初始化为 RT_FALSE,然后在名为 "ec200x_net" 的线程的 ec200x_init_thread_entry() 线程入口函数中调用 ec200x_power_on() 函数来修改 power_status 的值。ec200x_power_on() 函数中 power_status 的值修改为 RT_TRUE 依赖于 power_pin 引脚的定义,因此在 env 中必须定义 power_pin 的编号,默认为 -1,定义规则在文件 drivers/drv_gpio.c 中。另外还需要注意的是在代码中 power_pin 为低电平表示模组处于上电状态,power_pin 为高电平表示模组处于断电状态。power_pin 编号的定义在禁用网卡(netdev_set_down)与启用网卡(netdev_set_up)的实现中也至关重要,网卡的禁用与启用最终实际调用的函数为 ec200x_power_off() 和 ec200x_power_on(),因此必须定义power_pin 的编号,网卡禁用与启用的示例代码如下1/* "ec200x" 名字来源于设备注册时使用的名字,在文件 packages/at_device-v2.0.4/samples/at_sample_ec200x.c 中定义 */
2struct at_device * dev = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, "ec200x");/* 根据名字查找 AT 设备 */
3
4netdev_set_up(dev->netdev); /* 启用相应的网卡设备 */
5netdev_set_down(dev->netdev); /* 禁用相应的网卡设备 */
1.4 EC200x 是否能连接外网日志输出
rt-thread/components/net/sal_socket/src/sal_socket.c 中 check_netdev_internet_up_work() 函数会自动连接 "link.rt-thread.org" 的 8101 端口进行数据收发测试,从而判断是否可以连接外网。该文件中默认的打印级别为 DBG_INFO,为了方便看出是否可以连接外网,将 check_netdev_internet_up_work() 函数结尾的部分的测试结果打印由 LOG_D 修改为 LOG_I。该函数的执行的过程大致为在 ec200x 初始化线程 ec200x_init_thread_entry() 中将将外网检查任务提交到 sys_work 工作队列中,系统工作队列处理线程 _workqueue_thread_entry() 会不断的检测是否有需要运行的任务,如果有则执行相应的任务,即执行外网连接检查任务。外网连接检查任务提交到工作队列的执行过程如下 1ec200x_init_thread_entry /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
2 |-> ec200x_power_on /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
3 |-> at_obj_exec_cmd() /* 发送各种AT指令初始化EC200x rt-thread/components/net/at/src/at_client.c */
4 |-> ec200x_netdev_set_info /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
5 |-> at_device_get_by_name /* packages/at_device-v2.0.4/src/at_device.c */
6 |-> netdev_low_level_set_status /* rt-thread/components/net/netdev/src/netdev.c */
7 |-> netdev->flags |= NETDEV_FLAG_LINK_UP; /* 网络设备的状态改为连接 */
8 |-> netdev_low_level_set_link_status /* rt-thread/components/net/netdev/src/netdev.c */
9 |-> netdev_low_level_set_dhcp_status /* rt-thread/components/net/netdev/src/netdev.c */
10 |-> netdev_low_level_set_ipaddr /* 设置本地的IP地址 rt-thread/components/net/netdev/src/netdev.c */
11 |-> sal_check_netdev_internet_up /* rt-thread/components/net/sal_socket/src/sal_socket.c */
12 |-> rt_delayed_work_init(net_work, check_netdev_internet_up_work) /* 初始化外网连接检查任务 rt-thread/components/drivers/src/workqueue.c */
13 |-> (&work->work)->work_func = check_netdev_internet_up_work
14 |-> rt_work_submit(&(net_work->work), RT_TICK_PER_SECOND); /* rt-thread/components/drivers/src/workqueue.c */
15 |-> rt_workqueue_submit_work(sys_workq, work, time) /* 将任务提交到系统工作队列里面 rt-thread/components/drivers/src/workqueue.c */
16 |-> netdev_low_level_set_dns_server /* 设置DNS服务器 rt-thread/components/net/netdev/src/netdev.c */
17 |-> ec200x_netdev_check_link_status /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
18 |-> rt_thread_create(ec200x_check_link_status_entry) /* 线程名字为"ec200x",创建 GPRS 网络注册状态检查线程 packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
19 |-> rt_thread_startup(ec200x_check_link_status_entry) /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
20
21/* GPRS 网络注册状态检查线程 */
22ec200x_check_link_status_entry /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
23 |-> ec200x_check_link_status /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
24 |-> at_obj_exec_cmd("AT+CGREG?") /* 发送AT指令检查网络状态 */
25 |-> netdev_low_level_set_link_status /* rt-thread/components/net/netdev/src/netdev.c */
系统工作队列初始化和任务执行过程如下 1rt_work_sys_workqueue_init /* rt-thread/components/drivers/src/workqueue.c */
2 |-> rt_workqueue_create("sys_work") /* 创建系统工作队列 rt-thread/components/drivers/src/workqueue.c */
3 |-> rt_thread_create(_workqueue_thread_entry) /* 线程名字为"sys_work",创建队列线程 rt-thread/components/drivers/src/workqueue.c */
4
5_workqueue_thread_entry /* 系统工作队列处理线程 rt-thread/components/drivers/src/workqueue.c */
6 |-> if(rt_list_isempty)
7 |-> rt_thread_suspend(rt_thread_self()); /* 挂起自身 */
8 |-> rt_schedule(); /* 任务列表为空,挂起自身,切换线程 */
9 |-> rt_hw_interrupt_disable /* 任务列表不为空,依次往下执行,关闭中断 */
10 |-> rt_list_entry /* 找到要处理的任务节点 */
11 |-> rt_list_remove /* 将找到的任务节点从任务列表中移除 */
12 |-> rt_hw_interrupt_enable /* 使能中断 */
13 |-> work->work_func(work, work->work_data); /* 执行任务 */
外网连接检查任务的执行过程如下1check_netdev_internet_up_work /* 外网连接检查任务 rt-thread/components/net/sal_socket/src/sal_socket.c */
2 |-> 与 "link.rt-thread.org" 的 8101 端口建立连接,进行收发数据测试
3 |-> 打印测试结果
4 |-> 收发测试成功LOG_I("Set network interface device(%s) internet status up.", netdev->name);
5 |-> netdev->flags |= NETDEV_FLAG_INTERNET_UP;
6 |-> 收发测试失败LOG_I("Set network interface device(%s) internet status down.", netdev->name);
7 |-> netdev->flags &= ~NETDEV_FLAG_INTERNET_UP;1.5 AT 设备注册过程 1at_device_register /* packages/at_device-v2.0.4/samples/at_sample_ec200x.c */
2 |-> class = at_device_class_get(class_id) /* packages/at_device-v2.0.4/src/at_device.c */
3 |-> class->device_ops->init(device) /* packages/at_device-v2.0.4/src/at_device.c */
4 |-> ec200x_init /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
5 |-> ec200x->power_status = RT_FALSE; /* default power is off.packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
6 |-> ec200x->sleep_status = RT_FALSE; /* default sleep is disabled.packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
7 |-> at_client_init /* components/net/at/src/at_client.c */
8 |-> at_client_para_init /* components/net/at/src/at_client.c */
9 |-> rt_thread_create(client_parser) /* 线程名字为"at_clnt0",创建AT解析线程 components/net/at/src/at_client.c */
10 |-> client_parser /* AT解析线程的具体实现 components/net/at/src/at_client.c */
11 |-> rt_device_find /* 寻找串口设备 rt-thread/src/device.c */
12 |-> rt_device_open /* 打开串口设备 rt-thread/src/device.c */
13 |-> rt_thread_startup(client->parser) /* rt-thread/src/thread.c */
14 |-> ec200x_socket_init /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
15 |-> ec200x_netdev_add("ec200x") /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
16 |-> netdev_get_by_name("ec200x") /* rt-thread/components/net/netdev/src/netdev.c */
17 |-> netdev->ops = &ec200x_netdev_ops; /* 网络设备操作集 packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
18 |-> sal_at_netdev_set_pf_info /* rt-thread/components/net/sal_socket/impl/af_inet_at.c */
19 |-> netdev_register /* rt-thread/components/net/netdev/src/netdev.c */
20 |-> netdev->status_callback = RT_NULL; /* rt-thread/components/net/netdev/src/netdev.c */
21 |-> netdev->addr_callback = RT_NULL; /* rt-thread/components/net/netdev/src/netdev.c */
22 |-> ec200x->power_pin /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
23 |-> ec200x->power_status_pin /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
24 |-> ec200x->wakeup_pin /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
25 |-> ec200x_netdev_set_up /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
26 |-> at_device_get_by_name /* packages/at_device-v2.0.4/src/at_device.c */
27 |-> ec200x_net_init /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
28 |-> rt_thread_create(ec200x_init_thread_entry) /* 线程名字为"ec200x_net",执行各种AT指令初始化网络 packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
29 |-> rt_thread_startup(ec200x_init_thread_entry) /* 启动网络初始化线程 packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
30 |-> netdev_low_level_set_status /* rt-thread/components/net/netdev/src/netdev.c */
1.6 AT 设备类注册过程1ec200x_device_class_register /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
2 |-> ec200x_socket_class_register /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
3 |-> class->socket_num = AT_DEVICE_EC200X_SOCKETS_NUM; /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
4 |-> class->socket_ops = &ec200x_socket_ops; /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
5 |-> class->device_ops = &ec200x_device_ops; /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
6 |-> at_device_class_register
7/* packages/at_device-v2.0.4/src/at_device.c */
1.7 网卡的启用与禁用1.7.1 启用网卡的执行过程 1/* 启用网卡 */
2netdev_set_up(netdev) /* components/net/netdev/src/netdev.c */
3 |-> netdev->ops->set_up(netdev) /* netdev->ops = &ec200x_netdev_ops; packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
4 |-> ec200x_netdev_set_up------------------------------| /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
5 |-> ec200x_net_init | /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
6 |-> ec200x_init_thread_entry | /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
7 |
8/* module init */ |
9ec200x_init | /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
10 |-> at_client_init | /* components/net/at/src/at_client.c */
11 |-> ec200x_socket_init | /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
12 |-> ec200x_netdev_add | /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
13 |-> netdev_register | /* rt-thread/components/net/netdev/src/netdev.c */
14 |-> ec200x_netdev_set_up----------------------------------| /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
15 |-> ec200x_net_init /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
16 |-> ec200x_init_thread_entry /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
1.7.2 禁用网卡的执行过程 1/* 禁用网卡 */
2netdev_set_down(netdev) /* components/net/netdev/src/netdev.c */
3 |-> netdev->ops->set_down(netdev); /* components/net/netdev/src/netdev.c */
4 |-> ec200x_netdev_set_down----------------------------| /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
5 |-> ec200x_power_off | /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
6 |-> netdev_low_level_set_status(netdev, RT_FALSE) | /* rt-thread/components/net/netdev/src/netdev.c */
7 |-> netdev->flags &= ~NETDEV_FLAG_UP | /* rt-thread/components/net/netdev/src/netdev.c */
8 |-> netdev_auto_change_default | /* rt-thread/components/net/netdev/src/netdev.c */
9 |
10/* module deinit */ |
11ec200x_deinit | /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
12 |-> ec200x_netdev_set_down--------------------------------| /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
13 |-> ec200x_power_off /* packages/at_device-v2.0.4/class/ec200x/at_device_ec200x.c */
1.8 socket 编程源码分析1.8.1 socket 执行过程 1#define socket(domain, type, protocol)sal_socket(domain, type, protocol) /* rt-thread/components/net/sal_socket/include/socket/sys_socket/sys/socket.h */
2 |-> sal_socket /* rt-thread/components/net/sal_socket/src/sal_socket.c */
3 |-> socket_new /* rt-thread/components/net/sal_socket/src/sal_socket.c */
4 |-> socket_alloc /* rt-thread/components/net/sal_socket/src/sal_socket.c */
5 |-> sock = st->sockets; /* rt-thread/components/net/sal_socket/src/sal_socket.c */
6 |-> sock->socket = idx + SAL_SOCKET_OFFSET; /* rt-thread/components/net/sal_socket/src/sal_socket.c */
7 |-> sock->magic = SAL_SOCKET_MAGIC; /* rt-thread/components/net/sal_socket/src/sal_socket.c */
8 |-> sock->netdev = RT_NULL; /* rt-thread/components/net/sal_socket/src/sal_socket.c */
9 |-> sock->user_data = RT_NULL; /* rt-thread/components/net/sal_socket/src/sal_socket.c */
10 |-> sal_get_socket /* rt-thread/components/net/sal_socket/src/sal_socket.c */
11 |-> socket_init /* rt-thread/components/net/sal_socket/src/sal_socket.c */
12 |-> sock->netdev = netdev; /* rt-thread/components/net/sal_socket/src/sal_socket.c */
13 |-> SAL_NETDEV_SOCKETOPS_VALID /* rt-thread/components/net/sal_socket/src/sal_socket.c */
14 |-> pf->skt_ops->socket /* rt-thread/components/net/sal_socket/src/sal_socket.c */
15 |-> at_socket /* rt-thread/components/net/at/at_socket/at_socket.c */
16 |-> alloc_socket /* rt-thread/components/net/at/at_socket/at_socket.c */
17 |-> sock->type = socket_type; /* rt-thread/components/net/at/at_socket/at_socket.c */
18 |-> sock->state = AT_SOCKET_OPEN; /* rt-thread/components/net/at/at_socket/at_socket.c */
19 |-> sock->ops->at_set_event_cb(AT_SOCKET_EVT_RECV, at_recv_notice_cb); /* 设置接收回调函数 rt-thread/components/net/at/at_socket/at_socket.c */
20 |-> ec200x_socket_set_event_cb /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
21 |-> at_evt_cb_set = cb; /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
22 |-> sock->ops->at_set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb); /* 设置关闭套接字回调函数 rt-thread/components/net/at/at_socket/at_socket.c */
23 |-> ec200x_socket_set_event_cb /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
24 |-> at_evt_cb_set = cb; /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
1.8.2 connect 函数执行过程 1#define connect(s, name, namelen) sal_connect(s, name, namelen) /* rt-thread/components/net/sal_socket/include/socket/sys_socket/sys/socket.h */
2 |-> sal_connect /* rt-thread/components/net/sal_socket/src/sal_socket.c */
3 |-> SAL_SOCKET_OBJ_GET /* rt-thread/components/net/sal_socket/src/sal_socket.c */
4 |-> SAL_NETDEV_IS_UP /* rt-thread/components/net/sal_socket/src/sal_socket.c */
5 |-> SAL_NETDEV_SOCKETOPS_VALID /* rt-thread/components/net/sal_socket/src/sal_socket.c */
6 |-> pf->skt_ops->connect /* rt-thread/components/net/sal_socket/src/sal_socket.c */
7 |-> at_connect /* rt-thread/components/net/at/at_socket/at_socket.c */
8 |-> at_get_socket /* rt-thread/components/net/at/at_socket/at_socket.c */
9 |-> sock->ops->at_connect /* rt-thread/components/net/at/at_socket/at_socket.c */
10 |-> ec200x_socket_connect /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
1.8.3 send 函数执行过程 1#define send(s, dataptr, size, flags) sal_sendto(s, dataptr, size, flags, NULL, NULL) /* rt-thread/components/net/sal_socket/include/socket/sys_socket/sys/socket.h */
2#define sendto(s, dataptr, size, flags, to, tolen)sal_sendto(s, dataptr, size, flags, to, tolen)/* rt-thread/components/net/sal_socket/include/socket/sys_socket/sys/socket.h */
3 |-> sal_sendto /* rt-thread/components/net/sal_socket/src/sal_socket.c */
4 |-> SAL_SOCKET_OBJ_GET /* rt-thread/components/net/sal_socket/src/sal_socket.c */
5 |-> SAL_NETDEV_IS_UP /* rt-thread/components/net/sal_socket/src/sal_socket.c */
6 |-> SAL_NETDEV_SOCKETOPS_VALID /* rt-thread/components/net/sal_socket/src/sal_socket.c */
7 |-> pf->skt_ops->sendto /* rt-thread/components/net/sal_socket/src/sal_socket.c */
8 |-> at_sendto /* rt-thread/components/net/at/at_socket/at_socket.c */
9 |-> at_get_socket /* rt-thread/components/net/at/at_socket/at_socket.c */
10 |-> sock->ops->at_send /* rt-thread/components/net/at/at_socket/at_socket.c */
11 |-> ec200x_socket_send /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */1.8.4 recv 函数执行过程recv() 函数执行时,EC200x 接收的 URC 函数将数据放到 recvpkt_list 中,然后 recv() 函数从 recvpkt_list 中取出数据。 1#define recv(s, mem, len, flags) sal_recvfrom(s, mem, len, flags, NULL, NULL) /* rt-thread/components/net/sal_socket/include/socket/sys_socket/sys/socket.h */
2#define recvfrom(s, mem, len, flags, from, fromlen) sal_recvfrom(s, mem, len, flags, from, fromlen) /* rt-thread/components/net/sal_socket/include/socket/sys_socket/sys/socket.h */
3 |-> sal_recvfrom /* rt-thread/components/net/sal_socket/src/sal_socket.c */
4 |-> SAL_SOCKET_OBJ_GET /* rt-thread/components/net/sal_socket/src/sal_socket.c */
5 |-> SAL_NETDEV_IS_UP /* rt-thread/components/net/sal_socket/src/sal_socket.c */
6 |-> SAL_NETDEV_SOCKETOPS_VALID /* rt-thread/components/net/sal_socket/src/sal_socket.c */
7 |-> pf->skt_ops->recvfrom /* rt-thread/components/net/sal_socket/src/sal_socket.c */
8 |-> at_recvfrom /* rt-thread/components/net/at/at_socket/at_socket.c */
9 |-> at_get_socket /* rt-thread/components/net/at/at_socket/at_socket.c */
10 |-> at_recvpkt_get(&(sock->recvpkt_list)...) /* 从链表中获取数据 rt-thread/components/net/at/at_socket/at_socket.c */
11
12/* EC200x 接收的 URC 函数 */
13urc_recv_func /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
14 |-> recv_buf = (char *) rt_calloc(1, bfsz); /* 申请空间,供 at_recv_pkt 使用,挂载在 rlist 列表中 */
15 |-> at_client_obj_recv /* rt-thread/components/net/at/src/at_client.c */
16 |-> at_client_getchar /* rt-thread/components/net/at/src/at_client.c */
17 |-> at_evt_cb_set(socket, AT_SOCKET_EVT_RECV, recv_buf, bfsz); /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
18 |-> at_recv_notice_cb /* rt-thread/components/net/at/at_socket/at_socket.c */
19 |-> at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz); /* rt-thread/components/net/at/at_socket/at_socket.c */
20 |-> pkt->buff = (char *) ptr; /* 将buff指向之前申请到的空间 rt-thread/components/net/at/at_socket/at_socket.c */
21 |-> rt_slist_append /* 挂载到链表中 */
1.8.5 closesocket 函数执行过程
1#define closesocket(s)sal_closesocket(s) /* rt-thread/components/net/sal_socket/include/socket/sys_socket/sys/socket.h */
2 |-> sal_closesocket /* rt-thread/components/net/sal_socket/src/sal_socket.c */
3 |-> SAL_SOCKET_OBJ_GET /* rt-thread/components/net/sal_socket/src/sal_socket.c */
4 |-> SAL_NETDEV_SOCKETOPS_VALID /* rt-thread/components/net/sal_socket/src/sal_socket.c */
5 |-> pf->skt_ops->closesocket /* rt-thread/components/net/sal_socket/src/sal_socket.c */
6 |-> at_closesocket /* rt-thread/components/net/at/at_socket/at_socket.c */
7 |-> sock->ops->at_closesocket /* rt-thread/components/net/at/at_socket/at_socket.c */
8 |-> ec200x_socket_close /* packages/at_device-v2.0.4/class/ec200x/at_socket_ec200x.c */
9 |-> free_socket /* rt-thread/components/net/at/at_socket/at_socket.c */
10 |-> socket_delete /* rt-thread/components/net/sal_socket/src/sal_socket.c */
11 |-> sock = sal_get_socket(socket); /* rt-thread/components/net/sal_socket/src/sal_socket.c */
12 |-> sock->magic = 0; /* rt-thread/components/net/sal_socket/src/sal_socket.c */
13 |-> sock->netdev = RT_NULL; /* rt-thread/components/net/sal_socket/src/sal_socket.c */
14 |-> socket_free /* rt-thread/components/net/sal_socket/src/sal_socket.c */
15 |-> rt_free(sock); /* rt-thread/src/memheap.c */
16 |-> rt_memheap_free /* rt-thread/src/memheap.c */
页:
[1]