esp_eth.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_ETH_H__
  14. #define __ESP_ETH_H__
  15. #include <stdint.h>
  16. #include "esp_err.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef void (*eth_phy_fun)(void);
  21. typedef esp_err_t (*eth_tcpip_input_fun)(void *buffer, uint16_t len, void *eb);
  22. typedef void (*eth_gpio_config_func)(void);
  23. typedef enum {
  24. ETH_MODE_RMII = 0,
  25. ETH_MDOE_MII,
  26. } eth_mode_t;
  27. typedef enum {
  28. PHY0 = 0,
  29. PHY1,
  30. PHY2,
  31. PHY3,
  32. PHY4,
  33. PHY5,
  34. PHY6,
  35. PHY7,
  36. PHY8,
  37. PHY9,
  38. PHY10,
  39. PHY11,
  40. PHY12,
  41. PHY13,
  42. PHY14,
  43. PHY15,
  44. PHY16,
  45. PHY17,
  46. PHY18,
  47. PHY19,
  48. PHY20,
  49. PHY21,
  50. PHY22,
  51. PHY23,
  52. PHY24,
  53. PHY25,
  54. PHY26,
  55. PHY27,
  56. PHY28,
  57. PHY29,
  58. PHY30,
  59. PHY31,
  60. } eth_phy_base_t;
  61. /**
  62. * @brief ethernet configuration
  63. *
  64. */
  65. typedef struct {
  66. eth_phy_base_t phy_addr; /*!< phy base addr (0~31) */
  67. eth_mode_t mac_mode; /*!< mac mode only support RMII now */
  68. eth_tcpip_input_fun tcpip_input; /*!< tcpip input func */
  69. eth_phy_fun phy_init; /*!< phy init func */
  70. eth_gpio_config_func gpio_config; /*!< gpio config func */
  71. } eth_config_t;
  72. /**
  73. * @brief Init ethernet mac
  74. *
  75. * @note config can not be NULL,and phy chip must be suitable to phy init func.
  76. *
  77. * @param[in] config mac init data.
  78. *
  79. * @return
  80. * - ESP_OK
  81. * - ESP_FAIL
  82. */
  83. esp_err_t esp_eth_init(eth_config_t *config);
  84. /**
  85. * @brief Send packet from tcp/ip to mac
  86. *
  87. * @note buf can not be NULL,size must be less than 1580
  88. *
  89. * @param[in] buf: start address of packet data.
  90. *
  91. * @param[in] size: size (byte) of packet data.
  92. *
  93. * @return
  94. * - ESP_OK
  95. * - ESP_FAIL
  96. */
  97. esp_err_t esp_eth_tx(uint8_t *buf, uint16_t size);
  98. /**
  99. * @brief Enable ethernet interface
  100. *
  101. * @note Shout be called after esp_eth_init
  102. *
  103. * @return
  104. * - ESP_OK
  105. * - ESP_FAIL
  106. */
  107. esp_err_t esp_eth_enable(void);
  108. /**
  109. * @brief Disable ethernet interface
  110. *
  111. * @note Shout be called after esp_eth_init
  112. *
  113. * @return
  114. * - ESP_OK
  115. * - ESP_FAIL
  116. */
  117. esp_err_t esp_eth_disable(void);
  118. /**
  119. * @brief Get mac addr
  120. *
  121. * @note mac addr must be a valid unicast address
  122. *
  123. * @param[out] mac: start address of mac address.
  124. */
  125. void esp_eth_get_mac(uint8_t mac[6]);
  126. /**
  127. * @brief Read phy reg with smi interface.
  128. *
  129. * @note phy base addr must be right.
  130. *
  131. * @param[in] reg_num: phy reg num.
  132. *
  133. * @param[in] value: value which write to phy reg.
  134. */
  135. void esp_eth_smi_write(uint32_t reg_num, uint16_t value);
  136. /**
  137. * @brief Write phy reg with smi interface.
  138. *
  139. * @note phy base addr must be right.
  140. *
  141. * @param[in] reg_num: phy reg num.
  142. *
  143. * @return value what read from phy reg
  144. */
  145. uint16_t esp_eth_smi_read(uint32_t reg_num);
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif