fsl_enet_qos.h 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  1. /*
  2. * Copyright 2020-2021 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_ENET_QOS_H_
  8. #define _FSL_ENET_QOS_H_
  9. #include "fsl_common.h"
  10. #include "fsl_cache.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_qos_qos
  16. * @{
  17. */
  18. /*******************************************************************************
  19. * Definitions
  20. ******************************************************************************/
  21. /*! @name Driver version */
  22. /*@{*/
  23. /*! @brief Defines the driver version. */
  24. #define FSL_ENET_QOS_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))
  25. /*@}*/
  26. /*! @name Control and status region bit masks of the receive buffer descriptor. */
  27. /*@{*/
  28. /*! @brief Defines for read format. */
  29. #define ENET_QOS_RXDESCRIP_RD_BUFF1VALID_MASK (1UL << 24U) /*!< Buffer1 address valid. */
  30. #define ENET_QOS_RXDESCRIP_RD_BUFF2VALID_MASK (1UL << 25U) /*!< Buffer2 address valid. */
  31. #define ENET_QOS_RXDESCRIP_RD_IOC_MASK (1UL << 30U) /*!< Interrupt enable on complete. */
  32. #define ENET_QOS_RXDESCRIP_RD_OWN_MASK (1UL << 31U) /*!< Own bit. */
  33. /*! @brief Defines for write back format. */
  34. #define ENET_QOS_RXDESCRIP_WR_ERR_MASK ((1UL << 3U) | (1UL << 7U))
  35. #define ENET_QOS_RXDESCRIP_WR_PYLOAD_MASK (0x7UL)
  36. #define ENET_QOS_RXDESCRIP_WR_PTPMSGTYPE_MASK (0xF00UL)
  37. #define ENET_QOS_RXDESCRIP_WR_PTPTYPE_MASK (1UL << 12U)
  38. #define ENET_QOS_RXDESCRIP_WR_PTPVERSION_MASK (1UL << 13U)
  39. #define ENET_QOS_RXDESCRIP_WR_PTPTSA_MASK (1UL << 14U)
  40. #define ENET_QOS_RXDESCRIP_WR_PACKETLEN_MASK (0x7FFFUL)
  41. #define ENET_QOS_RXDESCRIP_WR_ERRSUM_MASK (1UL << 15U)
  42. #define ENET_QOS_RXDESCRIP_WR_TYPE_MASK (0x30000UL)
  43. #define ENET_QOS_RXDESCRIP_WR_DE_MASK (1UL << 19U)
  44. #define ENET_QOS_RXDESCRIP_WR_RE_MASK (1UL << 20U)
  45. #define ENET_QOS_RXDESCRIP_WR_OE_MASK (1UL << 21U)
  46. #define ENET_QOS_RXDESCRIP_WR_RWT_MASK (1UL << 22U)
  47. #define ENET_QOS_RXDESCRIP_WR_GP_MASK (1UL << 22U)
  48. #define ENET_QOS_RXDESCRIP_WR_CRC_MASK (1UL << 23U)
  49. #define ENET_QOS_RXDESCRIP_WR_RS0V_MASK (1UL << 25U)
  50. #define ENET_QOS_RXDESCRIP_WR_RS1V_MASK (1UL << 26U)
  51. #define ENET_QOS_RXDESCRIP_WR_RS2V_MASK (1UL << 27U)
  52. #define ENET_QOS_RXDESCRIP_WR_LD_MASK (1UL << 28U)
  53. #define ENET_QOS_RXDESCRIP_WR_FD_MASK (1UL << 29U)
  54. #define ENET_QOS_RXDESCRIP_WR_CTXT_MASK (1UL << 30U)
  55. #define ENET_QOS_RXDESCRIP_WR_OWN_MASK (1UL << 31U)
  56. #define ENET_QOS_RXDESCRIP_WR_SA_FAILURE_MASK (1UL << 16U)
  57. #define ENET_QOS_RXDESCRIP_WR_DA_FAILURE_MASK (1UL << 17U)
  58. /*@}*/
  59. /*! @name Control and status bit masks of the transmit buffer descriptor. */
  60. /*@{*/
  61. /*! @brief Defines for read format. */
  62. #define ENET_QOS_TXDESCRIP_RD_BL1_MASK (0x3fffUL)
  63. #define ENET_QOS_TXDESCRIP_RD_BL2_MASK (ENET_QOS_TXDESCRIP_RD_BL1_MASK << 16U)
  64. #define ENET_QOS_TXDESCRIP_RD_BL1(n) ((uint32_t)(n)&ENET_QOS_TXDESCRIP_RD_BL1_MASK)
  65. #define ENET_QOS_TXDESCRIP_RD_BL2(n) (((uint32_t)(n)&ENET_QOS_TXDESCRIP_RD_BL1_MASK) << 16)
  66. #define ENET_QOS_TXDESCRIP_RD_TTSE_MASK (1UL << 30UL)
  67. #define ENET_QOS_TXDESCRIP_RD_IOC_MASK (1UL << 31UL)
  68. #define ENET_QOS_TXDESCRIP_RD_FL_MASK (0x7FFFUL)
  69. #define ENET_QOS_TXDESCRIP_RD_FL(n) ((uint32_t)(n)&ENET_QOS_TXDESCRIP_RD_FL_MASK)
  70. #define ENET_QOS_TXDESCRIP_RD_CIC(n) (((uint32_t)(n)&0x3U) << 16U)
  71. #define ENET_QOS_TXDESCRIP_RD_TSE_MASK (1UL << 18U)
  72. #define ENET_QOS_TXDESCRIP_RD_SLOT(n) (((uint32_t)(n)&0x0fU) << 19U)
  73. #define ENET_QOS_TXDESCRIP_RD_SAIC(n) (((uint32_t)(n)&0x07U) << 23U)
  74. #define ENET_QOS_TXDESCRIP_RD_CPC(n) (((uint32_t)(n)&0x03U) << 26U)
  75. #define ENET_QOS_TXDESCRIP_RD_LDFD(n) (((uint32_t)(n)&0x03U) << 28U)
  76. #define ENET_QOS_TXDESCRIP_RD_LD_MASK (1UL << 28U)
  77. #define ENET_QOS_TXDESCRIP_RD_FD_MASK (1UL << 29U)
  78. #define ENET_QOS_TXDESCRIP_RD_CTXT_MASK (1UL << 30U)
  79. #define ENET_QOS_TXDESCRIP_RD_OWN_MASK (1UL << 31U)
  80. /*! @brief Defines for write back format. */
  81. #define ENET_QOS_TXDESCRIP_WB_TTSS_MASK (1UL << 17U)
  82. /*@}*/
  83. /*! @name Bit mask for interrupt enable type. */
  84. /*@{*/
  85. #define ENET_QOS_ABNORM_INT_MASK \
  86. (ENET_QOS_DMA_CHX_INT_EN_TXSE_MASK | ENET_QOS_DMA_CHX_INT_EN_RBUE_MASK | ENET_QOS_DMA_CHX_INT_EN_RSE_MASK | \
  87. ENET_QOS_DMA_CHX_INT_EN_RWTE_MASK | ENET_QOS_DMA_CHX_INT_EN_FBEE_MASK | ENET_QOS_DMA_CHX_INT_EN_ETIE_MASK)
  88. #define ENET_QOS_NORM_INT_MASK \
  89. (ENET_QOS_DMA_CHX_INT_EN_TIE_MASK | ENET_QOS_DMA_CHX_INT_EN_TBUE_MASK | ENET_QOS_DMA_CHX_INT_EN_RIE_MASK | \
  90. ENET_QOS_DMA_CHX_INT_EN_ERIE_MASK)
  91. /*@}*/
  92. /*! @name Defines some Ethernet parameters. */
  93. /*@{*/
  94. #ifndef ENET_QOS_RING_NUM_MAX
  95. #define ENET_QOS_RING_NUM_MAX (5U) /*!< The Maximum number of tx/rx descriptor rings. */
  96. #endif
  97. #define ENET_QOS_FRAME_MAX_FRAMELEN (1518U) /*!< Default maximum Ethernet frame size. */
  98. #define ENET_QOS_FCS_LEN (4U) /*!< Ethernet FCS length. */
  99. #define ENET_QOS_ADDR_ALIGNMENT (0x3U) /*!< Recommended Ethernet buffer alignment. */
  100. #define ENET_QOS_BUFF_ALIGNMENT (8U) /*!< Receive buffer alignment shall be 4bytes-aligned. */
  101. #define ENET_QOS_MTL_RXFIFOSIZE (8192U) /*!< The rx fifo size. */
  102. #define ENET_QOS_MTL_TXFIFOSIZE (8192U) /*!< The tx fifo size. */
  103. #define ENET_QOS_MACINT_ENUM_OFFSET (16U) /*!< The offest for mac interrupt in enum type. */
  104. #define ENET_QOS_RXP_ENTRY_COUNT (256U) /*!< RXP table entry count, implied by FRPES in MAC_HW_FEATURE3 */
  105. #define ENET_QOS_RXP_BUFFER_SIZE (256U) /*!< RXP Buffer size, implied by FRPBS in MAC_HW_FEATURE3 */
  106. #define ENET_QOS_EST_WID (24U) /*!< Width of the time interval in Gate Control List */
  107. #define ENET_QOS_EST_DEP (512U) /*!< Maxmimum depth of Gate Control List */
  108. /*@}*/
  109. /*! @brief Defines the status return codes for transaction. */
  110. enum
  111. {
  112. kStatus_ENET_QOS_InitMemoryFail =
  113. MAKE_STATUS(kStatusGroup_ENET_QOS, 0U), /*!< Init fails since buffer memory is not enough. */
  114. kStatus_ENET_QOS_RxFrameError =
  115. MAKE_STATUS(kStatusGroup_ENET_QOS, 1U), /*!< A frame received but data error happen. */
  116. kStatus_ENET_QOS_RxFrameFail = MAKE_STATUS(kStatusGroup_ENET_QOS, 2U), /*!< Failed to receive a frame. */
  117. kStatus_ENET_QOS_RxFrameEmpty = MAKE_STATUS(kStatusGroup_ENET_QOS, 3U), /*!< No frame arrive. */
  118. kStatus_ENET_QOS_RxFrameDrop =
  119. MAKE_STATUS(kStatusGroup_ENET_QOS, 4U), /*!< Rx frame is dropped since no buffer memory. */
  120. kStatus_ENET_QOS_TxFrameBusy =
  121. MAKE_STATUS(kStatusGroup_ENET_QOS, 5U), /*!< Transmit descriptors are under process. */
  122. kStatus_ENET_QOS_TxFrameFail = MAKE_STATUS(kStatusGroup_ENET_QOS, 6U), /*!< Transmit frame fail. */
  123. kStatus_ENET_QOS_TxFrameOverLen = MAKE_STATUS(kStatusGroup_ENET_QOS, 7U), /*!< Transmit oversize. */
  124. kStatus_ENET_QOS_Est_SwListBusy =
  125. MAKE_STATUS(kStatusGroup_ENET_QOS, 8U), /*!< SW Gcl List not yet processed by HW. */
  126. kStatus_ENET_QOS_Est_SwListWriteAbort = MAKE_STATUS(kStatusGroup_ENET_QOS, 9U), /*!< SW Gcl List write aborted .*/
  127. kStatus_ENET_QOS_Est_InvalidParameter =
  128. MAKE_STATUS(kStatusGroup_ENET_QOS, 10U), /*!< Invalid parameter in Gcl List .*/
  129. kStatus_ENET_QOS_Est_BtrError = MAKE_STATUS(kStatusGroup_ENET_QOS, 11U), /*!< Base Time Error when loading list.*/
  130. kStatus_ENET_QOS_TrgtBusy = MAKE_STATUS(kStatusGroup_ENET_QOS, 12U), /*!< Target time register busy.*/
  131. kStatus_ENET_QOS_Timeout = MAKE_STATUS(kStatusGroup_ENET_QOS, 13U), /*!< Target time register busy.*/
  132. kStatus_ENET_QOS_PpsBusy = MAKE_STATUS(kStatusGroup_ENET_QOS, 14U) /*!< Pps command busy.*/
  133. };
  134. /*! @brief Defines the MII/RGMII mode for data interface between the MAC and the PHY. */
  135. typedef enum _enet_qos_mii_mode
  136. {
  137. kENET_QOS_MiiMode = 0U, /*!< MII mode for data interface. */
  138. kENET_QOS_RgmiiMode = 1U, /*!< RGMII mode for data interface. */
  139. kENET_QOS_RmiiMode = 4U /*!< RMII mode for data interface. */
  140. } enet_qos_mii_mode_t;
  141. /*! @brief Defines the 10/100/1000 Mbps speed for the MII data interface. */
  142. typedef enum _enet_qos_mii_speed
  143. {
  144. kENET_QOS_MiiSpeed10M =
  145. ENET_QOS_MAC_CONFIGURATION_PS(1U) | ENET_QOS_MAC_CONFIGURATION_FES(0U), /*!< Speed 10 Mbps. */
  146. kENET_QOS_MiiSpeed100M =
  147. ENET_QOS_MAC_CONFIGURATION_PS(1U) | ENET_QOS_MAC_CONFIGURATION_FES(1U), /*!< Speed 100 Mbps. */
  148. kENET_QOS_MiiSpeed1000M =
  149. ENET_QOS_MAC_CONFIGURATION_PS(0U) | ENET_QOS_MAC_CONFIGURATION_FES(0U), /*!< Speed 1000 Mbps. */
  150. kENET_QOS_MiiSpeed2500M =
  151. ENET_QOS_MAC_CONFIGURATION_PS(0U) | ENET_QOS_MAC_CONFIGURATION_FES(1U) /*!< Speed 2500 Mbps. */
  152. } enet_qos_mii_speed_t;
  153. /*! @brief Defines the half or full duplex for the MII data interface. */
  154. typedef enum _enet_qos_mii_duplex
  155. {
  156. kENET_QOS_MiiHalfDuplex = 0U, /*!< Half duplex mode. */
  157. kENET_QOS_MiiFullDuplex /*!< Full duplex mode. */
  158. } enet_qos_mii_duplex_t;
  159. /*! @brief Define the MII opcode for normal MDIO_CLAUSES_22 Frame. */
  160. typedef enum _enet_qos_mii_normal_opcode
  161. {
  162. kENET_QOS_MiiWriteFrame =
  163. ENET_QOS_MAC_MDIO_ADDRESS_GOC_1(0U) |
  164. ENET_QOS_MAC_MDIO_ADDRESS_GOC_0(1U), /*!< Write frame operation for a valid MII management frame. */
  165. kENET_QOS_MiiReadFrame =
  166. ENET_QOS_MAC_MDIO_ADDRESS_GOC_1(1U) |
  167. ENET_QOS_MAC_MDIO_ADDRESS_GOC_0(1U) /*!< Read frame operation for a valid MII management frame. */
  168. } enet_qos_mii_normal_opcode;
  169. /*! @brief Define the DMA maximum transmit burst length. */
  170. typedef enum _enet_qos_dma_burstlen
  171. {
  172. kENET_QOS_BurstLen1 = 0x00001U, /*!< DMA burst length 1. */
  173. kENET_QOS_BurstLen2 = 0x00002U, /*!< DMA burst length 2. */
  174. kENET_QOS_BurstLen4 = 0x00004U, /*!< DMA burst length 4. */
  175. kENET_QOS_BurstLen8 = 0x00008U, /*!< DMA burst length 8. */
  176. kENET_QOS_BurstLen16 = 0x00010U, /*!< DMA burst length 16. */
  177. kENET_QOS_BurstLen32 = 0x00020U, /*!< DMA burst length 32. */
  178. kENET_QOS_BurstLen64 = 0x10008U, /*!< DMA burst length 64. eight times enabled. */
  179. kENET_QOS_BurstLen128 = 0x10010U, /*!< DMA burst length 128. eight times enabled. */
  180. kENET_QOS_BurstLen256 = 0x10020U, /*!< DMA burst length 256. eight times enabled. */
  181. } enet_qos_dma_burstlen;
  182. /*! @brief Define the flag for the descriptor. */
  183. typedef enum _enet_qos_desc_flag
  184. {
  185. kENET_QOS_MiddleFlag = 0, /*!< It's a middle descriptor of the frame. */
  186. kENET_QOS_LastFlagOnly, /*!< It's the last descriptor of the frame. */
  187. kENET_QOS_FirstFlagOnly, /*!< It's the first descriptor of the frame. */
  188. kENET_QOS_FirstLastFlag /*!< It's the first and last descriptor of the frame. */
  189. } enet_qos_desc_flag;
  190. /*! @brief Define the system time adjust operation control. */
  191. typedef enum _enet_qos_systime_op
  192. {
  193. kENET_QOS_SystimeAdd = 0U, /*!< System time add to. */
  194. kENET_QOS_SystimeSubtract = 1U /*!< System time subtract. */
  195. } enet_qos_systime_op;
  196. /*! @brief Define the system time rollover control. */
  197. typedef enum _enet_qos_ts_rollover_type
  198. {
  199. kENET_QOS_BinaryRollover = 0, /*!< System time binary rollover.*/
  200. kENET_QOS_DigitalRollover = 1 /*!< System time digital rollover.*/
  201. } enet_qos_ts_rollover_type;
  202. /*! @brief Defines some special configuration for ENET.
  203. *
  204. * These control flags are provided for special user requirements.
  205. * Normally, these is no need to set this control flags for ENET initialization.
  206. * But if you have some special requirements, set the flags to specialControl
  207. * in the enet_qos_config_t.
  208. * @note "kENET_QOS_StoreAndForward" is recommended to be set.
  209. */
  210. typedef enum _enet_qos_special_config
  211. {
  212. /***********************DMA CONFGI**********************************************/
  213. kENET_QOS_DescDoubleBuffer = 0x0001U, /*!< The double buffer is used in the tx/rx descriptor. */
  214. /**************************MTL************************************/
  215. kENET_QOS_StoreAndForward = 0x0002U, /*!< The rx/tx store and forward enable. */
  216. /***********************MAC****************************************/
  217. kENET_QOS_PromiscuousEnable = 0x0004U, /*!< The promiscuous enabled. */
  218. kENET_QOS_FlowControlEnable = 0x0008U, /*!< The flow control enabled. */
  219. kENET_QOS_BroadCastRxDisable = 0x0010U, /*!< The broadcast disabled. */
  220. kENET_QOS_MulticastAllEnable = 0x0020U, /*!< All multicast are passed. */
  221. kENET_QOS_8023AS2KPacket = 0x0040U, /*!< 8023as support for 2K packets. */
  222. kENET_QOS_HashMulticastEnable = 0x0080U /*!< The multicast packets are filtered through hash table. */
  223. } enet_qos_special_config_t;
  224. /*! @brief List of DMA interrupts supported by the ENET interrupt. This
  225. * enumeration uses one-bot encoding to allow a logical OR of multiple
  226. * members.
  227. */
  228. typedef enum _enet_qos_dma_interrupt_enable
  229. {
  230. kENET_QOS_DmaTx = ENET_QOS_DMA_CHX_INT_EN_TIE_MASK, /*!< Tx interrupt. */
  231. kENET_QOS_DmaTxStop = ENET_QOS_DMA_CHX_INT_EN_TXSE_MASK, /*!< Tx stop interrupt. */
  232. kENET_QOS_DmaTxBuffUnavail = ENET_QOS_DMA_CHX_INT_EN_TBUE_MASK, /*!< Tx buffer unavailable. */
  233. kENET_QOS_DmaRx = ENET_QOS_DMA_CHX_INT_EN_RIE_MASK, /*!< Rx interrupt. */
  234. kENET_QOS_DmaRxBuffUnavail = ENET_QOS_DMA_CHX_INT_EN_RBUE_MASK, /*!< Rx buffer unavailable. */
  235. kENET_QOS_DmaRxStop = ENET_QOS_DMA_CHX_INT_EN_RSE_MASK, /*!< Rx stop. */
  236. kENET_QOS_DmaRxWatchdogTimeout = ENET_QOS_DMA_CHX_INT_EN_RWTE_MASK, /*!< Rx watchdog timeout. */
  237. kENET_QOS_DmaEarlyTx = ENET_QOS_DMA_CHX_INT_EN_ETIE_MASK, /*!< Early transmit. */
  238. kENET_QOS_DmaEarlyRx = ENET_QOS_DMA_CHX_INT_EN_ERIE_MASK, /*!< Early receive. */
  239. kENET_QOS_DmaBusErr = ENET_QOS_DMA_CHX_INT_EN_FBEE_MASK, /*!< Fatal bus error. */
  240. } enet_qos_dma_interrupt_enable_t;
  241. /*! @brief List of mac interrupts supported by the ENET interrupt. This
  242. * enumeration uses one-bot encoding to allow a logical OR of multiple
  243. * members.
  244. */
  245. typedef enum _enet_qos_mac_interrupt_enable
  246. {
  247. kENET_QOS_MacPmt = (ENET_QOS_MAC_INTERRUPT_ENABLE_PMTIE_MASK << ENET_QOS_MACINT_ENUM_OFFSET),
  248. kENET_QOS_MacTimestamp = (ENET_QOS_MAC_INTERRUPT_ENABLE_TSIE_MASK << ENET_QOS_MACINT_ENUM_OFFSET),
  249. } enet_qos_mac_interrupt_enable_t;
  250. /*! @brief Defines the common interrupt event for callback use. */
  251. typedef enum _enet_qos_event
  252. {
  253. kENET_QOS_RxIntEvent, /*!< Receive interrupt event. */
  254. kENET_QOS_TxIntEvent, /*!< Transmit interrupt event. */
  255. kENET_QOS_WakeUpIntEvent, /*!< Wake up interrupt event. */
  256. kENET_QOS_TimeStampIntEvent, /*!< Time stamp interrupt event. */
  257. } enet_qos_event_t;
  258. /*! @brief Define the MTL mode for multiple queues/rings. */
  259. typedef enum _enet_qos_queue_mode
  260. {
  261. kENET_QOS_AVB_Mode = 1U, /*!< Enable queue in AVB mode. */
  262. kENET_QOS_DCB_Mode = 2U, /*!< Enable queue in DCB mode. */
  263. } enet_qos_queue_mode_t;
  264. /*! @brief Define the MTL tx scheduling algorithm for multiple queues/rings. */
  265. typedef enum _enet_qos_mtl_multiqueue_txsche
  266. {
  267. kENET_QOS_txWeightRR = 0U, /*!< Tx weight round-robin. */
  268. kENET_QOS_txWeightFQ = 1U, /*!< Tx weight fair queuing. */
  269. kENET_QOS_txDefictWeightRR = 2U, /*!< Tx deficit weighted round-robin. */
  270. kENET_QOS_txStrPrio = 3U, /*!< Tx strict priority. */
  271. } enet_qos_mtl_multiqueue_txsche;
  272. /*! @brief Define the MTL rx scheduling algorithm for multiple queues/rings. */
  273. typedef enum _enet_qos_mtl_multiqueue_rxsche
  274. {
  275. kENET_QOS_rxStrPrio = 0U, /*!< Rx strict priority, Queue 0 has the lowest priority. */
  276. kENET_QOS_rxWeightStrPrio, /*!< Weighted Strict Priority. */
  277. } enet_qos_mtl_multiqueue_rxsche;
  278. /*! @brief Define the MTL rx queue and DMA channel mapping. */
  279. typedef enum _enet_qos_mtl_rxqueuemap
  280. {
  281. kENET_QOS_StaticDirctMap = 0x100U, /*!< The received fame in rx Qn(n = 0,1) directly map to dma channel n. */
  282. kENET_QOS_DynamicMap =
  283. 0x1010U, /*!< The received frame in rx Qn(n = 0,1) map to the dma channel m(m = 0,1) related with the same Mac.
  284. */
  285. } enet_qos_mtl_rxqueuemap_t;
  286. /*! @brief Defines the package type for receive queue routing. */
  287. typedef enum _enet_qos_rx_queue_route
  288. {
  289. kENET_QOS_PacketNoQ = 0x0, /* Not specific queue */
  290. kENET_QOS_PacketAVCPQ = (1U << 0U), /* AV Untagged Control Packets Queue */
  291. kENET_QOS_PacketPTPQ = (1U << 1U), /* PTP Packets Queue */
  292. kENET_QOS_PacketDCBCPQ = (1U << 2U), /* DCB Control Packets Queue */
  293. kENET_QOS_PacketUPQ = (1U << 3U), /* Untagged Packets Queue */
  294. kENET_QOS_PacketMCBCQ = (1U << 4U), /* Multicast & Broadcast Packets Queue */
  295. } enet_qos_rx_queue_route_t;
  296. /*! @brief Defines the ENET PTP message related constant. */
  297. typedef enum _enet_qos_ptp_event_type
  298. {
  299. kENET_QOS_PtpEventMsgType = 3U, /*!< PTP event message type. */
  300. kENET_QOS_PtpSrcPortIdLen = 10U, /*!< PTP message sequence id length. */
  301. kENET_QOS_PtpEventPort = 319U, /*!< PTP event port number. */
  302. kENET_QOS_PtpGnrlPort = 320U /*!< PTP general port number. */
  303. } enet_qos_ptp_event_type_t;
  304. /*! @brief Defines the PPS instance numbers. */
  305. typedef enum _enet_qos_ptp_pps_instance
  306. {
  307. kENET_QOS_PtpPpsIstance0 = 0U, /*!< PPS instance 0. */
  308. kENET_QOS_PtpPpsIstance1, /*!< PPS instance 1. */
  309. kENET_QOS_PtpPpsIstance2, /*!< PPS instance 2. */
  310. kENET_QOS_PtpPpsIstance3 /*!< PPS instance 3. */
  311. } enet_qos_ptp_pps_instance_t;
  312. /*! @brief Defines the Target Time register mode. */
  313. typedef enum _enet_qos_ptp_pps_trgt_mode
  314. {
  315. kENET_QOS_PtpPpsTrgtModeOnlyInt = 0U, /*!< Only interrupts. */
  316. kENET_QOS_PtpPpsTrgtModeIntSt = 2, /*!< Both interrupt and output signal. */
  317. kENET_QOS_PtpPpsTrgtModeOnlySt = 3, /*!< Only output signal. */
  318. } enet_qos_ptp_pps_trgt_mode_t;
  319. /*! @brief Defines commands for ppscmd register. */
  320. typedef enum _enet_qos_ptp_pps_cmd
  321. {
  322. kENET_QOS_PtpPpsCmdNC = 0U, /*!< No Command. */
  323. kENET_QOS_PtpPpsCmdSSP = 1U, /*!< Start Single Pulse. */
  324. kENET_QOS_PtpPpsCmdSPT = 2U, /*!< Start Pulse Train. */
  325. kENET_QOS_PtpPpsCmdCS = 3U, /*!< Cancel Start. */
  326. kENET_QOS_PtpPpsCmdSPTAT = 4U, /*!< Stop Pulse Train At Time. */
  327. kENET_QOS_PtpPpsCmdSPTI = 5U, /*!< Stop Pulse Train Immediately. */
  328. kENET_QOS_PtpPpsCmdCSPT = 6U, /*!< Cancel Stop Pulse Train. */
  329. } enet_qos_ptp_pps_cmd_t;
  330. /*! @brief Defines the enmueration of ETS list length.
  331. */
  332. typedef enum _enet_qos_ets_list_length
  333. {
  334. kENET_QOS_Ets_List_64 = 7U, /*!< List length of 64 */
  335. kENET_QOS_Ets_List_128 = 8U, /*!< List length of 128 */
  336. kENET_QOS_Ets_List_256 = 9U, /*!< List length of 256 */
  337. kENET_QOS_Ets_List_512 = 10U, /*!< List length of 512 */
  338. kENET_QOS_Ets_List_1024 = 11U, /*!< List length of 1024 */
  339. } enet_qos_ets_list_length_t;
  340. /*! @brief Defines the enmueration of ETS gate control address.
  341. */
  342. typedef enum _enet_qos_ets_gccr_addr
  343. {
  344. kENET_QOS_Ets_btr_low = 0U, /*!< BTR Low */
  345. kENET_QOS_Ets_btr_high = 1U, /*!< BTR High */
  346. kENET_QOS_Ets_ctr_low = 2U, /*!< CTR Low */
  347. kENET_QOS_Ets_ctr_high = 3U, /*!< CTR High */
  348. kENET_QOS_Ets_ter = 4U, /*!< TER */
  349. kENET_QOS_Ets_llr = 5U, /*!< LLR */
  350. } enet_qos_ets_gccr_addr_t;
  351. /*! @brief Defines the enmueration of DMA channel used
  352. * for rx parser entry.
  353. */
  354. typedef enum _enet_qos_rxp_dma_chn
  355. {
  356. kENET_QOS_Rxp_DMAChn0 = 1U, /*!< DMA Channel 0 used for RXP entry match */
  357. kENET_QOS_Rxp_DMAChn1 = 2U, /*!< DMA Channel 1 used for RXP entry match */
  358. kENET_QOS_Rxp_DMAChn2 = 4U, /*!< DMA Channel 2 used for RXP entry match */
  359. kENET_QOS_Rxp_DMAChn3 = 8U, /*!< DMA Channel 3 used for RXP entry match */
  360. kENET_QOS_Rxp_DMAChn4 = 16U, /*!< DMA Channel 4 used for RXP entry match */
  361. } enet_qos_rxp_dma_chn_t;
  362. /*! @brief Defines the receive descriptor structure
  363. * has the read-format and write-back format structure. They both
  364. * has the same size with different region definition. so
  365. * we define the read-format region as the receive descriptor structure
  366. * Use the read-format region mask bits in the descriptor initialization
  367. * Use the write-back format region mask bits in the receive data process.
  368. */
  369. typedef struct _enet_qos_rx_bd_struct
  370. {
  371. __IO uint32_t buff1Addr; /*!< Buffer 1 address */
  372. __IO uint32_t reserved; /*!< Reserved */
  373. __IO uint32_t buff2Addr; /*!< Buffer 2 or next descriptor address */
  374. __IO uint32_t control; /*!< Buffer 1/2 byte counts and control */
  375. } enet_qos_rx_bd_struct_t;
  376. /*! @brief Defines the transmit descriptor structure
  377. * has the read-format and write-back format structure. They both
  378. * has the same size with different region definition. so
  379. * we define the read-format region as the transmit descriptor structure
  380. * Use the read-format region mask bits in the descriptor initialization
  381. * Use the write-back format region mask bits in the transmit data process.
  382. */
  383. typedef struct _enet_qos_tx_bd_struct
  384. {
  385. __IO uint32_t buff1Addr; /*!< Buffer 1 address */
  386. __IO uint32_t buff2Addr; /*!< Buffer 2 address */
  387. __IO uint32_t buffLen; /*!< Buffer 1/2 byte counts */
  388. __IO uint32_t controlStat; /*!< TDES control and status word */
  389. } enet_qos_tx_bd_struct_t;
  390. /*! @brief Defines the ENET PTP time stamp structure. */
  391. typedef struct _enet_qos_ptp_time
  392. {
  393. uint64_t second; /*!< Second. */
  394. uint32_t nanosecond; /*!< Nanosecond. */
  395. } enet_qos_ptp_time_t;
  396. /*! @brief Defines the frame info structure. */
  397. typedef struct enet_qos_frame_info
  398. {
  399. void *context; /*!< User specified data, could be buffer address for free */
  400. bool isTsAvail; /*!< Flag indicates timestamp available status */
  401. enet_qos_ptp_time_t timeStamp; /*!< Timestamp of frame */
  402. } enet_qos_frame_info_t;
  403. /*! @brief Defines the ENET transmit dirty addresses ring/queue structure. */
  404. typedef struct _enet_qos_tx_dirty_ring
  405. {
  406. enet_qos_frame_info_t *txDirtyBase; /*!< Dirty buffer descriptor base address pointer. */
  407. uint16_t txGenIdx; /*!< tx generate index. */
  408. uint16_t txConsumIdx; /*!< tx consume index. */
  409. uint16_t txRingLen; /*!< tx ring length. */
  410. bool isFull; /*!< tx ring is full flag, add this parameter to avoid waste one element. */
  411. } enet_qos_tx_dirty_ring_t;
  412. /*! @brief Defines the ENET PTP configuration structure. */
  413. typedef struct _enet_qos_ptp_config
  414. {
  415. bool fineUpdateEnable; /*!< Use the fine update. */
  416. uint32_t defaultAddend; /*!< Default addend value when fine update is enable, could be 2^32 / (refClk_Hz /
  417. ENET_QOS_MICRSECS_ONESECOND / ENET_QOS_SYSTIME_REQUIRED_CLK_MHZ). */
  418. uint32_t systemTimeClock_Hz; /*! The desired system time frequency. Must be lower than reference clock. (Only used
  419. with fine correction method). */
  420. bool ptp1588V2Enable; /*!< ptp 1588 version 2 is used. */
  421. enet_qos_ts_rollover_type tsRollover; /*!< 1588 time nanosecond rollover. */
  422. } enet_qos_ptp_config_t;
  423. /*! @brief Defines the EST gate operation structure. */
  424. typedef struct _enet_qos_est_gate_op
  425. {
  426. uint32_t gate;
  427. uint32_t interval;
  428. } enet_qos_est_gate_op_t;
  429. /*! @brief Defines the EST gate control list structure. */
  430. typedef struct _enet_qos_est_gcl
  431. {
  432. bool enable; /*!< Enable or disable EST */
  433. uint64_t baseTime; /*! Base Time 32 bits seconds 32 bits nanoseconds */
  434. uint64_t cycleTime; /*! Cycle Time 32 bits seconds 32 bits nanoseconds */
  435. uint32_t extTime; /*! Time Extension 32 bits seconds 32 bits nanoseconds */
  436. uint32_t numEntries; /*! Number of entries */
  437. enet_qos_est_gate_op_t *opList; /*! Pointer to GCL list size */
  438. } enet_qos_est_gcl_t;
  439. /*! @brief Defines the ENET_QOS Rx parser configuration structure.*/
  440. typedef struct _enet_qos_rxp_config
  441. {
  442. uint32_t matchData; /*! 4-byte match data used for comparing with incoming packet */
  443. uint32_t matchEnable; /*! When matchEnable is set to 1, the matchData is used for comparing */
  444. uint8_t acceptFrame : 1; /*! When acceptFrame = 1 and data is matched, the frame will be sent to DMA channel */
  445. uint8_t rejectFrame : 1; /*! When rejectFrame = 1 and data is matched, the frame will be dropped */
  446. uint8_t inverseMatch : 1; /*! Inverse match */
  447. uint8_t nextControl : 1; /*! Next instruction indexing control */
  448. uint8_t reserved : 4; /*! Reserved control fields */
  449. uint8_t frameOffset; /*! Frame offset in the packet data to be compared for match, in terms of 4 bytes. */
  450. uint8_t okIndex; /*! Memory Index to be used next. */
  451. uint8_t dmaChannel; /*! The DMA channel enet_qos_rxp_dma_chn_t used for receiving the frame when frame match and
  452. acceptFrame = 1 */
  453. uint32_t reserved2; /*! Reserved for future enhancements */
  454. } enet_qos_rxp_config_t;
  455. /*! @brief Defines the buffer descriptor configure structure.
  456. *
  457. * @note
  458. * 1. The receive and transmit descriptor start address pointer and tail pointer must be word-aligned.
  459. * 2. The recommended minimum tx/rx ring length is 4.
  460. * 3. The tx/rx descriptor tail address shall be the address pointer to the address just after the end
  461. * of the last last descriptor. because only the descriptors between the start address and the
  462. * tail address will be used by DMA.
  463. * 4. The descriptor address is the start address of all used contiguous memory.
  464. * for example, the rxDescStartAddrAlign is the start address of rxRingLen contiguous descriptor memories
  465. * for rx descriptor ring 0.
  466. * 5. The "*rxBufferstartAddr" is the first element of rxRingLen (2*rxRingLen for double buffers)
  467. * rx buffers. It means the *rxBufferStartAddr is the rx buffer for the first descriptor
  468. * the *rxBufferStartAddr + 1 is the rx buffer for the second descriptor or the rx buffer for
  469. * the second buffer in the first descriptor. so please make sure the rxBufferStartAddr is the
  470. * address of a rxRingLen or 2*rxRingLen array.
  471. */
  472. typedef struct _enet_qos_buffer_config
  473. {
  474. uint8_t rxRingLen; /*!< The length of receive buffer descriptor ring. */
  475. uint8_t txRingLen; /*!< The length of transmit buffer descriptor ring. */
  476. enet_qos_tx_bd_struct_t *txDescStartAddrAlign; /*!< Aligned transmit descriptor start address. */
  477. enet_qos_tx_bd_struct_t *txDescTailAddrAlign; /*!< Aligned transmit descriptor tail address. */
  478. enet_qos_frame_info_t *txDirtyStartAddr; /*!< Start address of the dirty tx frame information. */
  479. enet_qos_rx_bd_struct_t *rxDescStartAddrAlign; /*!< Aligned receive descriptor start address. */
  480. enet_qos_rx_bd_struct_t *rxDescTailAddrAlign; /*!< Aligned receive descriptor tail address. */
  481. uint32_t *rxBufferStartAddr; /*!< Start address of the rx buffers. */
  482. uint32_t rxBuffSizeAlign; /*!< Aligned receive data buffer size. */
  483. bool rxBuffNeedMaintain; /*!< Whether receive data buffer need cache maintain. */
  484. } enet_qos_buffer_config_t;
  485. /*! @brief Defines the CBS configuration for queue. */
  486. typedef struct _enet_qos_cbs_config
  487. {
  488. uint16_t sendSlope; /*!< Send slope configuration. */
  489. uint16_t idleSlope; /*!< Idle slope configuration. */
  490. uint32_t highCredit; /*!< High credit. */
  491. uint32_t lowCredit; /*!< Low credit. */
  492. } enet_qos_cbs_config_t;
  493. /*! @brief Defines the queue configuration structure. */
  494. typedef struct enet_qos_tx_queue_config
  495. {
  496. enet_qos_queue_mode_t mode; /*!< tx queue mode configuration. */
  497. uint32_t weight; /*!< Refer to the MTL TxQ Quantum Weight register. */
  498. uint32_t priority; /*!< Refer to Transmit Queue Priority Mapping register. */
  499. enet_qos_cbs_config_t *cbsConfig; /*!< CBS configuration if queue use AVB mode. */
  500. } enet_qos_queue_tx_config_t;
  501. /*! @brief Defines the queue configuration structure. */
  502. typedef struct enet_qos_rx_queue_config
  503. {
  504. enet_qos_queue_mode_t mode; /*!< rx queue mode configuration. */
  505. uint8_t mapChannel; /*!< tx queue map dma channel. */
  506. uint32_t priority; /*!< Rx queue priority. */
  507. enet_qos_rx_queue_route_t packetRoute; /*!< Receive packet routing. */
  508. } enet_qos_queue_rx_config_t;
  509. /*! @brief Defines the configuration when multi-queue is used. */
  510. typedef struct enet_qos_multiqueue_config
  511. {
  512. enet_qos_dma_burstlen burstLen; /*!< Burst len for the multi-queue. */
  513. uint8_t txQueueUse; /*!< Used Tx queue count. */
  514. enet_qos_mtl_multiqueue_txsche mtltxSche; /*!< Transmit schedule for multi-queue. */
  515. enet_qos_queue_tx_config_t txQueueConfig[ENET_QOS_RING_NUM_MAX]; /*!< Tx Queue configuration. */
  516. uint8_t rxQueueUse; /*!< Used Rx queue count. */
  517. enet_qos_mtl_multiqueue_rxsche mtlrxSche; /*!< Receive schedule for multi-queue. */
  518. enet_qos_queue_rx_config_t rxQueueConfig[ENET_QOS_RING_NUM_MAX]; /*!< Rx Queue configuration. */
  519. } enet_qos_multiqueue_config_t;
  520. /*! @brief Defines the Rx memory buffer alloc function pointer. */
  521. typedef void *(*enet_qos_rx_alloc_callback_t)(ENET_QOS_Type *base, void *userData, uint8_t channel);
  522. /*! @brief Defines the Rx memory buffer free function pointer. */
  523. typedef void (*enet_qos_rx_free_callback_t)(ENET_QOS_Type *base, void *buffer, void *userData, uint8_t channel);
  524. /*! @brief Defines the basic configuration structure for the ENET device.
  525. *
  526. * @note Default the signal queue is used so the "*multiqueueCfg" is set default
  527. * with NULL. Set the pointer with a valid configuration pointer if the multiple
  528. * queues are required. If multiple queue is enabled, please make sure the
  529. * buffer configuration for all are prepared also.
  530. */
  531. typedef struct _enet_qos_config
  532. {
  533. uint16_t specialControl; /*!< The logic or of enet_qos_special_config_t */
  534. enet_qos_multiqueue_config_t *multiqueueCfg; /*!< Use multi-queue. */
  535. /* -----------------MAC block-------------------------------*/
  536. enet_qos_mii_mode_t miiMode; /*!< MII mode. */
  537. enet_qos_mii_speed_t miiSpeed; /*!< MII Speed. */
  538. enet_qos_mii_duplex_t miiDuplex; /*!< MII duplex. */
  539. uint16_t
  540. pauseDuration; /*!< Used in the tx flow control frame, only valid when kENET_QOS_FlowControlEnable is set. */
  541. /* -----------------Timestamp -------------------------------*/
  542. enet_qos_ptp_config_t *ptpConfig; /*!< PTP 1588 feature configuration */
  543. uint32_t csrClock_Hz; /*!< CSR clock frequency in HZ. */
  544. enet_qos_rx_alloc_callback_t rxBuffAlloc; /*!< Callback to alloc memory, must be provided for zero-copy Rx. */
  545. enet_qos_rx_free_callback_t rxBuffFree; /*!< Callback to free memory, must be provided for zero-copy Rx. */
  546. } enet_qos_config_t;
  547. /* Forward declaration of the handle typedef. */
  548. typedef struct _enet_qos_handle enet_qos_handle_t;
  549. /*! @brief ENET callback function. */
  550. typedef void (*enet_qos_callback_t)(
  551. ENET_QOS_Type *base, enet_qos_handle_t *handle, enet_qos_event_t event, uint8_t channel, void *userData);
  552. /*! @brief Defines the ENET transmit buffer descriptor ring/queue structure. */
  553. typedef struct _enet_qos_tx_bd_ring
  554. {
  555. enet_qos_tx_bd_struct_t *txBdBase; /*!< Buffer descriptor base address pointer. */
  556. uint16_t txGenIdx; /*!< tx generate index. */
  557. uint16_t txConsumIdx; /*!< tx consume index. */
  558. volatile uint16_t txDescUsed; /*!< tx descriptor used number. */
  559. uint16_t txRingLen; /*!< tx ring length. */
  560. } enet_qos_tx_bd_ring_t;
  561. /*! @brief Defines the ENET receive buffer descriptor ring/queue structure. */
  562. typedef struct _enet_qos_rx_bd_ring
  563. {
  564. enet_qos_rx_bd_struct_t *rxBdBase; /*!< Buffer descriptor base address pointer. */
  565. uint16_t rxGenIdx; /*!< The current available receive buffer descriptor pointer. */
  566. uint16_t rxRingLen; /*!< Receive ring length. */
  567. uint32_t rxBuffSizeAlign; /*!< Receive buffer size. */
  568. } enet_qos_rx_bd_ring_t;
  569. /*! @brief Defines the ENET handler structure. */
  570. struct _enet_qos_handle
  571. {
  572. uint8_t txQueueUse; /*!< Used tx queue count. */
  573. uint8_t rxQueueUse; /*!< Used rx queue count. */
  574. bool doubleBuffEnable; /*!< The double buffer is used in the descriptor. */
  575. bool rxintEnable; /*!< Rx interrupt enabled. */
  576. bool rxMaintainEnable[ENET_QOS_RING_NUM_MAX]; /*!< Rx buffer cache maintain enabled. */
  577. enet_qos_rx_bd_ring_t rxBdRing[ENET_QOS_RING_NUM_MAX]; /*!< Receive buffer descriptor. */
  578. enet_qos_tx_bd_ring_t txBdRing[ENET_QOS_RING_NUM_MAX]; /*!< Transmit buffer descriptor. */
  579. enet_qos_tx_dirty_ring_t txDirtyRing[ENET_QOS_RING_NUM_MAX]; /*!< Transmit dirty buffers addresses. */
  580. uint32_t *rxBufferStartAddr[ENET_QOS_RING_NUM_MAX]; /*!< Rx buffer start address for reInitialize. */
  581. enet_qos_callback_t callback; /*!< Callback function. */
  582. void *userData; /*!< Callback function parameter.*/
  583. uint8_t multicastCount[64]; /*!< Multicast collisions counter */
  584. enet_qos_rx_alloc_callback_t rxBuffAlloc; /*!< Callback to alloc memory, must be provided for zero-copy Rx. */
  585. enet_qos_rx_free_callback_t rxBuffFree; /*!< Callback to free memory, must be provided for zero-copy Rx. */
  586. };
  587. /*! @brief Defines the frame buffer structure. */
  588. typedef struct _enet_qos_buffer_struct
  589. {
  590. void *buffer; /*!< The buffer store the whole or partial frame. */
  591. uint16_t length; /*!< The byte length of this buffer. */
  592. } enet_qos_buffer_struct_t;
  593. /*! @brief Defines the Rx frame error structure. */
  594. typedef struct _enet_qos_rx_frame_error
  595. {
  596. bool rxDstAddrFilterErr : 1; /*!< Destination Address Filter Fail. */
  597. bool rxSrcAddrFilterErr : 1; /*!< SA Address Filter Fail. */
  598. bool rxDribbleErr : 1; /*!< Dribble error. */
  599. bool rxReceiveErr : 1; /*!< Receive error. */
  600. bool rxOverFlowErr : 1; /*!< Receive over flow. */
  601. bool rxWatchDogErr : 1; /*!< Watch dog timeout. */
  602. bool rxGaintPacketErr : 1; /*!< Receive gaint packet. */
  603. bool rxCrcErr : 1; /*!< Receive CRC error. */
  604. } enet_qos_rx_frame_error_t;
  605. typedef struct _enet_qos_rx_frame_attribute_struct
  606. {
  607. bool isTsAvail; /*!< Rx frame timestamp is available or not. */
  608. enet_qos_ptp_time_t timestamp; /*!< The nanosecond part timestamp of this Rx frame. */
  609. } enet_qos_rx_frame_attribute_t;
  610. /*! @brief Defines the Rx frame data structure. */
  611. typedef struct _enet_qos_rx_frame_struct
  612. {
  613. enet_qos_buffer_struct_t *rxBuffArray; /*!< Rx frame buffer structure. */
  614. uint16_t totLen; /*!< Rx frame total length. */
  615. enet_qos_rx_frame_attribute_t rxAttribute; /*!< Rx frame attribute structure. */
  616. enet_qos_rx_frame_error_t rxFrameError; /*!< Rx frame error. */
  617. } enet_qos_rx_frame_struct_t;
  618. /*! @brief Defines the ENET QOS transfer statistics structure. */
  619. typedef struct _enet_qos_transfer_stats
  620. {
  621. uint32_t statsRxFrameCount; /*!< Rx frame number. */
  622. uint32_t statsRxCrcErr; /*!< Rx frame number with CRC error. */
  623. uint32_t statsRxAlignErr; /*!< Rx frame number with alignment error. */
  624. uint32_t statsRxLengthErr; /*!< Rx frame length field doesn't equal to packet size. */
  625. uint32_t statsRxFifoOverflowErr; /*!< Rx FIFO overflow count. */
  626. uint32_t statsTxFrameCount; /*!< Tx frame number. */
  627. uint32_t statsTxFifoUnderRunErr; /*!< Tx FIFO underrun count. */
  628. } enet_qos_transfer_stats_t;
  629. /* Typedef for interrupt handler. */
  630. typedef void (*enet_qos_isr_t)(ENET_QOS_Type *base, enet_qos_handle_t *handle);
  631. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  632. /*! @brief Pointers to enet clocks for each instance. */
  633. extern const clock_ip_name_t s_enetqosClock[];
  634. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  635. /*!
  636. * @brief Set ENET system configuration.
  637. * @note User needs to provide the implementation because the implementation is SoC specific.
  638. * This function set the phy selection and enable clock.
  639. * It should be called before any other ethernet operation.
  640. *
  641. * @param miiMode The MII/RGMII/RMII mode for interface between the phy and Ethernet.
  642. */
  643. extern void ENET_QOS_SetSYSControl(enet_qos_mii_mode_t miiMode);
  644. /*******************************************************************************
  645. * API
  646. ******************************************************************************/
  647. #if defined(__cplusplus)
  648. extern "C" {
  649. #endif
  650. /*!
  651. * @name Initialization and De-initialization
  652. * @{
  653. */
  654. /*!
  655. * @brief Gets the ENET default configuration structure.
  656. *
  657. * The purpose of this API is to get the default ENET configure
  658. * structure for @ref ENET_QOS_Init(). User may use the initialized
  659. * structure unchanged in @ref ENET_QOS_Init(), or modify some fields of the
  660. * structure before calling @ref ENET_QOS_Init().
  661. * Example:
  662. @code
  663. enet_qos_config_t config;
  664. ENET_QOS_GetDefaultConfig(&config);
  665. @endcode
  666. * @param config The ENET mac controller configuration structure pointer.
  667. */
  668. void ENET_QOS_GetDefaultConfig(enet_qos_config_t *config);
  669. /*!
  670. * @brief Initializes the ENET module.
  671. *
  672. * This function initializes it with the ENET basic
  673. * configuration.
  674. *
  675. * @param base ENET peripheral base address.
  676. * @param config ENET mac configuration structure pointer.
  677. * The "enet_qos_config_t" type mac configuration return from ENET_QOS_GetDefaultConfig
  678. * can be used directly. It is also possible to verify the Mac configuration using other methods.
  679. * @param macAddr Pointer to ENET mac address array of Ethernet device. This MAC address should be
  680. * provided.
  681. * @param macCount Count of macAddr in the ENET mac address array
  682. * @param refclkSrc_Hz ENET input reference clock.
  683. */
  684. status_t ENET_QOS_Up(
  685. ENET_QOS_Type *base, const enet_qos_config_t *config, uint8_t *macAddr, uint8_t macCount, uint32_t refclkSrc_Hz);
  686. /*!
  687. * @brief Initializes the ENET module.
  688. *
  689. * This function ungates the module clock and initializes it with the ENET basic
  690. * configuration.
  691. *
  692. * @param base ENET peripheral base address.
  693. * @param config ENET mac configuration structure pointer.
  694. * The "enet_qos_config_t" type mac configuration return from ENET_QOS_GetDefaultConfig
  695. * can be used directly. It is also possible to verify the Mac configuration using other methods.
  696. * @param macAddr Pointer to ENET mac address array of Ethernet device. This MAC address should be
  697. * provided.
  698. * @param macCount Count of macAddr in the ENET mac address array
  699. * @param refclkSrc_Hz ENET input reference clock.
  700. */
  701. status_t ENET_QOS_Init(
  702. ENET_QOS_Type *base, const enet_qos_config_t *config, uint8_t *macAddr, uint8_t macCount, uint32_t refclkSrc_Hz);
  703. /*!
  704. * @brief Stops the ENET module.
  705. * This function disables the ENET module.
  706. *
  707. * @param base ENET peripheral base address.
  708. */
  709. void ENET_QOS_Down(ENET_QOS_Type *base);
  710. /*!
  711. * @brief Deinitializes the ENET module.
  712. * This function gates the module clock and disables the ENET module.
  713. *
  714. * @param base ENET peripheral base address.
  715. */
  716. void ENET_QOS_Deinit(ENET_QOS_Type *base);
  717. /*!
  718. * @brief Get the ENET instance from peripheral base address.
  719. *
  720. * @param base ENET peripheral base address.
  721. * @return ENET instance.
  722. */
  723. uint32_t ENET_QOS_GetInstance(ENET_QOS_Type *base);
  724. /*!
  725. * @brief Initialize for all ENET descriptors.
  726. *
  727. * @note This function is do all tx/rx descriptors initialization. Because this API
  728. * read all interrupt registers first and then set the interrupt flag for all descriptors,
  729. * if the interrupt register is set. so the descriptor initialization should be called
  730. * after ENET_QOS_Init(), ENET_QOS_EnableInterrupts() and ENET_QOS_CreateHandle()(if transactional APIs
  731. * are used).
  732. *
  733. * @param base ENET peripheral base address.
  734. * @param config The configuration for ENET.
  735. * @param bufferConfig All buffers configuration.
  736. */
  737. status_t ENET_QOS_DescriptorInit(ENET_QOS_Type *base,
  738. enet_qos_config_t *config,
  739. enet_qos_buffer_config_t *bufferConfig);
  740. /*!
  741. * @brief Allocates Rx buffers for all BDs.
  742. * It's used for zero copy Rx. In zero copy Rx case, Rx buffers are dynamic. This function
  743. * will populate initial buffers in all BDs for receiving. Then ENET_QOS_GetRxFrame() is used
  744. * to get Rx frame with zero copy, it will allocate new buffer to replace the buffer in BD taken
  745. * by application application should free those buffers after they're used.
  746. *
  747. * @note This function should be called after ENET_QOS_CreateHandler() and buffer allocating callback
  748. * function should be ready.
  749. *
  750. * @param base ENET_QOS peripheral base address.
  751. * @param handle The ENET_QOS handler structure. This is the same handler pointer used in the ENET_QOS_Init.
  752. */
  753. status_t ENET_QOS_RxBufferAllocAll(ENET_QOS_Type *base, enet_qos_handle_t *handle);
  754. /*!
  755. * @brief Frees Rx buffers in all BDs.
  756. * It's used for zero copy Rx. In zero copy Rx case, Rx buffers are dynamic. This function
  757. * will free left buffers in all BDs.
  758. *
  759. * @param base ENET_QOS peripheral base address.
  760. * @param handle The ENET_QOS handler structure. This is the same handler pointer used in the ENET_QOS_Init.
  761. */
  762. void ENET_QOS_RxBufferFreeAll(ENET_QOS_Type *base, enet_qos_handle_t *handle);
  763. /*!
  764. * @brief Starts the ENET rx/tx.
  765. * This function enable the tx/rx and starts the rx/tx DMA.
  766. * This shall be set after ENET initialization and before
  767. * starting to receive the data.
  768. *
  769. * @param base ENET peripheral base address.
  770. * @param rxRingNum The number of the used rx rings. It shall not be
  771. * larger than the ENET_QOS_RING_NUM_MAX(2). If the ringNum is set with
  772. * 1, the ring 0 will be used.
  773. * @param txRingNum The number of the used tx rings. It shall not be
  774. * larger than the ENET_QOS_RING_NUM_MAX(2). If the ringNum is set with
  775. * 1, the ring 0 will be used.
  776. *
  777. * @note This must be called after all the ENET initialization.
  778. * And should be called when the ENET receive/transmit is required.
  779. */
  780. void ENET_QOS_StartRxTx(ENET_QOS_Type *base, uint8_t txRingNum, uint8_t rxRingNum);
  781. /* @} */
  782. /*!
  783. * @name MII interface operation
  784. * @{
  785. */
  786. /*!
  787. * @brief Sets the ENET MII speed and duplex.
  788. *
  789. * This API is provided to dynamically change the speed and duplex for MAC.
  790. *
  791. * @param base ENET peripheral base address.
  792. * @param speed The speed of the RMII mode.
  793. * @param duplex The duplex of the RMII mode.
  794. */
  795. static inline void ENET_QOS_SetMII(ENET_QOS_Type *base, enet_qos_mii_speed_t speed, enet_qos_mii_duplex_t duplex)
  796. {
  797. uint32_t reg = base->MAC_CONFIGURATION & ~(ENET_QOS_MAC_CONFIGURATION_DM_MASK | ENET_QOS_MAC_CONFIGURATION_PS_MASK |
  798. ENET_QOS_MAC_CONFIGURATION_FES_MASK);
  799. reg |= ENET_QOS_MAC_CONFIGURATION_DM(duplex) | (uint32_t)speed;
  800. base->MAC_CONFIGURATION = reg;
  801. }
  802. /*!
  803. * @brief Sets the ENET SMI(serial management interface)- MII management interface.
  804. *
  805. * @param base ENET peripheral base address.
  806. * @param csrClock_Hz CSR clock frequency in HZ
  807. */
  808. void ENET_QOS_SetSMI(ENET_QOS_Type *base, uint32_t csrClock_Hz);
  809. /*!
  810. * @brief Checks if the SMI is busy.
  811. *
  812. * @param base ENET peripheral base address.
  813. * @return The status of MII Busy status.
  814. */
  815. static inline bool ENET_QOS_IsSMIBusy(ENET_QOS_Type *base)
  816. {
  817. return ((base->MAC_MDIO_ADDRESS & ENET_QOS_MAC_MDIO_ADDRESS_GB_MASK) != 0U) ? true : false;
  818. }
  819. /*!
  820. * @brief Reads data from the PHY register through SMI interface.
  821. *
  822. * @param base ENET peripheral base address.
  823. * @return The data read from PHY
  824. */
  825. static inline uint16_t ENET_QOS_ReadSMIData(ENET_QOS_Type *base)
  826. {
  827. return (uint16_t)(base->MAC_MDIO_DATA & ENET_QOS_MAC_MDIO_DATA_GD_MASK);
  828. }
  829. /*!
  830. * @brief Starts an SMI read command.
  831. * It supports MDIO IEEE802.3 Clause 22.
  832. * After send command, user needs to check whether the transmission is over
  833. * with ENET_QOS_IsSMIBusy().
  834. *
  835. * @param base ENET peripheral base address.
  836. * @param phyAddr The PHY address.
  837. * @param phyReg The PHY register.
  838. */
  839. void ENET_QOS_StartSMIRead(ENET_QOS_Type *base, uint32_t phyAddr, uint32_t phyReg);
  840. /*!
  841. * @brief Starts a SMI write command.
  842. * It supports MDIO IEEE802.3 Clause 22.
  843. * After send command, user needs to check whether the transmission is over
  844. * with ENET_QOS_IsSMIBusy().
  845. *
  846. * @param base ENET peripheral base address.
  847. * @param phyAddr The PHY address.
  848. * @param phyReg The PHY register.
  849. * @param data The data written to PHY.
  850. */
  851. void ENET_QOS_StartSMIWrite(ENET_QOS_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t data);
  852. /*!
  853. * @brief Starts a SMI write command.
  854. * It supports MDIO IEEE802.3 Clause 45.
  855. * After send command, user needs to check whether the transmission is over
  856. * with ENET_QOS_IsSMIBusy().
  857. *
  858. * @param base ENET peripheral base address.
  859. * @param phyAddr The PHY address.
  860. * @param device The PHY device type.
  861. * @param phyReg The PHY register address.
  862. * @param data The data written to PHY.
  863. */
  864. void ENET_QOS_StartExtC45SMIWrite(
  865. ENET_QOS_Type *base, uint32_t phyAddr, uint32_t device, uint32_t phyReg, uint32_t data);
  866. /*!
  867. * @brief Starts a SMI read command.
  868. * It supports MDIO IEEE802.3 Clause 45.
  869. * After send command, user needs to check whether the transmission is over
  870. * with ENET_QOS_IsSMIBusy().
  871. *
  872. * @param base ENET peripheral base address.
  873. * @param phyAddr The PHY address.
  874. * @param device The PHY device type.
  875. * @param phyReg The PHY register address.
  876. */
  877. void ENET_QOS_StartExtC45SMIRead(ENET_QOS_Type *base, uint32_t phyAddr, uint32_t device, uint32_t phyReg);
  878. /* @} */
  879. /*!
  880. * @name Other basic operation
  881. * @{
  882. */
  883. /*!
  884. * @brief Sets the ENET module Mac address.
  885. *
  886. * @param base ENET peripheral base address.
  887. * @param macAddr The six-byte Mac address pointer.
  888. * The pointer is allocated by application and input into the API.
  889. * @param index Configure macAddr to MAC_ADDRESS[index] register.
  890. */
  891. static inline void ENET_QOS_SetMacAddr(ENET_QOS_Type *base, uint8_t *macAddr, uint8_t index)
  892. {
  893. uint32_t lowAddress;
  894. uint32_t highAddress;
  895. assert(macAddr != NULL);
  896. lowAddress = ((uint32_t)macAddr[3] << 24U) | ((uint32_t)macAddr[2] << 16U) | ((uint32_t)macAddr[1] << 8U) |
  897. ((uint32_t)macAddr[0]);
  898. highAddress = ((uint32_t)macAddr[5] << 8U) | ((uint32_t)macAddr[4]);
  899. /* Set Macaddr, the MAC address registers are configured to be double-synchronized to the MII clock
  900. domains, then the synchronization is triggered only when bits 31:24 (in little-endian mode)
  901. or bits 7:0 (in Big-Endian mode) of the MAC address low register are written to.*/
  902. base->MAC_ADDRESS[index].HIGH = highAddress | ENET_QOS_HIGH_AE_MASK;
  903. base->MAC_ADDRESS[index].LOW = lowAddress;
  904. }
  905. /*!
  906. * @brief Gets the ENET module Mac address.
  907. *
  908. * @param base ENET peripheral base address.
  909. * @param macAddr The six-byte Mac address pointer.
  910. * The pointer is allocated by application and input into the API.
  911. * @param index Get macAddr from MAC_ADDRESS[index] register.
  912. */
  913. void ENET_QOS_GetMacAddr(ENET_QOS_Type *base, uint8_t *macAddr, uint8_t index);
  914. /*!
  915. * @brief Adds the ENET_QOS device to a multicast group.
  916. *
  917. * @param base ENET_QOS peripheral base address.
  918. * @param address The six-byte multicast group address which is provided by application.
  919. */
  920. void ENET_QOS_AddMulticastGroup(ENET_QOS_Type *base, uint8_t *address);
  921. /*!
  922. * @brief Moves the ENET_QOS device from a multicast group.
  923. *
  924. * @param base ENET_QOS peripheral base address.
  925. * @param address The six-byte multicast group address which is provided by application.
  926. */
  927. void ENET_QOS_LeaveMulticastGroup(ENET_QOS_Type *base, uint8_t *address);
  928. /*!
  929. * @brief Enable ENET device to accept all multicast frames.
  930. *
  931. * @param base ENET peripheral base address.
  932. */
  933. static inline void ENET_QOS_AcceptAllMulticast(ENET_QOS_Type *base)
  934. {
  935. uint32_t reg = base->MAC_PACKET_FILTER;
  936. base->MAC_PACKET_FILTER = reg | ENET_QOS_MAC_PACKET_FILTER_PM_MASK;
  937. }
  938. /*!
  939. * @brief ENET device reject to accept all multicast frames.
  940. *
  941. * @param base ENET peripheral base address.
  942. */
  943. static inline void ENET_QOS_RejectAllMulticast(ENET_QOS_Type *base)
  944. {
  945. uint32_t reg = base->MAC_PACKET_FILTER;
  946. base->MAC_PACKET_FILTER = reg & ~ENET_QOS_MAC_PACKET_FILTER_PM_MASK;
  947. }
  948. /*!
  949. * @brief Set the MAC to enter into power down mode.
  950. * the remote power wake up frame and magic frame can wake up
  951. * the ENET from the power down mode.
  952. *
  953. * @param base ENET peripheral base address.
  954. * @param wakeFilter The wakeFilter provided to configure the wake up frame filter.
  955. * Set the wakeFilter to NULL is not required. But if you have the filter requirement,
  956. * please make sure the wakeFilter pointer shall be eight continuous
  957. * 32-bits configuration.
  958. */
  959. void ENET_QOS_EnterPowerDown(ENET_QOS_Type *base, uint32_t *wakeFilter);
  960. /*!
  961. * @brief Set the MAC to exit power down mode.
  962. * Exit from the power down mode and recover to normal work mode.
  963. *
  964. * @param base ENET peripheral base address.
  965. */
  966. static inline void ENET_QOS_ExitPowerDown(ENET_QOS_Type *base)
  967. {
  968. /* Clear and status ans reset the power down. */
  969. base->MAC_PMT_CONTROL_STATUS &= ~ENET_QOS_MAC_PMT_CONTROL_STATUS_PWRDWN_MASK;
  970. /* Restore the tx which is disabled when enter power down mode. */
  971. base->DMA_CH[0].DMA_CHX_TX_CTRL |= ENET_QOS_DMA_CHX_TX_CTRL_ST_MASK;
  972. base->DMA_CH[1].DMA_CHX_TX_CTRL |= ENET_QOS_DMA_CHX_TX_CTRL_ST_MASK;
  973. base->MAC_CONFIGURATION |= ENET_QOS_MAC_CONFIGURATION_TE_MASK;
  974. }
  975. /*!
  976. * @brief Enable/Disable Rx parser,please notice that for enable/disable Rx Parser,
  977. * should better disable Receive first.
  978. *
  979. * @param base ENET_QOS peripheral base address.
  980. * @param enable Enable/Disable Rx parser function
  981. * @retval kStatus_Success Configure rx parser success.
  982. * @retval kStatus_ENET_QOS_Timeout Poll status flag timeout.
  983. */
  984. status_t ENET_QOS_EnableRxParser(ENET_QOS_Type *base, bool enable);
  985. /* @} */
  986. /*!
  987. * @name Interrupts.
  988. * @{
  989. */
  990. /*!
  991. * @brief Enables the ENET DMA and MAC interrupts.
  992. *
  993. * This function enables the ENET interrupt according to the provided mask. The mask
  994. * is a logical OR of enet_qos_dma_interrupt_enable_t and enet_qos_mac_interrupt_enable_t.
  995. * For example, to enable the dma and mac interrupt, do the following.
  996. * @code
  997. * ENET_QOS_EnableInterrupts(ENET, kENET_QOS_DmaRx | kENET_QOS_DmaTx | kENET_QOS_MacPmt);
  998. * @endcode
  999. *
  1000. * @param base ENET peripheral base address.
  1001. * @param mask ENET interrupts to enable. This is a logical OR of both
  1002. * enumeration :: enet_qos_dma_interrupt_enable_t and enet_qos_mac_interrupt_enable_t.
  1003. */
  1004. void ENET_QOS_EnableInterrupts(ENET_QOS_Type *base, uint32_t mask);
  1005. /*!
  1006. * @brief Disables the ENET DMA and MAC interrupts.
  1007. *
  1008. * This function disables the ENET interrupt according to the provided mask. The mask
  1009. * is a logical OR of enet_qos_dma_interrupt_enable_t and enet_qos_mac_interrupt_enable_t.
  1010. * For example, to disable the dma and mac interrupt, do the following.
  1011. * @code
  1012. * ENET_QOS_DisableInterrupts(ENET, kENET_QOS_DmaRx | kENET_QOS_DmaTx | kENET_QOS_MacPmt);
  1013. * @endcode
  1014. *
  1015. * @param base ENET peripheral base address.
  1016. * @param mask ENET interrupts to disables. This is a logical OR of both
  1017. * enumeration :: enet_qos_dma_interrupt_enable_t and enet_qos_mac_interrupt_enable_t.
  1018. */
  1019. void ENET_QOS_DisableInterrupts(ENET_QOS_Type *base, uint32_t mask);
  1020. /*!
  1021. * @brief Gets the ENET DMA interrupt status flag.
  1022. *
  1023. * @param base ENET peripheral base address.
  1024. * @param channel The DMA Channel. Shall not be larger than ENET_QOS_RING_NUM_MAX.
  1025. * @return The event status of the interrupt source. This is the logical OR of members
  1026. * of the enumeration :: enet_qos_dma_interrupt_enable_t.
  1027. */
  1028. static inline uint32_t ENET_QOS_GetDmaInterruptStatus(ENET_QOS_Type *base, uint8_t channel)
  1029. {
  1030. return base->DMA_CH[channel].DMA_CHX_STAT;
  1031. }
  1032. /*!
  1033. * @brief Clear the ENET DMA interrupt status flag.
  1034. *
  1035. * @param base ENET peripheral base address.
  1036. * @param channel The DMA Channel. Shall not be larger than ENET_QOS_RING_NUM_MAX.
  1037. * @param mask The interrupt status to be cleared. This is the logical OR of members
  1038. * of the enumeration :: enet_qos_dma_interrupt_enable_t.
  1039. */
  1040. static inline void ENET_QOS_ClearDmaInterruptStatus(ENET_QOS_Type *base, uint8_t channel, uint32_t mask)
  1041. {
  1042. /* Clear the dam interrupt status bit in dma channel interrupt status register. */
  1043. base->DMA_CH[channel].DMA_CHX_STAT = mask;
  1044. }
  1045. /*!
  1046. * @brief Gets the ENET MAC interrupt status flag.
  1047. *
  1048. * @param base ENET peripheral base address.
  1049. * @return The event status of the interrupt source.
  1050. * Use the enum in enet_qos_mac_interrupt_enable_t and right shift
  1051. * ENET_QOS_MACINT_ENUM_OFFSET to mask the returned value to get the
  1052. * exact interrupt status.
  1053. */
  1054. static inline uint32_t ENET_QOS_GetMacInterruptStatus(ENET_QOS_Type *base)
  1055. {
  1056. return base->MAC_INTERRUPT_STATUS;
  1057. }
  1058. /*!
  1059. * @brief Clears the ENET mac interrupt events status flag.
  1060. *
  1061. * This function clears enabled ENET interrupts according to the provided mask. The mask
  1062. * is a logical OR of enumeration members. See the @ref enet_qos_mac_interrupt_enable_t.
  1063. * For example, to clear the TX frame interrupt and RX frame interrupt, do the following.
  1064. * @code
  1065. * ENET_QOS_ClearMacInterruptStatus(ENET, kENET_QOS_MacPmt);
  1066. * @endcode
  1067. *
  1068. * @param base ENET peripheral base address.
  1069. * @param mask ENET interrupt source to be cleared.
  1070. * This is the logical OR of members of the enumeration :: enet_qos_mac_interrupt_enable_t.
  1071. */
  1072. void ENET_QOS_ClearMacInterruptStatus(ENET_QOS_Type *base, uint32_t mask);
  1073. /* @} */
  1074. /*!
  1075. * @name Functional operation.
  1076. * @{
  1077. */
  1078. /*!
  1079. * @brief Get the tx descriptor DMA Own flag.
  1080. *
  1081. * @param txDesc The given tx descriptor.
  1082. * @retval True the dma own tx descriptor, false application own tx descriptor.
  1083. *
  1084. */
  1085. static inline bool ENET_QOS_IsTxDescriptorDmaOwn(enet_qos_tx_bd_struct_t *txDesc)
  1086. {
  1087. return ((txDesc->controlStat & ENET_QOS_TXDESCRIP_RD_OWN_MASK) != 0U) ? true : false;
  1088. }
  1089. /*!
  1090. * @brief Setup a given tx descriptor.
  1091. * This function is a low level functional API to setup or prepare
  1092. * a given tx descriptor.
  1093. *
  1094. * @param txDesc The given tx descriptor.
  1095. * @param buffer1 The first buffer address in the descriptor.
  1096. * @param bytes1 The bytes in the fist buffer.
  1097. * @param buffer2 The second buffer address in the descriptor.
  1098. * @param bytes2 The bytes in the second buffer.
  1099. * @param framelen The length of the frame to be transmitted.
  1100. * @param intEnable Interrupt enable flag.
  1101. * @param tsEnable The timestamp enable.
  1102. * @param flag The flag of this tx descriptor, @ref enet_qos_desc_flag .
  1103. * @param slotNum The slot num used for AV only.
  1104. *
  1105. * @note This must be called after all the ENET initialization.
  1106. * And should be called when the ENET receive/transmit is required.
  1107. * Transmit buffers are 'zero-copy' buffers, so the buffer must remain in
  1108. * memory until the packet has been fully transmitted. The buffers
  1109. * should be free or requeued in the transmit interrupt irq handler.
  1110. */
  1111. void ENET_QOS_SetupTxDescriptor(enet_qos_tx_bd_struct_t *txDesc,
  1112. void *buffer1,
  1113. uint32_t bytes1,
  1114. void *buffer2,
  1115. uint32_t bytes2,
  1116. uint32_t framelen,
  1117. bool intEnable,
  1118. bool tsEnable,
  1119. enet_qos_desc_flag flag,
  1120. uint8_t slotNum);
  1121. /*!
  1122. * @brief Update the tx descriptor tail pointer.
  1123. * This function is a low level functional API to update the
  1124. * the tx descriptor tail.
  1125. * This is called after you setup a new tx descriptor to update
  1126. * the tail pointer to make the new descriptor accessible by DMA.
  1127. *
  1128. * @param base ENET peripheral base address.
  1129. * @param channel The tx DMA channel.
  1130. * @param txDescTailAddrAlign The new tx tail pointer address.
  1131. *
  1132. */
  1133. static inline void ENET_QOS_UpdateTxDescriptorTail(ENET_QOS_Type *base, uint8_t channel, uint32_t txDescTailAddrAlign)
  1134. {
  1135. base->DMA_CH[channel].DMA_CHX_TXDESC_TAIL_PTR = txDescTailAddrAlign & ~ENET_QOS_ADDR_ALIGNMENT;
  1136. }
  1137. /*!
  1138. * @brief Update the rx descriptor tail pointer.
  1139. * This function is a low level functional API to update the
  1140. * the rx descriptor tail.
  1141. * This is called after you setup a new rx descriptor to update
  1142. * the tail pointer to make the new descriptor accessible by DMA
  1143. * and to anouse the rx poll command for DMA.
  1144. *
  1145. * @param base ENET peripheral base address.
  1146. * @param channel The rx DMA channel.
  1147. * @param rxDescTailAddrAlign The new rx tail pointer address.
  1148. *
  1149. */
  1150. static inline void ENET_QOS_UpdateRxDescriptorTail(ENET_QOS_Type *base, uint8_t channel, uint32_t rxDescTailAddrAlign)
  1151. {
  1152. base->DMA_CH[channel].DMA_CHX_RXDESC_TAIL_PTR = rxDescTailAddrAlign & ~ENET_QOS_ADDR_ALIGNMENT;
  1153. }
  1154. /*!
  1155. * @brief Gets the context in the ENET rx descriptor.
  1156. * This function is a low level functional API to get the
  1157. * the status flag from a given rx descriptor.
  1158. *
  1159. * @param rxDesc The given rx descriptor.
  1160. * @retval The RDES3 regions for write-back format rx buffer descriptor.
  1161. *
  1162. * @note This must be called after all the ENET initialization.
  1163. * And should be called when the ENET receive/transmit is required.
  1164. */
  1165. static inline uint32_t ENET_QOS_GetRxDescriptor(enet_qos_rx_bd_struct_t *rxDesc)
  1166. {
  1167. assert(rxDesc != NULL);
  1168. return rxDesc->control;
  1169. }
  1170. /*!
  1171. * @brief Updates the buffers and the own status for a given rx descriptor.
  1172. * This function is a low level functional API to Updates the
  1173. * buffers and the own status for a given rx descriptor.
  1174. *
  1175. * @param rxDesc The given rx descriptor.
  1176. * @param buffer1 The first buffer address in the descriptor.
  1177. * @param buffer2 The second buffer address in the descriptor.
  1178. * @param intEnable Interrupt enable flag.
  1179. * @param doubleBuffEnable The double buffer enable flag.
  1180. *
  1181. * @note This must be called after all the ENET initialization.
  1182. * And should be called when the ENET receive/transmit is required.
  1183. */
  1184. void ENET_QOS_UpdateRxDescriptor(
  1185. enet_qos_rx_bd_struct_t *rxDesc, void *buffer1, void *buffer2, bool intEnable, bool doubleBuffEnable);
  1186. /*!
  1187. * @brief Configure flexible rx parser.
  1188. *
  1189. * This function is used to configure the flexible rx parser table.
  1190. *
  1191. * @param base ENET peripheral base address..
  1192. * @param rxpConfig The rx parser configuration pointer.
  1193. * @param entryCount The rx parser entry count.
  1194. * @retval kStatus_Success Configure rx parser success.
  1195. * @retval kStatus_ENET_QOS_Timeout Poll status flag timeout.
  1196. */
  1197. status_t ENET_QOS_ConfigureRxParser(ENET_QOS_Type *base, enet_qos_rxp_config_t *rxpConfig, uint16_t entryCount);
  1198. /*!
  1199. * @brief Read flexible rx parser configuration at specified index.
  1200. *
  1201. * This function is used to read flexible rx parser configuration at specified index.
  1202. *
  1203. * @param base ENET peripheral base address..
  1204. * @param rxpConfig The rx parser configuration pointer.
  1205. * @param entryIndex The rx parser entry index to read, start from 0.
  1206. * @retval kStatus_Success Configure rx parser success.
  1207. * @retval kStatus_ENET_QOS_Timeout Poll status flag timeout.
  1208. */
  1209. status_t ENET_QOS_ReadRxParser(ENET_QOS_Type *base, enet_qos_rxp_config_t *rxpConfig, uint16_t entryIndex);
  1210. /*!
  1211. * @brief Program Gate Control List.
  1212. *
  1213. * This function is used to program the Enhanced Scheduled Transmisson. (IEEE802.1Qbv)
  1214. *
  1215. * @param base ENET peripheral base address..
  1216. * @param gcl Pointer to the Gate Control List structure.
  1217. * @param ptpClk_Hz frequency of the PTP clock.
  1218. */
  1219. status_t ENET_QOS_EstProgramGcl(ENET_QOS_Type *base, enet_qos_est_gcl_t *gcl, uint32_t ptpClk_Hz);
  1220. /*!
  1221. * @brief Read Gate Control List.
  1222. *
  1223. * This function is used to read the Enhanced Scheduled Transmisson list. (IEEE802.1Qbv)
  1224. *
  1225. * @param base ENET peripheral base address..
  1226. * @param gcl Pointer to the Gate Control List structure.
  1227. * @param listLen length of the provided opList array in gcl structure.
  1228. * @param hwList Boolean if True read HW list, false read SW list.
  1229. */
  1230. status_t ENET_QOS_EstReadGcl(ENET_QOS_Type *base, enet_qos_est_gcl_t *gcl, uint32_t listLen, bool hwList);
  1231. /*!
  1232. * @brief Enable Frame Preemption.
  1233. *
  1234. * This function is used to enable frame preemption. (IEEE802.1Qbu)
  1235. *
  1236. * @param base ENET peripheral base address..
  1237. */
  1238. static inline void ENET_QOS_FpeEnable(ENET_QOS_Type *base)
  1239. {
  1240. base->MAC_FPE_CTRL_STS |= ENET_QOS_MAC_FPE_CTRL_STS_EFPE_MASK;
  1241. }
  1242. /*!
  1243. * @brief Disable Frame Preemption.
  1244. *
  1245. * This function is used to disable frame preemption. (IEEE802.1Qbu)
  1246. *
  1247. * @param base ENET peripheral base address..
  1248. */
  1249. static inline void ENET_QOS_FpeDisable(ENET_QOS_Type *base)
  1250. {
  1251. base->MAC_FPE_CTRL_STS &= ~ENET_QOS_MAC_FPE_CTRL_STS_EFPE_MASK;
  1252. }
  1253. /*!
  1254. * @brief Configure preemptable transmit queues.
  1255. *
  1256. * This function is used to configure the preemptable queues. (IEEE802.1Qbu)
  1257. *
  1258. * @param base ENET peripheral base address..
  1259. * @param queueMask bitmask representing queues to set in preemptable mode.
  1260. * The N-th bit represents the queue N.
  1261. */
  1262. static inline void ENET_QOS_FpeConfigPreemptable(ENET_QOS_Type *base, uint8_t queueMask)
  1263. {
  1264. uint32_t control;
  1265. control = base->MTL_FPE_CTRL_STS & ~ENET_QOS_MTL_FPE_CTRL_STS_PEC_MASK;
  1266. control |= ENET_QOS_MTL_FPE_CTRL_STS_PEC(queueMask);
  1267. base->MTL_FPE_CTRL_STS = control;
  1268. }
  1269. /*!
  1270. * @brief Sets the ENET AVB feature.
  1271. *
  1272. * ENET_QOS AVB feature configuration, set transmit bandwidth.
  1273. * This API is called when the AVB feature is required.
  1274. *
  1275. * @param base ENET_QOS peripheral base address.
  1276. * @param config The ENET_QOS AVB feature configuration structure.
  1277. * @param queueIndex ENET_QOS queue index.
  1278. */
  1279. void ENET_QOS_AVBConfigure(ENET_QOS_Type *base, const enet_qos_cbs_config_t *config, uint8_t queueIndex);
  1280. /*!
  1281. * @brief Gets statistical data in transfer.
  1282. *
  1283. * @param base ENET_QOS peripheral base address.
  1284. * @param statistics The statistics structure pointer.
  1285. */
  1286. void ENET_QOS_GetStatistics(ENET_QOS_Type *base, enet_qos_transfer_stats_t *statistics);
  1287. /* @} */
  1288. /*!
  1289. * @name Transactional operation
  1290. * @{
  1291. */
  1292. /*!
  1293. * @brief Create ENET Handler
  1294. *
  1295. * This is a transactional API and it's provided to store all data which are needed
  1296. * during the whole transactional process. This API should not be used when you use
  1297. * functional APIs to do data tx/rx. This is function will store many data/flag for
  1298. * transactional use, so all configure API such as ENET_QOS_Init(), ENET_QOS_DescriptorInit(),
  1299. * ENET_QOS_EnableInterrupts() etc.
  1300. *
  1301. * @note as our transactional transmit API use the zero-copy transmit buffer.
  1302. * so there are two thing we emphasize here:
  1303. * 1. tx buffer free/requeue for application should be done in the tx
  1304. * interrupt handler. Please set callback: kENET_QOS_TxIntEvent with tx buffer free/requeue
  1305. * process APIs.
  1306. * 2. the tx interrupt is forced to open.
  1307. *
  1308. * @param base ENET peripheral base address.
  1309. * @param handle ENET handler.
  1310. * @param config ENET configuration.
  1311. * @param bufferConfig ENET buffer configuration.
  1312. * @param callback The callback function.
  1313. * @param userData The application data.
  1314. */
  1315. void ENET_QOS_CreateHandler(ENET_QOS_Type *base,
  1316. enet_qos_handle_t *handle,
  1317. enet_qos_config_t *config,
  1318. enet_qos_buffer_config_t *bufferConfig,
  1319. enet_qos_callback_t callback,
  1320. void *userData);
  1321. /*!
  1322. * @brief Gets the size of the read frame.
  1323. * This function gets a received frame size from the ENET buffer descriptors.
  1324. * @note The FCS of the frame is automatically removed by MAC and the size is the length without the FCS.
  1325. * After calling @ref ENET_QOS_GetRxFrameSize, @ref ENET_QOS_ReadFrame() should be called to update the
  1326. * receive buffers If the result is not "kStatus_ENET_QOS_RxFrameEmpty".
  1327. *
  1328. * @param base ENET peripheral base address.
  1329. * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_QOS_Init.
  1330. * @param length The length of the valid frame received.
  1331. * @param channel The DMAC channel for the rx.
  1332. * @retval kStatus_ENET_QOS_RxFrameEmpty No frame received. Should not call ENET_QOS_ReadFrame to read frame.
  1333. * @retval kStatus_ENET_QOS_RxFrameError Data error happens. @ref ENET_QOS_ReadFrame should be called with NULL data
  1334. * and NULL length to update the receive buffers.
  1335. * @retval kStatus_Success Receive a frame Successfully then the @ref ENET_QOS_ReadFrame
  1336. * should be called with the right data buffer and the captured data length input.
  1337. */
  1338. status_t ENET_QOS_GetRxFrameSize(ENET_QOS_Type *base, enet_qos_handle_t *handle, uint32_t *length, uint8_t channel);
  1339. /*!
  1340. * @brief Reads a frame from the ENET device.
  1341. * This function reads a frame from the ENET DMA descriptors.
  1342. * The ENET_QOS_GetRxFrameSize should be used to get the size of the prepared data buffer.
  1343. * For example use rx dma channel 0:
  1344. * @code
  1345. * uint32_t length;
  1346. * enet_qos_handle_t g_handle;
  1347. * status = ENET_QOS_GetRxFrameSize(&g_handle, &length, 0);
  1348. * if (length != 0)
  1349. * {
  1350. * uint8_t *data = memory allocate interface;
  1351. * if (!data)
  1352. * {
  1353. * ENET_QOS_ReadFrame(ENET, &g_handle, NULL, 0, 0);
  1354. * }
  1355. * else
  1356. * {
  1357. * status = ENET_QOS_ReadFrame(ENET, &g_handle, data, length, 0);
  1358. * }
  1359. * }
  1360. * else if (status == kStatus_ENET_QOS_RxFrameError)
  1361. * {
  1362. * ENET_QOS_ReadFrame(ENET, &g_handle, NULL, 0, 0);
  1363. * }
  1364. * @endcode
  1365. * @param base ENET peripheral base address.
  1366. * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_QOS_Init.
  1367. * @param data The data buffer provided by user to store the frame which memory size should be at least "length".
  1368. * @param length The size of the data buffer which is still the length of the received frame.
  1369. * @param channel The rx DMA channel. shall not be larger than 2.
  1370. * @param ts Pointer to the structure @ref enet_qos_ptp_time_t to save frame timestamp.
  1371. * @return The execute status, successful or failure.
  1372. */
  1373. status_t ENET_QOS_ReadFrame(ENET_QOS_Type *base,
  1374. enet_qos_handle_t *handle,
  1375. uint8_t *data,
  1376. uint32_t length,
  1377. uint8_t channel,
  1378. enet_qos_ptp_time_t *ts);
  1379. /*!
  1380. * @brief Transmits an ENET frame.
  1381. * @note The CRC is automatically appended to the data. Input the data
  1382. * to send without the CRC.
  1383. *
  1384. * @param base ENET peripheral base address.
  1385. * @param handle The ENET handler pointer. This is the same handler pointer used in the ENET_QOS_Init.
  1386. * @param data The data buffer provided by user to be send.
  1387. * @param length The length of the data to be send.
  1388. * @param channel Channel to send the frame, same with queue index.
  1389. * @param isNeedTs True to enable timestamp save for the frame
  1390. * @param context pointer to user context to be kept in the tx dirty frame information.
  1391. * @retval kStatus_Success Send frame succeed.
  1392. * @retval kStatus_ENET_QOS_TxFrameBusy Transmit buffer descriptor is busy under transmission.
  1393. * The transmit busy happens when the data send rate is over the MAC capacity.
  1394. * The waiting mechanism is recommended to be added after each call return with
  1395. * kStatus_ENET_QOS_TxFrameBusy.
  1396. */
  1397. status_t ENET_QOS_SendFrame(ENET_QOS_Type *base,
  1398. enet_qos_handle_t *handle,
  1399. uint8_t *data,
  1400. uint32_t length,
  1401. uint8_t channel,
  1402. bool isNeedTs,
  1403. void *context);
  1404. /*!
  1405. * @brief Reclaim tx descriptors.
  1406. * This function is used to update the tx descriptor status and
  1407. * store the tx timestamp when the 1588 feature is enabled.
  1408. * This is called by the transmit interrupt IRQ handler after the
  1409. * complete of a frame transmission.
  1410. *
  1411. * @param base ENET peripheral base address.
  1412. * @param handle The ENET handler pointer. This is the same handler pointer used in the ENET_QOS_Init.
  1413. * @param channel The tx DMA channel.
  1414. *
  1415. */
  1416. void ENET_QOS_ReclaimTxDescriptor(ENET_QOS_Type *base, enet_qos_handle_t *handle, uint8_t channel);
  1417. /*!
  1418. * @brief The ENET IRQ handler.
  1419. *
  1420. * @param base ENET peripheral base address.
  1421. * @param handle The ENET handler pointer.
  1422. */
  1423. void ENET_QOS_CommonIRQHandler(ENET_QOS_Type *base, enet_qos_handle_t *handle);
  1424. /*!
  1425. * @brief Set the second level IRQ handler, allow user to overwrite the default
  1426. * second level weak IRQ handler.
  1427. *
  1428. * @param base ENET peripheral base address.
  1429. * @param ISRHandler The handler to install.
  1430. */
  1431. void ENET_QOS_SetISRHandler(ENET_QOS_Type *base, enet_qos_isr_t ISRHandler);
  1432. /* @} */
  1433. /*!
  1434. * @name ENET Enhanced function operation
  1435. * @{
  1436. */
  1437. /*!
  1438. * @brief Correct the ENET PTP 1588 timer in coarse method.
  1439. *
  1440. * @param base ENET peripheral base address.
  1441. * @param operation The system time operation, refer to "enet_qos_systime_op"
  1442. * @param second The correction second.
  1443. * @param nanosecond The correction nanosecond.
  1444. */
  1445. status_t ENET_QOS_Ptp1588CorrectTimerInCoarse(ENET_QOS_Type *base,
  1446. enet_qos_systime_op operation,
  1447. uint32_t second,
  1448. uint32_t nanosecond);
  1449. /*!
  1450. * @brief Correct the ENET PTP 1588 timer in fine method.
  1451. *
  1452. *
  1453. * @param base ENET peripheral base address.
  1454. * @param addend The addend value to be set in the fine method
  1455. * @note Should take refer to the chapter "System time correction" and
  1456. * see the description for the "fine correction method".
  1457. */
  1458. status_t ENET_QOS_Ptp1588CorrectTimerInFine(ENET_QOS_Type *base, uint32_t addend);
  1459. /*!
  1460. * @brief Get the ENET Time stamp current addend value.
  1461. *
  1462. * @param base ENET peripheral base address.
  1463. * @return The addend value.
  1464. */
  1465. static inline uint32_t ENET_QOS_Ptp1588GetAddend(ENET_QOS_Type *base)
  1466. {
  1467. return base->MAC_TIMESTAMP_ADDEND;
  1468. }
  1469. /*!
  1470. * @brief Gets the current ENET time from the PTP 1588 timer without IRQ disable.
  1471. *
  1472. * @param base ENET peripheral base address.
  1473. * @param second The PTP 1588 system timer second.
  1474. * @param nanosecond The PTP 1588 system timer nanosecond.
  1475. * For the unit of the nanosecond is 1ns. so the nanosecond is the real nanosecond.
  1476. */
  1477. void ENET_QOS_Ptp1588GetTimerNoIRQDisable(ENET_QOS_Type *base, uint64_t *second, uint32_t *nanosecond);
  1478. /*!
  1479. * @brief Sets the ENET PTP 1588 PPS control.
  1480. * All channels operate in flexible PPS output mode.
  1481. *
  1482. * @param base ENET peripheral base address.
  1483. * @param instance The ENET QOS PTP PPS instance.
  1484. * @param trgtMode The target time register mode.
  1485. * @param cmd The target flexible PPS output control command.
  1486. */
  1487. static inline status_t ENET_Ptp1588PpsControl(ENET_QOS_Type *base,
  1488. enet_qos_ptp_pps_instance_t instance,
  1489. enet_qos_ptp_pps_trgt_mode_t trgtMode,
  1490. enet_qos_ptp_pps_cmd_t cmd)
  1491. {
  1492. uint32_t reg = 0UL;
  1493. uint8_t shift = (uint8_t)instance * 8U;
  1494. uint32_t pps_config = ENET_QOS_MAC_PPS_CONTROL_TRGTMODSEL0((uint32_t)trgtMode) |
  1495. ENET_QOS_MAC_PPS_CONTROL_PPSCTRL_PPSCMD((uint32_t)cmd);
  1496. reg = base->MAC_PPS_CONTROL;
  1497. /* Make sure CMD field is all zero */
  1498. if ((reg & (0xFUL << shift)) != 0UL)
  1499. {
  1500. return kStatus_ENET_QOS_PpsBusy;
  1501. }
  1502. reg &= ~(0xFFUL << shift);
  1503. reg |= (pps_config << shift) | ENET_QOS_MAC_PPS_CONTROL_PPSEN0(1U);
  1504. base->MAC_PPS_CONTROL = reg;
  1505. return kStatus_Success;
  1506. }
  1507. /*!
  1508. * @brief Sets the ENET OQS PTP 1588 PPS target time registers.
  1509. *
  1510. * @param base ENET QOS peripheral base address.
  1511. * @param instance The ENET QOS PTP PPS instance.
  1512. * @param seconds The target seconds.
  1513. * @param nanoseconds The target nanoseconds.
  1514. */
  1515. status_t ENET_QOS_Ptp1588PpsSetTrgtTime(ENET_QOS_Type *base,
  1516. enet_qos_ptp_pps_instance_t instance,
  1517. uint32_t seconds,
  1518. uint32_t nanoseconds);
  1519. /*!
  1520. * @brief Sets the ENET OQS PTP 1588 PPS output signal interval
  1521. *
  1522. * @param base ENET QOS peripheral base address.
  1523. * @param instance The ENET QOS PTP PPS instance.
  1524. * @param width Signal Width. It is stored in terms of number of
  1525. * units of sub-second increment value. The width value must be
  1526. * lesser than interval value.
  1527. */
  1528. static inline void ENET_QOS_Ptp1588PpsSetWidth(ENET_QOS_Type *base,
  1529. enet_qos_ptp_pps_instance_t instance,
  1530. uint32_t width)
  1531. {
  1532. uint32_t *mac_pps_width;
  1533. mac_pps_width = (uint32_t *)((uint32_t)&base->MAC_PPS0_WIDTH + 0x10U * (uint32_t)instance);
  1534. *mac_pps_width = ENET_QOS_MAC_PPS0_WIDTH_PPSWIDTH0(width);
  1535. }
  1536. /*!
  1537. * @brief Sets the ENET OQS PTP 1588 PPS output signal width
  1538. *
  1539. * @param base ENET QOS peripheral base address.
  1540. * @param instance The ENET QOS PTP PPS instance.
  1541. * @param interval Signal Interval. It is stored in terms of number of
  1542. * units of sub-second increment value.
  1543. */
  1544. static inline void ENET_QOS_Ptp1588PpsSetInterval(ENET_QOS_Type *base,
  1545. enet_qos_ptp_pps_instance_t instance,
  1546. uint32_t interval)
  1547. {
  1548. uint32_t *mac_pps_interval;
  1549. mac_pps_interval = (uint32_t *)((uint32_t)&base->MAC_PPS0_INTERVAL + 0x10U * (uint32_t)instance);
  1550. *mac_pps_interval = ENET_QOS_MAC_PPS0_INTERVAL_PPSINT0(interval);
  1551. }
  1552. /*!
  1553. * @brief Gets the current ENET time from the PTP 1588 timer.
  1554. *
  1555. * @param base ENET peripheral base address.
  1556. * @param second The PTP 1588 system timer second.
  1557. * @param nanosecond The PTP 1588 system timer nanosecond.
  1558. * For the unit of the nanosecond is 1ns.so the nanosecond is the real nanosecond.
  1559. */
  1560. void ENET_QOS_Ptp1588GetTimer(ENET_QOS_Type *base, uint64_t *second, uint32_t *nanosecond);
  1561. /*!
  1562. * @brief Gets the time stamp of the transmit frame.
  1563. *
  1564. * This function is used for PTP stack to get the timestamp captured by the ENET driver.
  1565. *
  1566. * @param handle The ENET handler pointer.This is the same state pointer used in
  1567. * ENET_QOS_Init.
  1568. * @param txFrame Input parameter, pointer to @ref enet_qos_frame_info_t for saving read out frame information.
  1569. * @param channel Channel for searching the tx frame.
  1570. */
  1571. void ENET_QOS_GetTxFrame(enet_qos_handle_t *handle, enet_qos_frame_info_t *txFrame, uint8_t channel);
  1572. /*!
  1573. * @brief Receives one frame in specified BD ring with zero copy.
  1574. *
  1575. * This function will use the user-defined allocate and free callback. Every time application gets one frame through
  1576. * this function, driver will allocate new buffers for the BDs whose buffers have been taken by application.
  1577. * @note This function will drop current frame and update related BDs as available for DMA if new buffers allocating
  1578. * fails. Application must provide a memory pool including at least BD number + 1 buffers(+2 if enable double buffer)
  1579. * to make this function work normally. If user calls this function in Rx interrupt handler, be careful that this
  1580. * function makes Rx BD ready with allocating new buffer(normal) or updating current BD(out of memory). If there's
  1581. * always new Rx frame input, Rx interrupt will be triggered forever. Application need to disable Rx interrupt according
  1582. * to specific design in this case.
  1583. *
  1584. * @param base ENET peripheral base address.
  1585. * @param handle The ENET handler pointer. This is the same handler pointer used in the ENET_Init.
  1586. * @param rxFrame The received frame information structure provided by user.
  1587. * @param channel Channel for searching the rx frame.
  1588. * @retval kStatus_Success Succeed to get one frame and allocate new memory for Rx buffer.
  1589. * @retval kStatus_ENET_QOS_RxFrameEmpty There's no Rx frame in the BD.
  1590. * @retval kStatus_ENET_QOS_RxFrameError There's issue in this receiving.
  1591. * @retval kStatus_ENET_QOS_RxFrameDrop There's no new buffer memory for BD, drop this frame.
  1592. */
  1593. status_t ENET_QOS_GetRxFrame(ENET_QOS_Type *base,
  1594. enet_qos_handle_t *handle,
  1595. enet_qos_rx_frame_struct_t *rxFrame,
  1596. uint8_t channel);
  1597. /* @} */
  1598. #if defined(__cplusplus)
  1599. }
  1600. #endif
  1601. /*! @}*/
  1602. #endif /* _FSL_ENET_QOS_H_ */