/** * \brief Perform a HW initialization to the PHY and set up clocks. * * This should be called only once to initialize the PHY pre-settings. * The PHY address is the reset status of CRS, RXD[3:0] (the emacPins' pullups). * The COL pin is used to select MII mode on reset (pulled up for Reduced MII). * The RXDV pin is used to select test mode on reset (pulled up for test mode). * The above pins should be predefined for corresponding settings in resetPins. * The GMAC peripheral pins are configured after the reset is done. * * \param p_gmac Pointer to the GMAC instance. * \param uc_phy_addr PHY address. * \param ul_mck GMAC MCK. * * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout. */ uint8_t ethernet_phy_init(Gmac *p_gmac, uint8_t uc_phy_addr, uint32_t mck) { uint8_t uc_rc; uint8_t uc_phy; #if 0 // chrishamm pio_set_output(PIN_GMAC_RESET_PIO, PIN_GMAC_RESET_MASK, 1, false, true); pio_set_input(PIN_GMAC_INT_PIO, PIN_GMAC_INT_MASK, PIO_PULLUP); pio_set_peripheral(PIN_GMAC_PIO, PIN_GMAC_PERIPH, PIN_GMAC_MASK); #endif ethernet_phy_reset(GMAC,uc_phy_addr); /* Configure GMAC runtime clock */ uc_rc = gmac_set_mdc_clock(p_gmac, mck); if (uc_rc != GMAC_OK) { return 0; } /* Check PHY Address */ uc_phy = ethernet_phy_find_valid(p_gmac, uc_phy_addr, 0); if (uc_phy == 0xFF) { return 0; } if (uc_phy != uc_phy_addr) { ethernet_phy_reset(p_gmac, uc_phy_addr); } return uc_rc; }
/** * \brief Perform a HW initialization to the PHY and set up clocks. * * This should be called only once to initialize the PHY pre-settings. * The PHY address is the reset status of CRS, RXD[3:0] (the emacPins' pullups). * The COL pin is used to select MII mode on reset (pulled up for Reduced MII). * The RXDV pin is used to select test mode on reset (pulled up for test mode). * The above pins should be predefined for corresponding settings in resetPins. * The GMAC peripheral pins are configured after the reset is done. * * \param p_gmac Pointer to the GMAC instance. * \param uc_phy_addr PHY address. * \param ul_mck GMAC MCK. * * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout. */ uint8_t ethernet_phy_init(Gmac *p_gmac, uint8_t uc_phy_addr, uint32_t mck) { uint8_t uc_rc = GMAC_TIMEOUT; uint8_t uc_phy; ethernet_phy_reset(GMAC,uc_phy_addr); /* Configure GMAC runtime clock */ uc_rc = gmac_set_mdc_clock(p_gmac, mck); if (uc_rc != GMAC_OK) { return 0; } /* Check PHY Address */ uc_phy = ethernet_phy_find_valid(p_gmac, uc_phy_addr, 0); if (uc_phy == 0xFF) { return 0; } if (uc_phy != uc_phy_addr) { ethernet_phy_reset(p_gmac, uc_phy_addr); } phy_props.phy_chn = uc_phy; return uc_phy; }