From 9756c65315eefdf4146fcd1524e394638822865b Mon Sep 17 00:00:00 2001 From: Ondrej Kosta Date: Fri, 21 Jun 2024 09:32:50 +0200 Subject: [PATCH] feat(dummy_phy): addressed review comments --- eth_dummy_phy/CMakeLists.txt | 2 +- .../examples/simple/main/CMakeLists.txt | 3 +- .../examples/simple/main/emac2emac.c | 48 +++++++++---------- eth_dummy_phy/idf_component.yml | 1 + 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/eth_dummy_phy/CMakeLists.txt b/eth_dummy_phy/CMakeLists.txt index 4906d77..8908d36 100644 --- a/eth_dummy_phy/CMakeLists.txt +++ b/eth_dummy_phy/CMakeLists.txt @@ -1,3 +1,3 @@ idf_component_register(SRCS "src/esp_eth_phy_dummy.c" INCLUDE_DIRS "include" - PRIV_REQUIRES log esp_eth) \ No newline at end of file + PRIV_REQUIRES log esp_eth esp_driver_gpio) \ No newline at end of file diff --git a/eth_dummy_phy/examples/simple/main/CMakeLists.txt b/eth_dummy_phy/examples/simple/main/CMakeLists.txt index 5dc4ee9..d360731 100644 --- a/eth_dummy_phy/examples/simple/main/CMakeLists.txt +++ b/eth_dummy_phy/examples/simple/main/CMakeLists.txt @@ -1 +1,2 @@ -idf_component_register(SRCS "emac2emac.c") +idf_component_register(SRCS "emac2emac.c" + PRIV_REQUIRES esp_netif esp_driver_gpio esp_eth) diff --git a/eth_dummy_phy/examples/simple/main/emac2emac.c b/eth_dummy_phy/examples/simple/main/emac2emac.c index 87429b5..ba96086 100644 --- a/eth_dummy_phy/examples/simple/main/emac2emac.c +++ b/eth_dummy_phy/examples/simple/main/emac2emac.c @@ -14,7 +14,6 @@ #include "esp_log.h" #include "sdkconfig.h" #include "driver/gpio.h" -#include "hal/gpio_hal.h" #include "esp_system.h" #include "esp_eth_driver.h" #include "esp_eth_phy_dummy.h" @@ -80,11 +79,11 @@ static void cmd_ping_on_ping_end(esp_ping_handle_t hdl, void *args) esp_ping_delete_session(hdl); } -static void ping_start(const esp_netif_ip_info_t *ip_info) +static void ping_start(const esp_ip4_addr_t *ip) { esp_ping_config_t config = ESP_PING_DEFAULT_CONFIG(); - ip4_addr_set_u32(ip_2_ip4(&config.target_addr), ip_info->gw.addr); + ip4_addr_set_u32(ip_2_ip4(&config.target_addr), ip->addr); config.target_addr.type = IPADDR_TYPE_V4; // currently only IPv4 for this example /* set callback functions */ @@ -147,7 +146,7 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base, ESP_LOGI(TAG, "~~~~~~~~~~~"); #if !CONFIG_EXAMPLE_DHCP_SERVER_EN - ping_start(ip_info); + ping_start(&ip_info->gw); #endif } @@ -166,18 +165,21 @@ IRAM_ATTR static void gpio_isr_handler(void *arg) void app_main(void) { -#if CONFIG_EXAMPLE_RMII_CLK_SOURCE_DEV - // ESP32 device which is RMII CLK source needs to wait with its Ethernet initialization for the "RMII CLK - // Sink Device" since the RMII CLK input pin (GPIO0) is also used as a boot strap pin. If the "RMII CLK Source Device" didn't wait, + // ESP32 device which is RMII CLK source needs to wait with its Ethernet initialization for the "RMII CLK Sink Device" + // since the RMII CLK input pin (GPIO0) is also used as a boot strap pin. If the "RMII CLK Source Device" didn't wait, // the "RMII CLK Sink Device" could boot into incorrect mode. +#if CONFIG_EXAMPLE_RMII_CLK_SOURCE_DEV esp_rom_gpio_pad_select_gpio(EMAC_CLK_OUT_180_GPIO); gpio_set_pull_mode(EMAC_CLK_OUT_180_GPIO, GPIO_FLOATING); // to not affect GPIO0 (so the Sink Device could be flashed) gpio_install_isr_service(0); - esp_rom_gpio_pad_select_gpio(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO); - gpio_set_direction(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO, GPIO_MODE_INPUT); - gpio_set_pull_mode(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO, GPIO_PULLDOWN_ONLY); - gpio_set_intr_type(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO, GPIO_INTR_ANYEDGE); - gpio_intr_enable(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO); + gpio_config_t gpio_source_cfg = { + .pin_bit_mask = (1ULL << CONFIG_EXAMPLE_CLK_SINK_READY_GPIO), + .mode = GPIO_MODE_INPUT, + .pull_up_en = GPIO_PULLUP_DISABLE, + .pull_down_en = GPIO_PULLDOWN_ENABLE, + .intr_type = GPIO_INTR_ANYEDGE + }; + gpio_config(&gpio_source_cfg); TaskHandle_t task_handle = xTaskGetHandle(pcTaskGetName(NULL)); gpio_isr_handler_add(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO, gpio_isr_handler, task_handle); ESP_LOGW(TAG, "waiting for RMII CLK sink device interrupt"); @@ -190,9 +192,14 @@ void app_main(void) } ESP_LOGI(TAG, "starting Ethernet initialization"); #else - esp_rom_gpio_pad_select_gpio(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO); - gpio_set_direction(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO, GPIO_MODE_OUTPUT); - gpio_set_pull_mode(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO, GPIO_FLOATING); + gpio_config_t gpio_sink_cfg = { + .pin_bit_mask = (1ULL << CONFIG_EXAMPLE_CLK_SINK_READY_GPIO), + .mode = GPIO_MODE_OUTPUT, + .pull_up_en = GPIO_PULLUP_DISABLE, + .pull_down_en = GPIO_PULLDOWN_DISABLE, + .intr_type = GPIO_INTR_DISABLE + }; + gpio_config(&gpio_sink_cfg); gpio_set_level(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO, 0); vTaskDelay(pdMS_TO_TICKS(STARTUP_DELAY_MS)); gpio_set_level(CONFIG_EXAMPLE_CLK_SINK_READY_GPIO, 1); @@ -210,8 +217,8 @@ void app_main(void) eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); // Update vendor specific MAC config based on board configuration // No SMI, speed/duplex must be statically configured the same in both devices - esp32_emac_config.smi_mdc_gpio_num = -1; - esp32_emac_config.smi_mdio_gpio_num = -1; + esp32_emac_config.smi_gpio.mdc_num = -1; + esp32_emac_config.smi_gpio.mdio_num = -1; #if CONFIG_EXAMPLE_RMII_CLK_SOURCE_DEV esp32_emac_config.clock_config.rmii.clock_mode = EMAC_CLK_OUT; esp32_emac_config.clock_config.rmii.clock_gpio = EMAC_CLK_OUT_180_GPIO; @@ -274,13 +281,6 @@ void app_main(void) ESP_ERROR_CHECK(esp_eth_start(eth_handle)); -#if !CONFIG_EXAMPLE_DHCP_SERVER_EN - vTaskDelay(pdMS_TO_TICKS(7000)); - esp_eth_stop(eth_handle); - vTaskDelay(pdMS_TO_TICKS(500)); - esp_eth_start(eth_handle); -#endif - #if CONFIG_EXAMPLE_RMII_CLK_SOURCE_DEV // Wait indefinitely or reset when "RMII CLK Sink Device" resets // We reset the "RMII CLK Source Device" to ensure there is no CLK at GPIO0 of the diff --git a/eth_dummy_phy/idf_component.yml b/eth_dummy_phy/idf_component.yml index 9cacdb6..60e8c22 100644 --- a/eth_dummy_phy/idf_component.yml +++ b/eth_dummy_phy/idf_component.yml @@ -1,4 +1,5 @@ version: 0.5.0 +license: 'Apache-2.0' targets: - esp32 - esp32p4