?? net_phy.c
字號:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
*
* uC/TCP-IP is provided in source form for FREE evaluation, for educational
* use or peaceful research. If you plan on using uC/TCP-IP in a commercial
* product you need to contact Micrium to properly license its use in your
* product. We provide ALL the source code for your convenience and to help
* you experience uC/TCP-IP. The fact that the source code is provided does
* NOT mean that you can use it without paying a licensing fee.
*
* Network Interface Card (NIC) port files provided, as is, for FREE and do
* NOT require any additional licensing or licensing fee.
*
* Knowledge of the source code may NOT be used to develop a similar product.
*
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK PHYSICAL LAYER
*
* DM9161AE
*
* Filename : net_phy.c
* Version : V1.87
* Programmer(s) : EHS
*********************************************************************************************************
* Note(s) : (1) Supports DM9161AE '3.3V Dual-Speed Fast Ethernet Transceiver' as described in
*
* Corporation (INTEL; http://www.intel.com)
* (a) DM9161AE (DM9161AE; Revision 249414-002)
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <net.h>
#include <net_phy.h>
#include <net_phy_def.h>
/*
*********************************************************************************************************
* NetNIC_PhyInit()
*
* Description : Initialize phyter (ethernet link controller)
* This instance configures the Davicom DM9161AE PHY
*
* Argument(s) : none.
*
* Return(s) : 1 for OK, 0 for error
*
* Caller(s) : AT91SAM7X256_EMAC_Init
*
* Note(s) : Assumes the MDI port as already been enabled for the PHY.
* : This is performed in net_nic.c, AT91SAM7X256_EMAC_Init().
*********************************************************************************************************
*/
void NetNIC_PhyInit (NET_ERR *perr)
{
CPU_INT16U reg_val;
NET_ERR AutoNeg_Err;
reg_val = 0; /* Init reg_val & void it to prevent a compiler */
(void)reg_val; /* warning since its not referenced in MII Mode */
#ifndef RMII
reg_val = NetNIC_PhyRegRd(AT91C_PHY_ADDR, MII_BMCR, perr); /* Read the Basic Mode Control Register (twice) */
if (*perr != NET_PHY_ERR_NONE) {
return;
}
reg_val = NetNIC_PhyRegRd(AT91C_PHY_ADDR, MII_BMCR, perr); /* Read the Basic Mode Control Register (twice) */
if (*perr != NET_PHY_ERR_NONE) {
return;
}
reg_val &= ~BMCR_ISOLATE; /* Mask off 'Disconnect from MII bit (BMCR_ISOLATE) */
NetNIC_PhyRegWr(AT91C_PHY_ADDR, MII_BMCR, reg_val, perr); /* Put the PHY into MII mode */
if (*perr != NET_PHY_ERR_NONE) {
return;
}
#endif
NetNIC_PhyAutoNeg(&AutoNeg_Err); /* Perform auto-negotiation */
if (*perr == NET_PHY_ERR_NONE) { /* If there are no errors enabling PHY interrupts.. */
*perr = AutoNeg_Err; /* set the return error to that of AutoNegotiation */
} /* This is done because the AutoNegotiation Error */
} /* is not fatal and does not return upon discovery */
/* AutoNegotiation errors occur if the link is down */
/*
*********************************************************************************************************
* NetNIC_PhyAutoNeg()
*
* Description : Do link auto-negotiation
*
* Argument(s) : none.
*
* Return(s) : 1 = no error, 0 = error
*
* Caller(s) : NetNIC_PhyInit.
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetNIC_PhyAutoNeg (NET_ERR *perr)
{
CPU_INT16U i;
CPU_INT16U reg_val;
CPU_BOOLEAN link;
i = DM9161AE_INIT_AUTO_NEG_RETRIES; /* Set the # of retries before declaring a timeout */
link = NetNIC_PhyLinkState(perr); /* Get the current link state. 1=linked, 0=no link */
if (*perr != NET_PHY_ERR_NONE) {
link = DEF_OFF; /* If we could not obtain the link state, try again */
}
if (link == DEF_OFF) {
reg_val = NetNIC_PhyRegRd(AT91C_PHY_ADDR, MII_BMCR, perr); /* Get current control register value */
reg_val |= DEF_BIT_09; /* Set the auto-negotiation start bit */
NetNIC_PhyRegWr(AT91C_PHY_ADDR, MII_BMCR, reg_val, perr); /* Initiate auto-negotiation */
do { /* Do while auto-neg incomplete, or retries expired */
DM9161AE_DlyAutoNegAck(); /* Wait for a while auto-neg to proceed (net_bsp.c) */
reg_val = NetNIC_PhyRegRd(AT91C_PHY_ADDR, MII_BMSR, perr); /* Read the Basic Mode Status Register */
reg_val = NetNIC_PhyRegRd(AT91C_PHY_ADDR, MII_BMSR, perr); /* Read the Basic Mode Status Register */
i--;
} while (((reg_val & BMSR_LSTATUS) == 0) && (i > 0)); /* While link not established and retries remain */
}
if (i == 0) { /* If we are out of retries... */
*perr = NET_PHY_ERR_AUTONEG_TIMEOUT; /* Return a timeout error */
} else {
*perr = NET_PHY_ERR_NONE; /* Link up and retries remain */
}
}
/*
*********************************************************************************************************
* NetNIC_PhyAutoNegState()
*
* Description : Returns state of auto-negotiation
* This instance probe the Davicom DM9161AE '3.3V Dual-Speed Fast Ethernet Transceiver'
*
* Argument(s) : none.
*
* Return(s) : State of auto-negociation (DEF_OFF = not completed, DEF_ON = completed).
*
* Caller(s) : NetNIC_PhyInit.
*
* Note(s) : If any error is encountered while reading the PHY, this function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -