enet_001.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * @brief Ethernet control functions
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __ENET_001_H_
  32. #define __ENET_001_H_
  33. #include "sys_config.h"
  34. #include "cmsis.h"
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /** @defgroup IP_ENET_001 IP: Ethernet register block and driver
  39. * @ingroup IP_Drivers
  40. * @{
  41. */
  42. /**
  43. * @brief 10/100 MII & RMII Ethernet with timestamping register block structure
  44. */
  45. typedef struct { /*!< ETHERNET Structure */
  46. __IO uint32_t MAC_CONFIG; /*!< MAC configuration register */
  47. __IO uint32_t MAC_FRAME_FILTER; /*!< MAC frame filter */
  48. __IO uint32_t MAC_HASHTABLE_HIGH; /*!< Hash table high register */
  49. __IO uint32_t MAC_HASHTABLE_LOW; /*!< Hash table low register */
  50. __IO uint32_t MAC_MII_ADDR; /*!< MII address register */
  51. __IO uint32_t MAC_MII_DATA; /*!< MII data register */
  52. __IO uint32_t MAC_FLOW_CTRL; /*!< Flow control register */
  53. __IO uint32_t MAC_VLAN_TAG; /*!< VLAN tag register */
  54. __I uint32_t RESERVED0;
  55. __I uint32_t MAC_DEBUG; /*!< Debug register */
  56. __IO uint32_t MAC_RWAKE_FRFLT; /*!< Remote wake-up frame filter */
  57. __IO uint32_t MAC_PMT_CTRL_STAT; /*!< PMT control and status */
  58. __I uint32_t RESERVED1[2];
  59. __I uint32_t MAC_INTR; /*!< Interrupt status register */
  60. __IO uint32_t MAC_INTR_MASK; /*!< Interrupt mask register */
  61. __IO uint32_t MAC_ADDR0_HIGH; /*!< MAC address 0 high register */
  62. __IO uint32_t MAC_ADDR0_LOW; /*!< MAC address 0 low register */
  63. __I uint32_t RESERVED2[430];
  64. __IO uint32_t MAC_TIMESTP_CTRL; /*!< Time stamp control register */
  65. __IO uint32_t SUBSECOND_INCR; /*!< Sub-second increment register */
  66. __I uint32_t SECONDS; /*!< System time seconds register */
  67. __I uint32_t NANOSECONDS; /*!< System time nanoseconds register */
  68. __IO uint32_t SECONDSUPDATE; /*!< System time seconds update register */
  69. __IO uint32_t NANOSECONDSUPDATE; /*!< System time nanoseconds update register */
  70. __IO uint32_t ADDEND; /*!< Time stamp addend register */
  71. __IO uint32_t TARGETSECONDS; /*!< Target time seconds register */
  72. __IO uint32_t TARGETNANOSECONDS; /*!< Target time nanoseconds register */
  73. __IO uint32_t HIGHWORD; /*!< System time higher word seconds register */
  74. __I uint32_t TIMESTAMPSTAT; /*!< Time stamp status register */
  75. __IO uint32_t PPSCTRL; /*!< PPS control register */
  76. __I uint32_t AUXNANOSECONDS; /*!< Auxiliary time stamp nanoseconds register */
  77. __I uint32_t AUXSECONDS; /*!< Auxiliary time stamp seconds register */
  78. __I uint32_t RESERVED3[562];
  79. __IO uint32_t DMA_BUS_MODE; /*!< Bus Mode Register */
  80. __IO uint32_t DMA_TRANS_POLL_DEMAND; /*!< Transmit poll demand register */
  81. __IO uint32_t DMA_REC_POLL_DEMAND; /*!< Receive poll demand register */
  82. __IO uint32_t DMA_REC_DES_ADDR; /*!< Receive descriptor list address register */
  83. __IO uint32_t DMA_TRANS_DES_ADDR; /*!< Transmit descriptor list address register */
  84. __IO uint32_t DMA_STAT; /*!< Status register */
  85. __IO uint32_t DMA_OP_MODE; /*!< Operation mode register */
  86. __IO uint32_t DMA_INT_EN; /*!< Interrupt enable register */
  87. __I uint32_t DMA_MFRM_BUFOF; /*!< Missed frame and buffer overflow register */
  88. __IO uint32_t DMA_REC_INT_WDT; /*!< Receive interrupt watchdog timer register */
  89. __I uint32_t RESERVED4[8];
  90. __I uint32_t DMA_CURHOST_TRANS_DES; /*!< Current host transmit descriptor register */
  91. __I uint32_t DMA_CURHOST_REC_DES; /*!< Current host receive descriptor register */
  92. __I uint32_t DMA_CURHOST_TRANS_BUF; /*!< Current host transmit buffer address register */
  93. __I uint32_t DMA_CURHOST_REC_BUF; /*!< Current host receive buffer address register */
  94. } IP_ENET_001_Type;
  95. /**
  96. * @brief MAC_CONFIG register bit defines
  97. */
  98. #define MAC_CFG_RE (1 << 2) /*!< Receiver enable */
  99. #define MAC_CFG_TE (1 << 3) /*!< Transmitter Enable */
  100. #define MAC_CFG_DF (1 << 4) /*!< Deferral Check */
  101. #define MAC_CFG_BL(n) ((n) << 5) /*!< Back-Off Limit */
  102. #define MAC_CFG_ACS (1 << 7) /*!< Automatic Pad/CRC Stripping */
  103. #define MAC_CFG_LUD (1 << 8) /*!< Link Up/Down, 1 = up */
  104. #define MAC_CFG_DR (1 << 9) /*!< Disable Retry */
  105. #define MAC_CFG_IPC (1 << 10) /*!< Checksum Offload */
  106. #define MAC_CFG_DM (1 << 11) /*!< Duplex Mode, 1 = full, 0 = half */
  107. #define MAC_CFG_LM (1 << 12) /*!< Loopback Mode */
  108. #define MAC_CFG_DO (1 << 13) /*!< Disable Receive Own */
  109. #define MAC_CFG_FES (1 << 14) /*!< Speed, 1 = 100Mbps, 0 = 10Mbos */
  110. #define MAC_CFG_PS (1 << 15) /*!< Port select, must always be 1 */
  111. #define MAC_CFG_DCRS (1 << 16) /*!< Disable carrier sense during transmission */
  112. #define MAC_CFG_IFG(n) ((n) << 17) /*!< Inter-frame gap, 40..96, n incs by 8 */
  113. #define MAC_CFG_JE (1 << 20) /*!< Jumbo Frame Enable */
  114. #define MAC_CFG_JD (1 << 22) /*!< Jabber Disable */
  115. #define MAC_CFG_WD (1 << 23) /*!< Watchdog Disable */
  116. /**
  117. * @brief MAC_FRAME_FILTER register bit defines
  118. */
  119. #define MAC_FF_PR (1 << 0) /*!< Promiscuous Mode */
  120. #define MAC_FF_DAIF (1 << 3) /*!< DA Inverse Filtering */
  121. #define MAC_FF_PM (1 << 4) /*!< Pass All Multicast */
  122. #define MAC_FF_DBF (1 << 5) /*!< Disable Broadcast Frames */
  123. #define MAC_FF_PCF(n) ((n) << 6) /*!< Pass Control Frames, n = see user manual */
  124. #define MAC_FF_SAIF (1 << 8) /*!< SA Inverse Filtering */
  125. #define MAC_FF_SAF (1 << 9) /*!< Source Address Filter Enable */
  126. #define MAC_FF_RA (1UL << 31) /*!< Receive all */
  127. /**
  128. * @brief MAC_MII_ADDR register bit defines
  129. */
  130. #define MAC_MIIA_GB (1 << 0) /*!< MII busy */
  131. #define MAC_MIIA_W (1 << 1) /*!< MII write */
  132. #define MAC_MIIA_CR(n) ((n) << 2) /*!< CSR clock range, n = see manual */
  133. #define MAC_MIIA_GR(n) ((n) << 6) /*!< MII register. n = 0..31 */
  134. #define MAC_MIIA_PA(n) ((n) << 11) /*!< Physical layer address, n = 0..31 */
  135. /**
  136. * @brief MAC_MII_DATA register bit defines
  137. */
  138. #define MAC_MIID_GDMSK (0xFFFF) /*!< MII data mask */
  139. /**
  140. * @brief MAC_FLOW_CONTROL register bit defines
  141. */
  142. #define MAC_FC_FCB (1 << 0) /*!< Flow Control Busy/Backpressure Activate */
  143. #define MAC_FC_TFE (1 << 1) /*!< Transmit Flow Control Enable */
  144. #define MAC_FC_RFE (1 << 2) /*!< Receive Flow Control Enable */
  145. #define MAC_FC_UP (1 << 3) /*!< Unicast Pause Frame Detect */
  146. #define MAC_FC_PLT(n) ((n) << 4) /*!< Pause Low Threshold, n = see manual */
  147. #define MAC_FC_DZPQ (1 << 7) /*!< Disable Zero-Quanta Pause */
  148. #define MAC_FC_PT(n) ((n) << 16) /*!< Pause time */
  149. /**
  150. * @brief MAC_VLAN_TAG register bit defines
  151. */
  152. #define MAC_VT_VL(n) ((n) << 0) /*!< VLAN Tag Identifier for Receive Frames */
  153. #define MAC_VT_ETC (1 << 7) /*!< Enable 12-Bit VLAN Tag Comparison */
  154. /**
  155. * @brief MAC_PMT_CTRL_STAT register bit defines
  156. */
  157. #define MAC_PMT_PD (1 << 0) /*!< Power-down */
  158. #define MAC_PMT_MPE (1 << 1) /*!< Magic packet enable */
  159. #define MAC_PMT_WFE (1 << 2) /*!< Wake-up frame enable */
  160. #define MAC_PMT_MPR (1 << 5) /*!< Magic Packet Received */
  161. #define MAC_PMT_WFR (1 << 6) /*!< Wake-up Frame Received */
  162. #define MAC_PMT_GU (1 << 9) /*!< Global Unicast */
  163. #define MAC_PMT_WFFRPR (1UL << 31) /*!< Wake-up Frame Filter Register Pointer Reset */
  164. /**
  165. * @brief MAC_INTR_MASK register bit defines
  166. */
  167. #define MAC_IM_PMT (1 << 3) /*!< PMT Interrupt Mask */
  168. /**
  169. * @brief MAC_ADDR0_HIGH register bit defines
  170. */
  171. #define MAC_ADRH_MO (1UL << 31) /*!< Always 1 when writing register */
  172. /**
  173. * @brief MAC_ADDR0_HIGH register bit defines
  174. */
  175. #define MAC_ADRH_MO (1UL << 31) /*!< Always 1 when writing register */
  176. /**
  177. * @brief MAC_TIMESTAMP register bit defines
  178. */
  179. #define MAC_TS_TSENA (1 << 0) /*!< Time Stamp Enable */
  180. #define MAC_TS_TSCFUP (1 << 1) /*!< Time Stamp Fine or Coarse Update */
  181. #define MAC_TS_TSINIT (1 << 2) /*!< Time Stamp Initialize */
  182. #define MAC_TS_TSUPDT (1 << 3) /*!< Time Stamp Update */
  183. #define MAC_TS_TSTRIG (1 << 4) /*!< Time Stamp Interrupt Trigger Enable */
  184. #define MAC_TS_TSADDR (1 << 5) /*!< Addend Reg Update */
  185. #define MAC_TS_TSENAL (1 << 8) /*!< Enable Time Stamp for All Frames */
  186. #define MAC_TS_TSCTRL (1 << 9) /*!< Time Stamp Digital or Binary rollover control */
  187. #define MAC_TS_TSVER2 (1 << 10) /*!< Enable PTP packet snooping for version 2 format */
  188. #define MAC_TS_TSIPENA (1 << 11) /*!< Enable Time Stamp Snapshot for PTP over Ethernet frames */
  189. #define MAC_TS_TSIPV6E (1 << 12) /*!< Enable Time Stamp Snapshot for IPv6 frames */
  190. #define MAC_TS_TSIPV4E (1 << 13) /*!< Enable Time Stamp Snapshot for IPv4 frames */
  191. #define MAC_TS_TSEVNT (1 << 14) /*!< Enable Time Stamp Snapshot for Event Messages */
  192. #define MAC_TS_TSMSTR (1 << 15) /*!< Enable Snapshot for Messages Relevant to Master */
  193. #define MAC_TS_TSCLKT(n) ((n) << 16) /*!< Select the type of clock node, n = see menual */
  194. #define MAC_TS_TSENMA (1 << 18) /*!< Enable MAC address for PTP frame filtering */
  195. /**
  196. * @brief DMA_BUS_MODE register bit defines
  197. */
  198. #define DMA_BM_SWR (1 << 0) /*!< Software reset */
  199. #define DMA_BM_DA (1 << 1) /*!< DMA arbitration scheme, 1 = TX has priority over TX */
  200. #define DMA_BM_DSL(n) ((n) << 2) /*!< Descriptor skip length, n = see manual */
  201. #define DMA_BM_ATDS (1 << 7) /*!< Alternate (Enhanced) descriptor size */
  202. #define DMA_BM_PBL(n) ((n) << 8) /*!< Programmable burst length, n = see manual */
  203. #define DMA_BM_PR(n) ((n) << 14) /*!< Rx-to-Tx priority ratio, n = see manual */
  204. #define DMA_BM_FB (1 << 16) /*!< Fixed burst */
  205. #define DMA_BM_RPBL(n) ((n) << 17) /*!< RxDMA PBL, n = see manual */
  206. #define DMA_BM_USP (1 << 23) /*!< Use separate PBL */
  207. #define DMA_BM_PBL8X (1 << 24) /*!< 8 x PBL mode */
  208. #define DMA_BM_AAL (1 << 25) /*!< Address-aligned beats */
  209. #define DMA_BM_MB (1 << 26) /*!< Mixed burst */
  210. #define DMA_BM_TXPR (1 << 27) /*!< Transmit DMA has higher priority than receive DMA */
  211. /**
  212. * @brief DMA_STAT register bit defines
  213. */
  214. #define DMA_ST_TI (1 << 0) /*!< Transmit interrupt */
  215. #define DMA_ST_TPS (1 << 1) /*!< Transmit process stopped */
  216. #define DMA_ST_TU (1 << 2) /*!< Transmit buffer unavailable */
  217. #define DMA_ST_TJT (1 << 3) /*!< Transmit jabber timeout */
  218. #define DMA_ST_OVF (1 << 4) /*!< Receive overflow */
  219. #define DMA_ST_UNF (1 << 5) /*!< Transmit underflow */
  220. #define DMA_ST_RI (1 << 6) /*!< Receive interrupt */
  221. #define DMA_ST_RU (1 << 7) /*!< Receive buffer unavailable */
  222. #define DMA_ST_RPS (1 << 8) /*!< Received process stopped */
  223. #define DMA_ST_RWT (1 << 9) /*!< Receive watchdog timeout */
  224. #define DMA_ST_ETI (1 << 10) /*!< Early transmit interrupt */
  225. #define DMA_ST_FBI (1 << 13) /*!< Fatal bus error interrupt */
  226. #define DMA_ST_ERI (1 << 14) /*!< Early receive interrupt */
  227. #define DMA_ST_AIE (1 << 15) /*!< Abnormal interrupt summary */
  228. #define DMA_ST_NIS (1 << 16) /*!< Normal interrupt summary */
  229. #define DMA_ST_ALL (0x1E7FF) /*!< All interrupts */
  230. /**
  231. * @brief DMA_OP_MODE register bit defines
  232. */
  233. #define DMA_OM_SR (1 << 1) /*!< Start/stop receive */
  234. #define DMA_OM_OSF (1 << 2) /*!< Operate on second frame */
  235. #define DMA_OM_RTC(n) ((n) << 3) /*!< Receive threshold control, n = see manual */
  236. #define DMA_OM_FUF (1 << 6) /*!< Forward undersized good frames */
  237. #define DMA_OM_FEF (1 << 7) /*!< Forward error frames */
  238. #define DMA_OM_ST (1 << 13) /*!< Start/Stop Transmission Command */
  239. #define DMA_OM_TTC(n) ((n) << 14) /*!< Transmit threshold control, n = see manual */
  240. #define DMA_OM_FTF (1 << 20) /*!< Flush transmit FIFO */
  241. #define DMA_OM_TSF (1 << 21) /*!< Transmit store and forward */
  242. #define DMA_OM_DFF (1 << 24) /*!< Disable flushing of received frames */
  243. #define DMA_OM_RSF (1 << 25) /*!< Receive store and forward */
  244. #define DMA_OM_DT (1 << 26) /*!< Disable Dropping of TCP/IP Checksum Error Frames */
  245. /**
  246. * @brief DMA_INT_EN register bit defines
  247. */
  248. #define DMA_IE_TIE (1 << 0) /*!< Transmit interrupt enable */
  249. #define DMA_IE_TSE (1 << 1) /*!< Transmit stopped enable */
  250. #define DMA_IE_TUE (1 << 2) /*!< Transmit buffer unavailable enable */
  251. #define DMA_IE_TJE (1 << 3) /*!< Transmit jabber timeout enable */
  252. #define DMA_IE_OVE (1 << 4) /*!< Overflow interrupt enable */
  253. #define DMA_IE_UNE (1 << 5) /*!< Underflow interrupt enable */
  254. #define DMA_IE_RIE (1 << 6) /*!< Receive interrupt enable */
  255. #define DMA_IE_RUE (1 << 7) /*!< Receive buffer unavailable enable */
  256. #define DMA_IE_RSE (1 << 8) /*!< Received stopped enable */
  257. #define DMA_IE_RWE (1 << 9) /*!< Receive watchdog timeout enable */
  258. #define DMA_IE_ETE (1 << 10) /*!< Early transmit interrupt enable */
  259. #define DMA_IE_FBE (1 << 13) /*!< Fatal bus error enable */
  260. #define DMA_IE_ERE (1 << 14) /*!< Early receive interrupt enable */
  261. #define DMA_IE_AIE (1 << 15) /*!< Abnormal interrupt summary enable */
  262. #define DMA_IE_NIE (1 << 16) /*!< Normal interrupt summary enable */
  263. /**
  264. * @brief DMA_MFRM_BUFOF register bit defines
  265. */
  266. #define DMA_MFRM_FMCMSK (0xFFFF) /*!< Number of frames missed mask */
  267. #define DMA_MFRM_OC (1 << 16) /*!< Overflow bit for missed frame counter */
  268. #define DMA_MFRM_FMA(n) (((n) & 0x0FFE0000) >> 17) /*!< Number of frames missed by the application mask/shift */
  269. #define DMA_MFRM_OF (1 << 28) /*!< Overflow bit for FIFO overflow counter */
  270. /**
  271. * @brief Common TRAN_DESC_T and TRAN_DESC_ENH_T CTRLSTAT field bit defines
  272. */
  273. #define TDES_DB (1 << 0) /*!< Deferred Bit */
  274. #define TDES_UF (1 << 1) /*!< Underflow Error */
  275. #define TDES_ED (1 << 2) /*!< Excessive Deferral */
  276. #define TDES_CCMSK(n) (((n) & 0x000000F0) >> 3)/*!< CC: Collision Count (Status field) mask and shift */
  277. #define TDES_VF (1 << 7) /*!< VLAN Frame */
  278. #define TDES_EC (1 << 8) /*!< Excessive Collision */
  279. #define TDES_LC (1 << 9) /*!< Late Collision */
  280. #define TDES_NC (1 << 10) /*!< No Carrier */
  281. #define TDES_LCAR (1 << 11) /*!< Loss of Carrier */
  282. #define TDES_IPE (1 << 12) /*!< IP Payload Error */
  283. #define TDES_FF (1 << 13) /*!< Frame Flushed */
  284. #define TDES_JT (1 << 14) /*!< Jabber Timeout */
  285. #define TDES_ES (1 << 15) /*!< Error Summary */
  286. #define TDES_IHE (1 << 16) /*!< IP Header Error */
  287. #define TDES_TTSS (1 << 17) /*!< Transmit Timestamp Status */
  288. #define TDES_OWN (1UL << 31) /*!< Own Bit */
  289. /**
  290. * @brief TRAN_DESC_ENH_T only CTRLSTAT field bit defines
  291. */
  292. #define TDES_ENH_IC (1UL << 30) /*!< Interrupt on Completion, enhanced descriptor */
  293. #define TDES_ENH_LS (1 << 29) /*!< Last Segment, enhanced descriptor */
  294. #define TDES_ENH_FS (1 << 28) /*!< First Segment, enhanced descriptor */
  295. #define TDES_ENH_DC (1 << 27) /*!< Disable CRC, enhanced descriptor */
  296. #define TDES_ENH_DP (1 << 26) /*!< Disable Pad, enhanced descriptor */
  297. #define TDES_ENH_TTSE (1 << 25) /*!< Transmit Timestamp Enable, enhanced descriptor */
  298. #define TDES_ENH_CIC(n) ((n) << 22) /*!< Checksum Insertion Control, enhanced descriptor */
  299. #define TDES_ENH_TER (1 << 21) /*!< Transmit End of Ring, enhanced descriptor */
  300. #define TDES_ENH_TCH (1 << 20) /*!< Second Address Chained, enhanced descriptor */
  301. /**
  302. * @brief TRAN_DESC_T only BSIZE field bit defines
  303. */
  304. #define TDES_NORM_IC (1UL << 31) /*!< Interrupt on Completion, normal descriptor */
  305. #define TDES_NORM_FS (1 << 30) /*!< First Segment, normal descriptor */
  306. #define TDES_NORM_LS (1 << 29) /*!< Last Segment, normal descriptor */
  307. #define TDES_NORM_CIC(n) ((n) << 27) /*!< Checksum Insertion Control, normal descriptor */
  308. #define TDES_NORM_DC (1 << 26) /*!< Disable CRC, normal descriptor */
  309. #define TDES_NORM_TER (1 << 25) /*!< Transmit End of Ring, normal descriptor */
  310. #define TDES_NORM_TCH (1 << 24) /*!< Second Address Chained, normal descriptor */
  311. #define TDES_NORM_DP (1 << 23) /*!< Disable Pad, normal descriptor */
  312. #define TDES_NORM_TTSE (1 << 22) /*!< Transmit Timestamp Enable, normal descriptor */
  313. #define TDES_NORM_BS2(n) (((n) & 0x3FF) << 11) /*!< Buffer 2 size, normal descriptor */
  314. #define TDES_NORM_BS1(n) (((n) & 0x3FF) << 0) /*!< Buffer 1 size, normal descriptor */
  315. /**
  316. * @brief TRAN_DESC_ENH_T only BSIZE field bit defines
  317. */
  318. #define TDES_ENH_BS2(n) (((n) & 0xFFF) << 16) /*!< Buffer 2 size, enhanced descriptor */
  319. #define TDES_ENH_BS1(n) (((n) & 0xFFF) << 0) /*!< Buffer 1 size, enhanced descriptor */
  320. /**
  321. * @brief Common REC_DESC_T and REC_DESC_ENH_T STATUS field bit defines
  322. */
  323. #define RDES_ESA (1 << 0) /*!< Extended Status Available/Rx MAC Address */
  324. #define RDES_CE (1 << 1) /*!< CRC Error */
  325. #define RDES_DRE (1 << 2) /*!< Dribble Bit Error */
  326. #define RDES_RE (1 << 3) /*!< Receive Error */
  327. #define RDES_RWT (1 << 4) /*!< Receive Watchdog Timeout */
  328. #define RDES_FT (1 << 5) /*!< Frame Type */
  329. #define RDES_LC (1 << 6) /*!< Late Collision */
  330. #define RDES_TSA (1 << 7) /*!< Timestamp Available/IP Checksum Error (Type1) /Giant Frame */
  331. #define RDES_LS (1 << 8) /*!< Last Descriptor */
  332. #define RDES_FS (1 << 9) /*!< First Descriptor */
  333. #define RDES_VLAN (1 << 10) /*!< VLAN Tag */
  334. #define RDES_OE (1 << 11) /*!< Overflow Error */
  335. #define RDES_LE (1 << 12) /*!< Length Error */
  336. #define RDES_SAF (1 << 13) /*!< Source Address Filter Fail */
  337. #define RDES_DE (1 << 14) /*!< Descriptor Error */
  338. #define RDES_ES (1 << 15) /*!< ES: Error Summary */
  339. #define RDES_FLMSK(n) (((n) & 0x3FFF0000) >> 16)/*!< Frame Length mask and shift */
  340. #define RDES_AFM (1 << 30) /*!< Destination Address Filter Fail */
  341. #define RDES_OWN (1UL << 31) /*!< Own Bit */
  342. /**
  343. * @brief Common REC_DESC_T and REC_DESC_ENH_T CTRL field bit defines
  344. */
  345. #define RDES_DINT (1UL << 31) /*!< Disable interrupt on completion */
  346. /**
  347. * @brief REC_DESC_T pnly CTRL field bit defines
  348. */
  349. #define RDES_NORM_RER (1 << 25) /*!< Receive End of Ring, normal descriptor */
  350. #define RDES_NORM_RCH (1 << 24) /*!< Second Address Chained, normal descriptor */
  351. #define RDES_NORM_BS2(n) (((n) & 0x3FF) << 11) /*!< Buffer 2 size, normal descriptor */
  352. #define RDES_NORM_BS1(n) (((n) & 0x3FF) << 0) /*!< Buffer 1 size, normal descriptor */
  353. /**
  354. * @brief REC_DESC_ENH_T only CTRL field bit defines
  355. */
  356. #define RDES_ENH_RER (1 << 15) /*!< Receive End of Ring, enhanced descriptor */
  357. #define RDES_ENH_RCH (1 << 14) /*!< Second Address Chained, enhanced descriptor */
  358. #define RDES_ENH_BS2(n) (((n) & 0xFFF) << 16) /*!< Buffer 2 size, enhanced descriptor */
  359. #define RDES_ENH_BS1(n) (((n) & 0xFFF) << 0) /*!< Buffer 1 size, enhanced descriptor */
  360. /**
  361. * @brief REC_DESC_ENH_T only EXTSTAT field bit defines
  362. */
  363. #define RDES_ENH_IPPL(n) (((n) & 0x7) >> 2) /*!< IP Payload Type mask and shift, enhanced descripto */
  364. #define RDES_ENH_IPHE (1 << 3) /*!< IP Header Error, enhanced descripto */
  365. #define RDES_ENH_IPPLE (1 << 4) /*!< IP Payload Error, enhanced descripto */
  366. #define RDES_ENH_IPCSB (1 << 5) /*!< IP Checksum Bypassed, enhanced descripto */
  367. #define RDES_ENH_IPV4 (1 << 6) /*!< IPv4 Packet Received, enhanced descripto */
  368. #define RDES_ENH_IPV6 (1 << 7) /*!< IPv6 Packet Received, enhanced descripto */
  369. #define RDES_ENH_MTMSK(n) (((n) & 0xF) >> 8) /*!< Message Type mask and shift, enhanced descripto */
  370. /**
  371. * @brief Maximum size of an ethernet buffer
  372. */
  373. #define EMAC_ETH_MAX_FLEN (1536)
  374. /**
  375. * @brief Structure of a transmit descriptor (without timestamp)
  376. */
  377. typedef struct {
  378. __IO uint32_t CTRLSTAT; /*!< TDES control and status word */
  379. __IO uint32_t BSIZE; /*!< Buffer 1/2 byte counts */
  380. __IO uint32_t B1ADD; /*!< Buffer 1 address */
  381. __IO uint32_t B2ADD; /*!< Buffer 2 or next descriptor address */
  382. } IP_ENET_001_TXDESC_Type;
  383. /**
  384. * @brief Structure of a enhanced transmit descriptor (with timestamp)
  385. */
  386. typedef struct {
  387. __IO uint32_t CTRLSTAT; /*!< TDES control and status word */
  388. __IO uint32_t BSIZE; /*!< Buffer 1/2 byte counts */
  389. __IO uint32_t B1ADD; /*!< Buffer 1 address */
  390. __IO uint32_t B2ADD; /*!< Buffer 2 or next descriptor address */
  391. __IO uint32_t TDES4; /*!< Reserved */
  392. __IO uint32_t TDES5; /*!< Reserved */
  393. __IO uint32_t TTSL; /*!< Timestamp value low */
  394. __IO uint32_t TTSH; /*!< Timestamp value high */
  395. } IP_ENET_001_ENHTXDESC_Type;
  396. /**
  397. * @brief Structure of a receive descriptor (without timestamp)
  398. */
  399. typedef struct {
  400. __IO uint32_t STATUS; /*!< RDES status word */
  401. __IO uint32_t CTRL; /*!< Buffer 1/2 byte counts and control */
  402. __IO uint32_t B1ADD; /*!< Buffer 1 address */
  403. __IO uint32_t B2ADD; /*!< Buffer 2 or next descriptor address */
  404. } IP_ENET_001_RXDESC_Type;
  405. /**
  406. * @brief Structure of a enhanced receive descriptor (with timestamp)
  407. */
  408. typedef struct {
  409. __IO uint32_t STATUS; /*!< RDES status word */
  410. __IO uint32_t CTRL; /*!< Buffer 1/2 byte counts */
  411. __IO uint32_t B1ADD; /*!< Buffer 1 address */
  412. __IO uint32_t B2ADD; /*!< Buffer 2 or next descriptor address */
  413. __IO uint32_t EXTSTAT; /*!< Extended Status */
  414. __IO uint32_t RDES5; /*!< Reserved */
  415. __IO uint32_t RTSL; /*!< Timestamp value low */
  416. __IO uint32_t RTSH; /*!< Timestamp value high */
  417. } IP_ENET_001_ENHRXDESC_Type;
  418. /**
  419. * @brief Resets the ethernet interface
  420. * @param LPC_ENET : Pointer to selected ENET peripheral
  421. * @return Nothing
  422. * Resets the ethernet interface. This should be called prior to
  423. * IP_ENET_Init with a small delay after this call.
  424. */
  425. void IP_ENET_Reset(IP_ENET_001_Type *LPC_ENET);
  426. /**
  427. * @brief Sets the address of the interface
  428. * @param LPC_ENET : Pointer to selected ENET peripheral
  429. * @param macAddr : Pointer to the 6 bytes used for the MAC address
  430. * @return Nothing
  431. */
  432. void IP_ENET_SetADDR(IP_ENET_001_Type *LPC_ENET, const uint8_t *macAddr);
  433. /**
  434. * @brief Initialize ethernet interface
  435. * @param LPC_ENET : Pointer to selected ENET peripheral
  436. * @return Nothing
  437. * Performs basic initialization of the ethernet interface in a default
  438. * state. This is enough to place the interface in a usable state, but
  439. * may require more setup outside this function.
  440. */
  441. void IP_ENET_Init(IP_ENET_001_Type *LPC_ENET);
  442. /**
  443. * @brief Sets up the PHY link clock divider and PHY address
  444. * @param LPC_ENET : Pointer to selected ENET peripheral
  445. * @param div : Divider value, may vary per chip
  446. * @param addr : PHY address, used with MII read and write
  447. * @return Nothing
  448. */
  449. void IP_ENET_SetupMII(IP_ENET_001_Type *LPC_ENET, uint32_t div, uint8_t addr);
  450. /**
  451. * @brief De-initialize the ethernet interface
  452. * @param LPC_ENET : Pointer to selected ENET peripheral
  453. * @return Nothing
  454. */
  455. void IP_ENET_DeInit(IP_ENET_001_Type *LPC_ENET);
  456. /**
  457. * @brief Starts a PHY write via the MII
  458. * @param LPC_ENET : Pointer to selected ENET peripheral
  459. * @param reg : PHY register to write
  460. * @param data : Data to write to PHY register
  461. * @return Nothing
  462. * Start a PHY write operation. Does not block, requires calling
  463. * IP_ENET_IsMIIBusy to determine when write is complete.
  464. */
  465. void IP_ENET_StartMIIWrite(IP_ENET_001_Type *LPC_ENET, uint8_t reg, uint16_t data);
  466. /**
  467. * @brief Starts a PHY read via the MII
  468. * @param LPC_ENET : Pointer to selected ENET peripheral
  469. * @param reg : PHY register to read
  470. * @return Nothing
  471. * Start a PHY read operation. Does not block, requires calling
  472. * IP_ENET_IsMIIBusy to determine when read is complete and calling
  473. * IP_ENET_ReadMIIData to get the data.
  474. */
  475. void IP_ENET_StartMIIRead(IP_ENET_001_Type *LPC_ENET, uint8_t reg);
  476. /**
  477. * @brief Returns MII link (PHY) busy status
  478. * @param LPC_ENET : Pointer to selected ENET peripheral
  479. * @return Returns true if busy, otherwise false
  480. */
  481. bool IP_ENET_IsMIIBusy(IP_ENET_001_Type *LPC_ENET);
  482. /**
  483. * @brief Returns the value read from the PHY
  484. * @param LPC_ENET : Pointer to selected ENET peripheral
  485. * @return Read value from PHY
  486. */
  487. STATIC INLINE uint16_t IP_ENET_ReadMIIData(IP_ENET_001_Type *LPC_ENET)
  488. {
  489. return LPC_ENET->MAC_MII_DATA;
  490. }
  491. /**
  492. * @brief Enables or disables ethernet transmit
  493. * @param LPC_ENET : Pointer to selected ENET peripheral
  494. * @param Enable : true to enable transmit, false to disable
  495. * @return Nothing
  496. */
  497. void IP_ENET_TXEnable(IP_ENET_001_Type *LPC_ENET, bool Enable);
  498. /**
  499. * @brief Enables or disables ethernet packet reception
  500. * @param LPC_ENET : Pointer to selected ENET peripheral
  501. * @param Enable : true to enable receive, false to disable
  502. * @return Nothing
  503. */
  504. void IP_ENET_RXEnable(IP_ENET_001_Type *LPC_ENET, bool Enable);
  505. /**
  506. * @brief Sets full or half duplex for the interface
  507. * @param LPC_ENET : Pointer to selected ENET peripheral
  508. * @param full : true to selected full duplex, false for half
  509. * @return Nothing
  510. */
  511. void IP_ENET_SetDuplex(IP_ENET_001_Type *LPC_ENET, bool full);
  512. /**
  513. * @brief Sets speed for the interface
  514. * @param LPC_ENET : Pointer to selected ENET peripheral
  515. * @param speed100 : true to select 100Mbps mode, false for 10Mbps
  516. * @return Nothing
  517. */
  518. void IP_ENET_SetSpeed(IP_ENET_001_Type *LPC_ENET, bool speed100);
  519. /**
  520. * @brief Configures the initial ethernet descriptors
  521. * @param LPC_ENET : Pointer to selected ENET peripheral
  522. * @param pTXDescs : Pointer to TX descriptor list
  523. * @param pRXDescs : Pointer to RX descriptor list
  524. * @return Nothing
  525. */
  526. void IP_ENET_InitDescriptors(IP_ENET_001_Type *LPC_ENET,
  527. IP_ENET_001_ENHTXDESC_Type *pTXDescs, IP_ENET_001_ENHRXDESC_Type *pRXDescs);
  528. /**
  529. * @brief Starts receive polling of RX descriptors
  530. * @param LPC_ENET : Pointer to selected ENET peripheral
  531. * @return Nothing
  532. */
  533. STATIC INLINE void IP_ENET_RXStart(IP_ENET_001_Type *LPC_ENET)
  534. {
  535. /* Start receive polling */
  536. LPC_ENET->DMA_REC_POLL_DEMAND = 1;
  537. }
  538. /**
  539. * @brief Starts transmit polling of TX descriptors
  540. * @param LPC_ENET : Pointer to selected ENET peripheral
  541. * @return Nothing
  542. */
  543. STATIC INLINE void IP_ENET_TXStart(IP_ENET_001_Type *LPC_ENET)
  544. {
  545. /* Start transmit polling */
  546. LPC_ENET->DMA_TRANS_POLL_DEMAND = 1;
  547. }
  548. /**
  549. * @}
  550. */
  551. #ifdef __cplusplus
  552. }
  553. #endif
  554. #endif /* __ENET_001_H_ */