From ebffa5f9f2039f5ead1a7feeab4ffde53760a197 Mon Sep 17 00:00:00 2001 From: suda-morris <362953310@qq.com> Date: Wed, 18 Sep 2019 18:28:18 +0800 Subject: [PATCH 1/2] ethernet: test apps can build with ethernet disabled --- tools/ci/test_build_system_cmake.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index bbe299b92..d4117384b 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -362,6 +362,19 @@ function run_tests() rm sdkconfig; rm sdkconfig.defaults; + print_status "can build with ethernet component disabled" + idf.py clean > /dev/null; + idf.py fullclean > /dev/null; + rm -f sdkconfig.defaults; + rm -f sdkconfig; + echo "CONFIG_ETH_USE_SPI_ETHERNET=" >> sdkconfig.defaults; + echo "CONFIG_ETH_USE_ESP32_EMAC=" >> sdkconfig.defaults; + idf.py reconfigure > /dev/null; + idf.py build || failure "Failed to build with ethernet component disabled" + assert_built ${APP_BINS} ${BOOTLOADER_BINS} ${PARTITION_BIN} + rm sdkconfig; + rm sdkconfig.defaults; + print_status "Building a project with CMake library imported and PSRAM workaround, all files compile with workaround" # Test for libraries compiled within ESP-IDF rm -rf build From dda49709fec61ea585cea2eba725147b2ad2bb1d Mon Sep 17 00:00:00 2001 From: suda-morris <362953310@qq.com> Date: Wed, 18 Sep 2019 18:28:55 +0800 Subject: [PATCH 2/2] ethernet: update spi-ethernet api --- components/esp_eth/include/esp_eth_mac.h | 28 +++++++++++++------ components/esp_eth/src/esp_eth_mac_dm9051.c | 14 +++++----- components/esp_eth/test/test_emac.c | 4 +-- .../protocol_examples_common/connect.c | 6 ++-- .../basic/main/ethernet_example_main.c | 6 ++-- .../eth2ap/main/ethernet_example_main.c | 6 ++-- examples/ethernet/iperf/main/cmd_ethernet.c | 6 ++-- 7 files changed, 41 insertions(+), 29 deletions(-) diff --git a/components/esp_eth/include/esp_eth_mac.h b/components/esp_eth/include/esp_eth_mac.h index 07507cefe..c189acb28 100644 --- a/components/esp_eth/include/esp_eth_mac.h +++ b/components/esp_eth/include/esp_eth_mac.h @@ -247,11 +247,6 @@ typedef struct { uint32_t sw_reset_timeout_ms; /*!< Software reset timeout value (Unit: ms) */ uint32_t rx_task_stack_size; /*!< Stack size of the receive task */ uint32_t rx_task_prio; /*!< Priority of the receive task */ - uint32_t queue_len; /*!< Length of the transaction queue */ -#if CONFIG_ETH_USE_SPI_ETHERNET - spi_device_handle_t spi_hdl; /*!< Handle of spi device */ -#endif - } eth_mac_config_t; /** @@ -263,7 +258,6 @@ typedef struct { .sw_reset_timeout_ms = 100, \ .rx_task_stack_size = 4096, \ .rx_task_prio = 15, \ - .queue_len = 100, \ } #if CONFIG_ETH_USE_ESP32_EMAC @@ -280,16 +274,34 @@ esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config); #endif #if CONFIG_ETH_SPI_ETHERNET_DM9051 +/** + * @brief DM9051 specific configuration + * + */ +typedef struct { + spi_device_handle_t spi_hdl; /*!< Handle of SPI device driver */ +} eth_dm9051_config_t; + +/** + * @brief Default DM9051 specific configuration + * + */ +#define ETH_DM9051_DEFAULT_CONFIG(spi_device) \ + { \ + .spi_hdl = spi_device, \ + } + /** * @brief Create DM9051 Ethernet MAC instance * -* @param config: Ethernet MAC configuration +* @param dm9051_config: DM9051 specific configuration +* @param mac_config: Ethernet MAC configuration * * @return * - instance: create MAC instance successfully * - NULL: create MAC instance failed because some error occurred */ -esp_eth_mac_t *esp_eth_mac_new_dm9051(const eth_mac_config_t *config); +esp_eth_mac_t *esp_eth_mac_new_dm9051(const eth_dm9051_config_t *dm9051_config, const eth_mac_config_t *mac_config); #endif #ifdef __cplusplus } diff --git a/components/esp_eth/src/esp_eth_mac_dm9051.c b/components/esp_eth/src/esp_eth_mac_dm9051.c index b2878cb13..c87f3e9ca 100644 --- a/components/esp_eth/src/esp_eth_mac_dm9051.c +++ b/components/esp_eth/src/esp_eth_mac_dm9051.c @@ -815,16 +815,16 @@ static esp_err_t emac_dm9051_del(esp_eth_mac_t *mac) return ESP_OK; } -esp_eth_mac_t *esp_eth_mac_new_dm9051(const eth_mac_config_t *config) +esp_eth_mac_t *esp_eth_mac_new_dm9051(const eth_dm9051_config_t *dm9051_config, const eth_mac_config_t *mac_config) { esp_eth_mac_t *ret = NULL; - MAC_CHECK(config, "can't set mac config to null", err, NULL); - MAC_CHECK(config->spi_hdl, "can't set spi handle to null", err, NULL); + MAC_CHECK(dm9051_config, "can't set dm9051 specific config to null", err, NULL); + MAC_CHECK(mac_config, "can't set mac config to null", err, NULL); emac_dm9051_t *emac = calloc(1, sizeof(emac_dm9051_t)); MAC_CHECK(emac, "calloc emac failed", err, NULL); /* bind methods and attributes */ - emac->sw_reset_timeout_ms = config->sw_reset_timeout_ms; - emac->spi_hdl = config->spi_hdl; + emac->sw_reset_timeout_ms = mac_config->sw_reset_timeout_ms; + emac->spi_hdl = dm9051_config->spi_hdl; emac->parent.set_mediator = emac_dm9051_set_mediator; emac->parent.init = emac_dm9051_init; emac->parent.deinit = emac_dm9051_deinit; @@ -843,8 +843,8 @@ esp_eth_mac_t *esp_eth_mac_new_dm9051(const eth_mac_config_t *config) emac->spi_lock = xSemaphoreCreateMutex(); MAC_CHECK(emac->spi_lock, "create lock failed", err_lock, NULL); /* create dm9051 task */ - BaseType_t xReturned = xTaskCreate(emac_dm9051_task, "dm9051_tsk", config->rx_task_stack_size, emac, - config->rx_task_prio, &emac->rx_task_hdl); + BaseType_t xReturned = xTaskCreate(emac_dm9051_task, "dm9051_tsk", mac_config->rx_task_stack_size, emac, + mac_config->rx_task_prio, &emac->rx_task_hdl); MAC_CHECK(xReturned == pdPASS, "create dm9051 task failed", err_tsk, NULL); return &(emac->parent); err_tsk: diff --git a/components/esp_eth/test/test_emac.c b/components/esp_eth/test/test_emac.c index 2ebe98b02..d38c3ac9c 100644 --- a/components/esp_eth/test/test_emac.c +++ b/components/esp_eth/test/test_emac.c @@ -119,8 +119,8 @@ TEST_CASE("dm9051 io test", "[ethernet][ignore]") TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, NULL)); TEST_ESP_OK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL)); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - mac_config.spi_hdl = spi_handle; - esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&mac_config); + eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle); + esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config); esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy); diff --git a/examples/common_components/protocol_examples_common/connect.c b/examples/common_components/protocol_examples_common/connect.c index 68895905a..27cc8fe2b 100644 --- a/examples/common_components/protocol_examples_common/connect.c +++ b/examples/common_components/protocol_examples_common/connect.c @@ -219,9 +219,9 @@ static void start() .queue_size = 20 }; ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle)); - /* dm9051 ethernet driver is based on spi driver, so need to specify the spi handle */ - mac_config.spi_hdl = spi_handle; - s_mac = esp_eth_mac_new_dm9051(&mac_config); + /* dm9051 ethernet driver is based on spi driver */ + eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle); + s_mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); s_phy = esp_eth_phy_new_dm9051(&phy_config); #endif esp_eth_config_t config = ETH_DEFAULT_CONFIG(s_mac, s_phy); diff --git a/examples/ethernet/basic/main/ethernet_example_main.c b/examples/ethernet/basic/main/ethernet_example_main.c index ed794a32b..e387283fa 100644 --- a/examples/ethernet/basic/main/ethernet_example_main.c +++ b/examples/ethernet/basic/main/ethernet_example_main.c @@ -104,9 +104,9 @@ void app_main() .queue_size = 20 }; ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle)); - /* dm9051 ethernet driver is based on spi driver, so need to specify the spi handle */ - mac_config.spi_hdl = spi_handle; - esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&mac_config); + /* dm9051 ethernet driver is based on spi driver */ + eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle); + esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config); #endif esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy); diff --git a/examples/ethernet/eth2ap/main/ethernet_example_main.c b/examples/ethernet/eth2ap/main/ethernet_example_main.c index 4796cd9a1..99afe94f8 100644 --- a/examples/ethernet/eth2ap/main/ethernet_example_main.c +++ b/examples/ethernet/eth2ap/main/ethernet_example_main.c @@ -177,9 +177,9 @@ static void initialize_ethernet(void) .queue_size = 20 }; ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle)); - /* dm9051 ethernet driver is based on spi driver, so need to specify the spi handle */ - mac_config.spi_hdl = spi_handle; - esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&mac_config); + /* dm9051 ethernet driver is based on spi driver */ + eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle); + esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config); #endif esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy); diff --git a/examples/ethernet/iperf/main/cmd_ethernet.c b/examples/ethernet/iperf/main/cmd_ethernet.c index 832d049b0..15f0d0e9f 100644 --- a/examples/ethernet/iperf/main/cmd_ethernet.c +++ b/examples/ethernet/iperf/main/cmd_ethernet.c @@ -215,9 +215,9 @@ void register_ethernet() .queue_size = 20 }; ESP_ERROR_CHECK(spi_bus_add_device(CONFIG_EXAMPLE_ETH_SPI_HOST, &devcfg, &spi_handle)); - /* dm9051 ethernet driver is based on spi driver, so need to specify the spi handle */ - mac_config.spi_hdl = spi_handle; - esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&mac_config); + /* dm9051 ethernet driver is based on spi driver */ + eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle); + esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config); #endif esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);