Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robert_jw 0:b2805b6888dc 1 #include "lwip/opt.h"
robert_jw 0:b2805b6888dc 2 #include "lwip/sys.h"
robert_jw 0:b2805b6888dc 3 #include "lwip/def.h"
robert_jw 0:b2805b6888dc 4 #include "lwip/mem.h"
robert_jw 0:b2805b6888dc 5 #include "lwip/pbuf.h"
robert_jw 0:b2805b6888dc 6 #include "lwip/stats.h"
robert_jw 0:b2805b6888dc 7 #include "lwip/snmp.h"
robert_jw 0:b2805b6888dc 8 #include "lwip/tcpip.h"
robert_jw 0:b2805b6888dc 9 #include "netif/etharp.h"
robert_jw 0:b2805b6888dc 10 #include "netif/ppp_oe.h"
robert_jw 0:b2805b6888dc 11
robert_jw 0:b2805b6888dc 12 #include "eth_arch.h"
robert_jw 0:b2805b6888dc 13 #include "sys_arch.h"
robert_jw 0:b2805b6888dc 14
robert_jw 0:b2805b6888dc 15 #include "fsl_enet_driver.h"
robert_jw 0:b2805b6888dc 16 #include "fsl_enet_hal.h"
robert_jw 0:b2805b6888dc 17 #include "fsl_device_registers.h"
robert_jw 0:b2805b6888dc 18 #include "fsl_phy_driver.h"
robert_jw 0:b2805b6888dc 19 #include "fsl_interrupt_manager.h"
robert_jw 0:b2805b6888dc 20 #include "k64f_emac_config.h"
robert_jw 0:b2805b6888dc 21 #include <ctype.h>
robert_jw 0:b2805b6888dc 22 #include <stdio.h>
robert_jw 0:b2805b6888dc 23 #include <string.h>
robert_jw 0:b2805b6888dc 24 #include <stdlib.h>
robert_jw 0:b2805b6888dc 25
robert_jw 0:b2805b6888dc 26 #include "mbed_interface.h"
robert_jw 0:b2805b6888dc 27
robert_jw 0:b2805b6888dc 28 extern IRQn_Type enet_irq_ids[HW_ENET_INSTANCE_COUNT][FSL_FEATURE_ENET_INTERRUPT_COUNT];
robert_jw 0:b2805b6888dc 29 extern uint8_t enetIntMap[kEnetIntNum];
robert_jw 0:b2805b6888dc 30 extern void *enetIfHandle;
robert_jw 0:b2805b6888dc 31
robert_jw 0:b2805b6888dc 32 /********************************************************************************
robert_jw 0:b2805b6888dc 33 * Internal data
robert_jw 0:b2805b6888dc 34 ********************************************************************************/
robert_jw 0:b2805b6888dc 35
robert_jw 0:b2805b6888dc 36 extern void k64f_init_eth_hardware(void);
robert_jw 0:b2805b6888dc 37
robert_jw 0:b2805b6888dc 38 /* K64F EMAC driver data structure */
robert_jw 0:b2805b6888dc 39 struct k64f_enetdata {
robert_jw 0:b2805b6888dc 40 struct netif *netif; /**< Reference back to LWIP parent netif */
robert_jw 0:b2805b6888dc 41 sys_sem_t RxReadySem; /**< RX packet ready semaphore */
robert_jw 0:b2805b6888dc 42 sys_sem_t TxCleanSem; /**< TX cleanup thread wakeup semaphore */
robert_jw 0:b2805b6888dc 43 sys_mutex_t TXLockMutex; /**< TX critical section mutex */
robert_jw 0:b2805b6888dc 44 sys_sem_t xTXDCountSem; /**< TX free buffer counting semaphore */
robert_jw 0:b2805b6888dc 45 volatile u32_t rx_free_descs; /**< Count of free RX descriptors */
robert_jw 0:b2805b6888dc 46 struct pbuf *rxb[ENET_RX_RING_LEN]; /**< RX pbuf pointer list, zero-copy mode */
robert_jw 0:b2805b6888dc 47 uint8_t *rx_desc_start_addr; /**< RX descriptor start address */
robert_jw 0:b2805b6888dc 48 uint8_t *tx_desc_start_addr; /**< TX descriptor start address */
robert_jw 0:b2805b6888dc 49 uint8_t tx_consume_index, tx_produce_index; /**< TX buffers ring */
robert_jw 0:b2805b6888dc 50 uint8_t rx_fill_index; /**< RX ring fill index */
robert_jw 0:b2805b6888dc 51 struct pbuf *txb[ENET_TX_RING_LEN]; /**< TX pbuf pointer list, zero-copy mode */
robert_jw 0:b2805b6888dc 52 void *txb_aligned[ENET_TX_RING_LEN]; /**< TX aligned buffers (if needed) */
robert_jw 0:b2805b6888dc 53 };
robert_jw 0:b2805b6888dc 54
robert_jw 0:b2805b6888dc 55 static struct k64f_enetdata k64f_enetdata;
robert_jw 0:b2805b6888dc 56
robert_jw 0:b2805b6888dc 57 static enet_dev_if_t enetDevIf[HW_ENET_INSTANCE_COUNT];
robert_jw 0:b2805b6888dc 58 static enet_mac_config_t g_enetMacCfg[HW_ENET_INSTANCE_COUNT] =
robert_jw 0:b2805b6888dc 59 {
robert_jw 0:b2805b6888dc 60 {
robert_jw 0:b2805b6888dc 61 ENET_ETH_MAX_FLEN , /*!< enet receive buffer size*/
robert_jw 0:b2805b6888dc 62 ENET_RX_LARGE_BUFFER_NUM, /*!< enet large receive buffer number*/
robert_jw 0:b2805b6888dc 63 ENET_RX_RING_LEN, /*!< enet receive bd number*/
robert_jw 0:b2805b6888dc 64 ENET_TX_RING_LEN, /*!< enet transmit bd number*/
robert_jw 0:b2805b6888dc 65 {0}, /*!< enet mac address*/
robert_jw 0:b2805b6888dc 66 kEnetCfgRmii, /*!< enet rmii interface*/
robert_jw 0:b2805b6888dc 67 kEnetCfgSpeed100M, /*!< enet rmii 100M*/
robert_jw 0:b2805b6888dc 68 kEnetCfgFullDuplex, /*!< enet rmii Full- duplex*/
robert_jw 0:b2805b6888dc 69 /*!< enet mac control flag recommended to use enet_mac_control_flag_t
robert_jw 0:b2805b6888dc 70 we send frame with crc so receive crc forward for data length check test*/
robert_jw 0:b2805b6888dc 71 kEnetRxCrcFwdEnable | kEnetRxFlowControlEnable,
robert_jw 0:b2805b6888dc 72 true, /*!< enet txaccelerator enabled*/
robert_jw 0:b2805b6888dc 73 true, /*!< enet rxaccelerator enabled*/
robert_jw 0:b2805b6888dc 74 false, /*!< enet store and forward*/
robert_jw 0:b2805b6888dc 75 {false, false, true, false, true}, /*!< enet rxaccelerator config*/
robert_jw 0:b2805b6888dc 76 {false, false, true}, /*!< enet txaccelerator config*/
robert_jw 0:b2805b6888dc 77 true, /*!< vlan frame support*/
robert_jw 0:b2805b6888dc 78 true, /*!< phy auto discover*/
robert_jw 0:b2805b6888dc 79 ENET_MII_CLOCK, /*!< enet MDC clock*/
robert_jw 0:b2805b6888dc 80 },
robert_jw 0:b2805b6888dc 81 };
robert_jw 0:b2805b6888dc 82
robert_jw 0:b2805b6888dc 83 static enet_phy_config_t g_enetPhyCfg[HW_ENET_INSTANCE_COUNT] =
robert_jw 0:b2805b6888dc 84 {
robert_jw 0:b2805b6888dc 85 {0, false}
robert_jw 0:b2805b6888dc 86 };
robert_jw 0:b2805b6888dc 87
robert_jw 0:b2805b6888dc 88 /** \brief Driver transmit and receive thread priorities
robert_jw 0:b2805b6888dc 89 *
robert_jw 0:b2805b6888dc 90 * Thread priorities for receive thread and TX cleanup thread. Alter
robert_jw 0:b2805b6888dc 91 * to prioritize receive or transmit bandwidth. In a heavily loaded
robert_jw 0:b2805b6888dc 92 * system or with LEIP_DEBUG enabled, the priorities might be better
robert_jw 0:b2805b6888dc 93 * the same. */
robert_jw 0:b2805b6888dc 94 #define RX_PRIORITY (osPriorityNormal)
robert_jw 0:b2805b6888dc 95 #define TX_PRIORITY (osPriorityNormal)
robert_jw 0:b2805b6888dc 96 #define PHY_PRIORITY (osPriorityNormal)
robert_jw 0:b2805b6888dc 97
robert_jw 0:b2805b6888dc 98 /** \brief Debug output formatter lock define
robert_jw 0:b2805b6888dc 99 *
robert_jw 0:b2805b6888dc 100 * When using FreeRTOS and with LWIP_DEBUG enabled, enabling this
robert_jw 0:b2805b6888dc 101 * define will allow RX debug messages to not interleave with the
robert_jw 0:b2805b6888dc 102 * TX messages (so they are actually readable). Not enabling this
robert_jw 0:b2805b6888dc 103 * define when the system is under load will cause the output to
robert_jw 0:b2805b6888dc 104 * be unreadable. There is a small tradeoff in performance for this
robert_jw 0:b2805b6888dc 105 * so use it only for debug. */
robert_jw 0:b2805b6888dc 106 //#define LOCK_RX_THREAD
robert_jw 0:b2805b6888dc 107
robert_jw 0:b2805b6888dc 108 /** \brief Signal used for ethernet ISR to signal packet_rx() thread.
robert_jw 0:b2805b6888dc 109 */
robert_jw 0:b2805b6888dc 110 #define RX_SIGNAL 1
robert_jw 0:b2805b6888dc 111
robert_jw 0:b2805b6888dc 112 // K64F-specific macros
robert_jw 0:b2805b6888dc 113 #define RX_PBUF_AUTO_INDEX (-1)
robert_jw 0:b2805b6888dc 114
robert_jw 0:b2805b6888dc 115 /********************************************************************************
robert_jw 0:b2805b6888dc 116 * Buffer management
robert_jw 0:b2805b6888dc 117 ********************************************************************************/
robert_jw 0:b2805b6888dc 118
robert_jw 0:b2805b6888dc 119 /** \brief Queues a pbuf into the RX descriptor list
robert_jw 0:b2805b6888dc 120 *
robert_jw 0:b2805b6888dc 121 * \param[in] k64f_enet Pointer to the drvier data structure
robert_jw 0:b2805b6888dc 122 * \param[in] p Pointer to pbuf to queue
robert_jw 0:b2805b6888dc 123 * \param[in] bidx Index to queue into
robert_jw 0:b2805b6888dc 124 */
robert_jw 0:b2805b6888dc 125 static void k64f_rxqueue_pbuf(struct k64f_enetdata *k64f_enet, struct pbuf *p, int bidx)
robert_jw 0:b2805b6888dc 126 {
robert_jw 0:b2805b6888dc 127 enet_bd_struct_t *start = (enet_bd_struct_t *)k64f_enet->rx_desc_start_addr;
robert_jw 0:b2805b6888dc 128 int idx;
robert_jw 0:b2805b6888dc 129
robert_jw 0:b2805b6888dc 130 /* Get next free descriptor index */
robert_jw 0:b2805b6888dc 131 if (bidx == RX_PBUF_AUTO_INDEX)
robert_jw 0:b2805b6888dc 132 idx = k64f_enet->rx_fill_index;
robert_jw 0:b2805b6888dc 133 else
robert_jw 0:b2805b6888dc 134 idx = bidx;
robert_jw 0:b2805b6888dc 135
robert_jw 0:b2805b6888dc 136 /* Setup descriptor and clear statuses */
robert_jw 0:b2805b6888dc 137 enet_hal_init_rxbds(start + idx, (uint8_t*)p->payload, idx == ENET_RX_RING_LEN - 1);
robert_jw 0:b2805b6888dc 138
robert_jw 0:b2805b6888dc 139 /* Save pbuf pointer for push to network layer later */
robert_jw 0:b2805b6888dc 140 k64f_enet->rxb[idx] = p;
robert_jw 0:b2805b6888dc 141
robert_jw 0:b2805b6888dc 142 /* Wrap at end of descriptor list */
robert_jw 0:b2805b6888dc 143 idx = (idx + 1) % ENET_RX_RING_LEN;
robert_jw 0:b2805b6888dc 144
robert_jw 0:b2805b6888dc 145 /* Queue descriptor(s) */
robert_jw 0:b2805b6888dc 146 k64f_enet->rx_free_descs -= 1;
robert_jw 0:b2805b6888dc 147
robert_jw 0:b2805b6888dc 148 if (bidx == RX_PBUF_AUTO_INDEX)
robert_jw 0:b2805b6888dc 149 k64f_enet->rx_fill_index = idx;
robert_jw 0:b2805b6888dc 150
robert_jw 0:b2805b6888dc 151 enet_hal_active_rxbd(BOARD_DEBUG_ENET_INSTANCE_ADDR);
robert_jw 0:b2805b6888dc 152
robert_jw 0:b2805b6888dc 153 LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
robert_jw 0:b2805b6888dc 154 ("k64f_rxqueue_pbuf: pbuf packet queued: %p (free desc=%d)\n", p,
robert_jw 0:b2805b6888dc 155 k64f_enet->rx_free_descs));
robert_jw 0:b2805b6888dc 156 }
robert_jw 0:b2805b6888dc 157
robert_jw 0:b2805b6888dc 158 /** \brief Attempt to allocate and requeue a new pbuf for RX
robert_jw 0:b2805b6888dc 159 *
robert_jw 0:b2805b6888dc 160 * \param[in] netif Pointer to the netif structure
robert_jw 0:b2805b6888dc 161 * \returns number of queued packets
robert_jw 0:b2805b6888dc 162 */
robert_jw 0:b2805b6888dc 163 s32_t k64f_rx_queue(struct netif *netif, int idx)
robert_jw 0:b2805b6888dc 164 {
robert_jw 0:b2805b6888dc 165 struct k64f_enetdata *k64f_enet = netif->state;
robert_jw 0:b2805b6888dc 166 enet_dev_if_t *enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
robert_jw 0:b2805b6888dc 167 struct pbuf *p;
robert_jw 0:b2805b6888dc 168 int queued = 0;
robert_jw 0:b2805b6888dc 169
robert_jw 0:b2805b6888dc 170 /* Attempt to requeue as many packets as possible */
robert_jw 0:b2805b6888dc 171 while (k64f_enet->rx_free_descs > 0) {
robert_jw 0:b2805b6888dc 172 /* Allocate a pbuf from the pool. We need to allocate at the
robert_jw 0:b2805b6888dc 173 maximum size as we don't know the size of the yet to be
robert_jw 0:b2805b6888dc 174 received packet. */
robert_jw 0:b2805b6888dc 175 p = pbuf_alloc(PBUF_RAW, enetIfPtr->macCfgPtr->rxBufferSize + RX_BUF_ALIGNMENT, PBUF_RAM);
robert_jw 0:b2805b6888dc 176 if (p == NULL) {
robert_jw 0:b2805b6888dc 177 LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
robert_jw 0:b2805b6888dc 178 ("k64_rx_queue: could not allocate RX pbuf (free desc=%d)\n",
robert_jw 0:b2805b6888dc 179 k64f_enet->rx_free_descs));
robert_jw 0:b2805b6888dc 180 return queued;
robert_jw 0:b2805b6888dc 181 }
robert_jw 0:b2805b6888dc 182 /* K64F note: the next line ensures that the RX buffer is properly aligned for the K64F
robert_jw 0:b2805b6888dc 183 RX descriptors (16 bytes alignment). However, by doing so, we're effectively changing
robert_jw 0:b2805b6888dc 184 a data structure which is internal to lwIP. This might not prove to be a good idea
robert_jw 0:b2805b6888dc 185 in the long run, but a better fix would probably involve modifying lwIP itself */
robert_jw 0:b2805b6888dc 186 p->payload = (void*)ENET_ALIGN((uint32_t)p->payload, RX_BUF_ALIGNMENT);
robert_jw 0:b2805b6888dc 187
robert_jw 0:b2805b6888dc 188 /* pbufs allocated from the RAM pool should be non-chained. */
robert_jw 0:b2805b6888dc 189 LWIP_ASSERT("k64f_rx_queue: pbuf is not contiguous (chained)", pbuf_clen(p) <= 1);
robert_jw 0:b2805b6888dc 190
robert_jw 0:b2805b6888dc 191 /* Queue packet */
robert_jw 0:b2805b6888dc 192 k64f_rxqueue_pbuf(k64f_enet, p, idx);
robert_jw 0:b2805b6888dc 193 queued++;
robert_jw 0:b2805b6888dc 194 }
robert_jw 0:b2805b6888dc 195
robert_jw 0:b2805b6888dc 196 return queued;
robert_jw 0:b2805b6888dc 197 }
robert_jw 0:b2805b6888dc 198
robert_jw 0:b2805b6888dc 199 /** \brief Sets up the RX descriptor ring buffers.
robert_jw 0:b2805b6888dc 200 *
robert_jw 0:b2805b6888dc 201 * This function sets up the descriptor list used for receive packets.
robert_jw 0:b2805b6888dc 202 *
robert_jw 0:b2805b6888dc 203 * \param[in] netif Pointer to driver data structure
robert_jw 0:b2805b6888dc 204 * \returns ERR_MEM if out of memory, ERR_OK otherwise
robert_jw 0:b2805b6888dc 205 */
robert_jw 0:b2805b6888dc 206 static err_t k64f_rx_setup(struct netif *netif, enet_rxbd_config_t *rxbdCfg) {
robert_jw 0:b2805b6888dc 207 struct k64f_enetdata *k64f_enet = netif->state;
robert_jw 0:b2805b6888dc 208 enet_dev_if_t *enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
robert_jw 0:b2805b6888dc 209 uint8_t *rxBdPtr;
robert_jw 0:b2805b6888dc 210 uint32_t rxBufferSizeAligned;
robert_jw 0:b2805b6888dc 211
robert_jw 0:b2805b6888dc 212 // Allocate RX descriptors
robert_jw 0:b2805b6888dc 213 rxBdPtr = (uint8_t *)calloc(1, enet_hal_get_bd_size() * enetIfPtr->macCfgPtr->rxBdNumber + ENET_BD_ALIGNMENT);
robert_jw 0:b2805b6888dc 214 if(!rxBdPtr)
robert_jw 0:b2805b6888dc 215 return ERR_MEM;
robert_jw 0:b2805b6888dc 216 k64f_enet->rx_desc_start_addr = (uint8_t *)ENET_ALIGN((uint32_t)rxBdPtr, ENET_BD_ALIGNMENT);
robert_jw 0:b2805b6888dc 217 k64f_enet->rx_free_descs = enetIfPtr->macCfgPtr->rxBdNumber;
robert_jw 0:b2805b6888dc 218 k64f_enet->rx_fill_index = 0;
robert_jw 0:b2805b6888dc 219
robert_jw 0:b2805b6888dc 220 rxBufferSizeAligned = ENET_ALIGN(enetIfPtr->macCfgPtr->rxBufferSize, ENET_RX_BUFFER_ALIGNMENT);
robert_jw 0:b2805b6888dc 221 enetIfPtr->macContextPtr->rxBufferSizeAligned = rxBufferSizeAligned;
robert_jw 0:b2805b6888dc 222 rxbdCfg->rxBdPtrAlign = k64f_enet->rx_desc_start_addr;
robert_jw 0:b2805b6888dc 223 rxbdCfg->rxBdNum = enetIfPtr->macCfgPtr->rxBdNumber;
robert_jw 0:b2805b6888dc 224 rxbdCfg->rxBufferNum = enetIfPtr->macCfgPtr->rxBdNumber;
robert_jw 0:b2805b6888dc 225
robert_jw 0:b2805b6888dc 226 k64f_rx_queue(netif, RX_PBUF_AUTO_INDEX);
robert_jw 0:b2805b6888dc 227 return ERR_OK;
robert_jw 0:b2805b6888dc 228 }
robert_jw 0:b2805b6888dc 229
robert_jw 0:b2805b6888dc 230 /** \brief Sets up the TX descriptor ring buffers.
robert_jw 0:b2805b6888dc 231 *
robert_jw 0:b2805b6888dc 232 * This function sets up the descriptor list used for transmit packets.
robert_jw 0:b2805b6888dc 233 *
robert_jw 0:b2805b6888dc 234 * \param[in] netif Pointer to driver data structure
robert_jw 0:b2805b6888dc 235 * \returns ERR_MEM if out of memory, ERR_OK otherwise
robert_jw 0:b2805b6888dc 236 */
robert_jw 0:b2805b6888dc 237 static err_t k64f_tx_setup(struct netif *netif, enet_txbd_config_t *txbdCfg) {
robert_jw 0:b2805b6888dc 238 struct k64f_enetdata *k64f_enet = netif->state;
robert_jw 0:b2805b6888dc 239 enet_dev_if_t *enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
robert_jw 0:b2805b6888dc 240 uint8_t *txBdPtr;
robert_jw 0:b2805b6888dc 241
robert_jw 0:b2805b6888dc 242 // Allocate TX descriptors
robert_jw 0:b2805b6888dc 243 txBdPtr = (uint8_t *)calloc(1, enet_hal_get_bd_size() * enetIfPtr->macCfgPtr->txBdNumber + ENET_BD_ALIGNMENT);
robert_jw 0:b2805b6888dc 244 if(!txBdPtr)
robert_jw 0:b2805b6888dc 245 return ERR_MEM;
robert_jw 0:b2805b6888dc 246
robert_jw 0:b2805b6888dc 247 k64f_enet->tx_desc_start_addr = (uint8_t *)ENET_ALIGN((uint32_t)txBdPtr, ENET_BD_ALIGNMENT);
robert_jw 0:b2805b6888dc 248 k64f_enet->tx_consume_index = k64f_enet->tx_produce_index = 0;
robert_jw 0:b2805b6888dc 249
robert_jw 0:b2805b6888dc 250 txbdCfg->txBdPtrAlign = k64f_enet->tx_desc_start_addr;
robert_jw 0:b2805b6888dc 251 txbdCfg->txBufferNum = enetIfPtr->macCfgPtr->txBdNumber;
robert_jw 0:b2805b6888dc 252 txbdCfg->txBufferSizeAlign = ENET_ALIGN(enetIfPtr->maxFrameSize, ENET_TX_BUFFER_ALIGNMENT);
robert_jw 0:b2805b6888dc 253
robert_jw 0:b2805b6888dc 254 // Make the TX descriptor ring circular
robert_jw 0:b2805b6888dc 255 enet_hal_init_txbds(k64f_enet->tx_desc_start_addr + enet_hal_get_bd_size() * (ENET_TX_RING_LEN - 1), 1);
robert_jw 0:b2805b6888dc 256
robert_jw 0:b2805b6888dc 257 return ERR_OK;
robert_jw 0:b2805b6888dc 258 }
robert_jw 0:b2805b6888dc 259
robert_jw 0:b2805b6888dc 260 /** \brief Free TX buffers that are complete
robert_jw 0:b2805b6888dc 261 *
robert_jw 0:b2805b6888dc 262 * \param[in] k64f_enet Pointer to driver data structure
robert_jw 0:b2805b6888dc 263 */
robert_jw 0:b2805b6888dc 264 static void k64f_tx_reclaim(struct k64f_enetdata *k64f_enet)
robert_jw 0:b2805b6888dc 265 {
robert_jw 0:b2805b6888dc 266 uint8_t i;
robert_jw 0:b2805b6888dc 267 volatile enet_bd_struct_t * bdPtr = (enet_bd_struct_t *)k64f_enet->tx_desc_start_addr;
robert_jw 0:b2805b6888dc 268
robert_jw 0:b2805b6888dc 269 /* Get exclusive access */
robert_jw 0:b2805b6888dc 270 sys_mutex_lock(&k64f_enet->TXLockMutex);
robert_jw 0:b2805b6888dc 271
robert_jw 0:b2805b6888dc 272 // Traverse all descriptors, looking for the ones modified by the uDMA
robert_jw 0:b2805b6888dc 273 i = k64f_enet->tx_consume_index;
robert_jw 0:b2805b6888dc 274 while(i != k64f_enet->tx_produce_index && !(bdPtr[i].control & kEnetTxBdReady)) {
robert_jw 0:b2805b6888dc 275 if (k64f_enet->txb_aligned[i]) {
robert_jw 0:b2805b6888dc 276 free(k64f_enet->txb_aligned[i]);
robert_jw 0:b2805b6888dc 277 k64f_enet->txb_aligned[i] = NULL;
robert_jw 0:b2805b6888dc 278 } else if (k64f_enet->txb[i]) {
robert_jw 0:b2805b6888dc 279 pbuf_free(k64f_enet->txb[i]);
robert_jw 0:b2805b6888dc 280 k64f_enet->txb[i] = NULL;
robert_jw 0:b2805b6888dc 281 }
robert_jw 0:b2805b6888dc 282 osSemaphoreRelease(k64f_enet->xTXDCountSem.id);
robert_jw 0:b2805b6888dc 283 bdPtr[i].controlExtend2 &= ~TX_DESC_UPDATED_MASK;
robert_jw 0:b2805b6888dc 284 i = (i + 1) % ENET_TX_RING_LEN;
robert_jw 0:b2805b6888dc 285 }
robert_jw 0:b2805b6888dc 286 k64f_enet->tx_consume_index = i;
robert_jw 0:b2805b6888dc 287
robert_jw 0:b2805b6888dc 288 /* Restore access */
robert_jw 0:b2805b6888dc 289 sys_mutex_unlock(&k64f_enet->TXLockMutex);
robert_jw 0:b2805b6888dc 290 }
robert_jw 0:b2805b6888dc 291
robert_jw 0:b2805b6888dc 292 /** \brief Low level init of the MAC and PHY.
robert_jw 0:b2805b6888dc 293 *
robert_jw 0:b2805b6888dc 294 * \param[in] netif Pointer to LWIP netif structure
robert_jw 0:b2805b6888dc 295 */
robert_jw 0:b2805b6888dc 296 static err_t low_level_init(struct netif *netif)
robert_jw 0:b2805b6888dc 297 {
robert_jw 0:b2805b6888dc 298 enet_dev_if_t * enetIfPtr;
robert_jw 0:b2805b6888dc 299 uint32_t device = BOARD_DEBUG_ENET_INSTANCE_ADDR;
robert_jw 0:b2805b6888dc 300 enet_rxbd_config_t rxbdCfg;
robert_jw 0:b2805b6888dc 301 enet_txbd_config_t txbdCfg;
robert_jw 0:b2805b6888dc 302 enet_phy_speed_t phy_speed;
robert_jw 0:b2805b6888dc 303 enet_phy_duplex_t phy_duplex;
robert_jw 0:b2805b6888dc 304
robert_jw 0:b2805b6888dc 305 k64f_init_eth_hardware();
robert_jw 0:b2805b6888dc 306
robert_jw 0:b2805b6888dc 307 /* Initialize device*/
robert_jw 0:b2805b6888dc 308 enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
robert_jw 0:b2805b6888dc 309 enetIfPtr->deviceNumber = device;
robert_jw 0:b2805b6888dc 310 enetIfPtr->macCfgPtr = &g_enetMacCfg[BOARD_DEBUG_ENET_INSTANCE];
robert_jw 0:b2805b6888dc 311 enetIfPtr->phyCfgPtr = &g_enetPhyCfg[BOARD_DEBUG_ENET_INSTANCE];
robert_jw 0:b2805b6888dc 312 enetIfPtr->macApiPtr = &g_enetMacApi;
robert_jw 0:b2805b6888dc 313 enetIfPtr->phyApiPtr = (void *)&g_enetPhyApi;
robert_jw 0:b2805b6888dc 314 memcpy(enetIfPtr->macCfgPtr->macAddr, (char*)netif->hwaddr, kEnetMacAddrLen);
robert_jw 0:b2805b6888dc 315
robert_jw 0:b2805b6888dc 316 /* Allocate buffer for ENET mac context*/
robert_jw 0:b2805b6888dc 317 enetIfPtr->macContextPtr = (enet_mac_context_t *)calloc(1, sizeof(enet_mac_context_t));
robert_jw 0:b2805b6888dc 318 if (!enetIfPtr->macContextPtr) {
robert_jw 0:b2805b6888dc 319 return ERR_BUF;
robert_jw 0:b2805b6888dc 320 }
robert_jw 0:b2805b6888dc 321
robert_jw 0:b2805b6888dc 322 /* Initialize enet buffers*/
robert_jw 0:b2805b6888dc 323 if(k64f_rx_setup(netif, &rxbdCfg) != ERR_OK) {
robert_jw 0:b2805b6888dc 324 return ERR_BUF;
robert_jw 0:b2805b6888dc 325 }
robert_jw 0:b2805b6888dc 326 /* Initialize enet buffers*/
robert_jw 0:b2805b6888dc 327 if(k64f_tx_setup(netif, &txbdCfg) != ERR_OK) {
robert_jw 0:b2805b6888dc 328 return ERR_BUF;
robert_jw 0:b2805b6888dc 329 }
robert_jw 0:b2805b6888dc 330 /* Initialize enet module*/
robert_jw 0:b2805b6888dc 331 if (enet_mac_init(enetIfPtr, &rxbdCfg, &txbdCfg) == kStatus_ENET_Success)
robert_jw 0:b2805b6888dc 332 {
robert_jw 0:b2805b6888dc 333 /* Initialize PHY*/
robert_jw 0:b2805b6888dc 334 if (enetIfPtr->macCfgPtr->isPhyAutoDiscover) {
robert_jw 0:b2805b6888dc 335 if (((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_auto_discover(enetIfPtr) != kStatus_PHY_Success)
robert_jw 0:b2805b6888dc 336 return ERR_IF;
robert_jw 0:b2805b6888dc 337 }
robert_jw 0:b2805b6888dc 338 if (((enet_phy_api_t *)(enetIfPtr->phyApiPtr))->phy_init(enetIfPtr) != kStatus_PHY_Success)
robert_jw 0:b2805b6888dc 339 return ERR_IF;
robert_jw 0:b2805b6888dc 340
robert_jw 0:b2805b6888dc 341 enetIfPtr->isInitialized = true;
robert_jw 0:b2805b6888dc 342 }
robert_jw 0:b2805b6888dc 343 else
robert_jw 0:b2805b6888dc 344 {
robert_jw 0:b2805b6888dc 345 // TODOETH: cleanup memory
robert_jw 0:b2805b6888dc 346 return ERR_IF;
robert_jw 0:b2805b6888dc 347 }
robert_jw 0:b2805b6888dc 348
robert_jw 0:b2805b6888dc 349 /* Get link information from PHY */
robert_jw 0:b2805b6888dc 350 phy_get_link_speed(enetIfPtr, &phy_speed);
robert_jw 0:b2805b6888dc 351 phy_get_link_duplex(enetIfPtr, &phy_duplex);
robert_jw 0:b2805b6888dc 352 BW_ENET_RCR_RMII_10T(enetIfPtr->deviceNumber, phy_speed == kEnetSpeed10M ? kEnetCfgSpeed10M : kEnetCfgSpeed100M);
robert_jw 0:b2805b6888dc 353 BW_ENET_TCR_FDEN(enetIfPtr->deviceNumber, phy_duplex == kEnetFullDuplex ? kEnetCfgFullDuplex : kEnetCfgHalfDuplex);
robert_jw 0:b2805b6888dc 354
robert_jw 0:b2805b6888dc 355 /* Enable Ethernet module*/
robert_jw 0:b2805b6888dc 356 enet_hal_config_ethernet(BOARD_DEBUG_ENET_INSTANCE_ADDR, true, true);
robert_jw 0:b2805b6888dc 357
robert_jw 0:b2805b6888dc 358 /* Active Receive buffer descriptor must be done after module enable*/
robert_jw 0:b2805b6888dc 359 enet_hal_active_rxbd(enetIfPtr->deviceNumber);
robert_jw 0:b2805b6888dc 360
robert_jw 0:b2805b6888dc 361 return ERR_OK;
robert_jw 0:b2805b6888dc 362 }
robert_jw 0:b2805b6888dc 363
robert_jw 0:b2805b6888dc 364 /********************************************************************************
robert_jw 0:b2805b6888dc 365 * LWIP port
robert_jw 0:b2805b6888dc 366 ********************************************************************************/
robert_jw 0:b2805b6888dc 367
robert_jw 0:b2805b6888dc 368 /** \brief Ethernet receive interrupt handler
robert_jw 0:b2805b6888dc 369 *
robert_jw 0:b2805b6888dc 370 * This function handles the receive interrupt of K64F.
robert_jw 0:b2805b6888dc 371 */
robert_jw 0:b2805b6888dc 372 void enet_mac_rx_isr(void *enetIfPtr)
robert_jw 0:b2805b6888dc 373 {
robert_jw 0:b2805b6888dc 374 /* Clear interrupt */
robert_jw 0:b2805b6888dc 375 enet_hal_clear_interrupt(((enet_dev_if_t *)enetIfPtr)->deviceNumber, kEnetRxFrameInterrupt);
robert_jw 0:b2805b6888dc 376 sys_sem_signal(&k64f_enetdata.RxReadySem);
robert_jw 0:b2805b6888dc 377 }
robert_jw 0:b2805b6888dc 378
robert_jw 0:b2805b6888dc 379 void enet_mac_tx_isr(void *enetIfPtr)
robert_jw 0:b2805b6888dc 380 {
robert_jw 0:b2805b6888dc 381 /*Clear interrupt*/
robert_jw 0:b2805b6888dc 382 enet_hal_clear_interrupt(((enet_dev_if_t *)enetIfPtr)->deviceNumber, kEnetTxFrameInterrupt);
robert_jw 0:b2805b6888dc 383 sys_sem_signal(&k64f_enetdata.TxCleanSem);
robert_jw 0:b2805b6888dc 384 }
robert_jw 0:b2805b6888dc 385
robert_jw 0:b2805b6888dc 386 /**
robert_jw 0:b2805b6888dc 387 * This function is the ethernet packet send function. It calls
robert_jw 0:b2805b6888dc 388 * etharp_output after checking link status.
robert_jw 0:b2805b6888dc 389 *
robert_jw 0:b2805b6888dc 390 * \param[in] netif the lwip network interface structure for this enetif
robert_jw 0:b2805b6888dc 391 * \param[in] q Pointer to pbug to send
robert_jw 0:b2805b6888dc 392 * \param[in] ipaddr IP address
robert_jw 0:b2805b6888dc 393 * \return ERR_OK or error code
robert_jw 0:b2805b6888dc 394 */
robert_jw 0:b2805b6888dc 395 err_t k64f_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)
robert_jw 0:b2805b6888dc 396 {
robert_jw 0:b2805b6888dc 397 /* Only send packet is link is up */
robert_jw 0:b2805b6888dc 398 if (netif->flags & NETIF_FLAG_LINK_UP)
robert_jw 0:b2805b6888dc 399 return etharp_output(netif, q, ipaddr);
robert_jw 0:b2805b6888dc 400
robert_jw 0:b2805b6888dc 401 return ERR_CONN;
robert_jw 0:b2805b6888dc 402 }
robert_jw 0:b2805b6888dc 403
robert_jw 0:b2805b6888dc 404 /** \brief Allocates a pbuf and returns the data from the incoming packet.
robert_jw 0:b2805b6888dc 405 *
robert_jw 0:b2805b6888dc 406 * \param[in] netif the lwip network interface structure
robert_jw 0:b2805b6888dc 407 * \param[in] idx index of packet to be read
robert_jw 0:b2805b6888dc 408 * \return a pbuf filled with the received packet (including MAC header)
robert_jw 0:b2805b6888dc 409 */
robert_jw 0:b2805b6888dc 410 static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
robert_jw 0:b2805b6888dc 411 {
robert_jw 0:b2805b6888dc 412 struct k64f_enetdata *k64f_enet = netif->state;
robert_jw 0:b2805b6888dc 413 enet_bd_struct_t * bdPtr = (enet_bd_struct_t*)k64f_enet->rx_desc_start_addr;
robert_jw 0:b2805b6888dc 414 struct pbuf *p = NULL;
robert_jw 0:b2805b6888dc 415 u32_t length = 0, orig_length;
robert_jw 0:b2805b6888dc 416 const u16_t err_mask = kEnetRxBdTrunc | kEnetRxBdCrc | kEnetRxBdNoOctet | kEnetRxBdLengthViolation;
robert_jw 0:b2805b6888dc 417
robert_jw 0:b2805b6888dc 418 #ifdef LOCK_RX_THREAD
robert_jw 0:b2805b6888dc 419 /* Get exclusive access */
robert_jw 0:b2805b6888dc 420 sys_mutex_lock(&k64f_enet->TXLockMutex);
robert_jw 0:b2805b6888dc 421 #endif
robert_jw 0:b2805b6888dc 422
robert_jw 0:b2805b6888dc 423 /* Determine if a frame has been received */
robert_jw 0:b2805b6888dc 424 if ((bdPtr[idx].control & err_mask) != 0) {
robert_jw 0:b2805b6888dc 425 #if LINK_STATS
robert_jw 0:b2805b6888dc 426 if ((bdPtr[idx].control & kEnetRxBdLengthViolation) != 0)
robert_jw 0:b2805b6888dc 427 LINK_STATS_INC(link.lenerr);
robert_jw 0:b2805b6888dc 428 else
robert_jw 0:b2805b6888dc 429 LINK_STATS_INC(link.chkerr);
robert_jw 0:b2805b6888dc 430 #endif
robert_jw 0:b2805b6888dc 431 LINK_STATS_INC(link.drop);
robert_jw 0:b2805b6888dc 432
robert_jw 0:b2805b6888dc 433 /* Re-queue the same buffer */
robert_jw 0:b2805b6888dc 434 k64f_enet->rx_free_descs++;
robert_jw 0:b2805b6888dc 435 p = k64f_enet->rxb[idx];
robert_jw 0:b2805b6888dc 436 k64f_enet->rxb[idx] = NULL;
robert_jw 0:b2805b6888dc 437 k64f_rxqueue_pbuf(k64f_enet, p, idx);
robert_jw 0:b2805b6888dc 438 p = NULL;
robert_jw 0:b2805b6888dc 439 } else {
robert_jw 0:b2805b6888dc 440 /* A packet is waiting, get length */
robert_jw 0:b2805b6888dc 441 length = enet_hal_get_bd_length(bdPtr + idx);
robert_jw 0:b2805b6888dc 442
robert_jw 0:b2805b6888dc 443 /* Zero-copy */
robert_jw 0:b2805b6888dc 444 p = k64f_enet->rxb[idx];
robert_jw 0:b2805b6888dc 445 orig_length = p->len;
robert_jw 0:b2805b6888dc 446 p->len = (u16_t) length;
robert_jw 0:b2805b6888dc 447
robert_jw 0:b2805b6888dc 448 /* Free pbuf from descriptor */
robert_jw 0:b2805b6888dc 449 k64f_enet->rxb[idx] = NULL;
robert_jw 0:b2805b6888dc 450 k64f_enet->rx_free_descs++;
robert_jw 0:b2805b6888dc 451
robert_jw 0:b2805b6888dc 452 /* Attempt to queue new buffer */
robert_jw 0:b2805b6888dc 453 if (k64f_rx_queue(netif, idx) == 0) {
robert_jw 0:b2805b6888dc 454 /* Drop frame (out of memory) */
robert_jw 0:b2805b6888dc 455 LINK_STATS_INC(link.drop);
robert_jw 0:b2805b6888dc 456
robert_jw 0:b2805b6888dc 457 /* Re-queue the same buffer */
robert_jw 0:b2805b6888dc 458 p->len = orig_length;
robert_jw 0:b2805b6888dc 459 k64f_rxqueue_pbuf(k64f_enet, p, idx);
robert_jw 0:b2805b6888dc 460
robert_jw 0:b2805b6888dc 461 LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
robert_jw 0:b2805b6888dc 462 ("k64f_low_level_input: Packet index %d dropped for OOM\n",
robert_jw 0:b2805b6888dc 463 idx));
robert_jw 0:b2805b6888dc 464 #ifdef LOCK_RX_THREAD
robert_jw 0:b2805b6888dc 465 sys_mutex_unlock(&k64f_enet->TXLockMutex);
robert_jw 0:b2805b6888dc 466 #endif
robert_jw 0:b2805b6888dc 467
robert_jw 0:b2805b6888dc 468 return NULL;
robert_jw 0:b2805b6888dc 469 }
robert_jw 0:b2805b6888dc 470
robert_jw 0:b2805b6888dc 471 LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
robert_jw 0:b2805b6888dc 472 ("k64f_low_level_input: Packet received: %p, size %d (index=%d)\n",
robert_jw 0:b2805b6888dc 473 p, length, idx));
robert_jw 0:b2805b6888dc 474
robert_jw 0:b2805b6888dc 475 /* Save size */
robert_jw 0:b2805b6888dc 476 p->tot_len = (u16_t) length;
robert_jw 0:b2805b6888dc 477 LINK_STATS_INC(link.recv);
robert_jw 0:b2805b6888dc 478 }
robert_jw 0:b2805b6888dc 479
robert_jw 0:b2805b6888dc 480 #ifdef LOCK_RX_THREAD
robert_jw 0:b2805b6888dc 481 sys_mutex_unlock(&k64f_enet->TXLockMutex);
robert_jw 0:b2805b6888dc 482 #endif
robert_jw 0:b2805b6888dc 483
robert_jw 0:b2805b6888dc 484 return p;
robert_jw 0:b2805b6888dc 485 }
robert_jw 0:b2805b6888dc 486
robert_jw 0:b2805b6888dc 487 /** \brief Attempt to read a packet from the EMAC interface.
robert_jw 0:b2805b6888dc 488 *
robert_jw 0:b2805b6888dc 489 * \param[in] netif the lwip network interface structure
robert_jw 0:b2805b6888dc 490 * \param[in] idx index of packet to be read
robert_jw 0:b2805b6888dc 491 */
robert_jw 0:b2805b6888dc 492 void k64f_enetif_input(struct netif *netif, int idx)
robert_jw 0:b2805b6888dc 493 {
robert_jw 0:b2805b6888dc 494 struct eth_hdr *ethhdr;
robert_jw 0:b2805b6888dc 495 struct pbuf *p;
robert_jw 0:b2805b6888dc 496
robert_jw 0:b2805b6888dc 497 /* move received packet into a new pbuf */
robert_jw 0:b2805b6888dc 498 p = k64f_low_level_input(netif, idx);
robert_jw 0:b2805b6888dc 499 if (p == NULL)
robert_jw 0:b2805b6888dc 500 return;
robert_jw 0:b2805b6888dc 501
robert_jw 0:b2805b6888dc 502 /* points to packet payload, which starts with an Ethernet header */
robert_jw 0:b2805b6888dc 503 ethhdr = (struct eth_hdr*)p->payload;
robert_jw 0:b2805b6888dc 504
robert_jw 0:b2805b6888dc 505 switch (htons(ethhdr->type)) {
robert_jw 0:b2805b6888dc 506 case ETHTYPE_IP:
robert_jw 0:b2805b6888dc 507 case ETHTYPE_ARP:
robert_jw 0:b2805b6888dc 508 #if PPPOE_SUPPORT
robert_jw 0:b2805b6888dc 509 case ETHTYPE_PPPOEDISC:
robert_jw 0:b2805b6888dc 510 case ETHTYPE_PPPOE:
robert_jw 0:b2805b6888dc 511 #endif /* PPPOE_SUPPORT */
robert_jw 0:b2805b6888dc 512 /* full packet send to tcpip_thread to process */
robert_jw 0:b2805b6888dc 513 if (netif->input(p, netif) != ERR_OK) {
robert_jw 0:b2805b6888dc 514 LWIP_DEBUGF(NETIF_DEBUG, ("k64f_enetif_input: IP input error\n"));
robert_jw 0:b2805b6888dc 515 /* Free buffer */
robert_jw 0:b2805b6888dc 516 pbuf_free(p);
robert_jw 0:b2805b6888dc 517 }
robert_jw 0:b2805b6888dc 518 break;
robert_jw 0:b2805b6888dc 519
robert_jw 0:b2805b6888dc 520 default:
robert_jw 0:b2805b6888dc 521 /* Return buffer */
robert_jw 0:b2805b6888dc 522 pbuf_free(p);
robert_jw 0:b2805b6888dc 523 break;
robert_jw 0:b2805b6888dc 524 }
robert_jw 0:b2805b6888dc 525 }
robert_jw 0:b2805b6888dc 526
robert_jw 0:b2805b6888dc 527 /** \brief Packet reception task
robert_jw 0:b2805b6888dc 528 *
robert_jw 0:b2805b6888dc 529 * This task is called when a packet is received. It will
robert_jw 0:b2805b6888dc 530 * pass the packet to the LWIP core.
robert_jw 0:b2805b6888dc 531 *
robert_jw 0:b2805b6888dc 532 * \param[in] pvParameters pointer to the interface data
robert_jw 0:b2805b6888dc 533 */
robert_jw 0:b2805b6888dc 534 static void packet_rx(void* pvParameters) {
robert_jw 0:b2805b6888dc 535 struct k64f_enetdata *k64f_enet = pvParameters;
robert_jw 0:b2805b6888dc 536 volatile enet_bd_struct_t * bdPtr = (enet_bd_struct_t*)k64f_enet->rx_desc_start_addr;
robert_jw 0:b2805b6888dc 537 int idx = 0;
robert_jw 0:b2805b6888dc 538
robert_jw 0:b2805b6888dc 539 while (1) {
robert_jw 0:b2805b6888dc 540 /* Wait for receive task to wakeup */
robert_jw 0:b2805b6888dc 541 sys_arch_sem_wait(&k64f_enet->RxReadySem, 0);
robert_jw 0:b2805b6888dc 542
robert_jw 0:b2805b6888dc 543 while ((bdPtr[idx].control & kEnetRxBdEmpty) == 0) {
robert_jw 0:b2805b6888dc 544 k64f_enetif_input(k64f_enet->netif, idx);
robert_jw 0:b2805b6888dc 545 idx = (idx + 1) % ENET_RX_RING_LEN;
robert_jw 0:b2805b6888dc 546 }
robert_jw 0:b2805b6888dc 547 }
robert_jw 0:b2805b6888dc 548 }
robert_jw 0:b2805b6888dc 549
robert_jw 0:b2805b6888dc 550 /** \brief Transmit cleanup task
robert_jw 0:b2805b6888dc 551 *
robert_jw 0:b2805b6888dc 552 * This task is called when a transmit interrupt occurs and
robert_jw 0:b2805b6888dc 553 * reclaims the pbuf and descriptor used for the packet once
robert_jw 0:b2805b6888dc 554 * the packet has been transferred.
robert_jw 0:b2805b6888dc 555 *
robert_jw 0:b2805b6888dc 556 * \param[in] pvParameters pointer to the interface data
robert_jw 0:b2805b6888dc 557 */
robert_jw 0:b2805b6888dc 558 static void packet_tx(void* pvParameters) {
robert_jw 0:b2805b6888dc 559 struct k64f_enetdata *k64f_enet = pvParameters;
robert_jw 0:b2805b6888dc 560
robert_jw 0:b2805b6888dc 561 while (1) {
robert_jw 0:b2805b6888dc 562 /* Wait for transmit cleanup task to wakeup */
robert_jw 0:b2805b6888dc 563 sys_arch_sem_wait(&k64f_enet->TxCleanSem, 0);
robert_jw 0:b2805b6888dc 564 // TODOETH: handle TX underrun?
robert_jw 0:b2805b6888dc 565 k64f_tx_reclaim(k64f_enet);
robert_jw 0:b2805b6888dc 566 }
robert_jw 0:b2805b6888dc 567 }
robert_jw 0:b2805b6888dc 568
robert_jw 0:b2805b6888dc 569 /** \brief Polls if an available TX descriptor is ready. Can be used to
robert_jw 0:b2805b6888dc 570 * determine if the low level transmit function will block.
robert_jw 0:b2805b6888dc 571 *
robert_jw 0:b2805b6888dc 572 * \param[in] netif the lwip network interface structure
robert_jw 0:b2805b6888dc 573 * \return 0 if no descriptors are read, or >0
robert_jw 0:b2805b6888dc 574 */
robert_jw 0:b2805b6888dc 575 s32_t k64f_tx_ready(struct netif *netif)
robert_jw 0:b2805b6888dc 576 {
robert_jw 0:b2805b6888dc 577 struct k64f_enetdata *k64f_enet = netif->state;
robert_jw 0:b2805b6888dc 578 s32_t fb;
robert_jw 0:b2805b6888dc 579 u32_t idx, cidx;
robert_jw 0:b2805b6888dc 580
robert_jw 0:b2805b6888dc 581 cidx = k64f_enet->tx_consume_index;
robert_jw 0:b2805b6888dc 582 idx = k64f_enet->tx_produce_index;
robert_jw 0:b2805b6888dc 583
robert_jw 0:b2805b6888dc 584 /* Determine number of free buffers */
robert_jw 0:b2805b6888dc 585 if (idx == cidx)
robert_jw 0:b2805b6888dc 586 fb = ENET_TX_RING_LEN;
robert_jw 0:b2805b6888dc 587 else if (cidx > idx)
robert_jw 0:b2805b6888dc 588 fb = (ENET_TX_RING_LEN - 1) -
robert_jw 0:b2805b6888dc 589 ((idx + ENET_TX_RING_LEN) - cidx);
robert_jw 0:b2805b6888dc 590 else
robert_jw 0:b2805b6888dc 591 fb = (ENET_TX_RING_LEN - 1) - (cidx - idx);
robert_jw 0:b2805b6888dc 592
robert_jw 0:b2805b6888dc 593 return fb;
robert_jw 0:b2805b6888dc 594 }
robert_jw 0:b2805b6888dc 595
robert_jw 0:b2805b6888dc 596 /*FUNCTION****************************************************************
robert_jw 0:b2805b6888dc 597 *
robert_jw 0:b2805b6888dc 598 * Function Name: enet_hal_update_txbds
robert_jw 0:b2805b6888dc 599 * Description: Update ENET transmit buffer descriptors.
robert_jw 0:b2805b6888dc 600 *END*********************************************************************/
robert_jw 0:b2805b6888dc 601 void k64f_update_txbds(struct k64f_enetdata *k64f_enet, int idx, uint8_t *buffer, uint16_t length, bool isLast)
robert_jw 0:b2805b6888dc 602 {
robert_jw 0:b2805b6888dc 603 volatile enet_bd_struct_t * bdPtr = (enet_bd_struct_t *)(k64f_enet->tx_desc_start_addr + idx * enet_hal_get_bd_size());
robert_jw 0:b2805b6888dc 604
robert_jw 0:b2805b6888dc 605 bdPtr->length = HTONS(length); /* Set data length*/
robert_jw 0:b2805b6888dc 606 bdPtr->buffer = (uint8_t *)HTONL((uint32_t)buffer); /* Set data buffer*/
robert_jw 0:b2805b6888dc 607 if (isLast)
robert_jw 0:b2805b6888dc 608 bdPtr->control |= kEnetTxBdLast;
robert_jw 0:b2805b6888dc 609 else
robert_jw 0:b2805b6888dc 610 bdPtr->control &= ~kEnetTxBdLast;
robert_jw 0:b2805b6888dc 611 bdPtr->controlExtend1 |= kEnetTxBdTxInterrupt;
robert_jw 0:b2805b6888dc 612 bdPtr->controlExtend2 &= ~TX_DESC_UPDATED_MASK; // descriptor not updated by DMA
robert_jw 0:b2805b6888dc 613 bdPtr->control |= kEnetTxBdTransmitCrc | kEnetTxBdReady;
robert_jw 0:b2805b6888dc 614 }
robert_jw 0:b2805b6888dc 615
robert_jw 0:b2805b6888dc 616 /** \brief Low level output of a packet. Never call this from an
robert_jw 0:b2805b6888dc 617 * interrupt context, as it may block until TX descriptors
robert_jw 0:b2805b6888dc 618 * become available.
robert_jw 0:b2805b6888dc 619 *
robert_jw 0:b2805b6888dc 620 * \param[in] netif the lwip network interface structure for this netif
robert_jw 0:b2805b6888dc 621 * \param[in] p the MAC packet to send (e.g. IP packet including MAC addresses and type)
robert_jw 0:b2805b6888dc 622 * \return ERR_OK if the packet could be sent or an err_t value if the packet couldn't be sent
robert_jw 0:b2805b6888dc 623 */
robert_jw 0:b2805b6888dc 624 static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
robert_jw 0:b2805b6888dc 625 {
robert_jw 0:b2805b6888dc 626 struct k64f_enetdata *k64f_enet = netif->state;
robert_jw 0:b2805b6888dc 627 struct pbuf *q;
robert_jw 0:b2805b6888dc 628 u32_t idx;
robert_jw 0:b2805b6888dc 629 s32_t dn;
robert_jw 0:b2805b6888dc 630 uint8_t *psend = NULL, *dst;
robert_jw 0:b2805b6888dc 631
robert_jw 0:b2805b6888dc 632 /* Get free TX buffer index */
robert_jw 0:b2805b6888dc 633 idx = k64f_enet->tx_produce_index;
robert_jw 0:b2805b6888dc 634
robert_jw 0:b2805b6888dc 635 /* Check the pbuf chain for payloads that are not 8-byte aligned.
robert_jw 0:b2805b6888dc 636 If found, a new properly aligned buffer needs to be allocated
robert_jw 0:b2805b6888dc 637 and the data copied there */
robert_jw 0:b2805b6888dc 638 for (q = p; q != NULL; q = q->next)
robert_jw 0:b2805b6888dc 639 if (((u32_t)q->payload & (TX_BUF_ALIGNMENT - 1)) != 0)
robert_jw 0:b2805b6888dc 640 break;
robert_jw 0:b2805b6888dc 641 if (q != NULL) {
robert_jw 0:b2805b6888dc 642 // Allocate properly aligned buffer
robert_jw 0:b2805b6888dc 643 psend = (uint8_t*)malloc(p->tot_len);
robert_jw 0:b2805b6888dc 644 if (NULL == psend)
robert_jw 0:b2805b6888dc 645 return ERR_MEM;
robert_jw 0:b2805b6888dc 646 LWIP_ASSERT("k64f_low_level_output: buffer not properly aligned", ((u32_t)psend & (TX_BUF_ALIGNMENT - 1)) == 0);
robert_jw 0:b2805b6888dc 647 for (q = p, dst = psend; q != NULL; q = q->next) {
robert_jw 0:b2805b6888dc 648 MEMCPY(dst, q->payload, q->len);
robert_jw 0:b2805b6888dc 649 dst += q->len;
robert_jw 0:b2805b6888dc 650 }
robert_jw 0:b2805b6888dc 651 k64f_enet->txb_aligned[idx] = psend;
robert_jw 0:b2805b6888dc 652 dn = 1;
robert_jw 0:b2805b6888dc 653 } else {
robert_jw 0:b2805b6888dc 654 k64f_enet->txb_aligned[idx] = NULL;
robert_jw 0:b2805b6888dc 655 dn = (s32_t) pbuf_clen(p);
robert_jw 0:b2805b6888dc 656 pbuf_ref(p);
robert_jw 0:b2805b6888dc 657 }
robert_jw 0:b2805b6888dc 658
robert_jw 0:b2805b6888dc 659 /* Wait until enough descriptors are available for the transfer. */
robert_jw 0:b2805b6888dc 660 /* THIS WILL BLOCK UNTIL THERE ARE ENOUGH DESCRIPTORS AVAILABLE */
robert_jw 0:b2805b6888dc 661 while (dn > k64f_tx_ready(netif))
robert_jw 0:b2805b6888dc 662 osSemaphoreWait(k64f_enet->xTXDCountSem.id, osWaitForever);
robert_jw 0:b2805b6888dc 663
robert_jw 0:b2805b6888dc 664 /* Get exclusive access */
robert_jw 0:b2805b6888dc 665 sys_mutex_lock(&k64f_enet->TXLockMutex);
robert_jw 0:b2805b6888dc 666
robert_jw 0:b2805b6888dc 667 /* Setup transfers */
robert_jw 0:b2805b6888dc 668 q = p;
robert_jw 0:b2805b6888dc 669 while (dn > 0) {
robert_jw 0:b2805b6888dc 670 dn--;
robert_jw 0:b2805b6888dc 671 if (psend != NULL) {
robert_jw 0:b2805b6888dc 672 k64f_update_txbds(k64f_enet, idx, psend, p->tot_len, 1);
robert_jw 0:b2805b6888dc 673 k64f_enet->txb[idx] = NULL;
robert_jw 0:b2805b6888dc 674
robert_jw 0:b2805b6888dc 675 LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
robert_jw 0:b2805b6888dc 676 ("k64f_low_level_output: aligned packet(%p) sent"
robert_jw 0:b2805b6888dc 677 " size = %d (index=%d)\n", psend, p->tot_len, idx));
robert_jw 0:b2805b6888dc 678 } else {
robert_jw 0:b2805b6888dc 679 LWIP_ASSERT("k64f_low_level_output: buffer not properly aligned", ((u32_t)q->payload & 0x07) == 0);
robert_jw 0:b2805b6888dc 680
robert_jw 0:b2805b6888dc 681 /* Only save pointer to free on last descriptor */
robert_jw 0:b2805b6888dc 682 if (dn == 0) {
robert_jw 0:b2805b6888dc 683 /* Save size of packet and signal it's ready */
robert_jw 0:b2805b6888dc 684 k64f_update_txbds(k64f_enet, idx, q->payload, q->len, 1);
robert_jw 0:b2805b6888dc 685 k64f_enet->txb[idx] = p;
robert_jw 0:b2805b6888dc 686 }
robert_jw 0:b2805b6888dc 687 else {
robert_jw 0:b2805b6888dc 688 /* Save size of packet, descriptor is not last */
robert_jw 0:b2805b6888dc 689 k64f_update_txbds(k64f_enet, idx, q->payload, q->len, 0);
robert_jw 0:b2805b6888dc 690 k64f_enet->txb[idx] = NULL;
robert_jw 0:b2805b6888dc 691 }
robert_jw 0:b2805b6888dc 692
robert_jw 0:b2805b6888dc 693 LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
robert_jw 0:b2805b6888dc 694 ("k64f_low_level_output: pbuf packet(%p) sent, chain#=%d,"
robert_jw 0:b2805b6888dc 695 " size = %d (index=%d)\n", q->payload, dn, q->len, idx));
robert_jw 0:b2805b6888dc 696 }
robert_jw 0:b2805b6888dc 697
robert_jw 0:b2805b6888dc 698 q = q->next;
robert_jw 0:b2805b6888dc 699
robert_jw 0:b2805b6888dc 700 idx = (idx + 1) % ENET_TX_RING_LEN;
robert_jw 0:b2805b6888dc 701 }
robert_jw 0:b2805b6888dc 702
robert_jw 0:b2805b6888dc 703 k64f_enet->tx_produce_index = idx;
robert_jw 0:b2805b6888dc 704 enet_hal_active_txbd(BOARD_DEBUG_ENET_INSTANCE_ADDR);
robert_jw 0:b2805b6888dc 705 LINK_STATS_INC(link.xmit);
robert_jw 0:b2805b6888dc 706
robert_jw 0:b2805b6888dc 707 /* Restore access */
robert_jw 0:b2805b6888dc 708 sys_mutex_unlock(&k64f_enet->TXLockMutex);
robert_jw 0:b2805b6888dc 709
robert_jw 0:b2805b6888dc 710 return ERR_OK;
robert_jw 0:b2805b6888dc 711 }
robert_jw 0:b2805b6888dc 712
robert_jw 0:b2805b6888dc 713 /*******************************************************************************
robert_jw 0:b2805b6888dc 714 * PHY task: monitor link
robert_jw 0:b2805b6888dc 715 *******************************************************************************/
robert_jw 0:b2805b6888dc 716
robert_jw 0:b2805b6888dc 717 #define PHY_TASK_PERIOD_MS 200
robert_jw 0:b2805b6888dc 718 #define STATE_UNKNOWN (-1)
robert_jw 0:b2805b6888dc 719
robert_jw 0:b2805b6888dc 720 typedef struct {
robert_jw 0:b2805b6888dc 721 int connected;
robert_jw 0:b2805b6888dc 722 enet_phy_speed_t speed;
robert_jw 0:b2805b6888dc 723 enet_phy_duplex_t duplex;
robert_jw 0:b2805b6888dc 724 } PHY_STATE;
robert_jw 0:b2805b6888dc 725
robert_jw 0:b2805b6888dc 726 int phy_link_status() {
robert_jw 0:b2805b6888dc 727 bool connection_status;
robert_jw 0:b2805b6888dc 728 enet_dev_if_t * enetIfPtr = (enet_dev_if_t*)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
robert_jw 0:b2805b6888dc 729 phy_get_link_status(enetIfPtr, &connection_status);
robert_jw 0:b2805b6888dc 730 return (int)connection_status;
robert_jw 0:b2805b6888dc 731 }
robert_jw 0:b2805b6888dc 732
robert_jw 0:b2805b6888dc 733 static void k64f_phy_task(void *data) {
robert_jw 0:b2805b6888dc 734 struct netif *netif = (struct netif*)data;
robert_jw 0:b2805b6888dc 735 bool connection_status;
robert_jw 0:b2805b6888dc 736 enet_dev_if_t * enetIfPtr = (enet_dev_if_t*)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
robert_jw 0:b2805b6888dc 737 PHY_STATE crt_state = {STATE_UNKNOWN, (enet_phy_speed_t)STATE_UNKNOWN, (enet_phy_duplex_t)STATE_UNKNOWN};
robert_jw 0:b2805b6888dc 738 PHY_STATE prev_state;
robert_jw 0:b2805b6888dc 739
robert_jw 0:b2805b6888dc 740 prev_state = crt_state;
robert_jw 0:b2805b6888dc 741 while (true) {
robert_jw 0:b2805b6888dc 742 // Get current status
robert_jw 0:b2805b6888dc 743 phy_get_link_status(enetIfPtr, &connection_status);
robert_jw 0:b2805b6888dc 744 crt_state.connected = connection_status ? 1 : 0;
robert_jw 0:b2805b6888dc 745 phy_get_link_speed(enetIfPtr, &crt_state.speed);
robert_jw 0:b2805b6888dc 746 phy_get_link_duplex(enetIfPtr, &crt_state.duplex);
robert_jw 0:b2805b6888dc 747
robert_jw 0:b2805b6888dc 748 // Compare with previous state
robert_jw 0:b2805b6888dc 749 if (crt_state.connected != prev_state.connected) {
robert_jw 0:b2805b6888dc 750 if (crt_state.connected)
robert_jw 0:b2805b6888dc 751 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1);
robert_jw 0:b2805b6888dc 752 else
robert_jw 0:b2805b6888dc 753 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1);
robert_jw 0:b2805b6888dc 754 }
robert_jw 0:b2805b6888dc 755
robert_jw 0:b2805b6888dc 756 if (crt_state.speed != prev_state.speed)
robert_jw 0:b2805b6888dc 757 BW_ENET_RCR_RMII_10T(enetIfPtr->deviceNumber, crt_state.speed == kEnetSpeed10M ? kEnetCfgSpeed10M : kEnetCfgSpeed100M);
robert_jw 0:b2805b6888dc 758
robert_jw 0:b2805b6888dc 759 // TODO: duplex change requires disable/enable of Ethernet interface, to be implemented
robert_jw 0:b2805b6888dc 760
robert_jw 0:b2805b6888dc 761 prev_state = crt_state;
robert_jw 0:b2805b6888dc 762 osDelay(PHY_TASK_PERIOD_MS);
robert_jw 0:b2805b6888dc 763 }
robert_jw 0:b2805b6888dc 764 }
robert_jw 0:b2805b6888dc 765
robert_jw 0:b2805b6888dc 766 /**
robert_jw 0:b2805b6888dc 767 * Should be called at the beginning of the program to set up the
robert_jw 0:b2805b6888dc 768 * network interface.
robert_jw 0:b2805b6888dc 769 *
robert_jw 0:b2805b6888dc 770 * This function should be passed as a parameter to netif_add().
robert_jw 0:b2805b6888dc 771 *
robert_jw 0:b2805b6888dc 772 * @param[in] netif the lwip network interface structure for this netif
robert_jw 0:b2805b6888dc 773 * @return ERR_OK if the loopif is initialized
robert_jw 0:b2805b6888dc 774 * ERR_MEM if private data couldn't be allocated
robert_jw 0:b2805b6888dc 775 * any other err_t on error
robert_jw 0:b2805b6888dc 776 */
robert_jw 0:b2805b6888dc 777 err_t eth_arch_enetif_init(struct netif *netif)
robert_jw 0:b2805b6888dc 778 {
robert_jw 0:b2805b6888dc 779 err_t err;
robert_jw 0:b2805b6888dc 780
robert_jw 0:b2805b6888dc 781 LWIP_ASSERT("netif != NULL", (netif != NULL));
robert_jw 0:b2805b6888dc 782
robert_jw 0:b2805b6888dc 783 k64f_enetdata.netif = netif;
robert_jw 0:b2805b6888dc 784
robert_jw 0:b2805b6888dc 785 /* set MAC hardware address */
robert_jw 0:b2805b6888dc 786 #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
robert_jw 0:b2805b6888dc 787 netif->hwaddr[0] = MBED_MAC_ADDR_0;
robert_jw 0:b2805b6888dc 788 netif->hwaddr[1] = MBED_MAC_ADDR_1;
robert_jw 0:b2805b6888dc 789 netif->hwaddr[2] = MBED_MAC_ADDR_2;
robert_jw 0:b2805b6888dc 790 netif->hwaddr[3] = MBED_MAC_ADDR_3;
robert_jw 0:b2805b6888dc 791 netif->hwaddr[4] = MBED_MAC_ADDR_4;
robert_jw 0:b2805b6888dc 792 netif->hwaddr[5] = MBED_MAC_ADDR_5;
robert_jw 0:b2805b6888dc 793 #else
robert_jw 0:b2805b6888dc 794 mbed_mac_address((char *)netif->hwaddr);
robert_jw 0:b2805b6888dc 795 #endif
robert_jw 0:b2805b6888dc 796 netif->hwaddr_len = ETHARP_HWADDR_LEN;
robert_jw 0:b2805b6888dc 797
robert_jw 0:b2805b6888dc 798 /* maximum transfer unit */
robert_jw 0:b2805b6888dc 799 netif->mtu = 1500;
robert_jw 0:b2805b6888dc 800
robert_jw 0:b2805b6888dc 801 /* device capabilities */
robert_jw 0:b2805b6888dc 802 // TODOETH: check if the flags are correct below
robert_jw 0:b2805b6888dc 803 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
robert_jw 0:b2805b6888dc 804
robert_jw 0:b2805b6888dc 805 /* Initialize the hardware */
robert_jw 0:b2805b6888dc 806 netif->state = &k64f_enetdata;
robert_jw 0:b2805b6888dc 807 err = low_level_init(netif);
robert_jw 0:b2805b6888dc 808 if (err != ERR_OK)
robert_jw 0:b2805b6888dc 809 return err;
robert_jw 0:b2805b6888dc 810
robert_jw 0:b2805b6888dc 811 #if LWIP_NETIF_HOSTNAME
robert_jw 0:b2805b6888dc 812 /* Initialize interface hostname */
robert_jw 0:b2805b6888dc 813 netif->hostname = "lwipk64f";
robert_jw 0:b2805b6888dc 814 #endif /* LWIP_NETIF_HOSTNAME */
robert_jw 0:b2805b6888dc 815
robert_jw 0:b2805b6888dc 816 netif->name[0] = 'e';
robert_jw 0:b2805b6888dc 817 netif->name[1] = 'n';
robert_jw 0:b2805b6888dc 818
robert_jw 0:b2805b6888dc 819 netif->output = k64f_etharp_output;
robert_jw 0:b2805b6888dc 820 netif->linkoutput = k64f_low_level_output;
robert_jw 0:b2805b6888dc 821
robert_jw 0:b2805b6888dc 822 /* CMSIS-RTOS, start tasks */
robert_jw 0:b2805b6888dc 823 #ifdef CMSIS_OS_RTX
robert_jw 0:b2805b6888dc 824 memset(k64f_enetdata.xTXDCountSem.data, 0, sizeof(k64f_enetdata.xTXDCountSem.data));
robert_jw 0:b2805b6888dc 825 k64f_enetdata.xTXDCountSem.def.semaphore = k64f_enetdata.xTXDCountSem.data;
robert_jw 0:b2805b6888dc 826 #endif
robert_jw 0:b2805b6888dc 827 k64f_enetdata.xTXDCountSem.id = osSemaphoreCreate(&k64f_enetdata.xTXDCountSem.def, ENET_TX_RING_LEN);
robert_jw 0:b2805b6888dc 828
robert_jw 0:b2805b6888dc 829 LWIP_ASSERT("xTXDCountSem creation error", (k64f_enetdata.xTXDCountSem.id != NULL));
robert_jw 0:b2805b6888dc 830
robert_jw 0:b2805b6888dc 831 err = sys_mutex_new(&k64f_enetdata.TXLockMutex);
robert_jw 0:b2805b6888dc 832 LWIP_ASSERT("TXLockMutex creation error", (err == ERR_OK));
robert_jw 0:b2805b6888dc 833
robert_jw 0:b2805b6888dc 834 /* Packet receive task */
robert_jw 0:b2805b6888dc 835 err = sys_sem_new(&k64f_enetdata.RxReadySem, 0);
robert_jw 0:b2805b6888dc 836 LWIP_ASSERT("RxReadySem creation error", (err == ERR_OK));
robert_jw 0:b2805b6888dc 837 sys_thread_new("receive_thread", packet_rx, netif->state, DEFAULT_THREAD_STACKSIZE, RX_PRIORITY);
robert_jw 0:b2805b6888dc 838
robert_jw 0:b2805b6888dc 839 /* Transmit cleanup task */
robert_jw 0:b2805b6888dc 840 err = sys_sem_new(&k64f_enetdata.TxCleanSem, 0);
robert_jw 0:b2805b6888dc 841 LWIP_ASSERT("TxCleanSem creation error", (err == ERR_OK));
robert_jw 0:b2805b6888dc 842 sys_thread_new("txclean_thread", packet_tx, netif->state, DEFAULT_THREAD_STACKSIZE, TX_PRIORITY);
robert_jw 0:b2805b6888dc 843
robert_jw 0:b2805b6888dc 844 /* PHY monitoring task */
robert_jw 0:b2805b6888dc 845 sys_thread_new("phy_thread", k64f_phy_task, netif, DEFAULT_THREAD_STACKSIZE, PHY_PRIORITY);
robert_jw 0:b2805b6888dc 846
robert_jw 0:b2805b6888dc 847 /* Allow the PHY task to detect the initial link state and set up the proper flags */
robert_jw 0:b2805b6888dc 848 osDelay(10);
robert_jw 0:b2805b6888dc 849
robert_jw 0:b2805b6888dc 850 return ERR_OK;
robert_jw 0:b2805b6888dc 851 }
robert_jw 0:b2805b6888dc 852
robert_jw 0:b2805b6888dc 853 void eth_arch_enable_interrupts(void) {
robert_jw 0:b2805b6888dc 854 enet_hal_config_interrupt(BOARD_DEBUG_ENET_INSTANCE_ADDR, (kEnetTxFrameInterrupt | kEnetRxFrameInterrupt), true);
robert_jw 0:b2805b6888dc 855 INT_SYS_EnableIRQ(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetRxfInt]]);
robert_jw 0:b2805b6888dc 856 INT_SYS_EnableIRQ(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetTxfInt]]);
robert_jw 0:b2805b6888dc 857 }
robert_jw 0:b2805b6888dc 858
robert_jw 0:b2805b6888dc 859 void eth_arch_disable_interrupts(void) {
robert_jw 0:b2805b6888dc 860 INT_SYS_DisableIRQ(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetRxfInt]]);
robert_jw 0:b2805b6888dc 861 INT_SYS_DisableIRQ(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetTxfInt]]);
robert_jw 0:b2805b6888dc 862 }
robert_jw 0:b2805b6888dc 863
robert_jw 0:b2805b6888dc 864 void ENET_Transmit_IRQHandler(void)
robert_jw 0:b2805b6888dc 865 {
robert_jw 0:b2805b6888dc 866 enet_mac_tx_isr(enetIfHandle);
robert_jw 0:b2805b6888dc 867 }
robert_jw 0:b2805b6888dc 868
robert_jw 0:b2805b6888dc 869 void ENET_Receive_IRQHandler(void)
robert_jw 0:b2805b6888dc 870 {
robert_jw 0:b2805b6888dc 871 enet_mac_rx_isr(enetIfHandle);
robert_jw 0:b2805b6888dc 872 }
robert_jw 0:b2805b6888dc 873
robert_jw 0:b2805b6888dc 874 #if FSL_FEATURE_ENET_SUPPORT_PTP
robert_jw 0:b2805b6888dc 875 void ENET_1588_Timer_IRQHandler(void)
robert_jw 0:b2805b6888dc 876 {
robert_jw 0:b2805b6888dc 877 enet_mac_ts_isr(enetIfHandle);
robert_jw 0:b2805b6888dc 878 }
robert_jw 0:b2805b6888dc 879 #endif
robert_jw 0:b2805b6888dc 880 /**
robert_jw 0:b2805b6888dc 881 * @}
robert_jw 0:b2805b6888dc 882 */
robert_jw 0:b2805b6888dc 883
robert_jw 0:b2805b6888dc 884 /* --------------------------------- End Of File ------------------------------ */
robert_jw 0:b2805b6888dc 885