/* Phy status update state machine */ s32_t lpc_phy_sts_sm(struct netif *netif) { static u32_t sts; s32_t changed = 0; switch (phyustate) { default: case 0: /* Read BMSR to clear faults */ lpc_mii_read_noblock(LAN8_BSR_REG); phyustate = 1; break; case 1: /* Wait for read status state */ if (!lpc_mii_is_busy()) { /* Get PHY status with link state */ sts = lpc_mii_read_data(); lpc_mii_read_noblock(LAN8_PHYSPLCTL_REG); phyustate = 2; } break; case 2: /* Wait for read status state */ if (!lpc_mii_is_busy()) { /* Update PHY status */ changed = lpc_update_phy_sts(netif, sts, lpc_mii_read_data()); phyustate = 0; } break; } return changed; }
/* Phy status update state machine */ uint32_t lpcPHYStsPoll(void) { switch (phyustate) { default: case 0: /* Read BMSR to clear faults */ Chip_ENET_StartMIIRead(LPC_ETHERNET, DP8_PHY_STAT_REG); physts &= ~PHY_LINK_CHANGED; physts = physts | PHY_LINK_BUSY; phyustate = 1; break; case 1: /* Wait for read status state */ if (!Chip_ENET_IsMIIBusy(LPC_ETHERNET)) { /* Update PHY status */ physts &= ~PHY_LINK_BUSY; lpc_update_phy_sts(Chip_ENET_ReadMIIData(LPC_ETHERNET)); phyustate = 0; } break; } return physts; }
/** * Initialize the LAN8720 PHY. * * This function initialises the LAN8720 PHY. It will block until complete. This * function is called as part of the EMAC driver Initialisation. Configuration * of the PHY at startup is controlled by setting up configuration defines in * lpc_emac_config.h. * * \param [in] netif NETIF structure * \return ERR_OK if the setup was successful, otherwise ERR_TIMEOUT */ err_t lpc_phy_init(struct netif *netif) { u32_t tmp = 2, tmp1; s32_t i; /** * Set these to 2 so there will always be a change and lpc_update_phy_sts does * something the first time its called */ olddphysts.phy_speed_100mbs = tmp; olddphysts.phy_full_duplex = tmp; olddphysts.phy_link_active = tmp; phyustate = 0; /* Only first read and write are checked for failure */ /* Put the LAN8720 in reset mode and wait for completion */ if (lpc_mii_write(LAN8_BCR_REG, LAN8_RESET) != 0) return ERR_TIMEOUT; i = 400; while (i > 0) { msDelay(1); /* 1 ms */ if (lpc_mii_read(LAN8_BCR_REG, &tmp) != 0) return ERR_TIMEOUT; if (!(tmp & (LAN8_RESET | LAN8_POWER_DOWN))) i = -1; else i--; } /* Timeout? */ if (i == 0) return ERR_TIMEOUT; /* Setup link based on configuration options */ #if PHY_USE_AUTONEG==1 tmp = LAN8_AUTONEG; #else tmp = 0; #endif #if PHY_USE_100MBS==1 tmp |= LAN8_SPEED_SELECT; #endif #if PHY_USE_FULL_DUPLEX==1 tmp |= LAN8_DUPLEX_MODE; #endif lpc_mii_write(LAN8_BCR_REG, tmp); /** * No point in waiting around for the link to go active if the cable is * unplugged, so set the current link status and exit. */ lpc_mii_read(LAN8_BSR_REG, &tmp); lpc_mii_read(LAN8_PHYSPLCTL_REG, &tmp1); lpc_update_phy_sts(netif, tmp, tmp1); return ERR_OK; }
/* Phy status update state machine */ s32_t lpc_phy_sts_sm(struct netif *netif) { s32_t changed = 0; switch (phyustate) { default: case 0: /* Read BMSR to clear faults */ lpc_mii_read_noblock(DP8_PHY_STAT_REG); phyustate = 1; break; case 1: /* Wait for read status state */ if (!lpc_mii_is_busy()) { /* Update PHY status */ changed = lpc_update_phy_sts(netif, lpc_mii_read_data()); phyustate = 0; } break; } return changed; }