5.程序调用过程5.1注册过程INIT_DEVICE_EXPORT(esp8266_device_class_register);RTThread自动初始化组件注册at_device_class
=> class = (struct at_device_class *) rt_calloc(1, sizeof(struct at_device_class)); 分配内存
=> esp8266_socket_class_register(class);
=> class->socket_num = AT_DEVICE_ESP8266_SOCKETS_NUM; ESP8266最大支持的socket数量
=> class->socket_ops = &esp8266_socket_ops保存at_socket_ops到class
=> class->device_ops = &esp8266_device_ops; 保存at_device_ops到class
=> at_device_class_register(class, AT_DEVICE_CLASS_ESP8266); 注册到AT设备类链表
at_device_register()运行设备前注册设备
=> device->sockets = (struct at_socket *) rt_calloc(class->socket_num, sizeof(struct at_socket));根据支持的最大
socket数据分配响应的空间。
=> device->class = class;保存AT设备类首地址到at_device结构体中
=> device->user_data = user_data; 保存用户数据
=> rt_slist_append(&at_device_list, &(device->list)); 保存当前设备结构体到AT设备链表
=> class->device_ops->init(device); 初始化当前设备
=> at_client_init(esp8266->client_name, esp8266->recv_line_num);初始化AT基本组件
=> device->client = at_client_get(esp8266->client_name);保存AT基本组件信息到at_device中
=> at_obj_set_urc_table();设置URC回调函数 针对配置的URC
=> esp8266_socket_init(device);初始化esp8266 socket
=> at_obj_set_urc_table()也是设备URC回调函数,针对收发消息的URC
=> device->netdev = esp8266_netdev_add(esp8266->device_name); 将esp8266注册成网卡
=> netdev = (struct netdev *) rt_calloc(1, sizeof(struct netdev));分配内存
=> netdev->ops = &esp8266_netdev_ops;设备网卡操作函数
=> sal_at_netdev_set_pf_info(netdev);将AT协议栈操作函数适配到SAL抽象层
=> netdev_register(netdev, netdev_name, RT_NULL)注册网卡
=> esp8266_netdev_set_up(device->netdev);打开网卡
=> device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);根据名字获取at_device
=> esp8266_net_init(device);初始化at_device
=> esp8266_init_thread_entry(device);根据env设置的是否是线程初始化esp8266,当前不是线程初始化
=> AT+RST ATE0 等ESP基本功能初始化
=> netdev_low_level_set_status(netdev, RT_TRUE);设置网卡状态
|