Ejemplo n.º 1
0
/*
 * This task will handle interrupts generated by the ethernet phy.  All
 * requests to the phy must be routed through the mac over the internal
 * MII bus, making dealing with the phy a slow process that is not
 * well suited for a real ISR.  Generally, this task runs briefly after
 * a phy interrupt, then suspends itself until the next interrupt.
 */
void ethLinkTask(void *pParams)
{

	/* Wait for a phy interrupt to un-suspend */
	vTaskSuspend(NULL);
	LWIP_DEBUGF(NETIF_DEBUG, ("eth0 ISR: Ethernet link down\n"));

	while (1) {

		if (EthernetPHYRead(ETH_BASE, ETH_STATUS_REG) &
				    ETH_PHY_LINK_UP) {

			/*
			 * Read the phy's interrupt register to clear the
			 * interrupts.
			 */
			EthernetPHYRead(ETH_BASE,ETH_INTSTATUS_REG);

			HWREGBITW(&ETHDevice[0], ETH_LINK_OK) = 1;
			LWIP_DEBUGF(NETIF_DEBUG, ("eth0 link status: Ethernet link up\n"));
			EthernetIntClear(ETH_BASE, ETH_INT_PHY);
			EthernetIntEnable(ETH_BASE, ETH_INT_PHY);

			/* Wait for a phy interrupt to un-suspend */
			vTaskSuspend(NULL);
			LWIP_DEBUGF(NETIF_DEBUG, ("eth0 ISR: Ethernet link down\n"));
		}

		else
			vTaskDelay(ETH_LINK_TASK_WAIT_MS);
	}
}
Ejemplo n.º 2
0
//*****************************************************************************
//
// In this function, the hardware should be initialized.
// Called from stellarisif_init().
//
// @param netif the already initialized lwip network interface structure
//        for this ethernetif
//!
//! \return None.
//!
//*****************************************************************************
static err_t low_level_init(struct netif *netif)
{
	ETHServiceTaskDisable(0);

	// set MAC hardware address length
	netif->hwaddr_len = ETHARP_HWADDR_LEN;

	LWIP_DEBUGF(NETIF_DEBUG, ("low_level_transmit: frame sent\n"));

	// set MAC hardware address
	ETHServiceTaskMACAddress(0, &(netif->hwaddr[0]));

	LWIP_DEBUGF(NETIF_DEBUG, ("low_level_init: MAC address is %"X8_F"%"X8_F"%"X8_F"%"X8_F"%"X8_F"%"X8_F"\n",
					netif->hwaddr[0],netif->hwaddr[1],netif->hwaddr[2],
					netif->hwaddr[3],netif->hwaddr[4],netif->hwaddr[5]));

	// maximum transfer unit
	netif->mtu = ETH_MTU;

	LWIP_DEBUGF(NETIF_DEBUG, ("low_level_init: MTU set to %"U16_F"\n",netif->mtu));

	// device capabilities
	// don't set NETIF_FLAG_ETHARP if this device is not an ethernet one
	netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;

	/* Create task to handle link status changes */
	xTaskCreate(ethLinkTask,
		    (signed char *)"eth-link",
		    DEFAULT_STACK_SIZE,
		    NULL,
		    ETH_LINK_TASK_PRIORITY,
		    &ethLink_task_handle);

	// Create the task that handles the incoming packets.
	if (pdPASS == xTaskCreate(ethernetif_input,
			( signed portCHAR * ) "eth-in",
			netifINTERFACE_TASK_STACK_SIZE,
			(void *)netif,
			netifINTERFACE_TASK_PRIORITY,
			NULL))
	{
		ETHServiceTaskEnable(0);
		LWIP_DEBUGF(NETIF_DEBUG, ("low_level_input: Waiting for Ethernet to become ready\n"));
		ETHServiceTaskWaitReady(0);
		EthernetPHYRead(ETH_BASE,ETH_INTSTATUS_REG);
		EthernetIntClear(ETH_BASE, ETH_INT_PHY);
		netif->flags |= NETIF_FLAG_LINK_UP;
		LWIP_DEBUGF(NETIF_DEBUG, ("low_level_init: Ethernet link is up\n"));
		EthernetIntEnable(ETH_BASE, ETH_INT_PHY);

		return ERR_OK;

	}
	else
	{
		LWIP_DEBUGF(NETIF_DEBUG, ("low_level_init: create receive task error\n"));
		return ERR_IF;
	}

}
static  void  AppTaskStart (void  *p_arg)
{
    CPU_INT32U  clk_freq;
    CPU_INT32U  ulPHYMR0;
    CPU_INT32U  cnts;
    OS_ERR      err;

   (void)&p_arg;

    BSP_Init();                                                 /* Initialize BSP functions                             */
    CPU_Init();                                                 /* Initialize the uC/CPU services                       */
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);                  /* Enable and Reset the Ethernet Controller.            */
    SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);
    ulPHYMR0 = EthernetPHYRead(ETH_BASE, PHY_MR0);              /* Power Down PHY                                       */
    EthernetPHYWrite(ETH_BASE, PHY_MR0, ulPHYMR0 | PHY_MR0_PWRDN);
    SysCtlPeripheralDeepSleepDisable(SYSCTL_PERIPH_ETH);
    clk_freq = BSP_CPUClkFreq();                                /* Determine SysTick reference freq.                    */
    cnts     = clk_freq / (CPU_INT32U)OSCfg_TickRate_Hz;        /* Determine nbr SysTick increments                     */
    OS_CPU_SysTickInit(cnts);                                   /* Init uC/OS periodic time src (SysTick).              */
    CPU_TS_TmrFreqSet(clk_freq);
    
   // #if(MICROSD_EN == 1)
    /* Mount the file system, using logical disk 0 */
    //f_mount(0, &g_sFatFs);
    /* Create a new log.txt file */
    //CmdLineProcess(g_cCmdBuf);
  //  #endif

    /* Enable Wheel ISR Interrupt */
    AppRobotMotorDriveSensorEnable();
    
    
    
  /* 
    Call your API here 
  */  
    OSTaskCreateNew((OS_TCB     *)&AppTaskOneTCB, (CPU_CHAR   *)"App Task One", (OS_TASK_PTR ) AppTaskOne, (void       *) 0, (OS_PRIO     ) APP_TASK_ONE_PRIO, (CPU_STK    *)&AppTaskOneStk[0], (CPU_STK_SIZE) APP_TASK_ONE_STK_SIZE / 10u, (CPU_STK_SIZE) APP_TASK_ONE_STK_SIZE, (OS_MSG_QTY  ) 0u, (OS_TICK     ) 0u, (void       *)(CPU_INT32U) 1, (OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR     *)&err, (OS_PERIOD) 5000);
    OSTaskCreateNew((OS_TCB     *)&AppTaskTwoTCB, (CPU_CHAR   *)"App Task Two", (OS_TASK_PTR ) AppTaskTwo, (void       *) 0, (OS_PRIO     ) APP_TASK_TWO_PRIO, (CPU_STK    *)&AppTaskTwoStk[0], (CPU_STK_SIZE) APP_TASK_TWO_STK_SIZE / 10u, (CPU_STK_SIZE) APP_TASK_TWO_STK_SIZE, (OS_MSG_QTY  ) 0u, (OS_TICK     ) 0u, (void       *) (CPU_INT32U) 2, (OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR     *)&err,(OS_PERIOD) 7000);
    OSTaskCreateNew((OS_TCB     *)&AppTaskThreeTCB, (CPU_CHAR   *)"App Task Three", (OS_TASK_PTR ) AppTaskThree, (void       *) 0, (OS_PRIO     ) APP_TASK_THREE_PRIO, (CPU_STK    *)&AppTaskThreeStk[0], (CPU_STK_SIZE) APP_TASK_THREE_STK_SIZE / 10u, (CPU_STK_SIZE) APP_TASK_THREE_STK_SIZE, (OS_MSG_QTY  ) 0u, (OS_TICK     ) 0u, (void       *)(CPU_INT32U) 3, (OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR     *)&err, (OS_PERIOD) 7000);
    OSTaskCreateNew((OS_TCB     *)&AppTaskFourTCB, (CPU_CHAR   *)"App Task Four", (OS_TASK_PTR ) AppTaskFour, (void       *) 0, (OS_PRIO     ) APP_TASK_FOUR_PRIO, (CPU_STK    *)&AppTaskFourStk[0], (CPU_STK_SIZE) APP_TASK_FOUR_STK_SIZE / 10u, (CPU_STK_SIZE) APP_TASK_FOUR_STK_SIZE, (OS_MSG_QTY  ) 0u, (OS_TICK     ) 0u, (void       *) (CPU_INT32U) 4, (OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR     *)&err,(OS_PERIOD) 10000);
    
    OSTaskDel((OS_TCB *)0, &err);
}
static void
lwIPSoftMDIXTimer(void *pvArg)
{
    //
    // Service the MDIX timer.
    //
    if((EthernetPHYRead(ETH_BASE, PHY_MR1) & PHY_MR1_LINK) == 0)
    {
        g_ulMDIXTimer += SOFT_MDIX_INTERVAL;

        //
        // See if there has not been a link for 2 seconds.
        //
        if(g_ulMDIXTimer >= 2000)
        {
            //
            // There has not been a link for 2 seconds, so flip the MDI/MDIX
            // switch.  This is handled automatically by Fury rev A2, but is
            // harmless.
            //
            HWREG(ETH_BASE + MAC_O_MDIX) ^= MAC_MDIX_EN;

            //
            // Reset the MDIX timer.
            //
            g_ulMDIXTimer = 0;
        }
    }
    else
    {
        //
        // There is a link, so reset the MDIX timer.
        //
        g_ulMDIXTimer = 0;
    }

    //
    // Re-schedule the soft-MDIX timer callback function timeout.
    //
    sys_timeout(SOFT_MDIX_INTERVAL, lwIPSoftMDIXTimer, NULL);
}
Ejemplo n.º 5
0
//*****************************************************************************
//
//! Initializes the lwIP TCP/IP stack.
//!
//! \param pucMAC is a pointer to a six byte array containing the MAC
//! address to be used for the interface.
//! \param ulIPAddr is the IP address to be used (static).
//! \param ulNetMask is the network mask to be used (static).
//! \param ulGWAddr is the Gateway address to be used (static).
//! \param ulIPMode 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
//! Stellaris Ethernet MAC, including DHCP and/or AutoIP, as configured.
//!
//! \return None.
//
//*****************************************************************************
void LWIPServiceTaskInit(void *pvParameters)
{
	struct ip_addr *ip_addr;
	struct ip_addr *net_mask;
	struct ip_addr *gw_addr;

	//struct ip_addr ip_addr_local;
	//struct ip_addr net_mask_local;

	char IPState = 0;

	char* configLoad;

	IP_CONFIG * ipCfg;

	printf("Initialisiere IP ");
	ipCfg = pvPortMalloc(sizeof(IP_CONFIG));

	configLoad = loadFromConfig(IP_CONFIG_FILE, "USE_DHCP");

#ifdef ENABLE_GRAPHIC
	vShowBootText("load ipconfig ...");
#endif

	printf("LWIPSTACK: LOAD CONFIG: (%s)\n", configLoad);
	if (configLoad == 0)
	{
		IPState = IPADDR_USE_AUTOIP;
	}
	else if (strcmp(configLoad, "true") == 0)
	{
		IPState = IPADDR_USE_DHCP;
	}
	else
	{
		IPState = IPADDR_USE_STATIC;
	}

	vPortFree(configLoad);

	// Start the TCP/IP thread & init stuff
	tcpip_init(NULL, NULL);

	vTaskDelay(100 / portTICK_RATE_MS);

	// Setup the network address values.
	if (IPState == IPADDR_USE_STATIC)
	{
		ip_addr = getAddresFromConfig("IP_ADDRESS");
		net_mask = getAddresFromConfig("IP_SUBNETMASK");
		gw_addr = getAddresFromConfig("IP_GATEWAY");
	}
#if LWIP_DHCP || LWIP_AUTOIP
	else
	{
		ip_addr = pvPortMalloc(sizeof(struct ip_addr));
		net_mask = pvPortMalloc(sizeof(struct ip_addr));
		gw_addr = pvPortMalloc(sizeof(struct ip_addr));
	}
#endif

	// Create, configure and add the Ethernet controller interface with
	// default settings.
	// WARNING: This must only be run after the OS has been started.
	// Typically this is the case, however, if not, you must place this
	// in a post-OS initialization
	// @SEE http://lwip.wikia.com/wiki/Initialization_using_tcpip.c

	printf("Starting NETIF ... \n");
#ifdef ENABLE_GRAPHIC
	vShowBootText("starting Network ...");
#endif
	netif_add(&lwip_netif, ip_addr, net_mask, gw_addr, NULL, ethernetif_init,
			tcpip_input);
	netif_set_default(&lwip_netif);

	printf("NETIF UP\n");

	// Start DHCP, if enabled.
#if LWIP_DHCP
	if (IPState == IPADDR_USE_DHCP)
	{
#ifdef ENABLE_GRAPHIC
		vShowBootText("waiting for DHCP ...");
#endif
		printf("Starte DHCP Client ...     ");
		if (dhcp_start(&lwip_netif) == ERR_OK)
		{
			printf("[ok]\n");
		}
		else
		{
			printf("[fail]\n");
		}
	}
#endif

	// Start AutoIP, if enabled and DHCP is not.
#if LWIP_AUTOIP
	if (IPState == IPADDR_USE_AUTOIP)
	{
		printf ("Setzte Auto IP (NICHT DHCP) ...\n");
		autoip_start(&lwip_netif);
	}
#endif

	if (IPState == IPADDR_USE_STATIC)
	{
		// Bring the interface up.
		netif_set_up(&lwip_netif);
	}
	vTaskDelay(1000 / portTICK_RATE_MS);

	while (0 == netif_is_up(&lwip_netif))
	{
		vTaskDelay(5000 / portTICK_RATE_MS);
		if (0 == netif_is_up(&lwip_netif))
		{
			dhcp_renew(&lwip_netif);
		}
	}

	printnetif(&lwip_netif);

	configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_SERVER");
	if (strcmp(configLoad, "true") == 0)
	{
		/* Initialize HTTP, DNS, SNTP */
		printf("HTTPD Starten ...\n");
		httpd_init();
	}
	vPortFree(configLoad);

#if ENABLE_SNTP
	printf("SNTP Starten ...\n");
	sntp_init();
#endif

#if ENABLE_DNS
	printf("DNS Starten ...\n");
	dns_init();
#endif

#if ENABLE_NET_BIOS
	printf("NETBIOS Starten ...\n");
	netbios_init();
#endif

	printf("Dienste gestartet ...\n");

#ifdef ENABLE_GRAPHIC
	configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_CLIENT");
	if (strcmp(configLoad, "true") == 0)
	{
		vShowBootText("loading menu ...");
		vLoadMenu();
	}
	else
	{
		vShowBootText("ready for requests ...");
	}
	vPortFree(configLoad);
#endif

	// Nothing else to do.  No point hanging around.
	while (1)
	{
		vTaskDelay(500 / portTICK_RATE_MS);
		if (EthernetPHYRead(ETH_BASE, PHY_MR1) & ETH_PHY_LINK_UP)
		{
			if (!(netif_is_up(&lwip_netif)))
			{
				// set link up flag
				netif_set_up(&lwip_netif);
#ifdef ENABLE_GRAPHIC
				vShowBootText("activate networkinterface ...");
				configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_CLIENT");
				if (strcmp(configLoad, "true") == 0)
				{
					vShowBootText("loading menu ...");
					vLoadMenu();
				}
				else
				{
					vShowBootText("ready for requests ...");
				}
				vPortFree(configLoad);
#endif
				if (IPState == IPADDR_USE_DHCP)
				{
					printf("DHCP Adresse anfordern ...  ");
					if (dhcp_renew(&lwip_netif) == ERR_OK)
					{
						printf("[ok]\n");
						printnetif(&lwip_netif);
					}
					else
					{
						printf("[fail]\n");
					}
				}
			}
		}
		else
		{
			if (netif_is_up(&lwip_netif))
			{
#ifdef ENABLE_GRAPHIC
				vShowBootText("no networkconnection!!");
#endif
				printf("Deaktiviere Netzwerkinterface ...  ");
				netif_set_down(&lwip_netif);
			}
		}

	}
}
static void
lwIPServiceTimers(void)
{
    //
    // Service the MDIX timer.
    //
    if((EthernetPHYRead(ETH_BASE, PHY_MR1) & PHY_MR1_LINK) == 0)
    {
        //
        // See if there has not been a link for 2 seconds.
        //
        if((g_ulLocalTimer - g_ulMDIXTimer) >= 2000)
        {
            //
            // There has not been a link for 2 seconds, so flip the MDI/MDIX
            // switch.  This is handled automatically by Fury rev A2, but is
            // harmless.
            //
            HWREG(ETH_BASE + MAC_O_MDIX) ^= MAC_MDIX_EN;

            //
            // Reset the MDIX timer.
            //
            g_ulMDIXTimer = g_ulLocalTimer;
        }
    }
    else
    {
        //
        // There is a link, so reset the MDIX timer.
        //
        g_ulMDIXTimer = g_ulLocalTimer;
    }

    //
    // Service the host timer.
    //
#if HOST_TMR_INTERVAL
    if((g_ulLocalTimer - g_ulHostTimer) >= HOST_TMR_INTERVAL)
    {
        g_ulHostTimer = g_ulLocalTimer;
        lwIPHostTimerHandler();
    }
#endif

    //
    // Service the ARP timer.
    //
#if LWIP_ARP
    if((g_ulLocalTimer - g_ulARPTimer) >= ARP_TMR_INTERVAL)
    {
        g_ulARPTimer = g_ulLocalTimer;
        etharp_tmr();
    }
#endif

    //
    // Service the TCP timer.
    //
#if LWIP_TCP
    if((g_ulLocalTimer - g_ulTCPTimer) >= TCP_TMR_INTERVAL)
    {
        g_ulTCPTimer = g_ulLocalTimer;
        tcp_tmr();
    }
#endif

    //
    // Service the AutoIP timer.
    //
#if LWIP_AUTOIP
    if((g_ulLocalTimer - g_ulAutoIPTimer) >= AUTOIP_TMR_INTERVAL)
    {
        g_ulAutoIPTimer = g_ulLocalTimer;
        autoip_tmr();
    }
#endif

    //
    // Service the DCHP Coarse Timer.
    //
#if LWIP_DHCP
    if((g_ulLocalTimer - g_ulDHCPCoarseTimer) >= DHCP_COARSE_TIMER_MSECS)
    {
        g_ulDHCPCoarseTimer = g_ulLocalTimer;
        dhcp_coarse_tmr();
    }
#endif

    //
    // Service the DCHP Fine Timer.
    //
#if LWIP_DHCP
    if((g_ulLocalTimer - g_ulDHCPFineTimer) >= DHCP_FINE_TIMER_MSECS)
    {
        g_ulDHCPFineTimer = g_ulLocalTimer;
        dhcp_fine_tmr();
    }
#endif

    //
    // Service the IP Reassembly Timer
    //
#if IP_REASSEMBLY
    if((g_ulLocalTimer - g_ulIPReassemblyTimer) >= IP_TMR_INTERVAL)
    {
        g_ulIPReassemblyTimer = g_ulLocalTimer;
        ip_reass_tmr();
    }
#endif

    //
    // Service the IGMP Timer
    //
#if LWIP_IGMP
    if((g_ulLocalTimer - g_ulIGMPTimer) >= IGMP_TMR_INTERVAL)
    {
        g_ulIGMPTimer = g_ulLocalTimer;
        igmp_tmr();
    }
#endif

    //
    // Service the DNS Timer
    //
#if LWIP_DNS
    if((g_ulLocalTimer - g_ulDNSTimer) >= DNS_TMR_INTERVAL)
    {
        g_ulDNSTimer = g_ulLocalTimer;
        dns_tmr();
    }
#endif
}
Ejemplo n.º 7
0
//*****************************************************************************
//
//! Service the lwIP timers.
//!
//! This function services all of the lwIP periodic timers, including TCP and
//! Host timers.  This should be called from the lwIP context, which may be
//! the Ethernet interrupt (in the case of a non-RTOS system) or the lwIP
//! thread, in the event that an RTOS is used.
//!
//! \return None.
//
//*****************************************************************************
static void lwIPServiceTimers(struct netif *netif)
{
	LWIP_DRIVER_DATA* drv_data = (LWIP_DRIVER_DATA*)netif;
	MAC_Type* mac = (MAC_Type*)netif->state;
    //
    // Service the MDIX timer.
    //
    if(drv_data->timer_main > drv_data->timer_mdix)
    {
        //
        // See if there has not been a link for 2 seconds.
        //
        if((EthernetPHYRead(mac, PHY_MR1) & PHY_MR1_LINK) == 0)
        {
            // There has not been a link for 2 seconds, so flip the MDI/MDIX
            // switch.  This is handled automatically by Fury rev A2, but is
            // harmless.
            //
        	mac->MDIX  ^= MAC_MDIX_EN;
       	    if (netif->flags & NETIF_FLAG_LINK_UP)
			{
#if LWIP_DHCP
                autoip_stop(netif);
                dhcp_start(netif);
#endif
				netif_set_link_down(netif);
			}
		}
		else
			netif_set_link_up(netif);
        //
        // Reset the MDIX timer.
        //
    	drv_data->timer_mdix = drv_data->timer_main + 2048;
    }

    //
    // Service the host timer.
    //
#if HOST_TMR_INTERVAL
    if(drv_data->timer_main > drv_data->timer_host )
    {
    	drv_data->timer_host = drv_data->timer_main + HOST_TMR_INTERVAL;
        lwIPHostTimerHandler();
    }
#endif

    //
    // Service the ARP timer.
    //
#if LWIP_ARP
    if(drv_data->timer_main > drv_data->timer_arp)
    {
    	drv_data->timer_arp = drv_data->timer_main + ARP_TMR_INTERVAL;
        etharp_tmr();
    }
#endif

    //
    // Service the TCP timer.
    //
#if LWIP_TCP
    if(drv_data->timer_main > drv_data->timer_tcp)
    {
    	drv_data->timer_tcp = drv_data->timer_main + TCP_TMR_INTERVAL;
        tcp_tmr();
    }
#endif

    //
    // Service the AutoIP timer.
    //
#if LWIP_AUTOIP
    if(drv_data->timer_main - drv_data->timer_autoIP)
    {
    	drv_data->timer_autoIP = drv_data->timer_main + AUTOIP_TMR_INTERVAL;
        autoip_tmr();
    }
#endif

    //
    // Service the DCHP Coarse Timer.
    //
#if LWIP_DHCP
    if(drv_data->timer_main > drv_data->timer_DHCPCoarse)
    {
    	drv_data->timer_DHCPCoarse = drv_data->timer_main + DHCP_COARSE_TIMER_MSECS;
        dhcp_coarse_tmr();
    }
#endif

    //
    // Service the DCHP Fine Timer.
    //
#if LWIP_DHCP
    if(drv_data->timer_main > drv_data->timer_DHCPFine)
    {
    	drv_data->timer_DHCPFine = drv_data->timer_main + DHCP_FINE_TIMER_MSECS;
        dhcp_fine_tmr();
    }
#endif
}
Ejemplo n.º 8
0
//*****************************************************************************
//
// This example demonstrates the use of the Ethernet Controller with the uIP
// TCP/IP stack.
//
//*****************************************************************************
int
main(void)
{
    uip_ipaddr_t ipaddr;
    static struct uip_eth_addr sTempAddr;
    long lPeriodicTimer, lARPTimer, lPacketLength;
    unsigned long ulUser0, ulUser1;
    unsigned long ulTemp;

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Initialize the OLED display.
    //
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("Ethernet with uIP", 12, 0, 15);

    //
    // Enable and Reset the Ethernet Controller.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
    SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);

    //
    // Enable Port F for Ethernet LEDs.
    //  LED0        Bit 3   Output
    //  LED1        Bit 2   Output
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    //
    // Configure SysTick for a periodic interrupt.
    //
    SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ);
    SysTickEnable();
    SysTickIntEnable();

    //
    // Intialize the Ethernet Controller and disable all Ethernet Controller
    // interrupt sources.
    //
    EthernetIntDisable(ETH_BASE, (ETH_INT_PHY | ETH_INT_MDIO | ETH_INT_RXER |
                       ETH_INT_RXOF | ETH_INT_TX | ETH_INT_TXER | ETH_INT_RX));
    ulTemp = EthernetIntStatus(ETH_BASE, false);
    EthernetIntClear(ETH_BASE, ulTemp);

    //
    // Initialize the Ethernet Controller for operation.
    //
    EthernetInitExpClk(ETH_BASE, SysCtlClockGet());

    //
    // Configure the Ethernet Controller for normal operation.
    // - Full Duplex
    // - TX CRC Auto Generation
    // - TX Padding Enabled
    //
    EthernetConfigSet(ETH_BASE, (ETH_CFG_TX_DPLXEN | ETH_CFG_TX_CRCEN |
                                 ETH_CFG_TX_PADEN));

    //
    // Wait for the link to become active.
    // 
    RIT128x96x4StringDraw("Waiting for Link", 12, 8, 15);
    ulTemp = EthernetPHYRead(ETH_BASE, PHY_MR1);
    while((ulTemp & 0x0004) == 0)
    {
        ulTemp = EthernetPHYRead(ETH_BASE, PHY_MR1);
    }
    RIT128x96x4StringDraw("Link Established", 12, 16, 15);

    //
    // Enable the Ethernet Controller.
    //
    EthernetEnable(ETH_BASE);

    //
    // Enable the Ethernet interrupt.
    //
    IntEnable(INT_ETH);

    //
    // Enable the Ethernet RX Packet interrupt source.
    //
    EthernetIntEnable(ETH_BASE, ETH_INT_RX);

    //
    // Enable all processor interrupts.
    //
    IntMasterEnable();

    //
    // Initialize the uIP TCP/IP stack.
    //
    uip_init();
