[ETH] Phy ID configurable as parameter

This commit is contained in:
brabo
2014-12-05 20:24:00 +01:00
committed by Frantisek Burian
parent c09d2583dd
commit 9cced2c0b4
3 changed files with 24 additions and 17 deletions

12
include/libopencm3/ethernet/phy.h Normal file → Executable file
View File

@@ -64,6 +64,8 @@
#define PHY_REG_BSR_FAULT (1<<4) #define PHY_REG_BSR_FAULT (1<<4)
#define PHY_REG_BSR_ANDONE (1<<5) #define PHY_REG_BSR_ANDONE (1<<5)
#define PHY0 0
#define PHY1 1
enum phy_status { enum phy_status {
LINK_DOWN, LINK_DOWN,
@@ -77,13 +79,13 @@ enum phy_status {
LINK_FD_10000M, LINK_FD_10000M,
}; };
void phy_reset(void); void phy_reset(uint8_t phy);
bool phy_link_isup(void); 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_force(uint8_t phy, enum phy_status mode);
void phy_autoneg_enable(void); void phy_autoneg_enable(uint8_t phy);
/**@}*/ /**@}*/

13
lib/ethernet/phy.c Normal file → Executable file
View File

@@ -40,23 +40,24 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** @brief Is the link up ? /** @brief Is the link up ?
* *
* @param[in] phy uint8_t phy ID of the PHY
* @returns bool true, if link is up * @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 /** @brief Reset the PHY
* *
* Reset the PHY chip and wait for done * 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); eth_smi_write(phy, PHY_REG_BCR, PHY_REG_BCR_RESET);
while (eth_smi_read(phy, PHY_REG_BCR) & PHY_REG_BCR_RESET);
while (eth_smi_read(1, PHY_REG_BCR) & PHY_REG_BCR_RESET);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

View File

@@ -43,11 +43,12 @@
* *
* Retrieve the link speed and duplex status of the link. * 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 * @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 * 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 * @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; uint16_t bst = 0;
@@ -70,7 +72,7 @@ void phy_autoneg_force(enum phy_status mode)
bst |= PHY_REG_BCR_100M; 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)); ~(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 /** @brief Enable the autonegotiation
* *
* Enable the autonegotiation of the link speed and duplex mode * 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);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/