esp_eth_phy.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // Copyright 2019 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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <stdbool.h>
  19. #include "esp_eth_com.h"
  20. #include "sdkconfig.h"
  21. /**
  22. * @brief Ethernet PHY
  23. *
  24. */
  25. typedef struct esp_eth_phy_s esp_eth_phy_t;
  26. /**
  27. * @brief Ethernet PHY
  28. *
  29. */
  30. struct esp_eth_phy_s {
  31. /**
  32. * @brief Set mediator for PHY
  33. *
  34. * @param[in] phy: Ethernet PHY instance
  35. * @param[in] mediator: mediator of Ethernet driver
  36. *
  37. * @return
  38. * - ESP_OK: set mediator for Ethernet PHY instance successfully
  39. * - ESP_ERR_INVALID_ARG: set mediator for Ethernet PHY instance failed because of some invalid arguments
  40. *
  41. */
  42. esp_err_t (*set_mediator)(esp_eth_phy_t *phy, esp_eth_mediator_t *mediator);
  43. /**
  44. * @brief Reset Ethernet PHY
  45. *
  46. * @param[in] phy: Ethernet PHY instance
  47. *
  48. * @return
  49. * - ESP_OK: reset Ethernet PHY successfully
  50. * - ESP_FAIL: reset Ethernet PHY failed because some error occurred
  51. *
  52. */
  53. esp_err_t (*reset)(esp_eth_phy_t *phy);
  54. /**
  55. * @brief Initialize Ethernet PHY
  56. *
  57. * @param[in] phy: Ethernet PHY instance
  58. *
  59. * @return
  60. * - ESP_OK: initialize Ethernet PHY successfully
  61. * - ESP_FAIL: initialize Ethernet PHY failed because some error occurred
  62. *
  63. */
  64. esp_err_t (*init)(esp_eth_phy_t *phy);
  65. /**
  66. * @brief Deinitialize Ethernet PHY
  67. *
  68. * @param[in] phyL Ethernet PHY instance
  69. *
  70. * @return
  71. * - ESP_OK: deinitialize Ethernet PHY successfully
  72. * - ESP_FAIL: deinitialize Ethernet PHY failed because some error occurred
  73. *
  74. */
  75. esp_err_t (*deinit)(esp_eth_phy_t *phy);
  76. /**
  77. * @brief Start auto negotiation
  78. *
  79. * @param[in] phy: Ethernet PHY instance
  80. *
  81. * @return
  82. * - ESP_OK: restart auto negotiation successfully
  83. * - ESP_FAIL: restart auto negotiation failed because some error occurred
  84. *
  85. */
  86. esp_err_t (*negotiate)(esp_eth_phy_t *phy);
  87. /**
  88. * @brief Get Ethernet PHY link status
  89. *
  90. * @param[in] phy: Ethernet PHY instance
  91. *
  92. * @return
  93. * - ESP_OK: get Ethernet PHY link status successfully
  94. * - ESP_FAIL: get Ethernet PHY link status failed because some error occurred
  95. *
  96. */
  97. esp_err_t (*get_link)(esp_eth_phy_t *phy);
  98. /**
  99. * @brief Power control of Ethernet PHY
  100. *
  101. * @param[in] phy: Ethernet PHY instance
  102. * @param[in] enable: set true to power on Ethernet PHY; ser false to power off Ethernet PHY
  103. *
  104. * @return
  105. * - ESP_OK: control Ethernet PHY power successfully
  106. * - ESP_FAIL: control Ethernet PHY power failed because some error occurred
  107. *
  108. */
  109. esp_err_t (*pwrctl)(esp_eth_phy_t *phy, bool enable);
  110. /**
  111. * @brief Set PHY chip address
  112. *
  113. * @param[in] phy: Ethernet PHY instance
  114. * @param[in] addr: PHY chip address
  115. *
  116. * @return
  117. * - ESP_OK: set Ethernet PHY address successfully
  118. * - ESP_FAIL: set Ethernet PHY address failed because some error occurred
  119. *
  120. */
  121. esp_err_t (*set_addr)(esp_eth_phy_t *phy, uint32_t addr);
  122. /**
  123. * @brief Get PHY chip address
  124. *
  125. * @param[in] phy: Ethernet PHY instance
  126. * @param[out] addr: PHY chip address
  127. *
  128. * @return
  129. * - ESP_OK: get Ethernet PHY address successfully
  130. * - ESP_ERR_INVALID_ARG: get Ethernet PHY address failed because of invalid argument
  131. *
  132. */
  133. esp_err_t (*get_addr)(esp_eth_phy_t *phy, uint32_t *addr);
  134. /**
  135. * @brief Free memory of Ethernet PHY instance
  136. *
  137. * @param[in] phy: Ethernet PHY instance
  138. *
  139. * @return
  140. * - ESP_OK: free PHY instance successfully
  141. * - ESP_FAIL: free PHY instance failed because some error occurred
  142. *
  143. */
  144. esp_err_t (*del)(esp_eth_phy_t *phy);
  145. };
  146. /**
  147. * @brief Ethernet PHY configuration
  148. *
  149. */
  150. typedef struct {
  151. uint32_t phy_addr; /*!< PHY address */
  152. uint32_t reset_timeout_ms; /*!< Reset timeout value (Unit: ms) */
  153. uint32_t autonego_timeout_ms; /*!< Auto-negotiation timeout value (Unit: ms) */
  154. } eth_phy_config_t;
  155. /**
  156. * @brief Default configuration for Ethernet PHY object
  157. *
  158. */
  159. #define ETH_PHY_DEFAULT_CONFIG() \
  160. { \
  161. .phy_addr = 1, \
  162. .reset_timeout_ms = 100, \
  163. .autonego_timeout_ms = 4000 \
  164. }
  165. /**
  166. * @brief Create a PHY instance of IP101
  167. *
  168. * @param[in] config: configuration of PHY
  169. *
  170. * @return
  171. * - instance: create PHY instance successfully
  172. * - NULL: create PHY instance failed because some error occurred
  173. */
  174. esp_eth_phy_t *esp_eth_phy_new_ip101(const eth_phy_config_t *config);
  175. /**
  176. * @brief Create a PHY instance of RTL8201
  177. *
  178. * @param[in] config: configuration of PHY
  179. *
  180. * @return
  181. * - instance: create PHY instance successfully
  182. * - NULL: create PHY instance failed because some error occurred
  183. */
  184. esp_eth_phy_t *esp_eth_phy_new_rtl8201(const eth_phy_config_t *config);
  185. /**
  186. * @brief Create a PHY instance of LAN8720
  187. *
  188. * @param[in] config: configuration of PHY
  189. *
  190. * @return
  191. * - instance: create PHY instance successfully
  192. * - NULL: create PHY instance failed because some error occurred
  193. */
  194. esp_eth_phy_t *esp_eth_phy_new_lan8720(const eth_phy_config_t *config);
  195. /**
  196. * @brief Create a PHY instance of DP83848
  197. *
  198. * @param[in] config: configuration of PHY
  199. *
  200. * @return
  201. * - instance: create PHY instance successfully
  202. * - NULL: create PHY instance failed because some error occurred
  203. */
  204. esp_eth_phy_t *esp_eth_phy_new_dp83848(const eth_phy_config_t *config);
  205. #if CONFIG_ETH_SPI_ETHERNET_DM9051
  206. /**
  207. * @brief Create a PHY instance of DM9051
  208. *
  209. * @param[in] config: configuration of PHY
  210. *
  211. * @return
  212. * - instance: create PHY instance successfully
  213. * - NULL: create PHY instance failed because some error occurred
  214. */
  215. esp_eth_phy_t *esp_eth_phy_new_dm9051(const eth_phy_config_t *config);
  216. #endif
  217. #ifdef __cplusplus
  218. }
  219. #endif