[ETH] Phy ID configurable as parameter
This commit is contained in:
13
lib/ethernet/phy.c
Normal file → Executable file
13
lib/ethernet/phy.c
Normal file → Executable file
@@ -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);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
Reference in New Issue
Block a user