首先看一下注释(这个是靠谱的):
/** Whether the network interface is 'up'. This is
* a software flag used to control whether this network
* interface is enabled and processes traffic.
* It must be set by the startup code before this netif can be used
* (also for dhcp/autoip).
*/
#define NETIF_FLAG_UP 0x01U
/** If set, the netif has broadcast capability.
* Set by the netif driver in its init function. */
#define NETIF_FLAG_BROADCAST 0x02U
/** If set, the interface has an active link
* (set by the network interface driver).
* Either set by the netif driver in its init function (if the link
* is up at that time) or at a later point once the link comes up
* (if link detection is supported by the hardware). */
#define NETIF_FLAG_LINK_UP 0x04U
那么下面这两个注释是否正确呢?
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);
}
先不谈DHCP的问题。
先谈自动协商,DP83848的自动协商成功必须在有网线插上的情况下进行。
所以这个问题很复杂,很可能STM32前几年给出的模板程序才是靠谱的程序。
那么什么叫做link呢? 一直以为是网线是否插上叫做是否link,现在觉得是MAC和PHY如果匹配正确那么就LINK UP,如果不匹配那么就LINK DOWN。
就是说如果禁止自动协商,那么即便没有插入网线,那么也是LINK UP的。