UInt16 ReadPhyRegister(AX88796CPhyRegister registerAddress) { // start reading our PHY register value UInt16 mdiocr = (UInt16)(ReadGlobalRegister(AX88796CRegister.MDIOCR) & 0xE0E0); // mask out the bits we will be setting mdiocr |= (UInt16)AX88796CRegisterBits.MDIOCR_MDIO_READ; mdiocr |= (UInt16)((UInt16)registerAddress & 0x1F); mdiocr |= (UInt16)(((UInt16)_phyID) << 8); WriteGlobalRegister(AX88796CRegister.MDIOCR, (UInt16)mdiocr); // wait for the PHY register value to be read successfully Int64 startTicks = Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks; bool mdioOperationSuccess = false; do { mdiocr = ReadGlobalRegister(AX88796CRegister.MDIOCR); if ((mdiocr & (UInt16)AX88796CRegisterBits.MDIOCR_MDIO_READWRITE_COMPLETE) == (UInt16)AX88796CRegisterBits.MDIOCR_MDIO_READWRITE_COMPLETE) { mdioOperationSuccess = true; break; } } while ((Utility.GetMachineTime().Ticks - startTicks) / System.TimeSpan.TicksPerMillisecond < 250); // wait up to 250ms if (!mdioOperationSuccess) { throw new Exception(); /* TODO: this should be a "could not configure network interface" exception */ } return(ReadGlobalRegister(AX88796CRegister.MDIODR)); }
UInt16 ReadPhyRegister(AX88796CPhyRegister registerAddress) { // start reading our PHY register value UInt16 mdiocr = (UInt16)(ReadGlobalRegister(AX88796CRegister.MDIOCR) & 0xE0E0); // mask out the bits we will be setting mdiocr |= (UInt16)AX88796CRegisterBits.MDIOCR_MDIO_READ; mdiocr |= (UInt16)((UInt16)registerAddress & 0x1F); mdiocr |= (UInt16)(((UInt16)_phyID) << 8); WriteGlobalRegister(AX88796CRegister.MDIOCR, (UInt16)mdiocr); // wait for the PHY register value to be read successfully Int64 startTicks = Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks; bool mdioOperationSuccess = false; do { mdiocr = ReadGlobalRegister(AX88796CRegister.MDIOCR); if ((mdiocr & (UInt16)AX88796CRegisterBits.MDIOCR_MDIO_READWRITE_COMPLETE) == (UInt16)AX88796CRegisterBits.MDIOCR_MDIO_READWRITE_COMPLETE) { mdioOperationSuccess = true; break; } } while ((Utility.GetMachineTime().Ticks - startTicks) / System.TimeSpan.TicksPerMillisecond < 250); // wait up to 250ms if (!mdioOperationSuccess) throw new Exception(); /* TODO: this should be a "could not configure network interface" exception */ return ReadGlobalRegister(AX88796CRegister.MDIODR); }