大家好,我手头有一个LPC2368+DP83848的平台,要用这个板子实现RJ45网口的通信,现在编写DP83848遇到严重问题,RL—ARM里有比较完整的代码
原谅我贴了很多代码,如果您懒得看,请看我的简短描述
这份代码首先把LPC2368的mac控制器上电,然后配置各种寄存器,他的精髓是通过readPHY和writePHY两个函数来控制PHY,代码里一些如PCONP这样的都是定义的宏,代表了一个寄存器地址。现在的问题是这样的,当然,keil生成了arm芯片LPC2368的启动代码,然后执行下面的代码,但是当代码执行到红色部分的时候,问题来了,我用jlink竟然发现id1和id2里面什么都没有,可事实绝不应该是这样的,这两个变量时从PHY的物理寄存器里读出值,这里一定不是全0,有数据的。。。请高手指点一二,多谢指教!!!
void init_ethernet (void)
{
/* Initialize the EMAC ethernet controller. */
U32 regv,tout,id1,id2;
/* Power Up the EMAC controller. */
PCONP |= 0x40000000;
/* Enable P1 Ethernet Pins. */
if (MAC_MODULEID == OLD_EMAC_MODULE_ID)
{
/* For the first silicon rev.'-' ID P1.6 should be set. */
PINSEL2 = 0x50151105;
}
else
{
/* on rev. 'A' and later, P1.6 should NOT be set. */
PINSEL2 = 0x50150105;
}
/* Reset all EMAC internal modules. */
MAC_MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX |
MAC1_SIM_RES | MAC1_SOFT_RES;
MAC_COMMAND = CR_REG_RES | CR_TX_RES | CR_RX_RES;
/* A short delay after reset. */
for (tout = 100; tout; tout--);
/* Initialize MAC control registers. */
MAC_MAC1 = MAC1_PASS_ALL;
MAC_MAC2 = MAC2_CRC_EN | MAC2_PAD_EN;
MAC_MAXF = ETH_MAX_FLEN;
MAC_CLRT = CLRT_DEF;
MAC_IPGR = IPGR_DEF;
/* Enable Reduced MII interface. */
MAC_COMMAND = CR_RMII | CR_PASS_RUNT_FRM;
/* Reset Reduced MII Logic. */
MAC_SUPP = SUPP_RES_RMII;
for (tout = 100; tout; tout--);
MAC_SUPP = 0;
/* Put the DP83848C in reset mode */
write_PHY (PHY_REG_BMCR, 0x8000);
/* Wait for hardware reset to end. */
for (tout = 0; tout < 0x100000; tout++)
{
regv = read_PHY (PHY_REG_BMCR);
if (!(regv & 0x8800))
{
/* Reset complete, device not Power Down. */
break;
}
}
/* Check if this is a DP83848C PHY. */
id1 = read_PHY (PHY_REG_IDR1);
id2 = read_PHY (PHY_REG_IDR2); if (((id1 << 16) | (id2 & 0xFFF0)) == DP83848C_ID)
{
/* Configure the PHY device */
#if defined (_10MBIT_)
/* Connect at 10MBit */
write_PHY (PHY_REG_BMCR, PHY_FULLD_10M);
#elif defined (_100MBIT_)
/* Connect at 100MBit */
write_PHY (PHY_REG_BMCR, PHY_FULLD_100M);
#else
/* Use autonegotiation about the link speed. */
write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG);
/* Wait to complete Auto_Negotiation. */
for (tout = 0; tout < 0x100000; tout++)
{
regv = read_PHY (PHY_REG_BMSR);
if (regv & 0x0020)
{
/* Autonegotiation Complete. */
break;
}
}
#endif
}
/* Check the link status. */
for (tout = 0; tout < 0x10000; tout++)
{
regv = read_PHY (PHY_REG_STS);
if (regv & 0x0001)
{
/* Link is on. */
break;
}
}
/* Configure Full/Half Duplex mode. */
if (regv & 0x0004)
{
/* Full duplex is enabled. */
MAC_MAC2 |= MAC2_FULL_DUP;
MAC_COMMAND |= CR_FULL_DUP;