diff --git a/components/esp_eth/include/esp_eth_mac.h b/components/esp_eth/include/esp_eth_mac.h index 47d3678fa..7262bb0b2 100644 --- a/components/esp_eth/include/esp_eth_mac.h +++ b/components/esp_eth/include/esp_eth_mac.h @@ -279,6 +279,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 f02f8b965..6a1c003ae 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 "hal/cpu_hal.h" #include "dm9051.h" #include "sdkconfig.h" @@ -754,8 +755,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 = cpu_hal_get_core_id(); + } + 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 9a68bc1cc..e06e885d7 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 "hal/cpu_hal.h" #include "hal/emac.h" #include "soc/soc.h" #include "sdkconfig.h" @@ -455,8 +456,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 = cpu_hal_get_core_id(); + } + 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/src/esp_eth_mac_openeth.c b/components/esp_eth/src/esp_eth_mac_openeth.c index c28ca1cbd..e2f650691 100644 --- a/components/esp_eth/src/esp_eth_mac_openeth.c +++ b/components/esp_eth/src/esp_eth_mac_openeth.c @@ -31,6 +31,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" +#include "hal/cpu_hal.h" #include "openeth.h" static const char *TAG = "emac_opencores"; @@ -398,8 +399,12 @@ esp_eth_mac_t *esp_eth_mac_new_openeth(const eth_mac_config_t *config) "alloc emac interrupt failed", out, NULL); // Create the RX task - BaseType_t xReturned = xTaskCreate(emac_opencores_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 = cpu_hal_get_core_id(); + } + BaseType_t xReturned = xTaskCreatePinnedToCore(emac_opencores_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", out, NULL); return &(emac->parent); diff --git a/components/esp_eth/test/test_emac.c b/components/esp_eth/test/test_emac.c index 2771cc01d..a07114085 100644 --- a/components/esp_eth/test/test_emac.c +++ b/components/esp_eth/test/test_emac.c @@ -141,6 +141,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(); // auto detect PHY address diff --git a/examples/ethernet/enc28j60/main/esp_eth_mac_enc28j60.c b/examples/ethernet/enc28j60/main/esp_eth_mac_enc28j60.c index 361bc91f2..b8f21f3a9 100644 --- a/examples/ethernet/enc28j60/main/esp_eth_mac_enc28j60.c +++ b/examples/ethernet/enc28j60/main/esp_eth_mac_enc28j60.c @@ -24,6 +24,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" +#include "hal/cpu_hal.h" #include "enc28j60.h" #include "sdkconfig.h" @@ -919,8 +920,12 @@ esp_eth_mac_t *esp_eth_mac_new_enc28j60(const eth_enc28j60_config_t *enc28j60_co emac->spi_lock = xSemaphoreCreateMutex(); MAC_CHECK(emac->spi_lock, "create lock failed", err, NULL); /* create enc28j60 task */ - BaseType_t xReturned = xTaskCreate(emac_enc28j60_task, "enc28j60_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 = cpu_hal_get_core_id(); + } + BaseType_t xReturned = xTaskCreatePinnedToCore(emac_enc28j60_task, "enc28j60_tsk", mac_config->rx_task_stack_size, emac, + mac_config->rx_task_prio, &emac->rx_task_hdl, core_num); MAC_CHECK(xReturned == pdPASS, "create enc28j60 task failed", err, NULL); return &(emac->parent);