示例#1
0
void vuIP_Task( void *pvParameters )
{
    portBASE_TYPE i;
    unsigned long ulNewEvent = 0UL;
    unsigned long ulUIP_Events = 0UL;

    ( void ) pvParameters;

    /* Initialise the uIP stack. */
    prvInitialise_uIP();

    /* Initialise the MAC. */
    vInitEmac();

    while( lEMACWaitForLink() != pdPASS )
    {
        vTaskDelay( uipINIT_WAIT );
    }

    for( ;; )
    {
        if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )
        {
            /* Is there received data ready to be processed? */
            uip_len = ( unsigned short ) ulEMACRead();

            if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
            {
                /* Standard uIP loop taken from the uIP manual. */
                if( xHeader->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();
                        vEMACWrite();
                    }
                }
                else if( xHeader->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 )
                    {
                        vEMACWrite();
                    }
                }
            }
            else
            {
                ulUIP_Events &= ~uipETHERNET_RX_EVENT;
            }
        }

        if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
        {
            ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;

            for( i = 0; i < UIP_CONNS; i++ )
            {
                uip_periodic( i );

                /* 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();
                    vEMACWrite();
                }
            }
        }

        /* Call the ARP timer function every 10 seconds. */
        if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
        {
            ulUIP_Events &= ~uipARP_TIMER_EVENT;
            uip_arp_timer();
        }

        if( ulUIP_Events == pdFALSE )
        {
            xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
            ulUIP_Events |= ulNewEvent;
        }
    }
}
示例#2
0
文件: uIP_Task.c 项目: ammarkham/moos
void vuIP_Task( void *pvParameters )
{
long i;
unsigned long ulNewEvent = 0UL, ulUIP_Events = 0UL;
unsigned short usPacketLength;

	/* Just to prevent compiler warnings about the unused parameter. */
	( void ) pvParameters;

	/* Initialise the uIP stack, configuring for web server usage. */
	prvInitialise_uIP();

	/* Initialise the MAC and PHY. */
	vEMACInit();

	for( ;; )
	{
		/* Is there received data ready to be processed? */
		usPacketLength = usEMACRead();

		/* Statements to be executed if data has been received on the Ethernet. */
		if( ( usPacketLength > 0U ) && ( uip_buf != NULL ) )
		{
			uip_len = usPacketLength;
			
			if( xHeader->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();
					vEMACWrite();
				}
			}
			else if( xHeader->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 )
				{
					vEMACWrite();
				}
			}
		}
		else
		{
			/* Clear the RX event latched in ulUIP_Events - if one was latched. */
			ulUIP_Events &= ~uipETHERNET_RX_EVENT;
		}

		/* Statements to be executed if the TCP/IP period timer has expired. */
		if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
		{
			ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;

			if( uip_buf != NULL )
			{
				for( i = 0; i < UIP_CONNS; i++ )
				{
					uip_periodic( i );
	
					/* 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();
						vEMACWrite();
					}
				}
			}
		}

		/* Statements to be executed if the ARP timer has expired. */
		if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
		{
			ulUIP_Events &= ~uipARP_TIMER_EVENT;
			uip_arp_timer();
		}

		/* If all latched events have been cleared - block until another event
		occurs. */
		if( ulUIP_Events == pdFALSE )
		{
			xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
			ulUIP_Events |= ulNewEvent;
		}
	}
}