esp_eth.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /**
  75. * @brief ethernet configuration
  76. *
  77. */
  78. typedef struct {
  79. eth_phy_base_t phy_addr; /*!< phy base addr (0~31) */
  80. eth_mode_t mac_mode; /*!< mac mode only support RMII now */
  81. eth_tcpip_input_func tcpip_input; /*!< tcpip input func */
  82. eth_phy_func phy_init; /*!< phy init func */
  83. eth_phy_check_link_func phy_check_link; /*!< phy check link func */
  84. eth_phy_check_init_func phy_check_init; /*!< phy check init func */
  85. eth_phy_get_speed_mode_func phy_get_speed_mode; /*!< phy check init func */
  86. eth_phy_get_duplex_mode_func phy_get_duplex_mode; /*!< phy check init func */
  87. eth_gpio_config_func gpio_config; /*!< gpio config func */
  88. bool flow_ctrl_enable; /*!< flag of flow ctrl enable */
  89. eth_phy_get_partner_pause_enable_func phy_get_partner_pause_enable; /*!< get partner pause enable */
  90. } eth_config_t;
  91. /**
  92. * @brief Init ethernet mac
  93. *
  94. * @note config can not be NULL,and phy chip must be suitable to phy init func.
  95. *
  96. * @param[in] config mac init data.
  97. *
  98. * @return
  99. * - ESP_OK
  100. * - ESP_FAIL
  101. */
  102. esp_err_t esp_eth_init(eth_config_t *config);
  103. /**
  104. * @brief Send packet from tcp/ip to mac
  105. *
  106. * @note buf can not be NULL,size must be less than 1580
  107. *
  108. * @param[in] buf: start address of packet data.
  109. *
  110. * @param[in] size: size (byte) of packet data.
  111. *
  112. * @return
  113. * - ESP_OK
  114. * - ESP_FAIL
  115. */
  116. esp_err_t esp_eth_tx(uint8_t *buf, uint16_t size);
  117. /**
  118. * @brief Enable ethernet interface
  119. *
  120. * @note Shout be called after esp_eth_init
  121. *
  122. * @return
  123. * - ESP_OK
  124. * - ESP_FAIL
  125. */
  126. esp_err_t esp_eth_enable(void);
  127. /**
  128. * @brief Disable ethernet interface
  129. *
  130. * @note Shout be called after esp_eth_init
  131. *
  132. * @return
  133. * - ESP_OK
  134. * - ESP_FAIL
  135. */
  136. esp_err_t esp_eth_disable(void);
  137. /**
  138. * @brief Get mac addr
  139. *
  140. * @note mac addr must be a valid unicast address
  141. *
  142. * @param[out] mac: start address of mac address.
  143. */
  144. void esp_eth_get_mac(uint8_t mac[6]);
  145. /**
  146. * @brief Read phy reg with smi interface.
  147. *
  148. * @note phy base addr must be right.
  149. *
  150. * @param[in] reg_num: phy reg num.
  151. *
  152. * @param[in] value: value which write to phy reg.
  153. */
  154. void esp_eth_smi_write(uint32_t reg_num, uint16_t value);
  155. /**
  156. * @brief Write phy reg with smi interface.
  157. *
  158. * @note phy base addr must be right.
  159. *
  160. * @param[in] reg_num: phy reg num.
  161. *
  162. * @return value what read from phy reg
  163. */
  164. uint16_t esp_eth_smi_read(uint32_t reg_num);
  165. /**
  166. * @brief Free emac rx buf.
  167. *
  168. * @note buf can not be null,and it is tcpip input buf.
  169. *
  170. * @param[in] buf: start address of recevie packet data.
  171. *
  172. */
  173. void esp_eth_free_rx_buf(void *buf);
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif