esp_eth.h 4.3 KB

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