Description
Source
Call Graph
Start Line: 256
unsigned char DM9161_InitPhy(Dm9161 *pDm, unsigned int mck, const Pin *pResetPins, unsigned int nbResetPins, const Pin *pEmacPins, unsigned int nbEmacPins)
{
unsigned char rc = 1;
unsigned char phy;
ASSERT(pDm, "-F- DM9161_InitPhy\n\r");
// Perform RESET
TRACE_DEBUG("RESET PHY\n\r");
if (pResetPins) {
// Configure PINS
PIO_Configure(pResetPins, nbResetPins);
// Execute reset
RSTC_SetExtResetLength(DM9161_RESET_LENGTH);
RSTC_ExtReset();
// Wait for end hardware reset
while (!RSTC_GetNrstLevel());
}
// Configure EMAC runtime pins
if (rc) {
PIO_Configure(pEmacPins, nbEmacPins);
rc = EMAC_SetMdcClock( mck );
if (!rc) {
TRACE_ERROR("No Valid MDC clock\n\r");
return 0;
}
// Check PHY Address
phy = DM9161_FindValidPhy(pDm);
if (phy == 0xFF) {
TRACE_ERROR("PHY Access fail\n\r");
return 0;
}
if(phy != pDm->phyAddress) {
pDm->phyAddress = phy;
DM9161_ResetPhy(pDm);
}
}
else {
TRACE_ERROR("PHY Reset Timeout\n\r");
}
return rc;
}