NXP LPC1768 Ethernet driver for lwip and CMSIS-RTOS

Dependents:   EthernetInterface EthernetInterface EthernetInterface_RSF EthernetInterface ... more

Legacy Networking Libraries

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

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

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

Software that is described herein is for illustrative purposes only
which provides customers with programming information regarding the
products. This software is supplied "AS IS" without any warranties.
NXP Semiconductors assumes no responsibility or liability for the
use of the software, conveys no license or title under any patent,
copyright, or mask work right to the product. NXP Semiconductors
reserves the right to make changes in the software without
notification. NXP Semiconductors also make no representation or
warranty that such application will be suitable for the specified
use without further testing or modification.

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Mon Sep 22 17:30:30 2014 +0100
Parent:
19:007f4e6b2776
Child:
21:10cdd9fe0509
Commit message:
Synchronized with git revision cb3999ca5e34d491101071a32bfc0916f5a77fe7

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

[NET, HAL] K64F - update files to use address of enet peripheral (not instance as required by KSDK v1.0)

Changed in this revision

arch/TARGET_Freescale/fsl_enet_driver.c Show annotated file Show diff for this revision Revisions of this file
arch/TARGET_Freescale/hardware_init_MK64F12.c Show annotated file Show diff for this revision Revisions of this file
arch/TARGET_Freescale/k64f_emac.c Show annotated file Show diff for this revision Revisions of this file
arch/TARGET_Freescale/k64f_emac_config.h Show annotated file Show diff for this revision Revisions of this file
--- a/arch/TARGET_Freescale/fsl_enet_driver.c	Fri Sep 19 13:45:16 2014 +0100
+++ b/arch/TARGET_Freescale/fsl_enet_driver.c	Mon Sep 22 17:30:30 2014 +0100
@@ -395,11 +395,8 @@
     /* Get device number and check the parameter*/
     devNumber = enetIfPtr->deviceNumber;
 
-    /* Store the global ENET structure for ISR input parameters for instance 0*/
-    if (!devNumber)
-    {
-        enetIfHandle = enetIfPtr;
-    }
+    /* Store the global ENET structure for ISR input parameters */
+    enetIfHandle = enetIfPtr;
 
     /* Turn on ENET module clock gate */
     CLOCK_SYS_EnableEnetClock(0U);
--- a/arch/TARGET_Freescale/hardware_init_MK64F12.c	Fri Sep 19 13:45:16 2014 +0100
+++ b/arch/TARGET_Freescale/hardware_init_MK64F12.c	Mon Sep 22 17:30:30 2014 +0100
@@ -50,33 +50,33 @@
     }
 
     /* Configure gpio*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 12, kPortMuxAlt4);  /*!< ENET RMII0_RXD1/MII0_RXD1*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 13, kPortMuxAlt4);  /*!< ENET RMII0_RXD0/MII0_RXD0*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 14, kPortMuxAlt4);  /*!< ENET RMII0_CRS_DV/MII0_RXDV*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 15, kPortMuxAlt4);  /*!< ENET RMII0_TXEN/MII0_TXEN*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 16, kPortMuxAlt4);  /*!< ENET RMII0_TXD0/MII0_TXD0*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 17, kPortMuxAlt4);  /*!< ENET RMII0_TXD01/MII0_TXD1*/
-    PORT_HAL_SetMuxMode(HW_PORTB, 0, kPortMuxAlt4);   /*!< ENET RMII0_MDIO/MII0_MDIO*/
-    PORT_HAL_SetOpenDrainCmd(HW_PORTB,0, true);   /*!< ENET RMII0_MDC/MII0_MDC*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 12, kPortMuxAlt4);  /*!< ENET RMII0_RXD1/MII0_RXD1*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 13, kPortMuxAlt4);  /*!< ENET RMII0_RXD0/MII0_RXD0*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 14, kPortMuxAlt4);  /*!< ENET RMII0_CRS_DV/MII0_RXDV*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 15, kPortMuxAlt4);  /*!< ENET RMII0_TXEN/MII0_TXEN*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 16, kPortMuxAlt4);  /*!< ENET RMII0_TXD0/MII0_TXD0*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 17, kPortMuxAlt4);  /*!< ENET RMII0_TXD01/MII0_TXD1*/
+    PORT_HAL_SetMuxMode(PORTB_BASE, 0, kPortMuxAlt4);   /*!< ENET RMII0_MDIO/MII0_MDIO*/
+    PORT_HAL_SetOpenDrainCmd(PORTB_BASE,0, true);   /*!< ENET RMII0_MDC/MII0_MDC*/
 
     // Added for FRDM-K64F
