version_2.0

Dependents:   cc3000_ping_demo_try_2

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Wed Jun 11 15:14:05 2014 +0100
Revision:
85:024bf7f99721
Parent:
82:6473597d706e
Release 85 of the mbed library

Main changes:

- K64F Ethernet fixes
- Updated tests
- Fixes for various mbed targets
- Code cleanup: fixed warnings, more consistent code style
- GCC support for K64F

There is a known issue with the I2C interface on some ST targets. If you
find the I2C interface problematic on your ST board, please log a bug
against this on mbed.org.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 82:6473597d706e 1 /*
bogdanm 82:6473597d706e 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
bogdanm 82:6473597d706e 3 * All rights reserved.
bogdanm 82:6473597d706e 4 *
bogdanm 82:6473597d706e 5 * Redistribution and use in source and binary forms, with or without modification,
bogdanm 82:6473597d706e 6 * are permitted provided that the following conditions are met:
bogdanm 82:6473597d706e 7 *
bogdanm 82:6473597d706e 8 * o Redistributions of source code must retain the above copyright notice, this list
bogdanm 82:6473597d706e 9 * of conditions and the following disclaimer.
bogdanm 82:6473597d706e 10 *
bogdanm 82:6473597d706e 11 * o Redistributions in binary form must reproduce the above copyright notice, this
bogdanm 82:6473597d706e 12 * list of conditions and the following disclaimer in the documentation and/or
bogdanm 82:6473597d706e 13 * other materials provided with the distribution.
bogdanm 82:6473597d706e 14 *
bogdanm 82:6473597d706e 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
bogdanm 82:6473597d706e 16 * contributors may be used to endorse or promote products derived from this
bogdanm 82:6473597d706e 17 * software without specific prior written permission.
bogdanm 82:6473597d706e 18 *
bogdanm 82:6473597d706e 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
bogdanm 82:6473597d706e 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
bogdanm 82:6473597d706e 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bogdanm 82:6473597d706e 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
bogdanm 82:6473597d706e 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
bogdanm 82:6473597d706e 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
bogdanm 82:6473597d706e 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
bogdanm 82:6473597d706e 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
bogdanm 82:6473597d706e 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
bogdanm 82:6473597d706e 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bogdanm 82:6473597d706e 29 */
bogdanm 82:6473597d706e 30
bogdanm 82:6473597d706e 31 #ifndef __FSL_ENET_HAL_H__
bogdanm 82:6473597d706e 32 #define __FSL_ENET_HAL_H__
bogdanm 82:6473597d706e 33
bogdanm 82:6473597d706e 34 #include <stdint.h>
bogdanm 82:6473597d706e 35 #include <stdbool.h>
bogdanm 82:6473597d706e 36 #include "fsl_device_registers.h"
bogdanm 82:6473597d706e 37 #include "fsl_enet_features.h"
bogdanm 82:6473597d706e 38 #include <assert.h>
bogdanm 82:6473597d706e 39
bogdanm 82:6473597d706e 40 /*!
bogdanm 82:6473597d706e 41 * @addtogroup enet_hal
bogdanm 82:6473597d706e 42 * @{
bogdanm 82:6473597d706e 43 */
bogdanm 82:6473597d706e 44
bogdanm 82:6473597d706e 45 /*******************************************************************************
bogdanm 82:6473597d706e 46 * Definitions
bogdanm 82:6473597d706e 47 ******************************************************************************/
bogdanm 82:6473597d706e 48 /*! @brief Defines the system endian type.*/
bogdanm 82:6473597d706e 49 #define SYSTEM_LITTLE_ENDIAN (1)
bogdanm 82:6473597d706e 50
bogdanm 82:6473597d706e 51 /*! @brief Define macro to do the endianness swap*/
bogdanm 82:6473597d706e 52 #define BSWAP_16(x) (uint16_t)((uint16_t)(((uint16_t)(x) & (uint16_t)0xFF00) >> 0x8) | (uint16_t)(((uint16_t)(x) & (uint16_t)0xFF) << 0x8))
bogdanm 82:6473597d706e 53 #define BSWAP_32(x) (uint32_t)((((uint32_t)(x) & 0x00FFU) << 24) | (((uint32_t)(x) & 0x00FF00U) << 8) | (((uint32_t)(x) & 0xFF0000U) >> 8) | (((uint32_t)(x) & 0xFF000000U) >> 24))
bogdanm 82:6473597d706e 54 #if SYSTEM_LITTLE_ENDIAN && FSL_FEATURE_ENET_DMA_BIG_ENDIAN_ONLY
bogdanm 82:6473597d706e 55 #define HTONS(n) BSWAP_16(n)
bogdanm 82:6473597d706e 56 #define HTONL(n) BSWAP_32(n)
bogdanm 82:6473597d706e 57 #define NTOHS(n) BSWAP_16(n)
bogdanm 82:6473597d706e 58 #define NTOHL(n) BSWAP_32(n)
bogdanm 82:6473597d706e 59 #else
bogdanm 82:6473597d706e 60 #define HTONS(n) (n)
bogdanm 82:6473597d706e 61 #define HTONL(n) (n)
bogdanm 82:6473597d706e 62 #define NTOHS(n) (n)
bogdanm 82:6473597d706e 63 #define NTOHL(n) (n)
bogdanm 82:6473597d706e 64 #endif
bogdanm 82:6473597d706e 65
bogdanm 82:6473597d706e 66 /*! @brief Defines the Status return codes.*/
bogdanm 82:6473597d706e 67 typedef enum _enet_status
bogdanm 82:6473597d706e 68 {
bogdanm 82:6473597d706e 69 kStatus_ENET_Success = 0,
bogdanm 82:6473597d706e 70 kStatus_ENET_InvalidInput, /*!< Invalid ENET input parameter */
bogdanm 82:6473597d706e 71 kStatus_ENET_MemoryAllocateFail, /*!< Memory allocate failure*/
bogdanm 82:6473597d706e 72 kStatus_ENET_GetClockFreqFail, /*!< Get clock frequency failure*/
bogdanm 82:6473597d706e 73 kStatus_ENET_Initialized, /*!< ENET device already initialized*/
bogdanm 82:6473597d706e 74 kStatus_ENET_Layer2QueueNull, /*!< NULL L2 PTP buffer queue pointer*/
bogdanm 82:6473597d706e 75 kStatus_ENET_Layer2OverLarge, /*!< Layer2 packet length over large*/
bogdanm 82:6473597d706e 76 kStatus_ENET_Layer2BufferFull, /*!< Layer2 packet buffer full*/
bogdanm 82:6473597d706e 77 kStatus_ENET_PtpringBufferFull, /*!< PTP ring buffer full*/
bogdanm 82:6473597d706e 78 kStatus_ENET_PtpringBufferEmpty, /*!< PTP ring buffer empty*/
bogdanm 82:6473597d706e 79 kStatus_ENET_Miiuninitialized, /*!< MII uninitialized*/
bogdanm 82:6473597d706e 80 kStatus_ENET_RxbdInvalid, /*!< Receive buffer descriptor invalid*/
bogdanm 82:6473597d706e 81 kStatus_ENET_RxbdEmpty, /*!< Receive buffer descriptor empty*/
bogdanm 82:6473597d706e 82 kStatus_ENET_RxbdTrunc, /*!< Receive buffer descriptor truncate*/
bogdanm 82:6473597d706e 83 kStatus_ENET_RxbdError, /*!< Receive buffer descriptor error*/
bogdanm 82:6473597d706e 84 kStatus_ENET_RxBdFull, /*!< Receive buffer descriptor full*/
bogdanm 82:6473597d706e 85 kStatus_ENET_SmallBdSize, /*!< Small receive buffer size*/
bogdanm 82:6473597d706e 86 kStatus_ENET_LargeBufferFull, /*!< Receive large buffer full*/
bogdanm 82:6473597d706e 87 kStatus_ENET_TxbdFull, /*!< Transmit buffer descriptor full*/
bogdanm 82:6473597d706e 88 kStatus_ENET_TxbdNull, /*!< Transmit buffer descriptor Null*/
bogdanm 82:6473597d706e 89 kStatus_ENET_TxBufferNull, /*!< Transmit data buffer Null*/
bogdanm 82:6473597d706e 90 kStatus_ENET_NoRxBufferLeft, /*!< No more receive buffer left*/
bogdanm 82:6473597d706e 91 kStatus_ENET_UnknownCommand, /*!< Invalid ENET PTP IOCTL command*/
bogdanm 82:6473597d706e 92 kStatus_ENET_TimeOut, /*!< ENET Timeout*/
bogdanm 82:6473597d706e 93 kStatus_ENET_MulticastPointerNull, /*!< Null multicast group pointer*/
bogdanm 82:6473597d706e 94 kStatus_ENET_AlreadyAddedMulticast /*!< Have Already added to multicast group*/
bogdanm 82:6473597d706e 95 } enet_status_t;
bogdanm 82:6473597d706e 96
bogdanm 82:6473597d706e 97
bogdanm 82:6473597d706e 98 #if FSL_FEATURE_ENET_DMA_BIG_ENDIAN_ONLY && SYSTEM_LITTLE_ENDIAN
bogdanm 82:6473597d706e 99 /*! @brief Defines the control and status regions of the receive buffer descriptor.*/
bogdanm 82:6473597d706e 100 typedef enum _enet_rx_bd_control_status
bogdanm 82:6473597d706e 101 {
bogdanm 82:6473597d706e 102 kEnetRxBdBroadCast = 0x8000, /*!< Broadcast */
bogdanm 82:6473597d706e 103 kEnetRxBdMultiCast = 0x4000, /*!< Multicast*/
bogdanm 82:6473597d706e 104 kEnetRxBdLengthViolation = 0x2000, /*!< Receive length violation*/
bogdanm 82:6473597d706e 105 kEnetRxBdNoOctet = 0x1000, /*!< Receive non-octet aligned frame*/
bogdanm 82:6473597d706e 106 kEnetRxBdCrc = 0x0400, /*!< Receive CRC error*/
bogdanm 82:6473597d706e 107 kEnetRxBdOverRun = 0x0200, /*!< Receive FIFO overrun*/
bogdanm 82:6473597d706e 108 kEnetRxBdTrunc = 0x0100, /*!< Frame is truncated */
bogdanm 82:6473597d706e 109 kEnetRxBdEmpty = 0x0080, /*!< Empty bit*/
bogdanm 82:6473597d706e 110 kEnetRxBdRxSoftOwner1 = 0x0040, /*!< Receive software owner*/
bogdanm 82:6473597d706e 111 kEnetRxBdWrap = 0x0020, /*!< Update buffer descriptor*/
bogdanm 82:6473597d706e 112 kEnetRxBdRxSoftOwner2 = 0x0010, /*!< Receive software owner*/
bogdanm 82:6473597d706e 113 kEnetRxBdLast = 0x0008, /*!< Last BD in the frame*/
bogdanm 82:6473597d706e 114 kEnetRxBdMiss = 0x0001 /*!< Receive for promiscuous mode*/
bogdanm 82:6473597d706e 115 } enet_rx_bd_control_status_t;
bogdanm 82:6473597d706e 116
bogdanm 82:6473597d706e 117 /*! @brief Defines the control extended regions of the receive buffer descriptor.*/
bogdanm 82:6473597d706e 118 typedef enum _enet_rx_bd_control_extend
bogdanm 82:6473597d706e 119 {
bogdanm 82:6473597d706e 120 kEnetRxBdUnicast = 0x0001, /*!< Unicast frame*/
bogdanm 82:6473597d706e 121 kEnetRxBdCollision = 0x0002, /*!< BD collision*/
bogdanm 82:6473597d706e 122 kEnetRxBdPhyErr = 0x0004, /*!< PHY error*/
bogdanm 82:6473597d706e 123 kEnetRxBdMacErr = 0x0080, /*!< Mac error*/
bogdanm 82:6473597d706e 124 kEnetRxBdIpv4 = 0x0100, /*!< Ipv4 frame*/
bogdanm 82:6473597d706e 125 kEnetRxBdIpv6 = 0x0200, /*!< Ipv6 frame*/
bogdanm 82:6473597d706e 126 kEnetRxBdVlan = 0x0400, /*!< VLAN*/
bogdanm 82:6473597d706e 127 kEnetRxBdProtocolChecksumErr = 0x1000, /*!< Protocol checksum error*/
bogdanm 82:6473597d706e 128 kEnetRxBdIpHeaderChecksumErr = 0x2000, /*!< IP header checksum error*/
bogdanm 82:6473597d706e 129 kEnetRxBdIntrrupt = 0x8000 /*!< BD interrupt*/
bogdanm 82:6473597d706e 130 } enet_rx_bd_control_extend_t;
bogdanm 82:6473597d706e 131
bogdanm 82:6473597d706e 132 /*! @brief Defines the control status region of the transmit buffer descriptor.*/
bogdanm 82:6473597d706e 133 typedef enum _enet_tx_bd_control_status
bogdanm 82:6473597d706e 134 {
bogdanm 82:6473597d706e 135 kEnetTxBdReady = 0x0080, /*!< Ready bit*/
bogdanm 82:6473597d706e 136 kEnetTxBdTxSoftOwner1 = 0x0040, /*!< Transmit software owner*/
bogdanm 82:6473597d706e 137 kEnetTxBdWrap = 0x0020, /*!< Wrap buffer descriptor*/
bogdanm 82:6473597d706e 138 kEnetTxBdTxSoftOwner2 = 0x0010, /*!< Transmit software owner*/
bogdanm 82:6473597d706e 139 kEnetTxBdLast = 0x0008, /*!< Last BD in the frame*/
bogdanm 82:6473597d706e 140 kEnetTxBdTransmitCrc = 0x0004 /*!< Receive for transmit CRC*/
bogdanm 82:6473597d706e 141 } enet_tx_bd_control_status_t;
bogdanm 82:6473597d706e 142
bogdanm 82:6473597d706e 143 /*! @brief Defines the control extended region of the transmit buffer descriptor.*/
bogdanm 82:6473597d706e 144 typedef enum _enet_tx_bd_control_extend
bogdanm 82:6473597d706e 145 {
bogdanm 82:6473597d706e 146 kEnetTxBdTxErr = 0x0080, /*!< Transmit error*/
bogdanm 82:6473597d706e 147 kEnetTxBdTxUnderFlowErr = 0x0020, /*!< Underflow error*/
bogdanm 82:6473597d706e 148 kEnetTxBdExcessCollisionErr = 0x0010, /*!< Excess collision error*/
bogdanm 82:6473597d706e 149 kEnetTxBdTxFrameErr = 0x0008, /*!< Frame error*/
bogdanm 82:6473597d706e 150 kEnetTxBdLatecollisionErr = 0x0004, /*!< Late collision error*/
bogdanm 82:6473597d706e 151 kEnetTxBdOverFlowErr = 0x0002, /*!< Overflow error*/
bogdanm 82:6473597d706e 152 kEnetTxTimestampErr = 0x0001 /*!< Timestamp error*/
bogdanm 82:6473597d706e 153 } enet_tx_bd_control_extend_t;
bogdanm 82:6473597d706e 154
bogdanm 82:6473597d706e 155 /*! @brief Defines the control extended2 region of the transmit buffer descriptor.*/
bogdanm 82:6473597d706e 156 typedef enum _enet_tx_bd_control_extend2
bogdanm 82:6473597d706e 157 {
bogdanm 82:6473597d706e 158 kEnetTxBdTxInterrupt = 0x0040, /*!< Transmit interrupt*/
bogdanm 82:6473597d706e 159 kEnetTxBdTimeStamp = 0x0020 /*!< Transmit timestamp flag */
bogdanm 82:6473597d706e 160 } enet_tx_bd_control_extend2_t;
bogdanm 82:6473597d706e 161 #else
bogdanm 82:6473597d706e 162 /*! @brief Defines the control and status region of the receive buffer descriptor.*/
bogdanm 82:6473597d706e 163 typedef enum _enet_rx_bd_control_status
bogdanm 82:6473597d706e 164 {
bogdanm 82:6473597d706e 165 kEnetRxBdEmpty = 0x8000, /*!< Empty bit*/
bogdanm 82:6473597d706e 166 kEnetRxBdRxSoftOwner1 = 0x4000, /*!< Receive software owner*/
bogdanm 82:6473597d706e 167 kEnetRxBdWrap = 0x2000, /*!< Update buffer descriptor*/
bogdanm 82:6473597d706e 168 kEnetRxBdRxSoftOwner2 = 0x1000, /*!< Receive software owner*/
bogdanm 82:6473597d706e 169 kEnetRxBdLast = 0x0800, /*!< Last BD in the frame*/
bogdanm 82:6473597d706e 170 kEnetRxBdMiss = 0x0100, /*!< Receive for promiscuous mode*/
bogdanm 82:6473597d706e 171 kEnetRxBdBroadCast = 0x0080, /*!< Broadcast */
bogdanm 82:6473597d706e 172 kEnetRxBdMultiCast = 0x0040, /*!< Multicast*/
bogdanm 82:6473597d706e 173 kEnetRxBdLengthViolation = 0x0020, /*!< Receive length violation*/
bogdanm 82:6473597d706e 174 kEnetRxBdNoOctet = 0x0010, /*!< Receive non-octet aligned frame*/
bogdanm 82:6473597d706e 175 kEnetRxBdCrc = 0x0004, /*!< Receive CRC error*/
bogdanm 82:6473597d706e 176 kEnetRxBdOverRun = 0x0002, /*!< Receive FIFO overrun*/
bogdanm 82:6473597d706e 177 kEnetRxBdTrunc = 0x0001 /*!< Frame is truncated */
bogdanm 82:6473597d706e 178 } enet_rx_bd_control_status_t;
bogdanm 82:6473597d706e 179
bogdanm 82:6473597d706e 180 /*! @brief Defines the control extended region of the receive buffer descriptor.*/
bogdanm 82:6473597d706e 181 typedef enum _enet_rx_bd_control_extend
bogdanm 82:6473597d706e 182 {
bogdanm 82:6473597d706e 183 kEnetRxBdIpv4 = 0x0001, /*!< Ipv4 frame*/
bogdanm 82:6473597d706e 184 kEnetRxBdIpv6 = 0x0002, /*!< Ipv6 frame*/
bogdanm 82:6473597d706e 185 kEnetRxBdVlan = 0x0004, /*!< VLAN*/
bogdanm 82:6473597d706e 186 kEnetRxBdProtocolChecksumErr = 0x0010, /*!< Protocol checksum error*/
bogdanm 82:6473597d706e 187 kEnetRxBdIpHeaderChecksumErr = 0x0020, /*!< IP header checksum error*/
bogdanm 82:6473597d706e 188 kEnetRxBdIntrrupt = 0x0080, /*!< BD interrupt*/
bogdanm 82:6473597d706e 189 kEnetRxBdUnicast = 0x0100, /*!< Unicast frame*/
bogdanm 82:6473597d706e 190 kEnetRxBdCollision = 0x0200, /*!< BD collision*/
bogdanm 82:6473597d706e 191 kEnetRxBdPhyErr = 0x0400, /*!< PHY error*/
bogdanm 82:6473597d706e 192 kEnetRxBdMacErr = 0x8000 /*!< Mac error */
bogdanm 82:6473597d706e 193 } enet_rx_bd_control_extend_t;
bogdanm 82:6473597d706e 194
bogdanm 82:6473597d706e 195 /*! @brief Defines the control status of the transmit buffer descriptor.*/
bogdanm 82:6473597d706e 196 typedef enum _enet_tx_bd_control_status
bogdanm 82:6473597d706e 197 {
bogdanm 82:6473597d706e 198 kEnetTxBdReady = 0x8000, /*!< Ready bit*/
bogdanm 82:6473597d706e 199 kEnetTxBdTxSoftOwner1 = 0x4000, /*!< Transmit software owner*/
bogdanm 82:6473597d706e 200 kEnetTxBdWrap = 0x2000, /*!< Wrap buffer descriptor*/
bogdanm 82:6473597d706e 201 kEnetTxBdTxSoftOwner2 = 0x1000, /*!< Transmit software owner*/
bogdanm 82:6473597d706e 202 kEnetTxBdLast = 0x0800, /*!< Last BD in the frame*/
bogdanm 82:6473597d706e 203 kEnetTxBdTransmitCrc = 0x0400 /*!< Receive for transmit CRC */
bogdanm 82:6473597d706e 204 } enet_tx_bd_control_status_t;
bogdanm 82:6473597d706e 205
bogdanm 82:6473597d706e 206 /*! @brief Defines the control extended of the transmit buffer descriptor.*/
bogdanm 82:6473597d706e 207 typedef enum _enet_tx_bd_control_extend
bogdanm 82:6473597d706e 208 {
bogdanm 82:6473597d706e 209 kEnetTxBdTxErr = 0x8000, /*!< Transmit error*/
bogdanm 82:6473597d706e 210 kEnetTxBdTxUnderFlowErr = 0x2000, /*!< Underflow error*/
bogdanm 82:6473597d706e 211 kEnetTxBdExcessCollisionErr = 0x1000, /*!< Excess collision error*/
bogdanm 82:6473597d706e 212 kEnetTxBdTxFrameErr = 0x0800, /*!< Frame error*/
bogdanm 82:6473597d706e 213 kEnetTxBdLatecollisionErr = 0x0400, /*!< Late collision error*/
bogdanm 82:6473597d706e 214 kEnetTxBdOverFlowErr = 0x0200, /*!< Overflow error*/
bogdanm 82:6473597d706e 215 kEnetTxTimestampErr = 0x0100 /*!< Timestamp error*/
bogdanm 82:6473597d706e 216 } enet_tx_bd_control_extend_t;
bogdanm 82:6473597d706e 217
bogdanm 82:6473597d706e 218 /*! @brief Defines the control extended2 of the transmit buffer descriptor.*/
bogdanm 82:6473597d706e 219 typedef enum _enet_tx_bd_control_extend2
bogdanm 82:6473597d706e 220 {
bogdanm 82:6473597d706e 221 kEnetTxBdTxInterrupt = 0x4000, /*!< Transmit interrupt*/
bogdanm 82:6473597d706e 222 kEnetTxBdTimeStamp = 0x2000 /*!< Transmit timestamp flag */
bogdanm 82:6473597d706e 223 } enet_tx_bd_control_extend2_t;
bogdanm 82:6473597d706e 224 #endif
bogdanm 82:6473597d706e 225
bogdanm 82:6473597d706e 226 /*! @brief Defines the macro to the different ENET constant value.*/
bogdanm 82:6473597d706e 227 typedef enum _enet_constant_parameter
bogdanm 82:6473597d706e 228 {
bogdanm 82:6473597d706e 229 kEnetMacAddrLen = 6, /*!< ENET mac address length*/
bogdanm 82:6473597d706e 230 kEnetHashValMask = 0x1f, /*!< ENET hash value mask*/
bogdanm 82:6473597d706e 231 kEnetRxBdCtlJudge1 = 0x0080,/*!< ENET receive buffer descriptor control judge value1*/
bogdanm 82:6473597d706e 232 kEnetRxBdCtlJudge2 = 0x8000 /*!< ENET receive buffer descriptor control judge value2*/
bogdanm 82:6473597d706e 233 } enet_constant_parameter_t;
bogdanm 82:6473597d706e 234
bogdanm 82:6473597d706e 235 /*! @brief Defines the RMII or MII mode for data interface between the MAC and the PHY.*/
bogdanm 82:6473597d706e 236 typedef enum _enet_config_rmii
bogdanm 82:6473597d706e 237 {
bogdanm 82:6473597d706e 238 kEnetCfgMii = 0, /*!< MII mode for data interface*/
bogdanm 82:6473597d706e 239 kEnetCfgRmii = 1 /*!< RMII mode for data interface*/
bogdanm 82:6473597d706e 240 } enet_config_rmii_t;
bogdanm 82:6473597d706e 241
bogdanm 82:6473597d706e 242 /*! @brief Defines the 10 Mbps or 100 Mbps speed mode for the data transfer.*/
bogdanm 82:6473597d706e 243 typedef enum _enet_config_speed
bogdanm 82:6473597d706e 244 {
bogdanm 82:6473597d706e 245 kEnetCfgSpeed100M = 0, /*!< Speed 100 M mode*/
bogdanm 82:6473597d706e 246 kEnetCfgSpeed10M = 1 /*!< Speed 10 M mode*/
bogdanm 82:6473597d706e 247 } enet_config_speed_t;
bogdanm 82:6473597d706e 248
bogdanm 82:6473597d706e 249 /*! @brief Defines the half or full duplex mode for the data transfer.*/
bogdanm 82:6473597d706e 250 typedef enum _enet_config_duplex
bogdanm 82:6473597d706e 251 {
bogdanm 82:6473597d706e 252 kEnetCfgHalfDuplex = 0, /*!< Half duplex mode*/
bogdanm 82:6473597d706e 253 kEnetCfgFullDuplex = 1 /*!< Full duplex mode*/
bogdanm 82:6473597d706e 254 } enet_config_duplex_t;
bogdanm 82:6473597d706e 255
bogdanm 82:6473597d706e 256 /*! @brief Defines the write/read operation for the MII.*/
bogdanm 82:6473597d706e 257 typedef enum _enet_mii_operation
bogdanm 82:6473597d706e 258 {
bogdanm 82:6473597d706e 259 kEnetWriteNoCompliant = 0, /*!< Write frame operation, but not MII compliant.*/
bogdanm 82:6473597d706e 260 kEnetWriteValidFrame = 1, /*!< Write frame operation for a valid MII management frame*/
bogdanm 82:6473597d706e 261 kEnetReadValidFrame = 2, /*!< Read frame operation for a valid MII management frame.*/
bogdanm 82:6473597d706e 262 kEnetReadNoCompliant = 3 /*!< Read frame operation, but not MII compliant*/
bogdanm 82:6473597d706e 263 }enet_mii_operation_t;
bogdanm 82:6473597d706e 264
bogdanm 82:6473597d706e 265 /*! @brief Define holdon time on MDIO output*/
bogdanm 82:6473597d706e 266 typedef enum _enet_mdio_holdon_clkcycle
bogdanm 82:6473597d706e 267 {
bogdanm 82:6473597d706e 268 kEnetMdioHoldOneClkCycle = 0, /*!< MDIO output hold on one clock cycle*/
bogdanm 82:6473597d706e 269 kEnetMdioHoldTwoClkCycle = 1, /*!< MDIO output hold on two clock cycles*/
bogdanm 82:6473597d706e 270 kEnetMdioHoldThreeClkCycle = 2, /*!< MDIO output hold on three clock cycles*/
bogdanm 82:6473597d706e 271 kEnetMdioHoldFourClkCycle = 3, /*!< MDIO output hold on four clock cycles*/
bogdanm 82:6473597d706e 272 kEnetMdioHoldFiveClkCycle = 4, /*!< MDIO output hold on five clock cycles*/
bogdanm 82:6473597d706e 273 kEnetMdioHoldSixClkCycle = 5, /*!< MDIO output hold on six clock cycles*/
bogdanm 82:6473597d706e 274 kEnetMdioHoldSevenClkCycle = 6, /*!< MDIO output hold seven two clock cycles*/
bogdanm 82:6473597d706e 275 kEnetMdioHoldEightClkCycle = 7, /*!< MDIO output hold on eight clock cycles*/
bogdanm 82:6473597d706e 276 }enet_mdio_holdon_clkcycle_t;
bogdanm 82:6473597d706e 277
bogdanm 82:6473597d706e 278 /*! @brief Defines the initialization, enables or disables the operation for a special address filter */
bogdanm 82:6473597d706e 279 typedef enum _enet_special_address_filter
bogdanm 82:6473597d706e 280 {
bogdanm 82:6473597d706e 281 kEnetSpecialAddressInit= 0, /*!< Initializes the special address filter.*/
bogdanm 82:6473597d706e 282 kEnetSpecialAddressEnable = 1, /*!< Enables the special address filter.*/
bogdanm 82:6473597d706e 283 kEnetSpecialAddressDisable = 2 /*!< Disables the special address filter.*/
bogdanm 82:6473597d706e 284 } enet_special_address_filter_t;
bogdanm 82:6473597d706e 285
bogdanm 82:6473597d706e 286 /*! @brief Defines the capture or compare mode for 1588 timer channels.*/
bogdanm 82:6473597d706e 287 typedef enum _enet_timer_channel_mode
bogdanm 82:6473597d706e 288 {
bogdanm 82:6473597d706e 289 kEnetChannelDisable = 0, /*!< Disable timer channel*/
bogdanm 82:6473597d706e 290 kEnetChannelRisingCapture = 1, /*!< Input capture on rising edge*/
bogdanm 82:6473597d706e 291 kEnetChannelFallingCapture = 2, /*!< Input capture on falling edge*/
bogdanm 82:6473597d706e 292 kEnetChannelBothCapture = 3, /*!< Input capture on both edges*/
bogdanm 82:6473597d706e 293 kEnetChannelSoftCompare = 4, /*!< Output compare software only*/
bogdanm 82:6473597d706e 294 kEnetChannelToggleCompare = 5, /*!< Toggle output on compare*/
bogdanm 82:6473597d706e 295 kEnetChannelClearCompare = 6, /*!< Clear output on compare*/
bogdanm 82:6473597d706e 296 kEnetChannelSetCompare = 7, /*!< Set output on compare*/
bogdanm 82:6473597d706e 297 kEnetChannelClearCompareSetOverflow = 10, /*!< Clear output on compare, set output on overflow*/
bogdanm 82:6473597d706e 298 kEnetChannelSetCompareClearOverflow = 11, /*!< Set output on compare, clear output on overflow*/
bogdanm 82:6473597d706e 299 kEnetChannelPulseLowonCompare = 14, /*!< Pulse output low on compare for one 1588 clock cycle*/
bogdanm 82:6473597d706e 300 kEnetChannelPulseHighonCompare = 15 /*!< Pulse output high on compare for one 1588 clock cycle*/
bogdanm 82:6473597d706e 301 } enet_timer_channel_mode_t;
bogdanm 82:6473597d706e 302
bogdanm 82:6473597d706e 303 /*! @brief Defines the RXFRAME/RXBYTE/TXFRAME/TXBYTE/MII/TSTIMER/TSAVAIL interrupt source for ENET.*/
bogdanm 82:6473597d706e 304 typedef enum _enet_interrupt_request
bogdanm 82:6473597d706e 305 {
bogdanm 82:6473597d706e 306 kEnetBabrInterrupt = 0x40000000, /*!< BABR interrupt source*/
bogdanm 82:6473597d706e 307 kEnetBabtInterrupt = 0x20000000, /*!< BABT interrupt source*/
bogdanm 82:6473597d706e 308 kEnetGraInterrupt = 0x10000000, /*!< GRA interrupt source*/
bogdanm 82:6473597d706e 309 kEnetTxFrameInterrupt = 0x8000000, /*!< TXFRAME interrupt source */
bogdanm 82:6473597d706e 310 kEnetTxByteInterrupt = 0x4000000, /*!< TXBYTE interrupt source*/
bogdanm 82:6473597d706e 311 kEnetRxFrameInterrupt = 0x2000000, /*!< RXFRAME interrupt source */
bogdanm 82:6473597d706e 312 kEnetRxByteInterrupt = 0x1000000, /*!< RXBYTE interrupt source */
bogdanm 82:6473597d706e 313 kEnetMiiInterrupt = 0x0800000, /*!< MII interrupt source*/
bogdanm 82:6473597d706e 314 kEnetEBERInterrupt = 0x0400000, /*!< EBERR interrupt source*/
bogdanm 82:6473597d706e 315 kEnetLcInterrupt = 0x0200000, /*!< LC interrupt source*/
bogdanm 82:6473597d706e 316 kEnetRlInterrupt = 0x0100000, /*!< RL interrupt source*/
bogdanm 82:6473597d706e 317 kEnetUnInterrupt = 0x0080000, /*!< UN interrupt source*/
bogdanm 82:6473597d706e 318 kEnetPlrInterrupt = 0x0040000, /*!< PLR interrupt source*/
bogdanm 82:6473597d706e 319 kEnetWakeupInterrupt = 0x0020000, /*!< WAKEUP interrupt source*/
bogdanm 82:6473597d706e 320 kEnetTsAvailInterrupt = 0x0010000, /*!< TS AVAIL interrupt source*/
bogdanm 82:6473597d706e 321 kEnetTsTimerInterrupt = 0x0008000, /*!< TS WRAP interrupt source*/
bogdanm 82:6473597d706e 322 kEnetAllInterrupt = 0x7FFFFFFF /*!< All interrupt*/
bogdanm 82:6473597d706e 323 } enet_interrupt_request_t;
bogdanm 82:6473597d706e 324
bogdanm 82:6473597d706e 325 /*! @brief Defines the six-byte Mac address type.*/
bogdanm 82:6473597d706e 326 typedef uint8_t enetMacAddr[kEnetMacAddrLen];
bogdanm 82:6473597d706e 327
bogdanm 82:6473597d706e 328 #if (!FSL_FEATURE_ENET_DMA_BIG_ENDIAN_ONLY) && SYSTEM_LITTLE_ENDIAN
bogdanm 82:6473597d706e 329 /*! @brief Defines the buffer descriptor structure for the little-Endian system and endianness configurable IP.*/
bogdanm 82:6473597d706e 330 typedef struct ENETBdStruct
bogdanm 82:6473597d706e 331 {
bogdanm 82:6473597d706e 332 uint16_t length; /*!< Buffer descriptor data length*/
bogdanm 82:6473597d706e 333 uint16_t control; /*!< Buffer descriptor control*/
bogdanm 82:6473597d706e 334 uint8_t *buffer; /*!< Data buffer pointer*/
bogdanm 82:6473597d706e 335 uint16_t controlExtend0; /*!< Extend buffer descriptor control0*/
bogdanm 82:6473597d706e 336 uint16_t controlExtend1; /*!< Extend buffer descriptor control1*/
bogdanm 82:6473597d706e 337 uint16_t payloadCheckSum; /*!< Internal payload checksum*/
bogdanm 82:6473597d706e 338 uint8_t headerLength; /*!< Header length*/
bogdanm 82:6473597d706e 339 uint8_t protocalTyte; /*!< Protocol type*/
bogdanm 82:6473597d706e 340 uint16_t reserved0;
bogdanm 82:6473597d706e 341 uint16_t controlExtend2; /*!< Extend buffer descriptor control2*/
bogdanm 82:6473597d706e 342 uint32_t timestamp; /*!< Timestamp */
bogdanm 82:6473597d706e 343 uint16_t reserved1;
bogdanm 82:6473597d706e 344 uint16_t reserved2;
bogdanm 82:6473597d706e 345 uint16_t reserved3;
bogdanm 82:6473597d706e 346 uint16_t reserved4;
bogdanm 82:6473597d706e 347 } enet_bd_struct_t;
bogdanm 85:024bf7f99721 348 #define TX_DESC_UPDATED_MASK (0x8000)
bogdanm 82:6473597d706e 349 #else
bogdanm 82:6473597d706e 350 /*! @brief Defines the buffer descriptors structure for the Big-Endian system.*/
bogdanm 82:6473597d706e 351 typedef struct ENETBdStruct
bogdanm 82:6473597d706e 352 {
bogdanm 82:6473597d706e 353 uint16_t control; /*!< Buffer descriptor control */
bogdanm 82:6473597d706e 354 uint16_t length; /*!< Buffer descriptor data length*/
bogdanm 82:6473597d706e 355 uint8_t *buffer; /*!< Data buffer pointer*/
bogdanm 82:6473597d706e 356 uint16_t controlExtend1; /*!< Extend buffer descriptor control1*/
bogdanm 82:6473597d706e 357 uint16_t controlExtend0; /*!< Extend buffer descriptor control0*/
bogdanm 82:6473597d706e 358 uint8_t headerLength; /*!< Header length*/
bogdanm 82:6473597d706e 359 uint8_t protocalTyte; /*!< Protocol type*/
bogdanm 82:6473597d706e 360 uint16_t payloadCheckSum; /*!< Internal payload checksum*/
bogdanm 82:6473597d706e 361 uint16_t controlExtend2; /*!< Extend buffer descriptor control2*/
bogdanm 82:6473597d706e 362 uint16_t reserved0;
bogdanm 82:6473597d706e 363 uint32_t timestamp; /*!< Timestamp pointer*/
bogdanm 82:6473597d706e 364 uint16_t reserved1;
bogdanm 82:6473597d706e 365 uint16_t reserved2;
bogdanm 82:6473597d706e 366 uint16_t reserved3;
bogdanm 82:6473597d706e 367 uint16_t reserved4;
bogdanm 82:6473597d706e 368 } enet_bd_struct_t;
bogdanm 85:024bf7f99721 369 #define TX_DESC_UPDATED_MASK (0x0080)
bogdanm 82:6473597d706e 370 #endif
bogdanm 82:6473597d706e 371
bogdanm 82:6473597d706e 372 /*! @brief Defines the configuration structure for the 1588 PTP timer.*/
bogdanm 82:6473597d706e 373 typedef struct ENETConfigPtpTimer
bogdanm 82:6473597d706e 374 {
bogdanm 82:6473597d706e 375 bool isSlaveEnabled; /*!< Master or slave PTP timer*/
bogdanm 82:6473597d706e 376 uint32_t clockIncease; /*!< Timer increase value each clock period*/
bogdanm 82:6473597d706e 377 uint32_t period; /*!< Timer period for generate interrupt event */
bogdanm 82:6473597d706e 378 } enet_config_ptp_timer_t;
bogdanm 82:6473597d706e 379
bogdanm 82:6473597d706e 380 /*! @brief Defines the transmit accelerator configuration.*/
bogdanm 82:6473597d706e 381 typedef struct ENETConfigTxAccelerator
bogdanm 82:6473597d706e 382 {
bogdanm 82:6473597d706e 383 bool isIpCheckEnabled; /*!< Insert IP header checksum */
bogdanm 82:6473597d706e 384 bool isProtocolCheckEnabled; /*!< Insert protocol checksum*/
bogdanm 82:6473597d706e 385 bool isShift16Enabled; /*!< Tx FIFO shift-16*/
bogdanm 82:6473597d706e 386 } enet_config_tx_accelerator_t;
bogdanm 82:6473597d706e 387
bogdanm 82:6473597d706e 388 /*! @brief Defines the receive accelerator configuration.*/
bogdanm 82:6473597d706e 389 typedef struct ENETConfigRxAccelerator
bogdanm 82:6473597d706e 390 {
bogdanm 82:6473597d706e 391 bool isIpcheckEnabled; /*!< Discard with wrong IP header checksum */
bogdanm 82:6473597d706e 392 bool isProtocolCheckEnabled; /*!< Discard with wrong protocol checksum*/
bogdanm 82:6473597d706e 393 bool isMacCheckEnabled; /*!< Discard with Mac layer errors*/
bogdanm 82:6473597d706e 394 bool isPadRemoveEnabled; /*!< Padding removal for short IP frames*/
bogdanm 82:6473597d706e 395 bool isShift16Enabled; /*!< Rx FIFO shift-16*/
bogdanm 82:6473597d706e 396 } enet_config_rx_accelerator_t;
bogdanm 82:6473597d706e 397
bogdanm 82:6473597d706e 398 /*! @brief Defines the transmit FIFO configuration.*/
bogdanm 82:6473597d706e 399 typedef struct ENETConfigTxFifo
bogdanm 82:6473597d706e 400 {
bogdanm 82:6473597d706e 401 bool isStoreForwardEnabled; /*!< Transmit FIFO store and forward */
bogdanm 82:6473597d706e 402 uint8_t txFifoWrite; /*!< Transmit FIFO write */
bogdanm 82:6473597d706e 403 uint8_t txEmpty; /*!< Transmit FIFO section empty threshold*/
bogdanm 82:6473597d706e 404 uint8_t txAlmostEmpty; /*!< Transmit FIFO section almost empty threshold*/
bogdanm 82:6473597d706e 405 uint8_t txAlmostFull; /*!< Transmit FIFO section almost full threshold*/
bogdanm 82:6473597d706e 406 } enet_config_tx_fifo_t;
bogdanm 82:6473597d706e 407
bogdanm 82:6473597d706e 408 /*! @brief Defines the receive FIFO configuration.*/
bogdanm 82:6473597d706e 409 typedef struct ENETConfigRxFifo
bogdanm 82:6473597d706e 410 {
bogdanm 82:6473597d706e 411 uint8_t rxFull; /*!< Receive FIFO section full threshold*/
bogdanm 82:6473597d706e 412 uint8_t rxAlmostFull; /*!< Receive FIFO section almost full threshold*/
bogdanm 82:6473597d706e 413 uint8_t rxEmpty; /*!< Receive FIFO section empty threshold*/
bogdanm 82:6473597d706e 414 uint8_t rxAlmostEmpty; /*!< Receive FIFO section almost empty threshold*/
bogdanm 82:6473597d706e 415 } enet_config_rx_fifo_t;
bogdanm 82:6473597d706e 416
bogdanm 82:6473597d706e 417 /*******************************************************************************
bogdanm 82:6473597d706e 418 * API
bogdanm 82:6473597d706e 419 ******************************************************************************/
bogdanm 82:6473597d706e 420
bogdanm 82:6473597d706e 421 #if defined(__cplusplus)
bogdanm 82:6473597d706e 422 extern "C" {
bogdanm 82:6473597d706e 423 #endif
bogdanm 82:6473597d706e 424
bogdanm 82:6473597d706e 425 /*!
bogdanm 82:6473597d706e 426 * @brief Resets the ENET module.
bogdanm 82:6473597d706e 427 *
bogdanm 82:6473597d706e 428 * @param instance The ENET instance number
bogdanm 82:6473597d706e 429 */
bogdanm 82:6473597d706e 430 static inline void enet_hal_reset_ethernet(uint32_t instance)
bogdanm 82:6473597d706e 431 {
bogdanm 82:6473597d706e 432 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 433
bogdanm 82:6473597d706e 434 HW_ENET_ECR_SET(instance, BM_ENET_ECR_RESET);
bogdanm 82:6473597d706e 435 }
bogdanm 82:6473597d706e 436
bogdanm 82:6473597d706e 437 /*!
bogdanm 82:6473597d706e 438 * @brief Gets the ENET status to check whether the reset has completed.
bogdanm 82:6473597d706e 439 *
bogdanm 82:6473597d706e 440 * @param instance The ENET instance number
bogdanm 82:6473597d706e 441 * @return Current status of the reset operation
bogdanm 82:6473597d706e 442 * - true if ENET reset completed.
bogdanm 82:6473597d706e 443 * - false if ENET reset has not completed.
bogdanm 82:6473597d706e 444 */
bogdanm 82:6473597d706e 445 static inline bool enet_hal_is_reset_completed(uint32_t instance)
bogdanm 82:6473597d706e 446 {
bogdanm 82:6473597d706e 447 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 448
bogdanm 82:6473597d706e 449 return (BR_ENET_ECR_RESET(instance) == 0);
bogdanm 82:6473597d706e 450 }
bogdanm 82:6473597d706e 451
bogdanm 82:6473597d706e 452 /*!
bogdanm 82:6473597d706e 453 * @brief Enable or disable stop mode.
bogdanm 82:6473597d706e 454 *
bogdanm 82:6473597d706e 455 * Enable stop mode will control device behavior in doze mode.
bogdanm 82:6473597d706e 456 * In doze mode, if this filed is set then all clock of the enet assemably are
bogdanm 82:6473597d706e 457 * disabled, except the RMII/MII clock.
bogdanm 82:6473597d706e 458 *
bogdanm 82:6473597d706e 459 * @param instance The ENET instance number.
bogdanm 82:6473597d706e 460 * @param isEnabled The switch to enable/disable stop mode.
bogdanm 82:6473597d706e 461 * - true to enabale the stop mode.
bogdanm 82:6473597d706e 462 * - false to disable the stop mode.
bogdanm 82:6473597d706e 463 */
bogdanm 82:6473597d706e 464 static inline void enet_hal_enable_stop(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 465 {
bogdanm 82:6473597d706e 466 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 467 BW_ENET_ECR_STOPEN(instance, isEnabled);
bogdanm 82:6473597d706e 468 }
bogdanm 82:6473597d706e 469 /*!
bogdanm 82:6473597d706e 470 * @brief Enable or disable sleep mode.
bogdanm 82:6473597d706e 471 *
bogdanm 82:6473597d706e 472 * Enable sleep mode will disable normal operating mode. When enable the sleep
bogdanm 82:6473597d706e 473 * mode, the magic packet detection is also enabled so that a remote agent can
bogdanm 82:6473597d706e 474 * wakeup the node.
bogdanm 82:6473597d706e 475 *
bogdanm 82:6473597d706e 476 * @param instance The ENET instance number.
bogdanm 82:6473597d706e 477 * @param isEnabled The switch to enable/disable the sleep mode.
bogdanm 82:6473597d706e 478 * - true to enabale the sleep mode.
bogdanm 82:6473597d706e 479 * - false to disable the sleep mode.
bogdanm 82:6473597d706e 480 */
bogdanm 82:6473597d706e 481 static inline void enet_hal_enable_sleep(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 482 {
bogdanm 82:6473597d706e 483 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 484 BW_ENET_ECR_SLEEP(instance, isEnabled);
bogdanm 82:6473597d706e 485 BW_ENET_ECR_MAGICEN(instance, isEnabled);
bogdanm 82:6473597d706e 486 }
bogdanm 82:6473597d706e 487
bogdanm 82:6473597d706e 488 /*!
bogdanm 82:6473597d706e 489 * @brief Sets the Mac address.
bogdanm 82:6473597d706e 490 *
bogdanm 82:6473597d706e 491 * This interface sets the six-byte Mac address of the ENET interface.
bogdanm 82:6473597d706e 492 *
bogdanm 82:6473597d706e 493 * @param instance The ENET instance number
bogdanm 82:6473597d706e 494 * @param hwAddr The mac address pointer store for six bytes Mac address
bogdanm 82:6473597d706e 495 */
bogdanm 82:6473597d706e 496 void enet_hal_set_mac_address(uint32_t instance, enetMacAddr hwAddr);
bogdanm 82:6473597d706e 497
bogdanm 82:6473597d706e 498 /*!
bogdanm 82:6473597d706e 499 * @brief Sets the hardware addressing filtering to a multicast group address.
bogdanm 82:6473597d706e 500 *
bogdanm 82:6473597d706e 501 * This interface is used to add the ENET device to a multicast group address.
bogdanm 82:6473597d706e 502 * After joining the group, Mac receives all frames with the group Mac address.
bogdanm 82:6473597d706e 503 *
bogdanm 82:6473597d706e 504 * @param instance The ENET instance number
bogdanm 82:6473597d706e 505 * @param crcValue The CRC value of the special address
bogdanm 82:6473597d706e 506 * @param mode The operation for init/enable/disable the specified hardware address
bogdanm 82:6473597d706e 507 */
bogdanm 82:6473597d706e 508 void enet_hal_set_group_hashtable(uint32_t instance, uint32_t crcValue, enet_special_address_filter_t mode);
bogdanm 82:6473597d706e 509
bogdanm 82:6473597d706e 510 /*!
bogdanm 82:6473597d706e 511 * @brief Sets the hardware addressing filtering to an individual address.
bogdanm 82:6473597d706e 512 *
bogdanm 82:6473597d706e 513 * This interface is used to add an individual address to the hardware address
bogdanm 82:6473597d706e 514 * filter. Mac receives all frames with the individual address as a destination address.
bogdanm 82:6473597d706e 515 *
bogdanm 82:6473597d706e 516 * @param instance The ENET instance number
bogdanm 82:6473597d706e 517 * @param crcValue The CRC value of the special address
bogdanm 82:6473597d706e 518 * @param mode The operation for init/enable/disable the specified hardware address
bogdanm 82:6473597d706e 519 */
bogdanm 82:6473597d706e 520 void enet_hal_set_individual_hashtable(uint32_t instance, uint32_t crcValue, enet_special_address_filter_t mode);
bogdanm 82:6473597d706e 521
bogdanm 82:6473597d706e 522 /*!
bogdanm 82:6473597d706e 523 * @brief Enable/disable payload length check.
bogdanm 82:6473597d706e 524 *
bogdanm 82:6473597d706e 525 * If the length/type is less than 0x600,When enable payload length check
bogdanm 82:6473597d706e 526 * the core checks the fame's payload length. If the length/type is greater
bogdanm 82:6473597d706e 527 * than or equal to 0x600. The MAC interprets the field as a type and no
bogdanm 82:6473597d706e 528 * payload length check is performanced.
bogdanm 82:6473597d706e 529 *
bogdanm 82:6473597d706e 530 * @param instance The ENET instance number
bogdanm 82:6473597d706e 531 * @param isEnabled The switch to enable/disable payload length check
bogdanm 82:6473597d706e 532 * - True to enabale payload length check.
bogdanm 82:6473597d706e 533 * - False to disable payload legnth check.
bogdanm 82:6473597d706e 534 */
bogdanm 82:6473597d706e 535 static inline void enet_hal_enable_payloadcheck(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 536 {
bogdanm 82:6473597d706e 537 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 538 BW_ENET_RCR_NLC(instance, isEnabled);
bogdanm 82:6473597d706e 539 }
bogdanm 82:6473597d706e 540
bogdanm 82:6473597d706e 541 /*!
bogdanm 82:6473597d706e 542 * @brief Enable/disable append CRC to transmitted frames.
bogdanm 82:6473597d706e 543 *
bogdanm 82:6473597d706e 544 * If transmit CRC forward is enabled, the transmit buffer descriptor controls
bogdanm 82:6473597d706e 545 * whether the frame has a CRC from the application. If transmit CRC forward is disabled,
bogdanm 82:6473597d706e 546 * transmitter does not append any CRC to transmitted frames.
bogdanm 82:6473597d706e 547 *
bogdanm 82:6473597d706e 548 * @param instance The ENET instance number
bogdanm 82:6473597d706e 549 * @param isEnabled The switch to enable/disable transmit the receive CRC
bogdanm 82:6473597d706e 550 * - True the transmitter control CRC through transmit buffer descriptor.
bogdanm 82:6473597d706e 551 * - False the transmitter does not append any CRC to transmitted frames.
bogdanm 82:6473597d706e 552 */
bogdanm 82:6473597d706e 553 static inline void enet_hal_enable_txcrcforward(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 554 {
bogdanm 82:6473597d706e 555 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 556 BW_ENET_TCR_CRCFWD(instance, !isEnabled);
bogdanm 82:6473597d706e 557 }
bogdanm 82:6473597d706e 558
bogdanm 82:6473597d706e 559 /*!
bogdanm 82:6473597d706e 560 * @brief Enable/disable forward the CRC filed of the received frame.
bogdanm 82:6473597d706e 561 *
bogdanm 82:6473597d706e 562 * This is used to deceide whether the CRC field of received frame is transmitted
bogdanm 82:6473597d706e 563 * or stripped. Enable this feature to strip CRC field from the frame.
bogdanm 82:6473597d706e 564 * If padding remove is enabled, this feature will be ignored and
bogdanm 82:6473597d706e 565 * the CRC field is checked and always terminated and removed.
bogdanm 82:6473597d706e 566 *
bogdanm 82:6473597d706e 567 * @param instance The ENET instance number
bogdanm 82:6473597d706e 568 * @param isEnabled The switch to enable/disable transmit the receive CRC
bogdanm 82:6473597d706e 569 * - True to transmit the received CRC.
bogdanm 82:6473597d706e 570 * - False to strip the received CRC.
bogdanm 82:6473597d706e 571 */
bogdanm 82:6473597d706e 572 static inline void enet_hal_enable_rxcrcforward(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 573 {
bogdanm 82:6473597d706e 574 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 575 BW_ENET_RCR_CRCFWD(instance, !isEnabled);
bogdanm 82:6473597d706e 576 }
bogdanm 82:6473597d706e 577 /*!
bogdanm 82:6473597d706e 578 * @brief Enable/disable forward PAUSE frames.
bogdanm 82:6473597d706e 579 *
bogdanm 82:6473597d706e 580 * This is used to deceide whether PAUSE frames is forwarded or discarded.
bogdanm 82:6473597d706e 581 *
bogdanm 82:6473597d706e 582 * @param instance The ENET instance number
bogdanm 82:6473597d706e 583 * @param isEnabled The switch to enable/disable forward PAUSE frames
bogdanm 82:6473597d706e 584 * - True to forward PAUSE frames.
bogdanm 82:6473597d706e 585 * - False to terminate and discard PAUSE frames.
bogdanm 82:6473597d706e 586 */
bogdanm 82:6473597d706e 587 static inline void enet_hal_enable_pauseforward(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 588 {
bogdanm 82:6473597d706e 589 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 590 BW_ENET_RCR_PAUFWD(instance, isEnabled);
bogdanm 82:6473597d706e 591 }
bogdanm 82:6473597d706e 592
bogdanm 82:6473597d706e 593 /*!
bogdanm 82:6473597d706e 594 * @brief Enable/disable frame padding remove on receive.
bogdanm 82:6473597d706e 595 *
bogdanm 82:6473597d706e 596 * Enable frame padding remove will remove the padding from the received frames.
bogdanm 82:6473597d706e 597 *
bogdanm 82:6473597d706e 598 * @param instance The ENET instance number
bogdanm 82:6473597d706e 599 * @param isEnabled The switch to enable/disable remove padding
bogdanm 82:6473597d706e 600 * - True to remove padding from frames.
bogdanm 82:6473597d706e 601 * - False to disable padding remove.
bogdanm 82:6473597d706e 602 */
bogdanm 82:6473597d706e 603 static inline void enet_hal_enable_padremove(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 604 {
bogdanm 82:6473597d706e 605 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 606 BW_ENET_RCR_PADEN(instance, isEnabled);
bogdanm 82:6473597d706e 607 }
bogdanm 82:6473597d706e 608
bogdanm 82:6473597d706e 609 /*!
bogdanm 82:6473597d706e 610 * @brief Enable/disable flow control.
bogdanm 82:6473597d706e 611 *
bogdanm 82:6473597d706e 612 * If flow control is enabled, the receive detects PAUSE frames.
bogdanm 82:6473597d706e 613 * Upon PAUSE frame detection, the transmitter stops transmitting
bogdanm 82:6473597d706e 614 * data frames for a given duration.
bogdanm 82:6473597d706e 615 *
bogdanm 82:6473597d706e 616 * @param instance The ENET instance number
bogdanm 82:6473597d706e 617 * @param isEnabled The switch to enable/disable flow control
bogdanm 82:6473597d706e 618 * - True to enable the flow control.
bogdanm 82:6473597d706e 619 * - False to disable the flow control.
bogdanm 82:6473597d706e 620 */
bogdanm 82:6473597d706e 621 static inline void enet_hal_enable_flowcontrol(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 622 {
bogdanm 82:6473597d706e 623 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 624 BW_ENET_RCR_CFEN(instance, isEnabled);
bogdanm 82:6473597d706e 625 BW_ENET_RCR_FCE(instance, isEnabled);
bogdanm 82:6473597d706e 626 }
bogdanm 82:6473597d706e 627
bogdanm 82:6473597d706e 628 /*!
bogdanm 82:6473597d706e 629 * @brief Enable/disable broadcast frame reject.
bogdanm 82:6473597d706e 630 *
bogdanm 82:6473597d706e 631 * If broadcast frame reject is enabled, frames with destination address
bogdanm 82:6473597d706e 632 * equal to 0xffff_ffff_ffff are rejected unless the promiscuous mode is open.
bogdanm 82:6473597d706e 633 *
bogdanm 82:6473597d706e 634 * @param instance The ENET instance number
bogdanm 82:6473597d706e 635 * @param isEnabled The switch to enable/disable reject broadcast frames
bogdanm 82:6473597d706e 636 * - True to reject broadcast frames.
bogdanm 82:6473597d706e 637 * - False to accept broadcast frames.
bogdanm 82:6473597d706e 638 */
bogdanm 82:6473597d706e 639 static inline void enet_hal_enable_broadcastreject(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 640 {
bogdanm 82:6473597d706e 641 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 642 BW_ENET_RCR_BC_REJ(instance, isEnabled);
bogdanm 82:6473597d706e 643 }
bogdanm 82:6473597d706e 644
bogdanm 82:6473597d706e 645 /*!
bogdanm 82:6473597d706e 646 * @brief Sets PAUSE duration for a PAUSE frame.
bogdanm 82:6473597d706e 647 *
bogdanm 82:6473597d706e 648 * This function is used to set the pause duraion used in transmission
bogdanm 82:6473597d706e 649 * of a PAUSE frame. When another node detects a PAUSE frame, that node
bogdanm 82:6473597d706e 650 * pauses transmission for the pause duration.
bogdanm 82:6473597d706e 651 *
bogdanm 82:6473597d706e 652 * @param instance The ENET instance number
bogdanm 82:6473597d706e 653 * @param pauseDuration The PAUSE duration for the transmitted PAUSE frame
bogdanm 82:6473597d706e 654 * the maximum pause duration is 0xFFFF.
bogdanm 82:6473597d706e 655 */
bogdanm 82:6473597d706e 656 static inline void enet_hal_set_pauseduration(uint32_t instance, uint32_t pauseDuration)
bogdanm 82:6473597d706e 657 {
bogdanm 82:6473597d706e 658 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 659 assert(pauseDuration <= BM_ENET_OPD_PAUSE_DUR);
bogdanm 82:6473597d706e 660 BW_ENET_OPD_PAUSE_DUR(instance, pauseDuration);
bogdanm 82:6473597d706e 661 }
bogdanm 82:6473597d706e 662
bogdanm 82:6473597d706e 663 /*!
bogdanm 82:6473597d706e 664 * @brief Gets receive PAUSE frame status.
bogdanm 82:6473597d706e 665 *
bogdanm 82:6473597d706e 666 * This function is used to get the received PAUSE frame status.
bogdanm 82:6473597d706e 667 *
bogdanm 82:6473597d706e 668 * @param instance The ENET instance number
bogdanm 82:6473597d706e 669 * @return The status of the received flow control frames
bogdanm 82:6473597d706e 670 * true if the flow control pause frame is received.
bogdanm 82:6473597d706e 671 * false if there is no flow control frame received or the pause duration is complete.
bogdanm 82:6473597d706e 672 */
bogdanm 82:6473597d706e 673 static inline bool enet_hal_get_rxpause_status(uint32_t instance)
bogdanm 82:6473597d706e 674 {
bogdanm 82:6473597d706e 675 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 676 return BR_ENET_TCR_RFC_PAUSE(instance);
bogdanm 82:6473597d706e 677 }
bogdanm 82:6473597d706e 678 /*!
bogdanm 82:6473597d706e 679 * @brief Enables transmit frame control PAUSE.
bogdanm 82:6473597d706e 680 *
bogdanm 82:6473597d706e 681 * This function enables pauses frame transmission.
bogdanm 82:6473597d706e 682 * When this is set, with transmission of data frames stopped, the MAC
bogdanm 82:6473597d706e 683 * transmits a MAC control PAUSE frame. NEXT, the MAC clear the
bogdanm 82:6473597d706e 684 * and resumes transmitting data frames.
bogdanm 82:6473597d706e 685 *
bogdanm 82:6473597d706e 686 * @param instance The ENET instance number
bogdanm 82:6473597d706e 687 * @param isEnabled The switch to enable/disable PAUSE control frame transmission
bogdanm 82:6473597d706e 688 * - True enable PAUSE control frame transmission.
bogdanm 82:6473597d706e 689 * - Flase disable PAUSE control frame transmission.
bogdanm 82:6473597d706e 690 */
bogdanm 82:6473597d706e 691 static inline void enet_hal_enable_txpause(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 692 {
bogdanm 82:6473597d706e 693 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 694 BW_ENET_TCR_TFC_PAUSE(instance, isEnabled);
bogdanm 82:6473597d706e 695 }
bogdanm 82:6473597d706e 696
bogdanm 82:6473597d706e 697 /*!
bogdanm 82:6473597d706e 698 * @brief Sets transmit PAUSE frame.
bogdanm 82:6473597d706e 699 *
bogdanm 82:6473597d706e 700 * This function Sets ENET transmit controller with pause duration.
bogdanm 82:6473597d706e 701 * And set the transmit control to do PAUSE frame transmission
bogdanm 82:6473597d706e 702 * This should be called when a PAUSE frame is dynamically wanted.
bogdanm 82:6473597d706e 703 *
bogdanm 82:6473597d706e 704 * @param instance The ENET instance number
bogdanm 82:6473597d706e 705 */
bogdanm 82:6473597d706e 706 void enet_hal_set_txpause(uint32_t instance, uint32_t pauseDuration);
bogdanm 82:6473597d706e 707
bogdanm 82:6473597d706e 708 /*!
bogdanm 82:6473597d706e 709 * @brief Sets the transmit inter-packet gap.
bogdanm 82:6473597d706e 710 *
bogdanm 82:6473597d706e 711 * This function indicates the IPG, in bytes, between transmitted frames.
bogdanm 82:6473597d706e 712 * Valid values range from 8 to 27. If value is less than 8, the IPG is 8.
bogdanm 82:6473597d706e 713 * If value is greater than 27, the IPG is 27.
bogdanm 82:6473597d706e 714 *
bogdanm 82:6473597d706e 715 * @param instance The ENET instance number
bogdanm 82:6473597d706e 716 * @param ipgValue The IPG for transmitted frames
bogdanm 82:6473597d706e 717 * The default value is 12, the maximum value set to ipg is 0x1F.
bogdanm 82:6473597d706e 718 *
bogdanm 82:6473597d706e 719 */
bogdanm 82:6473597d706e 720 static inline void enet_hal_set_txipg(uint32_t instance, uint32_t ipgValue)
bogdanm 82:6473597d706e 721 {
bogdanm 82:6473597d706e 722 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 723 assert(ipgValue <= BM_ENET_TIPG_IPG);
bogdanm 82:6473597d706e 724 BW_ENET_TIPG_IPG(instance, ipgValue);
bogdanm 82:6473597d706e 725 }
bogdanm 82:6473597d706e 726
bogdanm 82:6473597d706e 727 /*!
bogdanm 82:6473597d706e 728 * @brief Sets the receive frame truncation length.
bogdanm 82:6473597d706e 729 *
bogdanm 82:6473597d706e 730 * This function indicates the value a receive frame is truncated,
bogdanm 82:6473597d706e 731 * if it is greater than this value. The frame truncation length must be greater
bogdanm 82:6473597d706e 732 * than or equal to the receive maximum frame length.
bogdanm 82:6473597d706e 733 *
bogdanm 82:6473597d706e 734 * @param instance The ENET instance number
bogdanm 82:6473597d706e 735 * @param length The truncation length. The maximum value is 0x3FFF
bogdanm 82:6473597d706e 736 * The default truncation length is 2047(0x7FF).
bogdanm 82:6473597d706e 737 *
bogdanm 82:6473597d706e 738 */
bogdanm 82:6473597d706e 739 static inline void enet_hal_set_truncationlen(uint32_t instance, uint32_t length)
bogdanm 82:6473597d706e 740 {
bogdanm 82:6473597d706e 741 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 742 assert(length <= BM_ENET_FTRL_TRUNC_FL);
bogdanm 82:6473597d706e 743 BW_ENET_FTRL_TRUNC_FL(instance, length);
bogdanm 82:6473597d706e 744 }
bogdanm 82:6473597d706e 745
bogdanm 82:6473597d706e 746 /*!
bogdanm 82:6473597d706e 747 * @brief Sets the maximum receive buffer size and the maximum frame size.
bogdanm 82:6473597d706e 748 *
bogdanm 82:6473597d706e 749 * @param instance The ENET instance number
bogdanm 82:6473597d706e 750 * @param maxBufferSize The maximum receive buffer size, which should not be smaller than 256
bogdanm 82:6473597d706e 751 * It should be evenly divisible by 16 and the maximum receive size should not be larger than 0x3ff0.
bogdanm 82:6473597d706e 752 * @param maxFrameSize The maximum receive frame size, the reset value is 1518 or 1522 if the VLAN tags are
bogdanm 82:6473597d706e 753 * supported. The length is measured starting at DA and including the CRC.
bogdanm 82:6473597d706e 754 */
bogdanm 82:6473597d706e 755 static inline void enet_hal_set_rx_max_size(uint32_t instance, uint32_t maxBufferSize, uint32_t maxFrameSize)
bogdanm 82:6473597d706e 756 {
bogdanm 82:6473597d706e 757 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 758 /* max buffer size must larger than 256 to minimize bus usage*/
bogdanm 82:6473597d706e 759 assert(maxBufferSize >= 256);
bogdanm 82:6473597d706e 760 assert(maxFrameSize <= (BM_ENET_RCR_MAX_FL >> BP_ENET_RCR_MAX_FL));
bogdanm 82:6473597d706e 761
bogdanm 82:6473597d706e 762 BW_ENET_RCR_MAX_FL(instance, maxFrameSize);
bogdanm 82:6473597d706e 763 HW_ENET_MRBR_WR(instance, (maxBufferSize & BM_ENET_MRBR_R_BUF_SIZE));
bogdanm 82:6473597d706e 764 }
bogdanm 82:6473597d706e 765
bogdanm 82:6473597d706e 766 /*!
bogdanm 82:6473597d706e 767 * @brief Configures the ENET transmit FIFO.
bogdanm 82:6473597d706e 768 *
bogdanm 82:6473597d706e 769 * @param instance The ENET instance number
bogdanm 82:6473597d706e 770 * @param thresholdCfg The FIFO threshold configuration
bogdanm 82:6473597d706e 771 */
bogdanm 82:6473597d706e 772 void enet_hal_config_tx_fifo(uint32_t instance, enet_config_tx_fifo_t *thresholdCfg);
bogdanm 82:6473597d706e 773
bogdanm 82:6473597d706e 774 /*!
bogdanm 82:6473597d706e 775 * @brief Configures the ENET receive FIFO.
bogdanm 82:6473597d706e 776 *
bogdanm 82:6473597d706e 777 * @param instance The ENET instance number
bogdanm 82:6473597d706e 778 * @param thresholdCfg The FIFO threshold configuration
bogdanm 82:6473597d706e 779 */
bogdanm 82:6473597d706e 780 void enet_hal_config_rx_fifo(uint32_t instance, enet_config_rx_fifo_t *thresholdCfg);
bogdanm 82:6473597d706e 781
bogdanm 82:6473597d706e 782 /*!
bogdanm 82:6473597d706e 783 * @brief Sets the start address for ENET receive buffer descriptors.
bogdanm 82:6473597d706e 784 *
bogdanm 82:6473597d706e 785 * This interface provides the beginning of the receive
bogdanm 82:6473597d706e 786 * and receive buffer descriptor queue in the external memory. The
bogdanm 82:6473597d706e 787 * txbdAddr is recommended to be 128-bit aligned, must be evenly divisible by 16.
bogdanm 82:6473597d706e 788 *
bogdanm 82:6473597d706e 789 * @param instance The ENET instance number
bogdanm 82:6473597d706e 790 * @param rxBdAddr The start address of receive buffer descriptors
bogdanm 82:6473597d706e 791 */
bogdanm 82:6473597d706e 792 static inline void enet_hal_set_rxbd_address(uint32_t instance, uint32_t rxBdAddr)
bogdanm 82:6473597d706e 793 {
bogdanm 82:6473597d706e 794 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 795
bogdanm 82:6473597d706e 796 HW_ENET_RDSR_WR(instance,rxBdAddr); /* Initialize receive buffer descriptor start address*/
bogdanm 82:6473597d706e 797 }
bogdanm 82:6473597d706e 798 /*!
bogdanm 82:6473597d706e 799 * @brief Sets the start address for ENET transmit buffer descriptors.
bogdanm 82:6473597d706e 800 *
bogdanm 82:6473597d706e 801 * This interface provides the beginning of the receive
bogdanm 82:6473597d706e 802 * and transmit buffer descriptor queue in the external memory. The
bogdanm 82:6473597d706e 803 * txbdAddr is recommended to be 128-bit aligned, must be evenly divisible by 16.
bogdanm 82:6473597d706e 804 *
bogdanm 82:6473597d706e 805 * @param instance The ENET instance number
bogdanm 82:6473597d706e 806 * @param txBdAddr The start address of transmit buffer descriptors
bogdanm 82:6473597d706e 807 */
bogdanm 82:6473597d706e 808 static inline void enet_hal_set_txbd_address(uint32_t instance, uint32_t txBdAddr)
bogdanm 82:6473597d706e 809 {
bogdanm 82:6473597d706e 810 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 811
bogdanm 82:6473597d706e 812 HW_ENET_TDSR_WR(instance,txBdAddr); /* Initialize transmit buffer descriptor start address*/
bogdanm 82:6473597d706e 813 }
bogdanm 82:6473597d706e 814
bogdanm 82:6473597d706e 815 /*!
bogdanm 82:6473597d706e 816 * @brief Initializes the receive buffer descriptors.
bogdanm 82:6473597d706e 817 *
bogdanm 82:6473597d706e 818 * To make sure the uDMA will do the right data transfer after you activate
bogdanm 82:6473597d706e 819 * with wrap flag and all the buffer descriptors should be initialized with an empty bit.
bogdanm 82:6473597d706e 820 *
bogdanm 82:6473597d706e 821 * @param rxBds The current receive buffer descriptor
bogdanm 82:6473597d706e 822 * @param buffer The data buffer on buffer descriptor
bogdanm 82:6473597d706e 823 * @param isLastBd The flag to indicate the last receive buffer descriptor
bogdanm 82:6473597d706e 824 */
bogdanm 82:6473597d706e 825 void enet_hal_init_rxbds(void *rxBds, uint8_t *buffer, bool isLastBd);
bogdanm 82:6473597d706e 826
bogdanm 82:6473597d706e 827 /*!
bogdanm 82:6473597d706e 828 * @brief Initializes the transmit buffer descriptors.
bogdanm 82:6473597d706e 829 *
bogdanm 82:6473597d706e 830 * To make sure the uDMA will do the right data transfer after you active
bogdanm 82:6473597d706e 831 * with wrap flag.
bogdanm 82:6473597d706e 832 *
bogdanm 82:6473597d706e 833 * @param txBds The current transmit buffer descriptor.
bogdanm 82:6473597d706e 834 * @param isLastBd The last transmit buffer descriptor flag.
bogdanm 82:6473597d706e 835 */
bogdanm 82:6473597d706e 836 void enet_hal_init_txbds(void *txBds, bool isLastBd);
bogdanm 82:6473597d706e 837
bogdanm 82:6473597d706e 838 /*!
bogdanm 82:6473597d706e 839 * @brief Updates the receive buffer descriptors.
bogdanm 82:6473597d706e 840 *
bogdanm 82:6473597d706e 841 * This interface mainly clears the status region and updates the received
bogdanm 82:6473597d706e 842 * buffer descriptor to ensure that the BD is correctly used.
bogdanm 82:6473597d706e 843 *
bogdanm 82:6473597d706e 844 * @param rxBds The current receive buffer descriptor
bogdanm 82:6473597d706e 845 * @param data The data buffer address
bogdanm 82:6473597d706e 846 * @param isbufferUpdate The data buffer update flag. When you want to update
bogdanm 82:6473597d706e 847 * the data buffer of the buffer descriptor ensure that this flag
bogdanm 82:6473597d706e 848 * is set.
bogdanm 82:6473597d706e 849 */
bogdanm 82:6473597d706e 850 void enet_hal_update_rxbds(void *rxBds, uint8_t *data, bool isbufferUpdate);
bogdanm 82:6473597d706e 851
bogdanm 82:6473597d706e 852 /*!
bogdanm 82:6473597d706e 853 * @brief Initializes the transmit buffer descriptors.
bogdanm 82:6473597d706e 854 *
bogdanm 82:6473597d706e 855 * Ensures that the uDMA transfer data correctly after the user activates
bogdanm 82:6473597d706e 856 * with the wrap flag.
bogdanm 82:6473597d706e 857 *
bogdanm 82:6473597d706e 858 * @param txBds The current transmit buffer descriptor
bogdanm 82:6473597d706e 859 * @param isLastBd The last transmit buffer descriptor flag
bogdanm 82:6473597d706e 860 */
bogdanm 82:6473597d706e 861 void enet_hal_init_txbds(void *txBds, bool isLastBd);
bogdanm 82:6473597d706e 862
bogdanm 82:6473597d706e 863 /*!
bogdanm 82:6473597d706e 864 * @brief Updates the transmit buffer descriptors.
bogdanm 82:6473597d706e 865 *
bogdanm 82:6473597d706e 866 * This interface mainly clears the status region and updates the transmit
bogdanm 82:6473597d706e 867 * buffer descriptor to ensure tat this BD is correctly used again.
bogdanm 82:6473597d706e 868 * You should set the isTxtsCfged when the transmit timestamp feature is required.
bogdanm 82:6473597d706e 869 *
bogdanm 82:6473597d706e 870 * @param txBds The current transmit buffer descriptor
bogdanm 82:6473597d706e 871 * @param buffer The data buffer on buffer descriptor
bogdanm 82:6473597d706e 872 * @param length The data length on buffer descriptor
bogdanm 82:6473597d706e 873 * @param isTxtsCfged The timestamp configure flag. The timestamp is
bogdanm 82:6473597d706e 874 * added to the transmit buffer descriptor when this flag is set.
bogdanm 82:6473597d706e 875 */
bogdanm 82:6473597d706e 876 void enet_hal_update_txbds(void *txBds,uint8_t *buffer, uint16_t length, bool isTxtsCfged);
bogdanm 82:6473597d706e 877
bogdanm 82:6473597d706e 878 /*!
bogdanm 82:6473597d706e 879 * @brief Clears the context in the transmit buffer descriptors.
bogdanm 82:6473597d706e 880 *
bogdanm 82:6473597d706e 881 * Clears the data, length, control, and status region of the transmit buffer descriptor.
bogdanm 82:6473597d706e 882 *
bogdanm 82:6473597d706e 883 * @param curBd The current buffer descriptor
bogdanm 82:6473597d706e 884 */
bogdanm 82:6473597d706e 885 static inline void enet_hal_clear_txbds(void *curBd)
bogdanm 82:6473597d706e 886 {
bogdanm 82:6473597d706e 887 assert(curBd);
bogdanm 82:6473597d706e 888
bogdanm 82:6473597d706e 889 volatile enet_bd_struct_t *bdPtr = (enet_bd_struct_t *)curBd;
bogdanm 82:6473597d706e 890 bdPtr->length = 0; /* Set data length*/
bogdanm 82:6473597d706e 891 bdPtr->buffer = (uint8_t *)(NULL);/* Set data buffer*/
bogdanm 82:6473597d706e 892 bdPtr->control &= (kEnetTxBdWrap);/* Set control */
bogdanm 82:6473597d706e 893 }
bogdanm 82:6473597d706e 894
bogdanm 82:6473597d706e 895 /*!
bogdanm 82:6473597d706e 896 * @brief Gets the control and the status region of the receive buffer descriptors.
bogdanm 82:6473597d706e 897 *
bogdanm 82:6473597d706e 898 * This interface can get the whole control and status region of the
bogdanm 82:6473597d706e 899 * receive buffer descriptor. The enet_rx_bd_control_status_t enum type
bogdanm 82:6473597d706e 900 * definition should be used if you want to get each status bit of
bogdanm 82:6473597d706e 901 * the control and status region.
bogdanm 82:6473597d706e 902 *
bogdanm 82:6473597d706e 903 * @param curBd The current receive buffer descriptor
bogdanm 82:6473597d706e 904 * @return The control and status data on buffer descriptors
bogdanm 82:6473597d706e 905 */
bogdanm 82:6473597d706e 906 uint16_t enet_hal_get_rxbd_control(void *curBd);
bogdanm 82:6473597d706e 907
bogdanm 82:6473597d706e 908 /*!
bogdanm 82:6473597d706e 909 * @brief Gets the control and the status region of the transmit buffer descriptors.
bogdanm 82:6473597d706e 910 *
bogdanm 82:6473597d706e 911 * This interface can get the whole control and status region of the
bogdanm 82:6473597d706e 912 * transmit buffer descriptor. The enet_tx_bd_control_status_t enum type
bogdanm 82:6473597d706e 913 * definition should be used if you want to get each status bit of
bogdanm 82:6473597d706e 914 * the control and status region.
bogdanm 82:6473597d706e 915 *
bogdanm 82:6473597d706e 916 * @param curBd The current transmit buffer descriptor
bogdanm 82:6473597d706e 917 * @return The extended control region of transmit buffer descriptor
bogdanm 82:6473597d706e 918 */
bogdanm 82:6473597d706e 919 uint16_t enet_hal_get_txbd_control(void *curBd);
bogdanm 82:6473597d706e 920
bogdanm 82:6473597d706e 921 /*!
bogdanm 82:6473597d706e 922 * @brief Gets the extended control region of the receive buffer descriptors.
bogdanm 82:6473597d706e 923 *
bogdanm 82:6473597d706e 924 * This interface can get the whole control and status region of the
bogdanm 82:6473597d706e 925 * receive buffer descriptor. The enet_rx_bd_control_extend_t enum type
bogdanm 82:6473597d706e 926 * definition should be used if you want to get each status bit of
bogdanm 82:6473597d706e 927 * the control and status region.
bogdanm 82:6473597d706e 928 *
bogdanm 82:6473597d706e 929 * @param curBd The current receive buffer descriptor
bogdanm 82:6473597d706e 930 * @param controlRegion The different control region
bogdanm 82:6473597d706e 931 * @return The extended control region data of receive buffer descriptor
bogdanm 82:6473597d706e 932 * - true when the control region is set
bogdanm 82:6473597d706e 933 * - false when the control region is not set
bogdanm 82:6473597d706e 934 */
bogdanm 82:6473597d706e 935 bool enet_hal_get_rxbd_control_extend(void *curBd,enet_rx_bd_control_extend_t controlRegion);
bogdanm 82:6473597d706e 936 /*!
bogdanm 82:6473597d706e 937 * @brief Gets the extended control region of the transmit buffer descriptors.
bogdanm 82:6473597d706e 938 *
bogdanm 82:6473597d706e 939 * This interface can get the whole control and status region of the
bogdanm 82:6473597d706e 940 * transmit buffer descriptor. The enet_tx_bd_control_extend_t enum type
bogdanm 82:6473597d706e 941 * definition should be used if you want to get each status bit of
bogdanm 82:6473597d706e 942 * the control and status region.
bogdanm 82:6473597d706e 943 *
bogdanm 82:6473597d706e 944 * @param curBd The current transmit buffer descriptor
bogdanm 82:6473597d706e 945 * @return The extended control data
bogdanm 82:6473597d706e 946 */
bogdanm 82:6473597d706e 947 uint16_t enet_hal_get_txbd_control_extend(void *curBd);
bogdanm 82:6473597d706e 948
bogdanm 82:6473597d706e 949 /*!
bogdanm 82:6473597d706e 950 * @brief Gets the data length of the buffer descriptors.
bogdanm 82:6473597d706e 951 *
bogdanm 82:6473597d706e 952 * @param curBd The current buffer descriptor
bogdanm 82:6473597d706e 953 * @return The data length of the buffer descriptor
bogdanm 82:6473597d706e 954 */
bogdanm 82:6473597d706e 955 uint16_t enet_hal_get_bd_length(void *curBd);
bogdanm 82:6473597d706e 956
bogdanm 82:6473597d706e 957 /*!
bogdanm 82:6473597d706e 958 * @brief Gets the buffer address of the buffer descriptors.
bogdanm 82:6473597d706e 959 *
bogdanm 82:6473597d706e 960 * @param curBd The current buffer descriptor
bogdanm 82:6473597d706e 961 * @return The buffer address of the buffer descriptor
bogdanm 82:6473597d706e 962 */
bogdanm 82:6473597d706e 963 uint8_t* enet_hal_get_bd_buffer(void *curBd);
bogdanm 82:6473597d706e 964
bogdanm 82:6473597d706e 965 /*!
bogdanm 82:6473597d706e 966 * @brief Gets the timestamp of the buffer descriptors.
bogdanm 82:6473597d706e 967 *
bogdanm 82:6473597d706e 968 * @param curBd The current buffer descriptor
bogdanm 82:6473597d706e 969 * @return The time stamp of the frame in the buffer descriptor.
bogdanm 82:6473597d706e 970 * Notice that the frame timestamp is only set in the last
bogdanm 82:6473597d706e 971 * buffer descriptor of the frame.
bogdanm 82:6473597d706e 972 */
bogdanm 82:6473597d706e 973 uint32_t enet_hal_get_bd_timestamp(void *curBd);
bogdanm 82:6473597d706e 974
bogdanm 82:6473597d706e 975 /*!
bogdanm 82:6473597d706e 976 * @brief Activates the receive buffer descriptor.
bogdanm 82:6473597d706e 977 *
bogdanm 82:6473597d706e 978 * The buffer descriptor activation
bogdanm 82:6473597d706e 979 * should be done after the ENET module is enabled. Otherwise, the activation fails.
bogdanm 82:6473597d706e 980 *
bogdanm 82:6473597d706e 981 * @param instance The ENET instance number
bogdanm 82:6473597d706e 982 */
bogdanm 82:6473597d706e 983 static inline void enet_hal_active_rxbd(uint32_t instance)
bogdanm 82:6473597d706e 984 {
bogdanm 82:6473597d706e 985 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 986
bogdanm 82:6473597d706e 987 HW_ENET_RDAR_SET(instance, BM_ENET_RDAR_RDAR);
bogdanm 82:6473597d706e 988 }
bogdanm 82:6473597d706e 989
bogdanm 82:6473597d706e 990 /*!
bogdanm 82:6473597d706e 991 * @brief Activates the transmit buffer descriptor.
bogdanm 82:6473597d706e 992 *
bogdanm 82:6473597d706e 993 * The buffer descriptor activation should be done after the ENET module is
bogdanm 82:6473597d706e 994 * enabled. Otherwise, the activation fails.
bogdanm 82:6473597d706e 995 *
bogdanm 82:6473597d706e 996 * @param instance The ENET instance number
bogdanm 82:6473597d706e 997 */
bogdanm 82:6473597d706e 998 static inline void enet_hal_active_txbd(uint32_t instance)
bogdanm 82:6473597d706e 999 {
bogdanm 82:6473597d706e 1000 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1001
bogdanm 82:6473597d706e 1002 HW_ENET_TDAR_SET(instance, BM_ENET_TDAR_TDAR);
bogdanm 82:6473597d706e 1003 }
bogdanm 82:6473597d706e 1004
bogdanm 82:6473597d706e 1005 /*!
bogdanm 82:6473597d706e 1006 * @brief Configures the (R)MII of ENET.
bogdanm 82:6473597d706e 1007 *
bogdanm 82:6473597d706e 1008 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1009 * @param mode The RMII or MII mode
bogdanm 82:6473597d706e 1010 * @param speed The speed of RMII
bogdanm 82:6473597d706e 1011 * @param duplex The full or half duplex mode
bogdanm 82:6473597d706e 1012 * @param isRxOnTxDisabled The Receive on transmit disable flag
bogdanm 82:6473597d706e 1013 * @param isLoopEnabled The loop enable flag
bogdanm 82:6473597d706e 1014 */
bogdanm 82:6473597d706e 1015 void enet_hal_config_rmii(uint32_t instance, enet_config_rmii_t mode, enet_config_speed_t speed, enet_config_duplex_t duplex, bool isRxOnTxDisabled, bool isLoopEnabled);
bogdanm 82:6473597d706e 1016
bogdanm 82:6473597d706e 1017 /*!
bogdanm 82:6473597d706e 1018 * @brief Configures the MII of ENET.
bogdanm 82:6473597d706e 1019 *
bogdanm 82:6473597d706e 1020 * Sets the MII interface between Mac and PHY. The miiSpeed is
bogdanm 82:6473597d706e 1021 * a value that controls the frequency of the MDC, relative to the internal module clock(InterClockSrc).
bogdanm 82:6473597d706e 1022 * A value of zero in this parameter turns the MDC off and leaves it in the low voltage state.
bogdanm 82:6473597d706e 1023 * Any non-zero value results in the MDC frequency MDC = InterClockSrc/((miiSpeed + 1)*2).
bogdanm 82:6473597d706e 1024 * So miiSpeed = InterClockSrc/(2*MDC) - 1.
bogdanm 82:6473597d706e 1025 * The Maximum MDC clock is 2.5MHZ(maximum). We should round up and plus one to simlplify:
bogdanm 82:6473597d706e 1026 * miiSpeed = InterClockSrc/(2*2.5MHZ).
bogdanm 82:6473597d706e 1027 *
bogdanm 82:6473597d706e 1028 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1029 * @param miiSpeed The MII speed and it is ranged from 0~0x3F
bogdanm 82:6473597d706e 1030 * @param time The holdon clock cycles for MDIO output
bogdanm 82:6473597d706e 1031 * @param isPreambleDisabled The preamble disabled flag
bogdanm 82:6473597d706e 1032 */
bogdanm 82:6473597d706e 1033 static inline void enet_hal_config_mii(uint32_t instance, uint32_t miiSpeed,
bogdanm 82:6473597d706e 1034 enet_mdio_holdon_clkcycle_t clkCycle, bool isPreambleDisabled)
bogdanm 82:6473597d706e 1035 {
bogdanm 82:6473597d706e 1036 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1037
bogdanm 82:6473597d706e 1038 BW_ENET_MSCR_MII_SPEED(instance, miiSpeed); /* MII speed set*/
bogdanm 82:6473597d706e 1039 BW_ENET_MSCR_DIS_PRE(instance, isPreambleDisabled); /* Preamble is disabled*/
bogdanm 82:6473597d706e 1040 BW_ENET_MSCR_HOLDTIME(instance, clkCycle); /* hold on clock cycles for MDIO output*/
bogdanm 82:6473597d706e 1041
bogdanm 82:6473597d706e 1042 }
bogdanm 82:6473597d706e 1043
bogdanm 82:6473597d706e 1044 /*!
bogdanm 82:6473597d706e 1045 * @brief Gets the MII configuration status.
bogdanm 82:6473597d706e 1046 *
bogdanm 82:6473597d706e 1047 * This interface is usually called to check the MII interface before
bogdanm 82:6473597d706e 1048 * the Mac writes or reads the PHY registers.
bogdanm 82:6473597d706e 1049 *
bogdanm 82:6473597d706e 1050 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1051 * @return The MII configuration status
bogdanm 82:6473597d706e 1052 * - true if the MII has been configured.
bogdanm 82:6473597d706e 1053 * - false if the MII has not been configured.
bogdanm 82:6473597d706e 1054 */
bogdanm 82:6473597d706e 1055 static inline bool enet_hal_is_mii_enabled(uint32_t instance)
bogdanm 82:6473597d706e 1056 {
bogdanm 82:6473597d706e 1057 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1058
bogdanm 82:6473597d706e 1059 return (HW_ENET_MSCR_RD(instance) & 0x7E)!= 0;
bogdanm 82:6473597d706e 1060 }
bogdanm 82:6473597d706e 1061
bogdanm 82:6473597d706e 1062 /*!
bogdanm 82:6473597d706e 1063 * @brief Reads data from PHY.
bogdanm 82:6473597d706e 1064 *
bogdanm 82:6473597d706e 1065 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1066 * @return The data read from PHY
bogdanm 82:6473597d706e 1067 */
bogdanm 82:6473597d706e 1068 static inline uint32_t enet_hal_get_mii_data(uint32_t instance)
bogdanm 82:6473597d706e 1069 {
bogdanm 82:6473597d706e 1070 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1071
bogdanm 82:6473597d706e 1072 return (uint32_t)BR_ENET_MMFR_DATA(instance);
bogdanm 82:6473597d706e 1073 }
bogdanm 82:6473597d706e 1074
bogdanm 82:6473597d706e 1075 /*!
bogdanm 82:6473597d706e 1076 * @brief Sets the MII command.
bogdanm 82:6473597d706e 1077 *
bogdanm 82:6473597d706e 1078 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1079 * @param phyAddr The PHY address
bogdanm 82:6473597d706e 1080 * @param phyReg The PHY register
bogdanm 82:6473597d706e 1081 * @param operation The read or write operation
bogdanm 82:6473597d706e 1082 * @param data The data written to PHY
bogdanm 82:6473597d706e 1083 */
bogdanm 82:6473597d706e 1084 void enet_hal_set_mii_command(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, enet_mii_operation_t operation, uint32_t data);
bogdanm 82:6473597d706e 1085
bogdanm 82:6473597d706e 1086 /*!
bogdanm 82:6473597d706e 1087 * @brief Enables/Disables the ENET module.
bogdanm 82:6473597d706e 1088 *
bogdanm 82:6473597d706e 1089 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1090 * @param isEnhanced The enhanced 1588 feature switch
bogdanm 82:6473597d706e 1091 * @param isEnabled The ENET module enable switch
bogdanm 82:6473597d706e 1092 */
bogdanm 82:6473597d706e 1093 void enet_hal_config_ethernet(uint32_t instance, bool isEnhanced, bool isEnabled);
bogdanm 82:6473597d706e 1094
bogdanm 82:6473597d706e 1095 /*!
bogdanm 82:6473597d706e 1096 * @brief Enables/Disables the ENET interrupt.
bogdanm 82:6473597d706e 1097 *
bogdanm 82:6473597d706e 1098 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1099 * @param source The interrupt sources. enet_interrupt_request_t enum types
bogdanm 82:6473597d706e 1100 * is recommended as the interrupt source.
bogdanm 82:6473597d706e 1101 * @param isEnabled The interrupt enable switch
bogdanm 82:6473597d706e 1102 */
bogdanm 82:6473597d706e 1103 void enet_hal_config_interrupt(uint32_t instance, uint32_t source, bool isEnabled);
bogdanm 82:6473597d706e 1104
bogdanm 82:6473597d706e 1105 /*!
bogdanm 82:6473597d706e 1106 * @brief Clears ENET interrupt events.
bogdanm 82:6473597d706e 1107 *
bogdanm 82:6473597d706e 1108 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1109 * @param source The interrupt source to be cleared. enet_interrupt_request_t
bogdanm 82:6473597d706e 1110 * enum types is recommended as the interrupt source.
bogdanm 82:6473597d706e 1111 */
bogdanm 82:6473597d706e 1112 static inline void enet_hal_clear_interrupt(uint32_t instance, uint32_t source)
bogdanm 82:6473597d706e 1113 {
bogdanm 82:6473597d706e 1114 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1115
bogdanm 82:6473597d706e 1116 HW_ENET_EIR_WR(instance,source);
bogdanm 82:6473597d706e 1117 }
bogdanm 82:6473597d706e 1118
bogdanm 82:6473597d706e 1119 /*!
bogdanm 82:6473597d706e 1120 * @brief Gets the ENET interrupt status.
bogdanm 82:6473597d706e 1121 *
bogdanm 82:6473597d706e 1122 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1123 * @param source The interrupt sources. enet_interrupt_request_t
bogdanm 82:6473597d706e 1124 * enum types is recommended as the interrupt source.
bogdanm 82:6473597d706e 1125 * @return The event status of the interrupt source
bogdanm 82:6473597d706e 1126 * - true if the interrupt event happened.
bogdanm 82:6473597d706e 1127 * - false if the interrupt event has not happened.
bogdanm 82:6473597d706e 1128 */
bogdanm 82:6473597d706e 1129 static inline bool enet_hal_get_interrupt_status(uint32_t instance, uint32_t source)
bogdanm 82:6473597d706e 1130 {
bogdanm 82:6473597d706e 1131 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1132
bogdanm 82:6473597d706e 1133 return ((HW_ENET_EIR_RD(instance) & source) != 0);
bogdanm 82:6473597d706e 1134 }
bogdanm 82:6473597d706e 1135
bogdanm 82:6473597d706e 1136 /*
bogdanm 82:6473597d706e 1137 * @brief Enables/disables the ENET promiscuous mode.
bogdanm 82:6473597d706e 1138 *
bogdanm 82:6473597d706e 1139 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1140 * @param isEnabled The enable switch
bogdanm 82:6473597d706e 1141 */
bogdanm 82:6473597d706e 1142 static inline void enet_hal_config_promiscuous(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 1143 {
bogdanm 82:6473597d706e 1144 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1145
bogdanm 82:6473597d706e 1146 BW_ENET_RCR_PROM(instance,isEnabled);
bogdanm 82:6473597d706e 1147 }
bogdanm 82:6473597d706e 1148
bogdanm 82:6473597d706e 1149 /*!
bogdanm 82:6473597d706e 1150 * @brief Enables/disables the clear MIB counter.
bogdanm 82:6473597d706e 1151 *
bogdanm 82:6473597d706e 1152 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1153 * @param isEnabled The enable switch
bogdanm 82:6473597d706e 1154 */
bogdanm 82:6473597d706e 1155 static inline void enet_hal_clear_mib(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 1156 {
bogdanm 82:6473597d706e 1157 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1158
bogdanm 82:6473597d706e 1159 BW_ENET_MIBC_MIB_CLEAR(instance, isEnabled);
bogdanm 82:6473597d706e 1160
bogdanm 82:6473597d706e 1161 }
bogdanm 82:6473597d706e 1162
bogdanm 82:6473597d706e 1163 /*!
bogdanm 82:6473597d706e 1164 * @brief Sets the enable/disable of the MIB block.
bogdanm 82:6473597d706e 1165 *
bogdanm 82:6473597d706e 1166 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1167 * @param isEnabled The enable flag
bogdanm 82:6473597d706e 1168 * - True to enabale MIB block.
bogdanm 82:6473597d706e 1169 * - False to disable MIB block.
bogdanm 82:6473597d706e 1170 */
bogdanm 82:6473597d706e 1171 static inline void enet_hal_enable_mib(uint32_t instance, bool isEnabled)
bogdanm 82:6473597d706e 1172 {
bogdanm 82:6473597d706e 1173 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1174
bogdanm 82:6473597d706e 1175 BW_ENET_MIBC_MIB_DIS(instance,!isEnabled);
bogdanm 82:6473597d706e 1176
bogdanm 82:6473597d706e 1177 }
bogdanm 82:6473597d706e 1178
bogdanm 82:6473597d706e 1179 /*!
bogdanm 82:6473597d706e 1180 * @brief Gets the MIB idle status.
bogdanm 82:6473597d706e 1181 *
bogdanm 82:6473597d706e 1182 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1183 * @return true if in MIB idle and MIB is not updating else false.
bogdanm 82:6473597d706e 1184 */
bogdanm 82:6473597d706e 1185 static inline bool enet_hal_get_mib_status(uint32_t instance)
bogdanm 82:6473597d706e 1186 {
bogdanm 82:6473597d706e 1187 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1188
bogdanm 82:6473597d706e 1189 return BR_ENET_MIBC_MIB_IDLE(instance);
bogdanm 82:6473597d706e 1190 }
bogdanm 82:6473597d706e 1191
bogdanm 82:6473597d706e 1192 /*!
bogdanm 82:6473597d706e 1193 * @brief Sets the transmit accelerator.
bogdanm 82:6473597d706e 1194 *
bogdanm 82:6473597d706e 1195 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1196 * @param txCfgPtr The transmit accelerator configuration
bogdanm 82:6473597d706e 1197 */
bogdanm 82:6473597d706e 1198 void enet_hal_config_tx_accelerator(uint32_t instance, enet_config_tx_accelerator_t *txCfgPtr);
bogdanm 82:6473597d706e 1199
bogdanm 82:6473597d706e 1200 /*!
bogdanm 82:6473597d706e 1201 * @brief Sets the receive accelerator.
bogdanm 82:6473597d706e 1202 *
bogdanm 82:6473597d706e 1203 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1204 * @param rxCfgPtr The receive accelerator configuration
bogdanm 82:6473597d706e 1205 */
bogdanm 82:6473597d706e 1206 void enet_hal_config_rx_accelerator(uint32_t instance, enet_config_rx_accelerator_t *rxCfgPtr);
bogdanm 82:6473597d706e 1207
bogdanm 82:6473597d706e 1208 /*!
bogdanm 82:6473597d706e 1209 * @brief Initializes the 1588 timer.
bogdanm 82:6473597d706e 1210 *
bogdanm 82:6473597d706e 1211 * This interface initializes the 1588 context structure.
bogdanm 82:6473597d706e 1212 * Initialize 1588 parameters according to the user configuration structure.
bogdanm 82:6473597d706e 1213 *
bogdanm 82:6473597d706e 1214 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1215 * @param ptpCfg The 1588 timer configuration
bogdanm 82:6473597d706e 1216 */
bogdanm 82:6473597d706e 1217 void enet_hal_init_ptp_timer(uint32_t instance, enet_config_ptp_timer_t *ptpCfgPtr);
bogdanm 82:6473597d706e 1218
bogdanm 82:6473597d706e 1219 /*!
bogdanm 82:6473597d706e 1220 * @brief Enables or disables the 1588 timer.
bogdanm 82:6473597d706e 1221 *
bogdanm 82:6473597d706e 1222 * Enable the PTP timer will starts the timer. Disable the timer will stop timer
bogdanm 82:6473597d706e 1223 * at the current value.
bogdanm 82:6473597d706e 1224 *
bogdanm 82:6473597d706e 1225 * @param instance The ENET instance number.
bogdanm 82:6473597d706e 1226 * @param isEnabled The 1588 timer Enable switch
bogdanm 82:6473597d706e 1227 * - True enbaled the 1588 PTP timer.
bogdanm 82:6473597d706e 1228 * - False disable or stop the 1588 PTP timer.
bogdanm 82:6473597d706e 1229 */
bogdanm 82:6473597d706e 1230 static inline void enet_hal_enable_ptp_timer(uint32_t instance, uint32_t isEnabled)
bogdanm 82:6473597d706e 1231 {
bogdanm 82:6473597d706e 1232 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1233
bogdanm 82:6473597d706e 1234 BW_ENET_ATCR_EN(instance,isEnabled);
bogdanm 82:6473597d706e 1235 }
bogdanm 82:6473597d706e 1236
bogdanm 82:6473597d706e 1237 /*!
bogdanm 82:6473597d706e 1238 * @brief Restarts the 1588 timer.
bogdanm 82:6473597d706e 1239 *
bogdanm 82:6473597d706e 1240 * Restarting the PTP timer clears all PTP-timer counters to zero.
bogdanm 82:6473597d706e 1241 *
bogdanm 82:6473597d706e 1242 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1243 */
bogdanm 82:6473597d706e 1244 static inline void enet_hal_restart_ptp_timer(uint32_t instance)
bogdanm 82:6473597d706e 1245 {
bogdanm 82:6473597d706e 1246 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1247
bogdanm 82:6473597d706e 1248 BW_ENET_ATCR_RESTART(instance,1);
bogdanm 82:6473597d706e 1249 }
bogdanm 82:6473597d706e 1250
bogdanm 82:6473597d706e 1251 /*!
bogdanm 82:6473597d706e 1252 * @brief Adjusts the 1588 timer.
bogdanm 82:6473597d706e 1253 *
bogdanm 82:6473597d706e 1254 * Adjust the 1588 timer according to the increase and correction period of the configured correction.
bogdanm 82:6473597d706e 1255 *
bogdanm 82:6473597d706e 1256 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1257 * @param inceaseCorrection The increase correction for 1588 timer
bogdanm 82:6473597d706e 1258 * @param periodCorrection The period correction for 1588 timer
bogdanm 82:6473597d706e 1259 */
bogdanm 82:6473597d706e 1260 static inline void enet_hal_adjust_ptp_timer(uint32_t instance, uint32_t increaseCorrection, uint32_t periodCorrection)
bogdanm 82:6473597d706e 1261 {
bogdanm 82:6473597d706e 1262 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1263
bogdanm 82:6473597d706e 1264 HW_ENET_ATINC_SET(instance,((increaseCorrection << ENET_ATINC_INC_CORR_SHIFT) & ENET_ATINC_INC_CORR_MASK)); /* set correction for ptp timer increase*/
bogdanm 82:6473597d706e 1265 /* set correction for ptp timer period*/
bogdanm 82:6473597d706e 1266 HW_ENET_ATCOR_SET(instance, (BM_ENET_ATCOR_COR & periodCorrection));
bogdanm 82:6473597d706e 1267 }
bogdanm 82:6473597d706e 1268
bogdanm 82:6473597d706e 1269 /*!
bogdanm 82:6473597d706e 1270 * @brief Initializes the 1588 timer channel.
bogdanm 82:6473597d706e 1271 *
bogdanm 82:6473597d706e 1272 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1273 * @Param channel The 1588 timer channel number
bogdanm 82:6473597d706e 1274 * @param mode Compare or capture mode for the 1588 timer channel
bogdanm 82:6473597d706e 1275 */
bogdanm 82:6473597d706e 1276 static inline void enet_hal_init_timer_channel(uint32_t instance, uint32_t channel, enet_timer_channel_mode_t mode)
bogdanm 82:6473597d706e 1277 {
bogdanm 82:6473597d706e 1278 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1279 assert(channel < HW_ENET_TCSRn_COUNT);
bogdanm 82:6473597d706e 1280 HW_ENET_TCSRn_SET(instance, channel,
bogdanm 82:6473597d706e 1281 (BM_ENET_TCSRn_TMODE &(mode << BP_ENET_TCSRn_TMODE)));
bogdanm 82:6473597d706e 1282 HW_ENET_TCSRn_SET(instance, channel, BM_ENET_TCSRn_TIE);
bogdanm 82:6473597d706e 1283 }
bogdanm 82:6473597d706e 1284
bogdanm 82:6473597d706e 1285 /*!
bogdanm 82:6473597d706e 1286 * @brief Sets the compare value for the 1588 timer channel.
bogdanm 82:6473597d706e 1287 *
bogdanm 82:6473597d706e 1288 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1289 * @Param channel The 1588 timer channel number
bogdanm 82:6473597d706e 1290 * @param compareValue Compare value for 1588 timer channel
bogdanm 82:6473597d706e 1291 */
bogdanm 82:6473597d706e 1292 static inline void enet_hal_set_timer_channel_compare(uint32_t instance, uint32_t channel, uint32_t compareValue)
bogdanm 82:6473597d706e 1293 {
bogdanm 82:6473597d706e 1294 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1295 assert(channel < HW_ENET_TCSRn_COUNT);
bogdanm 82:6473597d706e 1296 HW_ENET_TCCRn_WR(instance,channel, compareValue);
bogdanm 82:6473597d706e 1297 }
bogdanm 82:6473597d706e 1298
bogdanm 82:6473597d706e 1299 /*!
bogdanm 82:6473597d706e 1300 * @brief Gets the 1588 timer channel status.
bogdanm 82:6473597d706e 1301 *
bogdanm 82:6473597d706e 1302 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1303 * @param channel The 1588 timer channel number
bogdanm 82:6473597d706e 1304 * @return Compare or capture operation status
bogdanm 82:6473597d706e 1305 * - True if the compare or capture has occurred.
bogdanm 82:6473597d706e 1306 * - False if the compare or capture has not occurred.
bogdanm 82:6473597d706e 1307 */
bogdanm 82:6473597d706e 1308 static inline bool enet_hal_get_timer_channel_status(uint32_t instance, uint32_t channel)
bogdanm 82:6473597d706e 1309 {
bogdanm 82:6473597d706e 1310 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1311 assert(channel < HW_ENET_TCSRn_COUNT);
bogdanm 82:6473597d706e 1312
bogdanm 82:6473597d706e 1313 return BR_ENET_TCSRn_TF(instance,channel);
bogdanm 82:6473597d706e 1314 }
bogdanm 82:6473597d706e 1315
bogdanm 82:6473597d706e 1316 /*!
bogdanm 82:6473597d706e 1317 * @brief Clears the 1588 timer channel flag.
bogdanm 82:6473597d706e 1318 *
bogdanm 82:6473597d706e 1319 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1320 * @param channel The 1588 timer channel number
bogdanm 82:6473597d706e 1321 */
bogdanm 82:6473597d706e 1322 static inline void enet_hal_clear_timer_channel_flag(uint32_t instance, uint32_t channel)
bogdanm 82:6473597d706e 1323 {
bogdanm 82:6473597d706e 1324 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1325 assert(channel < HW_ENET_TCSRn_COUNT);
bogdanm 82:6473597d706e 1326 HW_ENET_TCSRn_SET(instance, channel, BM_ENET_TCSRn_TF);/* clear interrupt flag*/
bogdanm 82:6473597d706e 1327 HW_ENET_TGSR_WR(instance,(1U << channel)); /* clear channel flag*/
bogdanm 82:6473597d706e 1328 }
bogdanm 82:6473597d706e 1329
bogdanm 82:6473597d706e 1330 /*!
bogdanm 82:6473597d706e 1331 * @brief Sets the capture command to the 1588 timer.
bogdanm 82:6473597d706e 1332 *
bogdanm 82:6473597d706e 1333 * This is used before reading the current time register.
bogdanm 82:6473597d706e 1334 * After set timer capture, please wait for about 1us before read
bogdanm 82:6473597d706e 1335 * the captured timer.
bogdanm 82:6473597d706e 1336 *
bogdanm 82:6473597d706e 1337 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1338 */
bogdanm 82:6473597d706e 1339 static inline void enet_hal_set_timer_capture(uint32_t instance)
bogdanm 82:6473597d706e 1340 {
bogdanm 82:6473597d706e 1341 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1342
bogdanm 82:6473597d706e 1343 HW_ENET_ATCR_SET(instance, BM_ENET_ATCR_CAPTURE);
bogdanm 82:6473597d706e 1344 }
bogdanm 82:6473597d706e 1345
bogdanm 82:6473597d706e 1346 /*!
bogdanm 82:6473597d706e 1347 * @brief Sets the 1588 timer.
bogdanm 82:6473597d706e 1348 *
bogdanm 82:6473597d706e 1349 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1350 * @param nanSecond The nanosecond set to 1588 timer
bogdanm 82:6473597d706e 1351 */
bogdanm 82:6473597d706e 1352 static inline void enet_hal_set_current_time(uint32_t instance, uint32_t nanSecond)
bogdanm 82:6473597d706e 1353 {
bogdanm 82:6473597d706e 1354 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1355
bogdanm 82:6473597d706e 1356 HW_ENET_ATVR_WR(instance,nanSecond);
bogdanm 82:6473597d706e 1357 }
bogdanm 82:6473597d706e 1358
bogdanm 82:6473597d706e 1359 /*!
bogdanm 82:6473597d706e 1360 * @brief Gets the time from the 1588 timer.
bogdanm 82:6473597d706e 1361 *
bogdanm 82:6473597d706e 1362 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1363 * @return the current time from 1588 timer
bogdanm 82:6473597d706e 1364 */
bogdanm 82:6473597d706e 1365 static inline uint32_t enet_hal_get_current_time(uint32_t instance)
bogdanm 82:6473597d706e 1366 {
bogdanm 82:6473597d706e 1367 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1368
bogdanm 82:6473597d706e 1369 return HW_ENET_ATVR_RD(instance);
bogdanm 82:6473597d706e 1370 }
bogdanm 82:6473597d706e 1371
bogdanm 82:6473597d706e 1372 /*!
bogdanm 82:6473597d706e 1373 * @brief Gets the transmit timestamp.
bogdanm 82:6473597d706e 1374 *
bogdanm 82:6473597d706e 1375 * @param instance The ENET instance number
bogdanm 82:6473597d706e 1376 * @return The timestamp of the last transmitted frame
bogdanm 82:6473597d706e 1377 */
bogdanm 82:6473597d706e 1378 static inline uint32_t enet_hal_get_tx_timestamp(uint32_t instance)
bogdanm 82:6473597d706e 1379 {
bogdanm 82:6473597d706e 1380 assert(instance < HW_ENET_INSTANCE_COUNT);
bogdanm 82:6473597d706e 1381
bogdanm 82:6473597d706e 1382 return HW_ENET_ATSTMP_RD(instance);
bogdanm 82:6473597d706e 1383 }
bogdanm 82:6473597d706e 1384
bogdanm 82:6473597d706e 1385 /*!
bogdanm 82:6473597d706e 1386 * @brief Gets the transmit buffer descriptor timestamp flag.
bogdanm 82:6473597d706e 1387 *
bogdanm 82:6473597d706e 1388 * @param curBd The ENET transmit buffer descriptor
bogdanm 82:6473597d706e 1389 * @return true if timestamp region is set else false.
bogdanm 82:6473597d706e 1390 */
bogdanm 82:6473597d706e 1391 bool enet_hal_get_txbd_timestamp_flag(void *curBd);
bogdanm 82:6473597d706e 1392
bogdanm 82:6473597d706e 1393 /*!
bogdanm 82:6473597d706e 1394 * @brief Gets the buffer descriptor timestamp.
bogdanm 82:6473597d706e 1395 *
bogdanm 82:6473597d706e 1396 * @param null
bogdanm 82:6473597d706e 1397 * @return The the size of the buffer descriptor
bogdanm 82:6473597d706e 1398 */
bogdanm 82:6473597d706e 1399 static inline uint32_t enet_hal_get_bd_size(void)
bogdanm 82:6473597d706e 1400 {
bogdanm 82:6473597d706e 1401 return sizeof(enet_bd_struct_t);
bogdanm 82:6473597d706e 1402 }
bogdanm 82:6473597d706e 1403
bogdanm 82:6473597d706e 1404 /* @} */
bogdanm 82:6473597d706e 1405
bogdanm 82:6473597d706e 1406 #if defined(__cplusplus)
bogdanm 82:6473597d706e 1407 }
bogdanm 82:6473597d706e 1408 #endif
bogdanm 82:6473597d706e 1409
bogdanm 82:6473597d706e 1410 /*! @}*/
bogdanm 82:6473597d706e 1411 #endif /*!< __FSL_ENET_HAL_H__*/
bogdanm 82:6473597d706e 1412
bogdanm 82:6473597d706e 1413 /*******************************************************************************
bogdanm 82:6473597d706e 1414 * EOF
bogdanm 82:6473597d706e 1415 ******************************************************************************/
bogdanm 82:6473597d706e 1416