2
0

network_driver_DM9051.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "esp_eth.h"
  2. #include "network_ethernet.h"
  3. static EXT_RAM_ATTR network_ethernet_driver_t DM9051;
  4. static EXT_RAM_ATTR spi_device_interface_config_t devcfg;
  5. static EXT_RAM_ATTR esp_netif_config_t cfg_spi;
  6. static EXT_RAM_ATTR esp_netif_inherent_config_t esp_netif_config;
  7. static esp_err_t start(spi_device_handle_t spi_handle, eth_config_t* ethernet_config) {
  8. #ifdef CONFIG_ETH_SPI_ETHERNET_DM9051
  9. eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
  10. eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
  11. eth_dm9051_config_t eth_config = ETH_DM9051_DEFAULT_CONFIG(spi_handle);
  12. // we assume that isr has been installed already
  13. eth_config.int_gpio_num = ethernet_config->intr;
  14. phy_config.phy_addr = -1;
  15. phy_config.reset_gpio_num = ethernet_config->rst;
  16. esp_eth_mac_t* mac = esp_eth_mac_new_dm9051(&eth_config, &mac_config);
  17. esp_eth_phy_t* phy = esp_eth_phy_new_dm9051(&phy_config);
  18. esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
  19. return esp_eth_driver_install(&config, &DM9051.handle);
  20. #else
  21. return ESP_ERR_NOT_SUPPORTED;
  22. #endif
  23. }
  24. static void init_config(eth_config_t* ethernet_config) {
  25. esp_netif_inherent_config_t loc_esp_netif_config = ESP_NETIF_INHERENT_DEFAULT_ETH();
  26. devcfg.command_bits = 1;
  27. devcfg.address_bits = 7;
  28. devcfg.mode = 0;
  29. devcfg.clock_speed_hz = ethernet_config->speed > 0 ? ethernet_config->speed : SPI_MASTER_FREQ_20M; // default speed
  30. devcfg.queue_size = 20;
  31. devcfg.spics_io_num = ethernet_config->cs;
  32. memcpy(&esp_netif_config, &loc_esp_netif_config, sizeof(loc_esp_netif_config));
  33. cfg_spi.base = &esp_netif_config,
  34. cfg_spi.stack = ESP_NETIF_NETSTACK_DEFAULT_ETH;
  35. DM9051.cfg_netif = &cfg_spi;
  36. DM9051.devcfg = &devcfg;
  37. DM9051.start = start;
  38. }
  39. network_ethernet_driver_t* DM9051_Detect(char* Driver) {
  40. if (!strcasestr(Driver, "DM9051"))
  41. return NULL;
  42. DM9051.rmii = false;
  43. DM9051.spi = true;
  44. #ifdef CONFIG_ETH_SPI_ETHERNET_DM9051
  45. DM9051.valid = true;
  46. #else
  47. DM9051.valid = false;
  48. #endif
  49. DM9051.init_config = init_config;
  50. return &DM9051;
  51. }