esp_eth_phy_802_3.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdbool.h>
  8. #include "esp_eth.h"
  9. #include "sdkconfig.h"
  10. #include "eth_phy_802_3_regs.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /**
  15. * @brief IEEE 802.3 PHY object infostructure
  16. *
  17. */
  18. typedef struct {
  19. esp_eth_phy_t parent; /*!< Parent Ethernet PHY instance */
  20. esp_eth_mediator_t *eth; /*!< Mediator of Ethernet driver */
  21. int addr; /*!< PHY address */
  22. uint32_t reset_timeout_ms; /*!< Reset timeout value (Unit: ms) */
  23. uint32_t autonego_timeout_ms; /*!< Auto-negotiation timeout value (Unit: ms) */
  24. eth_link_t link_status; /*!< Current Link status */
  25. int reset_gpio_num; /*!< Reset GPIO number, -1 means no hardware reset */
  26. } phy_802_3_t;
  27. /**
  28. * @brief Performs hardware reset with specific reset pin assertion time
  29. *
  30. * @param phy_802_3 IEEE 802.3 PHY object infostructure
  31. * @param reset_assert_us Hardware reset pin assertion time
  32. * @return
  33. * - ESP_OK: reset Ethernet PHY successfully
  34. */
  35. esp_err_t esp_eth_phy_802_3_reset_hw(phy_802_3_t *phy_802_3, uint32_t reset_assert_us);
  36. /**
  37. * @brief Detect PHY address
  38. *
  39. * @param eth Mediator of Ethernet driver
  40. * @param[out] detected_addr: a valid address after detection
  41. * @return
  42. * - ESP_OK: detect phy address successfully
  43. * - ESP_ERR_INVALID_ARG: invalid parameter
  44. * - ESP_ERR_NOT_FOUND: can't detect any PHY device
  45. * - ESP_FAIL: detect phy address failed because some error occurred
  46. */
  47. esp_err_t esp_eth_phy_802_3_detect_phy_addr(esp_eth_mediator_t *eth, int *detected_addr);
  48. /**
  49. * @brief Performs basic PHY chip initialization
  50. *
  51. * @note It should be called as the first function in PHY specific driver instance
  52. *
  53. * @param phy_802_3 IEEE 802.3 PHY object infostructure
  54. * @return
  55. * - ESP_OK: initialized Ethernet PHY successfully
  56. * - ESP_FAIL: initialization of Ethernet PHY failed because some error occurred
  57. * - ESP_ERR_INVALID_ARG: invalid argument
  58. * - ESP_ERR_NOT_FOUND: PHY device not detected
  59. * - ESP_ERR_TIMEOUT: MII Management read/write operation timeout
  60. * - ESP_ERR_INVALID_STATE: PHY is in invalid state to perform requested operation
  61. */
  62. esp_err_t esp_eth_phy_802_3_basic_phy_init(phy_802_3_t *phy_802_3);
  63. /**
  64. * @brief Performs basic PHY chip de-initialization
  65. *
  66. * @note It should be called as the last function in PHY specific driver instance
  67. *
  68. * @param phy_802_3 IEEE 802.3 PHY object infostructure
  69. * @return
  70. * - ESP_OK: de-initialized Ethernet PHY successfully
  71. * - ESP_FAIL: de-initialization of Ethernet PHY failed because some error occurred
  72. * - ESP_ERR_TIMEOUT: MII Management read/write operation timeout
  73. * - ESP_ERR_INVALID_STATE: PHY is in invalid state to perform requested operation
  74. */
  75. esp_err_t esp_eth_phy_802_3_basic_phy_deinit(phy_802_3_t *phy_802_3);
  76. /**
  77. * @brief Reads raw content of OUI field
  78. *
  79. * @param phy_802_3 IEEE 802.3 PHY object infostructure
  80. * @param[out] oui OUI value
  81. * @return
  82. * - ESP_OK: OUI field read successfully
  83. * - ESP_FAIL: OUI field read failed because some error occurred
  84. * - ESP_ERR_INVALID_ARG: invalid @c oui argument
  85. * - ESP_ERR_TIMEOUT: MII Management read/write operation timeout
  86. * - ESP_ERR_INVALID_STATE: PHY is in invalid state to perform requested operation
  87. */
  88. esp_err_t esp_eth_phy_802_3_read_oui(phy_802_3_t *phy_802_3, uint32_t *oui);
  89. /**
  90. * @brief Reads manufacturer’s model and revision number
  91. *
  92. * @param phy_802_3 IEEE 802.3 PHY object infostructure
  93. * @param[out] model Manufacturer’s model number (can be NULL when not required)
  94. * @param[out] rev Manufacturer’s revision number (can be NULL when not required)
  95. * @return
  96. * - ESP_OK: Manufacturer’s info read successfully
  97. * - ESP_FAIL: Manufacturer’s info read failed because some error occurred
  98. * - ESP_ERR_TIMEOUT: MII Management read/write operation timeout
  99. * - ESP_ERR_INVALID_STATE: PHY is in invalid state to perform requested operation
  100. */
  101. esp_err_t esp_eth_phy_802_3_read_manufac_info(phy_802_3_t *phy_802_3, uint8_t *model, uint8_t *rev);
  102. /**
  103. * @brief Returns address to parent IEEE 802.3 PHY object infostructure
  104. *
  105. * @param phy Ethernet PHY instance
  106. * @return phy_802_3_t*
  107. * - address to parent IEEE 802.3 PHY object infostructure
  108. */
  109. phy_802_3_t *esp_eth_phy_into_phy_802_3(esp_eth_phy_t *phy);
  110. /**
  111. * @brief Initializes configuration of parent IEEE 802.3 PHY object infostructure
  112. *
  113. * @param phy_802_3 Address to IEEE 802.3 PHY object infostructure
  114. * @param config Configuration of the IEEE 802.3 PHY object
  115. * @return
  116. * - ESP_OK: configuration initialized successfully
  117. * - ESP_ERR_INVALID_ARG: invalid @c config argument
  118. */
  119. esp_err_t esp_eth_phy_802_3_obj_config_init(phy_802_3_t *phy_802_3, const eth_phy_config_t *config);
  120. #ifdef __cplusplus
  121. }
  122. #endif