From 8da2e4088c5de96c435ce2cd335f756a296927b5 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 24 Jan 2022 15:40:11 +0100 Subject: [PATCH] esp_eth: Update esp32's EMAC API to decouple driver and vendor config --- components/esp_eth/include/esp_eth_mac.h | 80 ++++++++----------- components/esp_eth/src/esp_eth_mac_esp.c | 33 ++++---- components/esp_eth/test/test_emac.c | 18 +++-- .../esp_eth/test_apps/main/esp_eth_test.c | 12 ++- components/esp_netif/test/test_vfs_l2tap.c | 5 +- components/hal/emac_hal.c | 6 +- components/hal/esp32/include/hal/emac_ll.h | 11 ++- components/hal/include/hal/emac_hal.h | 9 ++- components/hal/include/hal/eth_types.h | 14 +++- components/mqtt/test/test_mqtt_connection.c | 5 +- .../protocol_examples_common/connect.c | 7 +- .../basic/main/ethernet_example_main.c | 7 +- .../enc28j60/main/enc28j60_example_main.c | 1 - .../eth2ap/main/ethernet_example_main.c | 7 +- examples/ethernet/iperf/main/cmd_ethernet.c | 8 +- .../main/simple_sniffer_example_main.c | 7 +- 16 files changed, 125 insertions(+), 105 deletions(-) diff --git a/components/esp_eth/include/esp_eth_mac.h b/components/esp_eth/include/esp_eth_mac.h index 0580ecb442..c054cafcf9 100644 --- a/components/esp_eth/include/esp_eth_mac.h +++ b/components/esp_eth/include/esp_eth_mac.h @@ -357,29 +357,6 @@ typedef union { } rmii; /*!< EMAC RMII Clock Configuration */ } eth_mac_clock_config_t; -/** -* @brief Options of EMAC DMA burst len -*/ -typedef enum { - ETH_DMA_BURST_LEN_32, - ETH_DMA_BURST_LEN_16, - ETH_DMA_BURST_LEN_8, - ETH_DMA_BURST_LEN_4, - ETH_DMA_BURST_LEN_2, - ETH_DMA_BURST_LEN_1, -} eth_mac_dma_burst_len_t; - -/** -* @brief EMAC specific configuration (sub-struct of Ethernet MAC config) -* -*/ -typedef struct { - int smi_mdc_gpio_num; /*!< SMI MDC GPIO number, set to -1 could bypass the SMI GPIO configuration */ - int smi_mdio_gpio_num; /*!< SMI MDIO GPIO number, set to -1 could bypass the SMI GPIO configuration */ - eth_data_interface_t interface; /*!< EMAC Data interface to PHY (MII/RMII) */ - eth_mac_clock_config_t clock_config; /*!< EMAC Interface clock configuration */ - eth_mac_dma_burst_len_t dma_burst_len; /*!< EMAC DMA burst length for both Tx and Rx */ -} eth_esp32_emac_t; /** * @brief Configuration of Ethernet MAC object @@ -390,14 +367,6 @@ typedef struct { uint32_t rx_task_stack_size; /*!< Stack size of the receive task */ uint32_t rx_task_prio; /*!< Priority of the receive task */ uint32_t flags; /*!< Flags that specify extra capability for mac driver */ - union { - eth_esp32_emac_t esp32_emac; /*!< ESP32's internal EMAC configuration */ - // Placeholder for another supported MAC configs - struct eth_custom_mac *p_custom_mac; /*!< Opaque pointer to an additional custom MAC config - * Note: This config could be used for IDF supported MAC - * as well as any additional MAC introduced in user-space - * */ - }; /*!< Union of mutually exclusive vendor specific MAC options */ } eth_mac_config_t; #define ETH_MAC_FLAG_WORK_WITH_CACHE_DISABLE (1 << 0) /*!< MAC driver can work when cache is disabled */ @@ -407,30 +376,47 @@ typedef struct { * @brief Default configuration for Ethernet MAC object * */ - #define ETH_MAC_DEFAULT_CONFIG() \ { \ .sw_reset_timeout_ms = 100, \ .rx_task_stack_size = 2048, \ .rx_task_prio = 15, \ .flags = 0, \ - .esp32_emac = { \ - .smi_mdc_gpio_num = 23, \ - .smi_mdio_gpio_num = 18, \ - .interface = EMAC_DATA_INTERFACE_RMII, \ - .clock_config = \ - { \ - .rmii = \ - { \ - .clock_mode = EMAC_CLK_DEFAULT, \ - .clock_gpio = EMAC_CLK_IN_GPIO \ - } \ - }, \ - .dma_burst_len = ETH_DMA_BURST_LEN_32 \ - } \ } #if CONFIG_ETH_USE_ESP32_EMAC +/** +* @brief EMAC specific configuration +* +*/ +typedef struct { + int smi_mdc_gpio_num; /*!< SMI MDC GPIO number, set to -1 could bypass the SMI GPIO configuration */ + int smi_mdio_gpio_num; /*!< SMI MDIO GPIO number, set to -1 could bypass the SMI GPIO configuration */ + eth_data_interface_t interface; /*!< EMAC Data interface to PHY (MII/RMII) */ + eth_mac_clock_config_t clock_config; /*!< EMAC Interface clock configuration */ + eth_mac_dma_burst_len_t dma_burst_len; /*!< EMAC DMA burst length for both Tx and Rx */ +} eth_esp32_emac_config_t; + +/** + * @brief Default ESP32's EMAC specific configuration + * + */ +#define ETH_ESP32_EMAC_DEFAULT_CONFIG() \ + { \ + .smi_mdc_gpio_num = 23, \ + .smi_mdio_gpio_num = 18, \ + .interface = EMAC_DATA_INTERFACE_RMII, \ + .clock_config = \ + { \ + .rmii = \ + { \ + .clock_mode = EMAC_CLK_DEFAULT, \ + .clock_gpio = EMAC_CLK_IN_GPIO \ + } \ + }, \ + .dma_burst_len = ETH_DMA_BURST_LEN_32 \ + } + /** * @brief Create ESP32 Ethernet MAC instance * @@ -440,7 +426,7 @@ typedef struct { * - instance: create MAC instance successfully * - NULL: create MAC instance failed because some error occurred */ -esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config); +esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_esp32_emac_config_t *esp32_config, const eth_mac_config_t *config); #endif // CONFIG_ETH_USE_ESP32_EMAC #if CONFIG_ETH_SPI_ETHERNET_DM9051 diff --git a/components/esp_eth/src/esp_eth_mac_esp.c b/components/esp_eth/src/esp_eth_mac_esp.c index 94d874d456..12b0a34f78 100644 --- a/components/esp_eth/src/esp_eth_mac_esp.c +++ b/components/esp_eth/src/esp_eth_mac_esp.c @@ -343,14 +343,9 @@ static esp_err_t emac_esp32_init(esp_eth_mac_t *mac) emac_hal_reset_desc_chain(&emac->hal); /* init mac registers by default */ emac_hal_init_mac_default(&emac->hal); - /* init dma registers by default with selected EMAC_RX_DMA_BURST */ - emac_hal_init_dma_default(&emac->hal, - emac->dma_burst_len == ETH_DMA_BURST_LEN_1 ? EMAC_LL_DMA_BURST_LENGTH_1BEAT : - emac->dma_burst_len == ETH_DMA_BURST_LEN_2 ? EMAC_LL_DMA_BURST_LENGTH_2BEAT : - emac->dma_burst_len == ETH_DMA_BURST_LEN_4 ? EMAC_LL_DMA_BURST_LENGTH_4BEAT : - emac->dma_burst_len == ETH_DMA_BURST_LEN_8 ? EMAC_LL_DMA_BURST_LENGTH_8BEAT : - emac->dma_burst_len == ETH_DMA_BURST_LEN_16 ? EMAC_LL_DMA_BURST_LENGTH_16BEAT : - EMAC_LL_DMA_BURST_LENGTH_32BEAT); + /* init dma registers with selected EMAC-DMA configuration */ + emac_hal_dma_config_t dma_config = { .dma_burst_len = emac->dma_burst_len }; + emac_hal_init_dma_default(&emac->hal, &dma_config); /* get emac address from efuse */ ESP_GOTO_ON_ERROR(esp_read_mac(emac->addr, ESP_MAC_ETH), err, TAG, "fetch ethernet mac address failed"); /* set MAC address to emac register */ @@ -469,7 +464,6 @@ static esp_err_t esp_emac_alloc_driver_obj(const eth_mac_config_t *config, emac_ emac = calloc(1, sizeof(emac_esp32_t)); } ESP_GOTO_ON_FALSE(emac, ESP_ERR_NO_MEM, err, TAG, "no mem for esp emac object"); - emac->dma_burst_len = config->esp32_emac.dma_burst_len; /* alloc memory for ethernet dma descriptor */ uint32_t desc_size = CONFIG_ETH_DMA_RX_BUFFER_NUM * sizeof(eth_dma_rx_descriptor_t) + CONFIG_ETH_DMA_TX_BUFFER_NUM * sizeof(eth_dma_tx_descriptor_t); @@ -505,12 +499,12 @@ err: return ret; } -static esp_err_t esp_emac_config_data_interface(const eth_mac_config_t *config, emac_esp32_t *emac) +static esp_err_t esp_emac_config_data_interface(const eth_esp32_emac_config_t *esp32_emac_config, emac_esp32_t *emac) { esp_err_t ret = ESP_OK; - switch (config->esp32_emac.interface) { + switch (esp32_emac_config->interface) { case EMAC_DATA_INTERFACE_MII: - emac->clock_config = config->esp32_emac.clock_config; + emac->clock_config = esp32_emac_config->clock_config; /* MII interface GPIO initialization */ emac_hal_iomux_init_mii(); /* Enable MII clock */ @@ -518,7 +512,7 @@ static esp_err_t esp_emac_config_data_interface(const eth_mac_config_t *config, break; case EMAC_DATA_INTERFACE_RMII: // by default, the clock mode is selected at compile time (by Kconfig) - if (config->esp32_emac.clock_config.rmii.clock_mode == EMAC_CLK_DEFAULT) { + if (esp32_emac_config->clock_config.rmii.clock_mode == EMAC_CLK_DEFAULT) { #if CONFIG_ETH_RMII_CLK_INPUT #if CONFIG_ETH_RMII_CLK_IN_GPIO == 0 emac->clock_config.rmii.clock_mode = EMAC_CLK_EXT_IN; @@ -537,7 +531,7 @@ static esp_err_t esp_emac_config_data_interface(const eth_mac_config_t *config, #error "Unsupported RMII clock mode" #endif } else { - emac->clock_config = config->esp32_emac.clock_config; + emac->clock_config = esp32_emac_config->clock_config; } /* RMII interface GPIO initialization */ emac_hal_iomux_init_rmii(); @@ -567,13 +561,13 @@ static esp_err_t esp_emac_config_data_interface(const eth_mac_config_t *config, } break; default: - ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "invalid EMAC Data Interface:%d", config->esp32_emac.interface); + ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "invalid EMAC Data Interface:%d", esp32_emac_config->interface); } err: return ret; } -esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config) +esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_esp32_emac_config_t *esp32_config, const eth_mac_config_t *config) { esp_err_t ret_code = ESP_OK; esp_eth_mac_t *ret = NULL; @@ -596,12 +590,13 @@ esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config) emac_isr_default_handler, &emac->hal, &(emac->intr_hdl)); } ESP_GOTO_ON_FALSE(ret_code == ESP_OK, NULL, err, TAG, "alloc emac interrupt failed"); - ret_code = esp_emac_config_data_interface(config, emac); + ret_code = esp_emac_config_data_interface(esp32_config, emac); ESP_GOTO_ON_FALSE(ret_code == ESP_OK, NULL, err_interf, TAG, "config emac interface failed"); + emac->dma_burst_len = esp32_config->dma_burst_len; emac->sw_reset_timeout_ms = config->sw_reset_timeout_ms; - emac->smi_mdc_gpio_num = config->esp32_emac.smi_mdc_gpio_num; - emac->smi_mdio_gpio_num = config->esp32_emac.smi_mdio_gpio_num; + emac->smi_mdc_gpio_num = esp32_config->smi_mdc_gpio_num; + emac->smi_mdio_gpio_num = esp32_config->smi_mdio_gpio_num; emac->flow_control_high_water_mark = FLOW_CONTROL_HIGH_WATER_MARK; emac->flow_control_low_water_mark = FLOW_CONTROL_LOW_WATER_MARK; emac->use_apll = false; diff --git a/components/esp_eth/test/test_emac.c b/components/esp_eth/test/test_emac.c index 404a4ab082..6fb053e93a 100644 --- a/components/esp_eth/test/test_emac.c +++ b/components/esp_eth/test/test_emac.c @@ -98,7 +98,8 @@ TEST_CASE("esp32 ethernet io test", "[ethernet][test_env=UT_T2_Ethernet]") { eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); mac_config.flags = ETH_MAC_FLAG_PIN_TO_CORE; // pin to core - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // auto detect PHY address phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO; @@ -132,7 +133,8 @@ TEST_CASE("esp32 ethernet speed/duplex/autonegotiation", "[ethernet][test_env=UT TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, eth_event_group)); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); mac_config.flags = ETH_MAC_FLAG_PIN_TO_CORE; // pin to core - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // auto detect PHY address phy_config.phy_addr = ESP_ETH_PHY_ADDR_AUTO; @@ -311,7 +313,8 @@ TEST_CASE("esp32 ethernet event test", "[ethernet][test_env=UT_T2_Ethernet]") TEST_ESP_OK(esp_event_loop_create_default()); TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, eth_event_group)); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); @@ -351,7 +354,8 @@ TEST_CASE("esp32 ethernet dhcp test", "[ethernet][test_env=UT_T2_Ethernet]") esp_netif_t *eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); @@ -398,7 +402,8 @@ TEST_CASE("esp32 ethernet start/stop stress test", "[ethernet][test_env=UT_T2_Et esp_netif_t *eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); @@ -499,7 +504,8 @@ TEST_CASE("esp32 ethernet download test", "[ethernet][test_env=UT_T2_Ethernet][t esp_netif_t *eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); diff --git a/components/esp_eth/test_apps/main/esp_eth_test.c b/components/esp_eth/test_apps/main/esp_eth_test.c index b934b51b59..e785aad0b4 100644 --- a/components/esp_eth/test_apps/main/esp_eth_test.c +++ b/components/esp_eth/test_apps/main/esp_eth_test.c @@ -48,7 +48,8 @@ TEST_CASE("start_and_stop", "[esp_eth]") TEST_ASSERT(eth_event_group != NULL); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance TEST_ASSERT_NOT_NULL(mac); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration #if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101) @@ -99,7 +100,8 @@ TEST_CASE("get_set_mac", "[esp_eth]") TEST_ASSERT_NOT_NULL(mutex); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance TEST_ASSERT_NOT_NULL(mac); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration #if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101) @@ -152,7 +154,8 @@ TEST_CASE("ethernet_broadcast_transmit", "[esp_eth]") TEST_ASSERT_NOT_NULL(mutex); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance TEST_ASSERT_NOT_NULL(mac); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration #if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101) @@ -222,7 +225,8 @@ TEST_CASE("recv_pkt", "[esp_eth]") TEST_ASSERT(eth_event_group != NULL); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default MAC configuration - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); // create MAC instance + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance TEST_ASSERT_NOT_NULL(mac); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration #if defined(CONFIG_TARGET_ETH_PHY_DEVICE_IP101) diff --git a/components/esp_netif/test/test_vfs_l2tap.c b/components/esp_netif/test/test_vfs_l2tap.c index 85e0b06d4d..61b75e398c 100644 --- a/components/esp_netif/test/test_vfs_l2tap.c +++ b/components/esp_netif/test/test_vfs_l2tap.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -144,7 +144,8 @@ static void ethernet_init(test_vfs_eth_network_t *network_hndls) network_hndls->eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - network_hndls->mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + network_hndls->mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); network_hndls->phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(network_hndls->mac, network_hndls->phy); diff --git a/components/hal/emac_hal.c b/components/hal/emac_hal.c index 8935f6f472..c4619b3b01 100644 --- a/components/hal/emac_hal.c +++ b/components/hal/emac_hal.c @@ -265,7 +265,7 @@ void emac_hal_enable_flow_ctrl(emac_hal_context_t *hal, bool enable) } } -void emac_hal_init_dma_default(emac_hal_context_t *hal, uint32_t dma_burst_len) +void emac_hal_init_dma_default(emac_hal_context_t *hal, emac_hal_dma_config_t *hal_config) { /* DMAOMR Configuration */ /* Enable Dropping of TCP/IP Checksum Error Frames */ @@ -294,10 +294,10 @@ void emac_hal_init_dma_default(emac_hal_context_t *hal, uint32_t dma_burst_len) emac_ll_mixed_burst_enable(hal->dma_regs, true); /* Enable Address Aligned Beates */ emac_ll_addr_align_enable(hal->dma_regs, true); - /* Use Separate PBL */ + /* Don't use Separate PBL */ emac_ll_use_separate_pbl_enable(hal->dma_regs, false); /* Set Rx/Tx DMA Burst Length */ - emac_ll_set_prog_burst_len(hal->dma_regs, dma_burst_len); + emac_ll_set_prog_burst_len(hal->dma_regs, hal_config->dma_burst_len); /* Enable Enhanced Descriptor,8 Words(32 Bytes) */ emac_ll_enhance_desc_enable(hal->dma_regs, true); /* Specifies the number of word to skip between two unchained descriptors (Ring mode) */ diff --git a/components/hal/esp32/include/hal/emac_ll.h b/components/hal/esp32/include/hal/emac_ll.h index bea18961bc..4fdc0e62f5 100644 --- a/components/hal/esp32/include/hal/emac_ll.h +++ b/components/hal/esp32/include/hal/emac_ll.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -468,9 +468,14 @@ static inline void emac_ll_set_rx_dma_pbl(emac_dma_dev_t *dma_regs, uint32_t pbl dma_regs->dmabusmode.rx_dma_pbl = pbl; } -static inline void emac_ll_set_prog_burst_len(emac_dma_dev_t *dma_regs, uint32_t len) +static inline void emac_ll_set_prog_burst_len(emac_dma_dev_t *dma_regs, eth_mac_dma_burst_len_t dma_burst_len) { - dma_regs->dmabusmode.prog_burst_len = len; + dma_regs->dmabusmode.prog_burst_len = dma_burst_len == ETH_DMA_BURST_LEN_1 ? EMAC_LL_DMA_BURST_LENGTH_1BEAT : + dma_burst_len == ETH_DMA_BURST_LEN_2 ? EMAC_LL_DMA_BURST_LENGTH_2BEAT : + dma_burst_len == ETH_DMA_BURST_LEN_4 ? EMAC_LL_DMA_BURST_LENGTH_4BEAT : + dma_burst_len == ETH_DMA_BURST_LEN_8 ? EMAC_LL_DMA_BURST_LENGTH_8BEAT : + dma_burst_len == ETH_DMA_BURST_LEN_16 ? EMAC_LL_DMA_BURST_LENGTH_16BEAT : + EMAC_LL_DMA_BURST_LENGTH_32BEAT; } static inline void emac_ll_enhance_desc_enable(emac_dma_dev_t *dma_regs, bool enable) diff --git a/components/hal/include/hal/emac_hal.h b/components/hal/include/hal/emac_hal.h index 2aebc0fdae..961f2c4ce3 100644 --- a/components/hal/include/hal/emac_hal.h +++ b/components/hal/include/hal/emac_hal.h @@ -164,6 +164,13 @@ typedef struct { } emac_hal_context_t; +/** + * @brief EMAC related configuration + */ +typedef struct { + eth_mac_dma_burst_len_t dma_burst_len; /*!< eth-type enum of chosen dma burst-len */ +} emac_hal_dma_config_t; + void emac_hal_init(emac_hal_context_t *hal, void *descriptors, uint8_t **rx_buf, uint8_t **tx_buf); @@ -189,7 +196,7 @@ void emac_hal_set_csr_clock_range(emac_hal_context_t *hal, int freq); void emac_hal_init_mac_default(emac_hal_context_t *hal); -void emac_hal_init_dma_default(emac_hal_context_t *hal, uint32_t dma_burst_len); +void emac_hal_init_dma_default(emac_hal_context_t *hal, emac_hal_dma_config_t *hal_config); void emac_hal_set_speed(emac_hal_context_t *hal, uint32_t speed); diff --git a/components/hal/include/hal/eth_types.h b/components/hal/include/hal/eth_types.h index d9ce868169..d7d1f2ec4a 100644 --- a/components/hal/include/hal/eth_types.h +++ b/components/hal/include/hal/eth_types.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -49,3 +49,15 @@ typedef enum { ETH_CHECKSUM_SW, /*!< Ethernet checksum calculate by software */ ETH_CHECKSUM_HW /*!< Ethernet checksum calculate by hardware */ } eth_checksum_t; + +/** +* @brief Internal ethernet EMAC's DMA available burst sizes +*/ +typedef enum { + ETH_DMA_BURST_LEN_32, + ETH_DMA_BURST_LEN_16, + ETH_DMA_BURST_LEN_8, + ETH_DMA_BURST_LEN_4, + ETH_DMA_BURST_LEN_2, + ETH_DMA_BURST_LEN_1, +} eth_mac_dma_burst_len_t; diff --git a/components/mqtt/test/test_mqtt_connection.c b/components/mqtt/test/test_mqtt_connection.c index bf3f09ab4a..6598b985c9 100644 --- a/components/mqtt/test/test_mqtt_connection.c +++ b/components/mqtt/test/test_mqtt_connection.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -100,7 +100,8 @@ void connect_test_fixture_setup(void) s_eth_netif = esp_netif_new(&netif_cfg); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - s_mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + s_mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); s_phy = esp_eth_phy_new_ip101(&phy_config); esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(s_mac, s_phy); diff --git a/examples/common_components/protocol_examples_common/connect.c b/examples/common_components/protocol_examples_common/connect.c index fb357dea66..c54deae670 100644 --- a/examples/common_components/protocol_examples_common/connect.c +++ b/examples/common_components/protocol_examples_common/connect.c @@ -379,9 +379,10 @@ static esp_netif_t *eth_start(void) phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; #if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET - mac_config.esp32_emac.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; - mac_config.esp32_emac.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; - s_mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; + s_mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_EXAMPLE_ETH_PHY_IP101 s_phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_RTL8201 diff --git a/examples/ethernet/basic/main/ethernet_example_main.c b/examples/ethernet/basic/main/ethernet_example_main.c index f1f20e3b18..3698fe7f0a 100644 --- a/examples/ethernet/basic/main/ethernet_example_main.c +++ b/examples/ethernet/basic/main/ethernet_example_main.c @@ -101,9 +101,10 @@ void app_main(void) phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; - mac_config.esp32_emac.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; - mac_config.esp32_emac.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_EXAMPLE_ETH_PHY_IP101 esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_RTL8201 diff --git a/examples/ethernet/enc28j60/main/enc28j60_example_main.c b/examples/ethernet/enc28j60/main/enc28j60_example_main.c index 05599b1c6f..fa28770d18 100644 --- a/examples/ethernet/enc28j60/main/enc28j60_example_main.c +++ b/examples/ethernet/enc28j60/main/enc28j60_example_main.c @@ -101,7 +101,6 @@ void app_main(void) enc28j60_config.int_gpio_num = CONFIG_EXAMPLE_ENC28J60_INT_GPIO; eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - mac_config.p_custom_mac = NULL; // ENC28J60 MAC doesn't use any specific config esp_eth_mac_t *mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); diff --git a/examples/ethernet/eth2ap/main/ethernet_example_main.c b/examples/ethernet/eth2ap/main/ethernet_example_main.c index 9a72ea9609..4f11e4591b 100644 --- a/examples/ethernet/eth2ap/main/ethernet_example_main.c +++ b/examples/ethernet/eth2ap/main/ethernet_example_main.c @@ -158,9 +158,10 @@ static void initialize_ethernet(void) phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; #if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET - mac_config.esp32_emac.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; - mac_config.esp32_emac.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_EXAMPLE_ETH_PHY_IP101 esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_RTL8201 diff --git a/examples/ethernet/iperf/main/cmd_ethernet.c b/examples/ethernet/iperf/main/cmd_ethernet.c index 0e2a82e9ce..e9999eda69 100644 --- a/examples/ethernet/iperf/main/cmd_ethernet.c +++ b/examples/ethernet/iperf/main/cmd_ethernet.c @@ -208,9 +208,10 @@ void register_ethernet(void) phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; #if CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET - mac_config.esp32_emac.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; - mac_config.esp32_emac.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_EXAMPLE_ETH_PHY_IP101 esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_EXAMPLE_ETH_PHY_RTL8201 @@ -293,7 +294,6 @@ void register_ethernet(void) eth_enc28j60_config_t enc28j60_config = ETH_ENC28J60_DEFAULT_CONFIG(spi_handle); enc28j60_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO; - mac_config.p_custom_mac = NULL; // ENC28J60 MAC doesn't use any specific config esp_eth_mac_t *mac = esp_eth_mac_new_enc28j60(&enc28j60_config, &mac_config); phy_config.autonego_timeout_ms = 0; // ENC28J60 doesn't support auto-negotiation diff --git a/examples/network/simple_sniffer/main/simple_sniffer_example_main.c b/examples/network/simple_sniffer/main/simple_sniffer_example_main.c index 935baa3397..107cd60d0b 100644 --- a/examples/network/simple_sniffer/main/simple_sniffer_example_main.c +++ b/examples/network/simple_sniffer/main/simple_sniffer_example_main.c @@ -135,9 +135,10 @@ static void initialize_eth(void) phy_config.phy_addr = CONFIG_SNIFFER_ETH_PHY_ADDR; phy_config.reset_gpio_num = CONFIG_SNIFFER_ETH_PHY_RST_GPIO; #if CONFIG_SNIFFER_USE_INTERNAL_ETHERNET - mac_config.esp32_emac.smi_mdc_gpio_num = CONFIG_SNIFFER_ETH_MDC_GPIO; - mac_config.esp32_emac.smi_mdio_gpio_num = CONFIG_SNIFFER_ETH_MDIO_GPIO; - esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config); + eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); + esp32_emac_config.smi_mdc_gpio_num = CONFIG_SNIFFER_ETH_MDC_GPIO; + esp32_emac_config.smi_mdio_gpio_num = CONFIG_SNIFFER_ETH_MDIO_GPIO; + esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); #if CONFIG_SNIFFER_ETH_PHY_IP101 esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); #elif CONFIG_SNIFFER_ETH_PHY_RTL8201