mbed(SerialHalfDuplex入り)
Fork of mbed by
TARGET_K64F/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/drivers/enet/fsl_enet_driver.h@83:8a40adfe8776, 2014-04-28 (annotated)
- Committer:
- bogdanm
- Date:
- Mon Apr 28 17:39:05 2014 +0100
- Revision:
- 83:8a40adfe8776
- Child:
- 90:cb3d968589d8
Release 83 of the mbed library
Main changes:
- updated tests
- K64F TCP/IP support
- lots of fixes in various targets
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 83:8a40adfe8776 | 1 | /* |
bogdanm | 83:8a40adfe8776 | 2 | * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc. |
bogdanm | 83:8a40adfe8776 | 3 | * All rights reserved. |
bogdanm | 83:8a40adfe8776 | 4 | * |
bogdanm | 83:8a40adfe8776 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
bogdanm | 83:8a40adfe8776 | 6 | * are permitted provided that the following conditions are met: |
bogdanm | 83:8a40adfe8776 | 7 | * |
bogdanm | 83:8a40adfe8776 | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
bogdanm | 83:8a40adfe8776 | 9 | * of conditions and the following disclaimer. |
bogdanm | 83:8a40adfe8776 | 10 | * |
bogdanm | 83:8a40adfe8776 | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
bogdanm | 83:8a40adfe8776 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
bogdanm | 83:8a40adfe8776 | 13 | * other materials provided with the distribution. |
bogdanm | 83:8a40adfe8776 | 14 | * |
bogdanm | 83:8a40adfe8776 | 15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
bogdanm | 83:8a40adfe8776 | 16 | * contributors may be used to endorse or promote products derived from this |
bogdanm | 83:8a40adfe8776 | 17 | * software without specific prior written permission. |
bogdanm | 83:8a40adfe8776 | 18 | * |
bogdanm | 83:8a40adfe8776 | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
bogdanm | 83:8a40adfe8776 | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
bogdanm | 83:8a40adfe8776 | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bogdanm | 83:8a40adfe8776 | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
bogdanm | 83:8a40adfe8776 | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
bogdanm | 83:8a40adfe8776 | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
bogdanm | 83:8a40adfe8776 | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
bogdanm | 83:8a40adfe8776 | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
bogdanm | 83:8a40adfe8776 | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
bogdanm | 83:8a40adfe8776 | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bogdanm | 83:8a40adfe8776 | 29 | */ |
bogdanm | 83:8a40adfe8776 | 30 | #ifndef __FSL_ENET_DRIVER_H__ |
bogdanm | 83:8a40adfe8776 | 31 | #define __FSL_ENET_DRIVER_H__ |
bogdanm | 83:8a40adfe8776 | 32 | |
bogdanm | 83:8a40adfe8776 | 33 | #include <stdint.h> |
bogdanm | 83:8a40adfe8776 | 34 | #include <stdbool.h> |
bogdanm | 83:8a40adfe8776 | 35 | #include "fsl_enet_hal.h" |
bogdanm | 83:8a40adfe8776 | 36 | #include "fsl_os_abstraction.h" |
bogdanm | 83:8a40adfe8776 | 37 | /*! |
bogdanm | 83:8a40adfe8776 | 38 | * @addtogroup enet_driver |
bogdanm | 83:8a40adfe8776 | 39 | * @{ |
bogdanm | 83:8a40adfe8776 | 40 | */ |
bogdanm | 83:8a40adfe8776 | 41 | |
bogdanm | 83:8a40adfe8776 | 42 | /******************************************************************************* |
bogdanm | 83:8a40adfe8776 | 43 | * Definitions |
bogdanm | 83:8a40adfe8776 | 44 | |
bogdanm | 83:8a40adfe8776 | 45 | ******************************************************************************/ |
bogdanm | 83:8a40adfe8776 | 46 | /*! @brief Defines the approach: ENET interrupt handler do receive */ |
bogdanm | 83:8a40adfe8776 | 47 | #define ENET_RECEIVE_ALL_INTERRUPT 0 |
bogdanm | 83:8a40adfe8776 | 48 | |
bogdanm | 83:8a40adfe8776 | 49 | /*! @brief Defines the statistic enable macro.*/ |
bogdanm | 83:8a40adfe8776 | 50 | #define ENET_ENABLE_DETAIL_STATS 0 |
bogdanm | 83:8a40adfe8776 | 51 | |
bogdanm | 83:8a40adfe8776 | 52 | /*! @brief Defines the alignment operation.*/ |
bogdanm | 83:8a40adfe8776 | 53 | #define ENET_ALIGN(x,align) ((unsigned int)((x) + ((align)-1)) & (unsigned int)(~(unsigned int)((align)- 1))) |
bogdanm | 83:8a40adfe8776 | 54 | |
bogdanm | 83:8a40adfe8776 | 55 | #if FSL_FEATURE_ENET_SUPPORT_PTP |
bogdanm | 83:8a40adfe8776 | 56 | /*! @brief Defines the PTP IOCTL macro.*/ |
bogdanm | 83:8a40adfe8776 | 57 | typedef enum _enet_ptp_ioctl |
bogdanm | 83:8a40adfe8776 | 58 | { |
bogdanm | 83:8a40adfe8776 | 59 | kEnetPtpGetRxTimestamp = 0, /*!< ENET PTP gets receive timestamp*/ |
bogdanm | 83:8a40adfe8776 | 60 | kEnetPtpGetTxTimestamp, /*!< ENET PTP gets transmit timestamp*/ |
bogdanm | 83:8a40adfe8776 | 61 | kEnetPtpGetCurrentTime, /*!< ENET PTP gets current time*/ |
bogdanm | 83:8a40adfe8776 | 62 | kEnetPtpSetCurrentTime, /*!< ENET PTP sets current time*/ |
bogdanm | 83:8a40adfe8776 | 63 | kEnetPtpFlushTimestamp, /*!< ENET PTP flushes timestamp*/ |
bogdanm | 83:8a40adfe8776 | 64 | kEnetPtpCorrectTime, /*!< ENET PTP time correction*/ |
bogdanm | 83:8a40adfe8776 | 65 | kEnetPtpSendEthernetPtpV2, /*!< ENET PTPv2 sends Ethernet frame*/ |
bogdanm | 83:8a40adfe8776 | 66 | kEnetPtpReceiveEthernetPtpV2 /*!< ENET PTPv2 receives with Ethernet frame*/ |
bogdanm | 83:8a40adfe8776 | 67 | } enet_ptp_ioctl_t; |
bogdanm | 83:8a40adfe8776 | 68 | |
bogdanm | 83:8a40adfe8776 | 69 | /*! @brief Defines the PTP message buffer number.*/ |
bogdanm | 83:8a40adfe8776 | 70 | typedef enum _enet_ptp_buffer_number |
bogdanm | 83:8a40adfe8776 | 71 | { |
bogdanm | 83:8a40adfe8776 | 72 | kEnetPtpL2bufferNumber = 10, /*!< PTP layer2 frame buffer number*/ |
bogdanm | 83:8a40adfe8776 | 73 | kEnetPtpRingNumber = 25 /*!< PTP Ring buffer number*/ |
bogdanm | 83:8a40adfe8776 | 74 | } enet_ptp_buffer_number_t; |
bogdanm | 83:8a40adfe8776 | 75 | |
bogdanm | 83:8a40adfe8776 | 76 | /*! @brief Defines the ENET PTP message related constant.*/ |
bogdanm | 83:8a40adfe8776 | 77 | typedef enum _enet_ptp_event_type |
bogdanm | 83:8a40adfe8776 | 78 | { |
bogdanm | 83:8a40adfe8776 | 79 | kEnetPtpSourcePortIdLen = 10, /*!< PTP message sequence id length*/ |
bogdanm | 83:8a40adfe8776 | 80 | kEnetPtpEventMsgType = 3, /*!< PTP event message type*/ |
bogdanm | 83:8a40adfe8776 | 81 | kEnetPtpEventPort = 319, /*!< PTP event port number*/ |
bogdanm | 83:8a40adfe8776 | 82 | kEnetPtpGnrlPort = 320 /*!< PTP general port number*/ |
bogdanm | 83:8a40adfe8776 | 83 | } enet_ptp_event_type_t; |
bogdanm | 83:8a40adfe8776 | 84 | |
bogdanm | 83:8a40adfe8776 | 85 | /*! @brief Defines all ENET PTP content offsets in the IPv4 PTP UDP/IP multicast message.*/ |
bogdanm | 83:8a40adfe8776 | 86 | typedef enum _enet_ipv4_ptp_content_offset |
bogdanm | 83:8a40adfe8776 | 87 | { |
bogdanm | 83:8a40adfe8776 | 88 | kEnetPtpIpVersionOffset = 0xe, /*!< IPv4 PTP message IP version offset*/ |
bogdanm | 83:8a40adfe8776 | 89 | kEnetPtpUdpProtocolOffset = 0x17,/*!< IPv4 PTP message UDP protocol offset*/ |
bogdanm | 83:8a40adfe8776 | 90 | kEnetPtpUdpPortOffset = 0x24, /*!< IPv4 PTP message UDP port offset*/ |
bogdanm | 83:8a40adfe8776 | 91 | kEnetPtpUdpMsgTypeOffset = 0x2a, /*!< IPv4 PTP message UDP message type offset*/ |
bogdanm | 83:8a40adfe8776 | 92 | kEnetPtpUdpVersionoffset = 0x2b, /*!< IPv4 PTP message UDP version offset*/ |
bogdanm | 83:8a40adfe8776 | 93 | kEnetPtpUdpClockIdOffset = 0x3e, /*!< IPv4 PTP message UDP clock id offset*/ |
bogdanm | 83:8a40adfe8776 | 94 | kEnetPtpUdpSequenIdOffset = 0x48,/*!< IPv4 PTP message UDP sequence id offset*/ |
bogdanm | 83:8a40adfe8776 | 95 | kEnetPtpUdpCtlOffset = 0x4a /*!< IPv4 PTP message UDP control offset*/ |
bogdanm | 83:8a40adfe8776 | 96 | } enet_ipv4_ptp_content_offset_t; |
bogdanm | 83:8a40adfe8776 | 97 | |
bogdanm | 83:8a40adfe8776 | 98 | /*! @brief Defines all ENET PTP content offset in THE IPv6 PTP UDP/IP multicast message.*/ |
bogdanm | 83:8a40adfe8776 | 99 | typedef enum _enet_ipv6_ptp_content_offset |
bogdanm | 83:8a40adfe8776 | 100 | { |
bogdanm | 83:8a40adfe8776 | 101 | kEnetPtpIpv6UdpProtocolOffset = 0x14, /*!< IPv6 PTP message UDP protocol offset*/ |
bogdanm | 83:8a40adfe8776 | 102 | kEnetPtpIpv6UdpPortOffset = 0x38, /*!< IPv6 PTP message UDP port offset*/ |
bogdanm | 83:8a40adfe8776 | 103 | kEnetPtpIpv6UdpMsgTypeOffset = 0x3e, /*!< IPv6 PTP message UDP message type offset*/ |
bogdanm | 83:8a40adfe8776 | 104 | kEnetPtpIpv6UdpVersionOffset = 0x3f, /*!< IPv6 PTP message UDP version offset*/ |
bogdanm | 83:8a40adfe8776 | 105 | kEnetPtpIpv6UdpClockIdOffset = 0x52, /*!< IPv6 PTP message UDP clock id offset*/ |
bogdanm | 83:8a40adfe8776 | 106 | kEnetPtpIpv6UdpSequenceIdOffset = 0x5c,/*!< IPv6 PTP message UDP sequence id offset*/ |
bogdanm | 83:8a40adfe8776 | 107 | kEnetPtpIpv6UdpCtlOffset = 0x5e /*!< IPv6 PTP message UDP control offset*/ |
bogdanm | 83:8a40adfe8776 | 108 | } enet_ipv6_ptp_content_offset_t; |
bogdanm | 83:8a40adfe8776 | 109 | |
bogdanm | 83:8a40adfe8776 | 110 | /*! @brief Defines all ENET PTP content offset in the PTP Layer2 Ethernet message.*/ |
bogdanm | 83:8a40adfe8776 | 111 | typedef enum _enet_ethernet_ptp_content_offset |
bogdanm | 83:8a40adfe8776 | 112 | { |
bogdanm | 83:8a40adfe8776 | 113 | kEnetPtpEtherPktTypeOffset = 0x0c, /*!< PTPv2 message Ethernet packet type offset*/ |
bogdanm | 83:8a40adfe8776 | 114 | kEnetPtpEtherMsgTypeOffset = 0x0e, /*!< PTPv2 message Ethernet message type offset*/ |
bogdanm | 83:8a40adfe8776 | 115 | kEnetPtpEtherVersionOffset = 0x0f, /*!< PTPv2 message Ethernet version type offset*/ |
bogdanm | 83:8a40adfe8776 | 116 | kEnetPtpEtherClockIdOffset = 0x22, /*!< PTPv2 message Ethernet clock id offset*/ |
bogdanm | 83:8a40adfe8776 | 117 | kEnetPtpEtherSequenceIdOffset = 0x2c,/*!< PTPv2 message Ethernet sequence id offset*/ |
bogdanm | 83:8a40adfe8776 | 118 | kEnetPtpEtherCtlOffset = 0x2e /*!< PTPv2 message Ethernet control offset*/ |
bogdanm | 83:8a40adfe8776 | 119 | } enet_ethernet_ptp_content_offset_t; |
bogdanm | 83:8a40adfe8776 | 120 | |
bogdanm | 83:8a40adfe8776 | 121 | /*! @brief Defines the 1588 timer parameters.*/ |
bogdanm | 83:8a40adfe8776 | 122 | typedef enum _enet_ptp_timer_wrap_period |
bogdanm | 83:8a40adfe8776 | 123 | { |
bogdanm | 83:8a40adfe8776 | 124 | kEnetPtpAtperVaule = 1000000000, /*!< PTP timer wrap around one second */ |
bogdanm | 83:8a40adfe8776 | 125 | kEnetBaseIncreaseUnit = 2 /*!< PTP timer adjusts clock and increases value to 2*/ |
bogdanm | 83:8a40adfe8776 | 126 | } enet_ptp_timer_wrap_period_t; |
bogdanm | 83:8a40adfe8776 | 127 | #endif |
bogdanm | 83:8a40adfe8776 | 128 | |
bogdanm | 83:8a40adfe8776 | 129 | /*! @brief Defines the interrupt source index for the interrupt vector change table.*/ |
bogdanm | 83:8a40adfe8776 | 130 | typedef enum _enet_interrupt_number |
bogdanm | 83:8a40adfe8776 | 131 | { |
bogdanm | 83:8a40adfe8776 | 132 | kEnetTstimerInt = 0, /*!< Timestamp interrupt*/ |
bogdanm | 83:8a40adfe8776 | 133 | kEnetTsAvailInt, /*!< TS-avail interrupt*/ |
bogdanm | 83:8a40adfe8776 | 134 | kEnetWakeUpInt, /*!< Wakeup interrupt*/ |
bogdanm | 83:8a40adfe8776 | 135 | kEnetPlrInt, /*!< Plr interrupt*/ |
bogdanm | 83:8a40adfe8776 | 136 | kEnetUnInt, /*!< Un interrupt*/ |
bogdanm | 83:8a40adfe8776 | 137 | kEnetRlInt, /*!< RL interrupt*/ |
bogdanm | 83:8a40adfe8776 | 138 | kEnetLcInt, /*!< LC interrupt*/ |
bogdanm | 83:8a40adfe8776 | 139 | kEnetEberrInt, /*!< Eberr interrupt*/ |
bogdanm | 83:8a40adfe8776 | 140 | kEnetMiiInt, /*!< MII interrupt*/ |
bogdanm | 83:8a40adfe8776 | 141 | kEnetRxbInt , /*!< Receive byte interrupt*/ |
bogdanm | 83:8a40adfe8776 | 142 | kEnetRxfInt, /*!< Receive frame interrupt*/ |
bogdanm | 83:8a40adfe8776 | 143 | kEnetTxbInt, /*!< Transmit byte interrupt*/ |
bogdanm | 83:8a40adfe8776 | 144 | kEnetTxfInt, /*!< Transmit frame interrupt*/ |
bogdanm | 83:8a40adfe8776 | 145 | kEnetGraInt, /*!< Gra interrupt*/ |
bogdanm | 83:8a40adfe8776 | 146 | kEnetBabtInt, /*!< Babt interrupt*/ |
bogdanm | 83:8a40adfe8776 | 147 | kEnetBabrInt, /*!< Babr interrupt*/ |
bogdanm | 83:8a40adfe8776 | 148 | kEnetIntNum /*!< Interrupt number*/ |
bogdanm | 83:8a40adfe8776 | 149 | } enet_interrupt_number_t; |
bogdanm | 83:8a40adfe8776 | 150 | |
bogdanm | 83:8a40adfe8776 | 151 | /*! @brief Defines the ENET main constant.*/ |
bogdanm | 83:8a40adfe8776 | 152 | typedef enum _enet_frame_max |
bogdanm | 83:8a40adfe8776 | 153 | { |
bogdanm | 83:8a40adfe8776 | 154 | kEnetMaxTimeout = 0x10000, /*!< Maximum timeout*/ |
bogdanm | 83:8a40adfe8776 | 155 | kEnetMaxFrameSize = 1518, /*!< Maximum frame size*/ |
bogdanm | 83:8a40adfe8776 | 156 | kEnetMaxFrameVlanSize = 1522, /*!< Maximum VLAN frame size*/ |
bogdanm | 83:8a40adfe8776 | 157 | kEnetMaxFrameDateSize = 1500, /*!< Maximum frame data size*/ |
bogdanm | 83:8a40adfe8776 | 158 | kEnetMaxFrameBdNumbers = 7, /*!< Maximum buffer descriptor numbers of a frame*/ |
bogdanm | 83:8a40adfe8776 | 159 | kEnetFrameFcsLen = 4, /*!< FCS length*/ |
bogdanm | 83:8a40adfe8776 | 160 | kEnetEthernetHeadLen = 14 /*!< Ethernet Frame header length*/ |
bogdanm | 83:8a40adfe8776 | 161 | } enet_frame_max_t; |
bogdanm | 83:8a40adfe8776 | 162 | |
bogdanm | 83:8a40adfe8776 | 163 | /*! @brief Defines the CRC data for a hash value calculation.*/ |
bogdanm | 83:8a40adfe8776 | 164 | typedef enum _enet_crc_parameter |
bogdanm | 83:8a40adfe8776 | 165 | { |
bogdanm | 83:8a40adfe8776 | 166 | kEnetCrcData = 0xFFFFFFFFU, /*!< CRC-32 maximum data */ |
bogdanm | 83:8a40adfe8776 | 167 | kEnetCrcOffset = 8, /*!< CRC-32 offset2*/ |
bogdanm | 83:8a40adfe8776 | 168 | kEnetCrcMask1 = 0x3F /*!< CRC-32 mask*/ |
bogdanm | 83:8a40adfe8776 | 169 | } enet_crc_parameter_t; |
bogdanm | 83:8a40adfe8776 | 170 | |
bogdanm | 83:8a40adfe8776 | 171 | /*! @brief Defines the ENET protocol type and main parameters.*/ |
bogdanm | 83:8a40adfe8776 | 172 | typedef enum _enet_protocol_type |
bogdanm | 83:8a40adfe8776 | 173 | { |
bogdanm | 83:8a40adfe8776 | 174 | kEnetProtocolIeee8023 = 0x88F7, /*!< Packet type Ethernet ieee802.3*/ |
bogdanm | 83:8a40adfe8776 | 175 | kEnetProtocolIpv4 = 0x0800, /*!< Packet type IPv4*/ |
bogdanm | 83:8a40adfe8776 | 176 | kEnetProtocolIpv6 = 0x86dd, /*!< Packet type IPv6*/ |
bogdanm | 83:8a40adfe8776 | 177 | kEnetProtocol8021QVlan = 0x8100, /*!< Packet type VLAN*/ |
bogdanm | 83:8a40adfe8776 | 178 | kEnetPacketUdpVersion = 0x11, /*!< UDP protocol type*/ |
bogdanm | 83:8a40adfe8776 | 179 | kEnetPacketIpv4Version = 0x4, /*!< Packet IP version IPv4*/ |
bogdanm | 83:8a40adfe8776 | 180 | kEnetPacketIpv6Version = 0x6 /*!< Packet IP version IPv6*/ |
bogdanm | 83:8a40adfe8776 | 181 | } enet_protocol_type_t; |
bogdanm | 83:8a40adfe8776 | 182 | |
bogdanm | 83:8a40adfe8776 | 183 | /*! @brief Defines the ENET MAC control Configure*/ |
bogdanm | 83:8a40adfe8776 | 184 | typedef enum _enet_mac_control_flag |
bogdanm | 83:8a40adfe8776 | 185 | { |
bogdanm | 83:8a40adfe8776 | 186 | kEnetSleepModeEnable = 0x1, /*!< ENET control sleep mode Enable*/ |
bogdanm | 83:8a40adfe8776 | 187 | kEnetPayloadlenCheckEnable = 0x2, /*!< ENET receive payload length check Enable*/ |
bogdanm | 83:8a40adfe8776 | 188 | kEnetRxFlowControlEnable = 0x4, /*!< ENET flow control, receiver detects PAUSE frames and stops transmitting data when a PAUSE frame is detected*/ |
bogdanm | 83:8a40adfe8776 | 189 | kEnetRxCrcFwdEnable = 0x8, /*!< Received frame crc is stripped from the frame*/ |
bogdanm | 83:8a40adfe8776 | 190 | kEnetRxPauseFwdEnable = 0x10,/*!< Pause frames are forwarded to the user application*/ |
bogdanm | 83:8a40adfe8776 | 191 | kEnetRxPadRemoveEnable = 0x20, /*!< Padding is removed from received frames*/ |
bogdanm | 83:8a40adfe8776 | 192 | kEnetRxBcRejectEnable = 0x40, /*!< Broadcast frame reject*/ |
bogdanm | 83:8a40adfe8776 | 193 | kEnetRxPromiscuousEnable = 0x80, /*!< Promiscuous mode enabled*/ |
bogdanm | 83:8a40adfe8776 | 194 | kEnetRxMiiLoopback = 0x100, /*!< MAC MII loopback mode*/ |
bogdanm | 83:8a40adfe8776 | 195 | } enet_mac_control_flag_t; |
bogdanm | 83:8a40adfe8776 | 196 | |
bogdanm | 83:8a40adfe8776 | 197 | /*! @brief Defines the multicast group structure for the ENET device. */ |
bogdanm | 83:8a40adfe8776 | 198 | typedef struct ENETMulticastGroup |
bogdanm | 83:8a40adfe8776 | 199 | { |
bogdanm | 83:8a40adfe8776 | 200 | enetMacAddr groupAdddr; /*!< Multicast group address*/ |
bogdanm | 83:8a40adfe8776 | 201 | uint32_t hash; /*!< Hash value of the multicast group address*/ |
bogdanm | 83:8a40adfe8776 | 202 | struct ENETMulticastGroup *next; /*!< Pointer of the next group structure*/ |
bogdanm | 83:8a40adfe8776 | 203 | struct ENETMulticastGroup *prv; /*!< Pointer of the previous structure*/ |
bogdanm | 83:8a40adfe8776 | 204 | } enet_multicast_group_t; |
bogdanm | 83:8a40adfe8776 | 205 | |
bogdanm | 83:8a40adfe8776 | 206 | /*! @brief Defines the receive buffer descriptor configure structure.*/ |
bogdanm | 83:8a40adfe8776 | 207 | typedef struct ENETRxBdConfig |
bogdanm | 83:8a40adfe8776 | 208 | { |
bogdanm | 83:8a40adfe8776 | 209 | uint8_t *rxBdPtrAlign; /*!< Aligned receive buffer descriptor pointer */ |
bogdanm | 83:8a40adfe8776 | 210 | uint8_t *rxBufferAlign; /*!< Aligned receive data buffer pointer */ |
bogdanm | 83:8a40adfe8776 | 211 | uint8_t *rxLargeBufferAlign; /*!< Aligned receive large data buffer pointer*/ |
bogdanm | 83:8a40adfe8776 | 212 | uint8_t rxBdNum; /*!< Aligned receive buffer descriptor pointer*/ |
bogdanm | 83:8a40adfe8776 | 213 | uint8_t rxBufferNum; /*!< Receive buffer number*/ |
bogdanm | 83:8a40adfe8776 | 214 | uint8_t rxLargeBufferNum; /*!< Large receive buffer number*/ |
bogdanm | 83:8a40adfe8776 | 215 | uint32_t rxLargeBufferSizeAlign; /*!< Aligned large receive buffer size*/ |
bogdanm | 83:8a40adfe8776 | 216 | }enet_rxbd_config_t; |
bogdanm | 83:8a40adfe8776 | 217 | |
bogdanm | 83:8a40adfe8776 | 218 | /*! @brief Defines the transmit buffer descriptor configure structure.*/ |
bogdanm | 83:8a40adfe8776 | 219 | typedef struct ENETTxBdConfig |
bogdanm | 83:8a40adfe8776 | 220 | { |
bogdanm | 83:8a40adfe8776 | 221 | uint8_t *txBdPtrAlign; /*!< Aligned transmit buffer descriptor pointer*/ |
bogdanm | 83:8a40adfe8776 | 222 | uint8_t *txBufferAlign; /*!< Aligned transmit buffer descriptor pointer*/ |
bogdanm | 83:8a40adfe8776 | 223 | uint8_t txBufferNum; /*!< Transmit buffer number*/ |
bogdanm | 83:8a40adfe8776 | 224 | uint32_t txBufferSizeAlign; /*!< Aligned transmit buffer size*/ |
bogdanm | 83:8a40adfe8776 | 225 | }enet_txbd_config_t; |
bogdanm | 83:8a40adfe8776 | 226 | |
bogdanm | 83:8a40adfe8776 | 227 | /*! @brief Defines the basic configuration structure for the ENET device.*/ |
bogdanm | 83:8a40adfe8776 | 228 | typedef struct ENETMacConfig |
bogdanm | 83:8a40adfe8776 | 229 | { |
bogdanm | 83:8a40adfe8776 | 230 | uint16_t rxBufferSize; /*!< Receive buffer size*/ |
bogdanm | 83:8a40adfe8776 | 231 | uint16_t rxLargeBufferNumber; /*!< Receive large buffer number; Needed only when the BD size is smaller than the maximum frame length.*/ |
bogdanm | 83:8a40adfe8776 | 232 | uint16_t rxBdNumber; /*!< Receive buffer descriptor number*/ |
bogdanm | 83:8a40adfe8776 | 233 | uint16_t txBdNumber; /*!< Transmit buffer descriptor number*/ |
bogdanm | 83:8a40adfe8776 | 234 | enetMacAddr macAddr; /*!< MAC hardware address*/ |
bogdanm | 83:8a40adfe8776 | 235 | enet_config_rmii_t rmiiCfgMode;/*!< RMII configure mode*/ |
bogdanm | 83:8a40adfe8776 | 236 | enet_config_speed_t speed; /*!< Speed configuration*/ |
bogdanm | 83:8a40adfe8776 | 237 | enet_config_duplex_t duplex; /*!< Duplex configuration*/ |
bogdanm | 83:8a40adfe8776 | 238 | /*!< Mac control configure, it is recommended to use enet_mac_control_flag_t |
bogdanm | 83:8a40adfe8776 | 239 | it is special control set for loop mode, sleep mode, crc forward/terminate etc*/ |
bogdanm | 83:8a40adfe8776 | 240 | uint32_t macCtlConfigure; |
bogdanm | 83:8a40adfe8776 | 241 | bool isTxAccelEnabled;/*!< Switcher to enable transmit accelerator*/ |
bogdanm | 83:8a40adfe8776 | 242 | bool isRxAccelEnabled;/*!< Switcher to enable receive accelerator*/ |
bogdanm | 83:8a40adfe8776 | 243 | bool isStoreAndFwEnabled; /*!< Switcher to enable store and forward*/ |
bogdanm | 83:8a40adfe8776 | 244 | enet_config_rx_accelerator_t rxAcceler; /*!< Receive accelerator configure*/ |
bogdanm | 83:8a40adfe8776 | 245 | enet_config_tx_accelerator_t txAcceler; /*!< Transmit accelerator configure*/ |
bogdanm | 83:8a40adfe8776 | 246 | bool isVlanEnabled; /*!< Switcher to enable VLAN frame*/ |
bogdanm | 83:8a40adfe8776 | 247 | bool isPhyAutoDiscover;/*!< Switcher to use PHY auto discover*/ |
bogdanm | 83:8a40adfe8776 | 248 | uint32_t miiClock; /*!< MII speed*/ |
bogdanm | 83:8a40adfe8776 | 249 | #if FSL_FEATURE_ENET_SUPPORT_PTP |
bogdanm | 83:8a40adfe8776 | 250 | uint16_t ptpRingBufferNumber; /*!< PTP ring buffer number*/ |
bogdanm | 83:8a40adfe8776 | 251 | bool isSlaveModeEnabled; /*!< PTP timer configuration*/ |
bogdanm | 83:8a40adfe8776 | 252 | #endif |
bogdanm | 83:8a40adfe8776 | 253 | } enet_mac_config_t; |
bogdanm | 83:8a40adfe8776 | 254 | |
bogdanm | 83:8a40adfe8776 | 255 | /*! @brief Defines the basic configuration for PHY.*/ |
bogdanm | 83:8a40adfe8776 | 256 | typedef struct ENETPhyConfig |
bogdanm | 83:8a40adfe8776 | 257 | { |
bogdanm | 83:8a40adfe8776 | 258 | uint8_t phyAddr; /*!< PHY address*/ |
bogdanm | 83:8a40adfe8776 | 259 | bool isLoopEnabled; /*!< Switcher to enable the HY loop mode*/ |
bogdanm | 83:8a40adfe8776 | 260 | } enet_phy_config_t; |
bogdanm | 83:8a40adfe8776 | 261 | |
bogdanm | 83:8a40adfe8776 | 262 | #if FSL_FEATURE_ENET_SUPPORT_PTP |
bogdanm | 83:8a40adfe8776 | 263 | /*! @brief Defines the ENET Mac PTP timestamp structure.*/ |
bogdanm | 83:8a40adfe8776 | 264 | typedef struct ENETMacPtpTime |
bogdanm | 83:8a40adfe8776 | 265 | { |
bogdanm | 83:8a40adfe8776 | 266 | uint64_t second; /*!< Second*/ |
bogdanm | 83:8a40adfe8776 | 267 | uint32_t nanosecond; /*!< Nanosecond*/ |
bogdanm | 83:8a40adfe8776 | 268 | } enet_mac_ptp_time_t; |
bogdanm | 83:8a40adfe8776 | 269 | |
bogdanm | 83:8a40adfe8776 | 270 | /*! @brief Defines the ENET PTP timer drift structure.*/ |
bogdanm | 83:8a40adfe8776 | 271 | typedef struct ENETPtpDrift |
bogdanm | 83:8a40adfe8776 | 272 | { |
bogdanm | 83:8a40adfe8776 | 273 | int32_t drift; /*!< Drift for the PTP timer to adjust*/ |
bogdanm | 83:8a40adfe8776 | 274 | } enet_ptp_drift_t; |
bogdanm | 83:8a40adfe8776 | 275 | |
bogdanm | 83:8a40adfe8776 | 276 | /*! @brief Defines the ENET MAC PTP time parameter.*/ |
bogdanm | 83:8a40adfe8776 | 277 | typedef struct ENETPtpMasterTimeData |
bogdanm | 83:8a40adfe8776 | 278 | { |
bogdanm | 83:8a40adfe8776 | 279 | uint8_t masterPtpInstance;/*!< PTP master timer instance*/ |
bogdanm | 83:8a40adfe8776 | 280 | uint64_t second; /*!< PTP master timer second */ |
bogdanm | 83:8a40adfe8776 | 281 | } enet_ptp_master_time_data_t; |
bogdanm | 83:8a40adfe8776 | 282 | |
bogdanm | 83:8a40adfe8776 | 283 | /*! @brief Defines the structure for the ENET PTP message data and timestamp data.*/ |
bogdanm | 83:8a40adfe8776 | 284 | typedef struct ENETMacPtpTsData |
bogdanm | 83:8a40adfe8776 | 285 | { |
bogdanm | 83:8a40adfe8776 | 286 | uint8_t version; /*!< PTP version*/ |
bogdanm | 83:8a40adfe8776 | 287 | uint8_t sourcePortId[kEnetPtpSourcePortIdLen];/*!< PTP source port ID*/ |
bogdanm | 83:8a40adfe8776 | 288 | uint16_t sequenceId; /*!< PTP sequence ID*/ |
bogdanm | 83:8a40adfe8776 | 289 | uint8_t messageType; /*!< PTP message type*/ |
bogdanm | 83:8a40adfe8776 | 290 | enet_mac_ptp_time_t timeStamp;/*!< PTP timestamp*/ |
bogdanm | 83:8a40adfe8776 | 291 | } enet_mac_ptp_ts_data_t; |
bogdanm | 83:8a40adfe8776 | 292 | |
bogdanm | 83:8a40adfe8776 | 293 | /*! @brief Defines the ENET PTP ring buffer structure for the PTP message timestamp store.*/ |
bogdanm | 83:8a40adfe8776 | 294 | typedef struct ENETMacPtpTsRing |
bogdanm | 83:8a40adfe8776 | 295 | { |
bogdanm | 83:8a40adfe8776 | 296 | uint32_t front; /*!< The first index of the ring*/ |
bogdanm | 83:8a40adfe8776 | 297 | uint32_t end; /*!< The end index of the ring*/ |
bogdanm | 83:8a40adfe8776 | 298 | uint32_t size; /*!< The size of the ring*/ |
bogdanm | 83:8a40adfe8776 | 299 | enet_mac_ptp_ts_data_t *ptpTsDataPtr;/*!< PTP message data structure*/ |
bogdanm | 83:8a40adfe8776 | 300 | } enet_mac_ptp_ts_ring_t; |
bogdanm | 83:8a40adfe8776 | 301 | |
bogdanm | 83:8a40adfe8776 | 302 | /*! @brief Defines the ENET packet for the PTP version2 message using the layer2 Ethernet frame.*/ |
bogdanm | 83:8a40adfe8776 | 303 | typedef struct ENETPtpL2packet |
bogdanm | 83:8a40adfe8776 | 304 | { |
bogdanm | 83:8a40adfe8776 | 305 | uint8_t packet[kEnetMaxFrameDateSize]; /*!< Buffer for ptpv2 message*/ |
bogdanm | 83:8a40adfe8776 | 306 | uint16_t length; /*!< PTP message length*/ |
bogdanm | 83:8a40adfe8776 | 307 | } enet_ptp_l2packet_t; |
bogdanm | 83:8a40adfe8776 | 308 | |
bogdanm | 83:8a40adfe8776 | 309 | /*! @brief Defines the ENET PTPv2 packet queue using the layer2 Ethernet frame.*/ |
bogdanm | 83:8a40adfe8776 | 310 | typedef struct ENETPtpL2queue |
bogdanm | 83:8a40adfe8776 | 311 | { |
bogdanm | 83:8a40adfe8776 | 312 | enet_ptp_l2packet_t l2Packet[kEnetPtpL2bufferNumber]; /*!< PTP layer2 packet*/ |
bogdanm | 83:8a40adfe8776 | 313 | uint16_t writeIdex; /*!< Queue write index*/ |
bogdanm | 83:8a40adfe8776 | 314 | uint16_t readIdx; /*!< Queue read index*/ |
bogdanm | 83:8a40adfe8776 | 315 | } enet_ptp_l2queue_t; |
bogdanm | 83:8a40adfe8776 | 316 | |
bogdanm | 83:8a40adfe8776 | 317 | /*! @brief Defines the ENET PTP layer2 Ethernet frame structure.*/ |
bogdanm | 83:8a40adfe8776 | 318 | typedef struct ENETPtpL2Ethernet |
bogdanm | 83:8a40adfe8776 | 319 | { |
bogdanm | 83:8a40adfe8776 | 320 | uint8_t *ptpMsg; /*!< PTP message*/ |
bogdanm | 83:8a40adfe8776 | 321 | uint16_t length; /*!< Length of the PTP message*/ |
bogdanm | 83:8a40adfe8776 | 322 | enetMacAddr hwAddr; /*!< Destination hardware address*/ |
bogdanm | 83:8a40adfe8776 | 323 | } enet_ptp_l2_ethernet_t; |
bogdanm | 83:8a40adfe8776 | 324 | |
bogdanm | 83:8a40adfe8776 | 325 | /*! @brief Defines the ENET PTP buffer structure for all 1588 data.*/ |
bogdanm | 83:8a40adfe8776 | 326 | typedef struct ENETPrivatePtpBuffer |
bogdanm | 83:8a40adfe8776 | 327 | { |
bogdanm | 83:8a40adfe8776 | 328 | enet_mac_ptp_ts_ring_t rxTimeStamp;/*!< Data structure for receive message*/ |
bogdanm | 83:8a40adfe8776 | 329 | enet_mac_ptp_ts_ring_t txTimeStamp;/*!< Data structure for transmit timestamp*/ |
bogdanm | 83:8a40adfe8776 | 330 | enet_ptp_l2queue_t *l2QueuePtr; /*!< Data structure for layer2 Ethernet queue*/ |
bogdanm | 83:8a40adfe8776 | 331 | uint64_t masterSecond; /*!< PTP time second when it's master time*/ |
bogdanm | 83:8a40adfe8776 | 332 | } enet_private_ptp_buffer_t; |
bogdanm | 83:8a40adfe8776 | 333 | #endif |
bogdanm | 83:8a40adfe8776 | 334 | |
bogdanm | 83:8a40adfe8776 | 335 | /*! @brief Defines the ENET header structure. */ |
bogdanm | 83:8a40adfe8776 | 336 | typedef struct ENETEthernetHeader |
bogdanm | 83:8a40adfe8776 | 337 | { |
bogdanm | 83:8a40adfe8776 | 338 | enetMacAddr destAddr; /*!< Destination address */ |
bogdanm | 83:8a40adfe8776 | 339 | enetMacAddr sourceAddr;/*!< Source address*/ |
bogdanm | 83:8a40adfe8776 | 340 | uint16_t type; /*!< Protocol type*/ |
bogdanm | 83:8a40adfe8776 | 341 | } enet_ethernet_header_t; |
bogdanm | 83:8a40adfe8776 | 342 | |
bogdanm | 83:8a40adfe8776 | 343 | /*! @brief Defines the ENET VLAN frame header structure. */ |
bogdanm | 83:8a40adfe8776 | 344 | typedef struct ENET8021vlanHeader |
bogdanm | 83:8a40adfe8776 | 345 | { |
bogdanm | 83:8a40adfe8776 | 346 | enetMacAddr destAddr; /*!< Destination address */ |
bogdanm | 83:8a40adfe8776 | 347 | enetMacAddr sourceAddr;/*!< Source address*/ |
bogdanm | 83:8a40adfe8776 | 348 | uint16_t tpidtag; /*!< ENET 8021tag header tag region*/ |
bogdanm | 83:8a40adfe8776 | 349 | uint16_t othertag; /*!< ENET 8021tag header type region*/ |
bogdanm | 83:8a40adfe8776 | 350 | uint16_t type; /*!< Protocol type*/ |
bogdanm | 83:8a40adfe8776 | 351 | } enet_8021vlan_header_t; |
bogdanm | 83:8a40adfe8776 | 352 | |
bogdanm | 83:8a40adfe8776 | 353 | /*! @brief Defines the ENET MAC context structure for the buffer address, buffer descriptor address, etc.*/ |
bogdanm | 83:8a40adfe8776 | 354 | typedef struct ENETMacContext |
bogdanm | 83:8a40adfe8776 | 355 | { |
bogdanm | 83:8a40adfe8776 | 356 | uint8_t *rxBufferPtr; /*!< Receive buffer pointer*/ |
bogdanm | 83:8a40adfe8776 | 357 | uint8_t *rxLargeBufferPtr; /*!< Receive large buffer descriptor*/ |
bogdanm | 83:8a40adfe8776 | 358 | uint8_t *txBufferPtr; /*!< Transmit buffer pointer*/ |
bogdanm | 83:8a40adfe8776 | 359 | uint8_t *rxBdBasePtr; /*!< Receive buffer descriptor base address pointer*/ |
bogdanm | 83:8a40adfe8776 | 360 | uint8_t *rxBdCurPtr; /*!< Current receive buffer descriptor pointer*/ |
bogdanm | 83:8a40adfe8776 | 361 | uint8_t *rxBdDirtyPtr; /*!< Receive dirty buffer descriptor*/ |
bogdanm | 83:8a40adfe8776 | 362 | uint8_t *txBdBasePtr; /*!< Transmit buffer descriptor base address pointer*/ |
bogdanm | 83:8a40adfe8776 | 363 | uint8_t *txBdCurPtr; /*!< Current transmit buffer descriptor pointer*/ |
bogdanm | 83:8a40adfe8776 | 364 | uint8_t *txBdDirtyPtr; /*!< Last cleaned transmit buffer descriptor pointer*/ |
bogdanm | 83:8a40adfe8776 | 365 | bool isTxFull; /*!< Transmit buffer descriptor full*/ |
bogdanm | 83:8a40adfe8776 | 366 | bool isRxFull; /*!< Receive buffer descriptor full*/ |
bogdanm | 83:8a40adfe8776 | 367 | uint32_t bufferdescSize; /*!< ENET buffer descriptor size*/ |
bogdanm | 83:8a40adfe8776 | 368 | uint16_t rxBufferSizeAligned; /*!< Receive buffer alignment size*/ |
bogdanm | 83:8a40adfe8776 | 369 | #if FSL_FEATURE_ENET_SUPPORT_PTP |
bogdanm | 83:8a40adfe8776 | 370 | enet_private_ptp_buffer_t privatePtp;/*!< PTP private buffer*/ |
bogdanm | 83:8a40adfe8776 | 371 | #endif |
bogdanm | 83:8a40adfe8776 | 372 | } enet_mac_context_t; |
bogdanm | 83:8a40adfe8776 | 373 | |
bogdanm | 83:8a40adfe8776 | 374 | /*! @brief Defines the ENET packets statistic structure.*/ |
bogdanm | 83:8a40adfe8776 | 375 | typedef struct ENETMacStats |
bogdanm | 83:8a40adfe8776 | 376 | { |
bogdanm | 83:8a40adfe8776 | 377 | uint32_t statsRxTotal; /*!< Total number of receive packets*/ |
bogdanm | 83:8a40adfe8776 | 378 | uint32_t statsRxMissed; /*!< Total number of receive packets*/ |
bogdanm | 83:8a40adfe8776 | 379 | uint32_t statsRxDiscard; /*!< Receive discarded with error */ |
bogdanm | 83:8a40adfe8776 | 380 | uint32_t statsRxError; /*!< Receive discarded with error packets*/ |
bogdanm | 83:8a40adfe8776 | 381 | uint32_t statsTxTotal; /*!< Total number of transmit packets*/ |
bogdanm | 83:8a40adfe8776 | 382 | uint32_t statsTxMissed; /*!< Transmit missed*/ |
bogdanm | 83:8a40adfe8776 | 383 | uint32_t statsTxDiscard; /*!< Transmit discarded with error */ |
bogdanm | 83:8a40adfe8776 | 384 | uint32_t statsTxError; /*!< Transmit error*/ |
bogdanm | 83:8a40adfe8776 | 385 | uint32_t statsRxAlign; /*!< Receive non-octet alignment*/ |
bogdanm | 83:8a40adfe8776 | 386 | uint32_t statsRxFcs; /*!< Receive CRC error*/ |
bogdanm | 83:8a40adfe8776 | 387 | uint32_t statsRxTruncate;/*!< Receive truncate*/ |
bogdanm | 83:8a40adfe8776 | 388 | uint32_t statsRxLengthGreater; /*!< Receive length greater than RCR[MAX_FL] */ |
bogdanm | 83:8a40adfe8776 | 389 | uint32_t statsRxCollision; /*!< Receive collision*/ |
bogdanm | 83:8a40adfe8776 | 390 | uint32_t statsRxOverRun; /*!< Receive over run*/ |
bogdanm | 83:8a40adfe8776 | 391 | uint32_t statsTxOverFlow; /*!< Transmit overflow*/ |
bogdanm | 83:8a40adfe8776 | 392 | uint32_t statsTxLateCollision; /*!< Transmit late collision*/ |
bogdanm | 83:8a40adfe8776 | 393 | uint32_t statsTxExcessCollision;/*!< Transmit excess collision*/ |
bogdanm | 83:8a40adfe8776 | 394 | uint32_t statsTxUnderFlow; /*!< Transmit under flow*/ |
bogdanm | 83:8a40adfe8776 | 395 | uint32_t statsTxLarge; /*!< Transmit large packet*/ |
bogdanm | 83:8a40adfe8776 | 396 | uint32_t statsTxSmall; /*!< Transmit small packet*/ |
bogdanm | 83:8a40adfe8776 | 397 | } enet_stats_t; |
bogdanm | 83:8a40adfe8776 | 398 | |
bogdanm | 83:8a40adfe8776 | 399 | /*! @brief Defines the ENET MAC packet buffer structure.*/ |
bogdanm | 83:8a40adfe8776 | 400 | typedef struct ENETMacPacketBuffer |
bogdanm | 83:8a40adfe8776 | 401 | { |
bogdanm | 83:8a40adfe8776 | 402 | uint8_t *data; |
bogdanm | 83:8a40adfe8776 | 403 | uint16_t length; |
bogdanm | 83:8a40adfe8776 | 404 | } enet_mac_packet_buffer_t; |
bogdanm | 83:8a40adfe8776 | 405 | |
bogdanm | 83:8a40adfe8776 | 406 | #if ENET_RECEIVE_ALL_INTERRUPT |
bogdanm | 83:8a40adfe8776 | 407 | typedef uint32_t (* enet_netif_callback_t)(void *enetPtr, enet_mac_packet_buffer_t *packetBuffer); |
bogdanm | 83:8a40adfe8776 | 408 | #endif |
bogdanm | 83:8a40adfe8776 | 409 | |
bogdanm | 83:8a40adfe8776 | 410 | /*! @brief Defines the ENET device data structure for the ENET.*/ |
bogdanm | 83:8a40adfe8776 | 411 | typedef struct ENETDevIf |
bogdanm | 83:8a40adfe8776 | 412 | { |
bogdanm | 83:8a40adfe8776 | 413 | struct ENETDevIf *next; /*!< Next device structure address*/ |
bogdanm | 83:8a40adfe8776 | 414 | void *netIfPtr; /*!< Store the connected upper layer in the structure*/ |
bogdanm | 83:8a40adfe8776 | 415 | #if ENET_RECEIVE_ALL_INTERRUPT |
bogdanm | 83:8a40adfe8776 | 416 | void *enetNetifService; /*!< Service function*/ |
bogdanm | 83:8a40adfe8776 | 417 | #endif |
bogdanm | 83:8a40adfe8776 | 418 | enet_multicast_group_t *multiGroupPtr; /*!< Multicast group chain*/ |
bogdanm | 83:8a40adfe8776 | 419 | uint32_t deviceNumber; /*!< Device number*/ |
bogdanm | 83:8a40adfe8776 | 420 | bool isInitialized; /*!< Device initialized*/ |
bogdanm | 83:8a40adfe8776 | 421 | uint16_t maxFrameSize; /*!< MAC maximum frame size*/ |
bogdanm | 83:8a40adfe8776 | 422 | enet_mac_config_t *macCfgPtr;/*!< MAC configuration structure*/ |
bogdanm | 83:8a40adfe8776 | 423 | enet_phy_config_t *phyCfgPtr;/*!< PHY configuration structure*/ |
bogdanm | 83:8a40adfe8776 | 424 | const struct ENETMacApi *macApiPtr; /*!< MAC application interface structure*/ |
bogdanm | 83:8a40adfe8776 | 425 | void *phyApiPtr; /*!< PHY application interface structure*/ |
bogdanm | 83:8a40adfe8776 | 426 | enet_mac_context_t *macContextPtr; /*!< MAC context pointer*/ |
bogdanm | 83:8a40adfe8776 | 427 | #if ENET_ENABLE_DETAIL_STATS |
bogdanm | 83:8a40adfe8776 | 428 | enet_stats_t stats; /*!< Packets statistic*/ |
bogdanm | 83:8a40adfe8776 | 429 | #endif |
bogdanm | 83:8a40adfe8776 | 430 | #if ENET_RECEIVE_ALL_INTERRUPT |
bogdanm | 83:8a40adfe8776 | 431 | enet_netif_callback_t enetNetifcall; /*!< Receive callback function to the upper layer*/ |
bogdanm | 83:8a40adfe8776 | 432 | #else |
bogdanm | 83:8a40adfe8776 | 433 | event_object_t enetReceiveSync; /*!< Receive sync signal*/ |
bogdanm | 83:8a40adfe8776 | 434 | #endif |
bogdanm | 83:8a40adfe8776 | 435 | lock_object_t enetContextSync; /*!< Sync signal*/ |
bogdanm | 83:8a40adfe8776 | 436 | } enet_dev_if_t; |
bogdanm | 83:8a40adfe8776 | 437 | |
bogdanm | 83:8a40adfe8776 | 438 | /*! @brief Defines the basic application for the ENET device.*/ |
bogdanm | 83:8a40adfe8776 | 439 | typedef struct ENETMacApi |
bogdanm | 83:8a40adfe8776 | 440 | { |
bogdanm | 83:8a40adfe8776 | 441 | uint32_t (* enet_mac_init)(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg, enet_txbd_config_t *txbdCfg);/*!< MAC initialize interface*/ |
bogdanm | 83:8a40adfe8776 | 442 | uint32_t (* enet_mac_deinit)(enet_dev_if_t * enetIfPtr);/*!< MAC close interface*/ |
bogdanm | 83:8a40adfe8776 | 443 | uint32_t (* enet_mac_send)(enet_dev_if_t * enetIfPtr, uint8_t *packet, uint32_t size);/*!< MAC send packets*/ |
bogdanm | 83:8a40adfe8776 | 444 | #if !ENET_RECEIVE_ALL_INTERRUPT |
bogdanm | 83:8a40adfe8776 | 445 | uint32_t (* enet_mac_receive)(enet_dev_if_t * enetIfPtr, enet_mac_packet_buffer_t *packBuffer);/*!< MAC receive interface*/ |
bogdanm | 83:8a40adfe8776 | 446 | #endif |
bogdanm | 83:8a40adfe8776 | 447 | uint32_t (* enet_mii_read)(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr);/*!< MII reads PHY*/ |
bogdanm | 83:8a40adfe8776 | 448 | uint32_t (* enet_mii_write)(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t data);/*!< MII writes PHY*/ |
bogdanm | 83:8a40adfe8776 | 449 | uint32_t (* enet_add_multicast_group)(uint32_t instance, enet_multicast_group_t *multiGroupPtr, uint8_t *groupAddr);/*!< Add multicast group*/ |
bogdanm | 83:8a40adfe8776 | 450 | uint32_t (* enet_leave_multicast_group)(uint32_t instance, enet_multicast_group_t *multiGroupPtr, uint8_t *groupAddr);/*!< Leave multicast group*/ |
bogdanm | 83:8a40adfe8776 | 451 | } enet_mac_api_t; |
bogdanm | 83:8a40adfe8776 | 452 | |
bogdanm | 83:8a40adfe8776 | 453 | /******************************************************************* |
bogdanm | 83:8a40adfe8776 | 454 | * Global variables |
bogdanm | 83:8a40adfe8776 | 455 | |
bogdanm | 83:8a40adfe8776 | 456 | ***********************************************************************/ |
bogdanm | 83:8a40adfe8776 | 457 | extern const enet_mac_api_t g_enetMacApi; |
bogdanm | 83:8a40adfe8776 | 458 | |
bogdanm | 83:8a40adfe8776 | 459 | /******************************************************************************* |
bogdanm | 83:8a40adfe8776 | 460 | * API |
bogdanm | 83:8a40adfe8776 | 461 | ******************************************************************************/ |
bogdanm | 83:8a40adfe8776 | 462 | |
bogdanm | 83:8a40adfe8776 | 463 | #if defined(__cplusplus) |
bogdanm | 83:8a40adfe8776 | 464 | extern "C" { |
bogdanm | 83:8a40adfe8776 | 465 | #endif |
bogdanm | 83:8a40adfe8776 | 466 | |
bogdanm | 83:8a40adfe8776 | 467 | /*! |
bogdanm | 83:8a40adfe8776 | 468 | * @name ENET Driver |
bogdanm | 83:8a40adfe8776 | 469 | * @{ |
bogdanm | 83:8a40adfe8776 | 470 | */ |
bogdanm | 83:8a40adfe8776 | 471 | |
bogdanm | 83:8a40adfe8776 | 472 | |
bogdanm | 83:8a40adfe8776 | 473 | #if FSL_FEATURE_ENET_SUPPORT_PTP |
bogdanm | 83:8a40adfe8776 | 474 | /*! |
bogdanm | 83:8a40adfe8776 | 475 | * @brief Initializes the ENET PTP context structure with the basic configuration. |
bogdanm | 83:8a40adfe8776 | 476 | * |
bogdanm | 83:8a40adfe8776 | 477 | * @param macContextPtr The pointer to the ENET MAC macContext structure. |
bogdanm | 83:8a40adfe8776 | 478 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 479 | */ |
bogdanm | 83:8a40adfe8776 | 480 | uint32_t enet_ptp_init(enet_private_ptp_buffer_t *privatePtpPtr, uint32_t ptpRxBufferNum, enet_mac_ptp_ts_data_t *ptpTsRxDataPtr, uint32_t ptpTxBufferNum, enet_mac_ptp_ts_data_t *ptpTsTxDataPtr); |
bogdanm | 83:8a40adfe8776 | 481 | |
bogdanm | 83:8a40adfe8776 | 482 | /*! |
bogdanm | 83:8a40adfe8776 | 483 | * @brief Initializes the ENET PTP timer with the basic configuration. |
bogdanm | 83:8a40adfe8776 | 484 | * |
bogdanm | 83:8a40adfe8776 | 485 | * After the PTP starts, the 1588 timer also starts running. If the user wants the 1588 timer |
bogdanm | 83:8a40adfe8776 | 486 | * as the slave, enable the isSlaveEnabled flag. |
bogdanm | 83:8a40adfe8776 | 487 | * |
bogdanm | 83:8a40adfe8776 | 488 | * @param instance The ENET instance number. |
bogdanm | 83:8a40adfe8776 | 489 | * @param ptpCfgPtr The pointer to the basic PTP timer configuration structure. |
bogdanm | 83:8a40adfe8776 | 490 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 491 | */ |
bogdanm | 83:8a40adfe8776 | 492 | uint32_t enet_ptp_start(uint32_t instance, bool isSlaveEnabled); |
bogdanm | 83:8a40adfe8776 | 493 | |
bogdanm | 83:8a40adfe8776 | 494 | /*! |
bogdanm | 83:8a40adfe8776 | 495 | * @brief Parses the ENET packet. |
bogdanm | 83:8a40adfe8776 | 496 | * |
bogdanm | 83:8a40adfe8776 | 497 | * Parses the ENET message and checks if it is a PTP message. If it is a PTP message, |
bogdanm | 83:8a40adfe8776 | 498 | * the message is stored in the PTP information structure. Message parsing |
bogdanm | 83:8a40adfe8776 | 499 | * decides whether timestamp processing is done after that. |
bogdanm | 83:8a40adfe8776 | 500 | * |
bogdanm | 83:8a40adfe8776 | 501 | * @param packet The ENET packet. |
bogdanm | 83:8a40adfe8776 | 502 | * @param ptpTsPtr The pointer to the PTP data structure. |
bogdanm | 83:8a40adfe8776 | 503 | * @param isPtpMsg The PTP message flag. |
bogdanm | 83:8a40adfe8776 | 504 | * @param isFastEnabled The fast operation flag. If set, only check if it is a ptp message |
bogdanm | 83:8a40adfe8776 | 505 | * and doesn't store any ptp message. |
bogdanm | 83:8a40adfe8776 | 506 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 507 | */ |
bogdanm | 83:8a40adfe8776 | 508 | uint32_t enet_ptp_parse(uint8_t *packet, enet_mac_ptp_ts_data_t *ptpTsPtr, bool *isPtpMsg, bool isFastEnabled); |
bogdanm | 83:8a40adfe8776 | 509 | |
bogdanm | 83:8a40adfe8776 | 510 | /*! |
bogdanm | 83:8a40adfe8776 | 511 | * @brief Gets the current value of the ENET PTP time. |
bogdanm | 83:8a40adfe8776 | 512 | * |
bogdanm | 83:8a40adfe8776 | 513 | * @param ptpTimerPtr The PTP timer structure. |
bogdanm | 83:8a40adfe8776 | 514 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 515 | */ |
bogdanm | 83:8a40adfe8776 | 516 | uint32_t enet_ptp_get_time(enet_mac_ptp_time_t *ptpTimerPtr); |
bogdanm | 83:8a40adfe8776 | 517 | |
bogdanm | 83:8a40adfe8776 | 518 | /*! |
bogdanm | 83:8a40adfe8776 | 519 | * @brief Sets the current value of the ENET PTP time. |
bogdanm | 83:8a40adfe8776 | 520 | * |
bogdanm | 83:8a40adfe8776 | 521 | * @param ptpTimerPtr The PTP timer structure. |
bogdanm | 83:8a40adfe8776 | 522 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 523 | */ |
bogdanm | 83:8a40adfe8776 | 524 | uint32_t enet_ptp_set_time(enet_mac_ptp_time_t *ptpTimerPtr); |
bogdanm | 83:8a40adfe8776 | 525 | |
bogdanm | 83:8a40adfe8776 | 526 | /*! |
bogdanm | 83:8a40adfe8776 | 527 | * @brief Adjusts the ENET PTP time. |
bogdanm | 83:8a40adfe8776 | 528 | * |
bogdanm | 83:8a40adfe8776 | 529 | * @param instance The ENET instance number. |
bogdanm | 83:8a40adfe8776 | 530 | * @param drift The PTP timer drift value. |
bogdanm | 83:8a40adfe8776 | 531 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 532 | */ |
bogdanm | 83:8a40adfe8776 | 533 | uint32_t enet_ptp_correction_time(uint32_t instance, int32_t drift); |
bogdanm | 83:8a40adfe8776 | 534 | |
bogdanm | 83:8a40adfe8776 | 535 | |
bogdanm | 83:8a40adfe8776 | 536 | /*! |
bogdanm | 83:8a40adfe8776 | 537 | * @brief Stores the transmit timestamp. |
bogdanm | 83:8a40adfe8776 | 538 | * |
bogdanm | 83:8a40adfe8776 | 539 | * @param ptpBuffer The PTP buffer pointer. |
bogdanm | 83:8a40adfe8776 | 540 | * @param bdPtr The current transmit buffer descriptor. |
bogdanm | 83:8a40adfe8776 | 541 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 542 | */ |
bogdanm | 83:8a40adfe8776 | 543 | uint32_t enet_ptp_store_tx_timestamp(enet_private_ptp_buffer_t *ptpBuffer,void *bdPtr); |
bogdanm | 83:8a40adfe8776 | 544 | |
bogdanm | 83:8a40adfe8776 | 545 | /*! |
bogdanm | 83:8a40adfe8776 | 546 | * @brief Stores receive timestamp. |
bogdanm | 83:8a40adfe8776 | 547 | * |
bogdanm | 83:8a40adfe8776 | 548 | * @param ptpBuffer The PTP buffer pointer. |
bogdanm | 83:8a40adfe8776 | 549 | * @param packet The current receive packet. |
bogdanm | 83:8a40adfe8776 | 550 | * @param bdPtr The current receive buffer descriptor. |
bogdanm | 83:8a40adfe8776 | 551 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 552 | */ |
bogdanm | 83:8a40adfe8776 | 553 | uint32_t enet_ptp_store_rx_timestamp(enet_private_ptp_buffer_t *ptpBuffer, uint8_t *packet, void *bdPtr); |
bogdanm | 83:8a40adfe8776 | 554 | |
bogdanm | 83:8a40adfe8776 | 555 | /*! |
bogdanm | 83:8a40adfe8776 | 556 | * @brief Initializes the buffer queue for the PTP layer2 Ethernet packets. |
bogdanm | 83:8a40adfe8776 | 557 | * |
bogdanm | 83:8a40adfe8776 | 558 | * @param ptpBuffer The PTP buffer pointer. |
bogdanm | 83:8a40adfe8776 | 559 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 560 | */ |
bogdanm | 83:8a40adfe8776 | 561 | uint32_t enet_ptp_l2queue_init(enet_private_ptp_buffer_t *ptpBuffer, enet_ptp_l2queue_t *ptpL2QuePtr); |
bogdanm | 83:8a40adfe8776 | 562 | |
bogdanm | 83:8a40adfe8776 | 563 | /*! |
bogdanm | 83:8a40adfe8776 | 564 | * @brief Adds the PTP layer2 Ethernet packet to the PTP Ethernet packet queue. |
bogdanm | 83:8a40adfe8776 | 565 | * |
bogdanm | 83:8a40adfe8776 | 566 | * @param ptpQuePtr The ENET private ptp layer2 buffer queue structure pointer. |
bogdanm | 83:8a40adfe8776 | 567 | * @param packet The packet buffer pointer. |
bogdanm | 83:8a40adfe8776 | 568 | * @param length The packet length. |
bogdanm | 83:8a40adfe8776 | 569 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 570 | */ |
bogdanm | 83:8a40adfe8776 | 571 | uint32_t enet_ptp_service_l2packet(enet_ptp_l2queue_t * ptpQuePtr, uint8_t *packet, uint16_t length); |
bogdanm | 83:8a40adfe8776 | 572 | |
bogdanm | 83:8a40adfe8776 | 573 | /*! |
bogdanm | 83:8a40adfe8776 | 574 | * @brief Sends the PTP layer2 Ethernet packet to the Net. |
bogdanm | 83:8a40adfe8776 | 575 | * |
bogdanm | 83:8a40adfe8776 | 576 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 577 | * @param paramPtr The buffer from upper layer. |
bogdanm | 83:8a40adfe8776 | 578 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 579 | */ |
bogdanm | 83:8a40adfe8776 | 580 | uint32_t enet_ptp_send_l2packet(enet_dev_if_t * enetIfPtr, void *paramPtr); |
bogdanm | 83:8a40adfe8776 | 581 | |
bogdanm | 83:8a40adfe8776 | 582 | /*! |
bogdanm | 83:8a40adfe8776 | 583 | * @brief Receives the PTP layer2 Ethernet packet from the Net. |
bogdanm | 83:8a40adfe8776 | 584 | * |
bogdanm | 83:8a40adfe8776 | 585 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 586 | * @param paramPtr The buffer receive from net and will send to upper layer. |
bogdanm | 83:8a40adfe8776 | 587 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 588 | */ |
bogdanm | 83:8a40adfe8776 | 589 | uint32_t enet_ptp_receive_l2packet(enet_dev_if_t * enetIfPtr,void *paramPtr); |
bogdanm | 83:8a40adfe8776 | 590 | |
bogdanm | 83:8a40adfe8776 | 591 | /*! |
bogdanm | 83:8a40adfe8776 | 592 | * @brief Provides the handler for the 1588 stack to do PTP IOCTL. |
bogdanm | 83:8a40adfe8776 | 593 | * |
bogdanm | 83:8a40adfe8776 | 594 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 595 | * @param commandId The command id. |
bogdanm | 83:8a40adfe8776 | 596 | * @param inOutPtr The data buffer. |
bogdanm | 83:8a40adfe8776 | 597 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 598 | */ |
bogdanm | 83:8a40adfe8776 | 599 | uint32_t enet_ptp_ioctl(enet_dev_if_t * enetIfPtr, uint32_t commandId, void *inOutPtr); |
bogdanm | 83:8a40adfe8776 | 600 | |
bogdanm | 83:8a40adfe8776 | 601 | /*! |
bogdanm | 83:8a40adfe8776 | 602 | * @brief Stops the ENET PTP timer. |
bogdanm | 83:8a40adfe8776 | 603 | * |
bogdanm | 83:8a40adfe8776 | 604 | * @param instance The ENET instance number. |
bogdanm | 83:8a40adfe8776 | 605 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 606 | */ |
bogdanm | 83:8a40adfe8776 | 607 | uint32_t enet_ptp_stop(uint32_t instance); |
bogdanm | 83:8a40adfe8776 | 608 | |
bogdanm | 83:8a40adfe8776 | 609 | /*! |
bogdanm | 83:8a40adfe8776 | 610 | * @brief Checks whether the PTP ring buffer is full. |
bogdanm | 83:8a40adfe8776 | 611 | * |
bogdanm | 83:8a40adfe8776 | 612 | * @param ptpTsRingPtr The ENET PTP timestamp ring. |
bogdanm | 83:8a40adfe8776 | 613 | * @return True if the PTP ring buffer is full. Otherwise, false. |
bogdanm | 83:8a40adfe8776 | 614 | */ |
bogdanm | 83:8a40adfe8776 | 615 | bool enet_ptp_ring_is_full(enet_mac_ptp_ts_ring_t *ptpTsRingPtr); |
bogdanm | 83:8a40adfe8776 | 616 | |
bogdanm | 83:8a40adfe8776 | 617 | /*! |
bogdanm | 83:8a40adfe8776 | 618 | * @brief Updates the latest ring buffers. |
bogdanm | 83:8a40adfe8776 | 619 | * |
bogdanm | 83:8a40adfe8776 | 620 | * Adds the PTP message data to the PTP ring buffers and increases the |
bogdanm | 83:8a40adfe8776 | 621 | * PTP ring buffer index. |
bogdanm | 83:8a40adfe8776 | 622 | * |
bogdanm | 83:8a40adfe8776 | 623 | * @param ptpTsRingPtr The ENET PTP timestamp ring. |
bogdanm | 83:8a40adfe8776 | 624 | * @param data The PTP data buffer. |
bogdanm | 83:8a40adfe8776 | 625 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 626 | */ |
bogdanm | 83:8a40adfe8776 | 627 | uint32_t enet_ptp_ring_update(enet_mac_ptp_ts_ring_t *ptpTsRingPtr, enet_mac_ptp_ts_data_t *data); |
bogdanm | 83:8a40adfe8776 | 628 | |
bogdanm | 83:8a40adfe8776 | 629 | /*! |
bogdanm | 83:8a40adfe8776 | 630 | * @brief Searches the element in ring buffers with the message ID and Clock ID. |
bogdanm | 83:8a40adfe8776 | 631 | * |
bogdanm | 83:8a40adfe8776 | 632 | * @param ptpTsRingPtr The ENET PTP timestamp ring. |
bogdanm | 83:8a40adfe8776 | 633 | * @param data The PTP data buffer. |
bogdanm | 83:8a40adfe8776 | 634 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 635 | */ |
bogdanm | 83:8a40adfe8776 | 636 | uint32_t enet_ptp_ring_search(enet_mac_ptp_ts_ring_t *ptpTsRingPtr, enet_mac_ptp_ts_data_t *data); |
bogdanm | 83:8a40adfe8776 | 637 | |
bogdanm | 83:8a40adfe8776 | 638 | /*! |
bogdanm | 83:8a40adfe8776 | 639 | * @brief Calculates the ENET PTP ring buffer index. |
bogdanm | 83:8a40adfe8776 | 640 | * |
bogdanm | 83:8a40adfe8776 | 641 | * @param size The ring size. |
bogdanm | 83:8a40adfe8776 | 642 | * @param curIdx The current ring index. |
bogdanm | 83:8a40adfe8776 | 643 | * @param offset The offset index. |
bogdanm | 83:8a40adfe8776 | 644 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 645 | */ |
bogdanm | 83:8a40adfe8776 | 646 | static inline uint32_t enet_ptp_ring_index(uint32_t size, uint32_t curIdx, uint32_t offset) |
bogdanm | 83:8a40adfe8776 | 647 | { |
bogdanm | 83:8a40adfe8776 | 648 | return ((curIdx + offset) % size); |
bogdanm | 83:8a40adfe8776 | 649 | } |
bogdanm | 83:8a40adfe8776 | 650 | |
bogdanm | 83:8a40adfe8776 | 651 | /*! |
bogdanm | 83:8a40adfe8776 | 652 | * @brief Frees all ring buffers. |
bogdanm | 83:8a40adfe8776 | 653 | * |
bogdanm | 83:8a40adfe8776 | 654 | * @param enetContextPtr The ENET MAC context buffer. |
bogdanm | 83:8a40adfe8776 | 655 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 656 | */ |
bogdanm | 83:8a40adfe8776 | 657 | uint32_t enet_ptp_deinit(enet_mac_context_t *enetContextPtr); |
bogdanm | 83:8a40adfe8776 | 658 | |
bogdanm | 83:8a40adfe8776 | 659 | /*! |
bogdanm | 83:8a40adfe8776 | 660 | * @brief The ENET PTP time interrupt handler. |
bogdanm | 83:8a40adfe8776 | 661 | * |
bogdanm | 83:8a40adfe8776 | 662 | * @param enetIfPtr The ENET context structure pointer. |
bogdanm | 83:8a40adfe8776 | 663 | */ |
bogdanm | 83:8a40adfe8776 | 664 | void enet_mac_ts_isr(void *enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 665 | #endif |
bogdanm | 83:8a40adfe8776 | 666 | /*! |
bogdanm | 83:8a40adfe8776 | 667 | * @brief(R)MII Read function. |
bogdanm | 83:8a40adfe8776 | 668 | * |
bogdanm | 83:8a40adfe8776 | 669 | * @param instance The ENET instance number. |
bogdanm | 83:8a40adfe8776 | 670 | * @param phyAddr The PHY address. |
bogdanm | 83:8a40adfe8776 | 671 | * @param phyReg The PHY register. |
bogdanm | 83:8a40adfe8776 | 672 | * @param dataPtr The data read from MII. |
bogdanm | 83:8a40adfe8776 | 673 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 674 | */ |
bogdanm | 83:8a40adfe8776 | 675 | uint32_t enet_mii_read(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr); |
bogdanm | 83:8a40adfe8776 | 676 | |
bogdanm | 83:8a40adfe8776 | 677 | /*! |
bogdanm | 83:8a40adfe8776 | 678 | * @brief(R)MII Read function. |
bogdanm | 83:8a40adfe8776 | 679 | * |
bogdanm | 83:8a40adfe8776 | 680 | * @param instance The ENET instance number. |
bogdanm | 83:8a40adfe8776 | 681 | * @param phyAddr The PHY address. |
bogdanm | 83:8a40adfe8776 | 682 | * @param phyReg The PHY register. |
bogdanm | 83:8a40adfe8776 | 683 | * @param data The data write to MII. |
bogdanm | 83:8a40adfe8776 | 684 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 685 | */ |
bogdanm | 83:8a40adfe8776 | 686 | uint32_t enet_mii_write(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t data); |
bogdanm | 83:8a40adfe8776 | 687 | |
bogdanm | 83:8a40adfe8776 | 688 | /*! |
bogdanm | 83:8a40adfe8776 | 689 | * @brief Initializes ENET buffer descriptors. |
bogdanm | 83:8a40adfe8776 | 690 | * |
bogdanm | 83:8a40adfe8776 | 691 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 692 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 693 | */ |
bogdanm | 83:8a40adfe8776 | 694 | uint32_t enet_mac_bd_init(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 695 | |
bogdanm | 83:8a40adfe8776 | 696 | /*! |
bogdanm | 83:8a40adfe8776 | 697 | * @brief Initializes the ENET MAC MII(MDC/MDIO) interface. |
bogdanm | 83:8a40adfe8776 | 698 | * |
bogdanm | 83:8a40adfe8776 | 699 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 700 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 701 | */ |
bogdanm | 83:8a40adfe8776 | 702 | uint32_t enet_mac_mii_init(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 703 | |
bogdanm | 83:8a40adfe8776 | 704 | /*! |
bogdanm | 83:8a40adfe8776 | 705 | * @brief Initialize the ENET receive buffer descriptors. |
bogdanm | 83:8a40adfe8776 | 706 | * |
bogdanm | 83:8a40adfe8776 | 707 | * If you open ENET_RECEIVE_ALL_INTERRUPT to do receive |
bogdanm | 83:8a40adfe8776 | 708 | * data buffer numbers can be the same as the receive descriptor numbers. |
bogdanm | 83:8a40adfe8776 | 709 | * But if you close ENET_RECEIVE_ALL_INTERRUPT and choose polling receive |
bogdanm | 83:8a40adfe8776 | 710 | * frames please make sure the receive data buffers are more than |
bogdanm | 83:8a40adfe8776 | 711 | * buffer descriptor numbers to guarantee a good performance. |
bogdanm | 83:8a40adfe8776 | 712 | * |
bogdanm | 83:8a40adfe8776 | 713 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 714 | * @param rxbdCfg The receive buffer descriptor configuration. |
bogdanm | 83:8a40adfe8776 | 715 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 716 | */ |
bogdanm | 83:8a40adfe8776 | 717 | uint32_t enet_mac_rxbd_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg); |
bogdanm | 83:8a40adfe8776 | 718 | |
bogdanm | 83:8a40adfe8776 | 719 | /*! |
bogdanm | 83:8a40adfe8776 | 720 | * @brief Deinitialize the ENET receive buffer descriptors. |
bogdanm | 83:8a40adfe8776 | 721 | * |
bogdanm | 83:8a40adfe8776 | 722 | * Deinitialize the ENET receive buffer descriptors. |
bogdanm | 83:8a40adfe8776 | 723 | * |
bogdanm | 83:8a40adfe8776 | 724 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 725 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 726 | */ |
bogdanm | 83:8a40adfe8776 | 727 | |
bogdanm | 83:8a40adfe8776 | 728 | uint32_t enet_mac_rxbd_deinit(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 729 | |
bogdanm | 83:8a40adfe8776 | 730 | /*! |
bogdanm | 83:8a40adfe8776 | 731 | * @brief Initialize the ENET transmit buffer descriptors. |
bogdanm | 83:8a40adfe8776 | 732 | * |
bogdanm | 83:8a40adfe8776 | 733 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 734 | * @param txbdCfg The transmit buffer descriptor configuration. |
bogdanm | 83:8a40adfe8776 | 735 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 736 | */ |
bogdanm | 83:8a40adfe8776 | 737 | uint32_t enet_mac_txbd_init(enet_dev_if_t * enetIfPtr, enet_txbd_config_t *txbdCfg); |
bogdanm | 83:8a40adfe8776 | 738 | |
bogdanm | 83:8a40adfe8776 | 739 | /*! |
bogdanm | 83:8a40adfe8776 | 740 | * @brief Deinitialize the ENET transmit buffer descriptors. |
bogdanm | 83:8a40adfe8776 | 741 | * |
bogdanm | 83:8a40adfe8776 | 742 | * Deinitialize the ENET transmit buffer descriptors. |
bogdanm | 83:8a40adfe8776 | 743 | * |
bogdanm | 83:8a40adfe8776 | 744 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 745 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 746 | */ |
bogdanm | 83:8a40adfe8776 | 747 | uint32_t enet_mac_txbd_deinit(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 748 | |
bogdanm | 83:8a40adfe8776 | 749 | /*! |
bogdanm | 83:8a40adfe8776 | 750 | * @brief Initializes ENET MAC FIFO and accelerator with the basic configuration. |
bogdanm | 83:8a40adfe8776 | 751 | * |
bogdanm | 83:8a40adfe8776 | 752 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 753 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 754 | */ |
bogdanm | 83:8a40adfe8776 | 755 | uint32_t enet_mac_configure_fifo_accel(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 756 | |
bogdanm | 83:8a40adfe8776 | 757 | /*! |
bogdanm | 83:8a40adfe8776 | 758 | * @brief the ENET controller with the basic configuration. |
bogdanm | 83:8a40adfe8776 | 759 | * |
bogdanm | 83:8a40adfe8776 | 760 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 761 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 762 | */ |
bogdanm | 83:8a40adfe8776 | 763 | uint32_t enet_mac_configure_controller(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 764 | |
bogdanm | 83:8a40adfe8776 | 765 | /*! |
bogdanm | 83:8a40adfe8776 | 766 | * @brief Deinit the ENET device. |
bogdanm | 83:8a40adfe8776 | 767 | * |
bogdanm | 83:8a40adfe8776 | 768 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 769 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 770 | */ |
bogdanm | 83:8a40adfe8776 | 771 | uint32_t enet_mac_deinit(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 772 | |
bogdanm | 83:8a40adfe8776 | 773 | #if !ENET_RECEIVE_ALL_INTERRUPT |
bogdanm | 83:8a40adfe8776 | 774 | /*! |
bogdanm | 83:8a40adfe8776 | 775 | * @brief Updates the receive buffer descriptor. |
bogdanm | 83:8a40adfe8776 | 776 | * |
bogdanm | 83:8a40adfe8776 | 777 | * This updates the used receive buffer descriptor ring to |
bogdanm | 83:8a40adfe8776 | 778 | * ensure that the used BDS is correctly used again. It cleans |
bogdanm | 83:8a40adfe8776 | 779 | * the status region and sets the control region of the used receive buffer |
bogdanm | 83:8a40adfe8776 | 780 | * descriptor. If the isBufferUpdate flag is set, the data buffer in the |
bogdanm | 83:8a40adfe8776 | 781 | * buffer descriptor is updated. |
bogdanm | 83:8a40adfe8776 | 782 | * |
bogdanm | 83:8a40adfe8776 | 783 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 784 | * @param isBufferUpdate The data buffer update flag. |
bogdanm | 83:8a40adfe8776 | 785 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 786 | */ |
bogdanm | 83:8a40adfe8776 | 787 | uint32_t enet_mac_update_rxbd(enet_dev_if_t * enetIfPtr, bool isBufferUpdate); |
bogdanm | 83:8a40adfe8776 | 788 | #else |
bogdanm | 83:8a40adfe8776 | 789 | /*! |
bogdanm | 83:8a40adfe8776 | 790 | * @brief Updates the receive buffer descriptor. |
bogdanm | 83:8a40adfe8776 | 791 | * |
bogdanm | 83:8a40adfe8776 | 792 | * Clears the status region and sets the control region of the current receive buffer |
bogdanm | 83:8a40adfe8776 | 793 | * descriptor to ensure that it is used correctly again. It increases the buffer |
bogdanm | 83:8a40adfe8776 | 794 | * descriptor index to the next buffer descriptor. |
bogdanm | 83:8a40adfe8776 | 795 | * |
bogdanm | 83:8a40adfe8776 | 796 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 797 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 798 | */ |
bogdanm | 83:8a40adfe8776 | 799 | uint32_t enet_mac_update_rxbd(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 800 | #endif |
bogdanm | 83:8a40adfe8776 | 801 | /*! |
bogdanm | 83:8a40adfe8776 | 802 | * @brief Processes the ENET receive frame error statistics. |
bogdanm | 83:8a40adfe8776 | 803 | * |
bogdanm | 83:8a40adfe8776 | 804 | * This interface gets the error statistics of the received frame. |
bogdanm | 83:8a40adfe8776 | 805 | * Because the error information is in the last BD of a frame, this interface |
bogdanm | 83:8a40adfe8776 | 806 | * should be called when processing the last BD of a frame. |
bogdanm | 83:8a40adfe8776 | 807 | * |
bogdanm | 83:8a40adfe8776 | 808 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 809 | * @param data The current control and status data of the buffer descriptor. |
bogdanm | 83:8a40adfe8776 | 810 | * @return The frame error status. |
bogdanm | 83:8a40adfe8776 | 811 | * - True if the frame has an error. |
bogdanm | 83:8a40adfe8776 | 812 | * - False if the frame does not have an error. |
bogdanm | 83:8a40adfe8776 | 813 | */ |
bogdanm | 83:8a40adfe8776 | 814 | bool enet_mac_rx_error_stats(enet_dev_if_t * enetIfPtr, uint32_t data); |
bogdanm | 83:8a40adfe8776 | 815 | |
bogdanm | 83:8a40adfe8776 | 816 | /*! |
bogdanm | 83:8a40adfe8776 | 817 | * @brief Processes the ENET transmit frame statistics. |
bogdanm | 83:8a40adfe8776 | 818 | * |
bogdanm | 83:8a40adfe8776 | 819 | * This interface gets the error statistics of the transmit frame. |
bogdanm | 83:8a40adfe8776 | 820 | * Because the error information is in the last BD of a frame, this interface |
bogdanm | 83:8a40adfe8776 | 821 | * should be called when processing the last BD of a frame. |
bogdanm | 83:8a40adfe8776 | 822 | * |
bogdanm | 83:8a40adfe8776 | 823 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 824 | * @param curBd The current buffer descriptor. |
bogdanm | 83:8a40adfe8776 | 825 | */ |
bogdanm | 83:8a40adfe8776 | 826 | void enet_mac_tx_error_stats(enet_dev_if_t * enetIfPtr,void *curBd); |
bogdanm | 83:8a40adfe8776 | 827 | |
bogdanm | 83:8a40adfe8776 | 828 | /*! |
bogdanm | 83:8a40adfe8776 | 829 | * @brief ENET transmit buffer descriptor cleanup. |
bogdanm | 83:8a40adfe8776 | 830 | * |
bogdanm | 83:8a40adfe8776 | 831 | * First, store the transmit frame error statistic and PTP timestamp of the transmitted packets. |
bogdanm | 83:8a40adfe8776 | 832 | * Second, clean up the used transmit buffer descriptors. |
bogdanm | 83:8a40adfe8776 | 833 | * If the PTP 1588 feature is open, this interface captures the 1588 timestamp. |
bogdanm | 83:8a40adfe8776 | 834 | * It is called by the transmit interrupt handler. |
bogdanm | 83:8a40adfe8776 | 835 | * |
bogdanm | 83:8a40adfe8776 | 836 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 837 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 838 | */ |
bogdanm | 83:8a40adfe8776 | 839 | uint32_t enet_mac_tx_cleanup(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 840 | #if !ENET_RECEIVE_ALL_INTERRUPT |
bogdanm | 83:8a40adfe8776 | 841 | /*! |
bogdanm | 83:8a40adfe8776 | 842 | * @brief Receives ENET packets. |
bogdanm | 83:8a40adfe8776 | 843 | * |
bogdanm | 83:8a40adfe8776 | 844 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 845 | * @param packBuffer The received data buffer. |
bogdanm | 83:8a40adfe8776 | 846 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 847 | */ |
bogdanm | 83:8a40adfe8776 | 848 | uint32_t enet_mac_receive(enet_dev_if_t * enetIfPtr, enet_mac_packet_buffer_t *packBuffer); |
bogdanm | 83:8a40adfe8776 | 849 | #else |
bogdanm | 83:8a40adfe8776 | 850 | /*! |
bogdanm | 83:8a40adfe8776 | 851 | * @brief Receives ENET packets. |
bogdanm | 83:8a40adfe8776 | 852 | * |
bogdanm | 83:8a40adfe8776 | 853 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 854 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 855 | */ |
bogdanm | 83:8a40adfe8776 | 856 | uint32_t enet_mac_receive(enet_dev_if_t * enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 857 | #endif |
bogdanm | 83:8a40adfe8776 | 858 | /*! |
bogdanm | 83:8a40adfe8776 | 859 | * @brief Transmits ENET packets. |
bogdanm | 83:8a40adfe8776 | 860 | * |
bogdanm | 83:8a40adfe8776 | 861 | * @param enetIfPtr The ENET context structure. |
bogdanm | 83:8a40adfe8776 | 862 | * @param packet The frame to be transmitted. |
bogdanm | 83:8a40adfe8776 | 863 | * @param size The frame size. |
bogdanm | 83:8a40adfe8776 | 864 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 865 | */ |
bogdanm | 83:8a40adfe8776 | 866 | uint32_t enet_mac_send(enet_dev_if_t * enetIfPtr, uint8_t *packet, uint32_t size); |
bogdanm | 83:8a40adfe8776 | 867 | |
bogdanm | 83:8a40adfe8776 | 868 | /*! |
bogdanm | 83:8a40adfe8776 | 869 | * @brief The ENET receive interrupt handler. |
bogdanm | 83:8a40adfe8776 | 870 | * |
bogdanm | 83:8a40adfe8776 | 871 | * @param enetIfPtr The ENET context structure pointer. |
bogdanm | 83:8a40adfe8776 | 872 | */ |
bogdanm | 83:8a40adfe8776 | 873 | void enet_mac_rx_isr(void *enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 874 | |
bogdanm | 83:8a40adfe8776 | 875 | /*! |
bogdanm | 83:8a40adfe8776 | 876 | * @brief The ENET transmit interrupt handler. |
bogdanm | 83:8a40adfe8776 | 877 | * |
bogdanm | 83:8a40adfe8776 | 878 | * @param enetIfPtr The ENET context structure pointer. |
bogdanm | 83:8a40adfe8776 | 879 | */ |
bogdanm | 83:8a40adfe8776 | 880 | void enet_mac_tx_isr(void *enetIfPtr); |
bogdanm | 83:8a40adfe8776 | 881 | |
bogdanm | 83:8a40adfe8776 | 882 | /*! |
bogdanm | 83:8a40adfe8776 | 883 | * @brief Calculates the CRC hash value. |
bogdanm | 83:8a40adfe8776 | 884 | * |
bogdanm | 83:8a40adfe8776 | 885 | * @param address The ENET MAC hardware address. |
bogdanm | 83:8a40adfe8776 | 886 | * @param crcVlaue The calculated CRC value of the Mac address. |
bogdanm | 83:8a40adfe8776 | 887 | */ |
bogdanm | 83:8a40adfe8776 | 888 | void enet_mac_calculate_crc32(enetMacAddr address, uint32_t *crcValue); |
bogdanm | 83:8a40adfe8776 | 889 | |
bogdanm | 83:8a40adfe8776 | 890 | /*! |
bogdanm | 83:8a40adfe8776 | 891 | * @brief Adds the ENET device to a multicast group. |
bogdanm | 83:8a40adfe8776 | 892 | * |
bogdanm | 83:8a40adfe8776 | 893 | * @param instance The ENET instance number. |
bogdanm | 83:8a40adfe8776 | 894 | * @param multiGroupPtr The ENET multicast group structure. |
bogdanm | 83:8a40adfe8776 | 895 | * @param address The ENET MAC hardware address. |
bogdanm | 83:8a40adfe8776 | 896 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 897 | */ |
bogdanm | 83:8a40adfe8776 | 898 | uint32_t enet_mac_add_multicast_group(uint32_t instance, enet_multicast_group_t *multiGroupPtr, enetMacAddr address); |
bogdanm | 83:8a40adfe8776 | 899 | |
bogdanm | 83:8a40adfe8776 | 900 | /*! |
bogdanm | 83:8a40adfe8776 | 901 | * @brief Moves the ENET device from a multicast group. |
bogdanm | 83:8a40adfe8776 | 902 | * |
bogdanm | 83:8a40adfe8776 | 903 | * @param instance The ENET instance number. |
bogdanm | 83:8a40adfe8776 | 904 | * @param multiGroupPtr The ENET multicast group structure. |
bogdanm | 83:8a40adfe8776 | 905 | * @param address The ENET MAC hardware address. |
bogdanm | 83:8a40adfe8776 | 906 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 907 | */ |
bogdanm | 83:8a40adfe8776 | 908 | uint32_t enet_mac_leave_multicast_group(uint32_t instance, enet_multicast_group_t *multiGroupPtr, enetMacAddr address); |
bogdanm | 83:8a40adfe8776 | 909 | |
bogdanm | 83:8a40adfe8776 | 910 | /*! |
bogdanm | 83:8a40adfe8776 | 911 | * @brief Initializes the ENET with the basic configuration. |
bogdanm | 83:8a40adfe8776 | 912 | * |
bogdanm | 83:8a40adfe8776 | 913 | * @param enetIfPtr The pointer to the basic configuration structure. |
bogdanm | 83:8a40adfe8776 | 914 | * @return The execution status. |
bogdanm | 83:8a40adfe8776 | 915 | */ |
bogdanm | 83:8a40adfe8776 | 916 | uint32_t enet_mac_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg, |
bogdanm | 83:8a40adfe8776 | 917 | enet_txbd_config_t *txbdCfg); |
bogdanm | 83:8a40adfe8776 | 918 | |
bogdanm | 83:8a40adfe8776 | 919 | /*! |
bogdanm | 83:8a40adfe8776 | 920 | * @brief Enqueues a data buffer to the buffer queue. |
bogdanm | 83:8a40adfe8776 | 921 | * |
bogdanm | 83:8a40adfe8776 | 922 | * @param queue The buffer queue. |
bogdanm | 83:8a40adfe8776 | 923 | * @param buffer The buffer to add to the buffer queue. |
bogdanm | 83:8a40adfe8776 | 924 | */ |
bogdanm | 83:8a40adfe8776 | 925 | void enet_mac_enqueue_buffer( void **queue, void *buffer); |
bogdanm | 83:8a40adfe8776 | 926 | |
bogdanm | 83:8a40adfe8776 | 927 | /*! |
bogdanm | 83:8a40adfe8776 | 928 | * @brief Dequeues a buffer from the buffer queue. |
bogdanm | 83:8a40adfe8776 | 929 | * |
bogdanm | 83:8a40adfe8776 | 930 | * @param queue The buffer queue. |
bogdanm | 83:8a40adfe8776 | 931 | * @return The dequeued data buffer. |
bogdanm | 83:8a40adfe8776 | 932 | */ |
bogdanm | 83:8a40adfe8776 | 933 | void *enet_mac_dequeue_buffer( void **queue); |
bogdanm | 83:8a40adfe8776 | 934 | |
bogdanm | 83:8a40adfe8776 | 935 | /* @} */ |
bogdanm | 83:8a40adfe8776 | 936 | |
bogdanm | 83:8a40adfe8776 | 937 | #if defined(__cplusplus) |
bogdanm | 83:8a40adfe8776 | 938 | extern } |
bogdanm | 83:8a40adfe8776 | 939 | #endif |
bogdanm | 83:8a40adfe8776 | 940 | |
bogdanm | 83:8a40adfe8776 | 941 | /*! @}*/ |
bogdanm | 83:8a40adfe8776 | 942 | |
bogdanm | 83:8a40adfe8776 | 943 | #endif /* __FSL_ENET_DRIVER_H__ */ |
bogdanm | 83:8a40adfe8776 | 944 | /******************************************************************************* |
bogdanm | 83:8a40adfe8776 | 945 | * EOF |
bogdanm | 83:8a40adfe8776 | 946 | ******************************************************************************/ |
bogdanm | 83:8a40adfe8776 | 947 |