LWIP底层执行流程

void MX_LWIP_Init(void)
{

IP_ADDRESS[0] = 192;
IP_ADDRESS[1] = 168;
IP_ADDRESS[2] = 1;
IP_ADDRESS[3] = 179;
NETMASK_ADDRESS[0] = 255;
NETMASK_ADDRESS[1] = 255;
NETMASK_ADDRESS[2] = 255;
NETMASK_ADDRESS[3] = 0;
GATEWAY_ADDRESS[0] = 192;
GATEWAY_ADDRESS[1] = 168;
GATEWAY_ADDRESS[2] = 1;
GATEWAY_ADDRESS[3] = 1;

/* Initilialize the LwIP stack with RTOS */
tcpip_init( NULL, NULL );

 /* IP addresses initialization without DHCP (IPv4) */

IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);

/* add the network interface (IPv4/IPv6) with RTOS */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
ethernetif_init初始化函数在 netif_add()内部会被调用。
既: if (init(netif) != ERR_OK) {
return NULL;
}

/* Registers the default network interface */
netif_set_default(&gnetif);

if (netif_is_link_up(&gnetif))
{
/* When the netif is fully configured this function must be called /
netif_set_up(&gnetif);
}
else
{
/
When the netif link is down this function must be called */
netif_set_down(&gnetif);
}

/* Set the link callback function, this function is called on change of link status*/
netif_set_link_callback(&gnetif, ethernetif_update_config);
ethernetif_update_config()在 下面创建的线程中被调用
既:
osThreadDef(LinkThr, ethernetif_set_link, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 2);
osThreadCreate (osThread(LinkThr), &link_arg);
ethernetif_set_link该线程每隔一段时间去读取PHY芯片的参数(轮询PHY芯片),并根据轮询结果及当前链路状态去调用函数ethernetif_update_config()。既就是netif_set_link_up(struct netif *netif)函数里的 NETIF_LINK_CALLBACK(netif)函数;

/* create a binary semaphore used for informing ethernetif of frame reception */
osSemaphoreDef(Netif_SEM);
Netif_LinkSemaphore = osSemaphoreCreate(osSemaphore(Netif_SEM) , 1 );

link_arg.netif = &gnetif;
link_arg.semaphore = Netif_LinkSemaphore;

// osQUE_link_state = xQueueCreate(0x5,sizeof(&link_arg.netif));

/* Create the Ethernet link handler thread */
osThreadDef(LinkThr, ethernetif_set_link, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 2);
osThreadCreate (osThread(LinkThr), &link_arg);

xTaskCreate (Task_Tcp_LinkMonitor,(const portCHAR *)“monitor”, 256,&link_arg,osPriorityHigh,0);

/* Start DHCP negotiation for a network interface (IPv4) */

#ifdef DHCP_ENABLE
if(gnetif.flags &NETIF_FLAG_LINK_UP)
{
dhcp_start(&gnetif);

}
#endif

/* USER CODE BEGIN 3 /
// if(gnetif.flags &NETIF_FLAG_LINK_UP)
// {
//
// xSemaphoreGive(link_arg.semaphore);
// }
/
USER CODE END 3 */
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值