name[0] = IFNAME0;netif->name[1] = IFNAME1;/* We directly use etharp_output() here to save a function call.* You can instead declare your own f。LwIP 之二 网络接口 netif(netif.c、ethernetif( 五 )。" />

LwIP 之二 网络接口 netif(netif.c、ethernetif( 五 )

<= DP83848_STATUS_LINK_DOWN){netif_set_link_down(netif);netif_set_down(netif);}else{switch (PHYLinkState){case DP83848_STATUS_100MBITS_FULLDUPLEX:duplex = ETH_FULLDUPLEX_MODE;speed= ETH_SPEED_100M;break;case DP83848_STATUS_100MBITS_HALFDUPLEX:duplex = ETH_HALFDUPLEX_MODE;speed= ETH_SPEED_100M;break;case DP83848_STATUS_10MBITS_FULLDUPLEX:duplex = ETH_FULLDUPLEX_MODE;speed= ETH_SPEED_10M;break;case DP83848_STATUS_10MBITS_HALFDUPLEX:duplex = ETH_HALFDUPLEX_MODE;speed= ETH_SPEED_10M;break;default:duplex = ETH_FULLDUPLEX_MODE;speed= ETH_SPEED_100M;break;}/* Get MAC Config MAC */HAL_ETH_GetMACConfig(&heth, &MACConf);MACConf.DuplexMode = duplex;MACConf.Speed= speed;HAL_ETH_SetMACConfig(&heth, &MACConf);HAL_ETH_Start_IT(&heth);netif_set_up(netif);netif_set_link_up(netif);}}#endif /* LWIP_ARP || LWIP_ETHERNET */}#if !LWIP_ARP/*** This function has to be completed by user in case of ARP OFF.** @param netif the lwip network interface structure for this ethernetif* @return ERR_OK if ...*/static err_t low_level_output_arp_off(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr){err_t errval;errval = ERR_OK;return errval;}#endif /* LWIP_ARP *//*** Should be called at the beginning of the program to set up the* network interface. It calls the function low_level_init() to do the* actual setup of the hardware.** This function should be passed as a parameter to netif_add().** @param netif the lwip network interface structure for this ethernetif* @return ERR_OK if the loopif is initialized*ERR_MEM if private data couldn't be allocated*any other err_t on error*/err_t ethernetif_init(struct netif *netif){LWIP_ASSERT("netif != NULL", (netif != NULL));#if LWIP_NETIF_HOSTNAME/* Initialize interface hostname */netif->hostname = "lwip";#endif /* LWIP_NETIF_HOSTNAME */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#if LWIP_ARP || LWIP_ETHERNET#if LWIP_ARPnetif->output = etharp_output;#else/* The user should write its 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_IPV6netif->output_ip6 = ethip6_output;#endif /* LWIP_IPV6 */netif->linkoutput = low_level_output;/* initialize the hardware */low_level_init(netif);return ERR_OK;}/*** @briefThis function sets the netif link status.* @paramnetif: the network interface* @retval None*/void ethernetif_link_check(void *argument){ETH_MACConfigTypeDef MACConf = {0};int32_t PHYLinkState= 0;uint32_t linkchanged = 0U, speed = 0U, duplex = 0U;struct netif* netif = (struct netif*)argument;for (;;){PHYLinkState = DP83848_GetLinkState(&DP83848);if (netif_is_link_up(netif) && (PHYLinkState <= DP83848_STATUS_LINK_DOWN)){HAL_ETH_Stop_IT(&heth);netif_set_down(netif);netif_set_link_down(netif);}else if (!netif_is_link_up(netif) && (PHYLinkState > DP83848_STATUS_LINK_DOWN)){switch (PHYLinkState){case DP83848_STATUS_100MBITS_FULLDUPLEX:duplex= ETH_FULLDUPLEX_MODE;speed= ETH_SPEED_100M;linkchanged = 1;break;case DP83848_STATUS_100MBITS_HALFDUPLEX:duplex= ETH_HALFDUPLEX_MODE;speed= ETH_SPEED_100M;linkchanged = 1;break;case DP83848_STATUS_10MBITS_FULLDUPLEX:duplex= ETH_FULLDUPLEX_MODE;speed= ETH_SPEED_10M;linkchanged = 1;break;case DP83848_STATUS_10MBITS_HALFDUPLEX:duplex= ETH_HALFDUPLEX_MODE;speed= ETH_SPEED_10M;linkchanged = 1;break;default:break;}if (linkchanged){/* Get MAC Config MAC */HAL_ETH_GetMACConfig(&heth, &MACConf);MACConf.DuplexMode = duplex;MACConf.Speed= speed;HAL_ETH_SetMACConfig(&heth, &MACConf);HAL_ETH_Start_IT(&heth);netif_set_up(netif);netif_set_link_up(netif);}}/* Suspend thread for 200 ms */sys_msleep(200);}}#if LWIP_NETIF_LINK_CALLBACK/*** @briefLink callback function, this function is called on change of link status*to update low level driver configuration.* @paramnetif: The network interface* @retval None*/void ethernetif_link_config(struct netif *netif){__IO uint32_t tickstart = 0;uint32_t regvalue = http://www.kingceram.com/post/0;if (netif_is_link_up(netif)){}else{/* Stop MAC interface */HAL_ETH_Stop(&heth);}}#endif /* LWIP_NETIF_LINK_CALLBACK *//*** @}*//************************ (C) COPYRIGHT ZCShou ***********END OF FILE**********/