lan8742a.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-08-25 LongfeiMa transplantation driver of lan8742a
  9. */
  10. #ifndef __LAN8742_H__
  11. #define __LAN8742_H__
  12. /* Includes ------------------------------------------------------------------*/
  13. #include <stdint.h>
  14. #include "stm32h7xx_hal.h"
  15. /* Basic Registers */
  16. #define LAN8742_REG_BCR 0 /* Basic Control Register */
  17. #define LAN8742_REG_BSR 1 /* Basic Status Register */
  18. /* Extended Registers */
  19. #define LAN8742_REG_PHYIDR1 2 /* PHY Identifier 1 */
  20. #define LAN8742_REG_PHYIDR2 3 /* PHY Identifier 2 */
  21. #define LAN8742_REG_ANAR 4 /* Auto-Negotiation Advertisement */
  22. #define LAN8742_REG_ANLPAR 5 /* Auto-Neg. Link Partner Ability */
  23. #define LAN8742_REG_ANER 6 /* Auto-Neg. Expansion Register */
  24. #define LAN8742_REG_ANEG_NP_TX 7 /* Auto-Neg. Next Page Tx */
  25. #define LAN8742_REG_ANEG_NP_RX 8 /* Auto-Neg. Next Page Rx */
  26. #define LAN8742_REG_MMD_ACCES_CTRL 13 /* MMD Access Control */
  27. #define LAN8742_REG_MMD_ACCES_AD 14 /* MMD Access Address/Data */
  28. /* Vendor-specific Registers */
  29. #define LAN8742_REG_MCSR 17 /* Mode Control/Status Register */
  30. #define LAN8742_REG_SMR 18 /* Special Modes Register */
  31. #define LAN8742_REG_TDR_PAT_DEL 24 /* TDR Patterns/Delay Control Reg. */
  32. #define LAN8742_REG_TDR_CTRL_STAT 25 /* TDR Control/Status Register */
  33. #define LAN8742_REG_SEC 26 /* System Error Counter Register */
  34. #define LAN8742_REG_SC_SI 27 /* Specifal Control/Status Indication*/
  35. #define LAN8742_REG_CABLE_LEN 28 /* Cable Length Register */
  36. #define LAN8742_REG_ISF 29 /* Interrupt Source Flag Register */
  37. #define LAN8742_REG_IM 30 /* Interrupt Mask Register */
  38. #define LAN8742_REG_PSCS 31 /* PHY Special Ctrl/Status Register */
  39. /* Basic Control Register */
  40. #define LAN8742_BCR_RESET 0x8000 /* Software Reset */
  41. #define LAN8742_BCR_LOOPBACK 0x4000 /* Loopback mode */
  42. #define LAN8742_BCR_SPEED_SEL 0x2000 /* Speed Select (1=100Mb/s) */
  43. #define LAN8742_BCR_ANEG_EN 0x1000 /* Auto Negotiation Enable */
  44. #define LAN8742_BCR_POWER_DOWN 0x0800 /* Power Down (1=power down mode) */
  45. #define LAN8742_BCR_ISOLATE 0x0400 /* Isolate Media interface */
  46. #define LAN8742_BCR_REST_ANEG 0x0200 /* Restart Auto Negotiation */
  47. #define LAN8742_BCR_DUPLEX 0x0100 /* Duplex Mode (1=Full duplex) */
  48. #define LAN8742_BCR_COL_TEST 0x0080 /* Enable Collision Test */
  49. /* Basic Status Register */
  50. #define LAN8742_BSR_100B_T4 0x8000 /* 100BASE-T4 Capable */
  51. #define LAN8742_BSR_100B_TX_FD 0x4000 /* 100BASE-TX Full Duplex Capable */
  52. #define LAN8742_BSR_100B_TX_HD 0x2000 /* 100BASE-TX Half Duplex Capable */
  53. #define LAN8742_BSR_10B_T_FD 0x1000 /* 10BASE-T Full Duplex Capable */
  54. #define LAN8742_BSR_10B_T_HD 0x0800 /* 10BASE-T Half Duplex Capable */
  55. #define LAN8742_BSR_100B_T2_FD 0x0400 /* 1000BASE-T2 Full Duplex Capable */
  56. #define LAN8742_BSR_100B_T2_HD 0x0200 /* 1000BASE-T2 Half Duplex Capable */
  57. #define LAN8742_BSR_EXTENDED_STAT 0x0100 /* Extended Status in register 15 */
  58. #define LAN8742_BSR_ANEG_COMPL 0x0020 /* Auto Negotiation Complete */
  59. #define LAN8742_BSR_REM_FAULT 0x0010 /* Remote Fault */
  60. #define LAN8742_BSR_ANEG_ABIL 0x0008 /* Auto Negotiation Ability */
  61. #define LAN8742_BSR_LINK_STAT 0x0004 /* Link Status (1=link us up) */
  62. #define LAN8742_BSR_JABBER_DET 0x0002 /* Jabber Detect */
  63. #define LAN8742_BSR_EXT_CAPAB 0x0001 /* Extended Capabilities */
  64. /* PHY Identifier Registers */
  65. #define LAN8742_PHY_ID1 0x0007 /* LAN8742 Device Identifier MSB */
  66. #define LAN8742_PHY_ID2 0xC130 /* LAN8742 Device Identifier LSB */
  67. /** @defgroup LAN8742_PHYSCSR_Bit_Definition LAN8742 PHYSCSR Bit Definition
  68. * @{
  69. */
  70. #define LAN8742_PHYSCSR_AUTONEGO_DONE ((uint16_t)0x1000U)
  71. #define LAN8742_PHYSCSR_HCDSPEEDMASK ((uint16_t)0x001CU)
  72. #define LAN8742_PHYSCSR_10BT_HD ((uint16_t)0x0004U)
  73. #define LAN8742_PHYSCSR_10BT_FD ((uint16_t)0x0014U)
  74. #define LAN8742_PHYSCSR_100BTX_HD ((uint16_t)0x0008U)
  75. #define LAN8742_PHYSCSR_100BTX_FD ((uint16_t)0x0018U)
  76. /* PHY Driver State Flags */
  77. #define LAN8742_PHY_INIT 0x01U /* Driver initialized */
  78. #define LAN8742_PHY_POWER 0x02U /* Driver power is on */
  79. /** @defgroup LAN8742_SMR_Bit_Definition LAN8742 SMR Bit Definition
  80. * @{
  81. */
  82. #define LAN8742_SMR_MODE ((uint16_t)0x00E0U)
  83. #define LAN8742_SMR_PHY_ADDR ((uint16_t)0x001FU)
  84. /** @defgroup LAN8742_IMR_ISFR_Bit_Definition LAN8742 IMR ISFR Bit Definition
  85. * @{
  86. */
  87. #define LAN8742_INT_8 ((uint16_t)0x0100U)
  88. #define LAN8742_INT_7 ((uint16_t)0x0080U)
  89. #define LAN8742_INT_6 ((uint16_t)0x0040U)
  90. #define LAN8742_INT_5 ((uint16_t)0x0020U)
  91. #define LAN8742_INT_4 ((uint16_t)0x0010U)
  92. #define LAN8742_INT_3 ((uint16_t)0x0008U)
  93. #define LAN8742_INT_2 ((uint16_t)0x0004U)
  94. #define LAN8742_INT_1 ((uint16_t)0x0002U)
  95. #define LAN8742_INT_ALL ((uint16_t)0x01FEU)
  96. /** @defgroup LAN8742_Status LAN8742 Status
  97. * @{
  98. */
  99. #define LAN8742_STATUS_READ_ERROR ((int32_t)-5)
  100. #define LAN8742_STATUS_WRITE_ERROR ((int32_t)-4)
  101. #define LAN8742_STATUS_ADDRESS_ERROR ((int32_t)-3)
  102. #define LAN8742_STATUS_RESET_TIMEOUT ((int32_t)-2)
  103. #define LAN8742_STATUS_ERROR ((int32_t)-1)
  104. #define LAN8742_STATUS_OK ((int32_t) 0)
  105. #define LAN8742_STATUS_LINK_DOWN ((int32_t) 1)
  106. #define LAN8742_STATUS_100MBITS_FULLDUPLEX ((int32_t) 2)
  107. #define LAN8742_STATUS_100MBITS_HALFDUPLEX ((int32_t) 3)
  108. #define LAN8742_STATUS_10MBITS_FULLDUPLEX ((int32_t) 4)
  109. #define LAN8742_STATUS_10MBITS_HALFDUPLEX ((int32_t) 5)
  110. #define LAN8742_STATUS_AUTONEGO_NOTDONE ((int32_t) 6)
  111. /* Exported types ------------------------------------------------------------*/
  112. /** @defgroup LAN8742_Exported_Types LAN8742 Exported Types
  113. * @{
  114. */
  115. typedef int32_t (*lan8742_Init_Func) (void);
  116. typedef int32_t (*lan8742_DeInit_Func) (void);
  117. typedef int32_t (*lan8742_ReadReg_Func) (uint32_t, uint32_t, uint32_t *);
  118. typedef int32_t (*lan8742_WriteReg_Func) (uint32_t, uint32_t, uint32_t);
  119. typedef int32_t (*lan8742_GetTick_Func) (void);
  120. typedef struct
  121. {
  122. lan8742_Init_Func Init;
  123. lan8742_DeInit_Func DeInit;
  124. lan8742_WriteReg_Func WriteReg;
  125. lan8742_ReadReg_Func ReadReg;
  126. lan8742_GetTick_Func GetTick;
  127. } lan8742_IOCtx_t;
  128. typedef struct
  129. {
  130. uint32_t DevAddr;
  131. uint32_t Is_Initialized;
  132. lan8742_IOCtx_t IO;
  133. void *pData;
  134. }lan8742_Object_t;
  135. extern ETH_HandleTypeDef EthHandle;
  136. int rt_hw_lan8742a_init(void);
  137. #endif /* __PHY_LAN8742_H */