lan8742a.h 7.7 KB

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