drv_emac.h 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * 2022-05-16 shelton first version
  9. */
  10. #ifndef __DRV_EMAC_H__
  11. #define __DRV_EMAC_H__
  12. #include <rtthread.h>
  13. #include <rthw.h>
  14. #include <rtdevice.h>
  15. #include "drv_common.h"
  16. #define CRYSTAL_ON_PHY 0 /* phy does not with crystal */
  17. /* the phy basic control register */
  18. #define PHY_BASIC_CONTROL_REG 0x00U
  19. #define PHY_RESET_MASK (1<<15)
  20. #define PHY_AUTO_NEGOTIATION_MASK (1<<12)
  21. /* the phy basic status register */
  22. #define PHY_BASIC_STATUS_REG 0x01U
  23. #define PHY_LINKED_STATUS_MASK (1<<2)
  24. #define PHY_AUTONEGO_COMPLETE_MASK (1<<5)
  25. /* the phy id one register */
  26. #define PHY_ID1_REG 0x02U
  27. /* the phy id two register */
  28. #define PHY_ID2_REG 0x03U
  29. /* the phy auto-negotiate advertise register */
  30. #define PHY_AUTONEG_ADVERTISE_REG 0x04U
  31. #if defined (PHY_USING_DM9162)
  32. #define PHY_CONTROL_REG (0x00) /*!< basic mode control register */
  33. #define PHY_STATUS_REG (0x01) /*!< basic mode status register */
  34. #define PHY_SPECIFIED_CS_REG (0x11) /*!< specified configuration and status register */
  35. /* phy control register */
  36. #define PHY_AUTO_NEGOTIATION_BIT (0x1000) /*!< enable auto negotiation */
  37. #define PHY_LOOPBACK_BIT (0x4000) /*!< enable loopback */
  38. #define PHY_RESET_BIT (0x8000) /*!< reset phy */
  39. /* phy status register */
  40. #define PHY_LINKED_STATUS_BIT (0x0004) /*!< link status */
  41. #define PHY_NEGO_COMPLETE_BIT (0x0020) /*!< auto negotiation complete */
  42. /* phy specified control/status register */
  43. #define PHY_FULL_DUPLEX_100MBPS_BIT (0x8000) /*!< full duplex 100 mbps */
  44. #define PHY_HALF_DUPLEX_100MBPS_BIT (0x4000) /*!< half duplex 100 mbps */
  45. #define PHY_FULL_DUPLEX_10MBPS_BIT (0x2000) /*!< full duplex 10 mbps */
  46. #define PHY_HALF_DUPLEX_10MBPS_BIT (0x1000) /*!< half duplex 10 mbps */
  47. #define PHY_DUPLEX_MODE (PHY_FULL_DUPLEX_100MBPS_BIT | PHY_FULL_DUPLEX_10MBPS_BIT) /*!< full duplex mode */
  48. #define PHY_SPEED_MODE (PHY_FULL_DUPLEX_10MBPS_BIT | PHY_HALF_DUPLEX_10MBPS_BIT) /*!< 10 mbps */
  49. /* the phy interrupt source flag register. */
  50. #define PHY_INTERRUPT_FLAG_REG 0x15U
  51. /* the phy interrupt mask register. */
  52. #define PHY_INTERRUPT_MASK_REG 0x15U
  53. #define PHY_LINK_CHANGE_FLAG (1<<2)
  54. #define PHY_LINK_CHANGE_MASK (1<<9)
  55. #define PHY_INT_MASK 0
  56. #elif defined (PHY_USING_DP83848)
  57. #define PHY_CONTROL_REG (0x00) /*!< basic mode control register */
  58. #define PHY_STATUS_REG (0x01) /*!< basic mode status register */
  59. #define PHY_SPECIFIED_CS_REG (0x10) /*!< phy status register */
  60. /* phy control register */
  61. #define PHY_AUTO_NEGOTIATION_BIT (0x1000) /*!< enable auto negotiation */
  62. #define PHY_LOOPBACK_BIT (0x4000) /*!< enable loopback */
  63. #define PHY_RESET_BIT (0x8000) /*!< reset phy */
  64. /* phy status register */
  65. #define PHY_LINKED_STATUS_BIT (0x0004) /*!< link status */
  66. #define PHY_NEGO_COMPLETE_BIT (0x0020) /*!< auto negotiation complete */
  67. #define PHY_DUPLEX_MODE (0x0004) /*!< full duplex mode */
  68. #define PHY_SPEED_MODE (0x0002) /*!< 10 mbps */
  69. /* the phy interrupt source flag register. */
  70. #define PHY_INTERRUPT_FLAG_REG 0x12U
  71. #define PHY_LINK_CHANGE_FLAG (1<<13)
  72. /* the phy interrupt control register. */
  73. #define PHY_INTERRUPT_CTRL_REG 0x11U
  74. #define PHY_INTERRUPT_EN ((1<<0)|(1<<1))
  75. /* the phy interrupt mask register. */
  76. #define PHY_INTERRUPT_MASK_REG 0x12U
  77. #define PHY_INT_MASK (1<<5)
  78. #endif
  79. #endif /* __DRV_EMAC_H__ */