esp_eth.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 enum {
  21. ETH_MODE_RMII = 0,
  22. ETH_MDOE_MII,
  23. } eth_mode_t;
  24. typedef enum {
  25. ETH_SPEED_MODE_10M = 0,
  26. ETH_SPEED_MODE_100M,
  27. } eth_speed_mode_t;
  28. typedef enum {
  29. ETH_MODE_HALFDUPLEX = 0,
  30. ETH_MDOE_FULLDUPLEX,
  31. } eth_duplex_mode_t;
  32. typedef enum {
  33. PHY0 = 0,
  34. PHY1,
  35. PHY2,
  36. PHY3,
  37. PHY4,
  38. PHY5,
  39. PHY6,
  40. PHY7,
  41. PHY8,
  42. PHY9,
  43. PHY10,
  44. PHY11,
  45. PHY12,
  46. PHY13,
  47. PHY14,
  48. PHY15,
  49. PHY16,
  50. PHY17,
  51. PHY18,
  52. PHY19,
  53. PHY20,
  54. PHY21,
  55. PHY22,
  56. PHY23,
  57. PHY24,
  58. PHY25,
  59. PHY26,
  60. PHY27,
  61. PHY28,
  62. PHY29,
  63. PHY30,
  64. PHY31,
  65. } eth_phy_base_t;
  66. typedef bool (*eth_phy_check_link_func)(void);
  67. typedef void (*eth_phy_check_init_func)(void);
  68. typedef eth_speed_mode_t (*eth_phy_get_speed_mode_func)(void);
  69. typedef eth_duplex_mode_t (*eth_phy_get_duplex_mode_func)(void);
  70. typedef void (*eth_phy_func)(void);
  71. typedef esp_err_t (*eth_tcpip_input_func)(void *buffer, uint16_t len, void *eb);
  72. typedef void (*eth_gpio_config_func)(void);
  73. typedef bool (*eth_phy_get_partner_pause_enable_func)(void);
  74. typedef void (*eth_phy_power_enable_func)(bool enable);
  75. /**
  76. * @brief ethernet configuration
  77. *
  78. */
  79. typedef struct {
  80. eth_phy_base_t phy_addr; /*!< phy base addr (0~31) */
  81. eth_mode_t mac_mode; /*!< mac mode only support RMII now */
  82. eth_tcpip_input_func tcpip_input; /*!< tcpip input func */
  83. eth_phy_func phy_init; /*!< phy init func */
  84. eth_phy_check_link_func phy_check_link; /*!< phy check link func */
  85. eth_phy_check_init_func phy_check_init; /*!< phy check init func */
  86. eth_phy_get_speed_mode_func phy_get_speed_mode; /*!< phy check init func */
  87. eth_phy_get_duplex_mode_func phy_get_duplex_mode; /*!< phy check init func */
  88. eth_gpio_config_func gpio_config; /*!< gpio config func */
  89. bool flow_ctrl_enable; /*!< flag of flow ctrl enable */
  90. eth_phy_get_partner_pause_enable_func phy_get_partner_pause_enable; /*!< get partner pause enable */
  91. eth_phy_power_enable_func phy_power_enable; /*!< enable or disable phy power */
  92. } eth_config_t;
  93. /**
  94. * @brief Init ethernet mac
  95. *
  96. * @note config can not be NULL,and phy chip must be suitable to phy init func.
  97. *
  98. * @param[in] config mac init data.
  99. *
  100. * @return
  101. * - ESP_OK
  102. * - ESP_FAIL
  103. */
  104. esp_err_t esp_eth_init(eth_config_t *config);
  105. /**
  106. * @brief Send packet from tcp/ip to mac
  107. *
  108. * @note buf can not be NULL,size must be less than 1580
  109. *
  110. * @param[in] buf: start address of packet data.
  111. *
  112. * @param[in] size: size (byte) of packet data.
  113. *
  114. * @return
  115. * - ESP_OK
  116. * - ESP_FAIL
  117. */
  118. esp_err_t esp_eth_tx(uint8_t *buf, uint16_t size);
  119. /**
  120. * @brief Enable ethernet interface
  121. *
  122. * @note Shout be called after esp_eth_init
  123. *
  124. * @return
  125. * - ESP_OK
  126. * - ESP_FAIL
  127. */
  128. esp_err_t esp_eth_enable(void);
  129. /**
  130. * @brief Disable ethernet interface
  131. *
  132. * @note Shout be called after esp_eth_init
  133. *
  134. * @return
  135. * - ESP_OK
  136. * - ESP_FAIL
  137. */
  138. esp_err_t esp_eth_disable(void);
  139. /**
  140. * @brief Get mac addr
  141. *
  142. * @note mac addr must be a valid unicast address
  143. *
  144. * @param[out] mac: start address of mac address.
  145. */
  146. void esp_eth_get_mac(uint8_t mac[6]);
  147. /**
  148. * @brief Read phy reg with smi interface.
  149. *
  150. * @note phy base addr must be right.
  151. *
  152. * @param[in] reg_num: phy reg num.
  153. *
  154. * @param[in] value: value which write to phy reg.
  155. */
  156. void esp_eth_smi_write(uint32_t reg_num, uint16_t value);
  157. /**
  158. * @brief Write phy reg with smi interface.
  159. *
  160. * @note phy base addr must be right.
  161. *
  162. * @param[in] reg_num: phy reg num.
  163. *
  164. * @return value what read from phy reg
  165. */
  166. uint16_t esp_eth_smi_read(uint32_t reg_num);
  167. /**
  168. * @brief Free emac rx buf.
  169. *
  170. * @note buf can not be null,and it is tcpip input buf.
  171. *
  172. * @param[in] buf: start address of recevie packet data.
  173. *
  174. */
  175. void esp_eth_free_rx_buf(void *buf);
  176. #ifdef __cplusplus
  177. }
  178. #endif
  179. #endif