components/esp_eth/src/esp_eth_phy_lan87xx.c
/**
 * @note This function is responsible for restarting a new auto-negotiation,
 *       the result of negotiation won't be relected to uppler layers.
 *       Instead, the negotiation result is fetched by linker timer, see `lan87xx_get_link()`
 */
@note This function is responsible for restarting a new auto-negotiation,
the result of negotiation won't be relected to uppler layers.
Instead, the negotiation result is fetched by linker timer, see `lan87xx_get_link()`
@note This function is responsible for restarting a new auto - negotiation the result of negotiation won ' t be relected to uppler layers . Instead the negotiation result is fetched by linker timer see ` lan87xx_get_link () `
static esp_err_t lan87xx_negotiate(esp_eth_phy_t *phy)
{
    esp_err_t ret = ESP_OK;
    phy_lan87xx_t *lan87xx = __containerof(phy, phy_lan87xx_t, parent);
    esp_eth_mediator_t *eth = lan87xx->eth;
    lan87xx->link_status = ETH_LINK_DOWN;
    bmcr_reg_t bmcr = {
        .speed_select = 1,     
        .duplex_mode = 1,      
        .en_auto_nego = 1,     
        .restart_auto_nego = 1 
    };
    ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, lan87xx->addr, ETH_PHY_BMCR_REG_ADDR, bmcr.val), err, TAG, "write BMCR failed");
    bmsr_reg_t bmsr;
    pscsr_reg_t pscsr;
    uint32_t to = 0;
    for (to = 0; to < lan87xx->autonego_timeout_ms / 100; to++) {
        vTaskDelay(pdMS_TO_TICKS(100));
        ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, lan87xx->addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)), err, TAG, "read BMSR failed");
        ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, lan87xx->addr, ETH_PHY_PSCSR_REG_ADDR, &(pscsr.val)), err, TAG, "read PSCSR failed");
        if (bmsr.auto_nego_complete && pscsr.auto_nego_done) {
            break;
        }
    }
    if (to >= lan87xx->autonego_timeout_ms / 100 && (lan87xx->link_status == ETH_LINK_UP)) {
        ESP_LOGW(TAG, "auto negotiation timeout");
    }
    return ESP_OK;
err:
    return ret;
}
static esp_err_t lan87xx_negotiate ( esp_eth_phy_t * phy ) { esp_err_t ret = ESP_OK ; phy_lan87xx_t * lan87xx = __containerof ( phy , phy_lan87xx_t , parent ) ; esp_eth_mediator_t * eth = lan87xx -> eth ; lan87xx -> link_status = ETH_LINK_DOWN ; bmcr_reg_t bmcr = { . speed_select = 1 , . duplex_mode = 1 , . en_auto_nego = 1 , . restart_auto_nego = 1 } ; ESP_GOTO_ON_ERROR ( eth -> phy_reg_write ( eth , lan87xx -> addr , ETH_PHY_BMCR_REG_ADDR , bmcr . val ) , err , TAG , " " ) ; bmsr_reg_t bmsr ; pscsr_reg_t pscsr ; uint32_t to = 0 ; for ( to = 0 ; to < lan87xx -> autonego_timeout_ms / 100 ; to ++ ) { vTaskDelay ( pdMS_TO_TICKS ( 100 ) ) ; ESP_GOTO_ON_ERROR ( eth -> phy_reg_read ( eth , lan87xx -> addr , ETH_PHY_BMSR_REG_ADDR , & ( bmsr . val ) ) , err , TAG , " " ) ; ESP_GOTO_ON_ERROR ( eth -> phy_reg_read ( eth , lan87xx -> addr , ETH_PHY_PSCSR_REG_ADDR , & ( pscsr . val ) ) , err , TAG , " " ) ; if ( bmsr . auto_nego_complete && pscsr . auto_nego_done ) { break ; } } if ( to >= lan87xx -> autonego_timeout_ms / 100 && ( lan87xx -> link_status == ETH_LINK_UP ) ) { ESP_LOGW ( TAG , " " ) ; } return ESP_OK ; err : return ret ; }
@note This function is responsible for restarting a new auto-negotiation,
       the result of negotiation won't be relected to uppler layers.
@note This function is responsible for restarting a new auto - negotiation the result of negotiation won ' t be relected to uppler layers .
/* in case any link status has changed, let's assume we're in link down status */ /* Restart auto negotiation */ /* 100Mbps */ /* Full Duplex */ /* Auto Negotiation */ /* Restart Auto Negotiation */ /* Wait for auto negotiation complete */ /* Auto negotiation failed, maybe no network cable plugged in, so output a warning */