NXP LPC1768 Ethernet driver for lwip and CMSIS-RTOS

Dependents:   EthernetInterface EthernetInterface EthernetInterface_RSF EthernetInterface ... more

Legacy Networking Libraries

This is an mbed 2 networking library. For mbed 5, the networking libraries have been revised to better support additional network stacks and thread safety here.

This library is based on the code of the NXP LPC port of the Lightweight TCP/IP Stack

Copyright(C) 2011, NXP Semiconductor
All rights reserved.

Software that is described herein is for illustrative purposes only
which provides customers with programming information regarding the
products. This software is supplied "AS IS" without any warranties.
NXP Semiconductors assumes no responsibility or liability for the
use of the software, conveys no license or title under any patent,
copyright, or mask work right to the product. NXP Semiconductors
reserves the right to make changes in the software without
notification. NXP Semiconductors also make no representation or
warranty that such application will be suitable for the specified
use without further testing or modification.
Committer:
mbed_official
Date:
Fri Sep 19 13:45:16 2014 +0100
Revision:
19:007f4e6b2776
Child:
20:620d381e7f4c
Synchronized with git revision b2831b6b077363f28ccc95f73483484ad4421ad7

Full URL: https://github.com/mbedmicro/mbed/commit/b2831b6b077363f28ccc95f73483484ad4421ad7/

