Skip to content

Commit

Permalink
feat(dummy_phy): addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kostaond committed Jun 21, 2024
1 parent 4281fb2 commit 9756c65
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion eth_dummy_phy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
idf_component_register(SRCS "src/esp_eth_phy_dummy.c"
INCLUDE_DIRS "include"
PRIV_REQUIRES log esp_eth)
PRIV_REQUIRES log esp_eth esp_driver_gpio)
3 changes: 2 additions & 1 deletion eth_dummy_phy/examples/simple/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
idf_component_register(SRCS "emac2emac.c")
idf_component_register(SRCS "emac2emac.c"
PRIV_REQUIRES esp_netif esp_driver_gpio esp_eth)
48 changes: 24 additions & 24 deletions eth_dummy_phy/examples/simple/main/emac2emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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
}

Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions eth_dummy_phy/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: 0.5.0
license: 'Apache-2.0'
targets:
- esp32
- esp32p4
Expand Down

0 comments on commit 9756c65

Please sign in to comment.