📄 net_phy.c
字号:
* Description : Do link auto-negotiation
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetNIC_PhyInit.
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetNIC_PhyAutoNeg (void)
{
CPU_INT16U i;
CPU_BOOLEAN link;
i = LM3SNNNN_PHY_INIT_AUTO_NEG_RETRIES;
link = NetNIC_PhyAutoNegState();
while ((link != DEF_ON) && (i > 0)) {
NetBSP_DlyMs(250);
link = NetNIC_PhyAutoNegState();
i--;
}
}
/*
*********************************************************************************************************
* NetNIC_PhyAutoNegState()
*
* Description : Returns state of auto-negotiation
*
* Argument(s) : none.
*
* Return(s) : State of auto-negociation (DEF_OFF = not completed, DEF_ON = completed).
*
* Caller(s) : NetNIC_PhyInit.
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_BOOLEAN NetNIC_PhyAutoNegState (void)
{
NET_ERR err;
CPU_INT32U reg_val;
reg_val = NetNIC_PhyRegRd(0, PHY_MR01, &err);
if ((reg_val & PHY_MR01_ANEGC) == PHY_MR01_ANEGC) {
return (DEF_ON);
} else {
return (DEF_OFF);
}
}
/*
*********************************************************************************************************
* NetNIC_PhyLinkState()
*
* Description : Returns state of ethernet link. This instance probe the LM3Snnnn's internal PHY.
*
* Argument(s) : none.
*
* Return(s) : State of ethernet link (DEF_OFF = link down, DEF_ON = link up).
*
* Note(s) : If any error is encountered while reading the PHY, this function
* will return link state = DEF_OFF.
*********************************************************************************************************
*/
CPU_BOOLEAN NetNIC_PhyLinkState (void)
{
CPU_INT16U reg_val;
NET_ERR err;
reg_val = NetNIC_PhyRegRd(0, PHY_MR01, &err);
if (err == NET_PHY_ERR_NONE) {
if ((reg_val & PHY_MR01_LINK) != 0) {
return (DEF_ON);
} else {
return (DEF_OFF);
}
} else {
return (DEF_OFF);
}
}
/*
*********************************************************************************************************
* NetPHY_GetLinkSpeed()
*
* Description : Returns the speed of the current Ethernet link
*
* Argument(s) : none.
*
* Return(s) : 0 = No Link, 10 = 10mbps, 100 = 100mbps
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_INT32U NetNIC_PhyLinkSpeed (void)
{
CPU_INT16U reg_val;
NET_ERR err;
if (NetNIC_PhyLinkState() == DEF_OFF) {
return (NET_PHY_SPD_0);
} else {
reg_val = NetNIC_PhyRegRd(0, PHY_MR00, &err);
if (err == NET_PHY_ERR_NONE) {
if ((reg_val & PHY_MR00_SPEEDSL) != 0) {
return (NET_PHY_SPD_100);
} else {
return (NET_PHY_SPD_10);
}
} else {
return (NET_PHY_SPD_0);
}
}
}
/*
*********************************************************************************************************
* NetPHY_GetDuplex()
*
* Description : Returns the duplex mode of the current Ethernet link. This instance probe the
* LM3Snnnn's internal PHY.
*
* Argument(s) : none.
*
* Return(s) : 0 = Unknown (Auto-Neg in progress), 1 = Half Duplex, 2 = Full Duplex
*
* Note(s) : none.
*********************************************************************************************************
*/
CPU_INT32U NetNIC_PhyLinkDuplex (void)
{
CPU_INT16U reg_val;
NET_ERR err;
if (NetNIC_PhyLinkState() == DEF_OFF) {
return (NET_PHY_DUPLEX_UNKNOWN);
} else {
reg_val = NetNIC_PhyRegRd(0, PHY_MR00, &err);
if (err == NET_PHY_ERR_NONE) {
if ((reg_val & PHY_MR00_DUPLEX) != 0) {
return (NET_PHY_DUPLEX_FULL);
} else {
return (NET_PHY_DUPLEX_HALF);
}
} else {
return (NET_PHY_DUPLEX_UNKNOWN);
}
}
}
/*
*********************************************************************************************************
*********************************************************************************************************
* GLOBAL FUNCTIONS: PHY INTERRUPTS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NetNIC_ISR_Handler()
*
* Description : (1) Update NetNIC_ConnStatus according to link state
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
void NetNIC_PhyISR_Handler (void)
{
volatile CPU_INT16U reg_val;
NET_ERR err;
NetNIC_ConnStatus = NetNIC_PhyLinkState(); /* Set NetNIC_ConnStatus according to link state */
if (NetNIC_ConnStatus == DEF_ON) {
NetNIC_LinkUp();
} else {
NetNIC_LinkDown();
}
reg_val = NetNIC_PhyRegRd(0, PHY_MR17, &err); /* Clear interrupts */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -