From d96d68ea38fa795dac7fae171f30af503bdac588 Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 27 May 2020 18:55:38 +0800 Subject: [PATCH] ethernet: support pin emac task to core --- components/esp_eth/include/esp_eth_mac.h | 1 + components/esp_eth/src/esp_eth_mac_dm9051.c | 9 +++++++-- components/esp_eth/src/esp_eth_mac_esp32.c | 9 +++++++-- components/esp_eth/test/test_emac.c | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/components/esp_eth/include/esp_eth_mac.h b/components/esp_eth/include/esp_eth_mac.h index db65eb723..5f3c8975e 100644 --- a/components/esp_eth/include/esp_eth_mac.h +++ b/components/esp_eth/include/esp_eth_mac.h @@ -275,6 +275,7 @@ typedef struct { } eth_mac_config_t; #define ETH_MAC_FLAG_WORK_WITH_CACHE_DISABLE (1 << 0) /*!< MAC driver can work when cache is disabled */ +#define ETH_MAC_FLAG_PIN_TO_CORE (1 << 1) /*!< Pin MAC task to the CPU core where driver installation happened */ /** * @brief Default configuration for Ethernet MAC object diff --git a/components/esp_eth/src/esp_eth_mac_dm9051.c b/components/esp_eth/src/esp_eth_mac_dm9051.c index 0a37aa5ab..e535d53bd 100644 --- a/components/esp_eth/src/esp_eth_mac_dm9051.c +++ b/components/esp_eth/src/esp_eth_mac_dm9051.c @@ -25,6 +25,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" +#include "freertos/portable.h" #include "dm9051.h" #include "sdkconfig.h" @@ -750,8 +751,12 @@ esp_eth_mac_t *esp_eth_mac_new_dm9051(const eth_dm9051_config_t *dm9051_config, emac->spi_lock = xSemaphoreCreateMutex(); MAC_CHECK(emac->spi_lock, "create lock failed", err, NULL); /* create dm9051 task */ - 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); + BaseType_t core_num = tskNO_AFFINITY; + if (mac_config->flags & ETH_MAC_FLAG_PIN_TO_CORE) { + core_num = xPortGetCoreID(); + } + BaseType_t xReturned = xTaskCreatePinnedToCore(emac_dm9051_task, "dm9051_tsk", mac_config->rx_task_stack_size, emac, + mac_config->rx_task_prio, &emac->rx_task_hdl, core_num); MAC_CHECK(xReturned == pdPASS, "create dm9051 task failed", err, NULL); return &(emac->parent); diff --git a/components/esp_eth/src/esp_eth_mac_esp32.c b/components/esp_eth/src/esp_eth_mac_esp32.c index 778ca422b..ac13d135e 100644 --- a/components/esp_eth/src/esp_eth_mac_esp32.c +++ b/components/esp_eth/src/esp_eth_mac_esp32.c @@ -26,6 +26,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" +#include "freertos/portable.h" #include "hal/emac.h" #include "soc/soc.h" #include "sdkconfig.h" @@ -451,8 +452,12 @@ esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_mac_config_t *config) "create pm lock failed", err, NULL); #endif /* create rx task */ - BaseType_t xReturned = xTaskCreate(emac_esp32_rx_task, "emac_rx", config->rx_task_stack_size, emac, - config->rx_task_prio, &emac->rx_task_hdl); + BaseType_t core_num = tskNO_AFFINITY; + if (config->flags & ETH_MAC_FLAG_PIN_TO_CORE) { + core_num = xPortGetCoreID(); + } + BaseType_t xReturned = xTaskCreatePinnedToCore(emac_esp32_rx_task, "emac_rx", config->rx_task_stack_size, emac, + config->rx_task_prio, &emac->rx_task_hdl, core_num); MAC_CHECK(xReturned == pdPASS, "create emac_rx task failed", err, NULL); return &(emac->parent); diff --git a/components/esp_eth/test/test_emac.c b/components/esp_eth/test/test_emac.c index fae610a69..a96e23818 100644 --- a/components/esp_eth/test/test_emac.c +++ b/components/esp_eth/test/test_emac.c @@ -88,6 +88,7 @@ static esp_err_t test_uninstall_driver(esp_eth_handle_t eth_hdl, uint32_t ms_to_ 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_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config);