/*
 * low_level_output(): Should do the actual transmission of the packet. The
 * packet is contained in the pbuf that is passed to the function. This pbuf
 * might be chained.
 */
static err_t low_level_output( struct netif *netif, struct pbuf *p )
{
struct pbuf *q;
static SemaphoreHandle_t xTxSemaphore = NULL;
err_t xReturn = ERR_OK;

	/* Parameter not used. */
	( void ) netif;

	if( xTxSemaphore == NULL )
	{
		vSemaphoreCreateBinary( xTxSemaphore );
	}

	#if ETH_PAD_SIZE
		pbuf_header( p, -ETH_PAD_SIZE );    /* drop the padding word */
	#endif

	/* Access to the EMAC is guarded using a semaphore. */
	if( xSemaphoreTake( xTxSemaphore, netifGUARD_BLOCK_TIME ) )
	{
		for( q = p; q != NULL; q = q->next )
		{
			/* Send the data from the pbuf to the interface, one pbuf at a
			time. The size of the data in each pbuf is kept in the ->len
			variable.  if q->next == NULL then this is the last pbuf in the
			chain. */
			if( !lEMACSend( q->payload, q->len, ( q->next == NULL ) ) )
			{
				xReturn = ~ERR_OK;
			}
		}

        xSemaphoreGive( xTxSemaphore );
	}


	#if ETH_PAD_SIZE
		pbuf_header( p, ETH_PAD_SIZE );     /* reclaim the padding word */
	#endif

	#if LINK_STATS
		lwip_stats.link.xmit++;
	#endif /* LINK_STATS */

    return xReturn;
}
示例#2
0
void vuIP_TASK( void *pvParameters )
{
/* The semaphore used by the EMAC ISR to indicate that an Rx frame is ready
for processing. */
xSemaphoreHandle xSemaphore = NULL;
portBASE_TYPE xARPTimer;
unsigned portBASE_TYPE uxPriority;
static volatile portTickType xStartTime, xCurrentTime;

	/* Initialize the uIP TCP/IP stack. */
	uip_init();
	uip_arp_init();
	
	/* Initialize the HTTP server. */
	httpd_init();

	/* Initialise the local timers. */
	xStartTime = xTaskGetTickCount();
	xARPTimer = 0;

	/* Initialise the EMAC.  A semaphore will be returned when this is
	successful. This routine contains code that polls status bits.  If the
	Ethernet cable is not plugged in then this can take a considerable time.
	To prevent this starving lower priority tasks of processing time we
	lower our priority prior to the call, then raise it back again once the
	initialisation is complete. */
	uxPriority = uxTaskPriorityGet( NULL );
	vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
	while( xSemaphore == NULL )
	{
		xSemaphore = xEMACInit();
	}
	vTaskPrioritySet( NULL, uxPriority );

	for( ;; )
	{
		/* Let the network device driver read an entire IP packet
		into the uip_buf. If it returns > 0, there is a packet in the
		uip_buf buffer. */
		uip_len = ulEMACPoll();

		/* Was a packet placed in the uIP buffer? */
		if( uip_len > 0 )
		{
			/* A packet is present in the uIP buffer. We call the
			appropriate ARP functions depending on what kind of packet we
			have received. If the packet is an IP packet, we should call
			uip_input() as well. */
			if( pucUIP_Buffer->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();
					lEMACSend();
				}
			}
			else if( pucUIP_Buffer->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 )
				{	
					lEMACSend();
				}
			}
		}
		else
		{
			/* The poll function returned 0, so no packet was
			received. Instead we check if it is time that we do the
			periodic processing. */
			xCurrentTime = xTaskGetTickCount();

			if( ( xCurrentTime - xStartTime ) >= RT_CLOCK_SECOND )
			{
				portBASE_TYPE i;

				/* Reset the timer. */
				xStartTime = xCurrentTime;

				/* Periodic check of all connections. */
				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();
						lEMACSend();
					}
				}

				#if UIP_UDP
					for( i = 0; i < UIP_UDP_CONNS; i++ )
					{
						uip_udp_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();
							tapdev_send();
						}
					}
				#endif /* UIP_UDP */

				/* Periodically call the ARP timer function. */
				if( ++xARPTimer == uipARP_FREQUENCY )
				{	
					uip_arp_timer();
					xARPTimer = 0;
				}
			}
			else
			{				
				/* We did not receive a packet, and there was no periodic
				processing to perform.  Block for a fixed period.  If a packet
				is received during this period we will be woken by the ISR
				giving us the Semaphore. */
				xSemaphoreTake( xSemaphore, uipMAX_BLOCK_TIME );
			}
		}
	}
}
示例#3
0
void vuIP_Task( void *pvParameters )
{
portBASE_TYPE i;
uip_ipaddr_t xIPAddr;
struct timer periodic_timer, arp_timer;

	/* Initialise the uIP stack. */
	timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
	timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
	uip_init();
	uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
	uip_sethostaddr( xIPAddr );
	httpd_init();

	/* Initialise the MAC. */
	do
    {
		vTaskDelay( uipINIT_WAIT );
		xEMACSemaphore = xEMACInit();        
    } while( xEMACSemaphore == NULL );

	for( ;; )
	{
		/* Is there received data ready to be processed? */
		uip_len = ulEMACPoll();
		
		if( uip_len > 0 )
		{
			/* 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();
					lEMACSend();
				}
			}
			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 )
				{
					lEMACSend();
				}
			}
		}
		else
		{
			if( timer_expired( &periodic_timer ) )
			{
				timer_reset( &periodic_timer );
				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();
						lEMACSend();
					}
				}	
	
				/* Call the ARP timer function every 10 seconds. */
				if( timer_expired( &arp_timer ) )
				{
					timer_reset( &arp_timer );
					uip_arp_timer();
				}
			}
			else
			{			
				/* We did not receive a packet, and there was no periodic
				processing to perform.  Block for a fixed period.  If a packet
				is received during this period we will be woken by the ISR
				giving us the Semaphore. */
				xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );			
			}
		}
	}
}
示例#4
0
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
  (void)netif;
  
  // struct ethernetif *ethernetif = netif->state;
  struct pbuf *q;


  /* MAKINGTHINGS: add */
  static xSemaphoreHandle xTxSemaphore = NULL;
  err_t xReturn = ERR_OK;

  /* MAKINGTHINGS: initiate transfer(); */
  if( xTxSemaphore == NULL )
  {
    vSemaphoreCreateBinary( xTxSemaphore );
  }

  
