mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ethernet: update spi-ethernet api
This commit is contained in:
parent
ebffa5f9f2
commit
dda49709fe
@ -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
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user