-    PORT_HAL_SetPullMode(HW_PORTB, 0, kPortPullUp);
-    PORT_HAL_SetPullCmd(HW_PORTB, 0, true);
+    PORT_HAL_SetPullMode(PORTB_BASE, 0, kPortPullUp);
+    PORT_HAL_SetPullCmd(PORTB_BASE, 0, true);
   
-    PORT_HAL_SetMuxMode(HW_PORTB, 1, kPortMuxAlt4);
+    PORT_HAL_SetMuxMode(PORTB_BASE, 1, kPortMuxAlt4);
     /* Configure GPIO for MII interface */
-    PORT_HAL_SetMuxMode(HW_PORTA, 9, kPortMuxAlt4);   /*!< ENET MII0_RXD3*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 10, kPortMuxAlt4);   /*!< ENET MII0_RXD2*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 11, kPortMuxAlt4);   /*!< ENET MII0_RXCLK*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 24, kPortMuxAlt4);   /*!< ENET MII0_TXD2*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 25, kPortMuxAlt4);   /*!< ENET MII0_TXCLK*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 26, kPortMuxAlt4);   /*!< ENET MII0_TXD3*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 27, kPortMuxAlt4);   /*!< ENET MII0_CRS*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 28, kPortMuxAlt4);   /*!< ENET MII0_TXER*/
-    PORT_HAL_SetMuxMode(HW_PORTA, 29, kPortMuxAlt4);   /*!< ENET MII0_COL*/  
+    PORT_HAL_SetMuxMode(PORTA_BASE, 9, kPortMuxAlt4);   /*!< ENET MII0_RXD3*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 10, kPortMuxAlt4);   /*!< ENET MII0_RXD2*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 11, kPortMuxAlt4);   /*!< ENET MII0_RXCLK*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 24, kPortMuxAlt4);   /*!< ENET MII0_TXD2*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 25, kPortMuxAlt4);   /*!< ENET MII0_TXCLK*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 26, kPortMuxAlt4);   /*!< ENET MII0_TXD3*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 27, kPortMuxAlt4);   /*!< ENET MII0_CRS*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 28, kPortMuxAlt4);   /*!< ENET MII0_TXER*/
+    PORT_HAL_SetMuxMode(PORTA_BASE, 29, kPortMuxAlt4);   /*!< ENET MII0_COL*/
 #if FSL_FEATURE_ENET_SUPPORT_PTP
-    PORT_HAL_SetMuxMode(HW_PORTC, (16 + ENET_TIMER_CHANNEL_NUM), kPortMuxAlt4); /* ENET ENET0_1588_TMR0*/
-    PORT_HAL_SetDriveStrengthMode(HW_PORTC, (16 + ENET_TIMER_CHANNEL_NUM), kPortHighDriveStrength); 
+    PORT_HAL_SetMuxMode(PORTC_BASE, (16 + ENET_TIMER_CHANNEL_NUM), kPortMuxAlt4); /* ENET ENET0_1588_TMR0*/
+    PORT_HAL_SetDriveStrengthMode(PORTC_BASE, (16 + ENET_TIMER_CHANNEL_NUM), kPortHighDriveStrength);
 #endif
 
     /* Open ENET clock gate*/
--- a/arch/TARGET_Freescale/k64f_emac.c	Fri Sep 19 13:45:16 2014 +0100
+++ b/arch/TARGET_Freescale/k64f_emac.c	Mon Sep 22 17:30:30 2014 +0100
@@ -148,7 +148,7 @@
   if (bidx == RX_PBUF_AUTO_INDEX)
     k64f_enet->rx_fill_index = idx;
 
