lab 3

Committer:
dewantkatare
Date:
Mon Sep 23 22:20:13 2019 +0000
Revision:
34:bdc93b5c3c52
Parent:
31:da93f0f73711
TCP ECHO, Ethernet onterface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 10:ab9330955226 1 #include "lwip/opt.h"
mbed_official 10:ab9330955226 2 #include "lwip/sys.h"
mbed_official 10:ab9330955226 3 #include "lwip/def.h"
mbed_official 10:ab9330955226 4 #include "lwip/mem.h"
mbed_official 10:ab9330955226 5 #include "lwip/pbuf.h"
mbed_official 10:ab9330955226 6 #include "lwip/stats.h"
mbed_official 10:ab9330955226 7 #include "lwip/snmp.h"
mbed_official 10:ab9330955226 8 #include "lwip/tcpip.h"
mbed_official 10:ab9330955226 9 #include "netif/etharp.h"
mbed_official 10:ab9330955226 10 #include "netif/ppp_oe.h"
mbed_official 10:ab9330955226 11
mbed_official 10:ab9330955226 12 #include "eth_arch.h"
mbed_official 10:ab9330955226 13 #include "sys_arch.h"
mbed_official 10:ab9330955226 14
mbed_official 31:da93f0f73711 15 #include "fsl_phy.h"
mbed_official 10:ab9330955226 16 #include "k64f_emac_config.h"
mbed_official 10:ab9330955226 17 #include <ctype.h>
mbed_official 10:ab9330955226 18 #include <stdio.h>
mbed_official 10:ab9330955226 19 #include <string.h>
mbed_official 10:ab9330955226 20 #include <stdlib.h>
mbed_official 10:ab9330955226 21
mbed_official 10:ab9330955226 22 #include "mbed_interface.h"
mbed_official 10:ab9330955226 23
mbed_official 31:da93f0f73711 24 enet_handle_t g_handle;
mbed_official 31:da93f0f73711 25 // TX Buffer descriptors
mbed_official 31:da93f0f73711 26 uint8_t *tx_desc_start_addr;
mbed_official 31:da93f0f73711 27 // RX Buffer descriptors
mbed_official 31:da93f0f73711 28 uint8_t *rx_desc_start_addr;
mbed_official 31:da93f0f73711 29 // RX packet buffer pointers
mbed_official 31:da93f0f73711 30 struct pbuf *rx_buff[ENET_RX_RING_LEN];
mbed_official 31:da93f0f73711 31 // TX packet buffer pointers
mbed_official 31:da93f0f73711 32 struct pbuf *tx_buff[ENET_RX_RING_LEN];
mbed_official 31:da93f0f73711 33 // RX packet payload pointers
mbed_official 31:da93f0f73711 34 uint32_t *rx_ptr[ENET_RX_RING_LEN];
mbed_official 10:ab9330955226 35
mbed_official 10:ab9330955226 36 /********************************************************************************
mbed_official 10:ab9330955226 37 * Internal data
mbed_official 10:ab9330955226 38 ********************************************************************************/
mbed_official 31:da93f0f73711 39 #define ENET_BuffSizeAlign(n) ENET_ALIGN(n, ENET_BUFF_ALIGNMENT)
mbed_official 31:da93f0f73711 40 #define ENET_ALIGN(x,align) ((unsigned int)((x) + ((align)-1)) & (unsigned int)(~(unsigned int)((align)- 1)))
mbed_official 10:ab9330955226 41 extern void k64f_init_eth_hardware(void);
mbed_official 10:ab9330955226 42
mbed_official 10:ab9330955226 43 /* K64F EMAC driver data structure */
mbed_official 10:ab9330955226 44 struct k64f_enetdata {
mbed_official 10:ab9330955226 45 struct netif *netif; /**< Reference back to LWIP parent netif */
mbed_official 10:ab9330955226 46 sys_sem_t RxReadySem; /**< RX packet ready semaphore */
mbed_official 10:ab9330955226 47 sys_sem_t TxCleanSem; /**< TX cleanup thread wakeup semaphore */
mbed_official 10:ab9330955226 48 sys_mutex_t TXLockMutex; /**< TX critical section mutex */
mbed_official 10:ab9330955226 49 sys_sem_t xTXDCountSem; /**< TX free buffer counting semaphore */
mbed_official 10:ab9330955226 50 uint8_t tx_consume_index, tx_produce_index; /**< TX buffers ring */
mbed_official 10:ab9330955226 51 };
mbed_official 10:ab9330955226 52
mbed_official 10:ab9330955226 53 static struct k64f_enetdata k64f_enetdata;
mbed_official 10:ab9330955226 54
mbed_official 10:ab9330955226 55 /** \brief Driver transmit and receive thread priorities
mbed_official 10:ab9330955226 56 *
mbed_official 10:ab9330955226 57 * Thread priorities for receive thread and TX cleanup thread. Alter
mbed_official 10:ab9330955226 58 * to prioritize receive or transmit bandwidth. In a heavily loaded
mbed_official 10:ab9330955226 59 * system or with LEIP_DEBUG enabled, the priorities might be better
mbed_official 10:ab9330955226 60 * the same. */
mbed_official 10:ab9330955226 61 #define RX_PRIORITY (osPriorityNormal)
mbed_official 10:ab9330955226 62 #define TX_PRIORITY (osPriorityNormal)
mbed_official 10:ab9330955226 63 #define PHY_PRIORITY (osPriorityNormal)
mbed_official 10:ab9330955226 64
mbed_official 10:ab9330955226 65 /********************************************************************************
mbed_official 10:ab9330955226 66 * Buffer management
mbed_official 10:ab9330955226 67 ********************************************************************************/
mbed_official 31:da93f0f73711 68 /*
mbed_official 31:da93f0f73711 69 * This function will queue a new receive buffer
mbed_official 10:ab9330955226 70 */
mbed_official 31:da93f0f73711 71 static void update_read_buffer(uint8_t *buf)
mbed_official 10:ab9330955226 72 {
mbed_official 31:da93f0f73711 73 if (buf != NULL) {
mbed_official 31:da93f0f73711 74 g_handle.rxBdCurrent->buffer = buf;
mbed_official 10:ab9330955226 75 }
mbed_official 10:ab9330955226 76
mbed_official 31:da93f0f73711 77 /* Clears status. */
mbed_official 31:da93f0f73711 78 g_handle.rxBdCurrent->control &= ENET_BUFFDESCRIPTOR_RX_WRAP_MASK;
mbed_official 10:ab9330955226 79
mbed_official 31:da93f0f73711 80 /* Sets the receive buffer descriptor with the empty flag. */
mbed_official 31:da93f0f73711 81 g_handle.rxBdCurrent->control |= ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK;
mbed_official 10:ab9330955226 82
mbed_official 31:da93f0f73711 83 /* Increases the buffer descriptor to the next one. */
mbed_official 31:da93f0f73711 84 if (g_handle.rxBdCurrent->control & ENET_BUFFDESCRIPTOR_RX_WRAP_MASK) {
mbed_official 31:da93f0f73711 85 g_handle.rxBdCurrent = g_handle.rxBdBase;
dewantkatare 34:bdc93b5c3c52 86 // g_handle.rxBdDirty = g_handle.rxBdBase;
mbed_official 31:da93f0f73711 87 } else {
mbed_official 31:da93f0f73711 88 g_handle.rxBdCurrent++;
dewantkatare 34:bdc93b5c3c52 89 //g_handle.rxBdDirty++;
mbed_official 31:da93f0f73711 90 }
mbed_official 10:ab9330955226 91
mbed_official 31:da93f0f73711 92 /* Actives the receive buffer descriptor. */
mbed_official 31:da93f0f73711 93 ENET->RDAR = ENET_RDAR_RDAR_MASK;
mbed_official 10:ab9330955226 94 }
mbed_official 10:ab9330955226 95
mbed_official 10:ab9330955226 96 /** \brief Free TX buffers that are complete
mbed_official 10:ab9330955226 97 *
mbed_official 10:ab9330955226 98 * \param[in] k64f_enet Pointer to driver data structure
mbed_official 10:ab9330955226 99 */
mbed_official 10:ab9330955226 100 static void k64f_tx_reclaim(struct k64f_enetdata *k64f_enet)
mbed_official 10:ab9330955226 101 {
mbed_official 31:da93f0f73711 102 uint8_t i = 0 ;
mbed_official 10:ab9330955226 103
mbed_official 10:ab9330955226 104 /* Get exclusive access */
mbed_official 10:ab9330955226 105 sys_mutex_lock(&k64f_enet->TXLockMutex);
mbed_official 10:ab9330955226 106
mbed_official 31:da93f0f73711 107 i = k64f_enet->tx_consume_index;
mbed_official 10:ab9330955226 108 // Traverse all descriptors, looking for the ones modified by the uDMA
mbed_official 31:da93f0f73711 109 while((i != k64f_enet->tx_produce_index) && (!(g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK))) {
mbed_official 31:da93f0f73711 110 pbuf_free(tx_buff[i]);
mbed_official 31:da93f0f73711 111 if (g_handle.txBdDirty->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
mbed_official 31:da93f0f73711 112 g_handle.txBdDirty = g_handle.txBdBase;
mbed_official 31:da93f0f73711 113 else
mbed_official 31:da93f0f73711 114 g_handle.txBdDirty++;
mbed_official 31:da93f0f73711 115
mbed_official 16:eb4a98a54ad0 116 i = (i + 1) % ENET_TX_RING_LEN;
mbed_official 10:ab9330955226 117 }
mbed_official 31:da93f0f73711 118
mbed_official 10:ab9330955226 119 k64f_enet->tx_consume_index = i;
mbed_official 10:ab9330955226 120 /* Restore access */
mbed_official 10:ab9330955226 121 sys_mutex_unlock(&k64f_enet->TXLockMutex);
mbed_official 10:ab9330955226 122 }
mbed_official 10:ab9330955226 123
mbed_official 31:da93f0f73711 124 /** \brief Ethernet receive interrupt handler
mbed_official 31:da93f0f73711 125 *
mbed_official 31:da93f0f73711 126 * This function handles the receive interrupt of K64F.
mbed_official 31:da93f0f73711 127 */
mbed_official 31:da93f0f73711 128 void enet_mac_rx_isr()
mbed_official 31:da93f0f73711 129 {
mbed_official 31:da93f0f73711 130 sys_sem_signal(&k64f_enetdata.RxReadySem);
mbed_official 31:da93f0f73711 131 }
mbed_official 31:da93f0f73711 132
mbed_official 31:da93f0f73711 133 void enet_mac_tx_isr()
mbed_official 31:da93f0f73711 134 {
mbed_official 31:da93f0f73711 135 sys_sem_signal(&k64f_enetdata.TxCleanSem);
mbed_official 31:da93f0f73711 136 }
mbed_official 31:da93f0f73711 137
mbed_official 31:da93f0f73711 138 void ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event_t event, void *param)
mbed_official 31:da93f0f73711 139 {
mbed_official 31:da93f0f73711 140 switch (event)
mbed_official 31:da93f0f73711 141 {
mbed_official 31:da93f0f73711 142 case kENET_RxEvent:
mbed_official 31:da93f0f73711 143 enet_mac_rx_isr();
mbed_official 31:da93f0f73711 144 break;
mbed_official 31:da93f0f73711 145 case kENET_TxEvent:
mbed_official 31:da93f0f73711 146 enet_mac_tx_isr();
mbed_official 31:da93f0f73711 147 break;
mbed_official 31:da93f0f73711 148 default:
mbed_official 31:da93f0f73711 149 break;
mbed_official 31:da93f0f73711 150 }
mbed_official 31:da93f0f73711 151 }
mbed_official 31:da93f0f73711 152
mbed_official 10:ab9330955226 153 /** \brief Low level init of the MAC and PHY.
mbed_official 10:ab9330955226 154 *
mbed_official 10:ab9330955226 155 * \param[in] netif Pointer to LWIP netif structure
mbed_official 10:ab9330955226 156 */
mbed_official 10:ab9330955226 157 static err_t low_level_init(struct netif *netif)
mbed_official 10:ab9330955226 158 {
mbed_official 31:da93f0f73711 159 struct k64f_enetdata *k64f_enet = netif->state;
mbed_official 31:da93f0f73711 160 uint8_t i;
mbed_official 31:da93f0f73711 161 uint32_t sysClock;
mbed_official 31:da93f0f73711 162 phy_speed_t phy_speed;
mbed_official 31:da93f0f73711 163 phy_duplex_t phy_duplex;
mbed_official 31:da93f0f73711 164 uint32_t phyAddr = 0;
mbed_official 31:da93f0f73711 165 bool link = false;
mbed_official 31:da93f0f73711 166 enet_config_t config;
mbed_official 31:da93f0f73711 167
mbed_official 31:da93f0f73711 168 // Allocate RX descriptors
mbed_official 31:da93f0f73711 169 rx_desc_start_addr = (uint8_t *)calloc(1, sizeof(enet_rx_bd_struct_t) * ENET_RX_RING_LEN + ENET_BUFF_ALIGNMENT);
mbed_official 31:da93f0f73711 170 if(!rx_desc_start_addr)
mbed_official 31:da93f0f73711 171 return ERR_MEM;
mbed_official 10:ab9330955226 172
mbed_official 31:da93f0f73711 173 // Allocate TX descriptors
mbed_official 31:da93f0f73711 174 tx_desc_start_addr = (uint8_t *)calloc(1, sizeof(enet_tx_bd_struct_t) * ENET_TX_RING_LEN + ENET_BUFF_ALIGNMENT);
mbed_official 31:da93f0f73711 175 if(!tx_desc_start_addr)
mbed_official 31:da93f0f73711 176 return ERR_MEM;
mbed_official 31:da93f0f73711 177
mbed_official 31:da93f0f73711 178 rx_desc_start_addr = (uint8_t *)ENET_ALIGN(rx_desc_start_addr, ENET_BUFF_ALIGNMENT);
mbed_official 31:da93f0f73711 179 tx_desc_start_addr = (uint8_t *)ENET_ALIGN(tx_desc_start_addr, ENET_BUFF_ALIGNMENT);
mbed_official 10:ab9330955226 180
mbed_official 31:da93f0f73711 181 /* Create buffers for each receive BD */
mbed_official 31:da93f0f73711 182 for (i = 0; i < ENET_RX_RING_LEN; i++) {
mbed_official 31:da93f0f73711 183 rx_buff[i] = pbuf_alloc(PBUF_RAW, ENET_ETH_MAX_FLEN + ENET_BUFF_ALIGNMENT, PBUF_RAM);
mbed_official 31:da93f0f73711 184 if (NULL == rx_buff[i])
mbed_official 31:da93f0f73711 185 return ERR_MEM;
mbed_official 31:da93f0f73711 186
mbed_official 31:da93f0f73711 187 /* K64F note: the next line ensures that the RX buffer is properly aligned for the K64F
mbed_official 31:da93f0f73711 188 RX descriptors (16 bytes alignment). However, by doing so, we're effectively changing
mbed_official 31:da93f0f73711 189 a data structure which is internal to lwIP. This might not prove to be a good idea
mbed_official 31:da93f0f73711 190 in the long run, but a better fix would probably involve modifying lwIP itself */
mbed_official 31:da93f0f73711 191 rx_buff[i]->payload = (void*)ENET_ALIGN((uint32_t)rx_buff[i]->payload, ENET_BUFF_ALIGNMENT);
mbed_official 31:da93f0f73711 192 rx_ptr[i] = rx_buff[i]->payload;
mbed_official 20:620d381e7f4c 193 }
mbed_official 10:ab9330955226 194
mbed_official 31:da93f0f73711 195 k64f_enet->tx_consume_index = k64f_enet->tx_produce_index = 0;
mbed_official 31:da93f0f73711 196
mbed_official 31:da93f0f73711 197 /* prepare the buffer configuration. */
mbed_official 31:da93f0f73711 198 enet_buffer_config_t buffCfg = {
mbed_official 31:da93f0f73711 199 ENET_RX_RING_LEN,
mbed_official 31:da93f0f73711 200 ENET_TX_RING_LEN,
mbed_official 31:da93f0f73711 201 ENET_ALIGN(ENET_ETH_MAX_FLEN, ENET_BUFF_ALIGNMENT),
mbed_official 31:da93f0f73711 202 0,
mbed_official 31:da93f0f73711 203 (volatile enet_rx_bd_struct_t *)rx_desc_start_addr,
mbed_official 31:da93f0f73711 204 (volatile enet_tx_bd_struct_t *)tx_desc_start_addr,
mbed_official 31:da93f0f73711 205 (uint8_t *)&rx_ptr,
mbed_official 31:da93f0f73711 206 NULL,
mbed_official 31:da93f0f73711 207 };
mbed_official 31:da93f0f73711 208
mbed_official 31:da93f0f73711 209 k64f_init_eth_hardware();
mbed_official 31:da93f0f73711 210
mbed_official 31:da93f0f73711 211 sysClock = CLOCK_GetFreq(kCLOCK_CoreSysClk);
mbed_official 10:ab9330955226 212
mbed_official 31:da93f0f73711 213 ENET_GetDefaultConfig(&config);
mbed_official 10:ab9330955226 214
mbed_official 31:da93f0f73711 215 PHY_Init(ENET, 0, sysClock);
mbed_official 31:da93f0f73711 216 PHY_GetLinkStatus(ENET, phyAddr, &link);
mbed_official 31:da93f0f73711 217 if (link)
mbed_official 31:da93f0f73711 218 {
mbed_official 31:da93f0f73711 219 /* Get link information from PHY */
mbed_official 31:da93f0f73711 220 PHY_GetLinkSpeedDuplex(ENET, phyAddr, &phy_speed, &phy_duplex);
mbed_official 31:da93f0f73711 221 /* Change the MII speed and duplex for actual link status. */
mbed_official 31:da93f0f73711 222 config.miiSpeed = (enet_mii_speed_t)phy_speed;
mbed_official 31:da93f0f73711 223 config.miiDuplex = (enet_mii_duplex_t)phy_duplex;
mbed_official 31:da93f0f73711 224 config.interrupt = kENET_RxFrameInterrupt | kENET_TxFrameInterrupt;
mbed_official 31:da93f0f73711 225 }
mbed_official 31:da93f0f73711 226 config.rxMaxFrameLen = ENET_ETH_MAX_FLEN;
mbed_official 31:da93f0f73711 227 config.macSpecialConfig = kENET_ControlFlowControlEnable;
mbed_official 31:da93f0f73711 228 config.txAccelerConfig = kENET_TxAccelIsShift16Enabled;
mbed_official 31:da93f0f73711 229 config.rxAccelerConfig = kENET_RxAccelisShift16Enabled | kENET_RxAccelMacCheckEnabled;
mbed_official 31:da93f0f73711 230 ENET_Init(ENET, &g_handle, &config, &buffCfg, netif->hwaddr, sysClock);
mbed_official 31:da93f0f73711 231 ENET_SetCallback(&g_handle, ethernet_callback, netif);
mbed_official 31:da93f0f73711 232 ENET_ActiveRead(ENET);
mbed_official 10:ab9330955226 233
mbed_official 10:ab9330955226 234 return ERR_OK;
mbed_official 10:ab9330955226 235 }
mbed_official 10:ab9330955226 236
mbed_official 10:ab9330955226 237
mbed_official 10:ab9330955226 238 /**
mbed_official 10:ab9330955226 239 * This function is the ethernet packet send function. It calls
mbed_official 10:ab9330955226 240 * etharp_output after checking link status.
mbed_official 10:ab9330955226 241 *
mbed_official 10:ab9330955226 242 * \param[in] netif the lwip network interface structure for this enetif
mbed_official 10:ab9330955226 243 * \param[in] q Pointer to pbug to send
mbed_official 10:ab9330955226 244 * \param[in] ipaddr IP address
mbed_official 10:ab9330955226 245 * \return ERR_OK or error code
mbed_official 10:ab9330955226 246 */
mbed_official 10:ab9330955226 247 err_t k64f_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)
mbed_official 20:620d381e7f4c 248 {
mbed_official 10:ab9330955226 249 /* Only send packet is link is up */
mbed_official 10:ab9330955226 250 if (netif->flags & NETIF_FLAG_LINK_UP)
mbed_official 10:ab9330955226 251 return etharp_output(netif, q, ipaddr);
mbed_official 10:ab9330955226 252
mbed_official 10:ab9330955226 253 return ERR_CONN;
mbed_official 10:ab9330955226 254 }
mbed_official 10:ab9330955226 255
mbed_official 10:ab9330955226 256 /** \brief Allocates a pbuf and returns the data from the incoming packet.
mbed_official 10:ab9330955226 257 *
mbed_official 10:ab9330955226 258 * \param[in] netif the lwip network interface structure
mbed_official 10:ab9330955226 259 * \param[in] idx index of packet to be read
mbed_official 10:ab9330955226 260 * \return a pbuf filled with the received packet (including MAC header)
mbed_official 10:ab9330955226 261 */
mbed_official 10:ab9330955226 262 static struct pbuf *k64f_low_level_input(struct netif *netif, int idx)
mbed_official 10:ab9330955226 263 {
mbed_official 31:da93f0f73711 264 volatile enet_rx_bd_struct_t *bdPtr = g_handle.rxBdCurrent;
mbed_official 10:ab9330955226 265 struct pbuf *p = NULL;
mbed_official 31:da93f0f73711 266 struct pbuf *temp_rxbuf = NULL;
mbed_official 31:da93f0f73711 267 u32_t length = 0;
mbed_official 31:da93f0f73711 268 const u16_t err_mask = ENET_BUFFDESCRIPTOR_RX_TRUNC_MASK | ENET_BUFFDESCRIPTOR_RX_CRC_MASK |
mbed_official 31:da93f0f73711 269 ENET_BUFFDESCRIPTOR_RX_NOOCTET_MASK | ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK;
mbed_official 31:da93f0f73711 270
mbed_official 10:ab9330955226 271
mbed_official 10:ab9330955226 272 #ifdef LOCK_RX_THREAD
mbed_official 10:ab9330955226 273 /* Get exclusive access */
mbed_official 10:ab9330955226 274 sys_mutex_lock(&k64f_enet->TXLockMutex);
mbed_official 10:ab9330955226 275 #endif
mbed_official 10:ab9330955226 276
mbed_official 10:ab9330955226 277 /* Determine if a frame has been received */
mbed_official 31:da93f0f73711 278 if ((bdPtr->control & err_mask) != 0) {
mbed_official 10:ab9330955226 279 #if LINK_STATS
mbed_official 31:da93f0f73711 280 if ((bdPtr->control & ENET_BUFFDESCRIPTOR_RX_LENVLIOLATE_MASK) != 0)
mbed_official 10:ab9330955226 281 LINK_STATS_INC(link.lenerr);
mbed_official 10:ab9330955226 282 else
mbed_official 10:ab9330955226 283 LINK_STATS_INC(link.chkerr);
mbed_official 10:ab9330955226 284 #endif
mbed_official 10:ab9330955226 285 LINK_STATS_INC(link.drop);
mbed_official 31:da93f0f73711 286 /* Re-use the same buffer in case of error */
mbed_official 31:da93f0f73711 287 update_read_buffer(NULL);
mbed_official 10:ab9330955226 288 } else {
mbed_official 10:ab9330955226 289 /* A packet is waiting, get length */
mbed_official 31:da93f0f73711 290 length = bdPtr->length;
mbed_official 10:ab9330955226 291
mbed_official 10:ab9330955226 292 /* Zero-copy */
mbed_official 31:da93f0f73711 293 p = rx_buff[idx];
mbed_official 31:da93f0f73711 294 p->len = length;
mbed_official 10:ab9330955226 295
mbed_official 10:ab9330955226 296 /* Attempt to queue new buffer */
mbed_official 31:da93f0f73711 297 temp_rxbuf = pbuf_alloc(PBUF_RAW, ENET_ETH_MAX_FLEN + ENET_BUFF_ALIGNMENT, PBUF_RAM);
mbed_official 31:da93f0f73711 298 if (NULL == temp_rxbuf) {
mbed_official 10:ab9330955226 299 /* Drop frame (out of memory) */
mbed_official 10:ab9330955226 300 LINK_STATS_INC(link.drop);
mbed_official 10:ab9330955226 301
mbed_official 10:ab9330955226 302 /* Re-queue the same buffer */
mbed_official 31:da93f0f73711 303 update_read_buffer(NULL);
mbed_official 10:ab9330955226 304
mbed_official 10:ab9330955226 305 LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
mbed_official 10:ab9330955226 306 ("k64f_low_level_input: Packet index %d dropped for OOM\n",
mbed_official 10:ab9330955226 307 idx));
mbed_official 10:ab9330955226 308 #ifdef LOCK_RX_THREAD
mbed_official 10:ab9330955226 309 sys_mutex_unlock(&k64f_enet->TXLockMutex);
mbed_official 10:ab9330955226 310 #endif
mbed_official 10:ab9330955226 311
mbed_official 10:ab9330955226 312 return NULL;
mbed_official 10:ab9330955226 313 }
mbed_official 10:ab9330955226 314
mbed_official 31:da93f0f73711 315 rx_buff[idx] = temp_rxbuf;
mbed_official 31:da93f0f73711 316 /* K64F note: the next line ensures that the RX buffer is properly aligned for the K64F
mbed_official 31:da93f0f73711 317 RX descriptors (16 bytes alignment). However, by doing so, we're effectively changing
mbed_official 31:da93f0f73711 318 a data structure which is internal to lwIP. This might not prove to be a good idea
mbed_official 31:da93f0f73711 319 in the long run, but a better fix would probably involve modifying lwIP itself */
mbed_official 31:da93f0f73711 320 rx_buff[idx]->payload = (void*)ENET_ALIGN((uint32_t)rx_buff[idx]->payload, ENET_BUFF_ALIGNMENT);
mbed_official 31:da93f0f73711 321 rx_ptr[idx] = rx_buff[idx]->payload;
mbed_official 31:da93f0f73711 322
mbed_official 31:da93f0f73711 323 update_read_buffer(rx_buff[idx]->payload);
mbed_official 10:ab9330955226 324 LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
mbed_official 10:ab9330955226 325 ("k64f_low_level_input: Packet received: %p, size %d (index=%d)\n",
mbed_official 10:ab9330955226 326 p, length, idx));
mbed_official 10:ab9330955226 327
mbed_official 10:ab9330955226 328 /* Save size */
mbed_official 10:ab9330955226 329 p->tot_len = (u16_t) length;
mbed_official 10:ab9330955226 330 LINK_STATS_INC(link.recv);
mbed_official 10:ab9330955226 331 }
mbed_official 10:ab9330955226 332
mbed_official 10:ab9330955226 333 #ifdef LOCK_RX_THREAD
mbed_official 10:ab9330955226 334 sys_mutex_unlock(&k64f_enet->TXLockMutex);
mbed_official 10:ab9330955226 335 #endif
mbed_official 10:ab9330955226 336
mbed_official 10:ab9330955226 337 return p;
mbed_official 10:ab9330955226 338 }
mbed_official 10:ab9330955226 339
mbed_official 10:ab9330955226 340 /** \brief Attempt to read a packet from the EMAC interface.
mbed_official 10:ab9330955226 341 *
mbed_official 10:ab9330955226 342 * \param[in] netif the lwip network interface structure
mbed_official 10:ab9330955226 343 * \param[in] idx index of packet to be read
mbed_official 10:ab9330955226 344 */
mbed_official 10:ab9330955226 345 void k64f_enetif_input(struct netif *netif, int idx)
mbed_official 10:ab9330955226 346 {
mbed_official 10:ab9330955226 347 struct eth_hdr *ethhdr;
mbed_official 10:ab9330955226 348 struct pbuf *p;
mbed_official 10:ab9330955226 349
mbed_official 10:ab9330955226 350 /* move received packet into a new pbuf */
mbed_official 10:ab9330955226 351 p = k64f_low_level_input(netif, idx);
mbed_official 10:ab9330955226 352 if (p == NULL)
mbed_official 10:ab9330955226 353 return;
mbed_official 10:ab9330955226 354
mbed_official 10:ab9330955226 355 /* points to packet payload, which starts with an Ethernet header */
mbed_official 10:ab9330955226 356 ethhdr = (struct eth_hdr*)p->payload;
mbed_official 10:ab9330955226 357
mbed_official 10:ab9330955226 358 switch (htons(ethhdr->type)) {
mbed_official 10:ab9330955226 359 case ETHTYPE_IP:
mbed_official 10:ab9330955226 360 case ETHTYPE_ARP:
mbed_official 10:ab9330955226 361 #if PPPOE_SUPPORT
mbed_official 10:ab9330955226 362 case ETHTYPE_PPPOEDISC:
mbed_official 10:ab9330955226 363 case ETHTYPE_PPPOE:
mbed_official 10:ab9330955226 364 #endif /* PPPOE_SUPPORT */
mbed_official 10:ab9330955226 365 /* full packet send to tcpip_thread to process */
mbed_official 10:ab9330955226 366 if (netif->input(p, netif) != ERR_OK) {
mbed_official 10:ab9330955226 367 LWIP_DEBUGF(NETIF_DEBUG, ("k64f_enetif_input: IP input error\n"));
mbed_official 10:ab9330955226 368 /* Free buffer */
mbed_official 10:ab9330955226 369 pbuf_free(p);
mbed_official 10:ab9330955226 370 }
mbed_official 10:ab9330955226 371 break;
mbed_official 10:ab9330955226 372
mbed_official 10:ab9330955226 373 default:
mbed_official 10:ab9330955226 374 /* Return buffer */
mbed_official 10:ab9330955226 375 pbuf_free(p);
mbed_official 10:ab9330955226 376 break;
mbed_official 10:ab9330955226 377 }
mbed_official 10:ab9330955226 378 }
mbed_official 10:ab9330955226 379
mbed_official 10:ab9330955226 380 /** \brief Packet reception task
mbed_official 10:ab9330955226 381 *
mbed_official 10:ab9330955226 382 * This task is called when a packet is received. It will
mbed_official 10:ab9330955226 383 * pass the packet to the LWIP core.
mbed_official 10:ab9330955226 384 *
mbed_official 10:ab9330955226 385 * \param[in] pvParameters pointer to the interface data
mbed_official 10:ab9330955226 386 */
mbed_official 10:ab9330955226 387 static void packet_rx(void* pvParameters) {
mbed_official 10:ab9330955226 388 struct k64f_enetdata *k64f_enet = pvParameters;
mbed_official 10:ab9330955226 389 int idx = 0;
mbed_official 10:ab9330955226 390
mbed_official 10:ab9330955226 391 while (1) {
mbed_official 10:ab9330955226 392 /* Wait for receive task to wakeup */
mbed_official 10:ab9330955226 393 sys_arch_sem_wait(&k64f_enet->RxReadySem, 0);
mbed_official 10:ab9330955226 394
mbed_official 31:da93f0f73711 395 while ((g_handle.rxBdCurrent->control & ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK) == 0) {
mbed_official 10:ab9330955226 396 k64f_enetif_input(k64f_enet->netif, idx);
mbed_official 10:ab9330955226 397 idx = (idx + 1) % ENET_RX_RING_LEN;
mbed_official 10:ab9330955226 398 }
mbed_official 10:ab9330955226 399 }
mbed_official 10:ab9330955226 400 }
mbed_official 10:ab9330955226 401
mbed_official 10:ab9330955226 402 /** \brief Transmit cleanup task
mbed_official 10:ab9330955226 403 *
mbed_official 10:ab9330955226 404 * This task is called when a transmit interrupt occurs and
mbed_official 10:ab9330955226 405 * reclaims the pbuf and descriptor used for the packet once
mbed_official 10:ab9330955226 406 * the packet has been transferred.
mbed_official 10:ab9330955226 407 *
mbed_official 10:ab9330955226 408 * \param[in] pvParameters pointer to the interface data
mbed_official 10:ab9330955226 409 */
mbed_official 10:ab9330955226 410 static void packet_tx(void* pvParameters) {
mbed_official 10:ab9330955226 411 struct k64f_enetdata *k64f_enet = pvParameters;
mbed_official 10:ab9330955226 412
mbed_official 10:ab9330955226 413 while (1) {
mbed_official 10:ab9330955226 414 /* Wait for transmit cleanup task to wakeup */
mbed_official 10:ab9330955226 415 sys_arch_sem_wait(&k64f_enet->TxCleanSem, 0);
mbed_official 10:ab9330955226 416 k64f_tx_reclaim(k64f_enet);
mbed_official 10:ab9330955226 417 }
mbed_official 10:ab9330955226 418 }
mbed_official 10:ab9330955226 419
mbed_official 10:ab9330955226 420 /** \brief Low level output of a packet. Never call this from an
mbed_official 10:ab9330955226 421 * interrupt context, as it may block until TX descriptors
mbed_official 10:ab9330955226 422 * become available.
mbed_official 10:ab9330955226 423 *
mbed_official 10:ab9330955226 424 * \param[in] netif the lwip network interface structure for this netif
mbed_official 10:ab9330955226 425 * \param[in] p the MAC packet to send (e.g. IP packet including MAC addresses and type)
mbed_official 10:ab9330955226 426 * \return ERR_OK if the packet could be sent or an err_t value if the packet couldn't be sent
mbed_official 10:ab9330955226 427 */
mbed_official 10:ab9330955226 428 static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
mbed_official 10:ab9330955226 429 {
mbed_official 10:ab9330955226 430 struct k64f_enetdata *k64f_enet = netif->state;
mbed_official 10:ab9330955226 431 struct pbuf *q;
mbed_official 31:da93f0f73711 432 struct pbuf *temp_pbuf;
mbed_official 10:ab9330955226 433 uint8_t *psend = NULL, *dst;
mbed_official 10:ab9330955226 434
mbed_official 31:da93f0f73711 435
mbed_official 31:da93f0f73711 436 temp_pbuf = pbuf_alloc(PBUF_RAW, p->tot_len + ENET_BUFF_ALIGNMENT, PBUF_RAM);
mbed_official 31:da93f0f73711 437 if (NULL == temp_pbuf)
mbed_official 31:da93f0f73711 438 return ERR_MEM;
mbed_official 31:da93f0f73711 439
mbed_official 31:da93f0f73711 440 /* K64F note: the next line ensures that the RX buffer is properly aligned for the K64F
mbed_official 31:da93f0f73711 441 RX descriptors (16 bytes alignment). However, by doing so, we're effectively changing
mbed_official 31:da93f0f73711 442 a data structure which is internal to lwIP. This might not prove to be a good idea
mbed_official 31:da93f0f73711 443 in the long run, but a better fix would probably involve modifying lwIP itself */
mbed_official 31:da93f0f73711 444 psend = (uint8_t *)ENET_ALIGN((uint32_t)temp_pbuf->payload, ENET_BUFF_ALIGNMENT);
mbed_official 31:da93f0f73711 445
mbed_official 31:da93f0f73711 446 for (q = p, dst = psend; q != NULL; q = q->next) {
mbed_official 31:da93f0f73711 447 MEMCPY(dst, q->payload, q->len);
mbed_official 31:da93f0f73711 448 dst += q->len;
mbed_official 10:ab9330955226 449 }
mbed_official 10:ab9330955226 450
mbed_official 31:da93f0f73711 451 /* Wait until a descriptor is available for the transfer. */
mbed_official 31:da93f0f73711 452 /* THIS WILL BLOCK UNTIL THERE ARE A DESCRIPTOR AVAILABLE */
mbed_official 31:da93f0f73711 453 while (g_handle.txBdCurrent->control & ENET_BUFFDESCRIPTOR_TX_READY_MASK)
mbed_official 10:ab9330955226 454 osSemaphoreWait(k64f_enet->xTXDCountSem.id, osWaitForever);
mbed_official 10:ab9330955226 455
mbed_official 10:ab9330955226 456 /* Get exclusive access */
mbed_official 10:ab9330955226 457 sys_mutex_lock(&k64f_enet->TXLockMutex);
mbed_official 10:ab9330955226 458
mbed_official 31:da93f0f73711 459 /* Save the buffer so that it can be freed when transmit is done */
mbed_official 31:da93f0f73711 460 tx_buff[k64f_enet->tx_produce_index] = temp_pbuf;
mbed_official 31:da93f0f73711 461 k64f_enet->tx_produce_index = (k64f_enet->tx_produce_index + 1) % ENET_TX_RING_LEN;
mbed_official 31:da93f0f73711 462
mbed_official 10:ab9330955226 463 /* Setup transfers */
mbed_official 31:da93f0f73711 464 g_handle.txBdCurrent->buffer = psend;
mbed_official 31:da93f0f73711 465 g_handle.txBdCurrent->length = p->tot_len;
mbed_official 31:da93f0f73711 466 g_handle.txBdCurrent->control |= (ENET_BUFFDESCRIPTOR_TX_READY_MASK | ENET_BUFFDESCRIPTOR_TX_LAST_MASK);
mbed_official 10:ab9330955226 467
mbed_official 31:da93f0f73711 468 /* Increase the buffer descriptor address. */
mbed_official 31:da93f0f73711 469 if (g_handle.txBdCurrent->control & ENET_BUFFDESCRIPTOR_TX_WRAP_MASK)
mbed_official 31:da93f0f73711 470 g_handle.txBdCurrent = g_handle.txBdBase;
mbed_official 31:da93f0f73711 471 else
mbed_official 31:da93f0f73711 472 g_handle.txBdCurrent++;
mbed_official 10:ab9330955226 473
mbed_official 31:da93f0f73711 474 /* Active the transmit buffer descriptor. */
mbed_official 31:da93f0f73711 475 ENET->TDAR = ENET_TDAR_TDAR_MASK;
mbed_official 10:ab9330955226 476
mbed_official 10:ab9330955226 477 LINK_STATS_INC(link.xmit);
mbed_official 10:ab9330955226 478
mbed_official 10:ab9330955226 479 /* Restore access */
mbed_official 10:ab9330955226 480 sys_mutex_unlock(&k64f_enet->TXLockMutex);
mbed_official 10:ab9330955226 481
mbed_official 10:ab9330955226 482 return ERR_OK;
mbed_official 10:ab9330955226 483 }
mbed_official 10:ab9330955226 484
mbed_official 10:ab9330955226 485 /*******************************************************************************
mbed_official 10:ab9330955226 486 * PHY task: monitor link
mbed_official 10:ab9330955226 487 *******************************************************************************/
mbed_official 10:ab9330955226 488
mbed_official 10:ab9330955226 489 #define PHY_TASK_PERIOD_MS 200
mbed_official 10:ab9330955226 490 #define STATE_UNKNOWN (-1)
mbed_official 10:ab9330955226 491
mbed_official 10:ab9330955226 492 typedef struct {
mbed_official 10:ab9330955226 493 int connected;
mbed_official 31:da93f0f73711 494 phy_speed_t speed;
mbed_official 31:da93f0f73711 495 phy_duplex_t duplex;
mbed_official 10:ab9330955226 496 } PHY_STATE;
mbed_official 10:ab9330955226 497
mbed_official 21:10cdd9fe0509 498 int phy_link_status() {
mbed_official 21:10cdd9fe0509 499 bool connection_status;
mbed_official 31:da93f0f73711 500 uint32_t phyAddr = 0;
mbed_official 31:da93f0f73711 501
mbed_official 31:da93f0f73711 502 PHY_GetLinkStatus(ENET, phyAddr, &connection_status);
mbed_official 21:10cdd9fe0509 503 return (int)connection_status;
mbed_official 21:10cdd9fe0509 504 }
mbed_official 21:10cdd9fe0509 505
mbed_official 10:ab9330955226 506 static void k64f_phy_task(void *data) {
mbed_official 10:ab9330955226 507 struct netif *netif = (struct netif*)data;
mbed_official 10:ab9330955226 508 bool connection_status;
mbed_official 31:da93f0f73711 509 PHY_STATE crt_state = {STATE_UNKNOWN, (phy_speed_t)STATE_UNKNOWN, (phy_duplex_t)STATE_UNKNOWN};
mbed_official 10:ab9330955226 510 PHY_STATE prev_state;
mbed_official 31:da93f0f73711 511 uint32_t phyAddr = 0;
mbed_official 31:da93f0f73711 512 uint32_t rcr = 0;
mbed_official 10:ab9330955226 513
mbed_official 10:ab9330955226 514 prev_state = crt_state;
mbed_official 10:ab9330955226 515 while (true) {
mbed_official 10:ab9330955226 516 // Get current status
mbed_official 31:da93f0f73711 517 PHY_GetLinkStatus(ENET, phyAddr, &connection_status);
mbed_official 10:ab9330955226 518 crt_state.connected = connection_status ? 1 : 0;
mbed_official 31:da93f0f73711 519 // Get the actual PHY link speed
mbed_official 31:da93f0f73711 520 PHY_GetLinkSpeedDuplex(ENET, phyAddr, &crt_state.speed, &crt_state.duplex);
mbed_official 10:ab9330955226 521
mbed_official 10:ab9330955226 522 // Compare with previous state
mbed_official 10:ab9330955226 523 if (crt_state.connected != prev_state.connected) {
mbed_official 10:ab9330955226 524 if (crt_state.connected)
mbed_official 10:ab9330955226 525 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_up, (void*) netif, 1);
mbed_official 10:ab9330955226 526 else
mbed_official 10:ab9330955226 527 tcpip_callback_with_block((tcpip_callback_fn)netif_set_link_down, (void*) netif, 1);
mbed_official 10:ab9330955226 528 }
mbed_official 10:ab9330955226 529
mbed_official 31:da93f0f73711 530 if (crt_state.speed != prev_state.speed) {
mbed_official 31:da93f0f73711 531 rcr = ENET->RCR;
mbed_official 31:da93f0f73711 532 rcr &= ~ENET_RCR_RMII_10T_MASK;
mbed_official 31:da93f0f73711 533 rcr |= ENET_RCR_RMII_10T(!crt_state.speed);
mbed_official 31:da93f0f73711 534 ENET->RCR = rcr;
mbed_official 31:da93f0f73711 535 }
mbed_official 10:ab9330955226 536
mbed_official 10:ab9330955226 537 prev_state = crt_state;
mbed_official 10:ab9330955226 538 osDelay(PHY_TASK_PERIOD_MS);
mbed_official 10:ab9330955226 539 }
mbed_official 10:ab9330955226 540 }
mbed_official 10:ab9330955226 541
mbed_official 10:ab9330955226 542 /**
mbed_official 10:ab9330955226 543 * Should be called at the beginning of the program to set up the
mbed_official 10:ab9330955226 544 * network interface.
mbed_official 10:ab9330955226 545 *
mbed_official 10:ab9330955226 546 * This function should be passed as a parameter to netif_add().
mbed_official 10:ab9330955226 547 *
mbed_official 10:ab9330955226 548 * @param[in] netif the lwip network interface structure for this netif
mbed_official 10:ab9330955226 549 * @return ERR_OK if the loopif is initialized
mbed_official 10:ab9330955226 550 * ERR_MEM if private data couldn't be allocated
mbed_official 10:ab9330955226 551 * any other err_t on error
mbed_official 10:ab9330955226 552 */
mbed_official 10:ab9330955226 553 err_t eth_arch_enetif_init(struct netif *netif)
mbed_official 10:ab9330955226 554 {
mbed_official 10:ab9330955226 555 err_t err;
mbed_official 10:ab9330955226 556
mbed_official 10:ab9330955226 557 LWIP_ASSERT("netif != NULL", (netif != NULL));
mbed_official 10:ab9330955226 558
mbed_official 10:ab9330955226 559 k64f_enetdata.netif = netif;
mbed_official 10:ab9330955226 560
mbed_official 10:ab9330955226 561 /* set MAC hardware address */
mbed_official 10:ab9330955226 562 #if (MBED_MAC_ADDRESS_SUM != MBED_MAC_ADDR_INTERFACE)
mbed_official 10:ab9330955226 563 netif->hwaddr[0] = MBED_MAC_ADDR_0;
mbed_official 10:ab9330955226 564 netif->hwaddr[1] = MBED_MAC_ADDR_1;
mbed_official 10:ab9330955226 565 netif->hwaddr[2] = MBED_MAC_ADDR_2;
mbed_official 10:ab9330955226 566 netif->hwaddr[3] = MBED_MAC_ADDR_3;
mbed_official 10:ab9330955226 567 netif->hwaddr[4] = MBED_MAC_ADDR_4;
mbed_official 10:ab9330955226 568 netif->hwaddr[5] = MBED_MAC_ADDR_5;
mbed_official 10:ab9330955226 569 #else
mbed_official 10:ab9330955226 570 mbed_mac_address((char *)netif->hwaddr);
mbed_official 10:ab9330955226 571 #endif
mbed_official 10:ab9330955226 572 netif->hwaddr_len = ETHARP_HWADDR_LEN;
mbed_official 10:ab9330955226 573
mbed_official 10:ab9330955226 574 /* maximum transfer unit */
mbed_official 10:ab9330955226 575 netif->mtu = 1500;
mbed_official 10:ab9330955226 576
mbed_official 10:ab9330955226 577 /* device capabilities */
mbed_official 10:ab9330955226 578 // TODOETH: check if the flags are correct below
mbed_official 10:ab9330955226 579 netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP;
mbed_official 10:ab9330955226 580
mbed_official 10:ab9330955226 581 /* Initialize the hardware */
mbed_official 10:ab9330955226 582 netif->state = &k64f_enetdata;
mbed_official 10:ab9330955226 583 err = low_level_init(netif);
mbed_official 10:ab9330955226 584 if (err != ERR_OK)
mbed_official 10:ab9330955226 585 return err;
mbed_official 10:ab9330955226 586
mbed_official 10:ab9330955226 587 #if LWIP_NETIF_HOSTNAME
mbed_official 10:ab9330955226 588 /* Initialize interface hostname */
mbed_official 10:ab9330955226 589 netif->hostname = "lwipk64f";
mbed_official 10:ab9330955226 590 #endif /* LWIP_NETIF_HOSTNAME */
mbed_official 10:ab9330955226 591
mbed_official 10:ab9330955226 592 netif->name[0] = 'e';
mbed_official 10:ab9330955226 593 netif->name[1] = 'n';
mbed_official 10:ab9330955226 594
mbed_official 10:ab9330955226 595 netif->output = k64f_etharp_output;
mbed_official 10:ab9330955226 596 netif->linkoutput = k64f_low_level_output;
mbed_official 10:ab9330955226 597
mbed_official 10:ab9330955226 598 /* CMSIS-RTOS, start tasks */
mbed_official 10:ab9330955226 599 #ifdef CMSIS_OS_RTX
mbed_official 10:ab9330955226 600 memset(k64f_enetdata.xTXDCountSem.data, 0, sizeof(k64f_enetdata.xTXDCountSem.data));
mbed_official 10:ab9330955226 601 k64f_enetdata.xTXDCountSem.def.semaphore = k64f_enetdata.xTXDCountSem.data;
mbed_official 10:ab9330955226 602 #endif
mbed_official 10:ab9330955226 603 k64f_enetdata.xTXDCountSem.id = osSemaphoreCreate(&k64f_enetdata.xTXDCountSem.def, ENET_TX_RING_LEN);
mbed_official 10:ab9330955226 604
mbed_official 10:ab9330955226 605 LWIP_ASSERT("xTXDCountSem creation error", (k64f_enetdata.xTXDCountSem.id != NULL));
mbed_official 10:ab9330955226 606
mbed_official 10:ab9330955226 607 err = sys_mutex_new(&k64f_enetdata.TXLockMutex);
mbed_official 10:ab9330955226 608 LWIP_ASSERT("TXLockMutex creation error", (err == ERR_OK));
mbed_official 10:ab9330955226 609
mbed_official 10:ab9330955226 610 /* Packet receive task */
mbed_official 10:ab9330955226 611 err = sys_sem_new(&k64f_enetdata.RxReadySem, 0);
mbed_official 10:ab9330955226 612 LWIP_ASSERT("RxReadySem creation error", (err == ERR_OK));
mbed_official 10:ab9330955226 613 sys_thread_new("receive_thread", packet_rx, netif->state, DEFAULT_THREAD_STACKSIZE, RX_PRIORITY);
mbed_official 10:ab9330955226 614
mbed_official 10:ab9330955226 615 /* Transmit cleanup task */
mbed_official 10:ab9330955226 616 err = sys_sem_new(&k64f_enetdata.TxCleanSem, 0);
mbed_official 10:ab9330955226 617 LWIP_ASSERT("TxCleanSem creation error", (err == ERR_OK));
mbed_official 10:ab9330955226 618 sys_thread_new("txclean_thread", packet_tx, netif->state, DEFAULT_THREAD_STACKSIZE, TX_PRIORITY);
mbed_official 10:ab9330955226 619
mbed_official 10:ab9330955226 620 /* PHY monitoring task */
mbed_official 10:ab9330955226 621 sys_thread_new("phy_thread", k64f_phy_task, netif, DEFAULT_THREAD_STACKSIZE, PHY_PRIORITY);
mbed_official 10:ab9330955226 622
mbed_official 10:ab9330955226 623 /* Allow the PHY task to detect the initial link state and set up the proper flags */
mbed_official 10:ab9330955226 624 osDelay(10);
mbed_official 10:ab9330955226 625
mbed_official 10:ab9330955226 626 return ERR_OK;
mbed_official 10:ab9330955226 627 }
mbed_official 10:ab9330955226 628
mbed_official 10:ab9330955226 629 void eth_arch_enable_interrupts(void) {
mbed_official 31:da93f0f73711 630 //NVIC_SetPriority(ENET_Receive_IRQn, 6U);
mbed_official 31:da93f0f73711 631 //NVIC_SetPriority(ENET_Transmit_IRQn, 6U);
mbed_official 10:ab9330955226 632 }
mbed_official 10:ab9330955226 633
mbed_official 10:ab9330955226 634 void eth_arch_disable_interrupts(void) {
mbed_official 10:ab9330955226 635
mbed_official 15:82aaaa2f4d5c 636 }
mbed_official 15:82aaaa2f4d5c 637
mbed_official 10:ab9330955226 638 /**
mbed_official 10:ab9330955226 639 * @}
mbed_official 10:ab9330955226 640 */
mbed_official 10:ab9330955226 641
mbed_official 10:ab9330955226 642 /* --------------------------------- End Of File ------------------------------ */
mbed_official 10:ab9330955226 643