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