gd32f10x_enet.h 122 KB

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