RTCT即线缆诊断,在车载以太网使用上是一个必备的功能
一 手册解读
解释如下
涉及的相关寄存器
二 相关代码
s8 RTL9010AA_VA_CableFaultLocationAndDiagnosis(u16* cable_length){
u32 mdio_data = 0;
u16 cable_st;
mdio_write(31, 0x0A42); //PAGSR:change page to 0xA42
mdio_write(17, 0x0001); //RTCTCR: bit0 = 1,rtct_en, enable RTCT and start to test
while (mdio_data != 0x8000){ //RTCTCR: bit15 = 1, check RTCT is finished
mdio_data = mdio_read(17);
mdio_data = mdio_data & 0x8000;
}
//read channel status and cable length
mdio_write(31, 0x0A43); //write reg31,page select register
mdio_write(27, 0x8022); //PHYSRAD
mdio_data = mdio_read(28); //PHYSRD: this value means cable status
cable_st = mdio_data & 0xFF00;
//normal mode
if (cable_st == 0x6000) {
*cable_length = 0xFFFF; // Cable is normal.
return CABLE_NORMAL;
}
//open mode
if (cable_st == 0x4800){
mdio_write(27, 0x8023);
mdio_data = mdio_read(28);
mdio_data = mdio_data * 2 / 15;
*cable_length = (mdio_data & 0xFFFF);
return CABLE_OPEN;
}
if (cable_st == 0x5000){
return CABLE_SHORT;
}
return ERROR;
}