mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_eth: restart negotiation in esp_eth_start
This commit is contained in:
parent
415418cf0e
commit
03a6c4975c
@ -261,6 +261,8 @@ esp_err_t esp_eth_start(esp_eth_handle_t hdl)
|
||||
esp_err_t ret = ESP_OK;
|
||||
esp_eth_driver_t *eth_driver = (esp_eth_driver_t *)hdl;
|
||||
ETH_CHECK(eth_driver, "ethernet driver handle can't be null", err, ESP_ERR_INVALID_ARG);
|
||||
esp_eth_phy_t *phy = eth_driver->phy;
|
||||
esp_eth_mac_t *mac = eth_driver->mac;
|
||||
// check if driver has started
|
||||
esp_eth_fsm_t expected_fsm = ESP_ETH_FSM_STOP;
|
||||
if (!atomic_compare_exchange_strong(ð_driver->fsm, &expected_fsm, ESP_ETH_FSM_START)) {
|
||||
@ -268,14 +270,13 @@ esp_err_t esp_eth_start(esp_eth_handle_t hdl)
|
||||
ret = ESP_ERR_INVALID_STATE;
|
||||
goto err;
|
||||
}
|
||||
ETH_CHECK(eth_driver->phy->reset(eth_driver->phy) == ESP_OK, "reset phy failed", err, ESP_FAIL);
|
||||
ETH_CHECK(phy->negotiate(phy) == ESP_OK, "phy negotiation failed", err, ESP_FAIL);
|
||||
ETH_CHECK(mac->start(mac) == ESP_OK, "start mac failed", err, ESP_FAIL);
|
||||
ETH_CHECK(esp_event_post(ETH_EVENT, ETHERNET_EVENT_START, ð_driver, sizeof(esp_eth_driver_t *), 0) == ESP_OK,
|
||||
"send ETHERNET_EVENT_START event failed", err, ESP_FAIL);
|
||||
ETH_CHECK(phy->get_link(phy) == ESP_OK, "phy get link status failed", err, ESP_FAIL);
|
||||
ETH_CHECK(xTimerStart(eth_driver->check_link_timer, 0) == pdPASS,
|
||||
"start eth_link_timer failed", err, ESP_FAIL);
|
||||
ETH_CHECK(esp_event_post(ETH_EVENT, ETHERNET_EVENT_START, ð_driver, sizeof(eth_driver), 0) == ESP_OK,
|
||||
"send ETHERNET_EVENT_START event failed", err_event, ESP_FAIL);
|
||||
return ESP_OK;
|
||||
err_event:
|
||||
xTimerStop(eth_driver->check_link_timer, 0);
|
||||
err:
|
||||
return ret;
|
||||
}
|
||||
|
@ -216,6 +216,8 @@ static esp_err_t dm9051_negotiate(esp_eth_phy_t *phy)
|
||||
{
|
||||
phy_dm9051_t *dm9051 = __containerof(phy, phy_dm9051_t, parent);
|
||||
esp_eth_mediator_t *eth = dm9051->eth;
|
||||
/* in case any link status has changed, let's assume we're in link down status */
|
||||
dm9051->link_status = ETH_LINK_DOWN;
|
||||
/* Start auto negotiation */
|
||||
bmcr_reg_t bmcr = {
|
||||
.speed_select = 1, /* 100Mbps */
|
||||
@ -229,8 +231,8 @@ static esp_err_t dm9051_negotiate(esp_eth_phy_t *phy)
|
||||
bmsr_reg_t bmsr;
|
||||
dscsr_reg_t dscsr;
|
||||
uint32_t to = 0;
|
||||
for (to = 0; to < dm9051->autonego_timeout_ms / 10; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
for (to = 0; to < dm9051->autonego_timeout_ms / 100; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
PHY_CHECK(eth->phy_reg_read(eth, dm9051->addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)) == ESP_OK,
|
||||
"read BMSR failed", err);
|
||||
PHY_CHECK(eth->phy_reg_read(eth, dm9051->addr, ETH_PHY_DSCSR_REG_ADDR, &(dscsr.val)) == ESP_OK,
|
||||
@ -239,11 +241,9 @@ static esp_err_t dm9051_negotiate(esp_eth_phy_t *phy)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (to >= dm9051->autonego_timeout_ms / 10) {
|
||||
if (to >= dm9051->autonego_timeout_ms / 100) {
|
||||
ESP_LOGW(TAG, "Ethernet PHY auto negotiation timeout");
|
||||
}
|
||||
/* Updata information about link, speed, duplex */
|
||||
PHY_CHECK(dm9051_update_link_duplex_speed(dm9051) == ESP_OK, "update link duplex speed failed", err);
|
||||
return ESP_OK;
|
||||
err:
|
||||
return ESP_FAIL;
|
||||
|
@ -205,6 +205,8 @@ static esp_err_t dp83848_negotiate(esp_eth_phy_t *phy)
|
||||
{
|
||||
phy_dp83848_t *dp83848 = __containerof(phy, phy_dp83848_t, parent);
|
||||
esp_eth_mediator_t *eth = dp83848->eth;
|
||||
/* in case any link status has changed, let's assume we're in link down status */
|
||||
dp83848->link_status = ETH_LINK_DOWN;
|
||||
/* Start auto negotiation */
|
||||
bmcr_reg_t bmcr = {
|
||||
.speed_select = 1, /* 100Mbps */
|
||||
@ -218,8 +220,8 @@ static esp_err_t dp83848_negotiate(esp_eth_phy_t *phy)
|
||||
bmsr_reg_t bmsr;
|
||||
physts_reg_t physts;
|
||||
uint32_t to = 0;
|
||||
for (to = 0; to < dp83848->autonego_timeout_ms / 10; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
for (to = 0; to < dp83848->autonego_timeout_ms / 100; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
PHY_CHECK(eth->phy_reg_read(eth, dp83848->addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)) == ESP_OK,
|
||||
"read BMSR failed", err);
|
||||
PHY_CHECK(eth->phy_reg_read(eth, dp83848->addr, ETH_PHY_STS_REG_ADDR, &(physts.val)) == ESP_OK,
|
||||
@ -229,11 +231,9 @@ static esp_err_t dp83848_negotiate(esp_eth_phy_t *phy)
|
||||
}
|
||||
}
|
||||
/* Auto negotiation failed, maybe no network cable plugged in, so output a warning */
|
||||
if (to >= dp83848->autonego_timeout_ms / 10) {
|
||||
if (to >= dp83848->autonego_timeout_ms / 100) {
|
||||
ESP_LOGW(TAG, "auto negotiation timeout");
|
||||
}
|
||||
/* Updata information about link, speed, duplex */
|
||||
PHY_CHECK(dp83848_update_link_duplex_speed(dp83848) == ESP_OK, "update link duplex speed failed", err);
|
||||
return ESP_OK;
|
||||
err:
|
||||
return ESP_FAIL;
|
||||
|
@ -245,6 +245,8 @@ static esp_err_t ip101_negotiate(esp_eth_phy_t *phy)
|
||||
{
|
||||
phy_ip101_t *ip101 = __containerof(phy, phy_ip101_t, parent);
|
||||
esp_eth_mediator_t *eth = ip101->eth;
|
||||
/* in case any link status has changed, let's assume we're in link down status */
|
||||
ip101->link_status = ETH_LINK_DOWN;
|
||||
/* Restart auto negotiation */
|
||||
bmcr_reg_t bmcr = {
|
||||
.speed_select = 1, /* 100Mbps */
|
||||
@ -257,8 +259,8 @@ static esp_err_t ip101_negotiate(esp_eth_phy_t *phy)
|
||||
/* Wait for auto negotiation complete */
|
||||
bmsr_reg_t bmsr;
|
||||
uint32_t to = 0;
|
||||
for (to = 0; to < ip101->autonego_timeout_ms / 10; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
for (to = 0; to < ip101->autonego_timeout_ms / 100; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
PHY_CHECK(eth->phy_reg_read(eth, ip101->addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)) == ESP_OK,
|
||||
"read BMSR failed", err);
|
||||
if (bmsr.auto_nego_complete) {
|
||||
@ -266,11 +268,9 @@ static esp_err_t ip101_negotiate(esp_eth_phy_t *phy)
|
||||
}
|
||||
}
|
||||
/* Auto negotiation failed, maybe no network cable plugged in, so output a warning */
|
||||
if (to >= ip101->autonego_timeout_ms / 10) {
|
||||
if (to >= ip101->autonego_timeout_ms / 100) {
|
||||
ESP_LOGW(TAG, "auto negotiation timeout");
|
||||
}
|
||||
/* Updata information about link, speed, duplex */
|
||||
PHY_CHECK(ip101_update_link_duplex_speed(ip101) == ESP_OK, "update link duplex speed failed", err);
|
||||
return ESP_OK;
|
||||
err:
|
||||
return ESP_FAIL;
|
||||
|
@ -290,6 +290,8 @@ static esp_err_t lan8720_negotiate(esp_eth_phy_t *phy)
|
||||
{
|
||||
phy_lan8720_t *lan8720 = __containerof(phy, phy_lan8720_t, parent);
|
||||
esp_eth_mediator_t *eth = lan8720->eth;
|
||||
/* in case any link status has changed, let's assume we're in link down status */
|
||||
lan8720->link_status = ETH_LINK_DOWN;
|
||||
/* Restart auto negotiation */
|
||||
bmcr_reg_t bmcr = {
|
||||
.speed_select = 1, /* 100Mbps */
|
||||
@ -302,8 +304,8 @@ static esp_err_t lan8720_negotiate(esp_eth_phy_t *phy)
|
||||
bmsr_reg_t bmsr;
|
||||
pscsr_reg_t pscsr;
|
||||
uint32_t to = 0;
|
||||
for (to = 0; to < lan8720->autonego_timeout_ms / 10; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
for (to = 0; to < lan8720->autonego_timeout_ms / 100; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
PHY_CHECK(eth->phy_reg_read(eth, lan8720->addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)) == ESP_OK,
|
||||
"read BMSR failed", err);
|
||||
PHY_CHECK(eth->phy_reg_read(eth, lan8720->addr, ETH_PHY_PSCSR_REG_ADDR, &(pscsr.val)) == ESP_OK,
|
||||
@ -313,11 +315,9 @@ static esp_err_t lan8720_negotiate(esp_eth_phy_t *phy)
|
||||
}
|
||||
}
|
||||
/* Auto negotiation failed, maybe no network cable plugged in, so output a warning */
|
||||
if (to >= lan8720->autonego_timeout_ms / 10) {
|
||||
if (to >= lan8720->autonego_timeout_ms / 100) {
|
||||
ESP_LOGW(TAG, "auto negotiation timeout");
|
||||
}
|
||||
/* Updata information about link, speed, duplex */
|
||||
PHY_CHECK(lan8720_update_link_duplex_speed(lan8720) == ESP_OK, "update link duplex speed failed", err);
|
||||
return ESP_OK;
|
||||
err:
|
||||
return ESP_FAIL;
|
||||
|
@ -199,6 +199,8 @@ static esp_err_t rtl8201_negotiate(esp_eth_phy_t *phy)
|
||||
{
|
||||
phy_rtl8201_t *rtl8201 = __containerof(phy, phy_rtl8201_t, parent);
|
||||
esp_eth_mediator_t *eth = rtl8201->eth;
|
||||
/* in case any link status has changed, let's assume we're in link down status */
|
||||
rtl8201->link_status = ETH_LINK_DOWN;
|
||||
/* Restart auto negotiation */
|
||||
bmcr_reg_t bmcr = {
|
||||
.speed_select = 1, /* 100Mbps */
|
||||
@ -211,8 +213,8 @@ static esp_err_t rtl8201_negotiate(esp_eth_phy_t *phy)
|
||||
/* Wait for auto negotiation complete */
|
||||
bmsr_reg_t bmsr;
|
||||
uint32_t to = 0;
|
||||
for (to = 0; to < rtl8201->autonego_timeout_ms / 10; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
for (to = 0; to < rtl8201->autonego_timeout_ms / 100; to++) {
|
||||
vTaskDelay(pdMS_TO_TICKS(100));
|
||||
PHY_CHECK(eth->phy_reg_read(eth, rtl8201->addr, ETH_PHY_BMSR_REG_ADDR, &(bmsr.val)) == ESP_OK,
|
||||
"read BMSR failed", err);
|
||||
if (bmsr.auto_nego_complete) {
|
||||
@ -220,11 +222,9 @@ static esp_err_t rtl8201_negotiate(esp_eth_phy_t *phy)
|
||||
}
|
||||
}
|
||||
/* Auto negotiation failed, maybe no network cable plugged in, so output a warning */
|
||||
if (to >= rtl8201->autonego_timeout_ms / 10) {
|
||||
if (to >= rtl8201->autonego_timeout_ms / 100) {
|
||||
ESP_LOGW(TAG, "auto negotiation timeout");
|
||||
}
|
||||
/* Updata information about link, speed, duplex */
|
||||
PHY_CHECK(rtl8201_update_link_duplex_speed(rtl8201) == ESP_OK, "update link duplex speed failed", err);
|
||||
return ESP_OK;
|
||||
err:
|
||||
return ESP_FAIL;
|
||||
|
@ -154,15 +154,14 @@ static esp_err_t w5500_negotiate(esp_eth_phy_t *phy)
|
||||
{
|
||||
phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent);
|
||||
esp_eth_mediator_t *eth = w5500->eth;
|
||||
|
||||
/* in case any link status has changed, let's assume we're in link down status */
|
||||
w5500->link_status = ETH_LINK_DOWN;
|
||||
phycfg_reg_t phycfg;
|
||||
PHY_CHECK(eth->phy_reg_read(eth, w5500->addr, W5500_REG_PHYCFGR, (uint32_t *) & (phycfg.val)) == ESP_OK, "read PHYCFG failed", err);
|
||||
phycfg.opsel = 1; // PHY working mode configured by register
|
||||
phycfg.opmode = 7; // all capable, auto-negotiation enabled
|
||||
PHY_CHECK(eth->phy_reg_write(eth, w5500->addr, W5500_REG_PHYCFGR, phycfg.val) == ESP_OK, "write PHYCFG failed", err);
|
||||
|
||||
/* Update information about link, speed, duplex */
|
||||
PHY_CHECK(w5500_update_link_duplex_speed(w5500) == ESP_OK, "update link duplex speed failed", err);
|
||||
return ESP_OK;
|
||||
err:
|
||||
return ESP_FAIL;
|
||||
|
Loading…
Reference in New Issue
Block a user