[NET] K64F - enet driver addition (latest merge removed that file)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 19:007f4e6b2776 1 /*
mbed_official 19:007f4e6b2776 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
mbed_official 19:007f4e6b2776 3 * All rights reserved.
mbed_official 19:007f4e6b2776 4 *
mbed_official 19:007f4e6b2776 5 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 19:007f4e6b2776 6 * are permitted provided that the following conditions are met:
mbed_official 19:007f4e6b2776 7 *
mbed_official 19:007f4e6b2776 8 * o Redistributions of source code must retain the above copyright notice, this list
mbed_official 19:007f4e6b2776 9 * of conditions and the following disclaimer.
mbed_official 19:007f4e6b2776 10 *
mbed_official 19:007f4e6b2776 11 * o Redistributions in binary form must reproduce the above copyright notice, this
mbed_official 19:007f4e6b2776 12 * list of conditions and the following disclaimer in the documentation and/or
mbed_official 19:007f4e6b2776 13 * other materials provided with the distribution.
mbed_official 19:007f4e6b2776 14 *
mbed_official 19:007f4e6b2776 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
mbed_official 19:007f4e6b2776 16 * contributors may be used to endorse or promote products derived from this
mbed_official 19:007f4e6b2776 17 * software without specific prior written permission.
mbed_official 19:007f4e6b2776 18 *
mbed_official 19:007f4e6b2776 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mbed_official 19:007f4e6b2776 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mbed_official 19:007f4e6b2776 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 19:007f4e6b2776 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
mbed_official 19:007f4e6b2776 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mbed_official 19:007f4e6b2776 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 19:007f4e6b2776 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
mbed_official 19:007f4e6b2776 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mbed_official 19:007f4e6b2776 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mbed_official 19:007f4e6b2776 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 19:007f4e6b2776 29 */
mbed_official 19:007f4e6b2776 30
mbed_official 19:007f4e6b2776 31 /* Modified by mbed for the lwIP port */
mbed_official 19:007f4e6b2776 32
mbed_official 19:007f4e6b2776 33 #include "fsl_enet_driver.h"
mbed_official 19:007f4e6b2776 34 #include "fsl_enet_hal.h"
mbed_official 19:007f4e6b2776 35 #include "fsl_clock_manager.h"
mbed_official 19:007f4e6b2776 36 #include "fsl_interrupt_manager.h"
mbed_official 19:007f4e6b2776 37 #include <string.h>
mbed_official 19:007f4e6b2776 38
mbed_official 19:007f4e6b2776 39 #include "sys_arch.h"
mbed_official 19:007f4e6b2776 40
mbed_official 19:007f4e6b2776 41 /*******************************************************************************
mbed_official 19:007f4e6b2776 42 * Variables
mbed_official 19:007f4e6b2776 43 ******************************************************************************/
mbed_official 19:007f4e6b2776 44 /*! @brief Define ENET's IRQ list */
mbed_official 19:007f4e6b2776 45
mbed_official 19:007f4e6b2776 46 void *enetIfHandle;
mbed_official 19:007f4e6b2776 47
mbed_official 19:007f4e6b2776 48 /*! @brief Define MAC driver API structure and for application of stack adaptor layer*/
mbed_official 19:007f4e6b2776 49 const enet_mac_api_t g_enetMacApi =
mbed_official 19:007f4e6b2776 50 {
mbed_official 19:007f4e6b2776 51 enet_mac_init,
mbed_official 19:007f4e6b2776 52 NULL, // enet_mac_deinit,
mbed_official 19:007f4e6b2776 53 NULL, // enet_mac_send,
mbed_official 19:007f4e6b2776 54 #if !ENET_RECEIVE_ALL_INTERRUPT
mbed_official 19:007f4e6b2776 55 NULL, // enet_mac_receive,
mbed_official 19:007f4e6b2776 56 #endif
mbed_official 19:007f4e6b2776 57 enet_mii_read,
mbed_official 19:007f4e6b2776 58 enet_mii_write,
mbed_official 19:007f4e6b2776 59 NULL, // enet_mac_add_multicast_group,
mbed_official 19:007f4e6b2776 60 NULL, //enet_mac_leave_multicast_group,
mbed_official 19:007f4e6b2776 61 };
mbed_official 19:007f4e6b2776 62 /*******************************************************************************
mbed_official 19:007f4e6b2776 63 * Code
mbed_official 19:007f4e6b2776 64 ******************************************************************************/
mbed_official 19:007f4e6b2776 65
mbed_official 19:007f4e6b2776 66 // NOTE: we need these functions to be non-blocking fpr the PHY task, hence the
mbed_official 19:007f4e6b2776 67 // osDelay() below
mbed_official 19:007f4e6b2776 68
mbed_official 19:007f4e6b2776 69 /*FUNCTION****************************************************************
mbed_official 19:007f4e6b2776 70 *
mbed_official 19:007f4e6b2776 71 * Function Name: enet_mii_read
mbed_official 19:007f4e6b2776 72 * Return Value: The execution status.
mbed_official 19:007f4e6b2776 73 * Description: Read function.
mbed_official 19:007f4e6b2776 74 * This interface read data over the (R)MII bus from the specified PHY register,
mbed_official 19:007f4e6b2776 75 * This function is called by all PHY interfaces.
mbed_official 19:007f4e6b2776 76 *END*********************************************************************/
mbed_official 19:007f4e6b2776 77 uint32_t enet_mii_read(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr)
mbed_official 19:007f4e6b2776 78 {
mbed_official 19:007f4e6b2776 79 uint32_t counter;
mbed_official 19:007f4e6b2776 80
mbed_official 19:007f4e6b2776 81 /* Check the input parameters*/
mbed_official 19:007f4e6b2776 82 if (!dataPtr)
mbed_official 19:007f4e6b2776 83 {
mbed_official 19:007f4e6b2776 84 return kStatus_ENET_InvalidInput;
mbed_official 19:007f4e6b2776 85 }
mbed_official 19:007f4e6b2776 86
mbed_official 19:007f4e6b2776 87 /* Check if the mii is enabled*/
mbed_official 19:007f4e6b2776 88 if (!enet_hal_is_mii_enabled(instance))
mbed_official 19:007f4e6b2776 89 {
mbed_official 19:007f4e6b2776 90 return kStatus_ENET_Miiuninitialized;
mbed_official 19:007f4e6b2776 91 }
mbed_official 19:007f4e6b2776 92
mbed_official 19:007f4e6b2776 93 /* Clear the MII interrupt event*/
mbed_official 19:007f4e6b2776 94 enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
mbed_official 19:007f4e6b2776 95
mbed_official 19:007f4e6b2776 96 /* Read command operation*/
mbed_official 19:007f4e6b2776 97 enet_hal_set_mii_command(instance, phyAddr, phyReg, kEnetReadValidFrame, 0);
mbed_official 19:007f4e6b2776 98
mbed_official 19:007f4e6b2776 99 /* Poll for MII complete*/
mbed_official 19:007f4e6b2776 100 for (counter = 0; counter < kEnetMaxTimeout; counter++)
mbed_official 19:007f4e6b2776 101 {
mbed_official 19:007f4e6b2776 102 if (enet_hal_get_interrupt_status(instance, kEnetMiiInterrupt))
mbed_official 19:007f4e6b2776 103 {
mbed_official 19:007f4e6b2776 104 break;
mbed_official 19:007f4e6b2776 105 }
mbed_official 19:007f4e6b2776 106 osDelay(1);
mbed_official 19:007f4e6b2776 107 }
mbed_official 19:007f4e6b2776 108
mbed_official 19:007f4e6b2776 109 /* Check for timeout*/
mbed_official 19:007f4e6b2776 110 if (counter == kEnetMaxTimeout)
mbed_official 19:007f4e6b2776 111 {
mbed_official 19:007f4e6b2776 112 return kStatus_ENET_TimeOut;
mbed_official 19:007f4e6b2776 113 }
mbed_official 19:007f4e6b2776 114
mbed_official 19:007f4e6b2776 115 /* Get data from mii register*/
mbed_official 19:007f4e6b2776 116 *dataPtr = enet_hal_get_mii_data(instance);
mbed_official 19:007f4e6b2776 117
mbed_official 19:007f4e6b2776 118 /* Clear MII interrupt event*/
mbed_official 19:007f4e6b2776 119 enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
mbed_official 19:007f4e6b2776 120
mbed_official 19:007f4e6b2776 121 return kStatus_ENET_Success;
mbed_official 19:007f4e6b2776 122 }
mbed_official 19:007f4e6b2776 123
mbed_official 19:007f4e6b2776 124 /*FUNCTION****************************************************************
mbed_official 19:007f4e6b2776 125 *
mbed_official 19:007f4e6b2776 126 * Function Name: enet_mii_write
mbed_official 19:007f4e6b2776 127 * Return Value: The execution status.
mbed_official 19:007f4e6b2776 128 * Description: Write function.
mbed_official 19:007f4e6b2776 129 * This interface write data over the (R)MII bus to the specified PHY register.
mbed_official 19:007f4e6b2776 130 * This function is called by all PHY interfaces.
mbed_official 19:007f4e6b2776 131 *END*********************************************************************/
mbed_official 19:007f4e6b2776 132 uint32_t enet_mii_write(uint32_t instance, uint32_t phyAddr, uint32_t phyReg, uint32_t data)
mbed_official 19:007f4e6b2776 133 {
mbed_official 19:007f4e6b2776 134 uint32_t counter;
mbed_official 19:007f4e6b2776 135
mbed_official 19:007f4e6b2776 136 /* Check if the mii is enabled*/
mbed_official 19:007f4e6b2776 137 if (!enet_hal_is_mii_enabled(instance))
mbed_official 19:007f4e6b2776 138 {
mbed_official 19:007f4e6b2776 139 return kStatus_ENET_Miiuninitialized;
mbed_official 19:007f4e6b2776 140 }
mbed_official 19:007f4e6b2776 141
mbed_official 19:007f4e6b2776 142 /* Clear the MII interrupt event*/
mbed_official 19:007f4e6b2776 143 enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
mbed_official 19:007f4e6b2776 144
mbed_official 19:007f4e6b2776 145 /* Read command operation*/
mbed_official 19:007f4e6b2776 146 enet_hal_set_mii_command(instance, phyAddr, phyReg, kEnetWriteValidFrame, data);
mbed_official 19:007f4e6b2776 147
mbed_official 19:007f4e6b2776 148 /* Poll for MII complete*/
mbed_official 19:007f4e6b2776 149 for (counter = 0; counter < kEnetMaxTimeout; counter++)
mbed_official 19:007f4e6b2776 150 {
mbed_official 19:007f4e6b2776 151 if (enet_hal_get_interrupt_status(instance, kEnetMiiInterrupt))
mbed_official 19:007f4e6b2776 152 {
mbed_official 19:007f4e6b2776 153 break;
mbed_official 19:007f4e6b2776 154 }
mbed_official 19:007f4e6b2776 155 osDelay(1);
mbed_official 19:007f4e6b2776 156 }
mbed_official 19:007f4e6b2776 157
mbed_official 19:007f4e6b2776 158 /* Check for timeout*/
mbed_official 19:007f4e6b2776 159 if (counter == kEnetMaxTimeout)
mbed_official 19:007f4e6b2776 160 {
mbed_official 19:007f4e6b2776 161 return kStatus_ENET_TimeOut;
mbed_official 19:007f4e6b2776 162 }
mbed_official 19:007f4e6b2776 163
mbed_official 19:007f4e6b2776 164 /* Clear MII intrrupt event*/
mbed_official 19:007f4e6b2776 165 enet_hal_clear_interrupt(instance, kEnetMiiInterrupt);
mbed_official 19:007f4e6b2776 166
mbed_official 19:007f4e6b2776 167 return kStatus_ENET_Success;
mbed_official 19:007f4e6b2776 168 }
mbed_official 19:007f4e6b2776 169 /*FUNCTION****************************************************************
mbed_official 19:007f4e6b2776 170 *
mbed_official 19:007f4e6b2776 171 * Function Name: enet_mac_mii_init
mbed_official 19:007f4e6b2776 172 * Return Value: The execution status.
mbed_official 19:007f4e6b2776 173 * Description:Initialize the ENET Mac mii(mdc/mdio)interface.
mbed_official 19:007f4e6b2776 174 *END*********************************************************************/
mbed_official 19:007f4e6b2776 175 uint32_t enet_mac_mii_init(enet_dev_if_t * enetIfPtr)
mbed_official 19:007f4e6b2776 176 {
mbed_official 19:007f4e6b2776 177 uint32_t frequency;
mbed_official 19:007f4e6b2776 178
mbed_official 19:007f4e6b2776 179 /* Check the input parameters*/
mbed_official 19:007f4e6b2776 180 if (enetIfPtr == NULL)
mbed_official 19:007f4e6b2776 181 {
mbed_official 19:007f4e6b2776 182 return kStatus_ENET_InvalidInput;
mbed_official 19:007f4e6b2776 183 }
mbed_official 19:007f4e6b2776 184
mbed_official 19:007f4e6b2776 185 /* Configure mii speed*/
mbed_official 19:007f4e6b2776 186 CLOCK_SYS_GetFreq(kSystemClock, &frequency);
mbed_official 19:007f4e6b2776 187 enet_hal_config_mii(enetIfPtr->deviceNumber, (frequency/(2 * enetIfPtr->macCfgPtr->miiClock) + 1),
mbed_official 19:007f4e6b2776 188 kEnetMdioHoldOneClkCycle, false);
mbed_official 19:007f4e6b2776 189
mbed_official 19:007f4e6b2776 190 return kStatus_ENET_Success;
mbed_official 19:007f4e6b2776 191 }
mbed_official 19:007f4e6b2776 192
mbed_official 19:007f4e6b2776 193 /*FUNCTION****************************************************************
mbed_official 19:007f4e6b2776 194 *
mbed_official 19:007f4e6b2776 195 * Function Name: enet_mac_rxbd_init
mbed_official 19:007f4e6b2776 196 * Return Value: The execution status.
mbed_official 19:007f4e6b2776 197 * Description:Initialize the ENET receive buffer descriptors.
mbed_official 19:007f4e6b2776 198 * Note: If you do receive on receive interrupt handler the receive
mbed_official 19:007f4e6b2776 199 * data buffer number can be the same as the receive descriptor numbers.
mbed_official 19:007f4e6b2776 200 * But if you are polling receive frames please make sure the receive data
mbed_official 19:007f4e6b2776 201 * buffers are more than buffer descriptors to guarantee a good performance.
mbed_official 19:007f4e6b2776 202 *END*********************************************************************/
mbed_official 19:007f4e6b2776 203 uint32_t enet_mac_rxbd_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg)
mbed_official 19:007f4e6b2776 204 {
mbed_official 19:007f4e6b2776 205 /* Check the input parameters*/
mbed_official 19:007f4e6b2776 206 if ((!enetIfPtr) || (!rxbdCfg))
mbed_official 19:007f4e6b2776 207 {
mbed_official 19:007f4e6b2776 208 return kStatus_ENET_InvalidInput;
mbed_official 19:007f4e6b2776 209 }
mbed_official 19:007f4e6b2776 210
mbed_official 19:007f4e6b2776 211 enetIfPtr->macContextPtr->bufferdescSize = enet_hal_get_bd_size();
mbed_official 19:007f4e6b2776 212
mbed_official 19:007f4e6b2776 213 /* Initialize the bd status*/
mbed_official 19:007f4e6b2776 214 enetIfPtr->macContextPtr->isRxFull = false;
mbed_official 19:007f4e6b2776 215
mbed_official 19:007f4e6b2776 216 /* Initialize receive bd base address and current address*/
mbed_official 19:007f4e6b2776 217 enetIfPtr->macContextPtr->rxBdBasePtr = rxbdCfg->rxBdPtrAlign;
mbed_official 19:007f4e6b2776 218 enetIfPtr->macContextPtr->rxBdCurPtr = enetIfPtr->macContextPtr->rxBdBasePtr;
mbed_official 19:007f4e6b2776 219 enetIfPtr->macContextPtr->rxBdDirtyPtr = enetIfPtr->macContextPtr->rxBdBasePtr;
mbed_official 19:007f4e6b2776 220 enet_hal_set_rxbd_address(enetIfPtr->deviceNumber, (uint32_t)(enetIfPtr->macContextPtr->rxBdBasePtr));
mbed_official 19:007f4e6b2776 221
mbed_official 19:007f4e6b2776 222 return kStatus_ENET_Success;
mbed_official 19:007f4e6b2776 223 }
mbed_official 19:007f4e6b2776 224
mbed_official 19:007f4e6b2776 225 /*FUNCTION****************************************************************
mbed_official 19:007f4e6b2776 226 *
mbed_official 19:007f4e6b2776 227 * Function Name: enet_mac_txbd_init
mbed_official 19:007f4e6b2776 228 * Return Value: The execution status.
mbed_official 19:007f4e6b2776 229 * Description:Initialize the ENET transmit buffer descriptors.
mbed_official 19:007f4e6b2776 230 * This function prepare all of the transmit buffer descriptors.
mbed_official 19:007f4e6b2776 231 *END*********************************************************************/
mbed_official 19:007f4e6b2776 232 uint32_t enet_mac_txbd_init(enet_dev_if_t * enetIfPtr, enet_txbd_config_t *txbdCfg)
mbed_official 19:007f4e6b2776 233 {
mbed_official 19:007f4e6b2776 234 /* Check the input parameters*/
mbed_official 19:007f4e6b2776 235 if ((!enetIfPtr) || (!txbdCfg))
mbed_official 19:007f4e6b2776 236 {
mbed_official 19:007f4e6b2776 237 return kStatus_ENET_InvalidInput;
mbed_official 19:007f4e6b2776 238 }
mbed_official 19:007f4e6b2776 239
mbed_official 19:007f4e6b2776 240 /* Initialize the bd status*/
mbed_official 19:007f4e6b2776 241 enetIfPtr->macContextPtr->isTxFull = false;
mbed_official 19:007f4e6b2776 242
mbed_official 19:007f4e6b2776 243 /* Initialize transmit bd base address and current address*/
mbed_official 19:007f4e6b2776 244 enetIfPtr->macContextPtr->txBdBasePtr = txbdCfg->txBdPtrAlign;
mbed_official 19:007f4e6b2776 245 enetIfPtr->macContextPtr->txBdCurPtr = enetIfPtr->macContextPtr->txBdBasePtr;
mbed_official 19:007f4e6b2776 246 enetIfPtr->macContextPtr->txBdDirtyPtr = enetIfPtr->macContextPtr->txBdBasePtr;
mbed_official 19:007f4e6b2776 247 enet_hal_set_txbd_address(enetIfPtr->deviceNumber, (uint32_t)(enetIfPtr->macContextPtr->txBdBasePtr));
mbed_official 19:007f4e6b2776 248 return kStatus_ENET_Success;
mbed_official 19:007f4e6b2776 249 }
mbed_official 19:007f4e6b2776 250
mbed_official 19:007f4e6b2776 251 /*FUNCTION****************************************************************
mbed_official 19:007f4e6b2776 252 *
mbed_official 19:007f4e6b2776 253 * Function Name: enet_mac_configure_fifo_accel
mbed_official 19:007f4e6b2776 254 * Return Value: The execution status.
mbed_official 19:007f4e6b2776 255 * Description: Configure the ENET FIFO and Accelerator.
mbed_official 19:007f4e6b2776 256 *END*********************************************************************/
mbed_official 19:007f4e6b2776 257 uint32_t enet_mac_configure_fifo_accel(enet_dev_if_t * enetIfPtr)
mbed_official 19:007f4e6b2776 258 {
mbed_official 19:007f4e6b2776 259 enet_config_rx_fifo_t rxFifo;
mbed_official 19:007f4e6b2776 260 enet_config_tx_fifo_t txFifo;
mbed_official 19:007f4e6b2776 261
mbed_official 19:007f4e6b2776 262 /* Check the input parameters*/
mbed_official 19:007f4e6b2776 263 if (!enetIfPtr)
mbed_official 19:007f4e6b2776 264 {
mbed_official 19:007f4e6b2776 265 return kStatus_ENET_InvalidInput;
mbed_official 19:007f4e6b2776 266 }
mbed_official 19:007f4e6b2776 267
mbed_official 19:007f4e6b2776 268 /* Initialize values that will not be initialized later on */
mbed_official 19:007f4e6b2776 269 rxFifo.rxEmpty = 0;
mbed_official 19:007f4e6b2776 270 rxFifo.rxFull = 0;
mbed_official 19:007f4e6b2776 271 txFifo.isStoreForwardEnabled = 0;
mbed_official 19:007f4e6b2776 272 txFifo.txFifoWrite = 0;
mbed_official 19:007f4e6b2776 273 txFifo.txEmpty = 0;
mbed_official 19:007f4e6b2776 274
mbed_official 19:007f4e6b2776 275 /* Configure tx/rx accelerator*/
mbed_official 19:007f4e6b2776 276 if (enetIfPtr->macCfgPtr->isRxAccelEnabled)
mbed_official 19:007f4e6b2776 277 {
mbed_official 19:007f4e6b2776 278 enet_hal_config_rx_accelerator(enetIfPtr->deviceNumber,
mbed_official 19:007f4e6b2776 279 (enet_config_rx_accelerator_t *)&(enetIfPtr->macCfgPtr->rxAcceler));
mbed_official 19:007f4e6b2776 280 if ((enetIfPtr->macCfgPtr->rxAcceler.isIpcheckEnabled) || (enetIfPtr->macCfgPtr->rxAcceler.isProtocolCheckEnabled))
mbed_official 19:007f4e6b2776 281 {
mbed_official 19:007f4e6b2776 282 rxFifo.rxFull = 0;
mbed_official 19:007f4e6b2776 283 }
mbed_official 19:007f4e6b2776 284 }
mbed_official 19:007f4e6b2776 285 if (enetIfPtr->macCfgPtr->isTxAccelEnabled)
mbed_official 19:007f4e6b2776 286 {
mbed_official 19:007f4e6b2776 287 enet_hal_config_tx_accelerator(enetIfPtr->deviceNumber,
mbed_official 19:007f4e6b2776 288 (enet_config_tx_accelerator_t *)&(enetIfPtr->macCfgPtr->txAcceler));
mbed_official 19:007f4e6b2776 289 if ((enetIfPtr->macCfgPtr->txAcceler.isIpCheckEnabled) || (enetIfPtr->macCfgPtr->txAcceler.isProtocolCheckEnabled))
mbed_official 19:007f4e6b2776 290 {
mbed_official 19:007f4e6b2776 291 txFifo.isStoreForwardEnabled = 1;
mbed_official 19:007f4e6b2776 292 }
mbed_official 19:007f4e6b2776 293 }
mbed_official 19:007f4e6b2776 294 if (enetIfPtr->macCfgPtr->isStoreAndFwEnabled)
mbed_official 19:007f4e6b2776 295 {
mbed_official 19:007f4e6b2776 296 rxFifo.rxFull = 0;
mbed_official 19:007f4e6b2776 297 txFifo.isStoreForwardEnabled = 1;
mbed_official 19:007f4e6b2776 298 }
mbed_official 19:007f4e6b2776 299
mbed_official 19:007f4e6b2776 300
mbed_official 19:007f4e6b2776 301 /* Set TFWR value if STRFWD is not being used */
mbed_official 19:007f4e6b2776 302 if (txFifo.isStoreForwardEnabled == 1)
mbed_official 19:007f4e6b2776 303 txFifo.txFifoWrite = 0;
mbed_official 19:007f4e6b2776 304 else
mbed_official 19:007f4e6b2776 305 /* TFWR value is a trade-off between transmit latency and risk of transmit FIFO underrun due to contention for the system bus
mbed_official 19:007f4e6b2776 306 TFWR = 15 means transmission will begin once 960 bytes has been written to the Tx FIFO (for frames larger than 960 bytes)
mbed_official 19:007f4e6b2776 307 See Section 45.4.18 - Transmit FIFO Watermark Register of the K64F Reference Manual for details */
mbed_official 19:007f4e6b2776 308 txFifo.txFifoWrite = 15;
mbed_official 19:007f4e6b2776 309
mbed_official 19:007f4e6b2776 310 /* Configure tx/rx FIFO with default value*/
mbed_official 19:007f4e6b2776 311 rxFifo.rxAlmostEmpty = 4;
mbed_official 19:007f4e6b2776 312 rxFifo.rxAlmostFull = 4;
mbed_official 19:007f4e6b2776 313 txFifo.txAlmostEmpty = 4;
mbed_official 19:007f4e6b2776 314 txFifo.txAlmostFull = 8;
mbed_official 19:007f4e6b2776 315 enet_hal_config_rx_fifo(enetIfPtr->deviceNumber, &rxFifo);
mbed_official 19:007f4e6b2776 316 enet_hal_config_tx_fifo(enetIfPtr->deviceNumber, &txFifo);
mbed_official 19:007f4e6b2776 317
mbed_official 19:007f4e6b2776 318 return kStatus_ENET_Success;
mbed_official 19:007f4e6b2776 319 }
mbed_official 19:007f4e6b2776 320
mbed_official 19:007f4e6b2776 321 /*FUNCTION****************************************************************
mbed_official 19:007f4e6b2776 322 *
mbed_official 19:007f4e6b2776 323 * Function Name: enet_mac_configure_controller
mbed_official 19:007f4e6b2776 324 * Return Value: The execution status.
mbed_official 19:007f4e6b2776 325 * Description: Configure the ENET controller with the basic configuration.
mbed_official 19:007f4e6b2776 326 *END*********************************************************************/
mbed_official 19:007f4e6b2776 327 uint32_t enet_mac_configure_controller(enet_dev_if_t * enetIfPtr)
mbed_official 19:007f4e6b2776 328 {
mbed_official 19:007f4e6b2776 329 uint32_t macCtlCfg;
mbed_official 19:007f4e6b2776 330
mbed_official 19:007f4e6b2776 331 /* Check the input parameters*/
mbed_official 19:007f4e6b2776 332 if (enetIfPtr == NULL)
mbed_official 19:007f4e6b2776 333 {
mbed_official 19:007f4e6b2776 334 return kStatus_ENET_InvalidInput;
mbed_official 19:007f4e6b2776 335 }
mbed_official 19:007f4e6b2776 336
mbed_official 19:007f4e6b2776 337 macCtlCfg = enetIfPtr->macCfgPtr->macCtlConfigure;
mbed_official 19:007f4e6b2776 338 /* Configure rmii/mii interface*/
mbed_official 19:007f4e6b2776 339 enet_hal_config_rmii(enetIfPtr->deviceNumber, enetIfPtr->macCfgPtr->rmiiCfgMode,
mbed_official 19:007f4e6b2776 340 enetIfPtr->macCfgPtr->speed, enetIfPtr->macCfgPtr->duplex, false,
mbed_official 19:007f4e6b2776 341 (macCtlCfg & kEnetRxMiiLoopback));
mbed_official 19:007f4e6b2776 342 /* Configure receive buffer size*/
mbed_official 19:007f4e6b2776 343 if (enetIfPtr->macCfgPtr->isVlanEnabled)
mbed_official 19:007f4e6b2776 344 {
mbed_official 19:007f4e6b2776 345 enetIfPtr->maxFrameSize = kEnetMaxFrameVlanSize;
mbed_official 19:007f4e6b2776 346 enet_hal_set_rx_max_size(enetIfPtr->deviceNumber,
mbed_official 19:007f4e6b2776 347 enetIfPtr->macContextPtr->rxBufferSizeAligned, kEnetMaxFrameVlanSize);
mbed_official 19:007f4e6b2776 348 }
mbed_official 19:007f4e6b2776 349 else
mbed_official 19:007f4e6b2776 350 {
mbed_official 19:007f4e6b2776 351 enetIfPtr->maxFrameSize = kEnetMaxFrameSize;
mbed_official 19:007f4e6b2776 352 enet_hal_set_rx_max_size(enetIfPtr->deviceNumber,
mbed_official 19:007f4e6b2776 353 enetIfPtr->macContextPtr->rxBufferSizeAligned, kEnetMaxFrameSize);
mbed_official 19:007f4e6b2776 354 }
mbed_official 19:007f4e6b2776 355
mbed_official 19:007f4e6b2776 356 /* Set receive controller promiscuous */
mbed_official 19:007f4e6b2776 357 enet_hal_config_promiscuous(enetIfPtr->deviceNumber, macCtlCfg & kEnetRxPromiscuousEnable);
mbed_official 19:007f4e6b2776 358 /* Set receive flow control*/
mbed_official 19:007f4e6b2776 359 enet_hal_enable_flowcontrol(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxFlowControlEnable));
mbed_official 19:007f4e6b2776 360 /* Set received PAUSE frames are forwarded/terminated*/
mbed_official 19:007f4e6b2776 361 enet_hal_enable_pauseforward(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxPauseFwdEnable));
mbed_official 19:007f4e6b2776 362 /* Set receive broadcast frame reject*/
mbed_official 19:007f4e6b2776 363 enet_hal_enable_broadcastreject(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxBcRejectEnable));
mbed_official 19:007f4e6b2776 364 /* Set padding is removed from the received frame*/
mbed_official 19:007f4e6b2776 365 enet_hal_enable_padremove(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxPadRemoveEnable));
mbed_official 19:007f4e6b2776 366 /* Set the crc of the received frame is stripped from the frame*/
mbed_official 19:007f4e6b2776 367 enet_hal_enable_rxcrcforward(enetIfPtr->deviceNumber, (macCtlCfg & kEnetRxCrcFwdEnable));
mbed_official 19:007f4e6b2776 368 /* Set receive payload length check*/
mbed_official 19:007f4e6b2776 369 enet_hal_enable_payloadcheck(enetIfPtr->deviceNumber, (macCtlCfg & kEnetPayloadlenCheckEnable));
mbed_official 19:007f4e6b2776 370 /* Set control sleep mode*/
mbed_official 19:007f4e6b2776 371 enet_hal_enable_sleep(enetIfPtr->deviceNumber, (macCtlCfg & kEnetSleepModeEnable));
mbed_official 19:007f4e6b2776 372 return kStatus_ENET_Success;
mbed_official 19:007f4e6b2776 373 }
mbed_official 19:007f4e6b2776 374
mbed_official 19:007f4e6b2776 375 /*FUNCTION****************************************************************
mbed_official 19:007f4e6b2776 376 *
mbed_official 19:007f4e6b2776 377 * Function Name: enet_mac_init
mbed_official 19:007f4e6b2776 378 * Return Value: The execution status.
mbed_official 19:007f4e6b2776 379 * Description:Initialize the ENET device with the basic configuration
mbed_official 19:007f4e6b2776 380 * When ENET is used, this function need to be called by the NET initialize
mbed_official 19:007f4e6b2776 381 * interface.
mbed_official 19:007f4e6b2776 382 *END*********************************************************************/
mbed_official 19:007f4e6b2776 383 uint32_t enet_mac_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg,
mbed_official 19:007f4e6b2776 384 enet_txbd_config_t *txbdCfg)
mbed_official 19:007f4e6b2776 385 {
mbed_official 19:007f4e6b2776 386 uint32_t timeOut = 0;
mbed_official 19:007f4e6b2776 387 uint32_t devNumber, result = 0;
mbed_official 19:007f4e6b2776 388
mbed_official 19:007f4e6b2776 389 /* Check the input parameters*/
mbed_official 19:007f4e6b2776 390 if (enetIfPtr == NULL)
mbed_official 19:007f4e6b2776 391 {
mbed_official 19:007f4e6b2776 392 return kStatus_ENET_InvalidInput;
mbed_official 19:007f4e6b2776 393 }
mbed_official 19:007f4e6b2776 394
mbed_official 19:007f4e6b2776 395 /* Get device number and check the parameter*/
mbed_official 19:007f4e6b2776 396 devNumber = enetIfPtr->deviceNumber;
mbed_official 19:007f4e6b2776 397
mbed_official 19:007f4e6b2776 398 /* Store the global ENET structure for ISR input parameters for instance 0*/
mbed_official 19:007f4e6b2776 399 if (!devNumber)
mbed_official 19:007f4e6b2776 400 {
mbed_official 19:007f4e6b2776 401 enetIfHandle = enetIfPtr;
mbed_official 19:007f4e6b2776 402 }
mbed_official 19:007f4e6b2776 403
mbed_official 19:007f4e6b2776 404 /* Turn on ENET module clock gate */
mbed_official 19:007f4e6b2776 405 CLOCK_SYS_EnableEnetClock(0U);
mbed_official 19:007f4e6b2776 406
mbed_official 19:007f4e6b2776 407 /* Reset ENET mac*/
mbed_official 19:007f4e6b2776 408 enet_hal_reset_ethernet(devNumber);
mbed_official 19:007f4e6b2776 409 while ((!enet_hal_is_reset_completed(devNumber)) && (timeOut < kEnetMaxTimeout))
mbed_official 19:007f4e6b2776 410 {
mbed_official 19:007f4e6b2776 411 time_delay(1);
mbed_official 19:007f4e6b2776 412 timeOut++;
mbed_official 19:007f4e6b2776 413 }
mbed_official 19:007f4e6b2776 414
mbed_official 19:007f4e6b2776 415 /* Check out if timeout*/
mbed_official 19:007f4e6b2776 416 if (timeOut == kEnetMaxTimeout)
mbed_official 19:007f4e6b2776 417 {
mbed_official 19:007f4e6b2776 418 return kStatus_ENET_TimeOut;
mbed_official 19:007f4e6b2776 419 }
mbed_official 19:007f4e6b2776 420
mbed_official 19:007f4e6b2776 421 /* Disable all ENET mac interrupt and Clear all interrupt events*/
mbed_official 19:007f4e6b2776 422 enet_hal_config_interrupt(devNumber, kEnetAllInterrupt, false);
mbed_official 19:007f4e6b2776 423 enet_hal_clear_interrupt(devNumber, kEnetAllInterrupt);
mbed_official 19:007f4e6b2776 424
mbed_official 19:007f4e6b2776 425 /* Program this station's physical address*/
mbed_official 19:007f4e6b2776 426 enet_hal_set_mac_address(devNumber, enetIfPtr->macCfgPtr->macAddr);
mbed_official 19:007f4e6b2776 427
mbed_official 19:007f4e6b2776 428 /* Clear group and individual hash register*/
mbed_official 19:007f4e6b2776 429 enet_hal_set_group_hashtable(devNumber, 0, kEnetSpecialAddressInit);
mbed_official 19:007f4e6b2776 430 enet_hal_set_individual_hashtable(devNumber, 0, kEnetSpecialAddressInit);
mbed_official 19:007f4e6b2776 431
mbed_official 19:007f4e6b2776 432 /* Configure mac controller*/
mbed_official 19:007f4e6b2776 433 result = enet_mac_configure_controller(enetIfPtr);
mbed_official 19:007f4e6b2776 434 if(result != kStatus_ENET_Success)
mbed_official 19:007f4e6b2776 435 {
mbed_official 19:007f4e6b2776 436 return result;
mbed_official 19:007f4e6b2776 437 }
mbed_official 19:007f4e6b2776 438 /* Clear mib zero counters*/
mbed_official 19:007f4e6b2776 439 enet_hal_clear_mib(devNumber, true);
mbed_official 19:007f4e6b2776 440
mbed_official 19:007f4e6b2776 441 /* Initialize FIFO and accelerator*/
mbed_official 19:007f4e6b2776 442 result = enet_mac_configure_fifo_accel(enetIfPtr);
mbed_official 19:007f4e6b2776 443 if(result != kStatus_ENET_Success)
mbed_official 19:007f4e6b2776 444 {
mbed_official 19:007f4e6b2776 445 return result;
mbed_official 19:007f4e6b2776 446 }
mbed_official 19:007f4e6b2776 447 /* Initialize receive buffer descriptors*/
mbed_official 19:007f4e6b2776 448 result = enet_mac_rxbd_init(enetIfPtr, rxbdCfg);
mbed_official 19:007f4e6b2776 449 if(result != kStatus_ENET_Success)
mbed_official 19:007f4e6b2776 450 {
mbed_official 19:007f4e6b2776 451 return result;
mbed_official 19:007f4e6b2776 452 }
mbed_official 19:007f4e6b2776 453 /* Initialize transmit buffer descriptors*/
mbed_official 19:007f4e6b2776 454 result = enet_mac_txbd_init(enetIfPtr, txbdCfg);
mbed_official 19:007f4e6b2776 455 if(result != kStatus_ENET_Success)
mbed_official 19:007f4e6b2776 456 {
mbed_official 19:007f4e6b2776 457 return result;
mbed_official 19:007f4e6b2776 458 }
mbed_official 19:007f4e6b2776 459 /* Initialize rmii/mii interface*/
mbed_official 19:007f4e6b2776 460 result = enet_mac_mii_init(enetIfPtr);
mbed_official 19:007f4e6b2776 461 if (result != kStatus_ENET_Success)
mbed_official 19:007f4e6b2776 462 {
mbed_official 19:007f4e6b2776 463 return result;
mbed_official 19:007f4e6b2776 464 }
mbed_official 19:007f4e6b2776 465
mbed_official 19:007f4e6b2776 466 return kStatus_ENET_Success;
mbed_official 19:007f4e6b2776 467 }
mbed_official 19:007f4e6b2776 468
mbed_official 19:007f4e6b2776 469 /*******************************************************************************
mbed_official 19:007f4e6b2776 470 * EOF
mbed_official 19:007f4e6b2776 471 ******************************************************************************/
mbed_official 19:007f4e6b2776 472