X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=lib%2Fsrc%2Fdriver%2Fethernet%2Flpc17xx%2FEtherDev_LAN8720.c;fp=lib%2Fsrc%2Fdriver%2Fethernet%2Flpc17xx%2FEtherDev_LAN8720.c;h=2a3c756c69f4821aa264827a06488b896ac2ae4b;hb=7d0f33691b6f7267ed176c052384a2f7b2705f0a;hp=dce41ff7d986a48d02ea70fb1a6a33def7901e67;hpb=1cb5d7af17066451ac4f22902bf134cde939fec1;p=mimic%2FMiMicSDK.git diff --git a/lib/src/driver/ethernet/lpc17xx/EtherDev_LAN8720.c b/lib/src/driver/ethernet/lpc17xx/EtherDev_LAN8720.c index dce41ff..2a3c756 100644 --- a/lib/src/driver/ethernet/lpc17xx/EtherDev_LAN8720.c +++ b/lib/src/driver/ethernet/lpc17xx/EtherDev_LAN8720.c @@ -90,7 +90,7 @@ #define PHY_SPEED_FDUPLX 0x0010 /* Full Duplex */ #define PHY_SPEED_100 0x0008 /* 100Mbit */ -#define ETHDEV_PHY_DEF_ADR 0x0100 /* Default PHY device address */ + #ifndef configEMAC_INTERRUPT_PRIORITY #define configEMAC_INTERRUPT_PRIORITY 5 @@ -117,15 +117,8 @@ static void prvConfigurePHY( void ); * parameters. */ static long prvSetupLinkStatus( void ); -/* - * Send lValue to the lPhyReg within the PHY. - */ -static long prvWritePHY( long lPhyReg, long lValue ); -/* - * Read a value from ucPhyReg within the PHY. *plStatus will be set to - * pdFALSE if there is an error. - */ -static unsigned short prvReadPHY( unsigned int ucPhyReg, NyLPC_TBool* o_status); + + static NyLPC_TBool start(const struct NyLPC_TEthAddr* i_eth_addr,NyLPC_TiEthernetDevice_onEvent i_handler,void* i_param); @@ -166,8 +159,8 @@ NyLPC_TBool EthDev_LAN8720_getInterface( //Reset MCU Interface. and wait for reset. prvSetupEMACHardware(); //Check peripheral name - ulID1 = prvReadPHY( PHY_REG_IDR1, &ret ); - ulID2 = prvReadPHY( PHY_REG_IDR2, &ret ); + ulID1 = EthDev_LPC17xx_prvReadPHY( PHY_REG_IDR1, &ret ); + ulID2 = EthDev_LPC17xx_prvReadPHY( PHY_REG_IDR2, &ret ); if( ( (ulID1 << 16UL ) | ( ulID2 & 0xFFF0UL ) ) != LAN8720_ID) { return NyLPC_TBool_FALSE; @@ -313,14 +306,14 @@ static void prvSetupEMACHardware( void ) LPC_EMAC->SUPP = SUPP_SPEED; /* Put the PHY in reset mode */ - prvWritePHY( PHY_REG_BMCR, MCFG_RES_MII ); + EthDev_LPC17xx_prvWritePHY( PHY_REG_BMCR, MCFG_RES_MII ); NyLPC_cThread_sleep( emacSHORT_DELAY_MS * 5); /* Wait for hardware reset to end. */ for( x = 0; x < 100; x++ ) { NyLPC_cThread_sleep( emacSHORT_DELAY_MS * 5 ); - us = prvReadPHY( PHY_REG_BMCR, &lDummy ); + us = EthDev_LPC17xx_prvReadPHY( PHY_REG_BMCR, &lDummy ); if( !( us & MCFG_RES_MII ) ) { /* Reset complete */ @@ -328,70 +321,8 @@ static void prvSetupEMACHardware( void ) } } } -/*-----------------------------------------------------------*/ - - -/*-----------------------------------------------------------*/ - -static NyLPC_TBool prvWritePHY( long lPhyReg, long lValue ) -{ - const long lMaxTime = 10; - long x; - - LPC_EMAC->MCMD = 0; - LPC_EMAC->MADR = ETHDEV_PHY_DEF_ADR | lPhyReg; - LPC_EMAC->MWTD = lValue; - - for( x = 0; x < lMaxTime; x++ ) - { - if( ( LPC_EMAC->MIND & MIND_BUSY ) == 0 ) - { - /* Operation has finished. */ - break; - } - - NyLPC_cThread_sleep( emacSHORT_DELAY_MS); - } - - if( x < lMaxTime ) - { - return NyLPC_TBool_TRUE; - } - else - { - return NyLPC_TBool_FALSE; - } -} -/*-----------------------------------------------------------*/ - -static unsigned short prvReadPHY( unsigned int ucPhyReg, NyLPC_TBool *o_status) -{ - long x; - const long lMaxTime = 10; - LPC_EMAC->MCMD = 1; - LPC_EMAC->MADR = ETHDEV_PHY_DEF_ADR | ucPhyReg; - LPC_EMAC->MCMD = MCMD_READ; - for( x = 0; x < lMaxTime; x++ ) - { - /* Operation has finished. */ - if( ( LPC_EMAC->MIND & MIND_BUSY ) == 0 ) - { - break; - } - NyLPC_cThread_sleep( emacSHORT_DELAY_MS); - } - - LPC_EMAC->MCMD = 0; - - if( x >= lMaxTime ) - { - *o_status =NyLPC_TBool_FALSE; - } - - return( LPC_EMAC->MRDD ); -} /** * Private function depend on configulation. * デバイス依存部分 @@ -406,13 +337,13 @@ static void prvConfigurePHY( void ) long x; NyLPC_TBool lDummy; /* Auto negotiate the configuration. */ - if( prvWritePHY( PHY_REG_BMCR, PHY_AUTO_NEG ) ) + if( EthDev_LPC17xx_prvWritePHY( PHY_REG_BMCR, PHY_AUTO_NEG ) ) { NyLPC_cThread_sleep( emacSHORT_DELAY_MS * 5 ); for( x = 0; x < 10; x++ ) { - us = prvReadPHY( PHY_REG_PHY_CTRL, &lDummy ); + us = EthDev_LPC17xx_prvReadPHY( PHY_REG_PHY_CTRL, &lDummy ); if( us & PHY_AUTO_NEG_COMPLETE ) { break; @@ -431,7 +362,7 @@ static long prvSetupLinkStatus( void ) /* Wait with timeout for the link to be established. */ for( x = 0; x < 10; x++ ) { - usLinkStatus = prvReadPHY (PHY_REG_PHY_CTRL, &lReturn ); + usLinkStatus = EthDev_LPC17xx_prvReadPHY (PHY_REG_PHY_CTRL, &lReturn ); if( usLinkStatus & PHY_AUTO_NEG_COMPLETE ) { /* Link is established. */