#ifdef USE_STATIC_IP
    uip_ipaddr(ipaddr, DEFAULT_IPADDR0, DEFAULT_IPADDR1, DEFAULT_IPADDR2,
               DEFAULT_IPADDR3);
    uip_sethostaddr(ipaddr);
    DisplayIPAddress(ipaddr, 18, 24);
    uip_ipaddr(ipaddr, DEFAULT_NETMASK0, DEFAULT_NETMASK1, DEFAULT_NETMASK2,
               DEFAULT_NETMASK3);
    uip_setnetmask(ipaddr);
#else
    uip_ipaddr(ipaddr, 0, 0, 0, 0);
    uip_sethostaddr(ipaddr);
    DisplayIPAddress(ipaddr, 18, 24);
    uip_ipaddr(ipaddr, 0, 0, 0, 0);
    uip_setnetmask(ipaddr);
#endif

    //
    // Configure the hardware MAC address for Ethernet Controller filtering of
    // incoming packets.
    //
    // For the Ethernet Eval Kits, the MAC address will be stored in the
    // non-volatile USER0 and USER1 registers.  These registers can be read
    // using the FlashUserGet function, as illustrated below.
    //
    FlashUserGet(&ulUser0, &ulUser1);
    if((ulUser0 == 0xffffffff) || (ulUser1 == 0xffffffff))
    {
        //
        // We should never get here.  This is an error if the MAC address has
        // not been programmed into the device.  Exit the program.
        //
        RIT128x96x4StringDraw("MAC Address", 0, 16, 15);
        RIT128x96x4StringDraw("Not Programmed!", 0, 24, 15);
        while(1)
        {
        }
    }

    //
    // Convert the 24/24 split MAC address from NV ram into a 32/16 split MAC
    // address needed to program the hardware registers, then program the MAC
    // address into the Ethernet Controller registers.
    //
    sTempAddr.addr[0] = ((ulUser0 >>  0) & 0xff);
    sTempAddr.addr[1] = ((ulUser0 >>  8) & 0xff);
    sTempAddr.addr[2] = ((ulUser0 >> 16) & 0xff);
    sTempAddr.addr[3] = ((ulUser1 >>  0) & 0xff);
    sTempAddr.addr[4] = ((ulUser1 >>  8) & 0xff);
    sTempAddr.addr[5] = ((ulUser1 >> 16) & 0xff);

    //
    // Program the hardware with it's MAC address (for filtering).
    //
    EthernetMACAddrSet(ETH_BASE, (unsigned char *)&sTempAddr);
    uip_setethaddr(sTempAddr);

    //
    // Initialize the TCP/IP Application (e.g. web server).
    //
    httpd_init();

