EMAC_LPC18xx.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /* --------------------------------------------------------------------------
  2. * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * $Date: 02. March 2016
  19. * $Revision: V2.6
  20. *
  21. * Project: Ethernet Media Access (MAC) Definitions for NXP LPC18xx
  22. * -------------------------------------------------------------------------- */
  23. #ifndef __EMAC_LPC18XX_H
  24. #define __EMAC_LPC18XX_H
  25. #include <string.h>
  26. #include "Driver_ETH_MAC.h"
  27. #include "RTE_Device.h"
  28. #include "RTE_Components.h"
  29. #include "cmsis_os.h"
  30. #include "LPC18xx.h"
  31. #include "SCU_LPC18xx.h"
  32. #if (defined(RTE_Drivers_ETH_MAC0) && !RTE_ENET)
  33. #error "Ethernet not configured in RTE_Device.h!"
  34. #endif
  35. #if (RTE_ENET_MII && RTE_ENET_RMII)
  36. #error "Ethernet interface configuration in RTE_Device.h is invalid!"
  37. #endif
  38. #define ENET LPC_ETHERNET
  39. /* Clock Control Unit register */
  40. #define CCU_CLK_CFG_RUN (1 << 0)
  41. #define CCU_CLK_CFG_AUTO (1 << 1)
  42. #define CCU_CLK_STAT_RUN (1 << 0)
  43. #define CLK_SRC_PLL1 0x09 // EMAC clock source
  44. /* CREG6 Control Register */
  45. #define EMAC_CREG6_ETH_MASK 0x00000007 // EMAC mode mask
  46. #define EMAC_CREG6_ETH_MII (0x0 << 0) // EMAC mode MII
  47. #define EMAC_CREG6_ETH_RMII (0x4 << 0) // EMAC mode RMII
  48. /* EMAC reset value for RGU */
  49. #define RGU_RESET_EMAC (1 << 22) // EMAC reset
  50. /* EMAC Driver state flags */
  51. #define EMAC_FLAG_INIT (1 << 0) // Driver initialized
  52. #define EMAC_FLAG_POWER (1 << 1) // Driver power on
  53. /* TDES0 Descriptor TX Packet Control/Status */
  54. #define EMAC_TDES0_OWN 0x80000000 // Own bit 1=DMA, 0=CPU
  55. #define EMAC_TDES0_IC 0x40000000 // Interrupt on completition
  56. #define EMAC_TDES0_LS 0x20000000 // Last segment
  57. #define EMAC_TDES0_FS 0x10000000 // First segment
  58. #define EMAC_TDES0_DC 0x08000000 // Disable CRC
  59. #define EMAC_TDES0_DP 0x04000000 // Disable pad
  60. #define EMAC_TDES0_TTSE 0x02000000 // Transmit time stamp enable
  61. #define EMAC_TDES0_TER 0x00200000 // Transmit end of ring
  62. #define EMAC_TDES0_TCH 0x00100000 // Second address chained
  63. #define EMAC_TDES0_TTSS 0x00020000 // Transmit time stamp status
  64. #define EMAC_TDES0_IHE 0x00010000 // IP header error
  65. #define EMAC_TDES0_ES 0x00008000 // Error summary
  66. #define EMAC_TDES0_JT 0x00004000 // Jabber timeout
  67. #define EMAC_TDES0_FF 0x00002000 // Frame flushed
  68. #define EMAC_TDES0_IPE 0x00001000 // IP payload error
  69. #define EMAC_TDES0_LOC 0x00000800 // Loss of carrier
  70. #define EMAC_TDES0_NC 0x00000400 // No carrier
  71. #define EMAC_TDES0_LC 0x00000200 // Late collision
  72. #define EMAC_TDES0_EC 0x00000100 // Excessive collision
  73. #define EMAC_TDES0_VF 0x00000080 // VLAN frame
  74. #define EMAC_TDES0_CC 0x00000078 // Collision count
  75. #define EMAC_TDES0_ED 0x00000004 // Excessive deferral
  76. #define EMAC_TDES0_UF 0x00000002 // Underflow error
  77. #define EMAC_TDES0_DB 0x00000001 // Deferred bit
  78. /* TDES1 Descriptor TX Packet Control */
  79. #define EMAC_TDES1_TBS2 0x1FFF0000 // Transmit buffer 2 size
  80. #define EMAC_TDES1_TBS1 0x00001FFF // Transmit buffer 1 size
  81. /* RDES0 Descriptor RX Packet Status */
  82. #define EMAC_RDES0_OWN 0x80000000 // Own bit 1=DMA, 0=CPU
  83. #define EMAC_RDES0_AFM 0x40000000 // Destination address filter fail
  84. #define EMAC_RDES0_FL 0x3FFF0000 // Frame length mask
  85. #define EMAC_RDES0_ES 0x00008000 // Error summary
  86. #define EMAC_RDES0_DE 0x00004000 // Descriptor error
  87. #define EMAC_RDES0_SAF 0x00002000 // Source address filter fail
  88. #define EMAC_RDES0_LE 0x00001000 // Length error
  89. #define EMAC_RDES0_OE 0x00000800 // Overflow error
  90. #define EMAC_RDES0_VLAN 0x00000400 // VLAN tag
  91. #define EMAC_RDES0_FS 0x00000200 // First descriptor
  92. #define EMAC_RDES0_LS 0x00000100 // Last descriptor
  93. #define EMAC_RDES0_TSA 0x00000080 // Timestamp available
  94. #define EMAC_RDES0_LC 0x00000040 // Late collision
  95. #define EMAC_RDES0_FT 0x00000020 // Frame type
  96. #define EMAC_RDES0_RWT 0x00000010 // Receive watchdog timeout
  97. #define EMAC_RDES0_RE 0x00000008 // Receive error
  98. #define EMAC_RDES0_DBE 0x00000004 // Dribble bit error
  99. #define EMAC_RDES0_CE 0x00000002 // CRC error
  100. #define EMAC_RDES0_ESA 0x00000001 // Extended Status/Rx MAC address
  101. /* RDES1 Descriptor RX Packet Control */
  102. #define EMAC_RDES1_RBS2 0x1FFF0000 // Receive buffer 2 size
  103. #define EMAC_RDES1_RER 0x00008000 // Receive end of ring
  104. #define EMAC_RDES1_RCH 0x00004000 // Second address chained
  105. #define EMAC_RDES1_RBS1 0x00001FFF // Receive buffer 1 size
  106. /* MAC Configuration Register */
  107. #define EMAC_MCR_WD 0x00800000 // Watchdog disable
  108. #define EMAC_MCR_JD 0x00400000 // Jabber disable
  109. #define EMAC_MCR_JE 0x00100000 // Jumbo frame enable
  110. #define EMAC_MCR_IFG 0x000E0000 // Inter-frame gap mask
  111. #define EMAC_MCR_DCRS 0x00010000 // Disable carrier sense during Tx
  112. #define EMAC_MCR_PS 0x00008000 // Port select
  113. #define EMAC_MCR_FES 0x00004000 // Speed
  114. #define EMAC_MCR_DO 0x00002000 // Disable receive own
  115. #define EMAC_MCR_LM 0x00001000 // Loopback mode
  116. #define EMAC_MCR_DM 0x00000800 // Duplex mode
  117. #define EMAC_MCR_DR 0x00000200 // Disable Retry
  118. #define EMAC_MCR_ACS 0x00000080 // Automatic pad/CRC stripping
  119. #define EMAC_MCR_BL 0x00000060 // Back-off limit mask
  120. #define EMAC_MCR_DF 0x00000010 // Deferral check
  121. #define EMAC_MCR_TE 0x00000008 // Transmitter enable
  122. #define EMAC_MCR_RE 0x00000004 // Receiver enable
  123. /* MAC Frame Filter Register */
  124. #define EMAC_MFFR_RA 0x80000000 // Receive all
  125. #define EMAC_MFFR_HPF 0x00000400 // Hash or perfect filter
  126. #define EMAC_MFFR_PCF 0x000000C0 // Pass control frames mask
  127. #define EMAC_MFFR_DBF 0x00000020 // Disable broadcast frames
  128. #define EMAC_MFFR_PAM 0x00000010 // Pass all multicast
  129. #define EMAC_MFFR_DAIF 0x00000008 // Dest. address inverse filtering
  130. #define EMAC_MFFR_HMC 0x00000004 // Hash multicast
  131. #define EMAC_MFFR_HUC 0x00000002 // Hash unicast
  132. #define EMAC_MFFR_PR 0x00000001 // Promiscuous mode
  133. /* MAC MII Address Register */
  134. #define EMAC_MMAR_PA 0x0000F800 // PHY address mask
  135. #define EMAC_MMAR_GR 0x000007C0 // MII register address mask
  136. #define EMAC_MMAR_CR 0x0000003C // Clock range mask
  137. #define EMAC_MMAR_W 0x00000002 // MII write
  138. #define EMAC_MMAR_GB 0x00000001 // MII busy
  139. /* MAC MII Address Register Clock Range */
  140. #define EMAC_MMAR_CR_Div102 (0x4 << 2) // Clk_M3_Ethernet: 150-250 MHz
  141. #define EMAC_MMAR_CR_Div62 (0x1 << 2) // Clk_M3_Ethernet: 100-150 MHz
  142. #define EMAC_MMAR_CR_Div42 (0x0 << 2) // Clk_M3_Ethernet: 60-100 MHz
  143. #define EMAC_MMAR_CR_Div26 (0x3 << 2) // Clk_M3_Ethernet: 35- 60 MHz
  144. #define EMAC_MMAR_CR_Div16 (0x2 << 2) // Clk_M3_Ethernet: 20- 35 MHz
  145. /* MAC MII Data Register */
  146. #define EMAC_MMDR_GD 0x0000FFFF // MII 16-bit rw data
  147. /* MAC Flow Control Register */
  148. #define EMAC_MFCR_PT 0xFFFF0000 // Pause time mask
  149. #define EMAC_MFCR_DZPQ 0x00000080 // Disable zero-quanta pause
  150. #define EMAC_MFCR_PLT 0x00000030 // Pause low threshold
  151. #define EMAC_MFCR_UP 0x00000008 // Unicaste pause frame detect
  152. #define EMAC_MFCR_RFE 0x00000004 // Receive flow control enable
  153. #define EMAC_MFCR_TFE 0x00000002 // Transmit flow control enable
  154. #define EMAC_MFCR_FCB 0x00000001 // Flow ctrl busy/backpressure activate
  155. /* MAC Power Management Control and Status Register */
  156. #define EMAC_PMTR_WFFRPR 0x80000000 // Wake-up frame filter register pointer reset
  157. #define EMAC_PMTR_GU 0x00000200 // Global unicast wake-up enable
  158. #define EMAC_PMTR_WFR 0x00000040 // Wake-up frame received status
  159. #define EMAC_PMTR_MPR 0x00000020 // Magic packet received status
  160. #define EMAC_PMTR_WFE 0x00000004 // Wake-up frame enable
  161. #define EMAC_PMTR_MPE 0x00000002 // Magic packet enable
  162. #define EMAC_PMTR_PD 0x00000001 // Power-down
  163. /* MAC Interrupt Status Register */
  164. #define EMAC_MISR_TS 0x00000200 // Timestamp interrupt status
  165. #define EMAC_MISR_PMT 0x00000008 // PMT interrupt status
  166. /* MAC Interrupt Mask Register */
  167. #define EMAC_MIMR_TSIM 0x00000200 // Timestamp interrupt mask
  168. #define EMAC_MIMR_PMTIM 0x00000008 // PMT interrupt mask
  169. /* MAC Timestamp Control Register */
  170. #define EMAC_MTCR_TSENMA 0x00040000 // Enable MAC address for PTP frame filtering
  171. #define EMAC_MTCR_TSCLKT 0x00030000 // Select the type of clock node, see manual
  172. #define EMAC_MTCR_TSMSTR 0x00008000 // Enable Snapshot for messages relevant to master
  173. #define EMAC_MTCR_TSEVNT 0x00004000 // Enable TS snapshot for event messages
  174. #define EMAC_MTCR_TSIPV4E 0x00002000 // Enable TS snapshot for IPv4 frames
  175. #define EMAC_MTCR_TSIPV6E 0x00001000 // Enable TS snapshot for IPv6 frames
  176. #define EMAC_MTCR_TSIPENA 0x00000800 // Enable TS snapshot for PTP over ethernet frames
  177. #define EMAC_MTCR_TSVER2 0x00000400 // PTP packet snooping for version 2 format
  178. #define EMAC_MTCR_TSCTRL 0x00000200 // Timestamp digital or binary rollover control
  179. #define EMAC_MTCR_TSENAL 0x00000100 // Enable timestamp for all frames
  180. #define EMAC_MTCR_TSADDR 0x00000020 // Addend register update
  181. #define EMAC_MTCR_TSTRIG 0x00000010 // Timestamp interrupt trigger enable
  182. #define EMAC_MTCR_TSUPDT 0x00000008 // Timestamp update
  183. #define EMAC_MTCR_TSINIT 0x00000004 // Timestamp initialize
  184. #define EMAC_MTCR_TSCFUP 0x00000002 // Timestamp fine or coarse update
  185. #define EMAC_MTCR_TSENA 0x00000001 // Timestamp enable
  186. /* MAC Timestamp Status Register */
  187. #define EMAC_MTSR_TSTARGT 0x00000002 // Timestamp target/alarm reached
  188. #define EMAC_MTSR_TSSOVF 0x00000001 // Timestamp seconds overflow
  189. /* DMA Status Register */
  190. #define EMAC_DSR_EB3 0x02000000 // Error bit 3
  191. #define EMAC_DSR_EB2 0x01000000 // Error bit 2
  192. #define EMAC_DSR_EB1 0x00800000 // Error bit 1
  193. #define EMAC_DSR_TS 0x00700000 // Transmit process state
  194. #define EMAC_DSR_RS 0x000E0000 // Receive process state
  195. #define EMAC_DSR_NIS 0x00010000 // Normal interrupt summary
  196. #define EMAC_DSR_AIS 0x00008000 // Abnormal interrupt summary
  197. #define EMAC_DSR_ERI 0x00004000 // Early receive interrupt
  198. #define EMAC_DSR_FBI 0x00002000 // Fatal bus error interrupt
  199. #define EMAC_DSR_ETI 0x00000400 // Early transmit interrupt
  200. #define EMAC_DSR_RWT 0x00000200 // Receive watchdog timeout
  201. #define EMAC_DSR_RPS 0x00000100 // Receive process stopped
  202. #define EMAC_DSR_RU 0x00000080 // Receive buffer unavailable
  203. #define EMAC_DSR_RI 0x00000040 // Receive interrupt
  204. #define EMAC_DSR_UNF 0x00000020 // Transmit underflow
  205. #define EMAC_DSR_OVF 0x00000010 // Receive overflow
  206. #define EMAC_DSR_TJT 0x00000008 // Transmit jabber timeout
  207. #define EMAC_DSR_TU 0x00000004 // Transmit buffer unavailable
  208. #define EMAC_DSR_TPS 0x00000002 // Transmit process stopped
  209. #define EMAC_DSR_TI 0x00000001 // Transmit interrupt
  210. /* DMA Bus Mode Register */
  211. #define EMAC_DBMR_TXPR 0x08000000 // DMA Tx priority
  212. #define EMAC_DBMR_MB 0x04000000 // Mixed burst
  213. #define EMAC_DBMR_AAL 0x02000000 // Address-aligned beats
  214. #define EMAC_DBMR_PBL8X 0x01000000 // 8 x PBL mode
  215. #define EMAC_DBMR_USP 0x00800000 // Use separate PBL
  216. #define EMAC_DBMR_RPBL 0x007E0000 // Rx DMA PBL mask
  217. #define EMAC_DBMR_FB 0x00010000 // Fixed burst
  218. #define EMAC_DBMR_PR 0x0000C000 // Rx-to-Tx priority ratio
  219. #define EMAC_DBMR_PBL 0x00003F00 // Programmable burst length mask
  220. #define EMAC_DBMR_ATDS 0x00000080 // Alternate descriptor size
  221. #define EMAC_DBMR_DSL 0x0000007C // Descriptor skip length
  222. #define EMAC_DBMR_DA 0x00000002 // DMA arbitration scheme
  223. #define EMAC_DBMR_SWR 0x00000001 // Software reset
  224. /* DMA Operation Mode Register */
  225. #define EMAC_DOMR_DFF 0x01000000 // Disable flushing of received frames
  226. #define EMAC_DOMR_FTF 0x00100000 // Flush transmit FIFO
  227. #define EMAC_DOMR_TTC 0x0001C000 // Transmit treshold control mask
  228. #define EMAC_DOMR_ST 0x00002000 // Start/stop transmission
  229. #define EMAC_DOMR_FEF 0x00000080 // Forward error frames
  230. #define EMAC_DOMR_FUF 0x00000040 // Forward undersized good frames
  231. #define EMAC_DOMR_RTC 0x00000018 // Receive threshold control mask
  232. #define EMAC_DOMR_OSF 0x00000004 // Operate on second frame
  233. #define EMAC_DOMR_SR 0x00000002 // Start/stop receive
  234. /* DMA Interrupt Enable Register */
  235. #define EMAC_DIER_NIE 0x00010000 // Normal interrupt summary enable
  236. #define EMAC_DIER_AIE 0x00008000 // Abnormal interrupt summary enable
  237. #define EMAC_DIER_ERE 0x00004000 // Early receive interrupt enable
  238. #define ENET_DIER_FBE 0x00002000 // Fatal bus error enable
  239. #define EMAC_DIER_ETE 0x00000400 // Early transmit interrupt enable
  240. #define EMAC_DIER_RWE 0x00000200 // Receive watchdog timeout enable
  241. #define EMAC_DIER_RSE 0x00000100 // Receive stopped enable
  242. #define EMAC_DIER_RUE 0x00000080 // Receive buffer unavailable enable
  243. #define EMAC_DIER_RIE 0x00000040 // Receive interrupt enable
  244. #define EMAC_DIER_UNE 0x00000020 // Underflow interrupt enable
  245. #define EMAC_DIER_OVE 0x00000010 // Overflow interrupt enable
  246. #define EMAC_DIER_TJE 0x00000008 // Transmit jabber timeout enable
  247. #define EMAC_DIER_TUE 0x00000004 // Transmit buffer unavailable enable
  248. #define EMAC_DIER_TSE 0x00000002 // Transmit stopped enable
  249. #define EMAC_DIER_TIE 0x00000001 // Transmit interrupt enable
  250. /* DMA RX Descriptor */
  251. typedef struct rx_desc {
  252. uint32_t volatile Stat; // Frame status
  253. uint32_t Ctrl; // Frame control
  254. uint8_t const *Addr; // Data buffer address
  255. struct rx_desc *Next; // Next Rx descriptor address
  256. #if (EMAC_TIME_STAMP)
  257. uint32_t ExtStat; // Extended status
  258. uint32_t Reserved[1]; // Not used
  259. uint32_t TimeLo; // Receive Timestamp low
  260. uint32_t TimeHi; // Receive Timestamp high
  261. #endif
  262. } RX_Desc;
  263. /* DMA TX Descriptor */
  264. typedef struct tx_desc {
  265. uint32_t volatile CtrlStat; // Frame control and status
  266. uint32_t Size; // Frame size
  267. uint8_t *Addr; // Data buffer address
  268. struct tx_desc *Next; // Next Tx descriptor address
  269. #if (EMAC_TIME_STAMP)
  270. uint32_t Reserved[2]; // Not used
  271. uint32_t TimeLo; // Transmit Timestamp low
  272. uint32_t TimeHi; // Transmit Timestamp high
  273. #endif
  274. } TX_Desc;
  275. /* EMAC Driver Control Information */
  276. typedef struct {
  277. ARM_ETH_MAC_SignalEvent_t cb_event; // Event callback
  278. uint8_t flags; // Control and state flags
  279. uint8_t tx_index; // Transmit descriptor index
  280. uint8_t rx_index; // Receive descriptor index
  281. #if (EMAC_TIME_STAMP)
  282. uint8_t tx_ts_index; // Transmit Timestamp descriptor index
  283. #endif
  284. uint8_t mmar_cr_val; // MII Address register Clock Range
  285. uint8_t *frame_end; // End of assembled frame fragments
  286. } EMAC_CTRL;
  287. #endif /* __EMAC_LPC18XX_H */