Procházet zdrojové kódy

Merge branch 'refactor/update_spi_ethernet_api' into 'master'

ethernet: update spi ethernet api

See merge request espressif/esp-idf!6123
Angus Gratton před 6 roky
rodič
revize
a68b400b9a

+ 20 - 8
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
 }

+ 7 - 7
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:

+ 2 - 2
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, &eth_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);

+ 3 - 3
examples/common_components/protocol_examples_common/connect.c

@@ -219,9 +219,9 @@ static void start(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;
-    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);

+ 3 - 3
examples/ethernet/basic/main/ethernet_example_main.c

@@ -104,9 +104,9 @@ void app_main(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);

+ 3 - 3
examples/ethernet/eth2ap/main/ethernet_example_main.c

@@ -176,9 +176,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);

+ 3 - 3
examples/ethernet/iperf/main/cmd_ethernet.c

@@ -215,9 +215,9 @@ void register_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);

+ 15 - 2
tools/ci/test_build_system_cmake.sh

@@ -371,6 +371,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
@@ -517,10 +530,10 @@ endmenu\n" >> ${IDF_PATH}/Kconfig;
     rm -rf CMakeLists.txt
     mv CMakeLists.txt.bak CMakeLists.txt
     rm -rf CMakeLists.txt.bak
-    
+
     print_status "Print all required argument deprecation warnings"
     idf.py -C${IDF_PATH}/tools/test_idf_py --test-0=a --test-1=b --test-2=c --test-3=d test-0 --test-sub-0=sa --test-sub-1=sb ta test-1 > out.txt
-    ! grep -e '"test-0" is deprecated' -e '"test_0" is deprecated' out.txt || failure "Deprecation warnings are displayed for non-deprecated option/command"       
+    ! grep -e '"test-0" is deprecated' -e '"test_0" is deprecated' out.txt || failure "Deprecation warnings are displayed for non-deprecated option/command"
     grep -e 'Warning: Option "test_sub_1" is deprecated and will be removed in future versions.' \
         -e 'Warning: Command "test-1" is deprecated and will be removed in future versions. Please use alternative command.' \
         -e 'Warning: Option "test_1" is deprecated and will be removed in future versions.' \