#ifndef USE_STATIC_IP
    //
    // Initialize the DHCP Client Application.
    //
    dhcpc_init(&sTempAddr.addr[0], 6);
    dhcpc_request();
#endif

    //
    // Main Application Loop.
    //
    lPeriodicTimer = 0;
    lARPTimer = 0;
    while(true)
    {
        //
        // Wait for an event to occur.  This can be either a System Tick event,
        // or an RX Packet event.
        //
        while(!g_ulFlags)
        {
        }

        //
        // If SysTick, Clear the SysTick interrupt flag and increment the
        // timers.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_SYSTICK) == 1)
        {
            HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 0;
            lPeriodicTimer += SYSTICKMS;
            lARPTimer += SYSTICKMS;
        }

        //
        // Check for an RX Packet and read it.
        //
        lPacketLength = EthernetPacketGetNonBlocking(ETH_BASE, uip_buf,
                                                     sizeof(uip_buf));
        if(lPacketLength > 0)
        {
            //
            // Set uip_len for uIP stack usage.
            //
            uip_len = (unsigned short)lPacketLength;

            //
            // Clear the RX Packet event and renable RX Packet interrupts.
            //
            if(HWREGBITW(&g_ulFlags, FLAG_RXPKT) == 1)
            {
                HWREGBITW(&g_ulFlags, FLAG_RXPKT) = 0;
                EthernetIntEnable(ETH_BASE, ETH_INT_RX);
            }

            //
            // Process incoming IP packets here.
            //
            if(BUF->type == htons(UIP_ETHTYPE_IP))
            {
                uip_arp_ipin();
                uip_input();

                //
                // If the above function invocation resulted in data that
                // should be sent out on the network, the global variable
                // uip_len is set to a value > 0.
                //
                if(uip_len > 0)
                {
                    uip_arp_out();
                    EthernetPacketPut(ETH_BASE, uip_buf, uip_len);
                    uip_len = 0;
                }
            }

            //
            // Process incoming ARP packets here.
            //
            else if(BUF->type == htons(UIP_ETHTYPE_ARP))
            {
                uip_arp_arpin();

                //
                // If the above function invocation resulted in data that
                // should be sent out on the network, the global variable
                // uip_len is set to a value > 0.
                //
                if(uip_len > 0)
                {
                    EthernetPacketPut(ETH_BASE, uip_buf, uip_len);
                    uip_len = 0;
                }
            }
        }

        //
        // Process TCP/IP Periodic Timer here.
        //
        if(lPeriodicTimer > UIP_PERIODIC_TIMER_MS)
        {
            lPeriodicTimer = 0;
            for(ulTemp = 0; ulTemp < UIP_CONNS; ulTemp++)
            {
                uip_periodic(ulTemp);

                //
                // If the above function invocation resulted in data that
                // should be sent out on the network, the global variable
                // uip_len is set to a value > 0.
                //
                if(uip_len > 0)
                {
                    uip_arp_out();
                    EthernetPacketPut(ETH_BASE, uip_buf, uip_len);
                    uip_len = 0;
                }
            }

#if UIP_UDP
            for(ulTemp = 0; ulTemp < UIP_UDP_CONNS; ulTemp++)
            {
                uip_udp_periodic(ulTemp);

                //
                // If the above function invocation resulted in data that
                // should be sent out on the network, the global variable
                // uip_len is set to a value > 0.
                //
                if(uip_len > 0)
                {
                    uip_arp_out();
                    EthernetPacketPut(ETH_BASE, uip_buf, uip_len);
                    uip_len = 0;
                }
            }
#endif // UIP_UDP
        }

        //
        // Process ARP Timer here.
        //
        if(lARPTimer > UIP_ARP_TIMER_MS)
        {
            lARPTimer = 0;
            uip_arp_timer();
        }
    }
}
Ejemplo n.º 9
0
unsigned int ethernet_link(void)
{
  return (EthernetPHYRead(ETH_BASE, PHY_MR1) & 0x04) ? 1 : 0;
}