fsl_enet.h 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  1. /*
  2. * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_ENET_H_
  31. #define _FSL_ENET_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup enet
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. #define ENET_PHY2 0x01U
  41. #define ENET_PHY1 0x0U
  42. #define DETECT_DELAY_ONE_SECOND 1000
  43. #define ENET_RXBD_NUM (128)
  44. #define ENET_TXBD_NUM (128)
  45. #define ENET_RXBUFF_ALIGN_SIZE (1536)
  46. #define ENET_TXBUFF_ALIGN_SIZE (1536)
  47. #define ENET_RXBUFF_TOTAL_SIZE (ENET_RXBD_NUM*ENET_RXBUFF_ALIGN_SIZE)
  48. #define ENET_TXBUFF_TOTAL_SIZE (ENET_TXBD_NUM*ENET_TXBUFF_ALIGN_SIZE)
  49. #define ENET_RX_MAX_BUFFER_SIZE (65536U)
  50. #define SYS_PAGE_SIZE (4096U)
  51. #define TX_BUFFER_INDEX_NUM (6)
  52. #define RX_BUFFER_INDEX_NUM (6)
  53. #define TX_BD_INDEX_NUM (0)
  54. #define RX_BD_INDEX_NUM (0)
  55. #define SYS_CLOCK_HZ (66000000)
  56. #define virtual_to_physical(v) ((void *)((size_t)v + PV_OFFSET))
  57. #define physical_to_virtual(p) ((void *)((size_t)p - PV_OFFSET))
  58. /*! @name Driver version */
  59. /*@{*/
  60. /*! @brief Defines the driver version. */
  61. #define FSL_ENET_DRIVER_VERSION (MAKE_VERSION(2, 1, 1)) /*!< Version 2.1.1. */
  62. /*@}*/
  63. /*! @name Control and status region bit masks of the receive buffer descriptor. */
  64. /*@{*/
  65. #define ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK 0x8000U /*!< Empty bit mask. */
  66. #define ENET_BUFFDESCRIPTOR_RX_SOFTOWNER1_MASK 0x4000U /*!< Software owner one mask. */
  67. #define ENET_BUFFDESCRIPTOR_RX_WRAP_MASK 0x2000U /*!< Next buffer descriptor is the start address. */
  68. #define ENET_BUFFDESCRIPTOR_RX_SOFTOWNER2_Mask 0x1000U /*!< Software owner two mask. */
  69. #define ENET_BUFFDESCRIPTOR_RX_LAST_MASK 0x0800U /*!< Last BD of the frame mask. */
  70. #define ENET_BUFFDESCRIPTOR_RX_MISS_MASK 0x0100U /*!< Received because of the promiscuous mode. */
  71. #define ENET_BUFFDESCRIPTOR_RX_BROADCAST_MASK 0x0080U /*!< Broadcast packet mask. */
  72. #define ENET_BUFFDESCRIPTOR_RX_MULTICAST_MASK 0x0040U /*!< Multicast packet mask. */
  73. #define ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK 0x0020U /*!< Length violation mask. */
  74. #define ENET_BUFFDESCRIPTOR_RX_NOOCTET_MASK 0x0010U /*!< Non-octet aligned frame mask. */
  75. #define ENET_BUFFDESCRIPTOR_RX_CRC_MASK 0x0004U /*!< CRC error mask. */
  76. #define ENET_BUFFDESCRIPTOR_RX_OVERRUN_MASK 0x0002U /*!< FIFO overrun mask. */
  77. #define ENET_BUFFDESCRIPTOR_RX_TRUNC_MASK 0x0001U /*!< Frame is truncated mask. */
  78. /*@}*/
  79. /*! @name Control and status bit masks of the transmit buffer descriptor. */
  80. /*@{*/
  81. #define ENET_BUFFDESCRIPTOR_TX_READY_MASK 0x8000U /*!< Ready bit mask. */
  82. #define ENET_BUFFDESCRIPTOR_TX_SOFTOWENER1_MASK 0x4000U /*!< Software owner one mask. */
  83. #define ENET_BUFFDESCRIPTOR_TX_WRAP_MASK 0x2000U /*!< Wrap buffer descriptor mask. */
  84. #define ENET_BUFFDESCRIPTOR_TX_SOFTOWENER2_MASK 0x1000U /*!< Software owner two mask. */
  85. #define ENET_BUFFDESCRIPTOR_TX_LAST_MASK 0x0800U /*!< Last BD of the frame mask. */
  86. #define ENET_BUFFDESCRIPTOR_TX_TRANMITCRC_MASK 0x0400U /*!< Transmit CRC mask. */
  87. /*@}*/
  88. /* Extended control regions for enhanced buffer descriptors. */
  89. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  90. /*! @name First extended control region bit masks of the receive buffer descriptor. */
  91. /*@{*/
  92. #define ENET_BUFFDESCRIPTOR_RX_IPV4_MASK 0x0001U /*!< Ipv4 frame mask. */
  93. #define ENET_BUFFDESCRIPTOR_RX_IPV6_MASK 0x0002U /*!< Ipv6 frame mask. */
  94. #define ENET_BUFFDESCRIPTOR_RX_VLAN_MASK 0x0004U /*!< VLAN frame mask. */
  95. #define ENET_BUFFDESCRIPTOR_RX_PROTOCOLCHECKSUM_MASK 0x0010U /*!< Protocol checksum error mask. */
  96. #define ENET_BUFFDESCRIPTOR_RX_IPHEADCHECKSUM_MASK 0x0020U /*!< IP header checksum error mask. */
  97. /*@}*/
  98. /*! @name Second extended control region bit masks of the receive buffer descriptor. */
  99. /*@{*/
  100. #define ENET_BUFFDESCRIPTOR_RX_INTERRUPT_MASK 0x0080U /*!< BD interrupt mask. */
  101. #define ENET_BUFFDESCRIPTOR_RX_UNICAST_MASK 0x0100U /*!< Unicast frame mask. */
  102. #define ENET_BUFFDESCRIPTOR_RX_COLLISION_MASK 0x0200U /*!< BD collision mask. */
  103. #define ENET_BUFFDESCRIPTOR_RX_PHYERR_MASK 0x0400U /*!< PHY error mask. */
  104. #define ENET_BUFFDESCRIPTOR_RX_MACERR_MASK 0x8000U /*!< Mac error mask. */
  105. /*@}*/
  106. /*! @name First extended control region bit masks of the transmit buffer descriptor. */
  107. /*@{*/
  108. #define ENET_BUFFDESCRIPTOR_TX_ERR_MASK 0x8000U /*!< Transmit error mask. */
  109. #define ENET_BUFFDESCRIPTOR_TX_UNDERFLOWERR_MASK 0x2000U /*!< Underflow error mask. */
  110. #define ENET_BUFFDESCRIPTOR_TX_EXCCOLLISIONERR_MASK 0x1000U /*!< Excess collision error mask. */
  111. #define ENET_BUFFDESCRIPTOR_TX_FRAMEERR_MASK 0x0800U /*!< Frame error mask. */
  112. #define ENET_BUFFDESCRIPTOR_TX_LATECOLLISIONERR_MASK 0x0400U /*!< Late collision error mask. */
  113. #define ENET_BUFFDESCRIPTOR_TX_OVERFLOWERR_MASK 0x0200U /*!< Overflow error mask. */
  114. #define ENET_BUFFDESCRIPTOR_TX_TIMESTAMPERR_MASK 0x0100U /*!< Timestamp error mask. */
  115. /*@}*/
  116. /*! @name Second extended control region bit masks of the transmit buffer descriptor. */
  117. /*@{*/
  118. #define ENET_BUFFDESCRIPTOR_TX_INTERRUPT_MASK 0x4000U /*!< Interrupt mask. */
  119. #define ENET_BUFFDESCRIPTOR_TX_TIMESTAMP_MASK 0x2000U /*!< Timestamp flag mask. */
  120. /*@}*/
  121. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  122. /*! @brief Defines the receive error status flag mask. */
  123. #define ENET_BUFFDESCRIPTOR_RX_ERR_MASK \
  124. (ENET_BUFFDESCRIPTOR_RX_TRUNC_MASK | ENET_BUFFDESCRIPTOR_RX_OVERRUN_MASK | \
  125. ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK | ENET_BUFFDESCRIPTOR_RX_NOOCTET_MASK | ENET_BUFFDESCRIPTOR_RX_CRC_MASK)
  126. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  127. #define ENET_BUFFDESCRIPTOR_RX_EXT_ERR_MASK \
  128. (ENET_BUFFDESCRIPTOR_RX_MACERR_MASK | ENET_BUFFDESCRIPTOR_RX_PHYERR_MASK | ENET_BUFFDESCRIPTOR_RX_COLLISION_MASK)
  129. #endif
  130. #define ENET_TX_INTERRUPT (kENET_TxFrameInterrupt | kENET_TxBufferInterrupt)
  131. #define ENET_RX_INTERRUPT (kENET_RxFrameInterrupt | kENET_RxBufferInterrupt)
  132. #define ENET_TS_INTERRUPT (kENET_TsTimerInterrupt | kENET_TsAvailInterrupt)
  133. #define ENET_ERR_INTERRUPT (kENET_BabrInterrupt | kENET_BabtInterrupt | kENET_EBusERInterrupt | \
  134. kENET_LateCollisionInterrupt | kENET_RetryLimitInterrupt | kENET_UnderrunInterrupt | kENET_PayloadRxInterrupt)
  135. /*! @name Defines the maximum Ethernet frame size. */
  136. /*@{*/
  137. #define ENET_FRAME_MAX_FRAMELEN 1518U /*!< Default maximum Ethernet frame size. */
  138. /*@}*/
  139. #define ENET_FIFO_MIN_RX_FULL 5U /*!< ENET minimum receive FIFO full. */
  140. #define ENET_RX_MIN_BUFFERSIZE 256U /*!< ENET minimum buffer size. */
  141. /*! @brief Defines the PHY address scope for the ENET. */
  142. #define ENET_PHY_MAXADDRESS (ENET_MMFR_PA_MASK >> ENET_MMFR_PA_SHIFT)
  143. /*! @brief Defines the status return codes for transaction. */
  144. enum _enet_status
  145. {
  146. kStatus_ENET_RxFrameError = MAKE_STATUS(kStatusGroup_ENET, 0U), /*!< A frame received but data error happen. */
  147. kStatus_ENET_RxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 1U), /*!< Failed to receive a frame. */
  148. kStatus_ENET_RxFrameEmpty = MAKE_STATUS(kStatusGroup_ENET, 2U), /*!< No frame arrive. */
  149. kStatus_ENET_TxFrameBusy =
  150. MAKE_STATUS(kStatusGroup_ENET, 3U), /*!< Transmit buffer descriptors are under process. */
  151. kStatus_ENET_TxFrameFail = MAKE_STATUS(kStatusGroup_ENET, 4U) /*!< Transmit frame fail. */
  152. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  153. ,
  154. kStatus_ENET_PtpTsRingFull = MAKE_STATUS(kStatusGroup_ENET, 5U), /*!< Timestamp ring full. */
  155. kStatus_ENET_PtpTsRingEmpty = MAKE_STATUS(kStatusGroup_ENET, 6U) /*!< Timestamp ring empty. */
  156. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  157. };
  158. /*! @brief Defines the RMII or MII mode for data interface between the MAC and the PHY. */
  159. typedef enum _enet_mii_mode
  160. {
  161. kENET_MiiMode = 0U, /*!< MII mode for data interface. */
  162. kENET_RmiiMode /*!< RMII mode for data interface. */
  163. } enet_mii_mode_t;
  164. /*! @brief Defines the 10 Mbps or 100 Mbps speed for the MII data interface. */
  165. typedef enum _enet_mii_speed
  166. {
  167. kENET_MiiSpeed10M = 0U, /*!< Speed 10 Mbps. */
  168. kENET_MiiSpeed100M /*!< Speed 100 Mbps. */
  169. } enet_mii_speed_t;
  170. /*! @brief Defines the half or full duplex for the MII data interface. */
  171. typedef enum _enet_mii_duplex
  172. {
  173. kENET_MiiHalfDuplex = 0U, /*!< Half duplex mode. */
  174. kENET_MiiFullDuplex /*!< Full duplex mode. */
  175. } enet_mii_duplex_t;
  176. /*! @brief Defines the write operation for the MII management frame. */
  177. typedef enum _enet_mii_write
  178. {
  179. kENET_MiiWriteNoCompliant = 0U, /*!< Write frame operation, but not MII-compliant. */
  180. kENET_MiiWriteValidFrame /*!< Write frame operation for a valid MII management frame. */
  181. } enet_mii_write_t;
  182. /*! @brief Defines the read operation for the MII management frame. */
  183. typedef enum _enet_mii_read
  184. {
  185. kENET_MiiReadValidFrame = 2U, /*!< Read frame operation for a valid MII management frame. */
  186. kENET_MiiReadNoCompliant = 3U /*!< Read frame operation, but not MII-compliant. */
  187. } enet_mii_read_t;
  188. #if defined (FSL_FEATURE_ENET_HAS_EXTEND_MDIO) && FSL_FEATURE_ENET_HAS_EXTEND_MDIO
  189. /*! @brief Define the MII opcode for extended MDIO_CLAUSES_45 Frame. */
  190. typedef enum _enet_mii_extend_opcode {
  191. kENET_MiiAddrWrite_C45 = 0U, /*!< Address Write operation. */
  192. kENET_MiiWriteFrame_C45 = 1U, /*!< Write frame operation for a valid MII management frame. */
  193. kENET_MiiReadFrame_C45 = 3U /*!< Read frame operation for a valid MII management frame. */
  194. } enet_mii_extend_opcode;
  195. #endif /* FSL_FEATURE_ENET_HAS_EXTEND_MDIO */
  196. /*! @brief Defines a special configuration for ENET MAC controller.
  197. *
  198. * These control flags are provided for special user requirements.
  199. * Normally, these control flags are unused for ENET initialization.
  200. * For special requirements, set the flags to
  201. * macSpecialConfig in the enet_config_t.
  202. * The kENET_ControlStoreAndFwdDisable is used to disable the FIFO store
  203. * and forward. FIFO store and forward means that the FIFO read/send is started
  204. * when a complete frame is stored in TX/RX FIFO. If this flag is set,
  205. * configure rxFifoFullThreshold and txFifoWatermark
  206. * in the enet_config_t.
  207. */
  208. typedef enum _enet_special_control_flag
  209. {
  210. kENET_ControlFlowControlEnable = 0x0001U, /*!< Enable ENET flow control: pause frame. */
  211. kENET_ControlRxPayloadCheckEnable = 0x0002U, /*!< Enable ENET receive payload length check. */
  212. kENET_ControlRxPadRemoveEnable = 0x0004U, /*!< Padding is removed from received frames. */
  213. kENET_ControlRxBroadCastRejectEnable = 0x0008U, /*!< Enable broadcast frame reject. */
  214. kENET_ControlMacAddrInsert = 0x0010U, /*!< Enable MAC address insert. */
  215. kENET_ControlStoreAndFwdDisable = 0x0020U, /*!< Enable FIFO store and forward. */
  216. kENET_ControlSMIPreambleDisable = 0x0040U, /*!< Enable SMI preamble. */
  217. kENET_ControlPromiscuousEnable = 0x0080U, /*!< Enable promiscuous mode. */
  218. kENET_ControlMIILoopEnable = 0x0100U, /*!< Enable ENET MII loop back. */
  219. kENET_ControlVLANTagEnable = 0x0200U /*!< Enable VLAN tag frame. */
  220. } enet_special_control_flag_t;
  221. /*! @brief List of interrupts supported by the peripheral. This
  222. * enumeration uses one-bot encoding to allow a logical OR of multiple
  223. * members. Members usually map to interrupt enable bits in one or more
  224. * peripheral registers.
  225. */
  226. typedef enum _enet_interrupt_enable
  227. {
  228. kENET_BabrInterrupt = ENET_EIR_BABR_MASK, /*!< Babbling receive error interrupt source */
  229. kENET_BabtInterrupt = ENET_EIR_BABT_MASK, /*!< Babbling transmit error interrupt source */
  230. kENET_GraceStopInterrupt = ENET_EIR_GRA_MASK, /*!< Graceful stop complete interrupt source */
  231. kENET_TxFrameInterrupt = ENET_EIR_TXF_MASK, /*!< TX FRAME interrupt source */
  232. kENET_TxBufferInterrupt = ENET_EIR_TXB_MASK, /*!< TX BUFFER interrupt source */
  233. kENET_RxFrameInterrupt = ENET_EIR_RXF_MASK, /*!< RX FRAME interrupt source */
  234. kENET_RxBufferInterrupt = ENET_EIR_RXB_MASK, /*!< RX BUFFER interrupt source */
  235. kENET_MiiInterrupt = ENET_EIR_MII_MASK, /*!< MII interrupt source */
  236. kENET_EBusERInterrupt = ENET_EIR_EBERR_MASK, /*!< Ethernet bus error interrupt source */
  237. kENET_LateCollisionInterrupt = ENET_EIR_LC_MASK, /*!< Late collision interrupt source */
  238. kENET_RetryLimitInterrupt = ENET_EIR_RL_MASK, /*!< Collision Retry Limit interrupt source */
  239. kENET_UnderrunInterrupt = ENET_EIR_UN_MASK, /*!< Transmit FIFO underrun interrupt source */
  240. kENET_PayloadRxInterrupt = ENET_EIR_PLR_MASK, /*!< Payload Receive interrupt source */
  241. kENET_WakeupInterrupt = ENET_EIR_WAKEUP_MASK, /*!< WAKEUP interrupt source */
  242. kENET_TsAvailInterrupt = ENET_EIR_TS_AVAIL_MASK, /*!< TS AVAIL interrupt source for PTP */
  243. kENET_TsTimerInterrupt = ENET_EIR_TS_TIMER_MASK /*!< TS WRAP interrupt source for PTP */
  244. } enet_interrupt_enable_t;
  245. /*! @brief Defines the common interrupt event for callback use. */
  246. typedef enum _enet_event
  247. {
  248. kENET_RxEvent, /*!< Receive event. */
  249. kENET_TxEvent, /*!< Transmit event. */
  250. kENET_ErrEvent, /*!< Error event: BABR/BABT/EBERR/LC/RL/UN/PLR . */
  251. kENET_WakeUpEvent, /*!< Wake up from sleep mode event. */
  252. kENET_TimeStampEvent, /*!< Time stamp event. */
  253. kENET_TimeStampAvailEvent /*!< Time stamp available event.*/
  254. } enet_event_t;
  255. /*! @brief Defines the transmit accelerator configuration. */
  256. typedef enum _enet_tx_accelerator
  257. {
  258. kENET_TxAccelIsShift16Enabled = ENET_TACC_SHIFT16_MASK, /*!< Transmit FIFO shift-16. */
  259. kENET_TxAccelIpCheckEnabled = ENET_TACC_IPCHK_MASK, /*!< Insert IP header checksum. */
  260. kENET_TxAccelProtoCheckEnabled = ENET_TACC_PROCHK_MASK /*!< Insert protocol checksum. */
  261. } enet_tx_accelerator_t;
  262. /*! @brief Defines the receive accelerator configuration. */
  263. typedef enum _enet_rx_accelerator
  264. {
  265. kENET_RxAccelPadRemoveEnabled = ENET_RACC_PADREM_MASK, /*!< Padding removal for short IP frames. */
  266. kENET_RxAccelIpCheckEnabled = ENET_RACC_IPDIS_MASK, /*!< Discard with wrong IP header checksum. */
  267. kENET_RxAccelProtoCheckEnabled = ENET_RACC_PRODIS_MASK, /*!< Discard with wrong protocol checksum. */
  268. kENET_RxAccelMacCheckEnabled = ENET_RACC_LINEDIS_MASK, /*!< Discard with Mac layer errors. */
  269. kENET_RxAccelisShift16Enabled = ENET_RACC_SHIFT16_MASK /*!< Receive FIFO shift-16. */
  270. } enet_rx_accelerator_t;
  271. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  272. /*! @brief Defines the ENET PTP message related constant. */
  273. typedef enum _enet_ptp_event_type
  274. {
  275. kENET_PtpEventMsgType = 3U, /*!< PTP event message type. */
  276. kENET_PtpSrcPortIdLen = 10U, /*!< PTP message sequence id length. */
  277. kENET_PtpEventPort = 319U, /*!< PTP event port number. */
  278. kENET_PtpGnrlPort = 320U /*!< PTP general port number. */
  279. } enet_ptp_event_type_t;
  280. /*! @brief Defines the IEEE 1588 PTP timer channel numbers. */
  281. typedef enum _enet_ptp_timer_channel
  282. {
  283. kENET_PtpTimerChannel1 = 0U, /*!< IEEE 1588 PTP timer Channel 1. */
  284. kENET_PtpTimerChannel2, /*!< IEEE 1588 PTP timer Channel 2. */
  285. kENET_PtpTimerChannel3, /*!< IEEE 1588 PTP timer Channel 3. */
  286. kENET_PtpTimerChannel4 /*!< IEEE 1588 PTP timer Channel 4. */
  287. } enet_ptp_timer_channel_t;
  288. /*! @brief Defines the capture or compare mode for IEEE 1588 PTP timer channels. */
  289. typedef enum _enet_ptp_timer_channel_mode
  290. {
  291. kENET_PtpChannelDisable = 0U, /*!< Disable timer channel. */
  292. kENET_PtpChannelRisingCapture = 1U, /*!< Input capture on rising edge. */
  293. kENET_PtpChannelFallingCapture = 2U, /*!< Input capture on falling edge. */
  294. kENET_PtpChannelBothCapture = 3U, /*!< Input capture on both edges. */
  295. kENET_PtpChannelSoftCompare = 4U, /*!< Output compare software only. */
  296. kENET_PtpChannelToggleCompare = 5U, /*!< Toggle output on compare. */
  297. kENET_PtpChannelClearCompare = 6U, /*!< Clear output on compare. */
  298. kENET_PtpChannelSetCompare = 7U, /*!< Set output on compare. */
  299. kENET_PtpChannelClearCompareSetOverflow = 10U, /*!< Clear output on compare, set output on overflow. */
  300. kENET_PtpChannelSetCompareClearOverflow = 11U, /*!< Set output on compare, clear output on overflow. */
  301. kENET_PtpChannelPulseLowonCompare = 14U, /*!< Pulse output low on compare for one IEEE 1588 clock cycle. */
  302. kENET_PtpChannelPulseHighonCompare = 15U /*!< Pulse output high on compare for one IEEE 1588 clock cycle. */
  303. } enet_ptp_timer_channel_mode_t;
  304. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  305. /*! @brief Defines the receive buffer descriptor structure for the little endian system.*/
  306. typedef struct _enet_rx_bd_struct
  307. {
  308. uint16_t length; /*!< Buffer descriptor data length. */
  309. uint16_t control; /*!< Buffer descriptor control and status. */
  310. uint8_t *buffer; /*!< Data buffer pointer. */
  311. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  312. uint16_t controlExtend0; /*!< Extend buffer descriptor control0. */
  313. uint16_t controlExtend1; /*!< Extend buffer descriptor control1. */
  314. uint16_t payloadCheckSum; /*!< Internal payload checksum. */
  315. uint8_t headerLength; /*!< Header length. */
  316. uint8_t protocolTyte; /*!< Protocol type. */
  317. uint16_t reserved0;
  318. uint16_t controlExtend2; /*!< Extend buffer descriptor control2. */
  319. uint32_t timestamp; /*!< Timestamp. */
  320. uint16_t reserved1;
  321. uint16_t reserved2;
  322. uint16_t reserved3;
  323. uint16_t reserved4;
  324. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  325. } enet_rx_bd_struct_t;
  326. /*! @brief Defines the enhanced transmit buffer descriptor structure for the little endian system. */
  327. typedef struct _enet_tx_bd_struct
  328. {
  329. uint16_t length; /*!< Buffer descriptor data length. */
  330. uint16_t control; /*!< Buffer descriptor control and status. */
  331. uint8_t *buffer; /*!< Data buffer pointer. */
  332. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  333. uint16_t controlExtend0; /*!< Extend buffer descriptor control0. */
  334. uint16_t controlExtend1; /*!< Extend buffer descriptor control1. */
  335. uint16_t reserved0;
  336. uint16_t reserved1;
  337. uint16_t reserved2;
  338. uint16_t controlExtend2; /*!< Extend buffer descriptor control2. */
  339. uint32_t timestamp; /*!< Timestamp. */
  340. uint16_t reserved3;
  341. uint16_t reserved4;
  342. uint16_t reserved5;
  343. uint16_t reserved6;
  344. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  345. } enet_tx_bd_struct_t;
  346. /*! @brief Defines the ENET data error statistic structure. */
  347. typedef struct _enet_data_error_stats
  348. {
  349. uint32_t statsRxLenGreaterErr; /*!< Receive length greater than RCR[MAX_FL]. */
  350. uint32_t statsRxAlignErr; /*!< Receive non-octet alignment/ */
  351. uint32_t statsRxFcsErr; /*!< Receive CRC error. */
  352. uint32_t statsRxOverRunErr; /*!< Receive over run. */
  353. uint32_t statsRxTruncateErr; /*!< Receive truncate. */
  354. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  355. uint32_t statsRxProtocolChecksumErr; /*!< Receive protocol checksum error. */
  356. uint32_t statsRxIpHeadChecksumErr; /*!< Receive IP header checksum error. */
  357. uint32_t statsRxMacErr; /*!< Receive Mac error. */
  358. uint32_t statsRxPhyErr; /*!< Receive PHY error. */
  359. uint32_t statsRxCollisionErr; /*!< Receive collision. */
  360. uint32_t statsTxErr; /*!< The error happen when transmit the frame. */
  361. uint32_t statsTxFrameErr; /*!< The transmit frame is error. */
  362. uint32_t statsTxOverFlowErr; /*!< Transmit overflow. */
  363. uint32_t statsTxLateCollisionErr; /*!< Transmit late collision. */
  364. uint32_t statsTxExcessCollisionErr; /*!< Transmit excess collision.*/
  365. uint32_t statsTxUnderFlowErr; /*!< Transmit under flow error. */
  366. uint32_t statsTxTsErr; /*!< Transmit time stamp error. */
  367. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  368. } enet_data_error_stats_t;
  369. /*! @brief Defines the receive buffer descriptor configuration structure.
  370. *
  371. * Note that for the internal DMA requirements, the buffers have a corresponding alignment requirements.
  372. * 1. The aligned receive and transmit buffer size must be evenly divisible by ENET_BUFF_ALIGNMENT.
  373. * when the data buffers are in cacheable region when cache is enabled, all those size should be
  374. * aligned to the maximum value of "ENET_BUFF_ALIGNMENT" and the cache line size.
  375. * 2. The aligned transmit and receive buffer descriptor start address must be at
  376. * least 64 bit aligned. However, it's recommended to be evenly divisible by ENET_BUFF_ALIGNMENT.
  377. * buffer descriptors should be put in non-cacheable region when cache is enabled.
  378. * 3. The aligned transmit and receive data buffer start address must be evenly divisible by ENET_BUFF_ALIGNMENT.
  379. * Receive buffers should be continuous with the total size equal to "rxBdNumber * rxBuffSizeAlign".
  380. * Transmit buffers should be continuous with the total size equal to "txBdNumber * txBuffSizeAlign".
  381. * when the data buffers are in cacheable region when cache is enabled, all those size should be
  382. * aligned to the maximum value of "ENET_BUFF_ALIGNMENT" and the cache line size.
  383. */
  384. typedef struct _enet_buffer_config
  385. {
  386. uint16_t rxBdNumber; /*!< Receive buffer descriptor number. */
  387. uint16_t txBdNumber; /*!< Transmit buffer descriptor number. */
  388. uint32_t rxBuffSizeAlign; /*!< Aligned receive data buffer size. */
  389. uint32_t txBuffSizeAlign; /*!< Aligned transmit data buffer size. */
  390. volatile enet_rx_bd_struct_t *rxBdStartAddrAlign; /*!< Aligned receive buffer descriptor start address. */
  391. volatile enet_tx_bd_struct_t *txBdStartAddrAlign; /*!< Aligned transmit buffer descriptor start address. */
  392. uint8_t *rxBufferAlign; /*!< Receive data buffer start address. */
  393. uint8_t *txBufferAlign; /*!< Transmit data buffer start address. */
  394. void *rxPhyBdStartAddrAlign; /*!< Aligned receive buffer descriptor physical start address. */
  395. void *txPhyBdStartAddrAlign; /*!< Aligned transmit buffer descriptor physical start address. */
  396. uint8_t *rxPhyBufferAlign; /*!< Receive data buffer physical start address. */
  397. uint8_t *txPhyBufferAlign; /*!< Transmit data buffer physical start address. */
  398. uint32_t rxBufferTotalSize; /*!< Receive data buffer max size. */
  399. uint32_t txBufferTotalSize; /*!< Transmit data buffer max size. */
  400. } enet_buffer_config_t;
  401. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  402. /*! @brief Defines the ENET PTP time stamp structure. */
  403. typedef struct _enet_ptp_time
  404. {
  405. uint64_t second; /*!< Second. */
  406. uint32_t nanosecond; /*!< Nanosecond. */
  407. } enet_ptp_time_t;
  408. /*! @brief Defines the structure for the ENET PTP message data and timestamp data.*/
  409. typedef struct _enet_ptp_time_data
  410. {
  411. uint8_t version; /*!< PTP version. */
  412. uint8_t sourcePortId[kENET_PtpSrcPortIdLen]; /*!< PTP source port ID. */
  413. uint16_t sequenceId; /*!< PTP sequence ID. */
  414. uint8_t messageType; /*!< PTP message type. */
  415. enet_ptp_time_t timeStamp; /*!< PTP timestamp. */
  416. } enet_ptp_time_data_t;
  417. /*! @brief Defines the ENET PTP ring buffer structure for the PTP message timestamp store.*/
  418. typedef struct _enet_ptp_time_data_ring
  419. {
  420. uint32_t front; /*!< The first index of the ring. */
  421. uint32_t end; /*!< The end index of the ring. */
  422. uint32_t size; /*!< The size of the ring. */
  423. enet_ptp_time_data_t *ptpTsData; /*!< PTP message data structure. */
  424. } enet_ptp_time_data_ring_t;
  425. /*! @brief Defines the ENET PTP configuration structure. */
  426. typedef struct _enet_ptp_config
  427. {
  428. uint8_t ptpTsRxBuffNum; /*!< Receive 1588 timestamp buffer number*/
  429. uint8_t ptpTsTxBuffNum; /*!< Transmit 1588 timestamp buffer number*/
  430. enet_ptp_time_data_t *rxPtpTsData; /*!< The start address of 1588 receive timestamp buffers */
  431. enet_ptp_time_data_t *txPtpTsData; /*!< The start address of 1588 transmit timestamp buffers */
  432. enet_ptp_timer_channel_t channel; /*!< Used for ERRATA_2579: the PTP 1588 timer channel for time interrupt. */
  433. uint32_t ptp1588ClockSrc_Hz; /*!< The clock source of the PTP 1588 timer. */
  434. } enet_ptp_config_t;
  435. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  436. #if defined (FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE) && FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE
  437. /*! @brief Defines the interrupt coalescing configure structure. */
  438. typedef struct _enet_intcoalesce_config
  439. {
  440. uint8_t txCoalesceFrameCount[FSL_FEATURE_ENET_QUEUE]; /*!< Transmit interrupt coalescing frame count threshold. */
  441. uint16_t txCoalesceTimeCount[FSL_FEATURE_ENET_QUEUE]; /*!< Transmit interrupt coalescing timer count threshold. */
  442. uint8_t rxCoalesceFrameCount[FSL_FEATURE_ENET_QUEUE]; /*!< Receive interrupt coalescing frame count threshold. */
  443. uint16_t rxCoalesceTimeCount[FSL_FEATURE_ENET_QUEUE]; /*!< Receive interrupt coalescing timer count threshold. */
  444. } enet_intcoalesce_config_t;
  445. #endif /* FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE */
  446. /*! @brief Defines the basic configuration structure for the ENET device.
  447. *
  448. * Note:
  449. * 1. macSpecialConfig is used for a special control configuration, a logical OR of
  450. * "enet_special_control_flag_t". For a special configuration for MAC,
  451. * set this parameter to 0.
  452. * 2. txWatermark is used for a cut-through operation. It is in steps of 64 bytes.
  453. * 0/1 - 64 bytes written to TX FIFO before transmission of a frame begins.
  454. * 2 - 128 bytes written to TX FIFO ....
  455. * 3 - 192 bytes written to TX FIFO ....
  456. * The maximum of txWatermark is 0x2F - 4032 bytes written to TX FIFO.
  457. * txWatermark allows minimizing the transmit latency to set the txWatermark to 0 or 1
  458. * or for larger bus access latency 3 or larger due to contention for the system bus.
  459. * 3. rxFifoFullThreshold is similar to the txWatermark for cut-through operation in RX.
  460. * It is in 64-bit words. The minimum is ENET_FIFO_MIN_RX_FULL and the maximum is 0xFF.
  461. * If the end of the frame is stored in FIFO and the frame size if smaller than the
  462. * txWatermark, the frame is still transmitted. The rule is the
  463. * same for rxFifoFullThreshold in the receive direction.
  464. * 4. When "kENET_ControlFlowControlEnable" is set in the macSpecialConfig, ensure
  465. * that the pauseDuration, rxFifoEmptyThreshold, and rxFifoStatEmptyThreshold
  466. * are set for flow control enabled case.
  467. * 5. When "kENET_ControlStoreAndFwdDisabled" is set in the macSpecialConfig, ensure
  468. * that the rxFifoFullThreshold and txFifoWatermark are set for store and forward disable.
  469. * 6. The rxAccelerConfig and txAccelerConfig default setting with 0 - accelerator
  470. * are disabled. The "enet_tx_accelerator_t" and "enet_rx_accelerator_t" are
  471. * recommended to be used to enable the transmit and receive accelerator.
  472. * After the accelerators are enabled, the store and forward feature should be enabled.
  473. * As a result, kENET_ControlStoreAndFwdDisabled should not be set.
  474. */
  475. typedef struct _enet_config
  476. {
  477. uint32_t macSpecialConfig; /*!< Mac special configuration. A logical OR of "enet_special_control_flag_t". */
  478. uint32_t interrupt; /*!< Mac interrupt source. A logical OR of "enet_interrupt_enable_t". */
  479. uint16_t rxMaxFrameLen; /*!< Receive maximum frame length. */
  480. enet_mii_mode_t miiMode; /*!< MII mode. */
  481. enet_mii_speed_t miiSpeed; /*!< MII Speed. */
  482. enet_mii_duplex_t miiDuplex; /*!< MII duplex. */
  483. uint8_t rxAccelerConfig; /*!< Receive accelerator, A logical OR of "enet_rx_accelerator_t". */
  484. uint8_t txAccelerConfig; /*!< Transmit accelerator, A logical OR of "enet_rx_accelerator_t". */
  485. uint16_t pauseDuration; /*!< For flow control enabled case: Pause duration. */
  486. uint8_t rxFifoEmptyThreshold; /*!< For flow control enabled case: when RX FIFO level reaches this value,
  487. it makes MAC generate XOFF pause frame. */
  488. #if defined (FSL_FEATURE_ENET_HAS_RECEIVE_STATUS_THRESHOLD) && FSL_FEATURE_ENET_HAS_RECEIVE_STATUS_THRESHOLD
  489. uint8_t rxFifoStatEmptyThreshold; /*!< For flow control enabled case: number of frames in the receive FIFO,
  490. independent of size, that can be accept. If the limit is reached, reception
  491. continues and a pause frame is triggered. */
  492. #endif /* FSL_FEATURE_ENET_HAS_RECEIVE_STATUS_THRESHOLD */
  493. uint8_t rxFifoFullThreshold; /*!< For store and forward disable case, the data required in RX FIFO to notify
  494. the MAC receive ready status. */
  495. uint8_t txFifoWatermark; /*!< For store and forward disable case, the data required in TX FIFO
  496. before a frame transmit start. */
  497. #if defined (FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE) && FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE
  498. enet_intcoalesce_config_t *intCoalesceCfg; /* If the interrupt coalsecence is not required in the ring n(0,1,2), please set
  499. to NULL. */
  500. #endif /* FSL_FEATURE_ENET_HAS_INTERRUPT_COALESCE */
  501. } enet_config_t;
  502. /* Forward declaration of the handle typedef. */
  503. typedef struct _enet_handle enet_handle_t;
  504. /*! @brief ENET callback function. */
  505. typedef void (*enet_callback_t)(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *userData);
  506. /*! @brief Defines the ENET handler structure. */
  507. struct _enet_handle
  508. {
  509. volatile enet_rx_bd_struct_t *rxBdBase; /*!< Receive buffer descriptor base address pointer. */
  510. volatile enet_rx_bd_struct_t *rxBdCurrent; /*!< The current available receive buffer descriptor pointer. */
  511. volatile enet_tx_bd_struct_t *txBdBase; /*!< Transmit buffer descriptor base address pointer. */
  512. volatile enet_tx_bd_struct_t *txBdCurrent; /*!< The current available transmit buffer descriptor pointer. */
  513. uint32_t rxBuffSizeAlign; /*!< Receive buffer size alignment. */
  514. uint32_t txBuffSizeAlign; /*!< Transmit buffer size alignment. */
  515. enet_callback_t callback; /*!< Callback function. */
  516. void *userData; /*!< Callback function parameter.*/
  517. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  518. volatile enet_tx_bd_struct_t *txBdDirtyStatic; /*!< The dirty transmit buffer descriptor for error static update. */
  519. volatile enet_tx_bd_struct_t *txBdDirtyTime; /*!< The dirty transmit buffer descriptor for time stamp update. */
  520. uint64_t msTimerSecond; /*!< The second for Master PTP timer .*/
  521. enet_ptp_time_data_ring_t rxPtpTsDataRing; /*!< Receive PTP 1588 time stamp data ring buffer. */
  522. enet_ptp_time_data_ring_t txPtpTsDataRing; /*!< Transmit PTP 1588 time stamp data ring buffer. */
  523. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  524. };
  525. /*******************************************************************************
  526. * API
  527. ******************************************************************************/
  528. #if defined(__cplusplus)
  529. extern "C" {
  530. #endif
  531. /*!
  532. * @name Initialization and de-initialization
  533. * @{
  534. */
  535. /*!
  536. * @brief Gets the ENET default configuration structure.
  537. *
  538. * The purpose of this API is to get the default ENET MAC controller
  539. * configuration structure for ENET_Init(). Users may use the initialized
  540. * structure unchanged in ENET_Init() or modify fields of the
  541. * structure before calling ENET_Init().
  542. * This is an example.
  543. @code
  544. enet_config_t config;
  545. ENET_GetDefaultConfig(&config);
  546. @endcode
  547. * @param config The ENET mac controller configuration structure pointer.
  548. */
  549. void ENET_GetDefaultConfig(enet_config_t *config);
  550. /*!
  551. * @brief Initializes the ENET module.
  552. *
  553. * This function ungates the module clock and initializes it with the ENET configuration.
  554. *
  555. * @param base ENET peripheral base address.
  556. * @param handle ENET handler pointer.
  557. * @param config ENET Mac configuration structure pointer.
  558. * The "enet_config_t" type mac configuration return from ENET_GetDefaultConfig
  559. * can be used directly. It is also possible to verify the Mac configuration using other methods.
  560. * @param bufferConfig ENET buffer configuration structure pointer.
  561. * The buffer configuration should be prepared for ENET Initialization.
  562. * @param macAddr ENET mac address of the Ethernet device. This Mac address should be
  563. * provided.
  564. * @param srcClock_Hz The internal module clock source for MII clock.
  565. *
  566. * @note ENET has two buffer descriptors legacy buffer descriptors and
  567. * enhanced IEEE 1588 buffer descriptors. The legacy descriptor is used by default. To
  568. * use the IEEE 1588 feature, use the enhanced IEEE 1588 buffer descriptor
  569. * by defining "ENET_ENHANCEDBUFFERDESCRIPTOR_MODE" and calling ENET_Ptp1588Configure()
  570. * to configure the 1588 feature and related buffers after calling ENET_Init().
  571. */
  572. void ENET_Init(ENET_Type *base,
  573. enet_handle_t *handle,
  574. const enet_config_t *config,
  575. const enet_buffer_config_t *bufferConfig,
  576. uint8_t *macAddr,
  577. uint32_t srcClock_Hz);
  578. /*!
  579. * @brief Deinitializes the ENET module.
  580. * This function gates the module clock, clears ENET interrupts, and disables the ENET module.
  581. *
  582. * @param base ENET peripheral base address.
  583. */
  584. void ENET_Deinit(ENET_Type *base);
  585. /*!
  586. * @brief Resets the ENET module.
  587. *
  588. * This function restores the ENET module to the reset state.
  589. * Note that this function sets all registers to the
  590. * reset state. As a result, the ENET module can't work after calling this function.
  591. *
  592. * @param base ENET peripheral base address.
  593. */
  594. static inline void ENET_Reset(ENET_Type *base)
  595. {
  596. base->ECR |= ENET_ECR_RESET_MASK;
  597. }
  598. /* @} */
  599. /*!
  600. * @name MII interface operation
  601. * @{
  602. */
  603. /*!
  604. * @brief Sets the ENET MII speed and duplex.
  605. *
  606. * @param base ENET peripheral base address.
  607. * @param speed The speed of the RMII mode.
  608. * @param duplex The duplex of the RMII mode.
  609. */
  610. void ENET_SetMII(ENET_Type *base, enet_mii_speed_t speed, enet_mii_duplex_t duplex);
  611. /*!
  612. * @brief Sets the ENET SMI (serial management interface) - MII management interface.
  613. *
  614. * @param base ENET peripheral base address.
  615. * @param srcClock_Hz This is the ENET module clock frequency. Normally it's the system clock. See clock distribution.
  616. * @param isPreambleDisabled The preamble disable flag.
  617. * - true Enables the preamble.
  618. * - false Disables the preamble.
  619. */
  620. void ENET_SetSMI(ENET_Type *base, uint32_t srcClock_Hz, bool isPreambleDisabled);
  621. /*!
  622. * @brief Gets the ENET SMI- MII management interface configuration.
  623. *
  624. * This API is used to get the SMI configuration to check whether the MII management
  625. * interface has been set.
  626. *
  627. * @param base ENET peripheral base address.
  628. * @return The SMI setup status true or false.
  629. */
  630. static inline bool ENET_GetSMI(ENET_Type *base)
  631. {
  632. return (0 != (base->MSCR & 0x7E));
  633. }
  634. /*!
  635. * @brief Reads data from the PHY register through an SMI interface.
  636. *
  637. * @param base ENET peripheral base address.
  638. * @return The data read from PHY
  639. */
  640. static inline uint32_t ENET_ReadSMIData(ENET_Type *base)
  641. {
  642. return (uint32_t)((base->MMFR & ENET_MMFR_DATA_MASK) >> ENET_MMFR_DATA_SHIFT);
  643. }
  644. /*!
  645. * @brief Starts an SMI (Serial Management Interface) read command.
  646. *
  647. * @param base ENET peripheral base address.
  648. * @param phyAddr The PHY address.
  649. * @param phyReg The PHY register.
  650. * @param operation The read operation.
  651. */
  652. void ENET_StartSMIRead(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, enet_mii_read_t operation);
  653. /*!
  654. * @brief Starts an SMI write command.
  655. *
  656. * @param base ENET peripheral base address.
  657. * @param phyAddr The PHY address.
  658. * @param phyReg The PHY register.
  659. * @param operation The write operation.
  660. * @param data The data written to PHY.
  661. */
  662. void ENET_StartSMIWrite(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, enet_mii_write_t operation, uint32_t data);
  663. #if defined (FSL_FEATURE_ENET_HAS_EXTEND_MDIO) && FSL_FEATURE_ENET_HAS_EXTEND_MDIO
  664. /*!
  665. * @brief Starts the extended IEEE802.3 Clause 45 MDIO format SMI read command.
  666. *
  667. * @param base ENET peripheral base address.
  668. * @param phyAddr The PHY address.
  669. * @param phyReg The PHY register. For MDIO IEEE802.3 Clause 45,
  670. * the phyReg is a 21-bits combination of the devaddr (5 bits device address)
  671. * and the regAddr (16 bits phy register): phyReg = (devaddr << 16) | regAddr.
  672. */
  673. void ENET_StartExtC45SMIRead(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg);
  674. /*!
  675. * @brief Starts the extended IEEE802.3 Clause 45 MDIO format SMI write command.
  676. *
  677. * @param base ENET peripheral base address.
  678. * @param phyAddr The PHY address.
  679. * @param phyReg The PHY register. For MDIO IEEE802.3 Clause 45,
  680. * the phyReg is a 21-bits combination of the devaddr (5 bits device address)
  681. * and the regAddr (16 bits phy register): phyReg = (devaddr << 16) | regAddr.
  682. * @param data The data written to PHY.
  683. */
  684. void ENET_StartExtC45SMIWrite(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t data);
  685. #endif /* FSL_FEATURE_ENET_HAS_EXTEND_MDIO */
  686. /* @} */
  687. /*!
  688. * @name MAC Address Filter
  689. * @{
  690. */
  691. /*!
  692. * @brief Sets the ENET module Mac address.
  693. *
  694. * @param base ENET peripheral base address.
  695. * @param macAddr The six-byte Mac address pointer.
  696. * The pointer is allocated by application and input into the API.
  697. */
  698. void ENET_SetMacAddr(ENET_Type *base, uint8_t *macAddr);
  699. /*!
  700. * @brief Gets the ENET module Mac address.
  701. *
  702. * @param base ENET peripheral base address.
  703. * @param macAddr The six-byte Mac address pointer.
  704. * The pointer is allocated by application and input into the API.
  705. */
  706. void ENET_GetMacAddr(ENET_Type *base, uint8_t *macAddr);
  707. /*!
  708. * @brief Adds the ENET device to a multicast group.
  709. *
  710. * @param base ENET peripheral base address.
  711. * @param address The six-byte multicast group address which is provided by application.
  712. */
  713. void ENET_AddMulticastGroup(ENET_Type *base, uint8_t *address);
  714. /*!
  715. * @brief Moves the ENET device from a multicast group.
  716. *
  717. * @param base ENET peripheral base address.
  718. * @param address The six-byte multicast group address which is provided by application.
  719. */
  720. void ENET_LeaveMulticastGroup(ENET_Type *base, uint8_t *address);
  721. /* @} */
  722. /*!
  723. * @name Other basic operations
  724. * @{
  725. */
  726. /*!
  727. * @brief Activates ENET read or receive.
  728. *
  729. * @param base ENET peripheral base address.
  730. *
  731. * @note This must be called after the MAC configuration and
  732. * state are ready. It must be called after the ENET_Init() and
  733. * ENET_Ptp1588Configure(). This should be called when the ENET receive required.
  734. */
  735. static inline void ENET_ActiveRead(ENET_Type *base)
  736. {
  737. base->RDAR = ENET_RDAR_RDAR_MASK;
  738. }
  739. /*!
  740. * @brief Enables/disables the MAC to enter sleep mode.
  741. * This function is used to set the MAC enter sleep mode.
  742. * When entering sleep mode, the magic frame wakeup interrupt should be enabled
  743. * to wake up MAC from the sleep mode and reset it to normal mode.
  744. *
  745. * @param base ENET peripheral base address.
  746. * @param enable True enable sleep mode, false disable sleep mode.
  747. */
  748. static inline void ENET_EnableSleepMode(ENET_Type *base, bool enable)
  749. {
  750. if (enable)
  751. {
  752. /* When this field is set, MAC enters sleep mode. */
  753. base->ECR |= ENET_ECR_SLEEP_MASK | ENET_ECR_MAGICEN_MASK;
  754. }
  755. else
  756. { /* MAC exits sleep mode. */
  757. base->ECR &= ~(ENET_ECR_SLEEP_MASK | ENET_ECR_MAGICEN_MASK);
  758. }
  759. }
  760. /*!
  761. * @brief Gets ENET transmit and receive accelerator functions from the MAC controller.
  762. *
  763. * @param base ENET peripheral base address.
  764. * @param txAccelOption The transmit accelerator option. The "enet_tx_accelerator_t" is
  765. * recommended as the mask to get the exact the accelerator option.
  766. * @param rxAccelOption The receive accelerator option. The "enet_rx_accelerator_t" is
  767. * recommended as the mask to get the exact the accelerator option.
  768. */
  769. static inline void ENET_GetAccelFunction(ENET_Type *base, uint32_t *txAccelOption, uint32_t *rxAccelOption)
  770. {
  771. assert(txAccelOption);
  772. assert(txAccelOption);
  773. *txAccelOption = base->TACC;
  774. *rxAccelOption = base->RACC;
  775. }
  776. /* @} */
  777. /*!
  778. * @name Interrupts
  779. * @{
  780. */
  781. /*!
  782. * @brief Enables the ENET interrupt.
  783. *
  784. * This function enables the ENET interrupt according to the provided mask. The mask
  785. * is a logical OR of enumeration members. See @ref enet_interrupt_enable_t.
  786. * For example, to enable the TX frame interrupt and RX frame interrupt, do the following.
  787. * @code
  788. * ENET_EnableInterrupts(ENET, kENET_TxFrameInterrupt | kENET_RxFrameInterrupt);
  789. * @endcode
  790. *
  791. * @param base ENET peripheral base address.
  792. * @param mask ENET interrupts to enable. This is a logical OR of the
  793. * enumeration :: enet_interrupt_enable_t.
  794. */
  795. static inline void ENET_EnableInterrupts(ENET_Type *base, uint32_t mask)
  796. {
  797. base->EIMR |= mask;
  798. }
  799. /*!
  800. * @brief Disables the ENET interrupt.
  801. *
  802. * This function disables the ENET interrupts according to the provided mask. The mask
  803. * is a logical OR of enumeration members. See @ref enet_interrupt_enable_t.
  804. * For example, to disable the TX frame interrupt and RX frame interrupt, do the following.
  805. * @code
  806. * ENET_DisableInterrupts(ENET, kENET_TxFrameInterrupt | kENET_RxFrameInterrupt);
  807. * @endcode
  808. *
  809. * @param base ENET peripheral base address.
  810. * @param mask ENET interrupts to disable. This is a logical OR of the
  811. * enumeration :: enet_interrupt_enable_t.
  812. */
  813. static inline void ENET_DisableInterrupts(ENET_Type *base, uint32_t mask)
  814. {
  815. base->EIMR &= ~mask;
  816. }
  817. /*!
  818. * @brief Gets the ENET interrupt status flag.
  819. *
  820. * @param base ENET peripheral base address.
  821. * @return The event status of the interrupt source. This is the logical OR of members
  822. * of the enumeration :: enet_interrupt_enable_t.
  823. */
  824. static inline uint32_t ENET_GetInterruptStatus(ENET_Type *base)
  825. {
  826. return base->EIR;
  827. }
  828. /*!
  829. * @brief Clears the ENET interrupt events status flag.
  830. *
  831. * This function clears enabled ENET interrupts according to the provided mask. The mask
  832. * is a logical OR of enumeration members. See the @ref enet_interrupt_enable_t.
  833. * For example, to clear the TX frame interrupt and RX frame interrupt, do the following.
  834. * @code
  835. * ENET_ClearInterruptStatus(ENET, kENET_TxFrameInterrupt | kENET_RxFrameInterrupt);
  836. * @endcode
  837. *
  838. * @param base ENET peripheral base address.
  839. * @param mask ENET interrupt source to be cleared.
  840. * This is the logical OR of members of the enumeration :: enet_interrupt_enable_t.
  841. */
  842. static inline void ENET_ClearInterruptStatus(ENET_Type *base, uint32_t mask)
  843. {
  844. base->EIR = mask;
  845. }
  846. /* @} */
  847. /*!
  848. * @name Transactional operation
  849. * @{
  850. */
  851. /*!
  852. * @brief Sets the callback function.
  853. * This API is provided for the application callback required case when ENET
  854. * interrupt is enabled. This API should be called after calling ENET_Init.
  855. *
  856. * @param handle ENET handler pointer. Should be provided by application.
  857. * @param callback The ENET callback function.
  858. * @param userData The callback function parameter.
  859. */
  860. void ENET_SetCallback(enet_handle_t *handle, enet_callback_t callback, void *userData);
  861. /*!
  862. * @brief Gets the ENET the error statistics of a received frame.
  863. *
  864. * This API must be called after the ENET_GetRxFrameSize and before the ENET_ReadFrame().
  865. * If the ENET_GetRxFrameSize returns kStatus_ENET_RxFrameError,
  866. * the ENET_GetRxErrBeforeReadFrame can be used to get the exact error statistics.
  867. * This is an example.
  868. * @code
  869. * status = ENET_GetRxFrameSize(&g_handle, &length);
  870. * if (status == kStatus_ENET_RxFrameError)
  871. * {
  872. * // Get the error information of the received frame.
  873. * ENET_GetRxErrBeforeReadFrame(&g_handle, &eErrStatic);
  874. * // update the receive buffer.
  875. * ENET_ReadFrame(EXAMPLE_ENET, &g_handle, NULL, 0);
  876. * }
  877. * @endcode
  878. * @param handle The ENET handler structure pointer. This is the same handler pointer used in the ENET_Init.
  879. * @param eErrorStatic The error statistics structure pointer.
  880. */
  881. void ENET_GetRxErrBeforeReadFrame(enet_handle_t *handle, enet_data_error_stats_t *eErrorStatic);
  882. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  883. /*!
  884. * @brief Gets the ENET transmit frame statistics after the data send.
  885. *
  886. * This interface gets the error statistics of the transmit frame.
  887. * Because the error information is reported by the uDMA after the data delivery, this interface
  888. * should be called after the data transmit API. It is recommended to call this function on
  889. * transmit interrupt handler. After calling the ENET_SendFrame, the
  890. * transmit interrupt notifies the transmit completion.
  891. *
  892. * @param handle The PTP handler pointer. This is the same handler pointer used in the ENET_Init.
  893. * @param eErrorStatic The error statistics structure pointer.
  894. * @return The execute status.
  895. */
  896. status_t ENET_GetTxErrAfterSendFrame(enet_handle_t *handle, enet_data_error_stats_t *eErrorStatic);
  897. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  898. /*!
  899. * @brief Gets the size of the read frame.
  900. * This function gets a received frame size from the ENET buffer descriptors.
  901. * @note The FCS of the frame is automatically removed by Mac and the size is the length without the FCS.
  902. * After calling ENET_GetRxFrameSize, ENET_ReadFrame() should be called to update the
  903. * receive buffers If the result is not "kStatus_ENET_RxFrameEmpty".
  904. *
  905. * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_Init.
  906. * @param length The length of the valid frame received.
  907. * @retval kStatus_ENET_RxFrameEmpty No frame received. Should not call ENET_ReadFrame to read frame.
  908. * @retval kStatus_ENET_RxFrameError Data error happens. ENET_ReadFrame should be called with NULL data
  909. * and NULL length to update the receive buffers.
  910. * @retval kStatus_Success Receive a frame Successfully then the ENET_ReadFrame
  911. * should be called with the right data buffer and the captured data length input.
  912. */
  913. status_t ENET_GetRxFrameSize(enet_handle_t *handle, uint32_t *length);
  914. /*!
  915. * @brief Reads a frame from the ENET device.
  916. * This function reads a frame (both the data and the length) from the ENET buffer descriptors.
  917. * The ENET_GetRxFrameSize should be used to get the size of the prepared data buffer.
  918. * This is an example.
  919. * @code
  920. * uint32_t length;
  921. * enet_handle_t g_handle;
  922. * //Get the received frame size firstly.
  923. * status = ENET_GetRxFrameSize(&g_handle, &length);
  924. * if (length != 0)
  925. * {
  926. * //Allocate memory here with the size of "length"
  927. * uint8_t *data = memory allocate interface;
  928. * if (!data)
  929. * {
  930. * ENET_ReadFrame(ENET, &g_handle, NULL, 0);
  931. * //Add the console warning log.
  932. * }
  933. * else
  934. * {
  935. * status = ENET_ReadFrame(ENET, &g_handle, data, length);
  936. * //Call stack input API to deliver the data to stack
  937. * }
  938. * }
  939. * else if (status == kStatus_ENET_RxFrameError)
  940. * {
  941. * //Update the received buffer when a error frame is received.
  942. * ENET_ReadFrame(ENET, &g_handle, NULL, 0);
  943. * }
  944. * @endcode
  945. * @param base ENET peripheral base address.
  946. * @param handle The ENET handler structure. This is the same handler pointer used in the ENET_Init.
  947. * @param data The data buffer provided by user to store the frame which memory size should be at least "length".
  948. * @param length The size of the data buffer which is still the length of the received frame.
  949. * @return The execute status, successful or failure.
  950. */
  951. status_t ENET_ReadFrame(ENET_Type *base,enet_handle_t *handle,const enet_config_t *config, uint8_t *data,uint16_t *length);
  952. /*!
  953. * @brief Transmits an ENET frame.
  954. * @note The CRC is automatically appended to the data. Input the data
  955. * to send without the CRC.
  956. *
  957. * @param base ENET peripheral base address.
  958. * @param handle The ENET handler pointer. This is the same handler pointer used in the ENET_Init.
  959. * @param data The data buffer provided by user to be send.
  960. * @param length The length of the data to be send.
  961. * @retval kStatus_Success Send frame succeed.
  962. * @retval kStatus_ENET_TxFrameBusy Transmit buffer descriptor is busy under transmission.
  963. * The transmit busy happens when the data send rate is over the MAC capacity.
  964. * The waiting mechanism is recommended to be added after each call return with
  965. * kStatus_ENET_TxFrameBusy.
  966. */
  967. status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *data, uint16_t length,uint32_t last_flag);
  968. /*!
  969. * @brief The transmit IRQ handler.
  970. *
  971. * @param base ENET peripheral base address.
  972. * @param handle The ENET handler pointer.
  973. */
  974. void ENET_TransmitIRQHandler(ENET_Type *base, enet_handle_t *handle);
  975. /*!
  976. * @brief The receive IRQ handler.
  977. *
  978. * @param base ENET peripheral base address.
  979. * @param handle The ENET handler pointer.
  980. */
  981. void ENET_ReceiveIRQHandler(ENET_Type *base, enet_handle_t *handle);
  982. /*!
  983. * @brief The error IRQ handler.
  984. *
  985. * @param base ENET peripheral base address.
  986. * @param handle The ENET handler pointer.
  987. */
  988. void ENET_ErrorIRQHandler(ENET_Type *base, enet_handle_t *handle);
  989. /*!
  990. * @brief the common IRQ handler for the tx/rx/error etc irq handler.
  991. *
  992. * This is used for the combined tx/rx/error interrupt for single ring (ring 0).
  993. *
  994. * @param base ENET peripheral base address.
  995. */
  996. void ENET_CommonFrame0IRQHandler(ENET_Type *base);
  997. /* @} */
  998. /*!
  999. * @brief the common IRQ handler for the tx/rx/error etc irq handler.
  1000. *
  1001. * This is used for the combined tx/rx/error interrupt for single ring (ring 0).
  1002. * @param irq gic interrupt number.
  1003. * @param base ENET peripheral base address.
  1004. */
  1005. void ENET_DriverIRQHandler(int irq, void *base);
  1006. /*!
  1007. * config pin for enet function
  1008. */
  1009. void ENET_InitPins(void);
  1010. #ifdef ENET_ENHANCEDBUFFERDESCRIPTOR_MODE
  1011. /*!
  1012. * @name ENET PTP 1588 function operation
  1013. * @{
  1014. */
  1015. /*!
  1016. * @brief Configures the ENET PTP IEEE 1588 feature with the basic configuration.
  1017. * The function sets the clock for PTP 1588 timer and enables
  1018. * time stamp interrupts and transmit interrupts for PTP 1588 features.
  1019. * This API should be called when the 1588 feature is enabled
  1020. * or the ENET_ENHANCEDBUFFERDESCRIPTOR_MODE is defined.
  1021. * ENET_Init should be called before calling this API.
  1022. *
  1023. * @note The PTP 1588 time-stamp second increase though time-stamp interrupt handler
  1024. * and the transmit time-stamp store is done through transmit interrupt handler.
  1025. * As a result, the TS interrupt and TX interrupt are enabled when you call this API.
  1026. *
  1027. * @param base ENET peripheral base address.
  1028. * @param handle ENET handler pointer.
  1029. * @param ptpConfig The ENET PTP1588 configuration.
  1030. */
  1031. void ENET_Ptp1588Configure(ENET_Type *base, enet_handle_t *handle, enet_ptp_config_t *ptpConfig);
  1032. /*!
  1033. * @brief Starts the ENET PTP 1588 Timer.
  1034. * This function is used to initialize the PTP timer. After the PTP starts,
  1035. * the PTP timer starts running.
  1036. *
  1037. * @param base ENET peripheral base address.
  1038. * @param ptpClkSrc The clock source of the PTP timer.
  1039. */
  1040. void ENET_Ptp1588StartTimer(ENET_Type *base, uint32_t ptpClkSrc);
  1041. /*!
  1042. * @brief Stops the ENET PTP 1588 Timer.
  1043. * This function is used to stops the ENET PTP timer.
  1044. *
  1045. * @param base ENET peripheral base address.
  1046. */
  1047. static inline void ENET_Ptp1588StopTimer(ENET_Type *base)
  1048. {
  1049. /* Disable PTP timer and reset the timer. */
  1050. base->ATCR &= ~ENET_ATCR_EN_MASK;
  1051. base->ATCR |= ENET_ATCR_RESTART_MASK;
  1052. }
  1053. /*!
  1054. * @brief Adjusts the ENET PTP 1588 timer.
  1055. *
  1056. * @param base ENET peripheral base address.
  1057. * @param corrIncrease The correction increment value. This value is added every time the correction
  1058. * timer expires. A value less than the PTP timer frequency(1/ptpClkSrc) slows down the timer,
  1059. * a value greater than the 1/ptpClkSrc speeds up the timer.
  1060. * @param corrPeriod The PTP timer correction counter wrap-around value. This defines after how
  1061. * many timer clock the correction counter should be reset and trigger a correction
  1062. * increment on the timer. A value of 0 disables the correction counter and no correction occurs.
  1063. */
  1064. void ENET_Ptp1588AdjustTimer(ENET_Type *base, uint32_t corrIncrease, uint32_t corrPeriod);
  1065. /*!
  1066. * @brief Sets the ENET PTP 1588 timer channel mode.
  1067. *
  1068. * @param base ENET peripheral base address.
  1069. * @param channel The ENET PTP timer channel number.
  1070. * @param mode The PTP timer channel mode, see "enet_ptp_timer_channel_mode_t".
  1071. * @param intEnable Enables or disables the interrupt.
  1072. */
  1073. static inline void ENET_Ptp1588SetChannelMode(ENET_Type *base,
  1074. enet_ptp_timer_channel_t channel,
  1075. enet_ptp_timer_channel_mode_t mode,
  1076. bool intEnable)
  1077. {
  1078. uint32_t tcrReg = 0;
  1079. tcrReg = ENET_TCSR_TMODE(mode) | ENET_TCSR_TIE(intEnable);
  1080. /* Disable channel mode first. */
  1081. base->CHANNEL[channel].TCSR = 0;
  1082. base->CHANNEL[channel].TCSR = tcrReg;
  1083. }
  1084. #if defined(FSL_FEATURE_ENET_HAS_TIMER_PWCONTROL) && FSL_FEATURE_ENET_HAS_TIMER_PWCONTROL
  1085. /*!
  1086. * @brief Sets ENET PTP 1588 timer channel mode pulse width.
  1087. *
  1088. * For the input "mode" in ENET_Ptp1588SetChannelMode, the kENET_PtpChannelPulseLowonCompare
  1089. * kENET_PtpChannelPulseHighonCompare only support the pulse width for one 1588 clock.
  1090. * this function is extended for control the pulse width from 1 to 32 1588 clock cycles.
  1091. * so call this function if you need to set the timer channel mode for
  1092. * kENET_PtpChannelPulseLowonCompare or kENET_PtpChannelPulseHighonCompare
  1093. * with pulse width more than one 1588 clock,
  1094. *
  1095. * @param base ENET peripheral base address.
  1096. * @param channel The ENET PTP timer channel number.
  1097. * @param isOutputLow True --- timer channel is configured for output compare
  1098. * pulse output low.
  1099. * false --- timer channel is configured for output compare
  1100. * pulse output high.
  1101. * @param pulseWidth The pulse width control value, range from 0 ~ 31.
  1102. * 0 --- pulse width is one 1588 clock cycle.
  1103. * 31 --- pulse width is thirty two 1588 clock cycles.
  1104. * @param intEnable Enables or disables the interrupt.
  1105. */
  1106. static inline void ENET_Ptp1588SetChannelOutputPulseWidth(ENET_Type *base,
  1107. enet_ptp_timer_channel_t channel,
  1108. bool isOutputLow,
  1109. uint8_t pulseWidth,
  1110. bool intEnable)
  1111. {
  1112. uint32_t tcrReg;
  1113. tcrReg = ENET_TCSR_TIE(intEnable) | ENET_TCSR_TPWC(pulseWidth);
  1114. if (isOutputLow)
  1115. {
  1116. tcrReg |= ENET_TCSR_TMODE(kENET_PtpChannelPulseLowonCompare);
  1117. }
  1118. else
  1119. {
  1120. tcrReg |= ENET_TCSR_TMODE(kENET_PtpChannelPulseHighonCompare);
  1121. }
  1122. /* Disable channel mode first. */
  1123. base->CHANNEL[channel].TCSR = 0;
  1124. base->CHANNEL[channel].TCSR = tcrReg;
  1125. }
  1126. #endif /* FSL_FEATURE_ENET_HAS_TIMER_PWCONTROL */
  1127. /*!
  1128. * @brief Sets the ENET PTP 1588 timer channel comparison value.
  1129. *
  1130. * @param base ENET peripheral base address.
  1131. * @param channel The PTP timer channel, see "enet_ptp_timer_channel_t".
  1132. * @param cmpValue The compare value for the compare setting.
  1133. */
  1134. static inline void ENET_Ptp1588SetChannelCmpValue(ENET_Type *base, enet_ptp_timer_channel_t channel, uint32_t cmpValue)
  1135. {
  1136. base->CHANNEL[channel].TCCR = cmpValue;
  1137. }
  1138. /*!
  1139. * @brief Gets the ENET PTP 1588 timer channel status.
  1140. *
  1141. * @param base ENET peripheral base address.
  1142. * @param channel The IEEE 1588 timer channel number.
  1143. * @return True or false, Compare or capture operation status
  1144. */
  1145. static inline bool ENET_Ptp1588GetChannelStatus(ENET_Type *base, enet_ptp_timer_channel_t channel)
  1146. {
  1147. return (0 != (base->CHANNEL[channel].TCSR & ENET_TCSR_TF_MASK));
  1148. }
  1149. /*!
  1150. * @brief Clears the ENET PTP 1588 timer channel status.
  1151. *
  1152. * @param base ENET peripheral base address.
  1153. * @param channel The IEEE 1588 timer channel number.
  1154. */
  1155. static inline void ENET_Ptp1588ClearChannelStatus(ENET_Type *base, enet_ptp_timer_channel_t channel)
  1156. {
  1157. base->CHANNEL[channel].TCSR |= ENET_TCSR_TF_MASK;
  1158. base->TGSR = (1U << channel);
  1159. }
  1160. /*!
  1161. * @brief Gets the current ENET time from the PTP 1588 timer.
  1162. *
  1163. * @param base ENET peripheral base address.
  1164. * @param handle The ENET state pointer. This is the same state pointer used in the ENET_Init.
  1165. * @param ptpTime The PTP timer structure.
  1166. */
  1167. void ENET_Ptp1588GetTimer(ENET_Type *base, enet_handle_t *handle, enet_ptp_time_t *ptpTime);
  1168. /*!
  1169. * @brief Sets the ENET PTP 1588 timer to the assigned time.
  1170. *
  1171. * @param base ENET peripheral base address.
  1172. * @param handle The ENET state pointer. This is the same state pointer used in the ENET_Init.
  1173. * @param ptpTime The timer to be set to the PTP timer.
  1174. */
  1175. void ENET_Ptp1588SetTimer(ENET_Type *base, enet_handle_t *handle, enet_ptp_time_t *ptpTime);
  1176. /*!
  1177. * @brief The IEEE 1588 PTP time stamp interrupt handler.
  1178. *
  1179. * @param base ENET peripheral base address.
  1180. * @param handle The ENET state pointer. This is the same state pointer used in the ENET_Init.
  1181. */
  1182. void ENET_Ptp1588TimerIRQHandler(ENET_Type *base, enet_handle_t *handle);
  1183. /*!
  1184. * @brief Gets the time stamp of the received frame.
  1185. *
  1186. * This function is used for PTP stack to get the timestamp captured by the ENET driver.
  1187. *
  1188. * @param handle The ENET handler pointer.This is the same state pointer used in
  1189. * ENET_Init.
  1190. * @param ptpTimeData The special PTP timestamp data for search the receive timestamp.
  1191. * @retval kStatus_Success Get 1588 timestamp success.
  1192. * @retval kStatus_ENET_PtpTsRingEmpty 1588 timestamp ring empty.
  1193. * @retval kStatus_ENET_PtpTsRingFull 1588 timestamp ring full.
  1194. */
  1195. status_t ENET_GetRxFrameTime(enet_handle_t *handle, enet_ptp_time_data_t *ptpTimeData);
  1196. /*!
  1197. * @brief Gets the time stamp of the transmit frame.
  1198. *
  1199. * This function is used for PTP stack to get the timestamp captured by the ENET driver.
  1200. *
  1201. * @param handle The ENET handler pointer.This is the same state pointer used in
  1202. * ENET_Init.
  1203. * @param ptpTimeData The special PTP timestamp data for search the receive timestamp.
  1204. * @retval kStatus_Success Get 1588 timestamp success.
  1205. * @retval kStatus_ENET_PtpTsRingEmpty 1588 timestamp ring empty.
  1206. * @retval kStatus_ENET_PtpTsRingFull 1588 timestamp ring full.
  1207. */
  1208. status_t ENET_GetTxFrameTime(enet_handle_t *handle, enet_ptp_time_data_t *ptpTimeData);
  1209. #endif /* ENET_ENHANCEDBUFFERDESCRIPTOR_MODE */
  1210. /* @} */
  1211. #if defined(__cplusplus)
  1212. }
  1213. #endif
  1214. /*! @}*/
  1215. #endif /* _FSL_ENET_H_ */