Esempio n. 1
0
static err_t
low_level_init(struct netif *netif)
{
	unsigned mac_address = (unsigned)(netif->state);
	struct xemac_s *xemac;
	xlltemacif_s *xlltemacif;

	xlltemacif = mem_malloc(sizeof *xlltemacif);
	if (xlltemacif == NULL) {
		LWIP_DEBUGF(NETIF_DEBUG, ("xlltemacif_init: out of memory\r\n"));
		return ERR_MEM;
	}

	xemac = mem_malloc(sizeof *xemac);
	if (xemac == NULL) {
		LWIP_DEBUGF(NETIF_DEBUG, ("xlltemacif_init: out of memory\r\n"));
		return ERR_MEM;
	}

	xemac->state = (void *)xlltemacif;
	xemac->topology_index = xtopology_find_index(mac_address);
	xemac->type = xemac_type_xps_ll_temac;

	xlltemacif->send_q = NULL;
	xlltemacif->recv_q = pq_create_queue();
	if (!xlltemacif->recv_q)
		return ERR_MEM;

	/* maximum transfer unit */
#ifdef USE_JUMBO_FRAMES
	netif->mtu = XTE_JUMBO_MTU - XTE_HDR_SIZE;
#else
	netif->mtu = XTE_MTU - XTE_HDR_SIZE;
#endif
#if LWIP_IGMP
	netif->igmp_mac_filter = xlltemacif_mac_filter_update;
#endif

	/* broadcast capability */
	netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;

#if LWIP_IGMP
	netif->flags |= NETIF_FLAG_IGMP;
#endif

#if !NO_SYS
	sys_sem_new(&xemac->sem_rx_data_available, 0);
#endif
	/* initialize the mac */
	init_lltemac(xlltemacif, netif);

	/* figure out if the system has DMA */
	if (XLlTemac_IsDma(&xlltemacif->lltemac)) {
		/* initialize the DMA engine */
		init_sdma(xemac);
	} else if (XLlTemac_IsFifo(&xlltemacif->lltemac)) {
		/* initialize the locallink FIFOs */
		init_ll_fifo(xemac);
	} else {
		/* should not occur */
		LWIP_DEBUGF(NETIF_DEBUG, ("xlltemacif_init: lltemac is not configured with DMA or FIFO\r\n"));
		return ERR_IF;
	}

	/* replace the state in netif (currently the emac baseaddress)
	 * with the xlltemac instance pointer.
	 */
	netif->state = (void *)xemac;

	return ERR_OK;
}
/**
*
* This function demonstrates the usage of the TEMAC by sending and receiving
* frames in polled mode.
*
*
* @param    TemacDeviceId is device ID of the Temac Device , typically
*           XPAR_<TEMAC_instance>_DEVICE_ID value from xparameters.h
*
* @return   XST_SUCCESS to indicate success, otherwise XST_FAILURE
*
* @note     None.
*
******************************************************************************/
int TemacPolledExample(u16 TemacDeviceId, u16 FifoDeviceId)
{
	int Status;
	XLlTemac_Config *MacCfgPtr;
	u32 Rdy;
	int LoopbackSpeed;

	/*************************************/
	/* Setup device for first-time usage */
	/*************************************/

	/*
	 * Initialize the FIFO and TEMAC instance
	 */
	MacCfgPtr = XLlTemac_LookupConfig(TemacDeviceId);
	Status = XLlTemac_CfgInitialize(&TemacInstance, MacCfgPtr,
					MacCfgPtr->BaseAddress);

	if (Status != XST_SUCCESS) {
		TemacUtilErrorTrap("Error in initialize");
		return XST_FAILURE;
	}
	XLlFifo_Initialize(&FifoInstance,
			    XLlTemac_LlDevBaseAddress(&TemacInstance));

	/*
	 * Check whether the IPIF interface is correct for this example
	 */
	if (!XLlTemac_IsFifo(&TemacInstance)) {
		TemacUtilErrorTrap
			("Device HW not configured for FIFO direct mode\r\n");
		return XST_FAILURE;
	}

	/*
	 * Set the MAC  address
	 */
	Status = XLlTemac_SetMacAddress(&TemacInstance, (u8 *) TemacMAC);
	if (Status != XST_SUCCESS) {
		TemacUtilErrorTrap("Error setting MAC address");
		return XST_FAILURE;
	}

        /* Make sure the hard temac is ready */
	Rdy = XLlTemac_ReadReg(TemacInstance.Config.BaseAddress,
			       XTE_RDY_OFFSET);
	while ((Rdy & XTE_RDY_HARD_ACS_RDY_MASK) == 0) {
		Rdy = XLlTemac_ReadReg(TemacInstance.Config.BaseAddress,
				       XTE_RDY_OFFSET);
	}

        /*
         * Set PHY to loopback, speed depends on phy type.
         * MII is 100 and all others are 1000.
         */
        if (XLlTemac_GetPhysicalInterface(&TemacInstance) == XTE_PHY_TYPE_MII)
        {
                LoopbackSpeed = TEMAC_LOOPBACK_SPEED;
        } else {
                LoopbackSpeed = TEMAC_LOOPBACK_SPEED_1G;
        }
        Status = TemacUtilEnterLoopback(&TemacInstance, LoopbackSpeed);
        if (Status != XST_SUCCESS) {
                TemacUtilErrorTrap("Error setting the PHY loopback");
                return XST_FAILURE;
        }

        /*
         * Set PHY<-->MAC data clock
         */
        XLlTemac_SetOperatingSpeed(&TemacInstance, (u16)LoopbackSpeed);

	/*
	 * Setting the operating speed of the MAC needs a delay.  There
	 * doesn't seem to be register to poll, so please consider this
	 * during your application design.
	 */
	TemacUtilPhyDelay(2);

	/****************************/
	/* Run through the examples */
	/****************************/

	/*
	 * Run the Single Frame polled example
	 */
	Status = TemacSingleFramePolledExample();
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Run the Multiple Frames polled example
	 */
	Status = TemacMultipleFramesPolledExample();
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	return XST_SUCCESS;


}