gd32f30x_enet.h 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  1. /*!
  2. \file gd32f30x_enet.h
  3. \brief definitions for the ENET
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. \version 2020-04-02, V2.0.1, firmware for GD32F30x
  8. \version 2020-09-30, V2.1.0, firmware for GD32F30x
  9. */
  10. /*
  11. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  12. Redistribution and use in source and binary forms, with or without modification,
  13. are permitted provided that the following conditions are met:
  14. 1. Redistributions of source code must retain the above copyright notice, this
  15. list of conditions and the following disclaimer.
  16. 2. Redistributions in binary form must reproduce the above copyright notice,
  17. this list of conditions and the following disclaimer in the documentation
  18. and/or other materials provided with the distribution.
  19. 3. Neither the name of the copyright holder nor the names of its contributors
  20. may be used to endorse or promote products derived from this software without
  21. specific prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  26. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  31. OF SUCH DAMAGE.
  32. */
  33. #ifndef GD32F30X_ENET_H
  34. #define GD32F30X_ENET_H
  35. #include "gd32f30x.h"
  36. #define IF_USE_EXTERNPHY_LIB 0
  37. #if (1 == IF_USE_EXTERNPHY_LIB)
  38. #include "phy.h"
  39. #endif
  40. #ifndef ENET_RXBUF_NUM
  41. #define ENET_RXBUF_NUM 5U /*!< ethernet Rx DMA descriptor number */
  42. #endif
  43. #ifndef ENET_TXBUF_NUM
  44. #define ENET_TXBUF_NUM 5U /*!< ethernet Tx DMA descriptor number */
  45. #endif
  46. #ifndef ENET_RXBUF_SIZE
  47. #define ENET_RXBUF_SIZE ENET_MAX_FRAME_SIZE /*!< ethernet receive buffer size */
  48. #endif
  49. #ifndef ENET_TXBUF_SIZE
  50. #define ENET_TXBUF_SIZE ENET_MAX_FRAME_SIZE /*!< ethernet transmit buffer size */
  51. #endif
  52. /* #define SELECT_DESCRIPTORS_ENHANCED_MODE */
  53. /* #define USE_DELAY */
  54. #ifndef _PHY_H_
  55. #define DP83848 0
  56. #define LAN8700 1
  57. #define PHY_TYPE DP83848
  58. #define PHY_ADDRESS ((uint16_t)1U) /*!< phy address determined by the hardware */
  59. /* PHY read write timeouts */
  60. #define PHY_READ_TO ((uint32_t)0x0004FFFFU) /*!< PHY read timeout */
  61. #define PHY_WRITE_TO ((uint32_t)0x0004FFFFU) /*!< PHY write timeout */
  62. /* PHY delay */
  63. #define PHY_RESETDELAY ((uint32_t)0x008FFFFFU) /*!< PHY reset delay */
  64. #define PHY_CONFIGDELAY ((uint32_t)0x00FFFFFFU) /*!< PHY configure delay */
  65. /* PHY register address */
  66. #define PHY_REG_BCR 0U /*!< tranceiver basic control register */
  67. #define PHY_REG_BSR 1U /*!< tranceiver basic status register */
  68. /* PHY basic control register */
  69. #define PHY_RESET ((uint16_t)0x8000) /*!< PHY reset */
  70. #define PHY_LOOPBACK ((uint16_t)0x4000) /*!< enable phy loop-back mode */
  71. #define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< configure speed to 100 Mbit/s and the full-duplex mode */
  72. #define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< configure speed to 100 Mbit/s and the half-duplex mode */
  73. #define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< configure speed to 10 Mbit/s and the full-duplex mode */
  74. #define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< configure speed to 10 Mbit/s and the half-duplex mode */
  75. #define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< enable auto-negotiation function */
  76. #define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< restart auto-negotiation function */
  77. #define PHY_POWERDOWN ((uint16_t)0x0800) /*!< enable the power down mode */
  78. #define PHY_ISOLATE ((uint16_t)0x0400) /*!< isolate PHY from MII */
  79. /* PHY basic status register */
  80. #define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< auto-negotioation process completed */
  81. #define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< valid link established */
  82. #define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< jabber condition detected */
  83. #if(PHY_TYPE == LAN8700)
  84. #define PHY_SR 31U /*!< tranceiver status register */
  85. #define PHY_SPEED_STATUS ((uint16_t)0x0004) /*!< configured information of speed: 10Mbit/s */
  86. #define PHY_DUPLEX_STATUS ((uint16_t)0x0010) /*!< configured information of duplex: full-duplex */
  87. #elif(PHY_TYPE == DP83848)
  88. #define PHY_SR 16U /*!< tranceiver status register */
  89. #define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< configured information of speed: 10Mbit/s */
  90. #define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< configured information of duplex: full-duplex */
  91. #endif /* PHY_TYPE */
  92. #endif /* _PHY_H_ */
  93. /* ENET definitions */
  94. #define ENET ENET_BASE
  95. /* registers definitions */
  96. #define ENET_MAC_CFG REG32((ENET) + 0x00U) /*!< ethernet MAC configuration register */
  97. #define ENET_MAC_FRMF REG32((ENET) + 0x04U) /*!< ethernet MAC frame filter register */
  98. #define ENET_MAC_HLH REG32((ENET) + 0x08U) /*!< ethernet MAC hash list high register */
  99. #define ENET_MAC_HLL REG32((ENET) + 0x0CU) /*!< ethernet MAC hash list low register */
  100. #define ENET_MAC_PHY_CTL REG32((ENET) + 0x10U) /*!< ethernet MAC PHY control register */
  101. #define ENET_MAC_PHY_DATA REG32((ENET) + 0x14U) /*!< ethernet MAC PHY data register */
  102. #define ENET_MAC_FCTL REG32((ENET) + 0x18U) /*!< ethernet MAC flow control register */
  103. #define ENET_MAC_VLT REG32((ENET) + 0x1CU) /*!< ethernet MAC VLAN tag register */
  104. #define ENET_MAC_RWFF REG32((ENET) + 0x28U) /*!< ethernet MAC remote wakeup frame filter register */
  105. #define ENET_MAC_WUM REG32((ENET) + 0x2CU) /*!< ethernet MAC wakeup management register */
  106. #define ENET_MAC_DBG REG32((ENET) + 0x34U) /*!< ethernet MAC debug register */
  107. #define ENET_MAC_INTF REG32((ENET) + 0x38U) /*!< ethernet MAC interrupt flag register */
  108. #define ENET_MAC_INTMSK REG32((ENET) + 0x3CU) /*!< ethernet MAC interrupt mask register */
  109. #define ENET_MAC_ADDR0H REG32((ENET) + 0x40U) /*!< ethernet MAC address 0 high register */
  110. #define ENET_MAC_ADDR0L REG32((ENET) + 0x44U) /*!< ethernet MAC address 0 low register */
  111. #define ENET_MAC_ADDR1H REG32((ENET) + 0x48U) /*!< ethernet MAC address 1 high register */
  112. #define ENET_MAC_ADDR1L REG32((ENET) + 0x4CU) /*!< ethernet MAC address 1 low register */
  113. #define ENET_MAC_ADDT2H REG32((ENET) + 0x50U) /*!< ethernet MAC address 2 high register */
  114. #define ENET_MAC_ADDR2L REG32((ENET) + 0x54U) /*!< ethernet MAC address 2 low register */
  115. #define ENET_MAC_ADDR3H REG32((ENET) + 0x58U) /*!< ethernet MAC address 3 high register */
  116. #define ENET_MAC_ADDR3L REG32((ENET) + 0x5CU) /*!< ethernet MAC address 3 low register */
  117. #define ENET_MAC_FCTH REG32((ENET) + 0x1080U) /*!< ethernet MAC flow control threshold register */
  118. #define ENET_MSC_CTL REG32((ENET) + 0x100U) /*!< ethernet MSC control register */
  119. #define ENET_MSC_RINTF REG32((ENET) + 0x104U) /*!< ethernet MSC receive interrupt flag register */
  120. #define ENET_MSC_TINTF REG32((ENET) + 0x108U) /*!< ethernet MSC transmit interrupt flag register */
  121. #define ENET_MSC_RINTMSK REG32((ENET) + 0x10CU) /*!< ethernet MSC receive interrupt mask register */
  122. #define ENET_MSC_TINTMSK REG32((ENET) + 0x110U) /*!< ethernet MSC transmit interrupt mask register */
  123. #define ENET_MSC_SCCNT REG32((ENET) + 0x14CU) /*!< ethernet MSC transmitted good frames after a single collision counter register */
  124. #define ENET_MSC_MSCCNT REG32((ENET) + 0x150U) /*!< ethernet MSC transmitted good frames after more than a single collision counter register */
  125. #define ENET_MSC_TGFCNT REG32((ENET) + 0x168U) /*!< ethernet MSC transmitted good frames counter register */
  126. #define ENET_MSC_RFCECNT REG32((ENET) + 0x194U) /*!< ethernet MSC received frames with CRC error counter register */
  127. #define ENET_MSC_RFAECNT REG32((ENET) + 0x198U) /*!< ethernet MSC received frames with alignment error counter register */
  128. #define ENET_MSC_RGUFCNT REG32((ENET) + 0x1C4U) /*!< ethernet MSC received good unicast frames counter register */
  129. #define ENET_PTP_TSCTL REG32((ENET) + 0x700U) /*!< ethernet PTP time stamp control register */
  130. #define ENET_PTP_SSINC REG32((ENET) + 0x704U) /*!< ethernet PTP subsecond increment register */
  131. #define ENET_PTP_TSH REG32((ENET) + 0x708U) /*!< ethernet PTP time stamp high register */
  132. #define ENET_PTP_TSL REG32((ENET) + 0x70CU) /*!< ethernet PTP time stamp low register */
  133. #define ENET_PTP_TSUH REG32((ENET) + 0x710U) /*!< ethernet PTP time stamp update high register */
  134. #define ENET_PTP_TSUL REG32((ENET) + 0x714U) /*!< ethernet PTP time stamp update low register */
  135. #define ENET_PTP_TSADDEND REG32((ENET) + 0x718U) /*!< ethernet PTP time stamp addend register */
  136. #define ENET_PTP_ETH REG32((ENET) + 0x71CU) /*!< ethernet PTP expected time high register */
  137. #define ENET_PTP_ETL REG32((ENET) + 0x720U) /*!< ethernet PTP expected time low register */
  138. #define ENET_PTP_TSF REG32((ENET) + 0x728U) /*!< ethernet PTP time stamp flag register */
  139. #define ENET_PTP_PPSCTL REG32((ENET) + 0x72CU) /*!< ethernet PTP PPS control register */
  140. #define ENET_DMA_BCTL REG32((ENET) + 0x1000U) /*!< ethernet DMA bus control register */
  141. #define ENET_DMA_TPEN REG32((ENET) + 0x1004U) /*!< ethernet DMA transmit poll enable register */
  142. #define ENET_DMA_RPEN REG32((ENET) + 0x1008U) /*!< ethernet DMA receive poll enable register */
  143. #define ENET_DMA_RDTADDR REG32((ENET) + 0x100CU) /*!< ethernet DMA receive descriptor table address register */
  144. #define ENET_DMA_TDTADDR REG32((ENET) + 0x1010U) /*!< ethernet DMA transmit descriptor table address register */
  145. #define ENET_DMA_STAT REG32((ENET) + 0x1014U) /*!< ethernet DMA status register */
  146. #define ENET_DMA_CTL REG32((ENET) + 0x1018U) /*!< ethernet DMA control register */
  147. #define ENET_DMA_INTEN REG32((ENET) + 0x101CU) /*!< ethernet DMA interrupt enable register */
  148. #define ENET_DMA_MFBOCNT REG32((ENET) + 0x1020U) /*!< ethernet DMA missed frame and buffer overflow counter register */
  149. #define ENET_DMA_RSWDC REG32((ENET) + 0x1024U) /*!< ethernet DMA receive state watchdog counter register */
  150. #define ENET_DMA_CTDADDR REG32((ENET) + 0x1048U) /*!< ethernet DMA current transmit descriptor address register */
  151. #define ENET_DMA_CRDADDR REG32((ENET) + 0x104CU) /*!< ethernet DMA current receive descriptor address register */
  152. #define ENET_DMA_CTBADDR REG32((ENET) + 0x1050U) /*!< ethernet DMA current transmit buffer address register */
  153. #define ENET_DMA_CRBADDR REG32((ENET) + 0x1054U) /*!< ethernet DMA current receive buffer address register */
  154. /* bits definitions */
  155. /* ENET_MAC_CFG */
  156. #define ENET_MAC_CFG_REN BIT(2) /*!< receiver enable */
  157. #define ENET_MAC_CFG_TEN BIT(3) /*!< transmitter enable */
  158. #define ENET_MAC_CFG_DFC BIT(4) /*!< defferal check */
  159. #define ENET_MAC_CFG_BOL BITS(5,6) /*!< back-off limit */
  160. #define ENET_MAC_CFG_APCD BIT(7) /*!< automatic pad/CRC drop */
  161. #define ENET_MAC_CFG_RTD BIT(9) /*!< retry disable */
  162. #define ENET_MAC_CFG_IPFCO BIT(10) /*!< IP frame checksum offload */
  163. #define ENET_MAC_CFG_DPM BIT(11) /*!< duplex mode */
  164. #define ENET_MAC_CFG_LBM BIT(12) /*!< loopback mode */
  165. #define ENET_MAC_CFG_ROD BIT(13) /*!< receive own disable */
  166. #define ENET_MAC_CFG_SPD BIT(14) /*!< fast eneternet speed */
  167. #define ENET_MAC_CFG_CSD BIT(16) /*!< carrier sense disable */
  168. #define ENET_MAC_CFG_IGBS BITS(17,19) /*!< inter-frame gap bit selection */
  169. #define ENET_MAC_CFG_JBD BIT(22) /*!< jabber disable */
  170. #define ENET_MAC_CFG_WDD BIT(23) /*!< watchdog disable */
  171. #define ENET_MAC_CFG_TFCD BIT(25) /*!< type frame CRC dropping */
  172. /* ENET_MAC_FRMF */
  173. #define ENET_MAC_FRMF_PM BIT(0) /*!< promiscuous mode */
  174. #define ENET_MAC_FRMF_HUF BIT(1) /*!< hash unicast filter */
  175. #define ENET_MAC_FRMF_HMF BIT(2) /*!< hash multicast filter */
  176. #define ENET_MAC_FRMF_DAIFLT BIT(3) /*!< destination address inverse filtering enable */
  177. #define ENET_MAC_FRMF_MFD BIT(4) /*!< multicast filter disable */
  178. #define ENET_MAC_FRMF_BFRMD BIT(5) /*!< broadcast frame disable */
  179. #define ENET_MAC_FRMF_PCFRM BITS(6,7) /*!< pass control frames */
  180. #define ENET_MAC_FRMF_SAIFLT BIT(8) /*!< source address inverse filtering */
  181. #define ENET_MAC_FRMF_SAFLT BIT(9) /*!< source address filter */
  182. #define ENET_MAC_FRMF_HPFLT BIT(10) /*!< hash or perfect filter */
  183. #define ENET_MAC_FRMF_FAR BIT(31) /*!< frames all receive */
  184. /* ENET_MAC_HLH */
  185. #define ENET_MAC_HLH_HLH BITS(0,31) /*!< hash list high */
  186. /* ENET_MAC_HLL */
  187. #define ENET_MAC_HLL_HLL BITS(0,31) /*!< hash list low */
  188. /* ENET_MAC_PHY_CTL */
  189. #define ENET_MAC_PHY_CTL_PB BIT(0) /*!< PHY busy */
  190. #define ENET_MAC_PHY_CTL_PW BIT(1) /*!< PHY write */
  191. #define ENET_MAC_PHY_CTL_CLR BITS(2,4) /*!< clock range */
  192. #define ENET_MAC_PHY_CTL_PR BITS(6,10) /*!< PHY register */
  193. #define ENET_MAC_PHY_CTL_PA BITS(11,15) /*!< PHY address */
  194. /* ENET_MAC_PHY_DATA */
  195. #define ENET_MAC_PHY_DATA_PD BITS(0,15) /*!< PHY data */
  196. /* ENET_MAC_FCTL */
  197. #define ENET_MAC_FCTL_FLCBBKPA BIT(0) /*!< flow control busy(in full duplex mode)/backpressure activate(in half duplex mode) */
  198. #define ENET_MAC_FCTL_TFCEN BIT(1) /*!< transmit flow control enable */
  199. #define ENET_MAC_FCTL_RFCEN BIT(2) /*!< receive flow control enable */
  200. #define ENET_MAC_FCTL_UPFDT BIT(3) /*!< unicast pause frame detect */
  201. #define ENET_MAC_FCTL_PLTS BITS(4,5) /*!< pause low threshold */
  202. #define ENET_MAC_FCTL_DZQP BIT(7) /*!< disable zero-quanta pause */
  203. #define ENET_MAC_FCTL_PTM BITS(16,31) /*!< pause time */
  204. /* ENET_MAC_VLT */
  205. #define ENET_MAC_VLT_VLTI BITS(0,15) /*!< VLAN tag identifier(for receive frames) */
  206. #define ENET_MAC_VLT_VLTC BIT(16) /*!< 12-bit VLAN tag comparison */
  207. /* ENET_MAC_RWFF */
  208. #define ENET_MAC_RWFF_DATA BITS(0,31) /*!< wakeup frame filter register data */
  209. /* ENET_MAC_WUM */
  210. #define ENET_MAC_WUM_PWD BIT(0) /*!< power down */
  211. #define ENET_MAC_WUM_MPEN BIT(1) /*!< magic packet enable */
  212. #define ENET_MAC_WUM_WFEN BIT(2) /*!< wakeup frame enable */
  213. #define ENET_MAC_WUM_MPKR BIT(5) /*!< magic packet received */
  214. #define ENET_MAC_WUM_WUFR BIT(6) /*!< wakeup frame received */
  215. #define ENET_MAC_WUM_GU BIT(9) /*!< global unicast */
  216. #define ENET_MAC_WUM_WUFFRPR BIT(31) /*!< wakeup frame filter register pointer reset */
  217. /* ENET_MAC_DBG */
  218. #define ENET_MAC_DBG_MRNI BIT(0) /*!< MAC receive state not idle */
  219. #define ENET_MAC_DBG_RXAFS BITS(1,2) /*!< Rx asynchronous FIFO status */
  220. #define ENET_MAC_DBG_RXFW BIT(4) /*!< RxFIFO is writing */
  221. #define ENET_MAC_DBG_RXFRS BITS(5,6) /*!< RxFIFO read operation status */
  222. #define ENET_MAC_DBG_RXFS BITS(8,9) /*!< RxFIFO state */
  223. #define ENET_MAC_DBG_MTNI BIT(16) /*!< MAC transmit state not idle */
  224. #define ENET_MAC_DBG_SOMT BITS(17,18) /*!< status of mac transmitter */
  225. #define ENET_MAC_DBG_PCS BIT(19) /*!< pause condition status */
  226. #define ENET_MAC_DBG_TXFRS BITS(20,21) /*!< TxFIFO read operation status */
  227. #define ENET_MAC_DBG_TXFW BIT(22) /*!< TxFIFO is writing */
  228. #define ENET_MAC_DBG_TXFNE BIT(24) /*!< TxFIFO not empty flag */
  229. #define ENET_MAC_DBG_TXFF BIT(25) /*!< TxFIFO full flag */
  230. /* ENET_MAC_INTF */
  231. #define ENET_MAC_INTF_WUM BIT(3) /*!< WUM status */
  232. #define ENET_MAC_INTF_MSC BIT(4) /*!< MSC status */
  233. #define ENET_MAC_INTF_MSCR BIT(5) /*!< MSC receive status */
  234. #define ENET_MAC_INTF_MSCT BIT(6) /*!< MSC transmit status */
  235. #define ENET_MAC_INTF_TMST BIT(9) /*!< timestamp trigger status */
  236. /* ENET_MAC_INTMSK */
  237. #define ENET_MAC_INTMSK_WUMIM BIT(3) /*!< WUM interrupt mask */
  238. #define ENET_MAC_INTMSK_TMSTIM BIT(9) /*!< timestamp trigger interrupt mask */
  239. /* ENET_MAC_ADDR0H */
  240. #define ENET_MAC_ADDR0H_ADDR0H BITS(0,15) /*!< MAC address0 high */
  241. #define ENET_MAC_ADDR0H_MO BIT(31) /*!< always read 1 and must be kept */
  242. /* ENET_MAC_ADDR0L */
  243. #define ENET_MAC_ADDR0L_ADDR0L BITS(0,31) /*!< MAC address0 low */
  244. /* ENET_MAC_ADDR1H */
  245. #define ENET_MAC_ADDR1H_ADDR1H BITS(0,15) /*!< MAC address1 high */
  246. #define ENET_MAC_ADDR1H_MB BITS(24,29) /*!< mask byte */
  247. #define ENET_MAC_ADDR1H_SAF BIT(30) /*!< source address filter */
  248. #define ENET_MAC_ADDR1H_AFE BIT(31) /*!< address filter enable */
  249. /* ENET_MAC_ADDR1L */
  250. #define ENET_MAC_ADDR1L_ADDR1L BITS(0,31) /*!< MAC address1 low */
  251. /* ENET_MAC_ADDR2H */
  252. #define ENET_MAC_ADDR2H_ADDR2H BITS(0,15) /*!< MAC address2 high */
  253. #define ENET_MAC_ADDR2H_MB BITS(24,29) /*!< mask byte */
  254. #define ENET_MAC_ADDR2H_SAF BIT(30) /*!< source address filter */
  255. #define ENET_MAC_ADDR2H_AFE BIT(31) /*!< address filter enable */
  256. /* ENET_MAC_ADDR2L */
  257. #define ENET_MAC_ADDR2L_ADDR2L BITS(0,31) /*!< MAC address2 low */
  258. /* ENET_MAC_ADDR3H */
  259. #define ENET_MAC_ADDR3H_ADDR3H BITS(0,15) /*!< MAC address3 high */
  260. #define ENET_MAC_ADDR3H_MB BITS(24,29) /*!< mask byte */
  261. #define ENET_MAC_ADDR3H_SAF BIT(30) /*!< source address filter */
  262. #define ENET_MAC_ADDR3H_AFE BIT(31) /*!< address filter enable */
  263. /* ENET_MAC_ADDR3L */
  264. #define ENET_MAC_ADDR3L_ADDR3L BITS(0,31) /*!< MAC address3 low */
  265. /* ENET_MAC_FCTH */
  266. #define ENET_MAC_FCTH_RFA BITS(0,2) /*!< threshold of active flow control */
  267. #define ENET_MAC_FCTH_RFD BITS(4,6) /*!< threshold of deactive flow control */
  268. /* ENET_MSC_CTL */
  269. #define ENET_MSC_CTL_CTR BIT(0) /*!< counter reset */
  270. #define ENET_MSC_CTL_CTSR BIT(1) /*!< counter stop rollover */
  271. #define ENET_MSC_CTL_RTOR BIT(2) /*!< reset on read */
  272. #define ENET_MSC_CTL_MCFZ BIT(3) /*!< MSC counter freeze */
  273. #define ENET_MSC_CTL_PMC BIT(4) /*!< preset MSC counter */
  274. #define ENET_MSC_CTL_AFHPM BIT(5) /*!< almost full or half preset mode */
  275. /* ENET_MSC_RINTF */
  276. #define ENET_MSC_RINTF_RFCE BIT(5) /*!< received frames CRC error */
  277. #define ENET_MSC_RINTF_RFAE BIT(6) /*!< received frames alignment error */
  278. #define ENET_MSC_RINTF_RGUF BIT(17) /*!< receive good unicast frames */
  279. /* ENET_MSC_TINTF */
  280. #define ENET_MSC_TINTF_TGFSC BIT(14) /*!< transmitted good frames single collision */
  281. #define ENET_MSC_TINTF_TGFMSC BIT(15) /*!< transmitted good frames more single collision */
  282. #define ENET_MSC_TINTF_TGF BIT(21) /*!< transmitted good frames */
  283. /* ENET_MSC_RINTMSK */
  284. #define ENET_MSC_RINTMSK_RFCEIM BIT(5) /*!< received frame CRC error interrupt mask */
  285. #define ENET_MSC_RINTMSK_RFAEIM BIT(6) /*!< received frames alignment error interrupt mask */
  286. #define ENET_MSC_RINTMSK_RGUFIM BIT(17) /*!< received good unicast frames interrupt mask */
  287. /* ENET_MSC_TINTMSK */
  288. #define ENET_MSC_TINTMSK_TGFSCIM BIT(14) /*!< transmitted good frames single collision interrupt mask */
  289. #define ENET_MSC_TINTMSK_TGFMSCIM BIT(15) /*!< transmitted good frames more single collision interrupt mask */
  290. #define ENET_MSC_TINTMSK_TGFIM BIT(21) /*!< transmitted good frames interrupt mask */
  291. /* ENET_MSC_SCCNT */
  292. #define ENET_MSC_SCCNT_SCC BITS(0,31) /*!< transmitted good frames single collision counter */
  293. /* ENET_MSC_MSCCNT */
  294. #define ENET_MSC_MSCCNT_MSCC BITS(0,31) /*!< transmitted good frames more one single collision counter */
  295. /* ENET_MSC_TGFCNT */
  296. #define ENET_MSC_TGFCNT_TGF BITS(0,31) /*!< transmitted good frames counter */
  297. /* ENET_MSC_RFCECNT */
  298. #define ENET_MSC_RFCECNT_RFCER BITS(0,31) /*!< received frames with CRC error counter */
  299. /* ENET_MSC_RFAECNT */
  300. #define ENET_MSC_RFAECNT_RFAER BITS(0,31) /*!< received frames alignment error counter */
  301. /* ENET_MSC_RGUFCNT */
  302. #define ENET_MSC_RGUFCNT_RGUF BITS(0,31) /*!< received good unicast frames counter */
  303. /* ENET_PTP_TSCTL */
  304. #define ENET_PTP_TSCTL_TMSEN BIT(0) /*!< timestamp enable */
  305. #define ENET_PTP_TSCTL_TMSFCU BIT(1) /*!< timestamp fine or coarse update */
  306. #define ENET_PTP_TSCTL_TMSSTI BIT(2) /*!< timestamp system time initialize */
  307. #define ENET_PTP_TSCTL_TMSSTU BIT(3) /*!< timestamp system time update */
  308. #define ENET_PTP_TSCTL_TMSITEN BIT(4) /*!< timestamp interrupt trigger enable */
  309. #define ENET_PTP_TSCTL_TMSARU BIT(5) /*!< timestamp addend register update */
  310. #define ENET_PTP_TSCTL_ARFSEN BIT(8) /*!< all received frames snapshot enable */
  311. #define ENET_PTP_TSCTL_SCROM BIT(9) /*!< subsecond counter rollover mode */
  312. #define ENET_PTP_TSCTL_PFSV BIT(10) /*!< PTP frame snooping version */
  313. #define ENET_PTP_TSCTL_ESEN BIT(11) /*!< received Ethernet snapshot enable */
  314. #define ENET_PTP_TSCTL_IP6SEN BIT(12) /*!< received IPv6 snapshot enable */
  315. #define ENET_PTP_TSCTL_IP4SEN BIT(13) /*!< received IPv4 snapshot enable */
  316. #define ENET_PTP_TSCTL_ETMSEN BIT(14) /*!< received event type message snapshot enable */
  317. #define ENET_PTP_TSCTL_MNMSEN BIT(15) /*!< received master node message snapshot enable */
  318. #define ENET_PTP_TSCTL_CKNT BITS(16,17) /*!< clock node type for time stamp */
  319. #define ENET_PTP_TSCTL_MAFEN BIT(18) /*!< MAC address filter enable for PTP frame */
  320. /* ENET_PTP_SSINC */
  321. #define ENET_PTP_SSINC_STMSSI BITS(0,7) /*!< system time subsecond increment */
  322. /* ENET_PTP_TSH */
  323. #define ENET_PTP_TSH_STMS BITS(0,31) /*!< system time second */
  324. /* ENET_PTP_TSL */
  325. #define ENET_PTP_TSL_STMSS BITS(0,30) /*!< system time subseconds */
  326. #define ENET_PTP_TSL_STS BIT(31) /*!< system time sign */
  327. /* ENET_PTP_TSUH */
  328. #define ENET_PTP_TSUH_TMSUS BITS(0,31) /*!< timestamp update seconds */
  329. /* ENET_PTP_TSUL */
  330. #define ENET_PTP_TSUL_TMSUSS BITS(0,30) /*!< timestamp update subseconds */
  331. #define ENET_PTP_TSUL_TMSUPNS BIT(31) /*!< timestamp update positive or negative sign */
  332. /* ENET_PTP_TSADDEND */
  333. #define ENET_PTP_TSADDEND_TMSA BITS(0,31) /*!< timestamp addend */
  334. /* ENET_PTP_ETH */
  335. #define ENET_PTP_ETH_ETSH BITS(0,31) /*!< expected time high */
  336. /* ENET_PTP_ETL */
  337. #define ENET_PTP_ETL_ETSL BITS(0,31) /*!< expected time low */
  338. /* ENET_PTP_TSF */
  339. #define ENET_PTP_TSF_TSSCO BIT(0) /*!< timestamp second counter overflow */
  340. #define ENET_PTP_TSF_TTM BIT(1) /*!< target time match */
  341. /* ENET_PTP_PPSCTL */
  342. #define ENET_PTP_PPSCTL_PPSOFC BITS(0,3) /*!< PPS output frequency configure */
  343. /* ENET_DMA_BCTL */
  344. #define ENET_DMA_BCTL_SWR BIT(0) /*!< software reset */
  345. #define ENET_DMA_BCTL_DAB BIT(1) /*!< DMA arbitration */
  346. #define ENET_DMA_BCTL_DPSL BITS(2,6) /*!< descriptor skip length */
  347. #define ENET_DMA_BCTL_DFM BIT(7) /*!< descriptor format mode */
  348. #define ENET_DMA_BCTL_PGBL BITS(8,13) /*!< programmable burst length */
  349. #define ENET_DMA_BCTL_RTPR BITS(14,15) /*!< RxDMA and TxDMA transfer priority ratio */
  350. #define ENET_DMA_BCTL_FB BIT(16) /*!< fixed Burst */
  351. #define ENET_DMA_BCTL_RXDP BITS(17,22) /*!< RxDMA PGBL */
  352. #define ENET_DMA_BCTL_UIP BIT(23) /*!< use independent PGBL */
  353. #define ENET_DMA_BCTL_FPBL BIT(24) /*!< four times PGBL mode */
  354. #define ENET_DMA_BCTL_AA BIT(25) /*!< address-aligned */
  355. #define ENET_DMA_BCTL_MB BIT(26) /*!< mixed burst */
  356. /* ENET_DMA_TPEN */
  357. #define ENET_DMA_TPEN_TPE BITS(0,31) /*!< transmit poll enable */
  358. /* ENET_DMA_RPEN */
  359. #define ENET_DMA_RPEN_RPE BITS(0,31) /*!< receive poll enable */
  360. /* ENET_DMA_RDTADDR */
  361. #define ENET_DMA_RDTADDR_SRT BITS(0,31) /*!< start address of receive table */
  362. /* ENET_DMA_TDTADDR */
  363. #define ENET_DMA_TDTADDR_STT BITS(0,31) /*!< start address of transmit table */
  364. /* ENET_DMA_STAT */
  365. #define ENET_DMA_STAT_TS BIT(0) /*!< transmit status */
  366. #define ENET_DMA_STAT_TPS BIT(1) /*!< transmit process stopped status */
  367. #define ENET_DMA_STAT_TBU BIT(2) /*!< transmit buffer unavailable status */
  368. #define ENET_DMA_STAT_TJT BIT(3) /*!< transmit jabber timeout status */
  369. #define ENET_DMA_STAT_RO BIT(4) /*!< receive overflow status */
  370. #define ENET_DMA_STAT_TU BIT(5) /*!< transmit underflow status */
  371. #define ENET_DMA_STAT_RS BIT(6) /*!< receive status */
  372. #define ENET_DMA_STAT_RBU BIT(7) /*!< receive buffer unavailable status */
  373. #define ENET_DMA_STAT_RPS BIT(8) /*!< receive process stopped status */
  374. #define ENET_DMA_STAT_RWT BIT(9) /*!< receive watchdog timeout status */
  375. #define ENET_DMA_STAT_ET BIT(10) /*!< early transmit status */
  376. #define ENET_DMA_STAT_FBE BIT(13) /*!< fatal bus error status */
  377. #define ENET_DMA_STAT_ER BIT(14) /*!< early receive status */
  378. #define ENET_DMA_STAT_AI BIT(15) /*!< abnormal interrupt summary */
  379. #define ENET_DMA_STAT_NI BIT(16) /*!< normal interrupt summary */
  380. #define ENET_DMA_STAT_RP BITS(17,19) /*!< receive process state */
  381. #define ENET_DMA_STAT_TP BITS(20,22) /*!< transmit process state */
  382. #define ENET_DMA_STAT_EB BITS(23,25) /*!< error bits status */
  383. #define ENET_DMA_STAT_MSC BIT(27) /*!< MSC status */
  384. #define ENET_DMA_STAT_WUM BIT(28) /*!< WUM status */
  385. #define ENET_DMA_STAT_TST BIT(29) /*!< timestamp trigger status */
  386. /* ENET_DMA_CTL */
  387. #define ENET_DMA_CTL_SRE BIT(1) /*!< start/stop receive enable */
  388. #define ENET_DMA_CTL_OSF BIT(2) /*!< operate on second frame */
  389. #define ENET_DMA_CTL_RTHC BITS(3,4) /*!< receive threshold control */
  390. #define ENET_DMA_CTL_FUF BIT(6) /*!< forward undersized good frames */
  391. #define ENET_DMA_CTL_FERF BIT(7) /*!< forward error frames */
  392. #define ENET_DMA_CTL_STE BIT(13) /*!< start/stop transmission enable */
  393. #define ENET_DMA_CTL_TTHC BITS(14,16) /*!< transmit threshold control */
  394. #define ENET_DMA_CTL_FTF BIT(20) /*!< flush transmit FIFO */
  395. #define ENET_DMA_CTL_TSFD BIT(21) /*!< transmit store-and-forward */
  396. #define ENET_DMA_CTL_DAFRF BIT(24) /*!< disable flushing of received frames */
  397. #define ENET_DMA_CTL_RSFD BIT(25) /*!< receive store-and-forward */
  398. #define ENET_DMA_CTL_DTCERFD BIT(26) /*!< dropping of TCP/IP checksum error frames disable */
  399. /* ENET_DMA_INTEN */
  400. #define ENET_DMA_INTEN_TIE BIT(0) /*!< transmit interrupt enable */
  401. #define ENET_DMA_INTEN_TPSIE BIT(1) /*!< transmit process stopped interrupt enable */
  402. #define ENET_DMA_INTEN_TBUIE BIT(2) /*!< transmit buffer unavailable interrupt enable */
  403. #define ENET_DMA_INTEN_TJTIE BIT(3) /*!< transmit jabber timeout interrupt enable */
  404. #define ENET_DMA_INTEN_ROIE BIT(4) /*!< receive overflow interrupt enable */
  405. #define ENET_DMA_INTEN_TUIE BIT(5) /*!< transmit underflow interrupt enable */
  406. #define ENET_DMA_INTEN_RIE BIT(6) /*!< receive interrupt enable */
  407. #define ENET_DMA_INTEN_RBUIE BIT(7) /*!< receive buffer unavailable interrupt enable */
  408. #define ENET_DMA_INTEN_RPSIE BIT(8) /*!< receive process stopped interrupt enable */
  409. #define ENET_DMA_INTEN_RWTIE BIT(9) /*!< receive watchdog timeout interrupt enable */
  410. #define ENET_DMA_INTEN_ETIE BIT(10) /*!< early transmit interrupt enable */
  411. #define ENET_DMA_INTEN_FBEIE BIT(13) /*!< fatal bus error interrupt enable */
  412. #define ENET_DMA_INTEN_ERIE BIT(14) /*!< early receive interrupt enable */
  413. #define ENET_DMA_INTEN_AIE BIT(15) /*!< abnormal interrupt summary enable */
  414. #define ENET_DMA_INTEN_NIE BIT(16) /*!< normal interrupt summary enable */
  415. /* ENET_DMA_MFBOCNT */
  416. #define ENET_DMA_MFBOCNT_MSFC BITS(0,15) /*!< missed frames by the controller */
  417. #define ENET_DMA_MFBOCNT_MSFA BITS(17,27) /*!< missed frames by the application */
  418. /* ENET_DMA_RSWDC */
  419. #define ENET_DMA_RSWDC_WDCFRS BITS(0,7) /*!< watchdog counter for receive status (RS) */
  420. /* ENET_DMA_CTDADDR */
  421. #define ENET_DMA_CTDADDR_TDAP BITS(0,31) /*!< transmit descriptor address pointer */
  422. /* ENET_DMA_CRDADDR */
  423. #define ENET_DMA_CRDADDR_RDAP BITS(0,31) /*!< receive descriptor address pointer */
  424. /* ENET_DMA_CTBADDR */
  425. #define ENET_DMA_CTBADDR_TBAP BITS(0,31) /*!< transmit buffer address pointer */
  426. /* ENET_DMA_CRBADDR */
  427. #define ENET_DMA_CRBADDR_RBAP BITS(0,31) /*!< receive buffer address pointer */
  428. /* ENET DMA Tx descriptor TDES0 */
  429. #define ENET_TDES0_DB BIT(0) /*!< deferred */
  430. #define ENET_TDES0_UFE BIT(1) /*!< underflow error */
  431. #define ENET_TDES0_EXD BIT(2) /*!< excessive deferral */
  432. #define ENET_TDES0_COCNT BITS(3,6) /*!< collision count */
  433. #define ENET_TDES0_VFRM BIT(7) /*!< VLAN frame */
  434. #define ENET_TDES0_ECO BIT(8) /*!< excessive collision */
  435. #define ENET_TDES0_LCO BIT(9) /*!< late collision */
  436. #define ENET_TDES0_NCA BIT(10) /*!< no carrier */
  437. #define ENET_TDES0_LCA BIT(11) /*!< loss of carrier */
  438. #define ENET_TDES0_IPPE BIT(12) /*!< IP payload error */
  439. #define ENET_TDES0_FRMF BIT(13) /*!< frame flushed */
  440. #define ENET_TDES0_JT BIT(14) /*!< jabber timeout */
  441. #define ENET_TDES0_ES BIT(15) /*!< error summary */
  442. #define ENET_TDES0_IPHE BIT(16) /*!< IP header error */
  443. #define ENET_TDES0_TTMSS BIT(17) /*!< transmit timestamp status */
  444. #define ENET_TDES0_TCHM BIT(20) /*!< the second address chained mode */
  445. #define ENET_TDES0_TERM BIT(21) /*!< transmit end of ring mode*/
  446. #define ENET_TDES0_CM BITS(22,23) /*!< checksum mode */
  447. #define ENET_TDES0_TTSEN BIT(25) /*!< transmit timestamp function enable */
  448. #define ENET_TDES0_DPAD BIT(26) /*!< disable adding pad */
  449. #define ENET_TDES0_DCRC BIT(27) /*!< disable CRC */
  450. #define ENET_TDES0_FSG BIT(28) /*!< first segment */
  451. #define ENET_TDES0_LSG BIT(29) /*!< last segment */
  452. #define ENET_TDES0_INTC BIT(30) /*!< interrupt on completion */
  453. #define ENET_TDES0_DAV BIT(31) /*!< DAV bit */
  454. /* ENET DMA Tx descriptor TDES1 */
  455. #define ENET_TDES1_TB1S BITS(0,12) /*!< transmit buffer 1 size */
  456. #define ENET_TDES1_TB2S BITS(16,28) /*!< transmit buffer 2 size */
  457. /* ENET DMA Tx descriptor TDES2 */
  458. #define ENET_TDES2_TB1AP BITS(0,31) /*!< transmit buffer 1 address pointer/transmit frame timestamp low 32-bit value */
  459. /* ENET DMA Tx descriptor TDES3 */
  460. #define ENET_TDES3_TB2AP BITS(0,31) /*!< transmit buffer 2 address pointer (or next descriptor address) / transmit frame timestamp high 32-bit value */
  461. #ifdef SELECT_DESCRIPTORS_ENHANCED_MODE
  462. /* ENET DMA Tx descriptor TDES6 */
  463. #define ENET_TDES6_TTSL BITS(0,31) /*!< transmit frame timestamp low 32-bit value */
  464. /* ENET DMA Tx descriptor TDES7 */
  465. #define ENET_TDES7_TTSH BITS(0,31) /*!< transmit frame timestamp high 32-bit value */
  466. #endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
  467. /* ENET DMA Rx descriptor RDES0 */
  468. #define ENET_RDES0_PCERR BIT(0) /*!< payload checksum error */
  469. #define ENET_RDES0_EXSV BIT(0) /*!< extended status valid */
  470. #define ENET_RDES0_CERR BIT(1) /*!< CRC error */
  471. #define ENET_RDES0_DBERR BIT(2) /*!< dribble bit error */
  472. #define ENET_RDES0_RERR BIT(3) /*!< receive error */
  473. #define ENET_RDES0_RWDT BIT(4) /*!< receive watchdog timeout */
  474. #define ENET_RDES0_FRMT BIT(5) /*!< frame type */
  475. #define ENET_RDES0_LCO BIT(6) /*!< late collision */
  476. #define ENET_RDES0_IPHERR BIT(7) /*!< IP frame header error */
  477. #define ENET_RDES0_TSV BIT(7) /*!< timestamp valid */
  478. #define ENET_RDES0_LDES BIT(8) /*!< last descriptor */
  479. #define ENET_RDES0_FDES BIT(9) /*!< first descriptor */
  480. #define ENET_RDES0_VTAG BIT(10) /*!< VLAN tag */
  481. #define ENET_RDES0_OERR BIT(11) /*!< overflow Error */
  482. #define ENET_RDES0_LERR BIT(12) /*!< length error */
  483. #define ENET_RDES0_SAFF BIT(13) /*!< SA filter fail */
  484. #define ENET_RDES0_DERR BIT(14) /*!< descriptor error */
  485. #define ENET_RDES0_ERRS BIT(15) /*!< error summary */
  486. #define ENET_RDES0_FRML BITS(16,29) /*!< frame length */
  487. #define ENET_RDES0_DAFF BIT(30) /*!< destination address filter fail */
  488. #define ENET_RDES0_DAV BIT(31) /*!< descriptor available */
  489. /* ENET DMA Rx descriptor RDES1 */
  490. #define ENET_RDES1_RB1S BITS(0,12) /*!< receive buffer 1 size */
  491. #define ENET_RDES1_RCHM BIT(14) /*!< receive chained mode for second address */
  492. #define ENET_RDES1_RERM BIT(15) /*!< receive end of ring mode*/
  493. #define ENET_RDES1_RB2S BITS(16,28) /*!< receive buffer 2 size */
  494. #define ENET_RDES1_DINTC BIT(31) /*!< disable interrupt on completion */
  495. /* ENET DMA Rx descriptor RDES2 */
  496. #define ENET_RDES2_RB1AP BITS(0,31) /*!< receive buffer 1 address pointer / receive frame timestamp low 32-bit */
  497. /* ENET DMA Rx descriptor RDES3 */
  498. #define ENET_RDES3_RB2AP BITS(0,31) /*!< receive buffer 2 address pointer (next descriptor address)/receive frame timestamp high 32-bit value */
  499. #ifdef SELECT_DESCRIPTORS_ENHANCED_MODE
  500. /* ENET DMA Rx descriptor RDES4 */
  501. #define ENET_RDES4_IPPLDT BITS(0,2) /*!< IP frame payload type */
  502. #define ENET_RDES4_IPHERR BIT(3) /*!< IP frame header error */
  503. #define ENET_RDES4_IPPLDERR BIT(4) /*!< IP frame payload error */
  504. #define ENET_RDES4_IPCKSB BIT(5) /*!< IP frame checksum bypassed */
  505. #define ENET_RDES4_IPF4 BIT(6) /*!< IP frame in version 4 */
  506. #define ENET_RDES4_IPF6 BIT(7) /*!< IP frame in version 6 */
  507. #define ENET_RDES4_PTPMT BITS(8,11) /*!< PTP message type */
  508. #define ENET_RDES4_PTPOEF BIT(12) /*!< PTP on ethernet frame */
  509. #define ENET_RDES4_PTPVF BIT(13) /*!< PTP version format */
  510. /* ENET DMA Rx descriptor RDES6 */
  511. #define ENET_RDES6_RTSL BITS(0,31) /*!< receive frame timestamp low 32-bit value */
  512. /* ENET DMA Rx descriptor RDES7 */
  513. #define ENET_RDES7_RTSH BITS(0,31) /*!< receive frame timestamp high 32-bit value */
  514. #endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
  515. /* constants definitions */
  516. /* define bit position and its register index offset */
  517. #define ENET_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
  518. #define ENET_REG_VAL(periph) (REG32(ENET + ((uint32_t)(periph)>>6)))
  519. #define ENET_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
  520. /* ENET clock range judgement */
  521. #define ENET_RANGE(hclk, n, m) (((hclk) >= (n))&&((hclk) < (m)))
  522. /* define MAC address configuration and reference address */
  523. #define ENET_SET_MACADDRH(p) (((uint32_t)(p)[5] << 8) | (uint32_t)(p)[4])
  524. #define ENET_SET_MACADDRL(p) (((uint32_t)(p)[3] << 24) | ((uint32_t)(p)[2] << 16) | ((uint32_t)(p)[1] << 8) | (uint32_t)(p)[0])
  525. #define ENET_ADDRH_BASE ((ENET) + 0x40U)
  526. #define ENET_ADDRL_BASE ((ENET) + 0x44U)
  527. #define ENET_GET_MACADDR(offset, n) ((uint8_t)((REG32((ENET_ADDRL_BASE + (offset)) - (((n) / 4U) * 4U)) >> (8U * ((n) % 4U))) & 0xFFU))
  528. /* register offset */
  529. #define MAC_FCTL_REG_OFFSET 0x0018U /*!< MAC flow control register offset */
  530. #define MAC_WUM_REG_OFFSET 0x002CU /*!< MAC wakeup management register offset */
  531. #define MAC_INTF_REG_OFFSET 0x0038U /*!< MAC interrupt flag register offset */
  532. #define MAC_INTMSK_REG_OFFSET 0x003CU /*!< MAC interrupt mask register offset */
  533. #define MSC_RINTF_REG_OFFSET 0x0104U /*!< MSC receive interrupt flag register offset */
  534. #define MSC_TINTF_REG_OFFSET 0x0108U /*!< MSC transmit interrupt flag register offset */
  535. #define MSC_RINTMSK_REG_OFFSET 0x010CU /*!< MSC receive interrupt mask register offset */
  536. #define MSC_TINTMSK_REG_OFFSET 0x0110U /*!< MSC transmit interrupt mask register offset */
  537. #define MSC_SCCNT_REG_OFFSET 0x014CU /*!< MSC transmitted good frames after a single collision counter register offset */
  538. #define MSC_MSCCNT_REG_OFFSET 0x0150U /*!< MSC transmitted good frames after more than a single collision counter register offset */
  539. #define MSC_TGFCNT_REG_OFFSET 0x0168U /*!< MSC transmitted good frames counter register offset */
  540. #define MSC_RFCECNT_REG_OFFSET 0x0194U /*!< MSC received frames with CRC error counter register offset */
  541. #define MSC_RFAECNT_REG_OFFSET 0x0198U /*!< MSC received frames with alignment error counter register offset */
  542. #define MSC_RGUFCNT_REG_OFFSET 0x01C4U /*!< MSC received good unicast frames counter register offset */
  543. #define PTP_TSF_REG_OFFSET 0x0728U /*!< PTP time stamp flag register offset */
  544. #define DMA_STAT_REG_OFFSET 0x1014U /*!< DMA status register offset */
  545. #define DMA_INTEN_REG_OFFSET 0x101CU /*!< DMA interrupt enable register offset */
  546. #define DMA_TDTADDR_REG_OFFSET 0x1010U /*!< DMA transmit descriptor table address register offset */
  547. #define DMA_CTDADDR_REG_OFFSET 0x1048U /*!< DMA current transmit descriptor address register */
  548. #define DMA_CTBADDR_REG_OFFSET 0x1050U /*!< DMA current transmit buffer address register */
  549. #define DMA_RDTADDR_REG_OFFSET 0x100CU /*!< DMA receive descriptor table address register */
  550. #define DMA_CRDADDR_REG_OFFSET 0x104CU /*!< DMA current receive descriptor address register */
  551. #define DMA_CRBADDR_REG_OFFSET 0x1054U /*!< DMA current receive buffer address register */
  552. /* ENET status flag get */
  553. typedef enum
  554. {
  555. /* ENET_MAC_WUM register */
  556. ENET_MAC_FLAG_MPKR = ENET_REGIDX_BIT(MAC_WUM_REG_OFFSET, 5U), /*!< magic packet received flag */
  557. ENET_MAC_FLAG_WUFR = ENET_REGIDX_BIT(MAC_WUM_REG_OFFSET, 6U), /*!< wakeup frame received flag */
  558. /* ENET_MAC_FCTL register */
  559. ENET_MAC_FLAG_FLOWCONTROL = ENET_REGIDX_BIT(MAC_FCTL_REG_OFFSET, 0U), /*!< flow control status flag */
  560. /* ENET_MAC_INTF register */
  561. ENET_MAC_FLAG_WUM = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 3U), /*!< WUM status flag */
  562. ENET_MAC_FLAG_MSC = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 4U), /*!< MSC status flag */
  563. ENET_MAC_FLAG_MSCR = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 5U), /*!< MSC receive status flag */
  564. ENET_MAC_FLAG_MSCT = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 6U), /*!< MSC transmit status flag */
  565. ENET_MAC_FLAG_TMST = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 9U), /*!< timestamp trigger status flag */
  566. /* ENET_PTP_TSF register */
  567. ENET_PTP_FLAG_TSSCO = ENET_REGIDX_BIT(PTP_TSF_REG_OFFSET, 0U), /*!< timestamp second counter overflow flag */
  568. ENET_PTP_FLAG_TTM = ENET_REGIDX_BIT(PTP_TSF_REG_OFFSET, 1U), /*!< target time match flag */
  569. /* ENET_MSC_RINTF register */
  570. ENET_MSC_FLAG_RFCE = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 5U), /*!< received frames CRC error flag */
  571. ENET_MSC_FLAG_RFAE = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 6U), /*!< received frames alignment error flag */
  572. ENET_MSC_FLAG_RGUF = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 17U), /*!< received good unicast frames flag */
  573. /* ENET_MSC_TINTF register */
  574. ENET_MSC_FLAG_TGFSC = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 14U), /*!< transmitted good frames single collision flag */
  575. ENET_MSC_FLAG_TGFMSC = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 15U), /*!< transmitted good frames more single collision flag */
  576. ENET_MSC_FLAG_TGF = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 21U), /*!< transmitted good frames flag */
  577. /* ENET_DMA_STAT register */
  578. ENET_DMA_FLAG_TS = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 0U), /*!< transmit status flag */
  579. ENET_DMA_FLAG_TPS = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 1U), /*!< transmit process stopped status flag */
  580. ENET_DMA_FLAG_TBU = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 2U), /*!< transmit buffer unavailable status flag */
  581. ENET_DMA_FLAG_TJT = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 3U), /*!< transmit jabber timeout status flag */
  582. ENET_DMA_FLAG_RO = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 4U), /*!< receive overflow status flag */
  583. ENET_DMA_FLAG_TU = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 5U), /*!< transmit underflow status flag */
  584. ENET_DMA_FLAG_RS = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 6U), /*!< receive status flag */
  585. ENET_DMA_FLAG_RBU = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 7U), /*!< receive buffer unavailable status flag */
  586. ENET_DMA_FLAG_RPS = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 8U), /*!< receive process stopped status flag */
  587. ENET_DMA_FLAG_RWT = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 9U), /*!< receive watchdog timeout status flag */
  588. ENET_DMA_FLAG_ET = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 10U), /*!< early transmit status flag */
  589. ENET_DMA_FLAG_FBE = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 13U), /*!< fatal bus error status flag */
  590. ENET_DMA_FLAG_ER = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 14U), /*!< early receive status flag */
  591. ENET_DMA_FLAG_AI = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 15U), /*!< abnormal interrupt summary flag */
  592. ENET_DMA_FLAG_NI = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
  593. ENET_DMA_FLAG_EB_DMA_ERROR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 23U), /*!< error during data transfer by RxDMA/TxDMA flag */
  594. ENET_DMA_FLAG_EB_TRANSFER_ERROR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 24U), /*!< error during write/read transfer flag */
  595. ENET_DMA_FLAG_EB_ACCESS_ERROR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 25U), /*!< error during data buffer/descriptor access flag */
  596. ENET_DMA_FLAG_MSC = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 27U), /*!< MSC status flag */
  597. ENET_DMA_FLAG_WUM = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 28U), /*!< WUM status flag */
  598. ENET_DMA_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U), /*!< timestamp trigger status flag */
  599. }enet_flag_enum;
  600. /* ENET stutus flag clear */
  601. typedef enum
  602. {
  603. /* ENET_DMA_STAT register */
  604. ENET_DMA_FLAG_TS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 0U), /*!< transmit status flag */
  605. ENET_DMA_FLAG_TPS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 1U), /*!< transmit process stopped status flag */
  606. ENET_DMA_FLAG_TBU_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 2U), /*!< transmit buffer unavailable status flag */
  607. ENET_DMA_FLAG_TJT_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 3U), /*!< transmit jabber timeout status flag */
  608. ENET_DMA_FLAG_RO_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 4U), /*!< receive overflow status flag */
  609. ENET_DMA_FLAG_TU_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 5U), /*!< transmit underflow status flag */
  610. ENET_DMA_FLAG_RS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 6U), /*!< receive status flag */
  611. ENET_DMA_FLAG_RBU_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 7U), /*!< receive buffer unavailable status flag */
  612. ENET_DMA_FLAG_RPS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 8U), /*!< receive process stopped status flag */
  613. ENET_DMA_FLAG_RWT_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 9U), /*!< receive watchdog timeout status flag */
  614. ENET_DMA_FLAG_ET_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 10U), /*!< early transmit status flag */
  615. ENET_DMA_FLAG_FBE_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 13U), /*!< fatal bus error status flag */
  616. ENET_DMA_FLAG_ER_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 14U), /*!< early receive status flag */
  617. ENET_DMA_FLAG_AI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 15U), /*!< abnormal interrupt summary flag */
  618. ENET_DMA_FLAG_NI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
  619. }enet_flag_clear_enum;
  620. /* ENET interrupt enable/disable */
  621. typedef enum
  622. {
  623. /* ENET_MAC_INTMSK register */
  624. ENET_MAC_INT_WUMIM = ENET_REGIDX_BIT(MAC_INTMSK_REG_OFFSET, 3U), /*!< WUM interrupt mask */
  625. ENET_MAC_INT_TMSTIM = ENET_REGIDX_BIT(MAC_INTMSK_REG_OFFSET, 9U), /*!< timestamp trigger interrupt mask */
  626. /* ENET_MSC_RINTMSK register */
  627. ENET_MSC_INT_RFCEIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 5U), /*!< received frame CRC error interrupt mask */
  628. ENET_MSC_INT_RFAEIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 6U), /*!< received frames alignment error interrupt mask */
  629. ENET_MSC_INT_RGUFIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 17U), /*!< received good unicast frames interrupt mask */
  630. /* ENET_MSC_TINTMSK register */
  631. ENET_MSC_INT_TGFSCIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 14U), /*!< transmitted good frames single collision interrupt mask */
  632. ENET_MSC_INT_TGFMSCIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 15U), /*!< transmitted good frames more single collision interrupt mask */
  633. ENET_MSC_INT_TGFIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 21U), /*!< transmitted good frames interrupt mask */
  634. /* ENET_DMA_INTEN register */
  635. ENET_DMA_INT_TIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 0U), /*!< transmit interrupt enable */
  636. ENET_DMA_INT_TPSIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 1U), /*!< transmit process stopped interrupt enable */
  637. ENET_DMA_INT_TBUIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 2U), /*!< transmit buffer unavailable interrupt enable */
  638. ENET_DMA_INT_TJTIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 3U), /*!< transmit jabber timeout interrupt enable */
  639. ENET_DMA_INT_ROIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 4U), /*!< receive overflow interrupt enable */
  640. ENET_DMA_INT_TUIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 5U), /*!< transmit underflow interrupt enable */
  641. ENET_DMA_INT_RIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 6U), /*!< receive interrupt enable */
  642. ENET_DMA_INT_RBUIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 7U), /*!< receive buffer unavailable interrupt enable */
  643. ENET_DMA_INT_RPSIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 8U), /*!< receive process stopped interrupt enable */
  644. ENET_DMA_INT_RWTIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 9U), /*!< receive watchdog timeout interrupt enable */
  645. ENET_DMA_INT_ETIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 10U), /*!< early transmit interrupt enable */
  646. ENET_DMA_INT_FBEIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 13U), /*!< fatal bus error interrupt enable */
  647. ENET_DMA_INT_ERIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 14U), /*!< early receive interrupt enable */
  648. ENET_DMA_INT_AIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 15U), /*!< abnormal interrupt summary enable */
  649. ENET_DMA_INT_NIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 16U), /*!< normal interrupt summary enable */
  650. }enet_int_enum;
  651. /* ENET interrupt flag get */
  652. typedef enum
  653. {
  654. /* ENET_MAC_INTF register */
  655. ENET_MAC_INT_FLAG_WUM = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 3U), /*!< WUM status flag */
  656. ENET_MAC_INT_FLAG_MSC = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 4U), /*!< MSC status flag */
  657. ENET_MAC_INT_FLAG_MSCR = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 5U), /*!< MSC receive status flag */
  658. ENET_MAC_INT_FLAG_MSCT = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 6U), /*!< MSC transmit status flag */
  659. ENET_MAC_INT_FLAG_TMST = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 9U), /*!< timestamp trigger status flag */
  660. /* ENET_MSC_RINTF register */
  661. ENET_MSC_INT_FLAG_RFCE = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 5U), /*!< received frames CRC error flag */
  662. ENET_MSC_INT_FLAG_RFAE = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 6U), /*!< received frames alignment error flag */
  663. ENET_MSC_INT_FLAG_RGUF = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 17U), /*!< received good unicast frames flag */
  664. /* ENET_MSC_TINTF register */
  665. ENET_MSC_INT_FLAG_TGFSC = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 14U), /*!< transmitted good frames single collision flag */
  666. ENET_MSC_INT_FLAG_TGFMSC = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 15U), /*!< transmitted good frames more single collision flag */
  667. ENET_MSC_INT_FLAG_TGF = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 21U), /*!< transmitted good frames flag */
  668. /* ENET_DMA_STAT register */
  669. ENET_DMA_INT_FLAG_TS = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 0U), /*!< transmit status flag */
  670. ENET_DMA_INT_FLAG_TPS = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 1U), /*!< transmit process stopped status flag */
  671. ENET_DMA_INT_FLAG_TBU = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 2U), /*!< transmit buffer unavailable status flag */
  672. ENET_DMA_INT_FLAG_TJT = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 3U), /*!< transmit jabber timeout status flag */
  673. ENET_DMA_INT_FLAG_RO = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 4U), /*!< receive overflow status flag */
  674. ENET_DMA_INT_FLAG_TU = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 5U), /*!< transmit underflow status flag */
  675. ENET_DMA_INT_FLAG_RS = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 6U), /*!< receive status flag */
  676. ENET_DMA_INT_FLAG_RBU = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 7U), /*!< receive buffer unavailable status flag */
  677. ENET_DMA_INT_FLAG_RPS = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 8U), /*!< receive process stopped status flag */
  678. ENET_DMA_INT_FLAG_RWT = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 9U), /*!< receive watchdog timeout status flag */
  679. ENET_DMA_INT_FLAG_ET = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 10U), /*!< early transmit status flag */
  680. ENET_DMA_INT_FLAG_FBE = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 13U), /*!< fatal bus error status flag */
  681. ENET_DMA_INT_FLAG_ER = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 14U), /*!< early receive status flag */
  682. ENET_DMA_INT_FLAG_AI = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 15U), /*!< abnormal interrupt summary flag */
  683. ENET_DMA_INT_FLAG_NI = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
  684. ENET_DMA_INT_FLAG_MSC = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 27U), /*!< MSC status flag */
  685. ENET_DMA_INT_FLAG_WUM = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 28U), /*!< WUM status flag */
  686. ENET_DMA_INT_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U), /*!< timestamp trigger status flag */
  687. }enet_int_flag_enum;
  688. /* ENET interrupt flag clear */
  689. typedef enum
  690. {
  691. /* ENET_DMA_STAT register */
  692. ENET_DMA_INT_FLAG_TS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 0U), /*!< transmit status flag */
  693. ENET_DMA_INT_FLAG_TPS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 1U), /*!< transmit process stopped status flag */
  694. ENET_DMA_INT_FLAG_TBU_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 2U), /*!< transmit buffer unavailable status flag */
  695. ENET_DMA_INT_FLAG_TJT_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 3U), /*!< transmit jabber timeout status flag */
  696. ENET_DMA_INT_FLAG_RO_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 4U), /*!< receive overflow status flag */
  697. ENET_DMA_INT_FLAG_TU_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 5U), /*!< transmit underflow status flag */
  698. ENET_DMA_INT_FLAG_RS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 6U), /*!< receive status flag */
  699. ENET_DMA_INT_FLAG_RBU_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 7U), /*!< receive buffer unavailable status flag */
  700. ENET_DMA_INT_FLAG_RPS_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 8U), /*!< receive process stopped status flag */
  701. ENET_DMA_INT_FLAG_RWT_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 9U), /*!< receive watchdog timeout status flag */
  702. ENET_DMA_INT_FLAG_ET_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 10U), /*!< early transmit status flag */
  703. ENET_DMA_INT_FLAG_FBE_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 13U), /*!< fatal bus error status flag */
  704. ENET_DMA_INT_FLAG_ER_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 14U), /*!< early receive status flag */
  705. ENET_DMA_INT_FLAG_AI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 15U), /*!< abnormal interrupt summary flag */
  706. ENET_DMA_INT_FLAG_NI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
  707. }enet_int_flag_clear_enum;
  708. /* current RX/TX descriptor/buffer/descriptor table address get */
  709. typedef enum
  710. {
  711. ENET_RX_DESC_TABLE = DMA_RDTADDR_REG_OFFSET, /*!< RX descriptor table */
  712. ENET_RX_CURRENT_DESC = DMA_CRDADDR_REG_OFFSET, /*!< current RX descriptor */
  713. ENET_RX_CURRENT_BUFFER = DMA_CRBADDR_REG_OFFSET, /*!< current RX buffer */
  714. ENET_TX_DESC_TABLE = DMA_TDTADDR_REG_OFFSET, /*!< TX descriptor table */
  715. ENET_TX_CURRENT_DESC = DMA_CTDADDR_REG_OFFSET, /*!< current TX descriptor */
  716. ENET_TX_CURRENT_BUFFER = DMA_CTBADDR_REG_OFFSET /*!< current TX buffer */
  717. }enet_desc_reg_enum;
  718. /* MAC statistics counter get */
  719. typedef enum
  720. {
  721. ENET_MSC_TX_SCCNT = MSC_SCCNT_REG_OFFSET, /*!< MSC transmitted good frames after a single collision counter */
  722. ENET_MSC_TX_MSCCNT = MSC_MSCCNT_REG_OFFSET, /*!< MSC transmitted good frames after more than a single collision counter */
  723. ENET_MSC_TX_TGFCNT = MSC_TGFCNT_REG_OFFSET, /*!< MSC transmitted good frames counter */
  724. ENET_MSC_RX_RFCECNT = MSC_RFCECNT_REG_OFFSET, /*!< MSC received frames with CRC error counter */
  725. ENET_MSC_RX_RFAECNT = MSC_RFAECNT_REG_OFFSET, /*!< MSC received frames with alignment error counter */
  726. ENET_MSC_RX_RGUFCNT = MSC_RGUFCNT_REG_OFFSET /*!< MSC received good unicast frames counter */
  727. }enet_msc_counter_enum;
  728. /* function option, used for ENET initialization */
  729. typedef enum
  730. {
  731. FORWARD_OPTION = BIT(0), /*!< configure the frame forward related parameters */
  732. DMABUS_OPTION = BIT(1), /*!< configure the DMA bus mode related parameters */
  733. DMA_MAXBURST_OPTION = BIT(2), /*!< configure the DMA max burst related parameters */
  734. DMA_ARBITRATION_OPTION = BIT(3), /*!< configure the DMA arbitration related parameters */
  735. STORE_OPTION = BIT(4), /*!< configure the store forward mode related parameters */
  736. DMA_OPTION = BIT(5), /*!< configure the DMA control related parameters */
  737. VLAN_OPTION = BIT(6), /*!< configure the VLAN tag related parameters */
  738. FLOWCTL_OPTION = BIT(7), /*!< configure the flow control related parameters */
  739. HASHH_OPTION = BIT(8), /*!< configure the hash list high 32-bit related parameters */
  740. HASHL_OPTION = BIT(9), /*!< configure the hash list low 32-bit related parameters */
  741. FILTER_OPTION = BIT(10), /*!< configure the frame filter control related parameters */
  742. HALFDUPLEX_OPTION = BIT(11), /*!< configure the halfduplex related parameters */
  743. TIMER_OPTION = BIT(12), /*!< configure the frame timer related parameters */
  744. INTERFRAMEGAP_OPTION = BIT(13), /*!< configure the inter frame gap related parameters */
  745. }enet_option_enum;
  746. /* phy mode and mac loopback configurations */
  747. typedef enum
  748. {
  749. ENET_AUTO_NEGOTIATION = 0x01u, /*!< PHY auto negotiation */
  750. ENET_100M_FULLDUPLEX = (ENET_MAC_CFG_SPD | ENET_MAC_CFG_DPM), /*!< 100Mbit/s, full-duplex */
  751. ENET_100M_HALFDUPLEX = ENET_MAC_CFG_SPD , /*!< 100Mbit/s, half-duplex */
  752. ENET_10M_FULLDUPLEX = ENET_MAC_CFG_DPM, /*!< 10Mbit/s, full-duplex */
  753. ENET_10M_HALFDUPLEX = (uint32_t)0x00000000U, /*!< 10Mbit/s, half-duplex */
  754. ENET_LOOPBACKMODE = (ENET_MAC_CFG_LBM | ENET_MAC_CFG_DPM) /*!< MAC in loopback mode at the MII */
  755. }enet_mediamode_enum;
  756. /* IP frame checksum function */
  757. typedef enum
  758. {
  759. ENET_NO_AUTOCHECKSUM = (uint32_t)0x00000000U, /*!< disable IP frame checksum function */
  760. ENET_AUTOCHECKSUM_DROP_FAILFRAMES = ENET_MAC_CFG_IPFCO, /*!< enable IP frame checksum function */
  761. ENET_AUTOCHECKSUM_ACCEPT_FAILFRAMES = (ENET_MAC_CFG_IPFCO|ENET_DMA_CTL_DTCERFD) /*!< enable IP frame checksum function, and the received frame
  762. with only payload error but no other errors will not be dropped */
  763. }enet_chksumconf_enum;
  764. /* received frame filter function */
  765. typedef enum
  766. {
  767. ENET_PROMISCUOUS_MODE = ENET_MAC_FRMF_PM, /*!< promiscuous mode enabled */
  768. ENET_RECEIVEALL = (int32_t)ENET_MAC_FRMF_FAR, /*!< all received frame are forwarded to application */
  769. ENET_BROADCAST_FRAMES_PASS = (uint32_t)0x00000000U, /*!< the address filters pass all received broadcast frames */
  770. ENET_BROADCAST_FRAMES_DROP = ENET_MAC_FRMF_BFRMD /*!< the address filters filter all incoming broadcast frames */
  771. }enet_frmrecept_enum;
  772. /* register group value get */
  773. typedef enum
  774. {
  775. ALL_MAC_REG = 0, /*!< MAC register group */
  776. ALL_MSC_REG = 22, /*!< MSC register group */
  777. ALL_PTP_REG = 33, /*!< PTP register group */
  778. ALL_DMA_REG = 44, /*!< DMA register group */
  779. }enet_registers_type_enum;
  780. /* dma direction select */
  781. typedef enum
  782. {
  783. ENET_DMA_TX = ENET_DMA_STAT_TP, /*!< DMA transmit direction */
  784. ENET_DMA_RX = ENET_DMA_STAT_RP /*!< DMA receive direction */
  785. }enet_dmadirection_enum;
  786. /* PHY operation direction select */
  787. typedef enum
  788. {
  789. ENET_PHY_READ = (uint32_t)0x00000000, /*!< read PHY */
  790. ENET_PHY_WRITE = ENET_MAC_PHY_CTL_PW /*!< write PHY */
  791. }enet_phydirection_enum;
  792. /* register operation direction select */
  793. typedef enum
  794. {
  795. ENET_REG_READ, /*!< read register */
  796. ENET_REG_WRITE /*!< write register */
  797. }enet_regdirection_enum;
  798. /* ENET MAC addresses */
  799. typedef enum
  800. {
  801. ENET_MAC_ADDRESS0 = ((uint32_t)0x00000000), /*!< MAC address0 */
  802. ENET_MAC_ADDRESS1 = ((uint32_t)0x00000008), /*!< MAC address1 */
  803. ENET_MAC_ADDRESS2 = ((uint32_t)0x00000010), /*!< MAC address2 */
  804. ENET_MAC_ADDRESS3 = ((uint32_t)0x00000018) /*!< MAC address3 */
  805. }enet_macaddress_enum;
  806. /* descriptor information */
  807. typedef enum
  808. {
  809. TXDESC_COLLISION_COUNT, /*!< the number of collisions occurred before the frame was transmitted */
  810. TXDESC_BUFFER_1_ADDR, /*!< transmit frame buffer 1 address */
  811. RXDESC_FRAME_LENGTH, /*!< the byte length of the received frame that was transferred to the buffer */
  812. RXDESC_BUFFER_1_SIZE, /*!< receive buffer 1 size */
  813. RXDESC_BUFFER_2_SIZE, /*!< receive buffer 2 size */
  814. RXDESC_BUFFER_1_ADDR /*!< receive frame buffer 1 address */
  815. }enet_descstate_enum;
  816. /* MSC counters preset mode */
  817. typedef enum
  818. {
  819. ENET_MSC_PRESET_NONE = 0U, /*!< do not preset MSC counter */
  820. ENET_MSC_PRESET_HALF = ENET_MSC_CTL_PMC, /*!< preset all MSC counters to almost-half(0x7FFF FFF0) value */
  821. ENET_MSC_PRESET_FULL = ENET_MSC_CTL_PMC | ENET_MSC_CTL_AFHPM /*!< preset all MSC counters to almost-full(0xFFFF FFF0) value */
  822. }enet_msc_preset_enum;
  823. /* structure for initialization of the ENET */
  824. typedef struct
  825. {
  826. uint32_t option_enable; /*!< select which function to configure */
  827. uint32_t forward_frame; /*!< frame forward related parameters */
  828. uint32_t dmabus_mode; /*!< DMA bus mode related parameters */
  829. uint32_t dma_maxburst; /*!< DMA max burst related parameters */
  830. uint32_t dma_arbitration; /*!< DMA Tx and Rx arbitration related parameters */
  831. uint32_t store_forward_mode; /*!< store forward mode related parameters */
  832. uint32_t dma_function; /*!< DMA control related parameters */
  833. uint32_t vlan_config; /*!< VLAN tag related parameters */
  834. uint32_t flow_control; /*!< flow control related parameters */
  835. uint32_t hashtable_high; /*!< hash list high 32-bit related parameters */
  836. uint32_t hashtable_low; /*!< hash list low 32-bit related parameters */
  837. uint32_t framesfilter_mode; /*!< frame filter control related parameters */
  838. uint32_t halfduplex_param; /*!< halfduplex related parameters */
  839. uint32_t timer_config; /*!< frame timer related parameters */
  840. uint32_t interframegap; /*!< inter frame gap related parameters */
  841. }enet_initpara_struct;
  842. /* structure for ENET DMA desciptors */
  843. typedef struct
  844. {
  845. uint32_t status; /*!< status */
  846. uint32_t control_buffer_size; /*!< control and buffer1, buffer2 lengths */
  847. uint32_t buffer1_addr; /*!< buffer1 address pointer/timestamp low */
  848. uint32_t buffer2_next_desc_addr; /*!< buffer2 or next descriptor address pointer/timestamp high */
  849. #ifdef SELECT_DESCRIPTORS_ENHANCED_MODE
  850. uint32_t extended_status; /*!< extended status */
  851. uint32_t reserved; /*!< reserved */
  852. uint32_t timestamp_low; /*!< timestamp low */
  853. uint32_t timestamp_high; /*!< timestamp high */
  854. #endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
  855. } enet_descriptors_struct;
  856. /* structure of PTP system time */
  857. typedef struct
  858. {
  859. uint32_t second; /*!< second of system time */
  860. uint32_t nanosecond; /*!< nanosecond of system time */
  861. uint32_t sign; /*!< sign of system time */
  862. }enet_ptp_systime_struct;
  863. /* mac_cfg register value */
  864. #define MAC_CFG_BOL(regval) (BITS(5,6) & ((uint32_t)(regval) << 5)) /*!< write value to ENET_MAC_CFG_BOL bit field */
  865. #define ENET_BACKOFFLIMIT_10 MAC_CFG_BOL(0) /*!< min (n, 10) */
  866. #define ENET_BACKOFFLIMIT_8 MAC_CFG_BOL(1) /*!< min (n, 8) */
  867. #define ENET_BACKOFFLIMIT_4 MAC_CFG_BOL(2) /*!< min (n, 4) */
  868. #define ENET_BACKOFFLIMIT_1 MAC_CFG_BOL(3) /*!< min (n, 1) */
  869. #define MAC_CFG_IGBS(regval) (BITS(17,19) & ((uint32_t)(regval) << 17)) /*!< write value to ENET_MAC_CFG_IGBS bit field */
  870. #define ENET_INTERFRAMEGAP_96BIT MAC_CFG_IGBS(0) /*!< minimum 96 bit times */
  871. #define ENET_INTERFRAMEGAP_88BIT MAC_CFG_IGBS(1) /*!< minimum 88 bit times */
  872. #define ENET_INTERFRAMEGAP_80BIT MAC_CFG_IGBS(2) /*!< minimum 80 bit times */
  873. #define ENET_INTERFRAMEGAP_72BIT MAC_CFG_IGBS(3) /*!< minimum 72 bit times */
  874. #define ENET_INTERFRAMEGAP_64BIT MAC_CFG_IGBS(4) /*!< minimum 64 bit times */
  875. #define ENET_INTERFRAMEGAP_56BIT MAC_CFG_IGBS(5) /*!< minimum 56 bit times */
  876. #define ENET_INTERFRAMEGAP_48BIT MAC_CFG_IGBS(6) /*!< minimum 48 bit times */
  877. #define ENET_INTERFRAMEGAP_40BIT MAC_CFG_IGBS(7) /*!< minimum 40 bit times */
  878. #define ENET_TYPEFRAME_CRC_DROP_ENABLE ENET_MAC_CFG_TFCD /*!< FCS field(last 4 bytes) of frame will be dropped before forwarding */
  879. #define ENET_TYPEFRAME_CRC_DROP_DISABLE ((uint32_t)0x00000000U) /*!< FCS field(last 4 bytes) of frame will not be dropped before forwarding */
  880. #define ENET_TYPEFRAME_CRC_DROP ENET_MAC_CFG_TFCD /*!< the function that FCS field(last 4 bytes) of frame will be dropped before forwarding */
  881. #define ENET_WATCHDOG_ENABLE ((uint32_t)0x00000000U) /*!< the MAC allows no more than 2048 bytes of the frame being received */
  882. #define ENET_WATCHDOG_DISABLE ENET_MAC_CFG_WDD /*!< the MAC disables the watchdog timer on the receiver, and can receive frames of up to 16384 bytes */
  883. #define ENET_JABBER_ENABLE ((uint32_t)0x00000000U) /*!< the maximum transmission byte is 2048 */
  884. #define ENET_JABBER_DISABLE ENET_MAC_CFG_JBD /*!< the maximum transmission byte can be 16384 */
  885. #define ENET_CARRIERSENSE_ENABLE ((uint32_t)0x00000000U) /*!< the MAC transmitter generates carrier sense error and aborts the transmission */
  886. #define ENET_CARRIERSENSE_DISABLE ENET_MAC_CFG_CSD /*!< the MAC transmitter ignores the MII CRS signal during frame transmission in half-duplex mode */
  887. #define ENET_SPEEDMODE_10M ((uint32_t)0x00000000U) /*!< 10 Mbit/s */
  888. #define ENET_SPEEDMODE_100M ENET_MAC_CFG_SPD /*!< 100 Mbit/s */
  889. #define ENET_RECEIVEOWN_ENABLE ((uint32_t)0x00000000U) /*!< the MAC receives all packets that are given by the PHY while transmitting */
  890. #define ENET_RECEIVEOWN_DISABLE ENET_MAC_CFG_ROD /*!< the MAC disables the reception of frames in half-duplex mode */
  891. #define ENET_LOOPBACKMODE_ENABLE ENET_MAC_CFG_LBM /*!< the MAC operates in loopback mode at the MII */
  892. #define ENET_LOOPBACKMODE_DISABLE ((uint32_t)0x00000000U) /*!< the MAC operates in normal mode */
  893. #define ENET_MODE_FULLDUPLEX ENET_MAC_CFG_DPM /*!< full-duplex mode enable */
  894. #define ENET_MODE_HALFDUPLEX ((uint32_t)0x00000000U) /*!< half-duplex mode enable */
  895. #define ENET_CHECKSUMOFFLOAD_ENABLE ENET_MAC_CFG_IPFCO /*!< IP frame checksum offload function enabled for received IP frame */
  896. #define ENET_CHECKSUMOFFLOAD_DISABLE ((uint32_t)0x00000000U) /*!< the checksum offload function in the receiver is disabled */
  897. #define ENET_RETRYTRANSMISSION_ENABLE ((uint32_t)0x00000000U) /*!< the MAC attempts retries up to 16 times based on the settings of BOL*/
  898. #define ENET_RETRYTRANSMISSION_DISABLE ENET_MAC_CFG_RTD /*!< the MAC attempts only 1 transmission */
  899. #define ENET_AUTO_PADCRC_DROP_ENABLE ENET_MAC_CFG_APCD /*!< the MAC strips the Pad/FCS field on received frames */
  900. #define ENET_AUTO_PADCRC_DROP_DISABLE ((uint32_t)0x00000000U) /*!< the MAC forwards all received frames without modify it */
  901. #define ENET_AUTO_PADCRC_DROP ENET_MAC_CFG_APCD /*!< the function of the MAC strips the Pad/FCS field on received frames */
  902. #define ENET_DEFERRALCHECK_ENABLE ENET_MAC_CFG_DFC /*!< the deferral check function is enabled in the MAC */
  903. #define ENET_DEFERRALCHECK_DISABLE ((uint32_t)0x00000000U) /*!< the deferral check function is disabled */
  904. /* mac_frmf register value */
  905. #define MAC_FRMF_PCFRM(regval) (BITS(6,7) & ((uint32_t)(regval) << 6)) /*!< write value to ENET_MAC_FRMF_PCFRM bit field */
  906. #define ENET_PCFRM_PREVENT_ALL MAC_FRMF_PCFRM(0) /*!< MAC prevents all control frames from reaching the application */
  907. #define ENET_PCFRM_PREVENT_PAUSEFRAME MAC_FRMF_PCFRM(1) /*!< MAC only forwards all other control frames except pause control frame */
  908. #define ENET_PCFRM_FORWARD_ALL MAC_FRMF_PCFRM(2) /*!< MAC forwards all control frames to application even if they fail the address filter */
  909. #define ENET_PCFRM_FORWARD_FILTERED MAC_FRMF_PCFRM(3) /*!< MAC forwards control frames that only pass the address filter */
  910. #define ENET_RX_FILTER_DISABLE ENET_MAC_FRMF_FAR /*!< all received frame are forwarded to application */
  911. #define ENET_RX_FILTER_ENABLE ((uint32_t)0x00000000U) /*!< only the frame passed the filter can be forwarded to application */
  912. #define ENET_SRC_FILTER_NORMAL_ENABLE ENET_MAC_FRMF_SAFLT /*!< filter source address */
  913. #define ENET_SRC_FILTER_INVERSE_ENABLE (ENET_MAC_FRMF_SAFLT | ENET_MAC_FRMF_SAIFLT) /*!< inverse source address filtering result */
  914. #define ENET_SRC_FILTER_DISABLE ((uint32_t)0x00000000U) /*!< source address function in filter disable */
  915. #define ENET_SRC_FILTER ENET_MAC_FRMF_SAFLT /*!< filter source address function */
  916. #define ENET_SRC_FILTER_INVERSE ENET_MAC_FRMF_SAIFLT /*!< inverse source address filtering result function */
  917. #define ENET_BROADCASTFRAMES_ENABLE ((uint32_t)0x00000000U) /*!< the address filters pass all received broadcast frames */
  918. #define ENET_BROADCASTFRAMES_DISABLE ENET_MAC_FRMF_BFRMD /*!< the address filters filter all incoming broadcast frames */
  919. #define ENET_DEST_FILTER_INVERSE_ENABLE ENET_MAC_FRMF_DAIFLT /*!< inverse DA filtering result */
  920. #define ENET_DEST_FILTER_INVERSE_DISABLE ((uint32_t)0x00000000U) /*!< not inverse DA filtering result */
  921. #define ENET_DEST_FILTER_INVERSE ENET_MAC_FRMF_DAIFLT /*!< inverse DA filtering result function */
  922. #define ENET_PROMISCUOUS_ENABLE ENET_MAC_FRMF_PM /*!< promiscuous mode enabled */
  923. #define ENET_PROMISCUOUS_DISABLE ((uint32_t)0x00000000U) /*!< promiscuous mode disabled */
  924. #define ENET_MULTICAST_FILTER_HASH_OR_PERFECT (ENET_MAC_FRMF_HMF | ENET_MAC_FRMF_HPFLT) /*!< pass multicast frames that match either the perfect or the hash filtering */
  925. #define ENET_MULTICAST_FILTER_HASH ENET_MAC_FRMF_HMF /*!< pass multicast frames that match the hash filtering */
  926. #define ENET_MULTICAST_FILTER_PERFECT ((uint32_t)0x00000000U) /*!< pass multicast frames that match the perfect filtering */
  927. #define ENET_MULTICAST_FILTER_NONE ENET_MAC_FRMF_MFD /*!< all multicast frames are passed */
  928. #define ENET_MULTICAST_FILTER_PASS ENET_MAC_FRMF_MFD /*!< pass all multicast frames function */
  929. #define ENET_MULTICAST_FILTER_HASH_MODE ENET_MAC_FRMF_HMF /*!< HASH multicast filter function */
  930. #define ENET_FILTER_MODE_EITHER ENET_MAC_FRMF_HPFLT /*!< HASH or perfect filter function */
  931. #define ENET_UNICAST_FILTER_EITHER (ENET_MAC_FRMF_HUF | ENET_MAC_FRMF_HPFLT) /*!< pass unicast frames that match either the perfect or the hash filtering */
  932. #define ENET_UNICAST_FILTER_HASH ENET_MAC_FRMF_HUF /*!< pass unicast frames that match the hash filtering */
  933. #define ENET_UNICAST_FILTER_PERFECT ((uint32_t)0x00000000U) /*!< pass unicast frames that match the perfect filtering */
  934. #define ENET_UNICAST_FILTER_HASH_MODE ENET_MAC_FRMF_HUF /*!< HASH unicast filter function */
  935. /* mac_phy_ctl register value */
  936. #define MAC_PHY_CTL_CLR(regval) (BITS(2,4) & ((uint32_t)(regval) << 2)) /*!< write value to ENET_MAC_PHY_CTL_CLR bit field */
  937. #define ENET_MDC_HCLK_DIV42 MAC_PHY_CTL_CLR(0) /*!< HCLK:60-100 MHz; MDC clock= HCLK/42 */
  938. #define ENET_MDC_HCLK_DIV62 MAC_PHY_CTL_CLR(1) /*!< HCLK:100-120 MHz; MDC clock= HCLK/62 */
  939. #define ENET_MDC_HCLK_DIV16 MAC_PHY_CTL_CLR(2) /*!< HCLK:20-35 MHz; MDC clock= HCLK/16 */
  940. #define ENET_MDC_HCLK_DIV26 MAC_PHY_CTL_CLR(3) /*!< HCLK:35-60 MHz; MDC clock= HCLK/26 */
  941. #define MAC_PHY_CTL_PR(regval) (BITS(6,10) & ((uint32_t)(regval) << 6)) /*!< write value to ENET_MAC_PHY_CTL_PR bit field */
  942. #define MAC_PHY_CTL_PA(regval) (BITS(11,15) & ((uint32_t)(regval) << 11)) /*!< write value to ENET_MAC_PHY_CTL_PA bit field */
  943. /* mac_phy_data register value */
  944. #define MAC_PHY_DATA_PD(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_PHY_DATA_PD bit field */
  945. /* mac_fctl register value */
  946. #define MAC_FCTL_PLTS(regval) (BITS(4,5) & ((uint32_t)(regval) << 4)) /*!< write value to ENET_MAC_FCTL_PLTS bit field */
  947. #define ENET_PAUSETIME_MINUS4 MAC_FCTL_PLTS(0) /*!< pause time minus 4 slot times */
  948. #define ENET_PAUSETIME_MINUS28 MAC_FCTL_PLTS(1) /*!< pause time minus 28 slot times */
  949. #define ENET_PAUSETIME_MINUS144 MAC_FCTL_PLTS(2) /*!< pause time minus 144 slot times */
  950. #define ENET_PAUSETIME_MINUS256 MAC_FCTL_PLTS(3) /*!< pause time minus 256 slot times */
  951. #define ENET_ZERO_QUANTA_PAUSE_ENABLE ((uint32_t)0x00000000U) /*!< enable the automatic zero-quanta generation function */
  952. #define ENET_ZERO_QUANTA_PAUSE_DISABLE ENET_MAC_FCTL_DZQP /*!< disable the automatic zero-quanta generation function */
  953. #define ENET_ZERO_QUANTA_PAUSE ENET_MAC_FCTL_DZQP /*!< the automatic zero-quanta generation function */
  954. #define ENET_MAC0_AND_UNIQUE_ADDRESS_PAUSEDETECT ENET_MAC_FCTL_UPFDT /*!< besides the unique multicast address, MAC also use the MAC0 address to detect pause frame */
  955. #define ENET_UNIQUE_PAUSEDETECT ((uint32_t)0x00000000U) /*!< only the unique multicast address for pause frame which is specified in IEEE802.3 can be detected */
  956. #define ENET_RX_FLOWCONTROL_ENABLE ENET_MAC_FCTL_RFCEN /*!< enable decoding function for the received pause frame and process it */
  957. #define ENET_RX_FLOWCONTROL_DISABLE ((uint32_t)0x00000000U) /*!< decode function for pause frame is disabled */
  958. #define ENET_RX_FLOWCONTROL ENET_MAC_FCTL_RFCEN /*!< decoding function for the received pause frame and process it */
  959. #define ENET_TX_FLOWCONTROL_ENABLE ENET_MAC_FCTL_TFCEN /*!< enable the flow control operation in the MAC */
  960. #define ENET_TX_FLOWCONTROL_DISABLE ((uint32_t)0x00000000U) /*!< disable the flow control operation in the MAC */
  961. #define ENET_TX_FLOWCONTROL ENET_MAC_FCTL_TFCEN /*!< the flow control operation in the MAC */
  962. #define ENET_BACK_PRESSURE_ENABLE ENET_MAC_FCTL_FLCBBKPA /*!< enable the back pressure operation in the MAC */
  963. #define ENET_BACK_PRESSURE_DISABLE ((uint32_t)0x00000000U) /*!< disable the back pressure operation in the MAC */
  964. #define ENET_BACK_PRESSURE ENET_MAC_FCTL_FLCBBKPA /*!< the back pressure operation in the MAC */
  965. #define MAC_FCTL_PTM(regval) (BITS(16,31) & ((uint32_t)(regval) << 16)) /*!< write value to ENET_MAC_FCTL_PTM bit field */
  966. /* mac_vlt register value */
  967. #define MAC_VLT_VLTI(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_VLT_VLTI bit field */
  968. #define ENET_VLANTAGCOMPARISON_12BIT ENET_MAC_VLT_VLTC /*!< only low 12 bits of the VLAN tag are used for comparison */
  969. #define ENET_VLANTAGCOMPARISON_16BIT ((uint32_t)0x00000000U) /*!< all 16 bits of the VLAN tag are used for comparison */
  970. /* mac_wum register value */
  971. #define ENET_WUM_FLAG_WUFFRPR ENET_MAC_WUM_WUFFRPR /*!< wakeup frame filter register poniter reset */
  972. #define ENET_WUM_FLAG_WUFR ENET_MAC_WUM_WUFR /*!< wakeup frame received */
  973. #define ENET_WUM_FLAG_MPKR ENET_MAC_WUM_MPKR /*!< magic packet received */
  974. #define ENET_WUM_POWER_DOWN ENET_MAC_WUM_PWD /*!< power down mode */
  975. #define ENET_WUM_MAGIC_PACKET_FRAME ENET_MAC_WUM_MPEN /*!< enable a wakeup event due to magic packet reception */
  976. #define ENET_WUM_WAKE_UP_FRAME ENET_MAC_WUM_WFEN /*!< enable a wakeup event due to wakeup frame reception */
  977. #define ENET_WUM_GLOBAL_UNICAST ENET_MAC_WUM_GU /*!< any received unicast frame passed filter is considered to be a wakeup frame */
  978. /* mac_dbg register value */
  979. #define ENET_MAC_RECEIVER_NOT_IDLE ENET_MAC_DBG_MRNI /*!< MAC receiver is not in idle state */
  980. #define ENET_RX_ASYNCHRONOUS_FIFO_STATE ENET_MAC_DBG_RXAFS /*!< Rx asynchronous FIFO status */
  981. #define ENET_RXFIFO_WRITING ENET_MAC_DBG_RXFW /*!< RxFIFO is doing write operation */
  982. #define ENET_RXFIFO_READ_STATUS ENET_MAC_DBG_RXFRS /*!< RxFIFO read operation status */
  983. #define ENET_RXFIFO_STATE ENET_MAC_DBG_RXFS /*!< RxFIFO state */
  984. #define ENET_MAC_TRANSMITTER_NOT_IDLE ENET_MAC_DBG_MTNI /*!< MAC transmitter is not in idle state */
  985. #define ENET_MAC_TRANSMITTER_STATUS ENET_MAC_DBG_SOMT /*!< status of MAC transmitter */
  986. #define ENET_PAUSE_CONDITION_STATUS ENET_MAC_DBG_PCS /*!< pause condition status */
  987. #define ENET_TXFIFO_READ_STATUS ENET_MAC_DBG_TXFRS /*!< TxFIFO read operation status */
  988. #define ENET_TXFIFO_WRITING ENET_MAC_DBG_TXFW /*!< TxFIFO is doing write operation */
  989. #define ENET_TXFIFO_NOT_EMPTY ENET_MAC_DBG_TXFNE /*!< TxFIFO is not empty */
  990. #define ENET_TXFIFO_FULL ENET_MAC_DBG_TXFF /*!< TxFIFO is full */
  991. #define GET_MAC_DBG_RXAFS(regval) GET_BITS((regval),1,2) /*!< get value of ENET_MAC_DBG_RXAFS bit field */
  992. #define GET_MAC_DBG_RXFRS(regval) GET_BITS((regval),5,6) /*!< get value of ENET_MAC_DBG_RXFRS bit field */
  993. #define GET_MAC_DBG_RXFS(regval) GET_BITS((regval),8,9) /*!< get value of ENET_MAC_DBG_RXFS bit field */
  994. #define GET_MAC_DBG_SOMT(regval) GET_BITS((regval),17,18) /*!< get value of ENET_MAC_DBG_SOMT bit field */
  995. #define GET_MAC_DBG_TXFRS(regval) GET_BITS((regval),20,21) /*!< get value of ENET_MAC_DBG_TXFRS bit field */
  996. /* mac_addr0h register value */
  997. #define MAC_ADDR0H_ADDR0H(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_ADDR0H_ADDR0H bit field */
  998. /* mac_addrxh register value, x = 1,2,3 */
  999. #define MAC_ADDR123H_ADDR123H(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_ADDRxH_ADDRxH(x=1,2,3) bit field */
  1000. #define ENET_ADDRESS_MASK_BYTE0 BIT(24) /*!< low register bits [7:0] */
  1001. #define ENET_ADDRESS_MASK_BYTE1 BIT(25) /*!< low register bits [15:8] */
  1002. #define ENET_ADDRESS_MASK_BYTE2 BIT(26) /*!< low register bits [23:16] */
  1003. #define ENET_ADDRESS_MASK_BYTE3 BIT(27) /*!< low register bits [31:24] */
  1004. #define ENET_ADDRESS_MASK_BYTE4 BIT(28) /*!< high register bits [7:0] */
  1005. #define ENET_ADDRESS_MASK_BYTE5 BIT(29) /*!< high register bits [15:8] */
  1006. #define ENET_ADDRESS_FILTER_SA BIT(30) /*!< use MAC address[47:0] is to compare with the SA fields of the received frame */
  1007. #define ENET_ADDRESS_FILTER_DA ((uint32_t)0x00000000) /*!< use MAC address[47:0] is to compare with the DA fields of the received frame */
  1008. /* mac_fcth register value */
  1009. #define MAC_FCTH_RFA(regval) ((BITS(0,2) & ((uint32_t)(regval) << 0)) << 8) /*!< write value to ENET_MAC_FCTH_RFA bit field */
  1010. #define ENET_ACTIVE_THRESHOLD_256BYTES MAC_FCTH_RFA(0) /*!< threshold level is 256 bytes */
  1011. #define ENET_ACTIVE_THRESHOLD_512BYTES MAC_FCTH_RFA(1) /*!< threshold level is 512 bytes */
  1012. #define ENET_ACTIVE_THRESHOLD_768BYTES MAC_FCTH_RFA(2) /*!< threshold level is 768 bytes */
  1013. #define ENET_ACTIVE_THRESHOLD_1024BYTES MAC_FCTH_RFA(3) /*!< threshold level is 1024 bytes */
  1014. #define ENET_ACTIVE_THRESHOLD_1280BYTES MAC_FCTH_RFA(4) /*!< threshold level is 1280 bytes */
  1015. #define ENET_ACTIVE_THRESHOLD_1536BYTES MAC_FCTH_RFA(5) /*!< threshold level is 1536 bytes */
  1016. #define ENET_ACTIVE_THRESHOLD_1792BYTES MAC_FCTH_RFA(6) /*!< threshold level is 1792 bytes */
  1017. #define MAC_FCTH_RFD(regval) ((BITS(4,6) & ((uint32_t)(regval) << 4)) << 8) /*!< write value to ENET_MAC_FCTH_RFD bit field */
  1018. #define ENET_DEACTIVE_THRESHOLD_256BYTES MAC_FCTH_RFD(0) /*!< threshold level is 256 bytes */
  1019. #define ENET_DEACTIVE_THRESHOLD_512BYTES MAC_FCTH_RFD(1) /*!< threshold level is 512 bytes */
  1020. #define ENET_DEACTIVE_THRESHOLD_768BYTES MAC_FCTH_RFD(2) /*!< threshold level is 768 bytes */
  1021. #define ENET_DEACTIVE_THRESHOLD_1024BYTES MAC_FCTH_RFD(3) /*!< threshold level is 1024 bytes */
  1022. #define ENET_DEACTIVE_THRESHOLD_1280BYTES MAC_FCTH_RFD(4) /*!< threshold level is 1280 bytes */
  1023. #define ENET_DEACTIVE_THRESHOLD_1536BYTES MAC_FCTH_RFD(5) /*!< threshold level is 1536 bytes */
  1024. #define ENET_DEACTIVE_THRESHOLD_1792BYTES MAC_FCTH_RFD(6) /*!< threshold level is 1792 bytes */
  1025. /* msc_ctl register value */
  1026. #define ENET_MSC_COUNTER_STOP_ROLLOVER ENET_MSC_CTL_CTSR /*!< counter stop rollover */
  1027. #define ENET_MSC_RESET_ON_READ ENET_MSC_CTL_RTOR /*!< reset on read */
  1028. #define ENET_MSC_COUNTERS_FREEZE ENET_MSC_CTL_MCFZ /*!< MSC counter freeze */
  1029. /* ptp_tsctl register value */
  1030. #define PTP_TSCTL_CKNT(regval) (BITS(16,17) & ((uint32_t)(regval) << 16)) /*!< write value to ENET_PTP_TSCTL_CKNT bit field */
  1031. #define ENET_RXTX_TIMESTAMP ENET_PTP_TSCTL_TMSEN /*!< enable timestamp function for transmit and receive frames */
  1032. #define ENET_PTP_TIMESTAMP_INT ENET_PTP_TSCTL_TMSITEN /*!< timestamp interrupt trigger enable */
  1033. #define ENET_ALL_RX_TIMESTAMP ENET_PTP_TSCTL_ARFSEN /*!< all received frames are taken snapshot */
  1034. #define ENET_NONTYPE_FRAME_SNAPSHOT ENET_PTP_TSCTL_ESEN /*!< take snapshot when received non type frame */
  1035. #define ENET_IPV6_FRAME_SNAPSHOT ENET_PTP_TSCTL_IP6SEN /*!< take snapshot for IPv6 frame */
  1036. #define ENET_IPV4_FRAME_SNAPSHOT ENET_PTP_TSCTL_IP4SEN /*!< take snapshot for IPv4 frame */
  1037. #define ENET_PTP_FRAME_USE_MACADDRESS_FILTER ENET_PTP_TSCTL_MAFEN /*!< enable MAC address1-3 to filter the PTP frame */
  1038. /* ptp_ssinc register value */
  1039. #define PTP_SSINC_STMSSI(regval) (BITS(0,7) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_PTP_SSINC_STMSSI bit field */
  1040. /* ptp_tsl register value */
  1041. #define GET_PTP_TSL_STMSS(regval) GET_BITS((uint32_t)(regval),0,30) /*!< get value of ENET_PTP_TSL_STMSS bit field */
  1042. #define ENET_PTP_TIME_POSITIVE ((uint32_t)0x00000000) /*!< time value is positive */
  1043. #define ENET_PTP_TIME_NEGATIVE ENET_PTP_TSL_STS /*!< time value is negative */
  1044. #define GET_PTP_TSL_STS(regval) (((regval) & BIT(31)) >> (31U)) /*!< get value of ENET_PTP_TSL_STS bit field */
  1045. /* ptp_tsul register value */
  1046. #define PTP_TSUL_TMSUSS(regval) (BITS(0,30) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_PTP_TSUL_TMSUSS bit field */
  1047. #define ENET_PTP_ADD_TO_TIME ((uint32_t)0x00000000) /*!< timestamp update value is added to system time */
  1048. #define ENET_PTP_SUBSTRACT_FROM_TIME ENET_PTP_TSUL_TMSUPNS /*!< timestamp update value is subtracted from system time */
  1049. /* ptp_ppsctl register value */
  1050. #define PTP_PPSCTL_PPSOFC(regval) (BITS(0,3) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_PTP_PPSCTL_PPSOFC bit field */
  1051. #define ENET_PPSOFC_1HZ PTP_PPSCTL_PPSOFC(0) /*!< PPS output 1Hz frequency */
  1052. #define ENET_PPSOFC_2HZ PTP_PPSCTL_PPSOFC(1) /*!< PPS output 2Hz frequency */
  1053. #define ENET_PPSOFC_4HZ PTP_PPSCTL_PPSOFC(2) /*!< PPS output 4Hz frequency */
  1054. #define ENET_PPSOFC_8HZ PTP_PPSCTL_PPSOFC(3) /*!< PPS output 8Hz frequency */
  1055. #define ENET_PPSOFC_16HZ PTP_PPSCTL_PPSOFC(4) /*!< PPS output 16Hz frequency */
  1056. #define ENET_PPSOFC_32HZ PTP_PPSCTL_PPSOFC(5) /*!< PPS output 32Hz frequency */
  1057. #define ENET_PPSOFC_64HZ PTP_PPSCTL_PPSOFC(6) /*!< PPS output 64Hz frequency */
  1058. #define ENET_PPSOFC_128HZ PTP_PPSCTL_PPSOFC(7) /*!< PPS output 128Hz frequency */
  1059. #define ENET_PPSOFC_256HZ PTP_PPSCTL_PPSOFC(8) /*!< PPS output 256Hz frequency */
  1060. #define ENET_PPSOFC_512HZ PTP_PPSCTL_PPSOFC(9) /*!< PPS output 512Hz frequency */
  1061. #define ENET_PPSOFC_1024HZ PTP_PPSCTL_PPSOFC(10) /*!< PPS output 1024Hz frequency */
  1062. #define ENET_PPSOFC_2048HZ PTP_PPSCTL_PPSOFC(11) /*!< PPS output 2048Hz frequency */
  1063. #define ENET_PPSOFC_4096HZ PTP_PPSCTL_PPSOFC(12) /*!< PPS output 4096Hz frequency */
  1064. #define ENET_PPSOFC_8192HZ PTP_PPSCTL_PPSOFC(13) /*!< PPS output 8192Hz frequency */
  1065. #define ENET_PPSOFC_16384HZ PTP_PPSCTL_PPSOFC(14) /*!< PPS output 16384Hz frequency */
  1066. #define ENET_PPSOFC_32768HZ PTP_PPSCTL_PPSOFC(15) /*!< PPS output 32768Hz frequency */
  1067. /* dma_bctl register value */
  1068. #define DMA_BCTL_DPSL(regval) (BITS(2,6) & ((uint32_t)(regval) << 2)) /*!< write value to ENET_DMA_BCTL_DPSL bit field */
  1069. #define GET_DMA_BCTL_DPSL(regval) GET_BITS((regval),2,6) /*!< get value of ENET_DMA_BCTL_DPSL bit field */
  1070. #define ENET_ENHANCED_DESCRIPTOR ENET_DMA_BCTL_DFM /*!< enhanced mode descriptor */
  1071. #define ENET_NORMAL_DESCRIPTOR ((uint32_t)0x00000000) /*!< normal mode descriptor */
  1072. #define DMA_BCTL_PGBL(regval) (BITS(8,13) & ((uint32_t)(regval) << 8)) /*!< write value to ENET_DMA_BCTL_PGBL bit field */
  1073. #define ENET_PGBL_1BEAT DMA_BCTL_PGBL(1) /*!< maximum number of beats is 1 */
  1074. #define ENET_PGBL_2BEAT DMA_BCTL_PGBL(2) /*!< maximum number of beats is 2 */
  1075. #define ENET_PGBL_4BEAT DMA_BCTL_PGBL(4) /*!< maximum number of beats is 4 */
  1076. #define ENET_PGBL_8BEAT DMA_BCTL_PGBL(8) /*!< maximum number of beats is 8 */
  1077. #define ENET_PGBL_16BEAT DMA_BCTL_PGBL(16) /*!< maximum number of beats is 16 */
  1078. #define ENET_PGBL_32BEAT DMA_BCTL_PGBL(32) /*!< maximum number of beats is 32 */
  1079. #define ENET_PGBL_4xPGBL_4BEAT (DMA_BCTL_PGBL(1)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 4 */
  1080. #define ENET_PGBL_4xPGBL_8BEAT (DMA_BCTL_PGBL(2)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 8 */
  1081. #define ENET_PGBL_4xPGBL_16BEAT (DMA_BCTL_PGBL(4)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 16 */
  1082. #define ENET_PGBL_4xPGBL_32BEAT (DMA_BCTL_PGBL(8)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 32 */
  1083. #define ENET_PGBL_4xPGBL_64BEAT (DMA_BCTL_PGBL(16)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 64 */
  1084. #define ENET_PGBL_4xPGBL_128BEAT (DMA_BCTL_PGBL(32)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 128 */
  1085. #define DMA_BCTL_RTPR(regval) (BITS(14,15) & ((uint32_t)(regval) << 14)) /*!< write value to ENET_DMA_BCTL_RTPR bit field */
  1086. #define ENET_ARBITRATION_RXTX_1_1 DMA_BCTL_RTPR(0) /*!< receive and transmit priority ratio is 1:1*/
  1087. #define ENET_ARBITRATION_RXTX_2_1 DMA_BCTL_RTPR(1) /*!< receive and transmit priority ratio is 2:1*/
  1088. #define ENET_ARBITRATION_RXTX_3_1 DMA_BCTL_RTPR(2) /*!< receive and transmit priority ratio is 3:1 */
  1089. #define ENET_ARBITRATION_RXTX_4_1 DMA_BCTL_RTPR(3) /*!< receive and transmit priority ratio is 4:1 */
  1090. #define ENET_ARBITRATION_RXPRIORTX ENET_DMA_BCTL_DAB /*!< RxDMA has higher priority than TxDMA */
  1091. #define ENET_FIXED_BURST_ENABLE ENET_DMA_BCTL_FB /*!< AHB can only use SINGLE/INCR4/INCR8/INCR16 during start of normal burst transfers */
  1092. #define ENET_FIXED_BURST_DISABLE ((uint32_t)0x00000000) /*!< AHB can use SINGLE/INCR burst transfer operations */
  1093. #define DMA_BCTL_RXDP(regval) (BITS(17,22) & ((uint32_t)(regval) << 17)) /*!< write value to ENET_DMA_BCTL_RXDP bit field */
  1094. #define ENET_RXDP_1BEAT DMA_BCTL_RXDP(1) /*!< maximum number of beats 1 */
  1095. #define ENET_RXDP_2BEAT DMA_BCTL_RXDP(2) /*!< maximum number of beats 2 */
  1096. #define ENET_RXDP_4BEAT DMA_BCTL_RXDP(4) /*!< maximum number of beats 4 */
  1097. #define ENET_RXDP_8BEAT DMA_BCTL_RXDP(8) /*!< maximum number of beats 8 */
  1098. #define ENET_RXDP_16BEAT DMA_BCTL_RXDP(16) /*!< maximum number of beats 16 */
  1099. #define ENET_RXDP_32BEAT DMA_BCTL_RXDP(32) /*!< maximum number of beats 32 */
  1100. #define ENET_RXDP_4xPGBL_4BEAT (DMA_BCTL_RXDP(1)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 4 */
  1101. #define ENET_RXDP_4xPGBL_8BEAT (DMA_BCTL_RXDP(2)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 8 */
  1102. #define ENET_RXDP_4xPGBL_16BEAT (DMA_BCTL_RXDP(4)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 16 */
  1103. #define ENET_RXDP_4xPGBL_32BEAT (DMA_BCTL_RXDP(8)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 32 */
  1104. #define ENET_RXDP_4xPGBL_64BEAT (DMA_BCTL_RXDP(16)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 64 */
  1105. #define ENET_RXDP_4xPGBL_128BEAT (DMA_BCTL_RXDP(32)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 128 */
  1106. #define ENET_RXTX_DIFFERENT_PGBL ENET_DMA_BCTL_UIP /*!< RxDMA uses the RXDP[5:0], while TxDMA uses the PGBL[5:0] */
  1107. #define ENET_RXTX_SAME_PGBL ((uint32_t)0x00000000) /*!< RxDMA/TxDMA uses PGBL[5:0] */
  1108. #define ENET_ADDRESS_ALIGN_ENABLE ENET_DMA_BCTL_AA /*!< enabled address-aligned */
  1109. #define ENET_ADDRESS_ALIGN_DISABLE ((uint32_t)0x00000000) /*!< disable address-aligned */
  1110. #define ENET_MIXED_BURST_ENABLE ENET_DMA_BCTL_MB /*!< AHB master interface transfer burst length greater than 16 with INCR */
  1111. #define ENET_MIXED_BURST_DISABLE ((uint32_t)0x00000000) /*!< AHB master interface only transfer fixed burst length with 16 and below */
  1112. /* dma_stat register value */
  1113. #define GET_DMA_STAT_RP(regval) GET_BITS((uint32_t)(regval),17,19) /*!< get value of ENET_DMA_STAT_RP bit field */
  1114. #define ENET_RX_STATE_STOPPED ((uint32_t)0x00000000) /*!< reset or stop rx command issued */
  1115. #define ENET_RX_STATE_FETCHING BIT(17) /*!< fetching the Rx descriptor */
  1116. #define ENET_RX_STATE_WAITING (BIT(17)|BIT(18)) /*!< waiting for receive packet */
  1117. #define ENET_RX_STATE_SUSPENDED BIT(19) /*!< Rx descriptor unavailable */
  1118. #define ENET_RX_STATE_CLOSING (BIT(17)|BIT(19)) /*!< closing receive descriptor */
  1119. #define ENET_RX_STATE_QUEUING ENET_DMA_STAT_RP /*!< transferring the receive packet data from recevie buffer to host memory */
  1120. #define GET_DMA_STAT_TP(regval) GET_BITS((uint32_t)(regval),20,22) /*!< get value of ENET_DMA_STAT_TP bit field */
  1121. #define ENET_TX_STATE_STOPPED ((uint32_t)0x00000000) /*!< reset or stop Tx Command issued */
  1122. #define ENET_TX_STATE_FETCHING BIT(20) /*!< fetching the Tx descriptor */
  1123. #define ENET_TX_STATE_WAITING BIT(21) /*!< waiting for status */
  1124. #define ENET_TX_STATE_READING (BIT(20)|BIT(21)) /*!< reading the data from host memory buffer and queuing it to transmit buffer */
  1125. #define ENET_TX_STATE_SUSPENDED (BIT(21)|BIT(22)) /*!< Tx descriptor unavailabe or transmit buffer underflow */
  1126. #define ENET_TX_STATE_CLOSING ENET_DMA_STAT_TP /*!< closing Tx descriptor */
  1127. #define GET_DMA_STAT_EB(regval) GET_BITS((uint32_t)(regval),23,25) /*!< get value of ENET_DMA_STAT_EB bit field */
  1128. #define ENET_ERROR_TXDATA_TRANSFER BIT(23) /*!< error during data transfer by TxDMA or RxDMA */
  1129. #define ENET_ERROR_READ_TRANSFER BIT(24) /*!< error during write transfer or read transfer */
  1130. #define ENET_ERROR_DESC_ACCESS BIT(25) /*!< error during descriptor or buffer access */
  1131. /* dma_ctl register value */
  1132. #define DMA_CTL_RTHC(regval) (BITS(3,4) & ((uint32_t)(regval) << 3)) /*!< write value to ENET_DMA_CTL_RTHC bit field */
  1133. #define ENET_RX_THRESHOLD_64BYTES DMA_CTL_RTHC(0) /*!< threshold level is 64 Bytes */
  1134. #define ENET_RX_THRESHOLD_32BYTES DMA_CTL_RTHC(1) /*!< threshold level is 32 Bytes */
  1135. #define ENET_RX_THRESHOLD_96BYTES DMA_CTL_RTHC(2) /*!< threshold level is 96 Bytes */
  1136. #define ENET_RX_THRESHOLD_128BYTES DMA_CTL_RTHC(3) /*!< threshold level is 128 Bytes */
  1137. #define DMA_CTL_TTHC(regval) (BITS(14,16) & ((uint32_t)(regval) << 14)) /*!< write value to ENET_DMA_CTL_TTHC bit field */
  1138. #define ENET_TX_THRESHOLD_64BYTES DMA_CTL_TTHC(0) /*!< threshold level is 64 Bytes */
  1139. #define ENET_TX_THRESHOLD_128BYTES DMA_CTL_TTHC(1) /*!< threshold level is 128 Bytes */
  1140. #define ENET_TX_THRESHOLD_192BYTES DMA_CTL_TTHC(2) /*!< threshold level is 192 Bytes */
  1141. #define ENET_TX_THRESHOLD_256BYTES DMA_CTL_TTHC(3) /*!< threshold level is 256 Bytes */
  1142. #define ENET_TX_THRESHOLD_40BYTES DMA_CTL_TTHC(4) /*!< threshold level is 40 Bytes */
  1143. #define ENET_TX_THRESHOLD_32BYTES DMA_CTL_TTHC(5) /*!< threshold level is 32 Bytes */
  1144. #define ENET_TX_THRESHOLD_24BYTES DMA_CTL_TTHC(6) /*!< threshold level is 24 Bytes */
  1145. #define ENET_TX_THRESHOLD_16BYTES DMA_CTL_TTHC(7) /*!< threshold level is 16 Bytes */
  1146. #define ENET_TCPIP_CKSUMERROR_ACCEPT ENET_DMA_CTL_DTCERFD /*!< Rx frame with only payload error but no other errors will not be dropped */
  1147. #define ENET_TCPIP_CKSUMERROR_DROP ((uint32_t)0x00000000) /*!< all error frames will be dropped when FERF = 0 */
  1148. #define ENET_RX_MODE_STOREFORWARD ENET_DMA_CTL_RSFD /*!< RxFIFO operates in store-and-forward mode */
  1149. #define ENET_RX_MODE_CUTTHROUGH ((uint32_t)0x00000000) /*!< RxFIFO operates in cut-through mode */
  1150. #define ENET_FLUSH_RXFRAME_ENABLE ((uint32_t)0x00000000) /*!< RxDMA flushes all frames */
  1151. #define ENET_FLUSH_RXFRAME_DISABLE ENET_DMA_CTL_DAFRF /*!< RxDMA does not flush any frames */
  1152. #define ENET_NO_FLUSH_RXFRAME ENET_DMA_CTL_DAFRF /*!< RxDMA does not flush frames function */
  1153. #define ENET_TX_MODE_STOREFORWARD ENET_DMA_CTL_TSFD /*!< TxFIFO operates in store-and-forward mode */
  1154. #define ENET_TX_MODE_CUTTHROUGH ((uint32_t)0x00000000) /*!< TxFIFO operates in cut-through mode */
  1155. #define ENET_FORWARD_ERRFRAMES_ENABLE (ENET_DMA_CTL_FERF << 2) /*!< all frame received with error except runt error are forwarded to memory */
  1156. #define ENET_FORWARD_ERRFRAMES_DISABLE ((uint32_t)0x00000000) /*!< RxFIFO drop error frame */
  1157. #define ENET_FORWARD_ERRFRAMES (ENET_DMA_CTL_FERF << 2) /*!< the function that all frame received with error except runt error are forwarded to memory */
  1158. #define ENET_FORWARD_UNDERSZ_GOODFRAMES_ENABLE (ENET_DMA_CTL_FUF << 2) /*!< forward undersized good frames */
  1159. #define ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE ((uint32_t)0x00000000) /*!< RxFIFO drops all frames whose length is less than 64 bytes */
  1160. #define ENET_FORWARD_UNDERSZ_GOODFRAMES (ENET_DMA_CTL_FUF << 2) /*!< the function that forwarding undersized good frames */
  1161. #define ENET_SECONDFRAME_OPT_ENABLE ENET_DMA_CTL_OSF /*!< TxDMA controller operate on second frame mode enable*/
  1162. #define ENET_SECONDFRAME_OPT_DISABLE ((uint32_t)0x00000000) /*!< TxDMA controller operate on second frame mode disable */
  1163. #define ENET_SECONDFRAME_OPT ENET_DMA_CTL_OSF /*!< TxDMA controller operate on second frame function */
  1164. /* dma_mfbocnt register value */
  1165. #define GET_DMA_MFBOCNT_MSFC(regval) GET_BITS((regval),0,15) /*!< get value of ENET_DMA_MFBOCNT_MSFC bit field */
  1166. #define GET_DMA_MFBOCNT_MSFA(regval) GET_BITS((regval),17,27) /*!< get value of ENET_DMA_MFBOCNT_MSFA bit field */
  1167. /* dma_rswdc register value */
  1168. #define DMA_RSWDC_WDCFRS(regval) (BITS(0,7) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_DMA_RSWDC_WDCFRS bit field */
  1169. /* dma tx descriptor tdes0 register value */
  1170. #define TDES0_CONT(regval) (BITS(3,6) & ((uint32_t)(regval) << 3)) /*!< write value to ENET DMA TDES0 CONT bit field */
  1171. #define GET_TDES0_COCNT(regval) GET_BITS((regval),3,6) /*!< get value of ENET DMA TDES0 CONT bit field */
  1172. #define TDES0_CM(regval) (BITS(22,23) & ((uint32_t)(regval) << 22)) /*!< write value to ENET DMA TDES0 CM bit field */
  1173. #define ENET_CHECKSUM_DISABLE TDES0_CM(0) /*!< checksum insertion disabled */
  1174. #define ENET_CHECKSUM_IPV4HEADER TDES0_CM(1) /*!< only IP header checksum calculation and insertion are enabled */
  1175. #define ENET_CHECKSUM_TCPUDPICMP_SEGMENT TDES0_CM(2) /*!< TCP/UDP/ICMP checksum insertion calculated but pseudo-header */
  1176. #define ENET_CHECKSUM_TCPUDPICMP_FULL TDES0_CM(3) /*!< TCP/UDP/ICMP checksum insertion fully calculated */
  1177. /* dma tx descriptor tdes1 register value */
  1178. #define TDES1_TB1S(regval) (BITS(0,12) & ((uint32_t)(regval) << 0)) /*!< write value to ENET DMA TDES1 TB1S bit field */
  1179. #define TDES1_TB2S(regval) (BITS(16,28) & ((uint32_t)(regval) << 16)) /*!< write value to ENET DMA TDES1 TB2S bit field */
  1180. /* dma rx descriptor rdes0 register value */
  1181. #define RDES0_FRML(regval) (BITS(16,29) & ((uint32_t)(regval) << 16)) /*!< write value to ENET DMA RDES0 FRML bit field */
  1182. #define GET_RDES0_FRML(regval) GET_BITS((regval),16,29) /*!< get value of ENET DMA RDES0 FRML bit field */
  1183. /* dma rx descriptor rdes1 register value */
  1184. #define ENET_RECEIVE_COMPLETE_INT_ENABLE ((uint32_t)0x00000000U) /*!< RS bit immediately set after Rx completed */
  1185. #define ENET_RECEIVE_COMPLETE_INT_DISABLE ENET_RDES1_DINTC /*!< RS bit not immediately set after Rx completed */
  1186. #define GET_RDES1_RB1S(regval) GET_BITS((regval),0,12) /*!< get value of ENET DMA RDES1 RB1S bit field */
  1187. #define GET_RDES1_RB2S(regval) GET_BITS((regval),16,28) /*!< get value of ENET DMA RDES1 RB2S bit field */
  1188. /* dma rx descriptor rdes4 register value */
  1189. #define RDES4_IPPLDT(regval) (BITS(0,2) & ((uint32_t)(regval) << 0)) /*!< write value to ENET DMA RDES4 IPPLDT bit field */
  1190. #define GET_RDES4_IPPLDT(regval) GET_BITS((regval),0,2) /*!< get value of ENET DMA RDES4 IPPLDT bit field */
  1191. #define RDES4_PTPMT(regval) (BITS(8,11) & ((uint32_t)(regval) << 8)) /*!< write value to ENET DMA RDES4 PTPMT bit field */
  1192. #define GET_RDES4_PTPMT(regval) GET_BITS((regval),8,11) /*!< get value of ENET DMA RDES4 PTPMT bit field */
  1193. /* ENET register mask value */
  1194. #define MAC_CFG_MASK ((uint32_t)0xFD30810FU) /*!< ENET_MAC_CFG register mask */
  1195. #define MAC_FCTL_MASK ((uint32_t)0x0000FF41U) /*!< ENET_MAC_FCTL register mask */
  1196. #define DMA_CTL_MASK ((uint32_t)0xF8DE3F23U) /*!< ENET_DMA_CTL register mask */
  1197. #define DMA_BCTL_MASK ((uint32_t)0xF800007DU) /*!< ENET_DMA_BCTL register mask */
  1198. #define ENET_MSC_PRESET_MASK (~(ENET_MSC_CTL_PMC | ENET_MSC_CTL_AFHPM)) /*!< ENET_MSC_CTL preset mask */
  1199. #ifdef SELECT_DESCRIPTORS_ENHANCED_MODE
  1200. #define ETH_DMATXDESC_SIZE 0x20U /*!< TxDMA enhanced descriptor size */
  1201. #define ETH_DMARXDESC_SIZE 0x20U /*!< RxDMA enhanced descriptor size */
  1202. #else
  1203. #define ETH_DMATXDESC_SIZE 0x10U /*!< TxDMA descriptor size */
  1204. #define ETH_DMARXDESC_SIZE 0x10U /*!< RxDMA descriptor size */
  1205. #endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
  1206. typedef enum{
  1207. ENET_CKNT_ORDINARY = PTP_TSCTL_CKNT(0), /*!< type of ordinary clock node type for timestamp */
  1208. ENET_CKNT_BOUNDARY = PTP_TSCTL_CKNT(1), /*!< type of boundary clock node type for timestamp */
  1209. ENET_CKNT_END_TO_END = PTP_TSCTL_CKNT(2), /*!< type of end-to-end transparent clock node type for timestamp */
  1210. ENET_CKNT_PEER_TO_PEER = PTP_TSCTL_CKNT(3), /*!< type of peer-to-peer transparent clock node type for timestamp */
  1211. ENET_PTP_SYSTIME_INIT = ENET_PTP_TSCTL_TMSSTI, /*!< timestamp initialize */
  1212. ENET_PTP_SYSTIME_UPDATE = ENET_PTP_TSCTL_TMSSTU, /*!< timestamp update */
  1213. ENET_PTP_ADDEND_UPDATE = ENET_PTP_TSCTL_TMSARU, /*!< addend register update */
  1214. ENET_PTP_FINEMODE = (int32_t)(ENET_PTP_TSCTL_TMSFCU| BIT(31)), /*!< the system timestamp uses the fine method for updating */
  1215. ENET_PTP_COARSEMODE = ENET_PTP_TSCTL_TMSFCU, /*!< the system timestamp uses the coarse method for updating */
  1216. ENET_SUBSECOND_DIGITAL_ROLLOVER = (int32_t)(ENET_PTP_TSCTL_SCROM | BIT(31)), /*!< digital rollover mode */
  1217. ENET_SUBSECOND_BINARY_ROLLOVER = ENET_PTP_TSCTL_SCROM, /*!< binary rollover mode */
  1218. ENET_SNOOPING_PTP_VERSION_2 = (int32_t)(ENET_PTP_TSCTL_PFSV| BIT(31)), /*!< version 2 */
  1219. ENET_SNOOPING_PTP_VERSION_1 = ENET_PTP_TSCTL_PFSV, /*!< version 1 */
  1220. ENET_EVENT_TYPE_MESSAGES_SNAPSHOT = (int32_t)(ENET_PTP_TSCTL_ETMSEN| BIT(31)), /*!< only event type messages are taken snapshot */
  1221. ENET_ALL_TYPE_MESSAGES_SNAPSHOT = ENET_PTP_TSCTL_ETMSEN, /*!< all type messages are taken snapshot except announce, management and signaling message */
  1222. ENET_MASTER_NODE_MESSAGE_SNAPSHOT = (int32_t)(ENET_PTP_TSCTL_MNMSEN| BIT(31)), /*!< snapshot is only take for master node message */
  1223. ENET_SLAVE_NODE_MESSAGE_SNAPSHOT = ENET_PTP_TSCTL_MNMSEN, /*!< snapshot is only taken for slave node message */
  1224. }enet_ptp_function_enum;
  1225. /* ENET remote wake-up frame register length */
  1226. #define ETH_WAKEUP_REGISTER_LENGTH 8U /*!< remote wake-up frame register length */
  1227. /* ENET frame size */
  1228. #define ENET_MAX_FRAME_SIZE 1524U /*!< header + frame_extra + payload + CRC */
  1229. /* ENET delay timeout */
  1230. #define ENET_DELAY_TO ((uint32_t)0x0004FFFFU) /*!< ENET delay timeout */
  1231. #define ENET_RESET_TO ((uint32_t)0x000004FFU) /*!< ENET reset timeout */
  1232. /* function declarations */
  1233. /* main function */
  1234. /* deinitialize the ENET, and reset structure parameters for ENET initialization */
  1235. void enet_deinit(void);
  1236. /* configure the parameters which are usually less cared for initialization */
  1237. void enet_initpara_config(enet_option_enum option, uint32_t para);
  1238. /* initialize ENET peripheral with generally concerned parameters and the less cared parameters */
  1239. ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum, enet_frmrecept_enum recept);
  1240. /* reset all core internal registers located in CLK_TX and CLK_RX */
  1241. ErrStatus enet_software_reset(void);
  1242. /* check receive frame valid and return frame size */
  1243. uint32_t enet_rxframe_size_get(void);
  1244. /* initialize the dma tx/rx descriptors's parameters in chain mode */
  1245. void enet_descriptors_chain_init(enet_dmadirection_enum direction);
  1246. /* initialize the dma tx/rx descriptors's parameters in ring mode */
  1247. void enet_descriptors_ring_init(enet_dmadirection_enum direction);
  1248. /* handle current received frame data to application buffer */
  1249. ErrStatus enet_frame_receive(uint8_t *buffer, uint32_t bufsize);
  1250. /* handle current received frame but without data copy to application buffer */
  1251. #define ENET_NOCOPY_FRAME_RECEIVE() enet_frame_receive(NULL, 0U)
  1252. /* handle application buffer data to transmit it */
  1253. ErrStatus enet_frame_transmit(uint8_t *buffer, uint32_t length);
  1254. /* handle current transmit frame but without data copy from application buffer */
  1255. #define ENET_NOCOPY_FRAME_TRANSMIT(len) enet_frame_transmit(NULL, (len))
  1256. /* configure the transmit IP frame checksum offload calculation and insertion */
  1257. ErrStatus enet_transmit_checksum_config(enet_descriptors_struct *desc, uint32_t checksum);
  1258. /* ENET Tx and Rx function enable (include MAC and DMA module) */
  1259. void enet_enable(void);
  1260. /* ENET Tx and Rx function disable (include MAC and DMA module) */
  1261. void enet_disable(void);
  1262. /* configure MAC address */
  1263. void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t paddr[]);
  1264. /* get MAC address */
  1265. ErrStatus enet_mac_address_get(enet_macaddress_enum mac_addr, uint8_t paddr[], uint8_t bufsize);
  1266. /* get the ENET MAC/MSC/PTP/DMA status flag */
  1267. FlagStatus enet_flag_get(enet_flag_enum enet_flag);
  1268. /* clear the ENET DMA status flag */
  1269. void enet_flag_clear(enet_flag_clear_enum enet_flag);
  1270. /* enable ENET MAC/MSC/DMA interrupt */
  1271. void enet_interrupt_enable(enet_int_enum enet_int);
  1272. /* disable ENET MAC/MSC/DMA interrupt */
  1273. void enet_interrupt_disable(enet_int_enum enet_int);
  1274. /* get ENET MAC/MSC/DMA interrupt flag */
  1275. FlagStatus enet_interrupt_flag_get(enet_int_flag_enum int_flag);
  1276. /* clear ENET DMA interrupt flag */
  1277. void enet_interrupt_flag_clear(enet_int_flag_clear_enum int_flag_clear);
  1278. /* MAC function */
  1279. /* ENET Tx function enable (include MAC and DMA module) */
  1280. void enet_tx_enable(void);
  1281. /* ENET Tx function disable (include MAC and DMA module) */
  1282. void enet_tx_disable(void);
  1283. /* ENET Rx function enable (include MAC and DMA module) */
  1284. void enet_rx_enable(void);
  1285. /* ENET Rx function disable (include MAC and DMA module) */
  1286. void enet_rx_disable(void);
  1287. /* put registers value into the application buffer */
  1288. void enet_registers_get(enet_registers_type_enum type, uint32_t *preg, uint32_t num);
  1289. /* get the enet debug status from the debug register */
  1290. uint32_t enet_debug_status_get(uint32_t mac_debug);
  1291. /* enable the MAC address filter */
  1292. void enet_address_filter_enable(enet_macaddress_enum mac_addr);
  1293. /* disable the MAC address filter */
  1294. void enet_address_filter_disable(enet_macaddress_enum mac_addr);
  1295. /* configure the MAC address filter */
  1296. void enet_address_filter_config(enet_macaddress_enum mac_addr, uint32_t addr_mask, uint32_t filter_type);
  1297. /* PHY interface configuration (configure SMI clock and reset PHY chip) */
  1298. ErrStatus enet_phy_config(void);
  1299. /* write to/read from a PHY register */
  1300. ErrStatus enet_phy_write_read(enet_phydirection_enum direction, uint16_t phy_address, uint16_t phy_reg, uint16_t *pvalue);
  1301. /* enable the loopback function of phy chip */
  1302. ErrStatus enet_phyloopback_enable(void);
  1303. /* disable the loopback function of phy chip */
  1304. ErrStatus enet_phyloopback_disable(void);
  1305. /* enable ENET forward feature */
  1306. void enet_forward_feature_enable(uint32_t feature);
  1307. /* disable ENET forward feature */
  1308. void enet_forward_feature_disable(uint32_t feature);
  1309. /* enable ENET fliter feature */
  1310. void enet_fliter_feature_enable(uint32_t feature);
  1311. /* disable ENET fliter feature */
  1312. void enet_fliter_feature_disable(uint32_t feature);
  1313. /* flow control function */
  1314. /* generate the pause frame, ENET will send pause frame after enable transmit flow control */
  1315. ErrStatus enet_pauseframe_generate(void);
  1316. /* configure the pause frame detect type */
  1317. void enet_pauseframe_detect_config(uint32_t detect);
  1318. /* configure the pause frame parameters */
  1319. void enet_pauseframe_config(uint32_t pausetime, uint32_t pause_threshold);
  1320. /* configure the threshold of the flow control(deactive and active threshold) */
  1321. void enet_flowcontrol_threshold_config(uint32_t deactive, uint32_t active);
  1322. /* enable ENET flow control feature */
  1323. void enet_flowcontrol_feature_enable(uint32_t feature);
  1324. /* disable ENET flow control feature */
  1325. void enet_flowcontrol_feature_disable(uint32_t feature);
  1326. /* DMA function */
  1327. /* get the dma transmit/receive process state */
  1328. uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction);
  1329. /* poll the dma transmission/reception enable */
  1330. void enet_dmaprocess_resume(enet_dmadirection_enum direction);
  1331. /* check and recover the Rx process */
  1332. void enet_rxprocess_check_recovery(void);
  1333. /* flush the ENET transmit fifo, and wait until the flush operation completes */
  1334. ErrStatus enet_txfifo_flush(void);
  1335. /* get the transmit/receive address of current descriptor, or current buffer, or descriptor table */
  1336. uint32_t enet_current_desc_address_get(enet_desc_reg_enum addr_get);
  1337. /* get the Tx or Rx descriptor information */
  1338. uint32_t enet_desc_information_get(enet_descriptors_struct *desc, enet_descstate_enum info_get);
  1339. /* get the number of missed frames during receiving */
  1340. void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop);
  1341. /* descriptor function */
  1342. /* get the bit flag of ENET dma descriptor */
  1343. FlagStatus enet_desc_flag_get(enet_descriptors_struct *desc, uint32_t desc_flag);
  1344. /* set the bit flag of ENET dma tx descriptor */
  1345. void enet_desc_flag_set(enet_descriptors_struct *desc, uint32_t desc_flag);
  1346. /* clear the bit flag of ENET dma tx descriptor */
  1347. void enet_desc_flag_clear(enet_descriptors_struct *desc, uint32_t desc_flag);
  1348. /* when receiving the completed, set RS bit in ENET_DMA_STAT register will immediately set */
  1349. void enet_rx_desc_immediate_receive_complete_interrupt(enet_descriptors_struct *desc);
  1350. /* when receiving the completed, set RS bit in ENET_DMA_STAT register will is set after a configurable delay time */
  1351. void enet_rx_desc_delay_receive_complete_interrupt(enet_descriptors_struct *desc, uint32_t delay_time);
  1352. /* drop current receive frame */
  1353. void enet_rxframe_drop(void);
  1354. /* enable DMA feature */
  1355. void enet_dma_feature_enable(uint32_t feature);
  1356. /* disable DMA feature */
  1357. void enet_dma_feature_disable(uint32_t feature);
  1358. /* special enhanced mode function */
  1359. #ifdef SELECT_DESCRIPTORS_ENHANCED_MODE
  1360. /* get the bit of extended status flag in ENET DMA descriptor */
  1361. uint32_t enet_rx_desc_enhanced_status_get(enet_descriptors_struct *desc, uint32_t desc_status);
  1362. /* configure descriptor to work in enhanced mode */
  1363. void enet_desc_select_enhanced_mode(void);
  1364. /* initialize the dma Tx/Rx descriptors's parameters in enhanced chain mode with ptp function */
  1365. void enet_ptp_enhanced_descriptors_chain_init(enet_dmadirection_enum direction);
  1366. /* initialize the dma Tx/Rx descriptors's parameters in enhanced ring mode with ptp function */
  1367. void enet_ptp_enhanced_descriptors_ring_init(enet_dmadirection_enum direction);
  1368. /* receive a packet data with timestamp values to application buffer, when the DMA is in enhanced mode */
  1369. ErrStatus enet_ptpframe_receive_enhanced_mode(uint8_t *buffer, uint32_t bufsize, uint32_t timestamp[]);
  1370. /* handle current received frame but without data copy to application buffer in PTP enhanced mode */
  1371. #define ENET_NOCOPY_PTPFRAME_RECEIVE_ENHANCED_MODE(ptr) enet_ptpframe_receive_enhanced_mode(NULL, 0U, (ptr))
  1372. /* send data with timestamp values in application buffer as a transmit packet, when the DMA is in enhanced mode */
  1373. ErrStatus enet_ptpframe_transmit_enhanced_mode(uint8_t *buffer, uint32_t length, uint32_t timestamp[]);
  1374. /* handle current transmit frame but without data copy from application buffer in PTP enhanced mode */
  1375. #define ENET_NOCOPY_PTPFRAME_TRANSMIT_ENHANCED_MODE(len, ptr) enet_ptpframe_transmit_enhanced_mode(NULL, (len), (ptr))
  1376. #else
  1377. /* configure descriptor to work in normal mode */
  1378. void enet_desc_select_normal_mode(void);
  1379. /* initialize the dma Tx/Rx descriptors's parameters in normal chain mode with ptp function */
  1380. void enet_ptp_normal_descriptors_chain_init(enet_dmadirection_enum direction, enet_descriptors_struct *desc_ptptab);
  1381. /* initialize the dma Tx/Rx descriptors's parameters in normal ring mode with ptp function */
  1382. void enet_ptp_normal_descriptors_ring_init(enet_dmadirection_enum direction, enet_descriptors_struct *desc_ptptab);
  1383. /* receive a packet data with timestamp values to application buffer, when the DMA is in normal mode */
  1384. ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, uint32_t timestamp[]);
  1385. /* handle current received frame but without data copy to application buffer in PTP normal mode */
  1386. #define ENET_NOCOPY_PTPFRAME_RECEIVE_NORMAL_MODE(ptr) enet_ptpframe_receive_normal_mode(NULL, 0U, (ptr))
  1387. /* send data with timestamp values in application buffer as a transmit packet, when the DMA is in normal mode */
  1388. ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, uint32_t timestamp[]);
  1389. /* handle current transmit frame but without data copy from application buffer in PTP normal mode */
  1390. #define ENET_NOCOPY_PTPFRAME_TRANSMIT_NORMAL_MODE(len, ptr) enet_ptpframe_transmit_normal_mode(NULL, (len), (ptr))
  1391. #endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
  1392. /* WUM function */
  1393. /* wakeup frame filter register pointer reset */
  1394. void enet_wum_filter_register_pointer_reset(void);
  1395. /* set the remote wakeup frame registers */
  1396. void enet_wum_filter_config(uint32_t pdata[]);
  1397. /* enable wakeup management features */
  1398. void enet_wum_feature_enable(uint32_t feature);
  1399. /* disable wakeup management features */
  1400. void enet_wum_feature_disable(uint32_t feature);
  1401. /* MSC function */
  1402. /* reset the MAC statistics counters */
  1403. void enet_msc_counters_reset(void);
  1404. /* enable the MAC statistics counter features */
  1405. void enet_msc_feature_enable(uint32_t feature);
  1406. /* disable the MAC statistics counter features */
  1407. void enet_msc_feature_disable(uint32_t feature);
  1408. /* configure MAC statistics counters preset mode */
  1409. void enet_msc_counters_preset_config(enet_msc_preset_enum mode);
  1410. /* get MAC statistics counter */
  1411. uint32_t enet_msc_counters_get(enet_msc_counter_enum counter);
  1412. /* PTP function */
  1413. /* change subsecond to nanosecond */
  1414. uint32_t enet_ptp_subsecond_2_nanosecond(uint32_t subsecond);
  1415. /* change nanosecond to subsecond */
  1416. uint32_t enet_ptp_nanosecond_2_subsecond(uint32_t nanosecond);
  1417. /* enable the PTP features */
  1418. void enet_ptp_feature_enable(uint32_t feature);
  1419. /* disable the PTP features */
  1420. void enet_ptp_feature_disable(uint32_t feature);
  1421. /* configure the PTP timestamp function */
  1422. ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum func);
  1423. /* configure the PTP system time subsecond increment value */
  1424. void enet_ptp_subsecond_increment_config(uint32_t subsecond);
  1425. /* adjusting the PTP clock frequency only in fine update mode */
  1426. void enet_ptp_timestamp_addend_config(uint32_t add);
  1427. /* initializing or adding/subtracting to second of the PTP system time */
  1428. void enet_ptp_timestamp_update_config(uint32_t sign, uint32_t second, uint32_t subsecond);
  1429. /* configure the PTP expected target time */
  1430. void enet_ptp_expected_time_config(uint32_t second, uint32_t nanosecond);
  1431. /* get the PTP current system time */
  1432. void enet_ptp_system_time_get(enet_ptp_systime_struct *systime_struct);
  1433. /* configure the PPS output frequency */
  1434. void enet_ptp_pps_output_frequency_config(uint32_t freq);
  1435. /* configure and start PTP timestamp counter */
  1436. void enet_ptp_start(int32_t updatemethod, uint32_t init_sec, uint32_t init_subsec, uint32_t carry_cfg, uint32_t accuracy_cfg);
  1437. /* adjust frequency in fine method by configure addend register */
  1438. void enet_ptp_finecorrection_adjfreq(int32_t carry_cfg);
  1439. /* update system time in coarse method */
  1440. void enet_ptp_coarsecorrection_systime_update(enet_ptp_systime_struct *systime_struct);
  1441. /* set system time in fine method */
  1442. void enet_ptp_finecorrection_settime(enet_ptp_systime_struct * systime_struct);
  1443. /* get the ptp flag status */
  1444. FlagStatus enet_ptp_flag_get(uint32_t flag);
  1445. /* internal function */
  1446. /* reset the ENET initpara struct, call it before using enet_initpara_config() */
  1447. void enet_initpara_reset(void);
  1448. #ifdef USE_DELAY
  1449. /* user can provide more timing precise _ENET_DELAY_ function */
  1450. #define _ENET_DELAY_ delay_ms
  1451. #else
  1452. /* default _ENET_DELAY_ function with less precise timing */
  1453. #define _ENET_DELAY_ enet_delay
  1454. #endif
  1455. #endif /* GD32F30X_ENET_H */