Пример #1
0
/**
 * Should be called at the beginning of the program to set up the
 * network interface. It calls the function prvLowLevelInit() to do the
 * actual setup of the hardware.
 *
 * This function should be passed as a parameter to netif_add().
 *
 * @param pxNetIf the lwip network interface structure for this ethernetif
 * @return ERR_OK if the loopif is initialized
 *		 ERR_MEM if private data couldn't be allocated
 *		 any other err_t on error
 */
err_t ethernetif_init( struct netif *pxNetIf )
{
err_t xReturn = ERR_OK;

	/* This is taken from lwIP example code and therefore does not conform
	to the FreeRTOS coding standard. */
	
struct xEthernetIf *pxEthernetIf;

	LWIP_ASSERT( "pxNetIf != NULL", ( pxNetIf != NULL ) );
	
	pxEthernetIf = mem_malloc( sizeof( struct xEthernetIf ) );
	if( pxEthernetIf == NULL ) 
	{
		LWIP_DEBUGF(NETIF_DEBUG, ( "ethernetif_init: out of memory\n" ) );
		xReturn = ERR_MEM;
	}
	else
	{
		#if LWIP_NETIF_HOSTNAME
		{
			/* Initialize interface hostname */
			pxNetIf->hostname = "lwip";
		}
		#endif /* LWIP_NETIF_HOSTNAME */

		pxNetIf->state = pxEthernetIf;
		pxNetIf->name[ 0 ] = IFNAME0;
		pxNetIf->name[ 1 ] = IFNAME1;

		/* We directly use etharp_output() here to save a function call.
		* You can instead declare your own function an call etharp_output()
		* from it if you have to do some checks before sending (e.g. if link
		* is available...) */
		pxNetIf->output = etharp_output;
		pxNetIf->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
		pxNetIf->hwaddr_len = ETHARP_HWADDR_LEN;
		pxNetIf->mtu = netifMAX_MTU;
		pxNetIf->linkoutput = prvLowLevelOutput;

		pxEthernetIf->ethaddr = ( struct eth_addr * ) &( pxNetIf->hwaddr[ 0 ] );
  
		/* initialize the hardware */
		prvLowLevelInit( pxNetIf );

		/* Was an interface opened? */
		if( pxOpenedInterfaceHandle == NULL )
		{
			/* Probably an invalid adapter number was defined in 
			FreeRTOSConfig.h. */
			xReturn = ERR_VAL;
			configASSERT( pxOpenedInterfaceHandle );
		}
	}

	return xReturn;
}
Пример #2
0
/**
 * Should be called at the beginning of the program to set up the
 * network interface. It calls the function ftmac100_Init() to do the
 * actual setup of the hardware.
 *
 * This function should be passed as a parameter to pxNetIf_add().
 *
 * @param pxNetIf the lwip network interface structure for this etherpxNetIf
 * @return ERR_OK if the loopif is initialized
 *		 ERR_MEM if private data couldn't be allocated
 *		 any other err_t on error
 */
err_t ftMac100_init( struct netif *pxNetIf )
{
	err_t xReturn = ERR_OK;

	LWIP_ASSERT( "pxNetIf != NULL", ( pxNetIf != NULL ) );

	pgMac100If = mem_malloc( sizeof( struct xFtmac100If ) );
	if( pgMac100If == NULL )
	{
		LWIP_DEBUGF(NETIF_DEBUG, ( "ftmac100_init: out of memory\n" ) );
		xReturn = ERR_MEM;
	}
	else
	{
		#if LWIP_NETIF_HOSTNAME
		{
			/* Initialize interface hostname */
			pxNetIf->hostname = "lwip";
		}
		#endif /* LWIP_NETIF_HOSTNAME */

		pgMac100If->netIf = pxNetIf;

		pxNetIf->state = pgMac100If;
		pxNetIf->name[ 0 ] = IFNAME0;
		pxNetIf->name[ 1 ] = IFNAME1;

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

		/* set MAC hardware address */
		pxNetIf->hwaddr[ 0 ] = pgMac100If->hwaddr[ 0 ] = 0xc3;
		pxNetIf->hwaddr[ 1 ] = pgMac100If->hwaddr[ 1 ] = 0x10;
		pxNetIf->hwaddr[ 2 ] = pgMac100If->hwaddr[ 2 ] = 0xda;
		pxNetIf->hwaddr[ 3 ] = pgMac100If->hwaddr[ 3 ] = 0xce;
		pxNetIf->hwaddr[ 4 ] = pgMac100If->hwaddr[ 4 ] = 0x3f;
		pxNetIf->hwaddr[ 5 ] = pgMac100If->hwaddr[ 5 ] = 0x69;

		/* device capabilities */
		pxNetIf->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;

		/* maximum transfer unit */
		pxNetIf->mtu = netifMAX_MTU;

		/* We directly use etharp_output() here to save a function call.
		* You can instead declare your own function an call etharp_output()
		* from it if you have to do some checks before sending (e.g. if link
		* is available...) */
		pxNetIf->output = etharp_output;
		pxNetIf->linkoutput = prvLowLevelOutput;

		ftMac100_alloc_buffers( );

		pgMac100If->rx_pointer = 0;
		pgMac100If->tx_clean_pointer = 0;
		pgMac100If->tx_pointer = 0;
		pgMac100If->tx_pending = 0;

		/* initialize the hardware */
		prvLowLevelInit( pgMac100If );

		/* Hardware ready now, create task for receive packets */
		if( ( xReturn = sys_sem_new( &pgMac100If->tx_sem, 1 ) ) != ERR_OK )
		{
			return xReturn;
		}
		else if( ( xReturn = sys_sem_new( &pgMac100If->rx_sem, 0 ) ) != ERR_OK )
		{
			return xReturn;
		}
		else if( sys_thread_new( "mac100rx", ftMac100_rx_task, pgMac100If, FTMAC100_RX_STACK_SIZE,
					 FTMAC100_RX_TASK_PRIORITY ) == NULL )
		{
			xReturn = ERR_MEM;
		}
	}

	return xReturn;
}