phy.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-10-14 wangqiang the first version
  9. */
  10. #ifndef __PHY_H__
  11. #define __PHY_H__
  12. #include <rtthread.h>
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /* Defines the PHY link speed. This is align with the speed for MAC. */
  18. #define PHY_SPEED_10M 0U /* PHY 10M speed. */
  19. #define PHY_SPEED_100M 1U /* PHY 100M speed. */
  20. /* Defines the PHY link duplex. */
  21. #define PHY_HALF_DUPLEX 0U /* PHY half duplex. */
  22. #define PHY_FULL_DUPLEX 1U /* PHY full duplex. */
  23. /*! @brief Defines the PHY loopback mode. */
  24. #define PHY_LOCAL_LOOP 0U /* PHY local loopback. */
  25. #define PHY_REMOTE_LOOP 1U /* PHY remote loopback. */
  26. #define PHY_STATUS_OK 0U
  27. #define PHY_STATUS_FAIL 1U
  28. #define PHY_STATUS_TIMEOUT 2U
  29. typedef struct rt_phy_msg
  30. {
  31. rt_uint32_t reg;
  32. rt_uint32_t value;
  33. }rt_phy_msg_t;
  34. typedef struct rt_phy_device
  35. {
  36. struct rt_device parent;
  37. struct rt_mdio_bus *bus;
  38. rt_uint32_t addr;
  39. struct rt_phy_ops *ops;
  40. }rt_phy_t;
  41. typedef rt_int32_t rt_phy_status;
  42. struct rt_phy_ops
  43. {
  44. rt_phy_status (*init)(void *object, rt_uint32_t phy_addr, rt_uint32_t src_clock_hz);
  45. rt_phy_status (*read)(rt_uint32_t reg, rt_uint32_t *data);
  46. rt_phy_status (*write)(rt_uint32_t reg, rt_uint32_t data);
  47. rt_phy_status (*loopback)(rt_uint32_t mode, rt_uint32_t speed, rt_bool_t enable);
  48. rt_phy_status (*get_link_status)(rt_bool_t *status);
  49. rt_phy_status (*get_link_speed_duplex)(rt_uint32_t *speed, rt_uint32_t *duplex);
  50. };
  51. rt_err_t rt_hw_phy_register(struct rt_phy_device *phy, const char *name);
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif /* __PHY_H__*/