#if ETH_PAD_SIZE
  pbuf_header(p, -ETH_PAD_SIZE);			/* drop the padding word */
#endif

  /* MAKINGTHINGS: Remove */
  /*
  for(q = p; q != NULL; q = q->next) {
    * Send the data from the pbuf to the interface, one pbuf at a
       time. The size of the data in each pbuf is kept in the ->len
       variable. *
    send data from(q->payload, q->len);
  }
  
  signal that packet should be sent();
  */

  /* MAKINGTHINGS: Add */
  /* Access to the EMAC is guarded using a semaphore. */
  if( xSemaphoreTake( xTxSemaphore, netifGUARD_BLOCK_TIME ) )
  {
          for( q = p; q != NULL; q = q->next )
          {
                  /* Send the data from the pbuf to the interface, one pbuf at a 
                  time. The size of the data in each pbuf is kept in the ->len 
                  variable.  if q->next == NULL then this is the last pbuf in the
                  chain. */
                  if( !lEMACSend( q->payload, q->len, ( q->next == NULL ) ) )
                  {
                          xReturn = ~ERR_OK;
                  }
          }

  xSemaphoreGive( xTxSemaphore );
  }


#if ETH_PAD_SIZE
  pbuf_header(p, ETH_PAD_SIZE);			/* reclaim the padding word */
#endif
  
#if LINK_STATS
  lwip_stats.link.xmit++;
#endif /* LINK_STATS */      

  /* MakingThings: Remove */
  // return ERR_OK;

  /* MakingThings: Add */
  return xReturn;

}