fsl_enet.h 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  1. /*
  2. * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_ENET_H_
  9. #define _FSL_ENET_H_
  10. #include "fsl_common.h"
  11. #if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
  12. #include "fsl_memory.h"
  13. #endif
  14. /*!
  15. * @addtogroup enet
  16. * @{
  17. */
  18. /*******************************************************************************
  19. * Definitions
  20. ******************************************************************************/
  21. /*! @name Driver version */
  22. /*@{*/
  23. /*! @brief Defines the driver version. */
  24. #define FSL_ENET_DRIVER_VERSION (MAKE_VERSION(2, 2, 3)) /*!< Version 2.2.3. */
  25. /*@}*/
  26. /*! @name ENET DESCRIPTOR QUEUE */
  27. /*@{*/
  28. /*! @brief Defines the queue number. */
  29. #ifndef FSL_FEATURE_ENET_QUEUE
  30. #define FSL_FEATURE_ENET_QUEUE 1 /* Singal queue for previous IP. */
  31. #endif
  32. /*@}*/
  33. /*! @name Control and status region bit masks of the receive buffer descriptor. */
  34. /*@{*/
  35. #define ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK 0x8000U /*!< Empty bit mask. */
  36. #define ENET_BUFFDESCRIPTOR_RX_SOFTOWNER1_MASK 0x4000U /*!< Software owner one mask. */
  37. #define ENET_BUFFDESCRIPTOR_RX_WRAP_MASK 0x2000U /*!< Next buffer descriptor is the start address. */
  38. #define ENET_BUFFDESCRIPTOR_RX_SOFTOWNER2_Mask 0x1000U /*!< Software owner two mask. */
  39. #define ENET_BUFFDESCRIPTOR_RX_LAST_MASK 0x0800U /*!< Last BD of the frame mask. */
  40. #define ENET_BUFFDESCRIPTOR_RX_MISS_MASK 0x0100U /*!< Received because of the promiscuous mode. */
  41. #define ENET_BUFFDESCRIPTOR_RX_BROADCAST_MASK 0x0080U /*!< Broadcast packet mask. */
  42. #define ENET_BUFFDESCRIPTOR_RX_MULTICAST_MASK 0x0040U /*!< Multicast packet mask. */
  43. #define ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK 0x0020U /*!< Length violation mask. */
  44. #define ENET_BUFFDESCRIPTOR_RX_NOOCTET_MASK 0x0010U /*!< Non-octet aligned frame mask. */
  45. #define ENET_BUFFDESCRIPTOR_RX_CRC_MASK 0x0004U /*!< CRC error mask. */
  46. #define ENET_BUFFDESCRIPTOR_RX_OVERRUN_MASK 0x0002U /*!< FIFO overrun mask. */
  47. #define ENET_BUFFDESCRIPTOR_RX_TRUNC_MASK 0x0001U /*!< Frame is truncated mask. */
  48. /*@}*/
  49. /*! @name Control and status bit masks of the transmit buffer descriptor. */
  50. /*@{*/
  51. #define ENET_BUFFDESCRIPTOR_TX_READY_MASK 0x8000U /*!< Ready bit mask. */
  52. #define ENET_BUFFDESCRIPTOR_TX_SOFTOWENER1_MASK 0x4000U /*!< Software owner one mask. */
  53. #define ENET_BUFFDESCRIPTOR_TX_WRAP_MASK 0x2000U /*!< Wrap buffer descriptor mask. */
  54. #define ENET_BUFFDESCRIPTOR_TX_SOFTOWENER2_MASK 0x1000U /*!< Software owner two mask. */
  55. #define ENET_BUFFDESCRIPTOR_TX_LAST_MASK 0x0800U /*!< Last BD of the frame mask. */
  56. #define ENET_BUFFDESCRIPTOR_TX_TRANMITCRC_MASK 0x0400U /*!< Transmit CRC mask. */
  57. /*@}*/
  58. /* Extended control regions for enhanced buffer descriptors. */
  59. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  60. /*! @name First extended control region bit masks of the receive buffer descriptor. */
  61. /*@{*/
  62. #define ENET_BUFFDESCRIPTOR_RX_IPV4_MASK 0x0001U /*!< Ipv4 frame mask. */
  63. #define ENET_BUFFDESCRIPTOR_RX_IPV6_MASK 0x0002U /*!< Ipv6 frame mask. */
  64. #define ENET_BUFFDESCRIPTOR_RX_VLAN_MASK 0x0004U /*!< VLAN frame mask. */
  65. #define ENET_BUFFDESCRIPTOR_RX_PROTOCOLCHECKSUM_MASK 0x0010U /*!< Protocol checksum error mask. */
  66. #define ENET_BUFFDESCRIPTOR_RX_IPHEADCHECKSUM_MASK 0x0020U /*!< IP header checksum error mask. */
  67. /*@}*/
  68. /*! @name Second extended control region bit masks of the receive buffer descriptor. */
  69. /*@{*/
  70. #define ENET_BUFFDESCRIPTOR_RX_INTERRUPT_MASK 0x0080U /*!< BD interrupt mask. */
  71. #define ENET_BUFFDESCRIPTOR_RX_UNICAST_MASK 0x0100U /*!< Unicast frame mask. */
  72. #define ENET_BUFFDESCRIPTOR_RX_COLLISION_MASK 0x0200U /*!< BD collision mask. */
  73. #define ENET_BUFFDESCRIPTOR_RX_PHYERR_MASK 0x0400U /*!< PHY error mask. */
  74. #define ENET_BUFFDESCRIPTOR_RX_MACERR_MASK 0x8000U /*!< Mac error mask. */
  75. /*@}*/
  76. /*! @name First extended control region bit masks of the transmit buffer descriptor. */
  77. /*@{*/
  78. #define ENET_BUFFDESCRIPTOR_TX_ERR_MASK 0x8000U /*!< Transmit error mask. */
  79. #define ENET_BUFFDESCRIPTOR_TX_UNDERFLOWERR_MASK 0x2000U /*!< Underflow error mask. */
  80. #define ENET_BUFFDESCRIPTOR_TX_EXCCOLLISIONERR_MASK 0x1000U /*!< Excess collision error mask. */
  81. #define ENET_BUFFDESCRIPTOR_TX_FRAMEERR_MASK 0x0800U /*!< Frame error mask. */
  82. #define ENET_BUFFDESCRIPTOR_TX_LATECOLLISIONERR_MASK 0x0400U /*!< Late collision error mask. */
  83. #define ENET_BUFFDESCRIPTOR_TX_OVERFLOWERR_MASK 0x0200U /*!< Overflow error mask. */
  84. #define ENET_BUFFDESCRIPTOR_TX_TIMESTAMPERR_MASK 0x0100U /*!< Timestamp error mask. */
  85. /*@}*/
  86. /*! @name Second extended control region bit masks of the transmit buffer descriptor. */
  87. /*@{*/
  88. #define ENET_BUFFDESCRIPTOR_TX_INTERRUPT_MASK 0x4000U /*!< Interrupt mask. */
  89. #define ENET_BUFFDESCRIPTOR_TX_TIMESTAMP_MASK 0x2000U /*!< Timestamp flag mask. */
  90. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  91. #define ENET_BUFFDESCRIPTOR_TX_USETXLAUNCHTIME_MASK 0x0100U /*!< Use the transmit launch time. */
  92. #define ENET_BUFFDESCRIPTOR_TX_FRAMETYPE_MASK 0x00F0U /*!< Frame type mask. */
  93. #define ENET_BUFFDESCRIPTOR_TX_FRAMETYPE_SHIFT 4U /*!< Frame type shift. */
  94. #define ENET_BD_FTYPE(n) ((n << ENET_BUFFDESCRIPTOR_TX_FRAMETYPE_SHIFT) & ENET_BUFFDESCRIPTOR_TX_FRAMETYPE_MASK)
  95. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  96. /*@}*/
  97. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  98. /*! @brief Defines the receive error status flag mask. */
  99. #define ENET_BUFFDESCRIPTOR_RX_ERR_MASK \
  100. (ENET_BUFFDESCRIPTOR_RX_TRUNC_MASK | ENET_BUFFDESCRIPTOR_RX_OVERRUN_MASK | \
  101. ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK | ENET_BUFFDESCRIPTOR_RX_NOOCTET_MASK | ENET_BUFFDESCRIPTOR_RX_CRC_MASK)
  102. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  103. #define ENET_BUFFDESCRIPTOR_RX_EXT_ERR_MASK \
  104. (ENET_BUFFDESCRIPTOR_RX_MACERR_MASK | ENET_BUFFDESCRIPTOR_RX_PHYERR_MASK | ENET_BUFFDESCRIPTOR_RX_COLLISION_MASK)
  105. #endif
  106. /*! @name Defines some Ethernet parameters. */
  107. /*@{*/
  108. #define ENET_FRAME_MAX_FRAMELEN 1518U /*!< Default maximum Ethernet frame size. */
  109. #define ENET_FIFO_MIN_RX_FULL 5U /*!< ENET minimum receive FIFO full. */
  110. #define ENET_RX_MIN_BUFFERSIZE 256U /*!< ENET minimum buffer size. */
  111. #define ENET_PHY_MAXADDRESS (ENET_MMFR_PA_MASK >> ENET_MMFR_PA_SHIFT)
  112. #if FSL_FEATURE_ENET_QUEUE > 1
  113. #define ENET_TX_INTERRUPT \
  114. (kENET_TxFrameInterrupt | kENET_TxBufferInterrupt | kENET_TxFrame1Interrupt | kENET_TxBuffer1Interrupt | \
  115. kENET_TxFrame2Interrupt | kENET_TxBuffer2Interrupt)
  116. #define ENET_RX_INTERRUPT \
  117. (kENET_RxFrameInterrupt | kENET_RxBufferInterrupt | kENET_RxFrame1Interrupt | kENET_RxBuffer1Interrupt | \
  118. kENET_RxFrame2Interrupt | kENET_RxBuffer2Interrupt)
  119. #else
  120. #define ENET_TX_INTERRUPT (kENET_TxFrameInterrupt | kENET_TxBufferInterrupt)
  121. #define ENET_RX_INTERRUPT (kENET_RxFrameInterrupt | kENET_RxBufferInterrupt)
  122. #endif /* FSL_FEATURE_ENET_QUEUE > 1 */
  123. #define ENET_TS_INTERRUPT (kENET_TsTimerInterrupt | kENET_TsAvailInterrupt)
  124. #define ENET_ERR_INTERRUPT \
  125. (kENET_BabrInterrupt | kENET_BabtInterrupt | kENET_EBusERInterrupt | kENET_LateCollisionInterrupt | \
  126. kENET_RetryLimitInterrupt | kENET_UnderrunInterrupt | kENET_PayloadRxInterrupt)
  127. #define ENET_ERR_INTERRUPT \
  128. (kENET_BabrInterrupt | kENET_BabtInterrupt | kENET_EBusERInterrupt | kENET_LateCollisionInterrupt | \
  129. kENET_RetryLimitInterrupt | kENET_UnderrunInterrupt | kENET_PayloadRxInterrupt)
  130. /*@}*/
  131. /*! @brief Defines the status return codes for transaction. */
  132. enum _enet_status
  133. {
  134. kStatus_ENET_RxFrameError = MAKE_STATUS(kStatusGroup_ENET, 0U), /*!< A frame received but data error happen. */
  135. kStatus_ENET_RxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 1U), /*!< Failed to receive a frame. */
  136. kStatus_ENET_RxFrameEmpty = MAKE_STATUS(kStatusGroup_ENET, 2U), /*!< No frame arrive. */
  137. kStatus_ENET_TxFrameOverLen = MAKE_STATUS(kStatusGroup_ENET, 3U), /*!< Tx frame over length. */
  138. kStatus_ENET_TxFrameBusy = MAKE_STATUS(kStatusGroup_ENET, 4U), /*!< Tx buffer descriptors are under process. */
  139. kStatus_ENET_TxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 5U) /*!< Transmit frame fail. */
  140. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  141. ,
  142. kStatus_ENET_PtpTsRingFull = MAKE_STATUS(kStatusGroup_ENET, 6U), /*!< Timestamp ring full. */
  143. kStatus_ENET_PtpTsRingEmpty = MAKE_STATUS(kStatusGroup_ENET, 7U) /*!< Timestamp ring empty. */
  144. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  145. };
  146. /*! @brief Defines the MII/RMII/RGMII mode for data interface between the MAC and the PHY. */
  147. typedef enum _enet_mii_mode
  148. {
  149. kENET_MiiMode = 0U, /*!< MII mode for data interface. */
  150. kENET_RmiiMode = 1U, /*!< RMII mode for data interface. */
  151. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  152. kENET_RgmiiMode = 2U /*!< RGMII mode for data interface. */
  153. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  154. } enet_mii_mode_t;
  155. /*! @brief Defines the 10/100/1000 Mbps speed for the MII data interface.
  156. *
  157. * Notice: "kENET_MiiSpeed1000M" only supported when mii mode is "kENET_RgmiiMode".
  158. */
  159. typedef enum _enet_mii_speed
  160. {
  161. kENET_MiiSpeed10M = 0U, /*!< Speed 10 Mbps. */
  162. kENET_MiiSpeed100M = 1U, /*!< Speed 100 Mbps. */
  163. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  164. kENET_MiiSpeed1000M = 2U /*!< Speed 1000M bps. */
  165. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  166. } enet_mii_speed_t;
  167. /*! @brief Defines the half or full duplex for the MII data interface. */
  168. typedef enum _enet_mii_duplex
  169. {
  170. kENET_MiiHalfDuplex = 0U, /*!< Half duplex mode. */
  171. kENET_MiiFullDuplex /*!< Full duplex mode. */
  172. } enet_mii_duplex_t;
  173. /*! @brief Define the MII opcode for normal MDIO_CLAUSES_22 Frame. */
  174. typedef enum _enet_mii_write
  175. {
  176. kENET_MiiWriteNoCompliant = 0U, /*!< Write frame operation, but not MII-compliant. */
  177. kENET_MiiWriteValidFrame /*!< Write frame operation for a valid MII management frame. */
  178. } enet_mii_write_t;
  179. /*! @brief Defines the read operation for the MII management frame. */
  180. typedef enum _enet_mii_read
  181. {
  182. kENET_MiiReadValidFrame = 2U, /*!< Read frame operation for a valid MII management frame. */
  183. kENET_MiiReadNoCompliant = 3U /*!< Read frame operation, but not MII-compliant. */
  184. } enet_mii_read_t;
  185. #if defined(FSL_FEATURE_ENET_HAS_EXTEND_MDIO) && FSL_FEATURE_ENET_HAS_EXTEND_MDIO
  186. /*! @brief Define the MII opcode for extended MDIO_CLAUSES_45 Frame. */
  187. typedef enum _enet_mii_extend_opcode
  188. {
  189. kENET_MiiAddrWrite_C45 = 0U, /*!< Address Write operation. */
  190. kENET_MiiWriteFrame_C45 = 1U, /*!< Write frame operation for a valid MII management frame. */
  191. kENET_MiiReadFrame_C45 = 3U /*!< Read frame operation for a valid MII management frame. */
  192. } enet_mii_extend_opcode;
  193. #endif /* FSL_FEATURE_ENET_HAS_EXTEND_MDIO */
  194. /*! @brief Defines a special configuration for ENET MAC controller.
  195. *
  196. * These control flags are provided for special user requirements.
  197. * Normally, these control flags are unused for ENET initialization.
  198. * For special requirements, set the flags to
  199. * macSpecialConfig in the enet_config_t.
  200. * The kENET_ControlStoreAndFwdDisable is used to disable the FIFO store
  201. * and forward. FIFO store and forward means that the FIFO read/send is started
  202. * when a complete frame is stored in TX/RX FIFO. If this flag is set,
  203. * configure rxFifoFullThreshold and txFifoWatermark
  204. * in the enet_config_t.
  205. */
  206. typedef enum _enet_special_control_flag
  207. {
  208. kENET_ControlFlowControlEnable = 0x0001U, /*!< Enable ENET flow control: pause frame. */
  209. kENET_ControlRxPayloadCheckEnable = 0x0002U, /*!< Enable ENET receive payload length check. */
  210. kENET_ControlRxPadRemoveEnable = 0x0004U, /*!< Padding is removed from received frames. */
  211. kENET_ControlRxBroadCastRejectEnable = 0x0008U, /*!< Enable broadcast frame reject. */
  212. kENET_ControlMacAddrInsert = 0x0010U, /*!< Enable MAC address insert. */
  213. kENET_ControlStoreAndFwdDisable = 0x0020U, /*!< Enable FIFO store and forward. */
  214. kENET_ControlSMIPreambleDisable = 0x0040U, /*!< Enable SMI preamble. */
  215. kENET_ControlPromiscuousEnable = 0x0080U, /*!< Enable promiscuous mode. */
  216. kENET_ControlMIILoopEnable = 0x0100U, /*!< Enable ENET MII loop back. */
  217. kENET_ControlVLANTagEnable = 0x0200U, /*!< Enable normal VLAN (single vlan tag). */
  218. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  219. kENET_ControlSVLANEnable = 0x0400U, /*!< Enable S-VLAN. */
  220. kENET_ControlVLANUseSecondTag = 0x0800U /*!< Enable extracting the second vlan tag for further processing. */
  221. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  222. } enet_special_control_flag_t;
  223. /*! @brief List of interrupts supported by the peripheral. This
  224. * enumeration uses one-bot encoding to allow a logical OR of multiple
  225. * members. Members usually map to interrupt enable bits in one or more
  226. * peripheral registers.
  227. */
  228. typedef enum _enet_interrupt_enable
  229. {
  230. kENET_BabrInterrupt = ENET_EIR_BABR_MASK, /*!< Babbling receive error interrupt source */
  231. kENET_BabtInterrupt = ENET_EIR_BABT_MASK, /*!< Babbling transmit error interrupt source */
  232. kENET_GraceStopInterrupt = ENET_EIR_GRA_MASK, /*!< Graceful stop complete interrupt source */
  233. kENET_TxFrameInterrupt = ENET_EIR_TXF_MASK, /*!< TX FRAME interrupt source */
  234. kENET_TxBufferInterrupt = ENET_EIR_TXB_MASK, /*!< TX BUFFER interrupt source */
  235. kENET_RxFrameInterrupt = ENET_EIR_RXF_MASK, /*!< RX FRAME interrupt source */
  236. kENET_RxBufferInterrupt = ENET_EIR_RXB_MASK, /*!< RX BUFFER interrupt source */
  237. kENET_MiiInterrupt = ENET_EIR_MII_MASK, /*!< MII interrupt source */
  238. kENET_EBusERInterrupt = ENET_EIR_EBERR_MASK, /*!< Ethernet bus error interrupt source */
  239. kENET_LateCollisionInterrupt = ENET_EIR_LC_MASK, /*!< Late collision interrupt source */
  240. kENET_RetryLimitInterrupt = ENET_EIR_RL_MASK, /*!< Collision Retry Limit interrupt source */
  241. kENET_UnderrunInterrupt = ENET_EIR_UN_MASK, /*!< Transmit FIFO underrun interrupt source */
  242. kENET_PayloadRxInterrupt = ENET_EIR_PLR_MASK, /*!< Payload Receive error interrupt source */
  243. kENET_WakeupInterrupt = ENET_EIR_WAKEUP_MASK, /*!< WAKEUP interrupt source */
  244. #if FSL_FEATURE_ENET_QUEUE > 1
  245. kENET_RxFlush2Interrupt = ENET_EIR_RXFLUSH_2_MASK, /*!< Rx DMA ring2 flush indication. */
  246. kENET_RxFlush1Interrupt = ENET_EIR_RXFLUSH_1_MASK, /*!< Rx DMA ring1 flush indication. */
  247. kENET_RxFlush0Interrupt = ENET_EIR_RXFLUSH_0_MASK, /*!< RX DMA ring0 flush indication. */
  248. kENET_TxFrame2Interrupt = ENET_EIR_TXF2_MASK, /*!< Tx frame interrupt for Tx ring/class 2. */
  249. kENET_TxBuffer2Interrupt = ENET_EIR_TXB2_MASK, /*!< Tx buffer interrupt for Tx ring/class 2. */
  250. kENET_RxFrame2Interrupt = ENET_EIR_RXF2_MASK, /*!< Rx frame interrupt for Rx ring/class 2. */
  251. kENET_RxBuffer2Interrupt = ENET_EIR_RXB2_MASK, /*!< Rx buffer interrupt for Rx ring/class 2. */
  252. kENET_TxFrame1Interrupt = ENET_EIR_TXF1_MASK, /*!< Tx frame interrupt for Tx ring/class 1. */
  253. kENET_TxBuffer1Interrupt = ENET_EIR_TXB1_MASK, /*!< Tx buffer interrupt for Tx ring/class 1. */
  254. kENET_RxFrame1Interrupt = ENET_EIR_RXF1_MASK, /*!< Rx frame interrupt for Rx ring/class 1. */
  255. kENET_RxBuffer1Interrupt = ENET_EIR_RXB1_MASK, /*!< Rx buffer interrupt for Rx ring/class 1. */
  256. #endif /* FSL_FEATURE_ENET_QUEUE > 1 */
  257. kENET_TsAvailInterrupt = ENET_EIR_TS_AVAIL_MASK, /*!< TS AVAIL interrupt source for PTP */
  258. kENET_TsTimerInterrupt = ENET_EIR_TS_TIMER_MASK /*!< TS WRAP interrupt source for PTP */
  259. } enet_interrupt_enable_t;
  260. /*! @brief Defines the common interrupt event for callback use. */
  261. typedef enum _enet_event
  262. {
  263. kENET_RxEvent, /*!< Receive event. */
  264. kENET_TxEvent, /*!< Transmit event. */
  265. kENET_ErrEvent, /*!< Error event: BABR/BABT/EBERR/LC/RL/UN/PLR . */
  266. kENET_WakeUpEvent, /*!< Wake up from sleep mode event. */
  267. kENET_TimeStampEvent, /*!< Time stamp event. */
  268. kENET_TimeStampAvailEvent /*!< Time stamp available event.*/
  269. } enet_event_t;
  270. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  271. /*! @brief Defines certain idle slope for bandwidth fraction. */
  272. typedef enum _enet_idle_slope
  273. {
  274. kENET_IdleSlope1 = 1U, /*!< The bandwidth fraction is about 0.002. */
  275. kENET_IdleSlope2 = 2U, /*!< The bandwidth fraction is about 0.003. */
  276. kENET_IdleSlope4 = 4U, /*!< The bandwidth fraction is about 0.008. */
  277. kENET_IdleSlope8 = 8U, /*!< The bandwidth fraction is about 0.02. */
  278. kENET_IdleSlope16 = 16U, /*!< The bandwidth fraction is about 0.03. */
  279. kENET_IdleSlope32 = 32U, /*!< The bandwidth fraction is about 0.06. */
  280. kENET_IdleSlope64 = 64U, /*!< The bandwidth fraction is about 0.11. */
  281. kENET_IdleSlope128 = 128U, /*!< The bandwidth fraction is about 0.20. */
  282. kENET_IdleSlope256 = 256U, /*!< The bandwidth fraction is about 0.33. */
  283. kENET_IdleSlope384 = 384U, /*!< The bandwidth fraction is about 0.43. */
  284. kENET_IdleSlope512 = 512U, /*!< The bandwidth fraction is about 0.50. */
  285. kENET_IdleSlope640 = 640U, /*!< The bandwidth fraction is about 0.56. */
  286. kENET_IdleSlope768 = 768U, /*!< The bandwidth fraction is about 0.60. */
  287. kENET_IdleSlope896 = 896U, /*!< The bandwidth fraction is about 0.64. */
  288. kENET_IdleSlope1024 = 1024U, /*!< The bandwidth fraction is about 0.67. */
  289. kENET_IdleSlope1152 = 1152U, /*!< The bandwidth fraction is about 0.69. */
  290. kENET_IdleSlope1280 = 1280U, /*!< The bandwidth fraction is about 0.71. */
  291. kENET_IdleSlope1408 = 1408U, /*!< The bandwidth fraction is about 0.73. */
  292. kENET_IdleSlope1536 = 1536U /*!< The bandwidth fraction is about 0.75. */
  293. } enet_idle_slope_t;
  294. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  295. /*! @brief Defines the transmit accelerator configuration. */
  296. typedef enum _enet_tx_accelerator
  297. {
  298. kENET_TxAccelIsShift16Enabled = ENET_TACC_SHIFT16_MASK, /*!< Transmit FIFO shift-16. */
  299. kENET_TxAccelIpCheckEnabled = ENET_TACC_IPCHK_MASK, /*!< Insert IP header checksum. */
  300. kENET_TxAccelProtoCheckEnabled = ENET_TACC_PROCHK_MASK /*!< Insert protocol checksum. */
  301. } enet_tx_accelerator_t;
  302. /*! @brief Defines the receive accelerator configuration. */
  303. typedef enum _enet_rx_accelerator
  304. {
  305. kENET_RxAccelPadRemoveEnabled = ENET_RACC_PADREM_MASK, /*!< Padding removal for short IP frames. */
  306. kENET_RxAccelIpCheckEnabled = ENET_RACC_IPDIS_MASK, /*!< Discard with wrong IP header checksum. */
  307. kENET_RxAccelProtoCheckEnabled = ENET_RACC_PRODIS_MASK, /*!< Discard with wrong protocol checksum. */
  308. kENET_RxAccelMacCheckEnabled = ENET_RACC_LINEDIS_MASK, /*!< Discard with Mac layer errors. */
  309. kENET_RxAccelisShift16Enabled = ENET_RACC_SHIFT16_MASK /*!< Receive FIFO shift-16. */
  310. } enet_rx_accelerator_t;
  311. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  312. /*! @brief Defines the ENET PTP message related constant. */
  313. typedef enum _enet_ptp_event_type
  314. {
  315. kENET_PtpEventMsgType = 3U, /*!< PTP event message type. */
  316. kENET_PtpSrcPortIdLen = 10U, /*!< PTP message sequence id length. */
  317. kENET_PtpEventPort = 319U, /*!< PTP event port number. */
  318. kENET_PtpGnrlPort = 320U /*!< PTP general port number. */
  319. } enet_ptp_event_type_t;
  320. /*! @brief Defines the IEEE 1588 PTP timer channel numbers. */
  321. typedef enum _enet_ptp_timer_channel
  322. {
  323. kENET_PtpTimerChannel1 = 0U, /*!< IEEE 1588 PTP timer Channel 1. */
  324. kENET_PtpTimerChannel2, /*!< IEEE 1588 PTP timer Channel 2. */
  325. kENET_PtpTimerChannel3, /*!< IEEE 1588 PTP timer Channel 3. */
  326. kENET_PtpTimerChannel4 /*!< IEEE 1588 PTP timer Channel 4. */
  327. } enet_ptp_timer_channel_t;
  328. /*! @brief Defines the capture or compare mode for IEEE 1588 PTP timer channels. */
  329. typedef enum _enet_ptp_timer_channel_mode
  330. {
  331. kENET_PtpChannelDisable = 0U, /*!< Disable timer channel. */
  332. kENET_PtpChannelRisingCapture = 1U, /*!< Input capture on rising edge. */
  333. kENET_PtpChannelFallingCapture = 2U, /*!< Input capture on falling edge. */
  334. kENET_PtpChannelBothCapture = 3U, /*!< Input capture on both edges. */
  335. kENET_PtpChannelSoftCompare = 4U, /*!< Output compare software only. */
  336. kENET_PtpChannelToggleCompare = 5U, /*!< Toggle output on compare. */
  337. kENET_PtpChannelClearCompare = 6U, /*!< Clear output on compare. */
  338. kENET_PtpChannelSetCompare = 7U, /*!< Set output on compare. */
  339. kENET_PtpChannelClearCompareSetOverflow = 10U, /*!< Clear output on compare, set output on overflow. */
  340. kENET_PtpChannelSetCompareClearOverflow = 11U, /*!< Set output on compare, clear output on overflow. */
  341. kENET_PtpChannelPulseLowonCompare = 14U, /*!< Pulse output low on compare for one IEEE 1588 clock cycle. */
  342. kENET_PtpChannelPulseHighonCompare = 15U /*!< Pulse output high on compare for one IEEE 1588 clock cycle. */
  343. } enet_ptp_timer_channel_mode_t;
  344. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  345. /*! @brief Defines the receive buffer descriptor structure for the little endian system.*/
  346. typedef struct _enet_rx_bd_struct
  347. {
  348. uint16_t length; /*!< Buffer descriptor data length. */
  349. uint16_t control; /*!< Buffer descriptor control and status. */
  350. uint8_t *buffer; /*!< Data buffer pointer. */
  351. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  352. uint16_t controlExtend0; /*!< Extend buffer descriptor control0. */
  353. uint16_t controlExtend1; /*!< Extend buffer descriptor control1. */
  354. uint16_t payloadCheckSum; /*!< Internal payload checksum. */
  355. uint8_t headerLength; /*!< Header length. */
  356. uint8_t protocolTyte; /*!< Protocol type. */
  357. uint16_t reserved0;
  358. uint16_t controlExtend2; /*!< Extend buffer descriptor control2. */
  359. uint32_t timestamp; /*!< Timestamp. */
  360. uint16_t reserved1;
  361. uint16_t reserved2;
  362. uint16_t reserved3;
  363. uint16_t reserved4;
  364. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  365. } enet_rx_bd_struct_t;
  366. /*! @brief Defines the enhanced transmit buffer descriptor structure for the little endian system. */
  367. typedef struct _enet_tx_bd_struct
  368. {
  369. uint16_t length; /*!< Buffer descriptor data length. */
  370. uint16_t control; /*!< Buffer descriptor control and status. */
  371. uint8_t *buffer; /*!< Data buffer pointer. */
  372. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  373. uint16_t controlExtend0; /*!< Extend buffer descriptor control0. */
  374. uint16_t controlExtend1; /*!< Extend buffer descriptor control1. */
  375. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  376. int8_t *txLaunchTime; /*!< Transmit launch time. */
  377. #else
  378. uint16_t reserved0;
  379. uint16_t reserved1;
  380. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  381. uint16_t reserved2;
  382. uint16_t controlExtend2; /*!< Extend buffer descriptor control2. */
  383. uint32_t timestamp; /*!< Timestamp. */
  384. uint16_t reserved3;
  385. uint16_t reserved4;
  386. uint16_t reserved5;
  387. uint16_t reserved6;
  388. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  389. } enet_tx_bd_struct_t;
  390. /*! @brief Defines the ENET data error statistics structure. */
  391. typedef struct _enet_data_error_stats
  392. {
  393. uint32_t statsRxLenGreaterErr; /*!< Receive length greater than RCR[MAX_FL]. */
  394. uint32_t statsRxAlignErr; /*!< Receive non-octet alignment/ */
  395. uint32_t statsRxFcsErr; /*!< Receive CRC error. */
  396. uint32_t statsRxOverRunErr; /*!< Receive over run. */
  397. uint32_t statsRxTruncateErr; /*!< Receive truncate. */
  398. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  399. uint32_t statsRxProtocolChecksumErr; /*!< Receive protocol checksum error. */
  400. uint32_t statsRxIpHeadChecksumErr; /*!< Receive IP header checksum error. */
  401. uint32_t statsRxMacErr; /*!< Receive Mac error. */
  402. uint32_t statsRxPhyErr; /*!< Receive PHY error. */
  403. uint32_t statsRxCollisionErr; /*!< Receive collision. */
  404. uint32_t statsTxErr; /*!< The error happen when transmit the frame. */
  405. uint32_t statsTxFrameErr; /*!< The transmit frame is error. */
  406. uint32_t statsTxOverFlowErr; /*!< Transmit overflow. */
  407. uint32_t statsTxLateCollisionErr; /*!< Transmit late collision. */
  408. uint32_t statsTxExcessCollisionErr; /*!< Transmit excess collision.*/
  409. uint32_t statsTxUnderFlowErr; /*!< Transmit under flow error. */
  410. uint32_t statsTxTsErr; /*!< Transmit time stamp error. */
  411. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  412. } enet_data_error_stats_t;
  413. /*! @brief Defines the receive buffer descriptor configuration structure.
  414. *
  415. * Note that for the internal DMA requirements, the buffers have a corresponding alignment requirements.
  416. * 1. The aligned receive and transmit buffer size must be evenly divisible by ENET_BUFF_ALIGNMENT.
  417. * when the data buffers are in cacheable region when cache is enabled, all those size should be
  418. * aligned to the maximum value of "ENET_BUFF_ALIGNMENT" and the cache line size.
  419. * 2. The aligned transmit and receive buffer descriptor start address must be at
  420. * least 64 bit aligned. However, it's recommended to be evenly divisible by ENET_BUFF_ALIGNMENT.
  421. * buffer descriptors should be put in non-cacheable region when cache is enabled.
  422. * 3. The aligned transmit and receive data buffer start address must be evenly divisible by ENET_BUFF_ALIGNMENT.
  423. * Receive buffers should be continuous with the total size equal to "rxBdNumber * rxBuffSizeAlign".
  424. * Transmit buffers should be continuous with the total size equal to "txBdNumber * txBuffSizeAlign".
  425. * when the data buffers are in cacheable region when cache is enabled, all those size should be
  426. * aligned to the maximum value of "ENET_BUFF_ALIGNMENT" and the cache line size.
  427. */
  428. typedef struct _enet_buffer_config
  429. {
  430. uint16_t rxBdNumber; /*!< Receive buffer descriptor number. */
  431. uint16_t txBdNumber; /*!< Transmit buffer descriptor number. */
  432. uint32_t rxBuffSizeAlign; /*!< Aligned receive data buffer size. */
  433. uint32_t txBuffSizeAlign; /*!< Aligned transmit data buffer size. */
  434. volatile enet_rx_bd_struct_t
  435. *rxBdStartAddrAlign; /*!< Aligned receive buffer descriptor start address: should be non-cacheable. */
  436. volatile enet_tx_bd_struct_t
  437. *txBdStartAddrAlign; /*!< Aligned transmit buffer descriptor start address: should be non-cacheable. */
  438. uint8_t *rxBufferAlign; /*!< Receive data buffer start address. */
  439. uint8_t *txBufferAlign; /*!< Transmit data buffer start address. */
  440. } enet_buffer_config_t;
  441. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  442. /*! @brief Defines the ENET PTP time stamp structure. */
  443. typedef struct _enet_ptp_time
  444. {
  445. uint64_t second; /*!< Second. */
  446. uint32_t nanosecond; /*!< Nanosecond. */
  447. } enet_ptp_time_t;
  448. /*! @brief Defines the structure for the ENET PTP message data and timestamp data.*/
  449. typedef struct _enet_ptp_time_data
  450. {
  451. uint8_t version; /*!< PTP version. */
  452. uint8_t sourcePortId[kENET_PtpSrcPortIdLen]; /*!< PTP source port ID. */
  453. uint16_t sequenceId; /*!< PTP sequence ID. */
  454. uint8_t messageType; /*!< PTP message type. */
  455. enet_ptp_time_t timeStamp; /*!< PTP timestamp. */
  456. } enet_ptp_time_data_t;
  457. /*! @brief Defines the ENET PTP ring buffer structure for the PTP message timestamp store.*/
  458. typedef struct _enet_ptp_time_data_ring
  459. {
  460. uint32_t front; /*!< The first index of the ring. */
  461. uint32_t end; /*!< The end index of the ring. */
  462. uint32_t size; /*!< The size of the ring. */
  463. enet_ptp_time_data_t *ptpTsData; /*!< PTP message data structure. */
  464. } enet_ptp_time_data_ring_t;
  465. /*! @brief Defines the ENET PTP configuration structure. */
  466. typedef struct _enet_ptp_config
  467. {
  468. uint8_t ptpTsRxBuffNum; /*!< Receive 1588 timestamp buffer number*/
  469. uint8_t ptpTsTxBuffNum; /*!< Transmit 1588 timestamp buffer number*/
  470. enet_ptp_time_data_t *rxPtpTsData; /*!< The start address of 1588 receive timestamp buffers */
  471. enet_ptp_time_data_t *txPtpTsData; /*!< The start address of 1588 transmit timestamp buffers */
  472. enet_ptp_timer_channel_t channel; /*!< Used for ERRATA_2579: the PTP 1588 timer channel for time interrupt. */
  473. uint32_t ptp1588ClockSrc_Hz; /*!< The clock source of the PTP 1588 timer. */
  474. } enet_ptp_config_t;
  475. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  476. #if defined(FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE) && FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE
  477. /*! @brief Defines the interrupt coalescing configure structure. */
  478. typedef struct _enet_intcoalesce_config
  479. {
  480. uint8_t txCoalesceFrameCount[FSL_FEATURE_ENET_QUEUE]; /*!< Transmit interrupt coalescing frame count threshold. */
  481. uint16_t txCoalesceTimeCount[FSL_FEATURE_ENET_QUEUE]; /*!< Transmit interrupt coalescing timer count threshold. */
  482. uint8_t rxCoalesceFrameCount[FSL_FEATURE_ENET_QUEUE]; /*!< Receive interrupt coalescing frame count threshold. */
  483. uint16_t rxCoalesceTimeCount[FSL_FEATURE_ENET_QUEUE]; /*!< Receive interrupt coalescing timer count threshold. */
  484. } enet_intcoalesce_config_t;
  485. #endif /* FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE */
  486. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  487. /*! @brief Defines the ENET AVB Configure structure.
  488. *
  489. * This is used for to configure the extended ring 1 and ring 2.
  490. * 1. The classification match format is (CMP3 << 12) | (CMP2 << 8) | (CMP1 << 4) | CMP0.
  491. * composed of four 3-bit compared VLAN priority field cmp0~cmp3, cm0 ~ cmp3 are used in parallel.
  492. *
  493. * If CMP1,2,3 are not unused, please set them to the same value as CMP0.
  494. * 2. The idleSlope is used to calculate the Band Width fraction, BW fraction = 1 / (1 + 512/idleSlope).
  495. * For avb configuration, the BW fraction of Class 1 and Class 2 combined must not exceed 0.75.
  496. */
  497. typedef struct _enet_avb_config
  498. {
  499. uint16_t rxClassifyMatch[FSL_FEATURE_ENET_QUEUE - 1]; /*!< The classification match value for the ring. */
  500. enet_idle_slope_t idleSlope[FSL_FEATURE_ENET_QUEUE - 1]; /*!< The idle slope for certian bandwidth fraction. */
  501. } enet_avb_config_t;
  502. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  503. /*! @brief Defines the basic configuration structure for the ENET device.
  504. *
  505. * Note:
  506. * 1. macSpecialConfig is used for a special control configuration, A logical OR of
  507. * "enet_special_control_flag_t". For a special configuration for MAC,
  508. * set this parameter to 0.
  509. * 2. txWatermark is used for a cut-through operation. It is in steps of 64 bytes:
  510. * 0/1 - 64 bytes written to TX FIFO before transmission of a frame begins.
  511. * 2 - 128 bytes written to TX FIFO ....
  512. * 3 - 192 bytes written to TX FIFO ....
  513. * The maximum of txWatermark is 0x2F - 4032 bytes written to TX FIFO ....
  514. * txWatermark allows minimizing the transmit latency to set the txWatermark to 0 or 1
  515. * or for larger bus access latency 3 or larger due to contention for the system bus.
  516. * 3. rxFifoFullThreshold is similar to the txWatermark for cut-through operation in RX.
  517. * It is in 64-bit words. The minimum is ENET_FIFO_MIN_RX_FULL and the maximum is 0xFF.
  518. * If the end of the frame is stored in FIFO and the frame size if smaller than the
  519. * txWatermark, the frame is still transmitted. The rule is the
  520. * same for rxFifoFullThreshold in the receive direction.
  521. * 4. When "kENET_ControlFlowControlEnable" is set in the macSpecialConfig, ensure
  522. * that the pauseDuration, rxFifoEmptyThreshold, and rxFifoStatEmptyThreshold
  523. * are set for flow control enabled case.
  524. * 5. When "kENET_ControlStoreAndFwdDisabled" is set in the macSpecialConfig, ensure
  525. * that the rxFifoFullThreshold and txFifoWatermark are set for store and forward disable.
  526. * 6. The rxAccelerConfig and txAccelerConfig default setting with 0 - accelerator
  527. * are disabled. The "enet_tx_accelerator_t" and "enet_rx_accelerator_t" are
  528. * recommended to be used to enable the transmit and receive accelerator.
  529. * After the accelerators are enabled, the store and forward feature should be enabled.
  530. * As a result, kENET_ControlStoreAndFwdDisabled should not be set.
  531. * 7. The intCoalesceCfg can be used in the rx or tx enabled cases to decrese the CPU loading.
  532. */
  533. typedef struct _enet_config
  534. {
  535. uint32_t macSpecialConfig; /*!< Mac special configuration. A logical OR of "enet_special_control_flag_t". */
  536. uint32_t interrupt; /*!< Mac interrupt source. A logical OR of "enet_interrupt_enable_t". */
  537. uint16_t rxMaxFrameLen; /*!< Receive maximum frame length. */
  538. enet_mii_mode_t miiMode; /*!< MII mode. */
  539. enet_mii_speed_t miiSpeed; /*!< MII Speed. */
  540. enet_mii_duplex_t miiDuplex; /*!< MII duplex. */
  541. uint8_t rxAccelerConfig; /*!< Receive accelerator, A logical OR of "enet_rx_accelerator_t". */
  542. uint8_t txAccelerConfig; /*!< Transmit accelerator, A logical OR of "enet_rx_accelerator_t". */
  543. uint16_t pauseDuration; /*!< For flow control enabled case: Pause duration. */
  544. uint8_t rxFifoEmptyThreshold; /*!< For flow control enabled case: when RX FIFO level reaches this value,
  545. it makes MAC generate XOFF pause frame. */
  546. #if defined(FSL_FEATURE_ENET_HAS_RECEIVE_STATUS_THRESHOLD) && FSL_FEATURE_ENET_HAS_RECEIVE_STATUS_THRESHOLD
  547. uint8_t rxFifoStatEmptyThreshold; /*!< For flow control enabled case: number of frames in the receive FIFO,
  548. independent of size, that can be accept. If the limit is reached, reception
  549. continues and a pause frame is triggered. */
  550. #endif /* FSL_FEATURE_ENET_HAS_RECEIVE_STATUS_THRESHOLD */
  551. uint8_t rxFifoFullThreshold; /*!< For store and forward disable case, the data required in RX FIFO to notify
  552. the MAC receive ready status. */
  553. uint8_t txFifoWatermark; /*!< For store and forward disable case, the data required in TX FIFO
  554. before a frame transmit start. */
  555. #if defined(FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE) && FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE
  556. enet_intcoalesce_config_t
  557. *intCoalesceCfg; /* If the interrupt coalsecence is not required in the ring n(0,1,2), please set
  558. to NULL. */
  559. #endif /* FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE */
  560. uint8_t ringNum; /*!< Number of used rings. default with 1 -- single ring. */
  561. } enet_config_t;
  562. /* Forward declaration of the handle typedef. */
  563. typedef struct _enet_handle enet_handle_t;
  564. /*! @brief ENET callback function. */
  565. #if FSL_FEATURE_ENET_QUEUE > 1
  566. typedef void (*enet_callback_t)(
  567. ENET_Type *base, enet_handle_t *handle, uint32_t ringId, enet_event_t event, void *userData);
  568. #else
  569. typedef void (*enet_callback_t)(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *userData);
  570. #endif /* FSL_FEATURE_ENET_QUEUE > 1 */
  571. /*! @brief Defines the ENET handler structure. */
  572. struct _enet_handle
  573. {
  574. volatile enet_rx_bd_struct_t
  575. *rxBdBase[FSL_FEATURE_ENET_QUEUE]; /*!< Receive buffer descriptor base address pointer. */
  576. volatile enet_rx_bd_struct_t
  577. *rxBdCurrent[FSL_FEATURE_ENET_QUEUE]; /*!< The current available receive buffer descriptor pointer. */
  578. volatile enet_tx_bd_struct_t
  579. *txBdBase[FSL_FEATURE_ENET_QUEUE]; /*!< Transmit buffer descriptor base address pointer. */
  580. volatile enet_tx_bd_struct_t
  581. *txBdCurrent[FSL_FEATURE_ENET_QUEUE]; /*!< The current available transmit buffer descriptor pointer. */
  582. uint32_t rxBuffSizeAlign[FSL_FEATURE_ENET_QUEUE]; /*!< Receive buffer size alignment. */
  583. uint32_t txBuffSizeAlign[FSL_FEATURE_ENET_QUEUE]; /*!< Transmit buffer size alignment. */
  584. uint8_t ringNum; /*!< Number of used rings. */
  585. enet_callback_t callback; /*!< Callback function. */
  586. void *userData; /*!< Callback function parameter.*/
  587. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  588. volatile enet_tx_bd_struct_t
  589. *txBdDirtyStatic[FSL_FEATURE_ENET_QUEUE]; /*!< The dirty transmit buffer descriptor for error static update. */
  590. volatile enet_tx_bd_struct_t
  591. *txBdDirtyTime[FSL_FEATURE_ENET_QUEUE]; /*!< The dirty transmit buffer descriptor for time stamp update. */
  592. uint64_t msTimerSecond; /*!< The second for Master PTP timer .*/
  593. enet_ptp_time_data_ring_t rxPtpTsDataRing; /*!< Receive PTP 1588 time stamp data ring buffer. */
  594. enet_ptp_time_data_ring_t txPtpTsDataRing; /*!< Transmit PTP 1588 time stamp data ring buffer. */
  595. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  596. };
  597. /*******************************************************************************
  598. * API
  599. ******************************************************************************/
  600. #if defined(__cplusplus)
  601. extern "C" {
  602. #endif
  603. /*!
  604. * @name Initialization and De-initialization
  605. * @{
  606. */
  607. /*!
  608. * @brief Gets the ENET default configuration structure.
  609. *
  610. * The purpose of this API is to get the default ENET MAC controller
  611. * configure structure for ENET_Init(). User may use the initialized
  612. * structure unchanged in ENET_Init(), or modify some fields of the
  613. * structure before calling ENET_Init().
  614. * Example:
  615. @code
  616. enet_config_t config;
  617. ENET_GetDefaultConfig(&config);
  618. @endcode
  619. * @param config The ENET mac controller configuration structure pointer.
  620. */
  621. void ENET_GetDefaultConfig(enet_config_t *config);
  622. /*!
  623. * @brief Initializes the ENET module.
  624. *
  625. * This function ungates the module clock and initializes it with the ENET configuration.
  626. *
  627. * @param base ENET peripheral base address.
  628. * @param handle ENET handler pointer.
  629. * @param config ENET mac configuration structure pointer.
  630. * The "enet_config_t" type mac configuration return from ENET_GetDefaultConfig
  631. * can be used directly. It is also possible to verify the Mac configuration using other methods.
  632. * @param bufferConfig ENET buffer configuration structure pointer.
  633. * The buffer configuration should be prepared for ENET Initialization.
  634. * It is the start address of "ringNum" enet_buffer_config structures.
  635. * To support added multi-ring features in some soc and compatible with the previous
  636. * enet driver version. For single ring supported, this bufferConfig is a buffer
  637. * configure structure pointer, for multi-ring supported and used case, this bufferConfig
  638. * pointer should be a buffer configure structure array pointer.
  639. * @param macAddr ENET mac address of Ethernet device. This MAC address should be
  640. * provided.
  641. * @param srcClock_Hz The internal module clock source for MII clock.
  642. *
  643. * @note ENET has two buffer descriptors legacy buffer descriptors and
  644. * enhanced IEEE 1588 buffer descriptors. The legacy descriptor is used by default. To
  645. * use the IEEE 1588 feature, use the enhanced IEEE 1588 buffer descriptor
  646. * by defining "ENET_ENHANCEDBUFFERDESCRIPTOR_MODE" and calling ENET_Ptp1588Configure()
  647. * to configure the 1588 feature and related buffers after calling ENET_Init().
  648. */
  649. void ENET_Init(ENET_Type *base,
  650. enet_handle_t *handle,
  651. const enet_config_t *config,
  652. const enet_buffer_config_t *bufferConfig,
  653. uint8_t *macAddr,
  654. uint32_t srcClock_Hz);
  655. /*!
  656. * @brief Deinitializes the ENET module.
  657. * This function gates the module clock, clears ENET interrupts, and disables the ENET module.
  658. *
  659. * @param base ENET peripheral base address.
  660. */
  661. void ENET_Deinit(ENET_Type *base);
  662. /*!
  663. * @brief Resets the ENET module.
  664. *
  665. * This function restores the ENET module to reset state.
  666. * Note that this function sets all registers to
  667. * reset state. As a result, the ENET module can't work after calling this function.
  668. *
  669. * @param base ENET peripheral base address.
  670. */
  671. static inline void ENET_Reset(ENET_Type *base)
  672. {
  673. base->ECR |= ENET_ECR_RESET_MASK;
  674. }
  675. /* @} */
  676. /*!
  677. * @name MII interface operation
  678. * @{
  679. */
  680. /*!
  681. * @brief Sets the ENET MII speed and duplex.
  682. *
  683. * This API is provided to dynamically change the speed and dulpex for MAC.
  684. *
  685. * @param base ENET peripheral base address.
  686. * @param speed The speed of the RMII mode.
  687. * @param duplex The duplex of the RMII mode.
  688. */
  689. void ENET_SetMII(ENET_Type *base, enet_mii_speed_t speed, enet_mii_duplex_t duplex);
  690. /*!
  691. * @brief Sets the ENET SMI(serial management interface)- MII management interface.
  692. *
  693. * @param base ENET peripheral base address.
  694. * @param srcClock_Hz This is the ENET module clock frequency. Normally it's the system clock. See clock distribution.
  695. * @param isPreambleDisabled The preamble disable flag.
  696. * - true Enables the preamble.
  697. * - false Disables the preamble.
  698. */
  699. void ENET_SetSMI(ENET_Type *base, uint32_t srcClock_Hz, bool isPreambleDisabled);
  700. /*!
  701. * @brief Gets the ENET SMI- MII management interface configuration.
  702. *
  703. * This API is used to get the SMI configuration to check whether the MII management
  704. * interface has been set.
  705. *
  706. * @param base ENET peripheral base address.
  707. * @return The SMI setup status true or false.
  708. */
  709. static inline bool ENET_GetSMI(ENET_Type *base)
  710. {
  711. return (0 != (base->MSCR & 0x7E));
  712. }
  713. /*!
  714. * @brief Reads data from the PHY register through an SMI interface.
  715. *
  716. * @param base ENET peripheral base address.
  717. * @return The data read from PHY
  718. */
  719. static inline uint32_t ENET_ReadSMIData(ENET_Type *base)
  720. {
  721. return (uint32_t)((base->MMFR & ENET_MMFR_DATA_MASK) >> ENET_MMFR_DATA_SHIFT);
  722. }
  723. /*!
  724. * @brief Starts an SMI (Serial Management Interface) read command.
  725. *
  726. * Used for standard IEEE802.3 MDIO Clause 22 format.
  727. *
  728. * @param base ENET peripheral base address.
  729. * @param phyAddr The PHY address.
  730. * @param phyReg The PHY register. Range from 0 ~ 31.
  731. * @param operation The read operation.
  732. */
  733. void ENET_StartSMIRead(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, enet_mii_read_t operation);
  734. /*!
  735. * @brief Starts an SMI write command.
  736. *
  737. * Used for standard IEEE802.3 MDIO Clause 22 format.
  738. *
  739. * @param base ENET peripheral base address.
  740. * @param phyAddr The PHY address.
  741. * @param phyReg The PHY register. Range from 0 ~ 31.
  742. * @param operation The write operation.
  743. * @param data The data written to PHY.
  744. */
  745. void ENET_StartSMIWrite(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, enet_mii_write_t operation, uint32_t data);
  746. #if defined(FSL_FEATURE_ENET_HAS_EXTEND_MDIO) && FSL_FEATURE_ENET_HAS_EXTEND_MDIO
  747. /*!
  748. * @brief Starts the extended IEEE802.3 Clause 45 MDIO format SMI read command.
  749. *
  750. * @param base ENET peripheral base address.
  751. * @param phyAddr The PHY address.
  752. * @param phyReg The PHY register. For MDIO IEEE802.3 Clause 45,
  753. * the phyReg is a 21-bits combination of the devaddr (5 bits device address)
  754. * and the regAddr (16 bits phy register): phyReg = (devaddr << 16) | regAddr.
  755. */
  756. void ENET_StartExtC45SMIRead(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg);
  757. /*!
  758. * @brief Starts the extended IEEE802.3 Clause 45 MDIO format SMI write command.
  759. *
  760. * @param base ENET peripheral base address.
  761. * @param phyAddr The PHY address.
  762. * @param phyReg The PHY register. For MDIO IEEE802.3 Clause 45,
  763. * the phyReg is a 21-bits combination of the devaddr (5 bits device address)
  764. * and the regAddr (16 bits phy register): phyReg = (devaddr << 16) | regAddr.
  765. * @param data The data written to PHY.
  766. */
  767. void ENET_StartExtC45SMIWrite(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t data);
  768. #endif /* FSL_FEATURE_ENET_HAS_EXTEND_MDIO */
  769. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  770. /*!
  771. * @brief Control the usage of the delayed tx/rx RGMII clock.
  772. *
  773. * @param base ENET peripheral base address.
  774. * @param txEnabled Enable or disable to generate the delayed version of RGMII_TXC.
  775. * @param rxEnabled Enable or disable to use the delayed version of RGMII_RXC.
  776. */
  777. static inline void ENET_SetRGMIIClockDelay(ENET_Type *base, bool txEnabled, bool rxEnabled)
  778. {
  779. uint32_t ecrReg = base->ECR;
  780. /* Set for transmit clock delay. */
  781. if (txEnabled)
  782. {
  783. ecrReg |= ENET_ECR_TXC_DLY_MASK;
  784. }
  785. else
  786. {
  787. ecrReg &= ~ENET_ECR_TXC_DLY_MASK;
  788. }
  789. /* Set for receive clock delay. */
  790. if (rxEnabled)
  791. {
  792. ecrReg |= ENET_ECR_RXC_DLY_MASK;
  793. }
  794. else
  795. {
  796. ecrReg &= ~ENET_ECR_RXC_DLY_MASK;
  797. }
  798. }
  799. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  800. /* @} */
  801. /*!
  802. * @name MAC Address Filter
  803. * @{
  804. */
  805. /*!
  806. * @brief Sets the ENET module Mac address.
  807. *
  808. * @param base ENET peripheral base address.
  809. * @param macAddr The six-byte Mac address pointer.
  810. * The pointer is allocated by application and input into the API.
  811. */
  812. void ENET_SetMacAddr(ENET_Type *base, uint8_t *macAddr);
  813. /*!
  814. * @brief Gets the ENET module Mac address.
  815. *
  816. * @param base ENET peripheral base address.
  817. * @param macAddr The six-byte Mac address pointer.
  818. * The pointer is allocated by application and input into the API.
  819. */
  820. void ENET_GetMacAddr(ENET_Type *base, uint8_t *macAddr);
  821. /*!
  822. * @brief Adds the ENET device to a multicast group.
  823. *
  824. * @param base ENET peripheral base address.
  825. * @param address The six-byte multicast group address which is provided by application.
  826. */
  827. void ENET_AddMulticastGroup(ENET_Type *base, uint8_t *address);
  828. /*!
  829. * @brief Moves the ENET device from a multicast group.
  830. *
  831. * @param base ENET peripheral base address.
  832. * @param address The six-byte multicast group address which is provided by application.
  833. */
  834. void ENET_LeaveMulticastGroup(ENET_Type *base, uint8_t *address);
  835. /* @} */
  836. /*!
  837. * @name Other basic operation
  838. * @{
  839. */
  840. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  841. #if defined(FSL_FEATURE_ENET_HAS_AVB) && FSL_FEATURE_ENET_HAS_AVB
  842. /*!
  843. * @brief Sets the ENET AVB feature.
  844. *
  845. * ENET AVB feature configuration, set the Receive classification match and transmit
  846. * bandwidth. This API is called when the AVB feature is required.
  847. *
  848. * Note: The AVB frames transmission scheme is credit-based tx scheme and it's only supported
  849. * with the Enhanced buffer descriptors. so the AVB configuration should only done with
  850. * Enhanced buffer descriptor. so when the AVB feature is required, please make sure the
  851. * the "ENET_ENHANCEDBUFFERDESCRIPTOR_MODE" is defined.
  852. *
  853. * @param base ENET peripheral base address.
  854. * @param handle ENET handler pointer.
  855. * @param config The ENET AVB feature configuration structure.
  856. */
  857. void ENET_AVBConfigure(ENET_Type *base, enet_handle_t *handle, const enet_avb_config_t *config);
  858. #endif /* FSL_FEATURE_ENET_HAS_AVB */
  859. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  860. /*!
  861. * @brief Activates ENET read or receive.
  862. *
  863. * This function is to active the enet read process. It is
  864. * used for single descriptor ring/queue.
  865. *
  866. * @param base ENET peripheral base address.
  867. *
  868. * @note This must be called after the MAC configuration and
  869. * state are ready. It must be called after the ENET_Init() and
  870. * ENET_Ptp1588Configure(). This should be called when the ENET receive required.
  871. */
  872. static inline void ENET_ActiveRead(ENET_Type *base)
  873. {
  874. base->RDAR = ENET_RDAR_RDAR_MASK;
  875. }
  876. #if FSL_FEATURE_ENET_QUEUE > 1
  877. /*!
  878. * @brief Activates ENET read or receive for multiple-queue/ring.
  879. *
  880. * This function is to active the enet read process. It is
  881. * used for extended multiple descriptor rings/queues.
  882. *
  883. * @param base ENET peripheral base address.
  884. *
  885. * @note This must be called after the MAC configuration and
  886. * state are ready. It must be called after the ENET_Init() and
  887. * ENET_Ptp1588Configure(). This should be called when the ENET receive required.
  888. */
  889. static inline void ENET_ActiveReadMultiRing(ENET_Type *base)
  890. {
  891. base->RDAR = ENET_RDAR_RDAR_MASK;
  892. base->RDAR1 = ENET_RDAR1_RDAR_MASK;
  893. base->RDAR2 = ENET_RDAR2_RDAR_MASK;
  894. }
  895. #endif /* FSL_FEATURE_ENET_QUEUE > 1 */
  896. /*!
  897. * @brief Enables/disables the MAC to enter sleep mode.
  898. * This function is used to set the MAC enter sleep mode.
  899. * When entering sleep mode, the magic frame wakeup interrupt should be enabled
  900. * to wake up MAC from the sleep mode and reset it to normal mode.
  901. *
  902. * @param base ENET peripheral base address.
  903. * @param enable True enable sleep mode, false disable sleep mode.
  904. */
  905. static inline void ENET_EnableSleepMode(ENET_Type *base, bool enable)
  906. {
  907. if (enable)
  908. {
  909. /* When this field is set, MAC enters sleep mode. */
  910. base->ECR |= ENET_ECR_SLEEP_MASK | ENET_ECR_MAGICEN_MASK;
  911. }
  912. else
  913. { /* MAC exits sleep mode. */
  914. base->ECR &= ~(ENET_ECR_SLEEP_MASK | ENET_ECR_MAGICEN_MASK);
  915. }
  916. }
  917. /*!
  918. * @brief Gets ENET transmit and receive accelerator functions from MAC controller.
  919. *
  920. * @param base ENET peripheral base address.
  921. * @param txAccelOption The transmit accelerator option. The "enet_tx_accelerator_t" is
  922. * recommended to be used to as the mask to get the exact the accelerator option.
  923. * @param rxAccelOption The receive accelerator option. The "enet_rx_accelerator_t" is
  924. * recommended to be used to as the mask to get the exact the accelerator option.
  925. */
  926. static inline void ENET_GetAccelFunction(ENET_Type *base, uint32_t *txAccelOption, uint32_t *rxAccelOption)
  927. {
  928. assert(txAccelOption);
  929. assert(txAccelOption);
  930. *txAccelOption = base->TACC;
  931. *rxAccelOption = base->RACC;
  932. }
  933. /* @} */
  934. /*!
  935. * @name Interrupts.
  936. * @{
  937. */
  938. /*!
  939. * @brief Enables the ENET interrupt.
  940. *
  941. * This function enables the ENET interrupt according to the provided mask. The mask
  942. * is a logical OR of enumeration members. See @ref enet_interrupt_enable_t.
  943. * For example, to enable the TX frame interrupt and RX frame interrupt, do the following.
  944. * @code
  945. * ENET_EnableInterrupts(ENET, kENET_TxFrameInterrupt | kENET_RxFrameInterrupt);
  946. * @endcode
  947. *
  948. * @param base ENET peripheral base address.
  949. * @param mask ENET interrupts to enable. This is a logical OR of the
  950. * enumeration :: enet_interrupt_enable_t.
  951. */
  952. static inline void ENET_EnableInterrupts(ENET_Type *base, uint32_t mask)
  953. {
  954. base->EIMR |= mask;
  955. }
  956. /*!
  957. * @brief Disables the ENET interrupt.
  958. *
  959. * This function disables the ENET interrupts according to the provided mask. The mask
  960. * is a logical OR of enumeration members. See @ref enet_interrupt_enable_t.
  961. * For example, to disable the TX frame interrupt and RX frame interrupt, do the following.
  962. * @code
  963. * ENET_DisableInterrupts(ENET, kENET_TxFrameInterrupt | kENET_RxFrameInterrupt);
  964. * @endcode
  965. *
  966. * @param base ENET peripheral base address.
  967. * @param mask ENET interrupts to disable. This is a logical OR of the
  968. * enumeration :: enet_interrupt_enable_t.
  969. */
  970. static inline void ENET_DisableInterrupts(ENET_Type *base, uint32_t mask)
  971. {
  972. base->EIMR &= ~mask;
  973. }
  974. /*!
  975. * @brief Gets the ENET interrupt status flag.
  976. *
  977. * @param base ENET peripheral base address.
  978. * @return The event status of the interrupt source. This is the logical OR of members
  979. * of the enumeration :: enet_interrupt_enable_t.
  980. */
  981. static inline uint32_t ENET_GetInterruptStatus(ENET_Type *base)
  982. {
  983. return base->EIR;
  984. }
  985. /*!
  986. * @brief Clears the ENET interrupt events status flag.
  987. *
  988. * This function clears enabled ENET interrupts according to the provided mask. The mask
  989. * is a logical OR of enumeration members. See the @ref enet_interrupt_enable_t.
  990. * For example, to clear the TX frame interrupt and RX frame interrupt, do the following.
  991. * @code
  992. * ENET_ClearInterruptStatus(ENET, kENET_TxFrameInterrupt | kENET_RxFrameInterrupt);
  993. * @endcode
  994. *
  995. * @param base ENET peripheral base address.
  996. * @param mask ENET interrupt source to be cleared.
  997. * This is the logical OR of members of the enumeration :: enet_interrupt_enable_t.
  998. */
  999. static inline void ENET_ClearInterruptStatus(ENET_Type *base, uint32_t mask)
  1000. {
  1001. base->EIR = mask;
  1002. }
  1003. /* @} */
  1004. /*!
  1005. * @name Transactional operation
  1006. * @{
  1007. */
  1008. /*!
  1009. * @brief Sets the callback function.
  1010. * This API is provided for the application callback required case when ENET
  1011. * interrupt is enabled. This API should be called after calling ENET_Init.
  1012. *
  1013. * @param handle ENET handler pointer. Should be provided by application.
  1014. * @param callback The ENET callback function.
  1015. * @param userData The callback function parameter.
  1016. */
  1017. void ENET_SetCallback(enet_handle_t *handle, enet_callback_t callback, void *userData);
  1018. /*!
  1019. * @brief Gets the error statistics of a received frame for ENET single ring.
  1020. *
  1021. * This API must be called after the ENET_GetRxFrameSize and before the ENET_ReadFrame().
  1022. * If the ENET_GetRxFrameSize returns kStatus_ENET_RxFrameError,
  1023. * the ENET_GetRxErrBeforeReadFrame can be used to get the exact error statistics.
  1024. * This is an example.
  1025. * @code
  1026. * status = ENET_GetRxFrameSize(&g_handle, &length);
  1027. * if (status == kStatus_ENET_RxFrameError)
  1028. * {
  1029. * // Get the error information of the received frame.
  1030. * ENET_GetRxErrBeforeReadFrame(&g_handle, &eErrStatic);
  1031. * // update the receive buffer.
  1032. * ENET_ReadFrame(EXAMPLE_ENET, &g_handle, NULL, 0);
  1033. * }
  1034. * @endcode
  1035. * @param handle The ENET handler structure pointer. This is the same handler pointer used in the ENET_Init.
  1036. * @param eErrorStatic The error statistics structure pointer.
  1037. */
  1038. void ENET_GetRxErrBeforeReadFrame(enet_handle_t *handle, enet_data_error_stats_t *eErrorStatic);
  1039. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  1040. /*!
  1041. * @brief Gets the ENET transmit frame statistics after the data send for single ring.
  1042. *
  1043. * This interface gets the error statistics of the transmit frame.
  1044. * Because the error information is reported by the uDMA after the data delivery, this interface
  1045. * should be called after the data transmit API. It is recommended to call this function on
  1046. * transmit interrupt handler. After calling the ENET_SendFrame, the
  1047. * transmit interrupt notifies the transmit completion.
  1048. *
  1049. * @param handle The PTP handler pointer. This is the same handler pointer used in the ENET_Init.
  1050. * @param eErrorStatic The error statistics structure pointer.
  1051. * @return The execute status.
  1052. */
  1053. status_t ENET_GetTxErrAfterSendFrame(enet_handle_t *handle, enet_data_error_stats_t *eErrorStatic);
  1054. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  1055. /*!
  1056. * @brief Gets the size of the read frame for single ring.
  1057. *
  1058. * This function gets a received frame size from the ENET buffer descriptors.
  1059. * @note The FCS of the frame is automatically removed by MAC and the size is the length without the FCS.
  1060. * After calling ENET_GetRxFrameSize, ENET_ReadFrame() should be called to update the
  1061. * receive buffers If the result is not "kStatus_ENET_RxFrameEmpty".
  1062. *
  1063. * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_Init.
  1064. * @param length The length of the valid frame received.
  1065. * @retval kStatus_ENET_RxFrameEmpty No frame received. Should not call ENET_ReadFrame to read frame.
  1066. * @retval kStatus_ENET_RxFrameError Data error happens. ENET_ReadFrame should be called with NULL data
  1067. * and NULL length to update the receive buffers.
  1068. * @retval kStatus_Success Receive a frame Successfully then the ENET_ReadFrame
  1069. * should be called with the right data buffer and the captured data length input.
  1070. */
  1071. status_t ENET_GetRxFrameSize(enet_handle_t *handle, uint32_t *length);
  1072. /*!
  1073. * @brief Reads a frame from the ENET device for single ring.
  1074. * This function reads a frame (both the data and the length) from the ENET buffer descriptors.
  1075. * The ENET_GetRxFrameSize should be used to get the size of the prepared data buffer.
  1076. * This is an example:
  1077. * @code
  1078. * uint32_t length;
  1079. * enet_handle_t g_handle;
  1080. * //Get the received frame size firstly.
  1081. * status = ENET_GetRxFrameSize(&g_handle, &length);
  1082. * if (length != 0)
  1083. * {
  1084. * //Allocate memory here with the size of "length"
  1085. * uint8_t *data = memory allocate interface;
  1086. * if (!data)
  1087. * {
  1088. * ENET_ReadFrame(ENET, &g_handle, NULL, 0);
  1089. * //Add the console warning log.
  1090. * }
  1091. * else
  1092. * {
  1093. * status = ENET_ReadFrame(ENET, &g_handle, data, length);
  1094. * //Call stack input API to deliver the data to stack
  1095. * }
  1096. * }
  1097. * else if (status == kStatus_ENET_RxFrameError)
  1098. * {
  1099. * //Update the received buffer when a error frame is received.
  1100. * ENET_ReadFrame(ENET, &g_handle, NULL, 0);
  1101. * }
  1102. * @endcode
  1103. * @param base ENET peripheral base address.
  1104. * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_Init.
  1105. * @param data The data buffer provided by user to store the frame which memory size should be at least "length".
  1106. * @param length The size of the data buffer which is still the length of the received frame.
  1107. * @return The execute status, successful or failure.
  1108. */
  1109. status_t ENET_ReadFrame(ENET_Type *base, enet_handle_t *handle, uint8_t *data, uint32_t length);
  1110. /*!
  1111. * @brief Transmits an ENET frame for single ring.
  1112. * @note The CRC is automatically appended to the data. Input the data
  1113. * to send without the CRC.
  1114. *
  1115. *
  1116. * @param base ENET peripheral base address.
  1117. * @param handle The ENET handler pointer. This is the same handler pointer used in the ENET_Init.
  1118. * @param data The data buffer provided by user to be send.
  1119. * @param length The length of the data to be send.
  1120. * @retval kStatus_Success Send frame succeed.
  1121. * @retval kStatus_ENET_TxFrameBusy Transmit buffer descriptor is busy under transmission.
  1122. * The transmit busy happens when the data send rate is over the MAC capacity.
  1123. * The waiting mechanism is recommended to be added after each call return with
  1124. * kStatus_ENET_TxFrameBusy.
  1125. */
  1126. status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *data, uint32_t length);
  1127. #if FSL_FEATURE_ENET_QUEUE > 1
  1128. /*!
  1129. * @brief Gets the error statistics of received frame for extended multi-ring.
  1130. *
  1131. * This API must be called after the ENET_GetRxFrameSizeMultiRing and before the ENET_ReadFrameMultiRing().
  1132. * If the ENET_GetRxFrameSizeMultiRing returns kStatus_ENET_RxFrameError,
  1133. * the ENET_GetRxErrBeforeReadFrameMultiRing can be used to get the exact error statistics.
  1134. *
  1135. * @param handle The ENET handler structure pointer. This is the same handler pointer used in the ENET_Init.
  1136. * @param eErrorStatic The error statistics structure pointer.
  1137. * @param ringId The ring index, range from 0 ~ FSL_FEATURE_ENET_QUEUE - 1.
  1138. */
  1139. void ENET_GetRxErrBeforeReadFrameMultiRing(enet_handle_t *handle,
  1140. enet_data_error_stats_t *eErrorStatic,
  1141. uint32_t ringId);
  1142. /*!
  1143. * @brief Transmits an ENET frame for extended multi-ring.
  1144. * @note The CRC is automatically appended to the data. Input the data
  1145. * to send without the CRC.
  1146. *
  1147. * In this API, multiple-ring are mainly used for extended avb frames are supported.
  1148. * The transmit scheme for avb frames is the credit-based scheme, the AVB class A, AVB class B
  1149. * and the non-AVB frame are transmitted in ring 1, ring 2 and ring 0 independently.
  1150. * So application should care about the transmit ring index when use multiple-ring transmission.
  1151. *
  1152. * @param base ENET peripheral base address.
  1153. * @param handle The ENET handler pointer. This is the same handler pointer used in the ENET_Init.
  1154. * @param data The data buffer provided by user to be send.
  1155. * @param length The length of the data to be send.
  1156. * @param ringId The ring index for transmission.
  1157. * @retval kStatus_Success Send frame succeed.
  1158. * @retval kStatus_ENET_TxFrameBusy Transmit buffer descriptor is busy under transmission.
  1159. * The transmit busy happens when the data send rate is over the MAC capacity.
  1160. * The waiting mechanism is recommended to be added after each call return with
  1161. * kStatus_ENET_TxFrameBusy.
  1162. */
  1163. status_t ENET_SendFrameMultiRing(
  1164. ENET_Type *base, enet_handle_t *handle, uint8_t *data, uint32_t length, uint32_t ringId);
  1165. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  1166. /*!
  1167. * @brief Gets the ENET transmit frame statistics after the data send for extended multi-ring.
  1168. *
  1169. * This interface gets the error statistics of the transmit frame.
  1170. * Because the error information is reported by the uDMA after the data delivery, this interface
  1171. * should be called after the data transmit API and shall be called by transmit interrupt handler.
  1172. * After calling the ENET_SendFrame, the transmit interrupt notifies the transmit completion.
  1173. *
  1174. * @param handle The PTP handler pointer. This is the same handler pointer used in the ENET_Init.
  1175. * @param eErrorStatic The error statistics structure pointer.
  1176. * @param ringId The ring index.
  1177. * @return The execute status.
  1178. */
  1179. status_t ENET_GetTxErrAfterSendFrameMultiRing(enet_handle_t *handle,
  1180. enet_data_error_stats_t *eErrorStatic,
  1181. uint32_t ringId);
  1182. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  1183. /*!
  1184. * @brief Gets the size of the read frame for extended mutli-ring.
  1185. *
  1186. * This function gets a received frame size from the ENET buffer descriptors.
  1187. * @note The FCS of the frame is automatically removed by MAC and the size is the length without the FCS.
  1188. * After calling ENET_GetRxFrameSizeMultiRing, ENET_ReadFrameMultiRing() should be called to update the
  1189. * receive buffers If the result is not "kStatus_ENET_RxFrameEmpty". The usage is
  1190. * the same to the single ring, refer to ENET_GetRxFrameSize.
  1191. *
  1192. * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_Init.
  1193. * @param length The length of the valid frame received.
  1194. * @param ringId The ring index or ring number;
  1195. * @retval kStatus_ENET_RxFrameEmpty No frame received. Should not call ENET_ReadFrameMultiRing to read frame.
  1196. * @retval kStatus_ENET_RxFrameError Data error happens. ENET_ReadFrameMultiRing should be called with NULL data
  1197. * and NULL length to update the receive buffers.
  1198. * @retval kStatus_Success Receive a frame Successfully then the ENET_ReadFrame
  1199. * should be called with the right data buffer and the captured data length input.
  1200. */
  1201. status_t ENET_GetRxFrameSizeMultiRing(enet_handle_t *handle, uint32_t *length, uint32_t ringId);
  1202. /*!
  1203. * @brief Reads a frame from the ENET device for multi-ring.
  1204. *
  1205. * This function reads a frame (both the data and the length) from the ENET buffer descriptors.
  1206. * The ENET_GetRxFrameSizeMultiRing should be used to get the size of the prepared data buffer.
  1207. * This usage is the same as the single ring, refer to ENET_ReadFrame.
  1208. * @param base ENET peripheral base address.
  1209. * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_Init.
  1210. * @param data The data buffer provided by user to store the frame which memory size should be at least "length".
  1211. * @param length The size of the data buffer which is still the length of the received frame.
  1212. * @param ringId The ring index or ring number;
  1213. * @return The execute status, successful or failure.
  1214. */
  1215. status_t ENET_ReadFrameMultiRing(
  1216. ENET_Type *base, enet_handle_t *handle, uint8_t *data, uint32_t length, uint32_t ringId);
  1217. /*!
  1218. * @brief The transmit IRQ handler.
  1219. *
  1220. * @param base ENET peripheral base address.
  1221. * @param handle The ENET handler pointer.
  1222. * @param ringId The ring id or ring number.
  1223. */
  1224. void ENET_TransmitIRQHandler(ENET_Type *base, enet_handle_t *handle, uint32_t ringId);
  1225. /*!
  1226. * @brief The receive IRQ handler.
  1227. *
  1228. * @param base ENET peripheral base address.
  1229. * @param handle The ENET handler pointer.
  1230. * @param ringId The ring id or ring number.
  1231. */
  1232. void ENET_ReceiveIRQHandler(ENET_Type *base, enet_handle_t *handle, uint32_t ringId);
  1233. /*!
  1234. * @brief the common IRQ handler for the tx/rx irq handler.
  1235. *
  1236. * This is used for the combined tx/rx interrupt for multi-ring (frame 1).
  1237. *
  1238. * @param base ENET peripheral base address.
  1239. */
  1240. void ENET_CommonFrame1IRQHandler(ENET_Type *base);
  1241. /*!
  1242. * @brief the common IRQ handler for the tx/rx irq handler.
  1243. *
  1244. * This is used for the combined tx/rx interrupt for multi-ring (frame 2).
  1245. *
  1246. * @param base ENET peripheral base address.
  1247. */
  1248. void ENET_CommonFrame2IRQHandler(ENET_Type *base);
  1249. #else
  1250. /*!
  1251. * @brief The transmit IRQ handler.
  1252. *
  1253. * @param base ENET peripheral base address.
  1254. * @param handle The ENET handler pointer.
  1255. */
  1256. void ENET_TransmitIRQHandler(ENET_Type *base, enet_handle_t *handle);
  1257. /*!
  1258. * @brief The receive IRQ handler.
  1259. *
  1260. * @param base ENET peripheral base address.
  1261. * @param handle The ENET handler pointer.
  1262. */
  1263. void ENET_ReceiveIRQHandler(ENET_Type *base, enet_handle_t *handle);
  1264. #endif /* FSL_FEATURE_ENET_QUEUE > 1 */
  1265. /*!
  1266. * @brief Some special IRQ handler including the error, mii, wakeup irq handler.
  1267. *
  1268. * @param base ENET peripheral base address.
  1269. * @param handle The ENET handler pointer.
  1270. */
  1271. void ENET_ErrorIRQHandler(ENET_Type *base, enet_handle_t *handle);
  1272. /*!
  1273. * @brief the common IRQ handler for the tx/rx/error etc irq handler.
  1274. *
  1275. * This is used for the combined tx/rx/error interrupt for single/mutli-ring (frame 0).
  1276. *
  1277. * @param base ENET peripheral base address.
  1278. */
  1279. void ENET_CommonFrame0IRQHandler(ENET_Type *base);
  1280. /* @} */
  1281. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  1282. /*!
  1283. * @name ENET PTP 1588 function operation
  1284. * @{
  1285. */
  1286. /*!
  1287. * @brief Configures the ENET PTP IEEE 1588 feature with the basic configuration.
  1288. * The function sets the clock for PTP 1588 timer and enables
  1289. * time stamp interrupts and transmit interrupts for PTP 1588 features.
  1290. * This API should be called when the 1588 feature is enabled
  1291. * or the ENET_ENHANCEDBUFFERDESCRIPTOR_MODE is defined.
  1292. * ENET_Init should be called before calling this API.
  1293. *
  1294. * @note The PTP 1588 time-stamp second increase though time-stamp interrupt handler
  1295. * and the transmit time-stamp store is done through transmit interrupt handler.
  1296. * As a result, the TS interrupt and TX interrupt are enabled when you call this API.
  1297. *
  1298. * @param base ENET peripheral base address.
  1299. * @param handle ENET handler pointer.
  1300. * @param ptpConfig The ENET PTP1588 configuration.
  1301. */
  1302. void ENET_Ptp1588Configure(ENET_Type *base, enet_handle_t *handle, enet_ptp_config_t *ptpConfig);
  1303. /*!
  1304. * @brief Starts the ENET PTP 1588 Timer.
  1305. * This function is used to initialize the PTP timer. After the PTP starts,
  1306. * the PTP timer starts running.
  1307. *
  1308. * @param base ENET peripheral base address.
  1309. * @param ptpClkSrc The clock source of the PTP timer.
  1310. */
  1311. void ENET_Ptp1588StartTimer(ENET_Type *base, uint32_t ptpClkSrc);
  1312. /*!
  1313. * @brief Stops the ENET PTP 1588 Timer.
  1314. * This function is used to stops the ENET PTP timer.
  1315. *
  1316. * @param base ENET peripheral base address.
  1317. */
  1318. static inline void ENET_Ptp1588StopTimer(ENET_Type *base)
  1319. {
  1320. /* Disable PTP timer and reset the timer. */
  1321. base->ATCR &= ~ENET_ATCR_EN_MASK;
  1322. base->ATCR |= ENET_ATCR_RESTART_MASK;
  1323. }
  1324. /*!
  1325. * @brief Adjusts the ENET PTP 1588 timer.
  1326. *
  1327. * @param base ENET peripheral base address.
  1328. * @param corrIncrease The correction increment value. This value is added every time the correction
  1329. * timer expires. A value less than the PTP timer frequency(1/ptpClkSrc) slows down the timer,
  1330. * a value greater than the 1/ptpClkSrc speeds up the timer.
  1331. * @param corrPeriod The PTP timer correction counter wrap-around value. This defines after how
  1332. * many timer clock the correction counter should be reset and trigger a correction
  1333. * increment on the timer. A value of 0 disables the correction counter and no correction occurs.
  1334. */
  1335. void ENET_Ptp1588AdjustTimer(ENET_Type *base, uint32_t corrIncrease, uint32_t corrPeriod);
  1336. /*!
  1337. * @brief Sets the ENET PTP 1588 timer channel mode.
  1338. *
  1339. * @param base ENET peripheral base address.
  1340. * @param channel The ENET PTP timer channel number.
  1341. * @param mode The PTP timer channel mode, see "enet_ptp_timer_channel_mode_t".
  1342. * @param intEnable Enables or disables the interrupt.
  1343. */
  1344. static inline void ENET_Ptp1588SetChannelMode(ENET_Type *base,
  1345. enet_ptp_timer_channel_t channel,
  1346. enet_ptp_timer_channel_mode_t mode,
  1347. bool intEnable)
  1348. {
  1349. uint32_t tcrReg = 0;
  1350. tcrReg = ENET_TCSR_TMODE(mode) | (intEnable ? ENET_TCSR_TIE_MASK : 0);
  1351. /* Disable channel mode first. */
  1352. base->CHANNEL[channel].TCSR = 0;
  1353. base->CHANNEL[channel].TCSR = tcrReg;
  1354. }
  1355. #if defined(FSL_FEATURE_ENET_HAS_TIMER_PWCONTROL) && FSL_FEATURE_ENET_HAS_TIMER_PWCONTROL
  1356. /*!
  1357. * @brief Sets ENET PTP 1588 timer channel mode pulse width.
  1358. *
  1359. * For the input "mode" in ENET_Ptp1588SetChannelMode, the kENET_PtpChannelPulseLowonCompare
  1360. * kENET_PtpChannelPulseHighonCompare only support the pulse width for one 1588 clock.
  1361. * this function is extended for control the pulse width from 1 to 32 1588 clock cycles.
  1362. * so call this function if you need to set the timer channel mode for
  1363. * kENET_PtpChannelPulseLowonCompare or kENET_PtpChannelPulseHighonCompare
  1364. * with pulse width more than one 1588 clock,
  1365. *
  1366. * @param base ENET peripheral base address.
  1367. * @param channel The ENET PTP timer channel number.
  1368. * @param isOutputLow True --- timer channel is configured for output compare
  1369. * pulse output low.
  1370. * false --- timer channel is configured for output compare
  1371. * pulse output high.
  1372. * @param pulseWidth The pulse width control value, range from 0 ~ 31.
  1373. * 0 --- pulse width is one 1588 clock cycle.
  1374. * 31 --- pulse width is thirty two 1588 clock cycles.
  1375. * @param intEnable Enables or disables the interrupt.
  1376. */
  1377. static inline void ENET_Ptp1588SetChannelOutputPulseWidth(
  1378. ENET_Type *base, enet_ptp_timer_channel_t channel, bool isOutputLow, uint8_t pulseWidth, bool intEnable)
  1379. {
  1380. uint32_t tcrReg;
  1381. tcrReg = ENET_TCSR_TIE(intEnable) | ENET_TCSR_TPWC(pulseWidth);
  1382. if (isOutputLow)
  1383. {
  1384. tcrReg |= ENET_TCSR_TMODE(kENET_PtpChannelPulseLowonCompare);
  1385. }
  1386. else
  1387. {
  1388. tcrReg |= ENET_TCSR_TMODE(kENET_PtpChannelPulseHighonCompare);
  1389. }
  1390. /* Disable channel mode first. */
  1391. base->CHANNEL[channel].TCSR = 0;
  1392. base->CHANNEL[channel].TCSR = tcrReg;
  1393. }
  1394. #endif /* FSL_FEATURE_ENET_HAS_TIMER_PWCONTROL */
  1395. /*!
  1396. * @brief Sets the ENET PTP 1588 timer channel comparison value.
  1397. *
  1398. * @param base ENET peripheral base address.
  1399. * @param channel The PTP timer channel, see "enet_ptp_timer_channel_t".
  1400. * @param cmpValue The compare value for the compare setting.
  1401. */
  1402. static inline void ENET_Ptp1588SetChannelCmpValue(ENET_Type *base, enet_ptp_timer_channel_t channel, uint32_t cmpValue)
  1403. {
  1404. base->CHANNEL[channel].TCCR = cmpValue;
  1405. }
  1406. /*!
  1407. * @brief Gets the ENET PTP 1588 timer channel status.
  1408. *
  1409. * @param base ENET peripheral base address.
  1410. * @param channel The IEEE 1588 timer channel number.
  1411. * @return True or false, Compare or capture operation status
  1412. */
  1413. static inline bool ENET_Ptp1588GetChannelStatus(ENET_Type *base, enet_ptp_timer_channel_t channel)
  1414. {
  1415. return (0 != (base->CHANNEL[channel].TCSR & ENET_TCSR_TF_MASK));
  1416. }
  1417. /*!
  1418. * @brief Clears the ENET PTP 1588 timer channel status.
  1419. *
  1420. * @param base ENET peripheral base address.
  1421. * @param channel The IEEE 1588 timer channel number.
  1422. */
  1423. static inline void ENET_Ptp1588ClearChannelStatus(ENET_Type *base, enet_ptp_timer_channel_t channel)
  1424. {
  1425. base->CHANNEL[channel].TCSR |= ENET_TCSR_TF_MASK;
  1426. base->TGSR = (1U << channel);
  1427. }
  1428. /*!
  1429. * @brief Gets the current ENET time from the PTP 1588 timer.
  1430. *
  1431. * @param base ENET peripheral base address.
  1432. * @param handle The ENET state pointer. This is the same state pointer used in the ENET_Init.
  1433. * @param ptpTime The PTP timer structure.
  1434. */
  1435. void ENET_Ptp1588GetTimer(ENET_Type *base, enet_handle_t *handle, enet_ptp_time_t *ptpTime);
  1436. /*!
  1437. * @brief Sets the ENET PTP 1588 timer to the assigned time.
  1438. *
  1439. * @param base ENET peripheral base address.
  1440. * @param handle The ENET state pointer. This is the same state pointer used in the ENET_Init.
  1441. * @param ptpTime The timer to be set to the PTP timer.
  1442. */
  1443. void ENET_Ptp1588SetTimer(ENET_Type *base, enet_handle_t *handle, enet_ptp_time_t *ptpTime);
  1444. /*!
  1445. * @brief The IEEE 1588 PTP time stamp interrupt handler.
  1446. *
  1447. * @param base ENET peripheral base address.
  1448. * @param handle The ENET state pointer. This is the same state pointer used in the ENET_Init.
  1449. */
  1450. void ENET_Ptp1588TimerIRQHandler(ENET_Type *base, enet_handle_t *handle);
  1451. /*!
  1452. * @brief Gets the time stamp of the received frame.
  1453. *
  1454. * This function is used for PTP stack to get the timestamp captured by the ENET driver.
  1455. *
  1456. * @param handle The ENET handler pointer.This is the same state pointer used in
  1457. * ENET_Init.
  1458. * @param ptpTimeData The special PTP timestamp data for search the receive timestamp.
  1459. * @retval kStatus_Success Get 1588 timestamp success.
  1460. * @retval kStatus_ENET_PtpTsRingEmpty 1588 timestamp ring empty.
  1461. * @retval kStatus_ENET_PtpTsRingFull 1588 timestamp ring full.
  1462. */
  1463. status_t ENET_GetRxFrameTime(enet_handle_t *handle, enet_ptp_time_data_t *ptpTimeData);
  1464. /*!
  1465. * @brief Gets the time stamp of the transmit frame.
  1466. *
  1467. * This function is used for PTP stack to get the timestamp captured by the ENET driver.
  1468. *
  1469. * @param handle The ENET handler pointer.This is the same state pointer used in
  1470. * ENET_Init.
  1471. * @param ptpTimeData The special PTP timestamp data for search the receive timestamp.
  1472. * @retval kStatus_Success Get 1588 timestamp success.
  1473. * @retval kStatus_ENET_PtpTsRingEmpty 1588 timestamp ring empty.
  1474. * @retval kStatus_ENET_PtpTsRingFull 1588 timestamp ring full.
  1475. */
  1476. status_t ENET_GetTxFrameTime(enet_handle_t *handle, enet_ptp_time_data_t *ptpTimeData);
  1477. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  1478. /* @} */
  1479. #if defined(__cplusplus)
  1480. }
  1481. #endif
  1482. /*! @}*/
  1483. #endif /* _FSL_ENET_H_ */