LWIP学习系列(二):STM32中ETH外设的配置与LWIP的结合使用_stm32 leip low_level_input()(2)

img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以戳这里获取

netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.

  • You can instead declare your own function an call etharp_output()
  • from it if you have to do some checks before sending (e.g. if link
  • is available…) */

#if LWIP_IPV4
#if LWIP_ARP || LWIP_ETHERNET
#if LWIP_ARP
netif->output = etharp_output;
#else
/* The user should write ist own code in low_level_output_arp_off function /
netif->output = low_level_output_arp_off;
#endif /
LWIP_ARP /
#endif /
LWIP_ARP || LWIP_ETHERNET /
#endif /
LWIP_IPV4 */

#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */

netif->linkoutput = low_level_output;

/* initialize the hardware */
low_level_init(netif);

return ERR_OK;
}


* 由**lwip官方**下载的示例代码



err_t
ethernetif_init(struct netif *netif)
{
struct ethernetif *ethernetif;

LWIP_ASSERT(“netif != NULL”, (netif != NULL));

ethernetif = mem_malloc(sizeof(struct ethernetif));
if (ethernetif == NULL) {
LWIP_DEBUGF(NETIF_DEBUG, (“ethernetif_init: out of memory\n”));
return ERR_MEM;
}

#if LWIP_NETIF_HOSTNAME
/* Initialize interface hostname /
netif->hostname = “lwip”;
#endif /
LWIP_NETIF_HOSTNAME */

/*

  • Initialize the snmp variables and counters inside the struct netif.
  • The last argument should be replaced with your link speed, in units
  • of bits per second.
    */
    MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, LINK_SPEED_OF_YOUR_NETIF_IN_BPS);

netif->state = ethernetif;
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.

  • You can instead declare your own function an call etharp_output()
  • from it if you have to do some checks before sending (e.g. if link
  • is available…) /
    #if LWIP_IPV4
    netif->output = etharp_output;
    #endif /
    LWIP_IPV4 /
    #if LWIP_IPV6
    netif->output_ip6 = ethip6_output;
    #endif /
    LWIP_IPV6 */
    netif->linkoutput = low_level_output;

ethernetif->ethaddr = (struct eth_addr *) & (netif->hwaddr[0]);

/* initialize the hardware */
low_level_init(netif);

return ERR_OK;
}


**小结:**由上面两种程序对比,可以看出大同小异。基本上都是对**netif 网卡结构体进行赋值**,然后**真正的初始化**交由**low\_level\_init**来进行。


#### (3)**
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值