drv_eth_phy.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * Copyright (C) 2016 CSI Project. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _CSI_ETH_PHY_H_
  17. #define _CSI_ETH_PHY_H_
  18. #include "drv_eth.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef void *eth_phy_handle_t;
  23. #define CSI_ETH_PHY_API_VERSION CSI_ETH_VERSION_MAJOR_MINOR(2,1) /* API version */
  24. #define _CSI_Driver_ETH_PHY_(n) Driver_ETH_PHY##n
  25. #define CSI_Driver_ETH_PHY_(n) _CSI_Driver_ETH_PHY_(n)
  26. /****** Ethernet PHY Mode *****/
  27. #define CSI_ETH_PHY_SPEED_Pos 0
  28. #define CSI_ETH_PHY_SPEED_Msk (3UL << CSI_ETH_PHY_SPEED_Pos)
  29. #define CSI_ETH_PHY_SPEED_10M (CSI_ETH_SPEED_10M << CSI_ETH_PHY_SPEED_Pos) ///< 10 Mbps link speed
  30. #define CSI_ETH_PHY_SPEED_100M (CSI_ETH_SPEED_100M << CSI_ETH_PHY_SPEED_Pos) ///< 100 Mbps link speed
  31. #define CSI_ETH_PHY_SPEED_1G (CSI_ETH_SPEED_1G << CSI_ETH_PHY_SPEED_Pos) ///< 1 Gpbs link speed
  32. #define CSI_ETH_PHY_DUPLEX_Pos 2
  33. #define CSI_ETH_PHY_DUPLEX_Msk (1UL << CSI_ETH_PHY_DUPLEX_Pos)
  34. #define CSI_ETH_PHY_DUPLEX_HALF (CSI_ETH_DUPLEX_HALF << CSI_ETH_PHY_DUPLEX_Pos) ///< Half duplex link
  35. #define CSI_ETH_PHY_DUPLEX_FULL (CSI_ETH_DUPLEX_FULL << CSI_ETH_PHY_DUPLEX_Pos) ///< Full duplex link
  36. #define CSI_ETH_PHY_AUTO_NEGOTIATE (1UL << 3) ///< Auto Negotiation mode
  37. #define CSI_ETH_PHY_LOOPBACK (1UL << 4) ///< Loop-back test mode
  38. #define CSI_ETH_PHY_ISOLATE (1UL << 5) ///< Isolate PHY from MII/RMII interface
  39. typedef int32_t (*csi_eth_phy_read_t) (uint8_t phy_addr, uint8_t reg_addr, uint16_t *data); ///< Read Ethernet PHY Register.
  40. typedef int32_t (*csi_eth_phy_write_t) (uint8_t phy_addr, uint8_t reg_addr, uint16_t data); ///< Write Ethernet PHY Register.
  41. typedef struct {
  42. csi_eth_phy_read_t phy_read;
  43. csi_eth_phy_write_t phy_write;
  44. eth_link_info_t link_info;
  45. }eth_phy_priv_t;
  46. // Function documentation
  47. /**
  48. \brief Get driver version.
  49. \param[in] handle ethernet phy handle
  50. \return driver version
  51. */
  52. csi_drv_version_t csi_eth_phy_get_version(eth_phy_handle_t handle);
  53. /**
  54. \brief Initialize Ethernet PHY Device.
  55. \param[in] fn_read
  56. \param[in] fn_write
  57. \return ethernet phy handle
  58. */
  59. eth_phy_handle_t csi_eth_phy_initialize(csi_eth_phy_read_t fn_read, csi_eth_phy_write_t fn_write);
  60. /**
  61. \brief De-initialize Ethernet PHY Device.
  62. \param[in] handle ethernet phy handle
  63. \return error code
  64. */
  65. int32_t csi_eth_phy_uninitialize(eth_phy_handle_t handle);
  66. /**
  67. \brief Control Ethernet PHY Device Power.
  68. \param[in] handle ethernet phy handle
  69. \param[in] state Power state
  70. \return error code
  71. */
  72. int32_t csi_eth_phy_power_control(eth_phy_handle_t handle, eth_power_state_t state);
  73. /**
  74. \brief Set Ethernet Media Interface.
  75. \param[in] handle ethernet phy handle
  76. \param[in] interface Media Interface type
  77. \return error code
  78. */
  79. int32_t csi_eth_phy_set_interface(eth_phy_handle_t handle, uint32_t interface);
  80. /**
  81. \brief Set Ethernet PHY Device Operation mode.
  82. \param[in] handle ethernet phy handle
  83. \param[in] mode Operation Mode
  84. \return error code
  85. */
  86. int32_t csi_eth_phy_set_mode(eth_phy_handle_t handle, uint32_t mode);
  87. /**
  88. \brief Get Ethernet PHY Device Link state.
  89. \param[in] handle ethernet phy handle
  90. \return current link status \ref eth_link_state_t
  91. */
  92. eth_link_state_t csi_eth_phy_get_linkstate(eth_phy_handle_t handle);
  93. /**
  94. \brief Get Ethernet PHY Device Link information.
  95. \param[in] handle ethernet phy handle
  96. \return current link parameters \ref eth_link_info_t
  97. */
  98. eth_link_info_t csi_eth_phy_get_linkinfo(eth_phy_handle_t handle);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif