/** * Creates task to feed data from interrupt to lwIP, * initializes EMAC0, then initializes lwIP */ void init_ethernet(void){/*{{{*/ { // Enable Ethernet hardware/*{{{*/ uint32_t user0, user1; /** * Enable ethernet * See page 160 of spmu298a */ MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EMAC0); MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_EMAC0); //Enable internal PHY MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EPHY0); MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_EPHY0); // Set Ethernet LED pinouts // See Page 269 of spmu298a.pdf MAP_GPIOPinConfigure(GPIO_PF0_EN0LED0); MAP_GPIOPinConfigure(GPIO_PF4_EN0LED1); GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4); // Busy wait until MAC ready while(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_EMAC0) == 0); //Using builtin PHY, so don't need to call GPIOPinTypeEthernetMII() MAP_EMACPHYConfigSet(EMAC0_BASE, EMAC_PHY_TYPE_INTERNAL|EMAC_PHY_INT_MDIX_EN|EMAC_PHY_AN_100B_T_FULL_DUPLEX); // Initialize MAC (see spmu363a.pdf) // Maybe should optimize burst size MAP_EMACInit(EMAC0_BASE, g_syshz, EMAC_BCONFIG_MIXED_BURST|EMAC_BCONFIG_PRIORITY_FIXED, 4, 4, 0); // Set options // Tune parameters MAP_EMACConfigSet(EMAC0_BASE, (EMAC_CONFIG_FULL_DUPLEX | EMAC_CONFIG_CHECKSUM_OFFLOAD | EMAC_CONFIG_7BYTE_PREAMBLE | EMAC_CONFIG_IF_GAP_96BITS | EMAC_CONFIG_USE_MACADDR0 | EMAC_CONFIG_SA_FROM_DESCRIPTOR | EMAC_CONFIG_100MBPS| EMAC_CONFIG_BO_LIMIT_1024), (EMAC_MODE_RX_STORE_FORWARD | EMAC_MODE_TX_STORE_FORWARD | EMAC_MODE_TX_THRESHOLD_64_BYTES | EMAC_MODE_RX_THRESHOLD_64_BYTES), 0); //Mac Address saved in user0 and user1 by default MAP_FlashUserGet(&user0, &user1); mac_addr[0] = user0 & 0xFF; mac_addr[1] = user0 >> 8 & 0xFF; mac_addr[2] = user0 >> 16 & 0xFF; mac_addr[3] = user1 & 0xFF; mac_addr[4] = user1 >> 8 & 0xFF; mac_addr[5] = user1 >> 16 & 0xFF; MAP_EMACAddrSet(EMAC0_BASE, 0, mac_addr ); //Explicitly Disable PTP EMACTimestampDisable(EMAC0_BASE); }/*}}}*/ // Lower priority of ISR so *FromISR functions can be safely called MAP_IntPrioritySet(INT_EMAC0, ETH_ISR_PRIO); tcpip_init(tcpip_init_cb, NULL); }/*}}}*/
//***************************************************************************** // //! Initializes the lwIP TCP/IP stack. //! //! \param ui32SysClkHz is the current system clock rate in Hz. //! \param pui8MAC is a pointer to a six byte array containing the MAC //! address to be used for the interface. //! \param ui32IPAddr is the IP address to be used (static). //! \param ui32NetMask is the network mask to be used (static). //! \param ui32GWAddr is the Gateway address to be used (static). //! \param ui32IPMode is the IP Address Mode. \b IPADDR_USE_STATIC will force //! static IP addressing to be used, \b IPADDR_USE_DHCP will force DHCP with //! fallback to Link Local (Auto IP), while \b IPADDR_USE_AUTOIP will force //! Link Local only. //! //! This function performs initialization of the lwIP TCP/IP stack for the //! Ethernet MAC, including DHCP and/or AutoIP, as configured. //! //! \return None. // //***************************************************************************** void lwIPInit(uint32_t ui32SysClkHz, const uint8_t *pui8MAC, uint32_t ui32IPAddr, uint32_t ui32NetMask, uint32_t ui32GWAddr, uint32_t ui32IPMode) { // // Check the parameters. // #if LWIP_DHCP && LWIP_AUTOIP ASSERT((ui32IPMode == IPADDR_USE_STATIC) || (ui32IPMode == IPADDR_USE_DHCP) || (ui32IPMode == IPADDR_USE_AUTOIP)); #elif LWIP_DHCP ASSERT((ui32IPMode == IPADDR_USE_STATIC) || (ui32IPMode == IPADDR_USE_DHCP)); #elif LWIP_AUTOIP ASSERT((ui32IPMode == IPADDR_USE_STATIC) || (ui32IPMode == IPADDR_USE_AUTOIP)); #else ASSERT(ui32IPMode == IPADDR_USE_STATIC); #endif // // Enable the ethernet peripheral. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EMAC0); MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_EMAC0); // // Enable the internal PHY if it's present and we're being // asked to use it. // if((EMAC_PHY_CONFIG & EMAC_PHY_TYPE_MASK) == EMAC_PHY_TYPE_INTERNAL) { // // We've been asked to configure for use with the internal // PHY. Is it present? // if(MAP_SysCtlPeripheralPresent(SYSCTL_PERIPH_EPHY0)) { // // Yes - enable and reset it. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_EPHY0); MAP_SysCtlPeripheralReset(SYSCTL_PERIPH_EPHY0); } else { // // Internal PHY is not present on this part so hang here. // while(1) { } } } // // Wait for the MAC to come out of reset. // while(!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_EMAC0)) { } // // Configure for use with whichever PHY the user requires. // MAP_EMACPHYConfigSet(EMAC0_BASE, EMAC_PHY_CONFIG); // // Initialize the MAC and set the DMA mode. // MAP_EMACInit(EMAC0_BASE, ui32SysClkHz, EMAC_BCONFIG_MIXED_BURST | EMAC_BCONFIG_PRIORITY_FIXED, 4, 4, 0); // // Set MAC configuration options. // MAP_EMACConfigSet(EMAC0_BASE, (EMAC_CONFIG_FULL_DUPLEX | EMAC_CONFIG_CHECKSUM_OFFLOAD | EMAC_CONFIG_7BYTE_PREAMBLE | EMAC_CONFIG_IF_GAP_96BITS | EMAC_CONFIG_USE_MACADDR0 | EMAC_CONFIG_SA_FROM_DESCRIPTOR | EMAC_CONFIG_BO_LIMIT_1024), (EMAC_MODE_RX_STORE_FORWARD | EMAC_MODE_TX_STORE_FORWARD | EMAC_MODE_TX_THRESHOLD_64_BYTES | EMAC_MODE_RX_THRESHOLD_64_BYTES), 0); // // Program the hardware with its MAC address (for filtering). // MAP_EMACAddrSet(EMAC0_BASE, 0, (uint8_t *)pui8MAC); // // Save the network configuration for later use by the private // initialization. // g_ui32IPMode = ui32IPMode; g_ui32IPAddr = ui32IPAddr; g_ui32NetMask = ui32NetMask; g_ui32GWAddr = ui32GWAddr; // // Initialize lwIP. The remainder of initialization is done immediately if // not using a RTOS and it is deferred to the TCP/IP thread's context if // using a RTOS. // #if NO_SYS lwIPPrivateInit(0); #else tcpip_init(lwIPPrivateInit, 0); #endif }