Lwip协议栈的详细分析与移植.docVIP

  • 161
  • 0
  • 约 15页
  • 2015-09-06 发布于重庆
  • 举报
Lwip协议栈的详细分析与移植.doc

Lwip协议栈的分析与移植 主要解决两个问题:操作系统仿真层的移植。这个基于uCOS-II的代码太多了。1,设备驱动的移植.驱动的移植主要就是完成ethernetif.c的工作。作者已经给好了驱动的接口。struct netif { ? struct netif *next; ? struct ip_addr ip_addr; ? struct ip_addr netmask; ? struct ip_addr gw; ? err_t (* input)(struct pbuf *p, struct netif *inp); ? err_t (* output)(struct netif *netif, struct pbuf *p, ?????? struct ip_addr *ipaddr); ? err_t (* linkoutput)(struct netif *netif, struct pbuf *p); ? void *state; #if LWIP_DHCP ? struct dhcp *dhcp; #endif ? unsigned char hwaddr_len; ? unsigned char hwaddr[NETIF_MAX_HWADDR_LEN]; ? u16_t mtu; ? char name[2]; ? u8_t num; ? u8_t flags; }; 主要就是: ??? err_t (* input)(struct pbuf *p, struct netif *inp);??????? 这个是被驱动调用的,传递一个数据包给TCP/IP栈。??? err_t (* output)(struct netif *netif, struct pbuf *p,struct ip_addr *ipaddr); ??????? 这个是被IP模块调用的,向以太网上发送一个数据包,函数要先通过IP地址获得解决硬件地址,然后发包。??? err_t (* linkoutput)(struct netif *netif, struct pbuf *p); ??????? 这个是直接发送数据包的接口相应的作者在ethernetif.c里面给了几个函数框架,这个文件相当于一个硬件抽象层。static void low_level_init(struct netif *netif) ??? 网卡初始化函数static err_t low_level_output(struct netif *netif, struct pbuf *p) ??? 链路层发送函数,实现err_t (* linkoutput)接口。static struct pbuf *low_level_input(struct netif *netif) ??? 得到一整帧数据static err_t ethernetif_output(struct netif *netif, struct pbuf *p,struct ip_addr *ipaddr) ??? 实现发送线程,实现err_t (* output)接口。static void ethernetif_input(struct netif *netif) ??? 实现接收线程,识别数据包是ARP包还是IP包err_t ethernetif_init(struct netif *netif) ??? 初始化底层接口其实,写驱动的时候只要自己再建个ethernet.c,实际的网络硬件控制的文件然后提供几个函数比如:void EMACInit( void ) ??? 硬件的初始化void EMACPacketSend ( u8_t *buffer, u16_t length ) ??? 用来将buffer里面的包复制到网络设备的发送缓冲里面,发送。u16_t EMACPacketReceive ( u8_t *buffer, u16_t max_length? ) ??? 用来将网络设备的接收缓冲里面的包数据复制到buffer里面。u16_t EMACPacketLength ( u16_t max_length ) ??? 获得包长度??? 还有其他控制类函数。 最后,用ethernet.c里的函数完成ethernetif.c里的框架。这样脉络可能会清楚一点。struct netif *netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, void *state, err_t (* init)(struct netif *netif),

文档评论(0)

1亿VIP精品文档

相关文档