1#define ESP8266_SAMPLE_DEIVCE_NAME “esp0”
2static struct at_device_esp8266 esp0 =
3{
4 ESP8266_SAMPLE_DEIVCE_NAME,
5 ESP8266_SAMPLE_CLIENT_NAME,
6
7 ESP8266_SAMPLE_WIFI_SSID,
8 ESP8266_SAMPLE_WIFI_PASSWORD,
9 ESP8266_SAMPLE_RECV_BUFF_LEN,
10};
11
12struct at_device_esp8266 *esp8266 = &esp0;
13
14return at_device_register(&(esp8266-》device),
15 esp8266-》device_name,
16 esp8266-》client_name,
17 AT_DEVICE_CLASS_ESP8266,
18 (void *) esp8266);
从at_device_class_list列表通过客户端ID获取ESP8266设备类对象
创建并初始化AT device class对象
在at_device_list列表注册AT设备
调用ESP8266设备类对象的初始化驱动接口
1static int esp8266_init(struct at_device *device)
创建esp_net线程,链接无线网络后自动销毁
1static void esp8266_init_thread_entry(void *parameter)
注册ESP8266设备操作接口:
1static const struct netdev_ops esp8266_netdev_ops =
2{
3 esp8266_netdev_set_up,
4 esp8266_netdev_set_down,
5
6 esp8266_netdev_set_addr_info,
7 esp8266_netdev_set_dns_server,
8 esp8266_netdev_set_dhcp,
9
10#ifdef NETDEV_USING_PING
11 esp8266_netdev_ping,
12#endif
13#ifdef NETDEV_USING_NETSTAT
14 esp8266_netdev_netstat,
15#endif
16};
17netdev-》ops = &esp8266_netdev_ops
1static int esp8266_net_init(struct at_device *device)
2
注册urc_table
1static const struct at_urc urc_table[] =
2{
3 {“busy p”, “
”, urc_busy_p_func},
4 {“busy s”, “
”, urc_busy_s_func},
5 {“WIFI CONNECTED”, “
”, urc_func},
6 {“WIFI DISCONNECT”, “
”, urc_func},
7};
1static const struct at_urc urc_table[] =
2{
3 {“SEND OK”, “
”, urc_send_func},
4 {“SEND FAIL”, “
”, urc_send_func},
5 {“Recv”, “bytes
”, urc_send_bfsz_func},
6 {“”, “,CLOSED
”, urc_close_func},
7 {“+IPD”, “:”, urc_recv_func},
8};
4.2 lwip网络协议栈驱动移植
驱动架构图:
4.2.1 添加lwip协议栈软件包
在 RT-Thread Setting 文件中借助图形化配置工具打开软件 lwip 的组件,保存更新。
4.2.2 移植网络设备层和LAN8720驱动移植
移植网络设备层和LAN8720驱动: