/******************************************************************************* * Function Name : ENET_SetOperatingMode * Description : Sets the Operating mode * Input : ENET_OperatingMode:(see ENET_OperatingMode in 91x_enet.h) * Output : None * Return : None *******************************************************************************/ portBASE_TYPE ENET_SetOperatingMode( void ) { unsigned portLONG ulStatusReg, ulControlReg, ulLinkAbilityReg; /* Link status is latched, so read twice to get current value */ ulStatusReg = ENET_MIIReadReg(0, STE100P_STATUS_REG); ulStatusReg = ENET_MIIReadReg(0, STE100P_STATUS_REG); if( !( ulStatusReg & STE100P_STATUS_LINKED ) ) { /* No Link. */ return pdFAIL; } ulControlReg = ENET_MIIReadReg(0, STE100P_CONTROL_REG); if (ulControlReg & STE100P_AUTO_NEGOTIATE_ABILITY) { /* AutoNegotiation is enabled. */ if (!(ulStatusReg & STE100P_AUTO_NEGOTIATE_COMPLETE)) { /* Auto-negotiation in progress. */ return pdFAIL; } ulLinkAbilityReg = ENET_MIIReadReg(0, STE100P_LINK_ABILITY); if( ( ulLinkAbilityReg & STE100P_100FULL ) || ( ulLinkAbilityReg & STE100P_10FULL ) ) { ENET_MAC->MCR |=MAC_MCR_FDM; /* full duplex mode */ ENET_MAC->MCR &=~MAC_MCR_DRO; /* enable frame reception during transmission */ } else { ENET_MAC->MCR &=~MAC_MCR_FDM; /* half duplex mode */ ENET_MAC->MCR |=MAC_MCR_DRO; /* disable frame reception during transmission */ } } else { if( ulStatusReg & STE100P_CTRL_FULL ) { ENET_MAC->MCR |=MAC_MCR_FDM; /* full duplex mode */ ENET_MAC->MCR &=~MAC_MCR_DRO; /* enable frame reception during transmission */ } else { ENET_MAC->MCR &=~MAC_MCR_FDM; /* half duplex mode */ ENET_MAC->MCR |=MAC_MCR_DRO; /* disable frame reception during transmission */ } } return pdPASS; }
/******************************************************************************* * Function Name : ENET_SetOperatingMode * Description : Sets the Operating mode. * Input : ENET_OperatingMode: the operating mode of MAC. This parameter * can be any the following values: * - AUTO_NEGOTIATION * - FULLDUPLEX_100M * - HALFDUPLEX_100M * - FULLDUPLEX_10M * - HALFDUPLEX_10M * Output : None * Return : None *******************************************************************************/ void ENET_SetOperatingMode(u32 ENET_OperatingMode) { u32 regValue; if(ENET_OperatingMode == AUTO_NEGOTIATION) { /* The Link Status bit is a Latching High bit, so we need to read twice to get the real value */ ENET_MIIReadReg (PHY_ADDRESS, PHY_XSR); /* We wait for linked satus... */ while( !(ENET_MIIReadReg (PHY_ADDRESS, PHY_XSR) & PHY_Linked_Status) ); /* Enable Auto-Negotiation */ ENET_MIIWriteReg (PHY_ADDRESS, PHY_XCR, PHY_AutoNegotiation); /* Wait until the autonegotiation will be completed */ while( !(ENET_MIIReadReg (PHY_ADDRESS, PHY_XSR) & PHY_AutoNego_Complete) ); /* Read the result of the autonegotiation */ regValue = ENET_MIIReadReg (PHY_ADDRESS, PHY_XCIIS); /* Configure the MAC with the Duplex Mode fixed by the autonegotiation process */ if( regValue & PHY_Configured_Speed) { ENET_MAC->MCR |=ENET_MCR_FDM; /* Full Duplex Mode */ ENET_MAC->MCR &=~ENET_MCR_DRO; /* Enable frame reception during transmission */ } else { ENET_MAC->MCR &=~ENET_MCR_FDM; /* Half Duplex Mode */ ENET_MAC->MCR |=ENET_MCR_DRO; /* Disable frame reception during transmission */ } } else { if (ENET_OperatingMode==PHY_FULLDUPLEX_100M ||ENET_OperatingMode==PHY_FULLDUPLEX_10M ) { ENET_MAC->MCR |=ENET_MCR_FDM; /* Full Duplex Mode */ ENET_MAC->MCR &=~ENET_MCR_DRO; /* Enable Frame Reception During Transmission */ } else { ENET_MAC->MCR &=~ENET_MCR_FDM; /* Half Duplex Mode */ ENET_MAC->MCR |=ENET_MCR_DRO; /* Disable Frame Reception During Transmission */ } /* Set the operating mode in the PHY device */ ENET_MIIWriteReg(PHY_ADDRESS,PHY_XCR, ENET_OperatingMode); } }
/******************************************************************************* * Function Name : ENET_PHYReset * Description : PHY software reset. * Input : phyDev: specifies the PHY device address. * Output : None. * Return : None. *******************************************************************************/ void ENET_PHYReset(u8 phyDev) { /* Reset the PHY device */ ENET_MIIWriteReg(phyDev, PHY_XCR, PHY_Reset_Control); /* Wait until the reset will be completed */ while( ENET_MIIReadReg(phyDev, PHY_XCR) & PHY_Reset_Control); }
/******************************************************************************* * Function Name : ENET_PHYLoopBack * Description : Enables or disables the PHY loopBack mode. * Input : - phyDev: specifies the PHY device address. * - NewState: new state of the PHY peripheral. * Output : Non * Return : None *******************************************************************************/ void ENET_PHYLoopBack(u8 phyDev, FunctionalState NewState) { u32 regValue; /* Get the PHY configuration to update it */ regValue = ENET_MIIReadReg(phyDev, PHY_XCR); if (NewState == ENABLE) { /* Enable the loopback mode */ regValue |= PHY_Loopback; } else { /* Put the PHY in the normal mode */ regValue &= ~PHY_Loopback; } /* Update the PHY control register with the new configuration */ ENET_MIIWriteReg(phyDev, PHY_XCR, regValue); ENET_MIIReadReg(phyDev, PHY_XCR); }
/******************************************************************************* * Function Name : ENET_PHYGetITSrc * Description : Specifies the source of the PHY interrupt. * Input : phyDev: specifies the PHY device address. * Output : None * Return : PHY source interrupt. *******************************************************************************/ u32 ENET_PHYGetITSrc(u8 phyDev) { u32 regValue; /* Read the XCIIS register */ regValue = ENET_MIIReadReg(phyDev,PHY_XCIIS); /* Subtract the configuration part */ regValue &= ~PHY_ConfigurationMask; /* Return the interrupt status */ return (regValue); }
/******************************************************************************* * Function Name : ENET_PHYITConfig * Description : Enables or disables the specified PHY interrupt. * Input : - phyDev: specifies the PHY device address. * - PHY_IT: specifies the PHY interrupt source to be configured. * - NewState: new state of the specified PHY interrupt. * Output : None * Return : None *******************************************************************************/ void ENET_PHYITConfig(u8 phyDev, u32 PHY_IT, FunctionalState NewState) { u32 regValue; if( NewState == ENABLE ) { /* Enable the specified PHY_IT */ ENET_MIIWriteReg(phyDev,PHY_XIE, PHY_IT); } else { /* Get the XIE register valur */ regValue = ENET_MIIReadReg(phyDev,PHY_XIE); /* Disable, only, the specified PHY_IT */ regValue &= ~PHY_IT; ENET_MIIWriteReg(phyDev,PHY_XIE, regValue); } }
/******************************************************************************* * Function Name : ENET_PHYPowerdown * Description : Puts the PHY device in the power-down mode. * Input : - phyDev: specifies the PHY device address. * - NewState: new state of the PHY power mode. * Output : None * Return : None *******************************************************************************/ void ENET_PHYPowerdown(u8 phyDev, FunctionalState NewState) { u32 regValue; /* Get the PHY configuration to update it */ regValue = ENET_MIIReadReg(phyDev, PHY_XCR); if (NewState == ENABLE) { /* Put the PHY in the power-down mode */ regValue |= PHY_Powerdown; } else { /* Put the PHY in the normal power mode */ regValue &= ~PHY_Powerdown; } /* Update the PHY control register with the new configuration */ ENET_MIIWriteReg(phyDev, PHY_XCR, regValue); }
/******************************************************************************* * Function Name : ENET_PHYIsolate * Description : Isolates PHY from MII. * Input : - phyDev: specifies the PHY device address. * - NewState: new state of the link PHY/MII. * Output : None * Return : None *******************************************************************************/ void ENET_PHYIsolate(u8 phyDev, FunctionalState NewState) { u32 regValue; /* Get the PHY configuration to update it */ regValue = ENET_MIIReadReg(phyDev, PHY_XCR); if (NewState == ENABLE) { /* Isolate the PHY from the MII */ regValue |= PHY_Isolate; } else { /* Restablish the link MII/PHY */ regValue &= ~PHY_Isolate; } /* Update the PHY control register with the new configuration */ ENET_MIIWriteReg(phyDev, PHY_XCR, regValue); }