diff --git a/include/libopencm3/ethernet/phy.h b/include/libopencm3/ethernet/phy.h old mode 100644 new mode 100755 index 325695cb..e3c1b95d --- a/include/libopencm3/ethernet/phy.h +++ b/include/libopencm3/ethernet/phy.h @@ -64,6 +64,8 @@ #define PHY_REG_BSR_FAULT (1<<4) #define PHY_REG_BSR_ANDONE (1<<5) +#define PHY0 0 +#define PHY1 1 enum phy_status { LINK_DOWN, @@ -77,13 +79,13 @@ enum phy_status { LINK_FD_10000M, }; -void phy_reset(void); -bool phy_link_isup(void); +void phy_reset(uint8_t phy); +bool phy_link_isup(uint8_t phy); -enum phy_status phy_link_status(void); +enum phy_status phy_link_status(uint8_t phy); -void phy_autoneg_force(enum phy_status mode); -void phy_autoneg_enable(void); +void phy_autoneg_force(uint8_t phy, enum phy_status mode); +void phy_autoneg_enable(uint8_t phy); /**@}*/ diff --git a/lib/ethernet/phy.c b/lib/ethernet/phy.c old mode 100644 new mode 100755 index 4866198a..363e1466 --- a/lib/ethernet/phy.c +++ b/lib/ethernet/phy.c @@ -40,23 +40,24 @@ /*---------------------------------------------------------------------------*/ /** @brief Is the link up ? * + * @param[in] phy uint8_t phy ID of the PHY * @returns bool true, if link is up */ -bool phy_link_isup(void) +bool phy_link_isup(uint8_t phy) { - return eth_smi_read(1, PHY_REG_BSR) & PHY_REG_BSR_UP; + return eth_smi_read(phy, PHY_REG_BSR) & PHY_REG_BSR_UP; } /*---------------------------------------------------------------------------*/ /** @brief Reset the PHY * * Reset the PHY chip and wait for done + * @param[in] phy uint8_t phy ID of the PHY */ -void phy_reset(void) +void phy_reset(uint8_t phy) { - eth_smi_write(1, PHY_REG_BCR, PHY_REG_BCR_RESET); - - while (eth_smi_read(1, PHY_REG_BCR) & PHY_REG_BCR_RESET); + eth_smi_write(phy, PHY_REG_BCR, PHY_REG_BCR_RESET); + while (eth_smi_read(phy, PHY_REG_BCR) & PHY_REG_BCR_RESET); } /*---------------------------------------------------------------------------*/ diff --git a/lib/ethernet/phy_ksz8051mll.c b/lib/ethernet/phy_ksz8051mll.c index b045ef62..275b5db9 100755 --- a/lib/ethernet/phy_ksz8051mll.c +++ b/lib/ethernet/phy_ksz8051mll.c @@ -43,11 +43,12 @@ * * Retrieve the link speed and duplex status of the link. * + * @param[in] phy uint8_t phy ID of the PHY * @returns ::phy_status Link status */ -enum phy_status phy_link_status(void) +enum phy_status phy_link_status(uint8_t phy) { - return eth_smi_read(1, PHY_REG_CR1) & 0x07; + return eth_smi_read(phy, PHY_REG_CR1) & 0x07; } /*---------------------------------------------------------------------------*/ @@ -55,9 +56,10 @@ enum phy_status phy_link_status(void) * * Force the autonegotiation and set link speed and duplex mode of the link * + * @param[in] phy uint8_t phy ID of the PHY * @param[in] mode enum phy_status Desired link status */ -void phy_autoneg_force(enum phy_status mode) +void phy_autoneg_force(uint8_t phy, enum phy_status mode) { uint16_t bst = 0; @@ -70,7 +72,7 @@ void phy_autoneg_force(enum phy_status mode) bst |= PHY_REG_BCR_100M; } - eth_smi_bit_op(1, PHY_REG_BCR, bst, + eth_smi_bit_op(phy, PHY_REG_BCR, bst, ~(PHY_REG_BCR_AN | PHY_REG_BCR_100M | PHY_REG_BCR_FD)); } @@ -78,10 +80,12 @@ void phy_autoneg_force(enum phy_status mode) /** @brief Enable the autonegotiation * * Enable the autonegotiation of the link speed and duplex mode + * + * @param[in] phy uint8_t phy ID of the PHY */ -void phy_autoneg_enable(void) +void phy_autoneg_enable(uint8_t phy) { - eth_smi_bit_set(1, PHY_REG_BCR, PHY_REG_BCR_AN | PHY_REG_BCR_ANRST); + eth_smi_bit_set(phy, PHY_REG_BCR, PHY_REG_BCR_AN | PHY_REG_BCR_ANRST); } /*---------------------------------------------------------------------------*/