lpc1768开发板,周立功能例程中自带的PHY驱动是ksz8041,我买的路虎开发板是DP83848,我所做的工作是把周立功能完善的例程移植到我的便宜的路虎开发板上。总共有几个地方需要更改:
/ // probe phy address
// for(i=0;i<32;i++)
// {
// PHYID = Read_PHY(i , 2 );
// if(PHYID == 0x0022) {
// break;
// }
// }
//
// if(i >= 32) {
// while(1);
// }
//
// PHYID = i;
//
// Write_PHY(PHYID, 0, 0x9200 );
//
// do {
// OSTimeDly(OS_TICKS_PER_SEC);
// tempreg = Read_PHY(PHYID, 0x1f );
//
// if(tempreg&0x001c) {
// break;
// }
// } while(1);
//
// OSTimeDly(OS_TICKS_PER_SEC);
// tempreg = Read_PHY(PHYID, 0x1f );
// tempreg &= 0x001c;
//
// /* INPUT MAC ADDRESS */
// SetMacID(NetPort[num].My_Mac);
//
// if(tempreg == 0x0018)//100fdx
// {
// dulxp = 1;
// speed = 100;
// LPC_EMAC->MAC2 = 0x31; /* half duplex, CRC and PAD enabled. */
// LPC_EMAC->SUPP |= 0x0100; /* RMII Support Reg. speed is set to 100M */
// LPC_EMAC->Command |= 0x0640;
// /* back to back int-packet gap */
// LPC_EMAC->IPGT = 0x0015; /* IPG setting in half duplex mode */
// } else if(tempreg == 0x0008) { //100hdx
// dulxp = 0;
// speed = 100;
// LPC_EMAC->MAC2 = 0x30; /* full duplex, CRC and PAD enabled. */
// LPC_EMAC->SUPP |= 0x0100; /* RMII Support Reg. speed is set to 100M */
// LPC_EMAC->Command |= 0x0240;
// /* back to back int-packet gap */
// LPC_EMAC->IPGT = 0x0012; /* IPG setting in full duplex mode */
// } else if(tempreg == 0x0014) { //10fdx
// dulxp = 1;
// speed = 10;
// LPC_EMAC->MAC2 = 0x31; /* full duplex, CRC and PAD enabled. */
// LPC_EMAC->SUPP = 0; /* RMII Support Reg. speed is set to 10M */
// LPC_EMAC->Command |= 0x0640;
// /* back to back int-packet gap */
// LPC_EMAC->IPGT = 0x0015; /* IPG setting in full duplex mode */
// } else if(tempreg == 0x0004) { //10hdx
// dulxp = 0;
// speed = 10;
// LPC_EMAC->MAC2 = 0x30; /* half duplex, CRC and PAD enabled. */
// LPC_EMAC->SUPP = 0; /* RMII Support Reg. speed is set to 10M */
// LPC_EMAC->Command |= 0x0240;
// /* back to back int-packet gap */
// LPC_EMAC->IPGT = 0x0012; /* IPG setting in half duplex mode */
// }
周立功的这一部分程序,写的很一般,没有一点可读性,替换为
PHYID=DP83848C_DEF_ADR; //willow add 20110513
/* Put the DP83848C in reset mode */
Write_PHY (DP83848C_DEF_ADR,PHY_REG_BMCR, 0x8000);
/* Wait for hardware reset to end. */
for (tout = 0; tout < 0x100000; tout++)
{
regv = Read_PHY (DP83848C_DEF_ADR,PHY_REG_BMCR);
if (!(regv & 0x8000))
{
/* Reset complete */
break;
}
}
/* Check if this is a DP83848C PHY. */
id1 = Read_PHY (DP83848C_DEF_ADR,PHY_REG_IDR1);
id2 = Read_PHY (DP83848C_DEF_ADR,PHY_REG_IDR2);
if (((id1 << 16) | (id2 & 0xFFF0)) == DP83848C_ID)
{
/* Configure the PHY device */
/* Use autonegotiation about the link speed. */
Write_PHY (DP83848C_DEF_ADR,PHY_REG_BMCR, PHY_AUTO_NEG);
/* Wait to complete Auto_Negotiation. */
for (tout = 0; tout < 0x100000; tout++)
{
regv = Read_PHY (DP83848C_DEF_ADR,PHY_REG_BMSR);
if (regv & 0x0020)
{
/* Autonegotiation Complete. */
break;
}
}
}
/* Check the link status. */
for (tout = 0; tout < 0x10000; tout++)
{
regv = Read_PHY (DP83848C_DEF_ADR,PHY_REG_STS);
if (regv & 0x0001)
{
/* Link is on. */
break;
}
}
if((tempreg&0x0006)==0x0004)//100fdx
{
dulxp = 1;
speed = 100;
LPC_EMAC->MAC2 = 0x31; /* half duplex, CRC and PAD enabled. */
LPC_EMAC->SUPP |= 0x0100; /* RMII Support Reg. speed is set to 100M */
LPC_EMAC->Command |= 0x0640;
/* back to back int-packet gap */
LPC_EMAC->IPGT = 0x0015; /* IPG setting in half duplex mode */
} else if((tempreg&0x0006)==0x0000) { //100hdx
dulxp = 0;
speed = 100;
LPC_EMAC->MAC2 = 0x30; /* full duplex, CRC and PAD enabled. */
LPC_EMAC->SUPP |= 0x0100; /* RMII Support Reg. speed is set to 100M */
LPC_EMAC->Command |= 0x0240;
/* back to back int-packet gap */
LPC_EMAC->IPGT = 0x0012; /* IPG setting in full duplex mode */
} else if((tempreg&0x0006)==0x0006) { //10fdx
dulxp = 1;
speed = 10;
LPC_EMAC->MAC2 = 0x31; /* full duplex, CRC and PAD enabled. */
LPC_EMAC->SUPP = 0; /* RMII Support Reg. speed is set to 10M */
LPC_EMAC->Command |= 0x0640;
/* back to back int-packet gap */
LPC_EMAC->IPGT = 0x0015; /* IPG setting in full duplex mode */
} else if((tempreg&0x0006)==0x0002) { //10hdx
dulxp = 0;
speed = 10;
LPC_EMAC->MAC2 = 0x30; /* half duplex, CRC and PAD enabled. */
LPC_EMAC->SUPP = 0; /* RMII Support Reg. speed is set to 10M */
LPC_EMAC->Command |= 0x0240;
/* back to back int-packet gap */
LPC_EMAC->IPGT = 0x0012; /* IPG setting in half duplex mode */
}
这里面的几个DP83848的寄存器的定义,一定要加在你包含的头文件里面,不然编译器会报“xxxx没有定义”
上面把初始化部分改完了,周立功能例程,还有一个地方改,INT8U Rec_Packet() {}这个函数也调用了底层读写寄存器的值,来判断PHY是否工作。把这个改一下,程序就能正常工作了。呵呵
联系客服