中级会员
- 积分
- 339
- 金钱
- 339
- 注册时间
- 2012-10-11
- 在线时间
- 134 小时
|
发表于 2022-9-2 09:56:13
|
显示全部楼层
本帖最后由 我乐意 于 2022-9-2 09:57 编辑
我在sdk里添加了ksz8081配置函数,目前能连接上电脑,但是ping不通,
static u32_t get_phy_speed_ksz8081(XEmacPs *xemacpsp, u32_t phy_addr) {
u16_t temp;
u16_t control;
u16_t status;
u16_t status_speed;
u32_t timeout_counter = 0;
u32_t temp_speed;
u32_t phyregtemp;
xil_printf("Start PHY autonegotiation \r\n");
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",IEEE_CONTROL_REG_OFFSET, control);
XEmacPs_PhyRead(xemacpsp, phy_addr, 0x17, &control);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",0x17, control);
XEmacPs_PhyWrite(xemacpsp,phy_addr, IEEE_PAGE_ADDRESS_REGISTER, 2);//RMII Override
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_PAGE_ADDRESS_REGISTER, &control);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",IEEE_PAGE_ADDRESS_REGISTER, control);
XEmacPs_PhyWrite(xemacpsp,phy_addr, 0x1F, 0x8180);//0x8180 0xA180
XEmacPs_PhyRead(xemacpsp, phy_addr, 0x1F, &control);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",0x1F, control);
control = 0x1E1;
XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG, control);
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG, &control);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",IEEE_AUTONEGO_ADVERTISE_REG, control);
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
xil_printf("ADDRESS_REGISTER 0:0x%x -> 0x%x \r\n",IEEE_CONTROL_REG_OFFSET, control);
control &= 0xEDFF;
control |= 0x2500;
XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, control);
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
xil_printf("ADDRESS_REGISTER 1:0x%x -> 0x%x \r\n",IEEE_CONTROL_REG_OFFSET, control);
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
control |= IEEE_CTRL_RESET_MASK;
XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, control);
while (1) {
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
if (control & IEEE_CTRL_RESET_MASK)
continue;
else
break;
}
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",IEEE_STATUS_REG_OFFSET, control);
XEmacPs_PhyWrite(xemacpsp,phy_addr, IEEE_PAGE_ADDRESS_REGISTER, 2);//RMII Override
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_PAGE_ADDRESS_REGISTER, &control);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",IEEE_PAGE_ADDRESS_REGISTER, control);
XEmacPs_PhyWrite(xemacpsp,phy_addr, 0x1F, 0x8180);//0x8180 0xA180
XEmacPs_PhyRead(xemacpsp, phy_addr, 0x1F, &control);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",0x1F, control);
control = 0x1E1;
XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG, control);
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_AUTONEGO_ADVERTISE_REG, &control);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",IEEE_AUTONEGO_ADVERTISE_REG, control);
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
xil_printf("ADDRESS_REGISTER 0:0x%x -> 0x%x \r\n",IEEE_CONTROL_REG_OFFSET, control);
control &= 0xEDFF;
control |= 0x2500;
XEmacPs_PhyWrite(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, control);
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_CONTROL_REG_OFFSET, &control);
xil_printf("ADDRESS_REGISTER 1:0x%x -> 0x%x \r\n",IEEE_CONTROL_REG_OFFSET, control);
XEmacPs_PhyWrite(xemacpsp,phy_addr, 0x1E, 0x00);//Modify-20220901
xil_printf("Waiting for PHY to complete autonegotiation.\r\n");
/*
while ( !(status & IEEE_STAT_AUTONEGOTIATE_COMPLETE) ) {
sleep(1);
timeout_counter++;
if (timeout_counter == 30) {
xil_printf("Auto negotiation error \r\n");
return XST_FAILURE;
}
XEmacPs_PhyRead(xemacpsp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
xil_printf("ADDRESS_REGISTER:0x%x -> 0x%x \r\n",IEEE_STATUS_REG_OFFSET, control);
}
*/
xil_printf("autonegotiation complete \r\n");
XEmacPs_PhyRead(xemacpsp, phy_addr,0x05, &status_speed);
xil_printf("status_speed 0x05-> 0x%x \r\n",status_speed);
XEmacPs_PhyRead(xemacpsp, phy_addr,0x06, &status_speed);
xil_printf("status_speed 0x06-> 0x%x \r\n",status_speed);
XEmacPs_PhyRead(xemacpsp, phy_addr,0x08, &status_speed);
xil_printf("status_speed 0x08-> 0x%x \r\n",status_speed);
XEmacPs_PhyRead(xemacpsp, phy_addr,0x17, &status_speed);
xil_printf("status_speed 0x17-> 0x%x \r\n",status_speed);
XEmacPs_PhyRead(xemacpsp, phy_addr,0x1e, &status_speed);
xil_printf("status_speed 0x1e-> 0x%x \r\n",status_speed);
if ( ((status_speed & 0x06) == 0x06)||((status_speed & 0x02) == 0x02) )/* 100Mbps */
{
if ( (status_speed & 0x06) == 0x06)/* 100Mbps */
{
xil_printf("100BASE-TX full-duplex \r\n");
}
else
{
xil_printf("100BASE-TX half-duplex \r\n");
}
return 100;
}
else if ( ((status_speed & 0x05) == 0x05) ||((status_speed & 0x01) == 0x01) ) /* 10Mbps */
{
if ( (status_speed & 0x05) == 0x05)/* 100Mbps */
{
xil_printf("10BASE-TX full-duplex \r\n");
}
else
{
xil_printf("10BASE-TX half-duplex \r\n");
}
return 10;
}
else
return 0;
return XST_SUCCESS;
} |
|