drv_emac.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * COPYRIGHT (C) 2018, Real-Thread Information Technology Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2015-07-15 Bernard The first version
  9. */
  10. #ifndef EMAC_DRV_H__
  11. #define EMAC_DRV_H__
  12. //#define ENHANCED_BD
  13. ///* Ethernet standard lengths in bytes*/
  14. //#define ETH_ADDR_LEN (6)
  15. //#define ETH_TYPE_LEN (2)
  16. //#define ETH_CRC_LEN (4)
  17. //#define ETH_MAX_DATA (1500)
  18. //#define ETH_MIN_DATA (46)
  19. //#define ETH_HDR_LEN (ETH_ADDR_LEN * 2 + ETH_TYPE_LEN)
  20. //// 6 * 2 + 2 + 1500 + 4
  21. ///* Maximum and Minimum Ethernet Frame Sizes */
  22. //#define ETH_MAX_FRM (ETH_HDR_LEN + ETH_MAX_DATA + ETH_CRC_LEN)
  23. //#define ETH_MIN_FRM (ETH_HDR_LEN + ETH_MIN_DATA + ETH_CRC_LEN)
  24. //#define ETH_MTU (ETH_HDR_LEN + ETH_MAX_DATA)
  25. ///********INTERFACE**********/
  26. //typedef enum
  27. //{
  28. // MAC_MII,
  29. // MAC_RMII,
  30. //} ENET_INTERFACE;
  31. ///********AUTONEG**********/
  32. //typedef enum
  33. //{
  34. // AUTONEG_ON,
  35. // AUTONEG_OFF
  36. //} ENET_AUTONEG;
  37. ///********SPEED**********/
  38. //typedef enum
  39. //{
  40. // MII_10BASET,
  41. // MII_100BASET
  42. //} ENET_SPEED;
  43. ///********DUPLEX**********/
  44. ///* MII Duplex Settings */
  45. //typedef enum
  46. //{
  47. // MII_HDX, /*!< half-duplex */
  48. // MII_FDX /*!< full-duplex */
  49. //} ENET_DUPLEX;
  50. ///********LOOPBACK**********/
  51. //typedef enum
  52. //{
  53. // INTERNAL_LOOPBACK,
  54. // EXTERNAL_LOOPBACK,
  55. // NO_LOOPBACK
  56. //} ENET_LOOPBACK;
  57. ///********EXTERNAL**********/
  58. //typedef enum
  59. //{
  60. // EXTERNAL_NONE,
  61. // EXTERNAL_YES
  62. //} ENET_EXTERNAL_CONN;
  63. ///*
  64. // * FEC Configuration Parameters
  65. // */
  66. //typedef struct
  67. //{
  68. // //ENET_Type* hw_base; /* FEC channel */
  69. // ENET_INTERFACE interface; /* Transceiver mode */
  70. // ENET_AUTONEG neg; /* FEC autoneg */
  71. // ENET_SPEED speed; /* Ethernet Speed */
  72. // ENET_DUPLEX duplex; /* Ethernet Duplex */
  73. // ENET_LOOPBACK loopback; /* Loopback Mode */
  74. // ENET_EXTERNAL_CONN external; /* outside test? */
  75. // uint8_t prom; /* Promiscuous Mode? */
  76. // uint8_t mac[6]; /* Ethernet Address */
  77. //} ENET_CONFIG;
  78. //// Choose Enhanced Buffer Descriptor or Legacy
  79. ////#define ENHANCED_BD
  80. //// Buffer sizes in bytes (must be divisible by 16)
  81. //#define RX_BUFFER_SIZE ETH_MAX_FRM
  82. //#define TX_BUFFER_SIZE ETH_MAX_FRM
  83. //// Number of Receive and Transmit Buffers and Buffer Descriptors
  84. //#define NUM_RXBDS 8
  85. //#define NUM_TXBDS 4
  86. //// Buffer Descriptor Format
  87. //typedef struct
  88. //{
  89. // uint16_t status; /* control and status */
  90. // uint16_t length; /* transfer length */
  91. // uint8_t *data; /* buffer address */
  92. //#ifdef ENHANCED_BD
  93. // uint32_t ebd_status;
  94. // uint16_t length_proto_type;
  95. // uint16_t payload_checksum;
  96. // uint32_t bdu;
  97. // uint32_t timestamp;
  98. // uint32_t reserverd_word1;
  99. // uint32_t reserverd_word2;
  100. //#endif /* ENHANCED_BD */
  101. //} NBUF;
  102. //// ----------------------------------------------------------------------
  103. //// TX Buffer Descriptor Bit Definitions
  104. //// ----------------------------------------------------------------------
  105. //#define TX_BD_R 0x0080
  106. //#define TX_BD_TO1 0x0040
  107. //#define TX_BD_W 0x0020
  108. //#define TX_BD_TO2 0x0010
  109. //#define TX_BD_L 0x0008
  110. //#define TX_BD_TC 0x0004
  111. //#define TX_BD_ABC 0x0002
  112. //// ----------------------------------------------------------------------
  113. //// TX Enhanced BD Bit Definitions
  114. //// ----------------------------------------------------------------------
  115. //#define TX_BD_INT 0x00000040
  116. //#define TX_BD_TS 0x00000020
  117. //#define TX_BD_PINS 0x00000010
  118. //#define TX_BD_IINS 0x00000008
  119. //#define TX_BD_TXE 0x00800000
  120. //#define TX_BD_UE 0x00200000
  121. //#define TX_BD_EE 0x00100000
  122. //#define TX_BD_FE 0x00080000
  123. //#define TX_BD_LCE 0x00040000
  124. //#define TX_BD_OE 0x00020000
  125. //#define TX_BD_TSE 0x00010000
  126. //#define TX_BD_BDU 0x00000080
  127. //// ----------------------------------------------------------------------
  128. //// RX Buffer Descriptor Bit Definitions
  129. //// ----------------------------------------------------------------------
  130. //// Offset 0 flags - status: Big Endian
  131. //#define RX_BD_E 0x0080
  132. //#define RX_BD_R01 0x0040
  133. //#define RX_BD_W 0x0020
  134. //#define RX_BD_R02 0x0010
  135. //#define RX_BD_L 0x0008
  136. //#define RX_BD_M 0x0001
  137. //#define RX_BD_BC 0x8000
  138. //#define RX_BD_MC 0x4000
  139. //#define RX_BD_LG 0x2000
  140. //#define RX_BD_NO 0x1000
  141. //#define RX_BD_CR 0x0400
  142. //#define RX_BD_OV 0x0200
  143. //#define RX_BD_TR 0x0100
  144. //// ----------------------------------------------------------------------
  145. //// RX Enhanced BD Bit Definitions
  146. //// ----------------------------------------------------------------------
  147. //#define RX_BD_ME 0x00000080
  148. //#define RX_BD_PE 0x00000004
  149. //#define RX_BD_CE 0x00000002
  150. //#define RX_BD_UC 0x00000001
  151. //#define RX_BD_INT 0x00008000
  152. //#define RX_BD_ICE 0x20000000
  153. //#define RX_BD_PCR 0x10000000
  154. //#define RX_BD_VLAN 0x04000000
  155. //#define RX_BD_IPV6 0x02000000
  156. //#define RX_BD_FRAG 0x01000000
  157. //#define RX_BD_BDU 0x00000080
  158. ///* MII Register Addresses */
  159. //#define PHY_BMCR (0x00)
  160. //#define PHY_BMSR (0x01)
  161. //#define PHY_PHYIDR1 (0x02)
  162. //#define PHY_PHYIDR2 (0x03)
  163. //#define PHY_ANAR (0x04)
  164. //#define PHY_ANLPAR (0x05)
  165. //#define PHY_ANLPARNP (0x05)
  166. //#define PHY_ANER (0x06)
  167. //#define PHY_ANNPTR (0x07)
  168. //#define PHY_PHYSTS (0x10)
  169. //#define PHY_MICR (0x11)
  170. //#define PHY_MISR (0x12)
  171. //#define PHY_PAGESEL (0x13)
  172. ///*TSI-EVB definition: National Semiconductor*/
  173. //#define PHY_PHYCR2 (0x1C)
  174. ///*TWR definition: Micrel*/
  175. //#define PHY_PHYCTRL1 (0x1E)
  176. //#define PHY_PHYCTRL2 (0x1F)
  177. ///* Bit definitions and macros for PHY_BMCR */
  178. //#define PHY_BMCR_RESET (0x8000)
  179. //#define PHY_BMCR_LOOP (0x4000)
  180. //#define PHY_BMCR_SPEED (0x2000)
  181. //#define PHY_BMCR_AN_ENABLE (0x1000)
  182. //#define PHY_BMCR_POWERDOWN (0x0800)
  183. //#define PHY_BMCR_ISOLATE (0x0400)
  184. //#define PHY_BMCR_AN_RESTART (0x0200)
  185. //#define PHY_BMCR_FDX (0x0100)
  186. //#define PHY_BMCR_COL_TEST (0x0080)
  187. ///* Bit definitions and macros for PHY_BMSR */
  188. //#define PHY_BMSR_100BT4 (0x8000)
  189. //#define PHY_BMSR_100BTX_FDX (0x4000)
  190. //#define PHY_BMSR_100BTX (0x2000)
  191. //#define PHY_BMSR_10BT_FDX (0x1000)
  192. //#define PHY_BMSR_10BT (0x0800)
  193. //#define PHY_BMSR_NO_PREAMBLE (0x0040)
  194. //#define PHY_BMSR_AN_COMPLETE (0x0020)
  195. //#define PHY_BMSR_REMOTE_FAULT (0x0010)
  196. //#define PHY_BMSR_AN_ABILITY (0x0008)
  197. //#define PHY_BMSR_LINK (0x0004)
  198. //#define PHY_BMSR_JABBER (0x0002)
  199. //#define PHY_BMSR_EXTENDED (0x0001)
  200. ///* Bit definitions and macros for PHY_ANAR */
  201. //#define PHY_ANAR_NEXT_PAGE (0x8001)
  202. //#define PHY_ANAR_REM_FAULT (0x2001)
  203. //#define PHY_ANAR_PAUSE (0x0401)
  204. //#define PHY_ANAR_100BT4 (0x0201)
  205. //#define PHY_ANAR_100BTX_FDX (0x0101)
  206. //#define PHY_ANAR_100BTX (0x0081)
  207. //#define PHY_ANAR_10BT_FDX (0x0041)
  208. //#define PHY_ANAR_10BT (0x0021)
  209. //#define PHY_ANAR_802_3 (0x0001)
  210. ///* Bit definitions and macros for PHY_ANLPAR */
  211. //#define PHY_ANLPAR_NEXT_PAGE (0x8000)
  212. //#define PHY_ANLPAR_ACK (0x4000)
  213. //#define PHY_ANLPAR_REM_FAULT (0x2000)
  214. //#define PHY_ANLPAR_PAUSE (0x0400)
  215. //#define PHY_ANLPAR_100BT4 (0x0200)
  216. //#define PHY_ANLPAR_100BTX_FDX (0x0100)
  217. //#define PHY_ANLPAR_100BTX (0x0080)
  218. //#define PHY_ANLPAR_10BTX_FDX (0x0040)
  219. //#define PHY_ANLPAR_10BT (0x0020)
  220. ///* Bit definitions of PHY_PHYSTS: National */
  221. //#define PHY_PHYSTS_MDIXMODE (0x4000)
  222. //#define PHY_PHYSTS_RX_ERR_LATCH (0x2000)
  223. //#define PHY_PHYSTS_POL_STATUS (0x1000)
  224. //#define PHY_PHYSTS_FALSECARRSENSLAT (0x0800)
  225. //#define PHY_PHYSTS_SIGNALDETECT (0x0400)
  226. //#define PHY_PHYSTS_PAGERECEIVED (0x0100)
  227. //#define PHY_PHYSTS_MIIINTERRUPT (0x0080)
  228. //#define PHY_PHYSTS_REMOTEFAULT (0x0040)
  229. //#define PHY_PHYSTS_JABBERDETECT (0x0020)
  230. //#define PHY_PHYSTS_AUTONEGCOMPLETE (0x0010)
  231. //#define PHY_PHYSTS_LOOPBACKSTATUS (0x0008)
  232. //#define PHY_PHYSTS_DUPLEXSTATUS (0x0004)
  233. //#define PHY_PHYSTS_SPEEDSTATUS (0x0002)
  234. //#define PHY_PHYSTS_LINKSTATUS (0x0001)
  235. ///* Bit definitions of PHY_PHYCR2 */
  236. //#define PHY_PHYCR2_SYNC_ENET_EN (0x2000)
  237. //#define PHY_PHYCR2_CLK_OUT_RXCLK (0x1000)
  238. //#define PHY_PHYCR2_BC_WRITE (0x0800)
  239. //#define PHY_PHYCR2_PHYTER_COMP (0x0400)
  240. //#define PHY_PHYCR2_SOFT_RESET (0x0200)
  241. //#define PHY_PHYCR2_CLK_OUT_DIS (0x0001)
  242. ///* Bit definition and macros for PHY_PHYCTRL1 */
  243. //#define PHY_PHYCTRL1_LED_MASK (0xC000)
  244. //#define PHY_PHYCTRL1_POLARITY (0x2000)
  245. //#define PHY_PHYCTRL1_MDX_STATE (0x0800)
  246. //#define PHY_PHYCTRL1_REMOTE_LOOP (0x0080)
  247. ///* Bit definition and macros for PHY_PHYCTRL2 */
  248. //#define PHY_PHYCTRL2_HP_MDIX (0x8000)
  249. //#define PHY_PHYCTRL2_MDIX_SELECT (0x4000)
  250. //#define PHY_PHYCTRL2_PAIRSWAP_DIS (0x2000)
  251. //#define PHY_PHYCTRL2_ENERGY_DET (0x1000)
  252. //#define PHY_PHYCTRL2_FORCE_LINK (0x0800)
  253. //#define PHY_PHYCTRL2_POWER_SAVING (0x0400)
  254. //#define PHY_PHYCTRL2_INT_LEVEL (0x0200)
  255. //#define PHY_PHYCTRL2_EN_JABBER (0x0100)
  256. //#define PHY_PHYCTRL2_AUTONEG_CMPLT (0x0080)
  257. //#define PHY_PHYCTRL2_ENABLE_PAUSE (0x0040)
  258. //#define PHY_PHYCTRL2_PHY_ISOLATE (0x0020)
  259. //#define PHY_PHYCTRL2_OP_MOD_MASK (0x001C)
  260. //#define PHY_PHYCTRL2_EN_SQE_TEST (0x0002)
  261. //#define PHY_PHYCTRL2_DATA_SCRAM_DIS (0x0001)
  262. ///* Bit definitions of PHY_PHYCTRL2_OP_MOD_MASK */
  263. //#define PHY_PHYCTRL2_OP_MOD_SHIFT 2
  264. //#define PHY_PHYCTRL2_MODE_OP_MOD_STILL_NEG 0
  265. //#define PHY_PHYCTRL2_MODE_OP_MOD_10MBPS_HD 1
  266. //#define PHY_PHYCTRL2_MODE_OP_MOD_100MBPS_HD 2
  267. //#define PHY_PHYCTRL2_MODE_OP_MOD_10MBPS_FD 5
  268. //#define PHY_PHYCTRL2_MODE_OP_MOD_100MBPS_FD 6
  269. //#define MII_TIMEOUT 0x1FF
  270. //#define MII_LINK_TIMEOUT 0x1FF
  271. //int drv_emac_hw_init(void);
  272. #endif