Skip to content

Commit

Permalink
Update ch390/src/esp_eth_phy_ch390.c
Browse files Browse the repository at this point in the history
Co-authored-by: bogdankolendovskyy <[email protected]>
  • Loading branch information
SergeyKharenko and bogdankolendovskyy authored Nov 27, 2024
1 parent f5abf79 commit 5f4231e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ch390/src/esp_eth_phy_ch390.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,32 @@ static esp_err_t ch390_get_link(esp_eth_phy_t *phy)
return ret;
}

static esp_err_t ch390_autonego_ctrl(esp_eth_phy_t *phy, eth_phy_autoneg_cmd_t cmd, bool *autonego_en_stat)
{
esp_err_t ret = ESP_OK;
phy_802_3_t *phy_802_3 = esp_eth_phy_into_phy_802_3(phy);
esp_eth_mediator_t *eth = phy_802_3->eth;
if (cmd == ESP_ETH_PHY_AUTONEGO_EN) {
bmcr_reg_t bmcr;
ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, phy_802_3->addr, ETH_PHY_BMCR_REG_ADDR, &(bmcr.val)), err, TAG, "read BMCR failed");
ESP_GOTO_ON_FALSE(bmcr.en_loopback == 0, ESP_ERR_INVALID_STATE, err, TAG, "Autonegotiation can't be enabled while in loopback operation");
}
return esp_eth_phy_802_3_autonego_ctrl(phy_802_3, cmd, autonego_en_stat);
err:
return ret;
}

static esp_err_t ch390_loopback(esp_eth_phy_t *phy, bool enable)
{
esp_err_t ret = ESP_OK;
phy_802_3_t *phy_802_3 = esp_eth_phy_into_phy_802_3(phy);
bool auto_nego_en = true;
ESP_GOTO_ON_ERROR(ch390_autonego_ctrl(phy, ESP_ETH_PHY_AUTONEGO_G_STAT, &auto_nego_en), err, TAG, "get status of autonegotiation failed");
ESP_GOTO_ON_FALSE(!(auto_nego_en && enable), ESP_ERR_INVALID_STATE, err, TAG, "Unable to set loopback while autonegotiation is enabled. Disable it to use loopback");
return esp_eth_phy_802_3_loopback(phy_802_3, enable);
err:
return ret;
}
static esp_err_t ch390_init(esp_eth_phy_t *phy)
{
esp_err_t ret = ESP_OK;
Expand Down

0 comments on commit 5f4231e

Please sign in to comment.