Port to C027 (using AppShield and Ethernet)

Dependencies:   C12832 EthernetInterface LM75B MMA7660 MQTT mbed-rtos mbed

Fork of IBMIoTClientEthernetExample by IBM Watson IoT

Committer:
samdanbury
Date:
Wed Aug 20 12:45:14 2014 +0000
Revision:
6:37b6d0d56190
Code completely changed to improve the structure, flow and memory usage of the application

Who changed what in which revision?

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