-  enet_hal_active_rxbd(BOARD_DEBUG_ENET_INSTANCE);
+  enet_hal_active_rxbd(BOARD_DEBUG_ENET_INSTANCE_ADDR);
 
   LWIP_DEBUGF(UDP_LPC_EMAC | LWIP_DBG_TRACE,
     ("k64f_rxqueue_pbuf: pbuf packet queued: %p (free desc=%d)\n", p,
@@ -296,7 +296,7 @@
 static err_t low_level_init(struct netif *netif)
 {
   enet_dev_if_t * enetIfPtr;
-  uint32_t device = BOARD_DEBUG_ENET_INSTANCE;
+  uint32_t device = BOARD_DEBUG_ENET_INSTANCE_ADDR;
   enet_rxbd_config_t rxbdCfg;
   enet_txbd_config_t txbdCfg;
   enet_phy_speed_t phy_speed;
@@ -305,10 +305,10 @@
   k64f_init_eth_hardware();
   
   /* Initialize device*/
-  enetIfPtr = (enet_dev_if_t *)&enetDevIf[device];
+  enetIfPtr = (enet_dev_if_t *)&enetDevIf[BOARD_DEBUG_ENET_INSTANCE];
   enetIfPtr->deviceNumber = device;
-  enetIfPtr->macCfgPtr = &g_enetMacCfg[device];
-  enetIfPtr->phyCfgPtr = &g_enetPhyCfg[device];
+  enetIfPtr->macCfgPtr = &g_enetMacCfg[BOARD_DEBUG_ENET_INSTANCE];
+  enetIfPtr->phyCfgPtr = &g_enetPhyCfg[BOARD_DEBUG_ENET_INSTANCE];
   enetIfPtr->macApiPtr = &g_enetMacApi;
   enetIfPtr->phyApiPtr = (void *)&g_enetPhyApi;
   memcpy(enetIfPtr->macCfgPtr->macAddr, (char*)netif->hwaddr, kEnetMacAddrLen);
@@ -317,7 +317,7 @@
   enetIfPtr->macContextPtr = (enet_mac_context_t *)calloc(1, sizeof(enet_mac_context_t));
   if (!enetIfPtr->macContextPtr) {
     return ERR_BUF;
-  }  
+  }
 
   /* Initialize enet buffers*/
   if(k64f_rx_setup(netif, &rxbdCfg) != ERR_OK) {
@@ -353,7 +353,7 @@
   BW_ENET_TCR_FDEN(enetIfPtr->deviceNumber, phy_duplex == kEnetFullDuplex ? kEnetCfgFullDuplex : kEnetCfgHalfDuplex);
 
   /* Enable Ethernet module*/
-  enet_hal_config_ethernet(device, true, true);
+  enet_hal_config_ethernet(BOARD_DEBUG_ENET_INSTANCE_ADDR, true, true);
 
   /* Active Receive buffer descriptor must be done after module enable*/
   enet_hal_active_rxbd(enetIfPtr->deviceNumber);
@@ -380,7 +380,7 @@
 {
   /*Clear interrupt*/
   enet_hal_clear_interrupt(((enet_dev_if_t *)enetIfPtr)->deviceNumber, kEnetTxFrameInterrupt);
-  sys_sem_signal(&k64f_enetdata.TxCleanSem);    
+  sys_sem_signal(&k64f_enetdata.TxCleanSem);
 }
 
 /**
@@ -393,7 +393,7 @@
  * \return ERR_OK or error code
  */
 err_t k64f_etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)
-{ 
+{
   /* Only send packet is link is up */
   if (netif->flags & NETIF_FLAG_LINK_UP)
     return etharp_output(netif, q, ipaddr);
@@ -701,7 +701,7 @@
   }
 
   k64f_enet->tx_produce_index = idx;
-  enet_hal_active_txbd(BOARD_DEBUG_ENET_INSTANCE);
+  enet_hal_active_txbd(BOARD_DEBUG_ENET_INSTANCE_ADDR);
   LINK_STATS_INC(link.xmit);
 
   /* Restore access */
@@ -844,7 +844,7 @@
 }
 
 void eth_arch_enable_interrupts(void) {
-  enet_hal_config_interrupt(BOARD_DEBUG_ENET_INSTANCE, (kEnetTxFrameInterrupt | kEnetRxFrameInterrupt), true);
+  enet_hal_config_interrupt(BOARD_DEBUG_ENET_INSTANCE_ADDR, (kEnetTxFrameInterrupt | kEnetRxFrameInterrupt), true);
   INT_SYS_EnableIRQ(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetRxfInt]]);
   INT_SYS_EnableIRQ(enet_irq_ids[BOARD_DEBUG_ENET_INSTANCE][enetIntMap[kEnetTxfInt]]);
 }
--- a/arch/TARGET_Freescale/k64f_emac_config.h	Fri Sep 19 13:45:16 2014 +0100
+++ b/arch/TARGET_Freescale/k64f_emac_config.h	Mon Sep 22 17:30:30 2014 +0100
@@ -40,6 +40,7 @@
 #define RX_BUF_ALIGNMENT              (16)
 #define TX_BUF_ALIGNMENT              (8)
 #define BOARD_DEBUG_ENET_INSTANCE     (0)
+#define BOARD_DEBUG_ENET_INSTANCE_ADDR (ENET_BASE)
 
 #define ENET_ETH_MAX_FLEN             (1522) // recommended size for a VLAN frame