int main() { // Configure ethernet XEmacLite_Config *etherconfig = XEmacLite_LookupConfig(XPAR_EMACLITE_0_DEVICE_ID); XEmacLite_CfgInitialize(ðer, etherconfig, etherconfig->BaseAddress); XEmacLite_SetMacAddress(ðer, mac_address); //Set our sending MAC address XEmacLite_FlushReceive(ðer); //Clear any received messages xil_printf("\r\n%s", "Please input the desired world size:"); // receiveWorldInfo(); // Receive the world information from the user via UART int worldLoop, i; worldSize = 0; for(worldLoop = 0; worldLoop < 99999; worldLoop++){ XEmacLite_FlushReceive(ðer); //Clear any received messages tmit_buffer[14] = 0x01; // Set the type field tmit_buffer[15] = worldSize; // Add the world size to the transmit buffer worldID = worldLoop; for(i = 0; i < 4; i++){ // Add the world ID to the transmit, as it is over several bytes we need to loop through and bit shift tmit_buffer[16 + i] = worldLoop >> 8*(3-i); } sendToEthernet(6); // Send the generated buffer to the server via ethernet receiveFromEthernet(); receiveFromHardware(); receiveFromEthernet(); } return 0; }
/** * * The entry point for the EmacLite Ping reply example in polled mode. * * @param DeviceId is device ID of the XEmacLite Device. * * @return XST_FAILURE to indicate failure, otherwise XST_SUCCESS is * returned. * * @note This is in a continuous loop generating a specified number of * ping replies as defined by MAX_PING_REPLIES. * ******************************************************************************/ int EmacLitePingReplyExample(u16 DeviceId) { int Status; XEmacLite *EmacLiteInstPtr = &EmacLiteInstance; XEmacLite_Config *ConfigPtr; NumOfPingReplies = 0; /* * Initialize the EmacLite device. */ ConfigPtr = XEmacLite_LookupConfig(DeviceId); if (ConfigPtr == NULL) { return XST_FAILURE; } Status = XEmacLite_CfgInitialize(EmacLiteInstPtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the MAC address. */ XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalMacAddr); /* * Empty any existing receive frames. */ XEmacLite_FlushReceive(EmacLiteInstPtr); while (1) { /* * Wait for a Receive packet. */ while (RecvFrameLength == 0) { RecvFrameLength = XEmacLite_Recv(EmacLiteInstPtr, (u8 *)RxFrame); } /* * Process the Receive frame. */ ProcessRecvFrame(EmacLiteInstPtr); RecvFrameLength = 0; /* * If the number of ping replies sent is equal to that * specified by the user then exit out of this loop. */ if (NumOfPingReplies == MAX_PING_REPLIES) { return XST_SUCCESS; } } }
// Initialize the interface - performed at system startup // This function must set up the interface, including arranging to // handle interrupts, etc, so that it may be "started" cheaply later. static bool emaclite_init(struct cyg_netdevtab_entry *dtp) { struct eth_drv_sc *sc = (struct eth_drv_sc *)dtp->device_instance; struct emaclite_info *qi = (struct emaclite_info *)sc->driver_private; unsigned char _enaddr[6]; bool esa_ok; /* Try to read the ethernet address of the transciever ... */ #if defined(CYGPKG_REDBOOT) && defined(CYGSEM_REDBOOT_FLASH_CONFIG) esa_ok = flash_get_config(qi->esa_key, _enaddr, CONFIG_ESA); #else esa_ok = CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, qi->esa_key, _enaddr, CONFIG_ESA); #endif if (esa_ok) { memcpy(qi->enaddr, _enaddr, sizeof(qi->enaddr)); } else { /* No 'flash config' data available - use default */ diag_printf("Emaclite_ETH - Warning! Using default ESA for '%s'\n", dtp->name); } /* Initialize Xilinx driver - device id 0*/ if (XEmacLite_Initialize(&qi->dev, 0) != XST_SUCCESS) { diag_printf("Emaclite_ETH - can't initialize\n"); return false; } if (XEmacLite_SelfTest(&qi->dev) != XST_SUCCESS) { diag_printf("Emaclite_ETH - self test failed\n"); return false; } XEmacLite_SetMacAddress(&qi->dev, qi->enaddr); XEmacLite_SetSendHandler(&qi->dev, sc, emaclite_TxEvent); XEmacLite_SetRecvHandler(&qi->dev, sc, emaclite_RxEvent); #ifdef CYGPKG_NET /* Set up to handle interrupts */ cyg_drv_interrupt_create(qi->int_vector, 0, // Highest //CYGARC_SIU_PRIORITY_HIGH, (cyg_addrword_t)sc, // Data passed to ISR (cyg_ISR_t *)emaclite_isr, (cyg_DSR_t *)eth_drv_dsr, &qi->emaclite_interrupt_handle, &qi->emaclite_interrupt); cyg_drv_interrupt_attach(qi->emaclite_interrupt_handle); cyg_drv_interrupt_acknowledge(qi->int_vector); cyg_drv_interrupt_unmask(qi->int_vector); #endif /* Operating mode */ _s3esk_dev = &qi->dev; /* Initialize upper level driver for ecos */ (sc->funs->eth_drv->init)(sc, (unsigned char *)&qi->enaddr); return true; }
// // This function is called for low level "control" operations // static int emaclite_control(struct eth_drv_sc *sc, unsigned long key, void *data, int length) { struct emaclite_info *qi = (struct emaclite_info *)sc->driver_private; switch (key) { case ETH_DRV_SET_MAC_ADDRESS: XEmacLite_SetMacAddress(&qi->dev, qi->enaddr); return 0; break; default: return 1; break; } }
// Initialize the interface - performed at system startup // This function must set up the interface, including arranging to // handle interrupts, etc, so that it may be "started" cheaply later. static bool s3esk_eth_init(struct cyg_netdevtab_entry *dtp) { struct eth_drv_sc *sc = (struct eth_drv_sc *)dtp->device_instance; struct s3esk_eth_info *qi = (struct s3esk_eth_info *)sc->driver_private; //Xuint32 opt; unsigned char _enaddr[6]; bool esa_ok; // Try to read the ethernet address of the transciever ... #if defined(CYGPKG_REDBOOT) && defined(CYGSEM_REDBOOT_FLASH_CONFIG) esa_ok = flash_get_config(qi->esa_key, _enaddr, CONFIG_ESA); #else esa_ok = CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, qi->esa_key, _enaddr, CONFIG_ESA); #endif if (esa_ok) { memcpy(qi->enaddr, _enaddr, sizeof(qi->enaddr)); } else { // No 'flash config' data available - use default diag_printf("s3esk_ETH - Warning! Using default ESA for '%s'\n", dtp->name); } // Initialize Xilinx driver if (XEmacLite_Initialize(&qi->dev, XPAR_ETHERNET_MAC_DEVICE_ID) != XST_SUCCESS) { diag_printf("s3esk_ETH - can't initialize\n"); return false; } //if (XEmac_mIsSgDma(&qi->dev)) { // diag_printf("s3esk_ETH - DMA support?\n"); // return false; //} if (XEmacLite_SelfTest(&qi->dev) != XST_SUCCESS) { diag_printf("s3esk_ETH - self test failed\n"); return false; } //XEmac_ClearStats(&qi->dev); // Configure device operating mode //opt = XEM_UNICAST_OPTION | // XEM_BROADCAST_OPTION | // XEM_INSERT_PAD_OPTION | // XEM_INSERT_FCS_OPTION | // XEM_STRIP_PAD_FCS_OPTION; //if (XEmac_SetOptions(&qi->dev, opt) != XST_SUCCESS) { // diag_printf("s3esk_ETH - can't configure mode\n"); // return false; //} //if (XEmacLite_SetMacAddress(&qi->dev, qi->enaddr) != XST_SUCCESS) { // diag_printf("s3esk_ETH - can't set ESA\n"); // return false; //} XEmacLite_SetMacAddress(&qi->dev, qi->enaddr); // Set up FIFO handling routines - these are callbacks from the // Xilinx driver code which happen at interrupt time XEmacLite_SetSendHandler(&qi->dev, sc, s3esk_eth_TxEvent); XEmacLite_SetRecvHandler(&qi->dev, sc, s3esk_eth_RxEvent); //XEmac_SetErrorHandler(&qi->dev, sc, s3esk_eth_ErrEvent); #ifdef CYGPKG_NET // Set up to handle interrupts cyg_drv_interrupt_create(qi->int_vector, 0, // Highest //CYGARC_SIU_PRIORITY_HIGH, (cyg_addrword_t)sc, // Data passed to ISR (cyg_ISR_t *)s3esk_eth_isr, (cyg_DSR_t *)eth_drv_dsr, &qi->s3esk_eth_interrupt_handle, &qi->s3esk_eth_interrupt); cyg_drv_interrupt_attach(qi->s3esk_eth_interrupt_handle); cyg_drv_interrupt_acknowledge(qi->int_vector); cyg_drv_interrupt_unmask(qi->int_vector); #endif // Operating mode _s3esk_dev = &qi->dev; //if (!_eth_phy_init(qi->phy)) { // return false; //} //#ifdef CYGSEM_DEVS_ETH_POWERPC_s3esk_RESET_PHY //_eth_phy_reset(qi->phy); //#endif // Initialize upper level driver for ecos (sc->funs->eth_drv->init)(sc, (unsigned char *)&qi->enaddr); return true; }
/** * In this function, the hardware should be initialized. * Called from ethernetif_init(). * * @param pxNetIf the already initialized lwip network interface structure * for this etherpxNetIf */ static void prvLowLevelInit( struct netif *pxNetIf ) { portBASE_TYPE xStatus; extern void vInitialisePHY( XEmacLite *xemaclitep ); unsigned portBASE_TYPE uxOriginalPriority; /* Hardware initialisation can take some time, so temporarily lower the task priority to ensure other functionality is not adversely effected. The priority will get raised again before this function exits. */ uxOriginalPriority = uxTaskPriorityGet( NULL ); vTaskPrioritySet( NULL, tskIDLE_PRIORITY ); /* set MAC hardware address length */ pxNetIf->hwaddr_len = ETHARP_HWADDR_LEN; /* set MAC hardware address */ pxNetIf->hwaddr[ 0 ] = configMAC_ADDR0; pxNetIf->hwaddr[ 1 ] = configMAC_ADDR1; pxNetIf->hwaddr[ 2 ] = configMAC_ADDR2; pxNetIf->hwaddr[ 3 ] = configMAC_ADDR3; pxNetIf->hwaddr[ 4 ] = configMAC_ADDR4; pxNetIf->hwaddr[ 5 ] = configMAC_ADDR5; /* device capabilities */ pxNetIf->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; /* maximum transfer unit */ pxNetIf->mtu = netifMAX_MTU; /* Broadcast capability */ pxNetIf->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; /* Initialize the mac */ xStatus = XEmacLite_Initialize( &xEMACInstance, XPAR_EMACLITE_0_DEVICE_ID ); if( xStatus == XST_SUCCESS ) { /* Set mac address */ XEmacLite_SetMacAddress( &xEMACInstance, ( Xuint8* )( pxNetIf->hwaddr ) ); /* Flush any frames already received */ XEmacLite_FlushReceive( &xEMACInstance ); /* Set Rx, Tx interrupt handlers */ XEmacLite_SetRecvHandler( &xEMACInstance, ( void * ) pxNetIf, prvRxHandler ); XEmacLite_SetSendHandler( &xEMACInstance, NULL, prvTxHandler ); /* Enable Rx, Tx interrupts */ XEmacLite_EnableInterrupts( &xEMACInstance ); /* Install the standard Xilinx library interrupt handler itself. *NOTE* The xPortInstallInterruptHandler() API function must be used for this purpose. */ xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_EMACLITE_0_VEC_ID, ( XInterruptHandler ) XEmacLite_InterruptHandler, &xEMACInstance ); vInitialisePHY( &xEMACInstance ); /* Enable the interrupt in the interrupt controller. *NOTE* The vPortEnableInterrupt() API function must be used for this purpose. */ vPortEnableInterrupt( XPAR_INTC_0_EMACLITE_0_VEC_ID ); } /* Reset the task priority back to its original value. */ vTaskPrioritySet( NULL, uxOriginalPriority ); configASSERT( xStatus == pdPASS ); }
/** * * The entry point for the EmacLite driver to ping request example in polled * mode. This function will generate specified number of request packets as * defined in "NUM_OF_PING_REQ_PKTS. * * @param DeviceId is device ID of the XEmacLite Device. * * @return XST_FAILURE to indicate failure, otherwise it will return * XST_SUCCESS. * * @note None. * ******************************************************************************/ static int EmacLitePingReqExample(u16 DeviceId) { int Status; int Index; int Count; int EchoReplyStatus; XEmacLite_Config *ConfigPtr; XEmacLite *EmacLiteInstPtr = &EmacLiteInstance; SeqNum = 0; RecvFrameLength = 0; EchoReplyStatus = XST_FAILURE; NumOfPingReqPkts = NUM_OF_PING_REQ_PKTS; /* * Initialize the EmacLite device. */ ConfigPtr = XEmacLite_LookupConfig(DeviceId); if (ConfigPtr == NULL) { return XST_FAILURE; } Status = XEmacLite_CfgInitialize(EmacLiteInstPtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the MAC address. */ XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalMacAddr); /* * Empty any existing receive frames. */ XEmacLite_FlushReceive(EmacLiteInstPtr); while (NumOfPingReqPkts--) { /* * Introduce delay. */ Count = DELAY; while (Count--) { } /* * Send an ARP or an ICMP packet based on receive packet. */ if (SeqNum == 0) { SendArpReqFrame(EmacLiteInstPtr); } else { SendEchoReqFrame(EmacLiteInstPtr); } /* * Check next 10 packets for the correct reply. */ Index = NUM_RX_PACK_CHECK_REQ; while (Index--) { /* * Wait for a Receive packet. */ Count = NUM_PACK_CHECK_RX_PACK; while (RecvFrameLength == 0) { RecvFrameLength = XEmacLite_Recv( EmacLiteInstPtr, (u8 *)RxFrame); /* * To avoid infinite loop when no packet is * received. */ if (Count-- == 0) { break; } } /* * Process the Receive frame. */ if (RecvFrameLength != 0) { EchoReplyStatus = ProcessRecvFrame( EmacLiteInstPtr); } RecvFrameLength = 0; /* * Comes out of loop when an echo reply packet is * received. */ if (EchoReplyStatus == XST_SUCCESS) { break; } } /* * If no echo reply packet is received, it reports * request timed out. */ if (EchoReplyStatus == XST_FAILURE) { xil_printf("Packet No: %d", NUM_OF_PING_REQ_PKTS - NumOfPingReqPkts); xil_printf(" Seq NO %d Request timed out\r\n", SeqNum); } } return XST_SUCCESS; }
/** * * The main entry point for the EmacLite driver example in polled mode. * * This function will transmit/receive the Ethernet frames and verify the * data in the received frame (if the MDIO interface is configured in the * EmacLite core). * This function simply transmits a frame if the MDIO interface is not * configured in the EmacLite core. * * @param DeviceId is device ID of the XEmacLite Device , typically * XPAR_<EMAC_instance>_DEVICE_ID value from xparameters.h. * * @return XST_SUCCESS to indicate success, XST_FAILURE otherwise. * * @note None. * ******************************************************************************/ int EmacLitePolledExample(u16 DeviceId) { int Status; XEmacLite *EmacLiteInstPtr = &EmacLiteInstance; u32 PhyAddress = 0; RecvFrameLength = 0; XEmacLite_Config *ConfigPtr; /* * Initialize the EmacLite device. */ ConfigPtr = XEmacLite_LookupConfig(DeviceId); if (ConfigPtr == NULL) { return XST_FAILURE; } Status = XEmacLite_CfgInitialize(EmacLiteInstPtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the MAC address. */ XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalAddress); /* * Empty any existing receive frames. */ XEmacLite_FlushReceive(EmacLiteInstPtr); /* * Check if there is a TX buffer available, if there isn't it is an * error. */ if (XEmacLite_TxBufferAvailable(EmacLiteInstPtr) != TRUE) { return XST_FAILURE; } /* * If the MDIO is configured in the device. */ if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) { /* * Detect the PHY device and enable the MAC Loop back * in the PHY. */ PhyAddress = EmacLitePhyDetect(EmacLiteInstPtr); Status = EmacLiteEnablePhyLoopBack(EmacLiteInstPtr, PhyAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } } /* * Reset the receive frame length to zero. */ RecvFrameLength = 0; Status = EmacLiteSendFrame(EmacLiteInstPtr, EMACLITE_TEST_FRAME_SIZE); if (Status != XST_SUCCESS) { if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) { /* * Disable the MAC Loop back in the PHY. */ EmacLiteDisablePhyLoopBack(EmacLiteInstPtr, PhyAddress); return XST_FAILURE; } } /* * If the MDIO is not configured in the core then return XST_SUCCESS * as the frame has been transmitted. */ if (!XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) { return XST_SUCCESS; } /* * Poll for receive packet. */ while ((volatile u32)RecvFrameLength == 0) { RecvFrameLength = XEmacLite_Recv(EmacLiteInstPtr, (u8 *)RxFrame); } /* * Check the received frame. */ Status = EmacLiteRecvFrame(EMACLITE_TEST_FRAME_SIZE); if ((Status != XST_SUCCESS) && (Status != XST_NO_DATA)) { /* * Disable the MAC Loop back in the PHY. */ EmacLiteDisablePhyLoopBack(EmacLiteInstPtr, PhyAddress); return XST_FAILURE; } /* * Disable the MAC Loop back in the PHY. */ EmacLiteDisablePhyLoopBack(EmacLiteInstPtr, PhyAddress); return XST_SUCCESS; }
int main() { static XIntc intc; Xil_ICacheEnable(); Xil_DCacheEnable(); xil_printf("Testing UART output.\r\n"); // Camera DMA Configuration XAxiDma_Config *dmaconf = XAxiDma_LookupConfig(XPAR_AXI_DMA_0_DEVICE_ID); XAxiDma dma; XAxiDma_CfgInitialize(&dma, dmaconf); XAxiDma_Resume(&dma); XAxiDma_Reset(&dma); while(!XAxiDma_ResetIsDone(&dma)); // Initialize Video InitVideo(); // Example camera DMA read // Note - transfer MUST be 4096B // Data format is 20-bit pixel number (stored in a 32 bit integer) followed by 16-bit RGB values // This will not work until you implement camera_stream.v. // (or at least, until you have it barely working) //int resdde = XAxiDma_SimpleTransfer(&dma, (u32)((unsigned char*)&camera), 4096, XAXIDMA_DEVICE_TO_DMA); //while(XAxiDma_Busy(&dma,XAXIDMA_DEVICE_TO_DMA)); int Status; XEmacLite *EmacLiteInstPtr = &EmacLiteInstance; u32 PhyAddress = 0; RecvFrameLength = 0; XEmacLite_Config *ConfigPtr; /* * Initialize the EmacLite device. */ ConfigPtr = XEmacLite_LookupConfig(XPAR_ETHERNET_LITE_DEVICE_ID); if (ConfigPtr == NULL) { return XST_FAILURE; } Status = XEmacLite_CfgInitialize(EmacLiteInstPtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the MAC address. */ XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalAddress); /* * Empty any existing receive frames. */ XEmacLite_FlushReceive(EmacLiteInstPtr); /* * Check if there is a TX buffer available, if there isn't it is an * error. */ if (XEmacLite_TxBufferAvailable(EmacLiteInstPtr) != TRUE) { return XST_FAILURE; } /* * Reset the receive frame length to zero. */ RecvFrameLength = 0; // Example program that sends packets and changes the color of an on-screen box upon receiving a packet. unsigned char c = 0; unsigned char r=0xFF, g=0x0, b=0x0; while(1) { c++; if(XEmacLite_IsTxDone(ConfigPtr->BaseAddress)) { Status = EmacLiteSendFrame(EmacLiteInstPtr, EMACLITE_TEST_FRAME_SIZE); if (Status != XST_SUCCESS) { if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) { return XST_FAILURE; } } } else { RecvFrameLength = XEmacLite_Recv(EmacLiteInstPtr, (u8 *)RxFrame); if (RecvFrameLength > 0) { xil_printf("Received a packet!\r\n"); unsigned char oldr = r; r=g; g=b; b=oldr; } // Example of writing data to the screen int x, y; for (x = 0; x < 20; x++) for (y = 0; y < 20; y++) if (t[y*20 + x]) { fptr[y*640*4 + x*4] = b; fptr[y*640*4 + x*4 + 1] = g; fptr[y*640*4 + x*4 + 2] = r; } } } Xil_DCacheDisable(); Xil_ICacheDisable(); return 0; }
/** * * The main entry point for the EmacLite driver in interrupt mode example. * This function will transmit/receive the frame using internal loop back and * verify the data in the received frame. * * @param DeviceId is device ID of the XEmacLite Device , typically * XPAR_<EMAC_instance>_DEVICE_ID value from xparameters.h. * * @return XST_SUCCESS to indicate success, otherwise XST_FAILURE. * * @note None. * ******************************************************************************/ int EmacLiteIntrLoopbackExample(u16 DeviceId) { int Status; XIntc *IntcInstancePtr; XEmacLite *EmacLiteInstPtr; u32 TxLength; XEmacLite_Config *ConfigPtr; RecvFrameLength = 0; IntcInstancePtr = &IntcInstance; EmacLiteInstPtr =&EmacLiteInstance; /* * Initialize the EmacLite device. */ ConfigPtr = XEmacLite_LookupConfig(DeviceId); if (ConfigPtr == NULL) { return XST_FAILURE; } Status = XEmacLite_CfgInitialize(EmacLiteInstPtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the MAC address. */ XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalAddress); /* * Set up the interrupt infrastructure. */ Status = EmacLiteSetupIntrSystem(IntcInstancePtr, EmacLiteInstPtr, INTC_EMACLITE_ID); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the EmacLite handlers. */ XEmacLite_SetRecvHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr), (XEmacLite_Handler)EmacLiteRecvHandler); XEmacLite_SetSendHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr), (XEmacLite_Handler)EmacLiteSendHandler); /* * Empty any existing receive frames. */ XEmacLite_FlushReceive(EmacLiteInstPtr); /* * Enable the EmacLite interrupts. */ XEmacLite_EnableInterrupts(EmacLiteInstPtr); /* * Check if there is a Tx buffer available. */ if (XEmacLite_TxBufferAvailable(EmacLiteInstPtr) != TRUE) { return XST_FAILURE; } /* * Enable internal loop back. */ XEmacLite_EnableLoopBack(EmacLiteInstPtr); /* * Send/Receive frames of varying sizes and verify the data in the * received frames. */ for (TxLength = 1; TxLength <= XEL_MTU_SIZE; ) { RecvFrameLength = 0; /* * Send a frame. */ Status = EmacLiteSendFrame(EmacLiteInstPtr, TxLength); if (Status != XST_SUCCESS) { /* * Disable internal loop back. */ XEmacLite_DisableLoopBack(EmacLiteInstPtr); return XST_FAILURE; } /* * Wait for the frame to be transmitted and received back. * As the core is in loopback the transmit interrupt and the * receive interrupt occur simulataneously. */ while ((RecvFrameLength == 0) && (TransmitComplete == FALSE)); /* * Check the receive frame. */ Status = EmacLiteRecvFrame(TxLength++); if ((Status != XST_SUCCESS) && (Status != XST_NO_DATA)) { /* * Disable internal loop back. */ XEmacLite_DisableLoopBack(EmacLiteInstPtr); /* * Disable and disconnect the EmacLite Interrupts. */ XEmacLite_DisableInterrupts(EmacLiteInstPtr); EmacLiteDisableIntrSystem(IntcInstancePtr, INTC_EMACLITE_ID); return XST_FAILURE; } } /* * Disable internal loop back. */ XEmacLite_DisableLoopBack(EmacLiteInstPtr); /* * Disable and disconnect the EmacLite Interrupts. */ XEmacLite_DisableInterrupts(EmacLiteInstPtr); EmacLiteDisableIntrSystem(IntcInstancePtr, INTC_EMACLITE_ID); return XST_SUCCESS; }
static err_t low_level_init(struct netif *netif) { struct xemac_s *xemac; XEmacLite_Config *config; XEmacLite *xemaclitep; struct xtopology_t *xtopologyp; xemacliteif_s *xemacliteif; unsigned link_speed = 1000; xemaclitep = mem_malloc(sizeof *xemaclitep); #ifndef XLWIP_CONFIG_INCLUDE_EMACLITE_ON_ZYNQ #if XPAR_INTC_0_HAS_FAST == 1 xemaclitep_fast = xemaclitep; #endif #endif if (xemaclitep == NULL) { LWIP_DEBUGF(NETIF_DEBUG, ("xemacliteif_init: out of memory\r\n")); return ERR_MEM; } xemac = mem_malloc(sizeof *xemac); if (xemac == NULL) { LWIP_DEBUGF(NETIF_DEBUG, ("xemacliteif_init: out of memory\r\n")); return ERR_MEM; } xemacliteif = mem_malloc(sizeof *xemacliteif); if (xemacliteif == NULL) { LWIP_DEBUGF(NETIF_DEBUG, ("xemacliteif_init: out of memory\r\n")); return ERR_MEM; } /* obtain pointer to topology structure for this emac */ xemac->topology_index = xtopology_find_index((unsigned)(netif->state)); xtopologyp = &xtopology[xemac->topology_index]; /* obtain config of this emaclite */ config = xemaclite_lookup_config((unsigned)(netif->state)); /* maximum transfer unit */ netif->mtu = XEL_MTU_SIZE; /* broadcast capability */ netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; /* initialize the mac */ XEmacLite_Initialize(xemaclitep, config->DeviceId); xemaclitep->NextRxBufferToUse = 0; #if XLWIP_CONFIG_INCLUDE_EMACLITE_ON_ZYNQ == 1 XScuGic_RegisterHandler(xtopologyp->scugic_baseaddr, xtopologyp->intc_emac_intr, (Xil_ExceptionHandler)XEmacLite_InterruptHandler, xemaclitep); XScuGic_SetPriTrigTypeByDistAddr(INTC_DIST_BASE_ADDR, xtopologyp->intc_emac_intr, EMACLITE_INTR_PRIORITY_SET_IN_GIC, TRIG_TYPE_RISING_EDGE_SENSITIVE); XScuGic_EnableIntr(INTC_DIST_BASE_ADDR, xtopologyp->intc_emac_intr); #else #if NO_SYS #if XPAR_INTC_0_HAS_FAST == 1 XIntc_RegisterFastHandler(xtopologyp->intc_baseaddr, xtopologyp->intc_emac_intr, (XFastInterruptHandler)XEmacLite_FastInterruptHandler); #else XIntc_RegisterHandler(xtopologyp->intc_baseaddr, xtopologyp->intc_emac_intr, (XInterruptHandler)XEmacLite_InterruptHandler, xemaclitep); #endif #else xPortInstallInterruptHandler( XPAR_INTC_0_EMACLITE_0_VEC_ID, ( XInterruptHandler ) XEmacLite_InterruptWrapper, xemaclitep ); vPortEnableInterrupt( XPAR_INTC_0_EMACLITE_0_VEC_ID ); #endif #endif /* set mac address */ XEmacLite_SetMacAddress(xemaclitep, (unsigned char*)(netif->hwaddr)); /* flush any frames already received */ XEmacLite_FlushReceive(xemaclitep); /* set Rx, Tx interrupt handlers */ XEmacLite_SetRecvHandler(xemaclitep, (void *)(xemac), xemacif_recv_handler); XEmacLite_SetSendHandler(xemaclitep, (void *)(xemac), xemacif_send_handler); /* enable Rx, Tx interrupts */ XEmacLite_EnableInterrupts(xemaclitep); #if !NO_SYS sys_sem_new(&xemac->sem_rx_data_available, 0); #endif /* replace the state in netif (currently the base address of emaclite) * with the xemacliteif instance pointer. * this contains a pointer to the config table entry */ xemac->type = xemac_type_xps_emaclite; xemac->state = (void *)xemacliteif; netif->state = (void *)xemac; xemacliteif->instance = xemaclitep; xemacliteif->recv_q = pq_create_queue(); if (!xemacliteif->recv_q) return ERR_MEM; xemacliteif->send_q = pq_create_queue(); if (!xemacliteif->send_q) return ERR_MEM; /* Initialize PHY */ /* set PHY <--> MAC data clock */ #ifdef CONFIG_LINKSPEED_AUTODETECT link_speed = get_IEEE_phy_speed_emaclite(xemaclitep); xil_printf("auto-negotiated link speed: %d\r\n", link_speed); #elif defined(CONFIG_LINKSPEED1000) xil_printf("Link speed of 1000 Mbps not possible\r\n"); #elif defined(CONFIG_LINKSPEED100) link_speed = 100; configure_IEEE_phy_speed_emaclite(xemaclitep, link_speed); xil_printf("link speed: %d\r\n", link_speed); #elif defined(CONFIG_LINKSPEED10) link_speed = 10; configure_IEEE_phy_speed_emaclite(xemaclitep, link_speed); xil_printf("link speed: %d\r\n", link_speed); #endif return ERR_OK; }
/** * * The main entry point for the EmacLite driver example in interrupt mode. * This function will transmit/receive the Ethernet frames and verify the * data in the received frame (if the MDIO interface is configured in the * EmacLite core). * This function simply transmits a frame if the MDIO interface is not * configured in the EmacLite core. * * @param IntcInstancePtr is a pointer to the instance of the Intc. * @param EmacLiteInstPtr is a pointer to the instance of the EmacLite. * @param EmacLiteDeviceId is device ID of the XEmacLite Device , * typically XPAR_<EMACLITE_instance>_DEVICE_ID value from * xparameters.h. * @param EmacLiteIntrId is the interrupt ID and is typically * XPAR_<INTC_instance>_<EMACLITE_instance>_VEC_ID value from * xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ******************************************************************************/ int EmacLiteIntrExample(INTC *IntcInstancePtr, XEmacLite *EmacLiteInstPtr, u16 EmacLiteDeviceId, u16 EmacLiteIntrId) { int Status; u32 PhyAddress = 0; XEmacLite_Config *ConfigPtr; /* * Initialize the EmacLite device. */ ConfigPtr = XEmacLite_LookupConfig(EmacLiteDeviceId); if (ConfigPtr == NULL) { return XST_FAILURE; } Status = XEmacLite_CfgInitialize(EmacLiteInstPtr, ConfigPtr, ConfigPtr->BaseAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the MAC address. */ XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalAddress); /* * Empty any existing receive frames. */ XEmacLite_FlushReceive(EmacLiteInstPtr); /* * Check if there is a Tx buffer available, if there isn't it is an * error. */ if (XEmacLite_TxBufferAvailable(EmacLiteInstPtr) != TRUE) { return XST_FAILURE; } /* * Set up the interrupt infrastructure. */ Status = EmacLiteSetupIntrSystem(IntcInstancePtr, EmacLiteInstPtr, EmacLiteIntrId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the EmacLite handlers. */ XEmacLite_SetRecvHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr), (XEmacLite_Handler)EmacLiteRecvHandler); XEmacLite_SetSendHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr), (XEmacLite_Handler)EmacLiteSendHandler); /* * Enable the interrupts in the EmacLite controller. */ XEmacLite_EnableInterrupts(EmacLiteInstPtr); RecvFrameLength = 0; /* * If the MDIO is configured in the device. */ if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) { /* * Detect the PHY device and enable the MAC Loop back * in the PHY. */ PhyAddress = EmacLitePhyDetect(EmacLiteInstPtr); Status = EmacLiteEnablePhyLoopBack(EmacLiteInstPtr, PhyAddress); if (Status != XST_SUCCESS) { XEmacLite_DisableInterrupts(EmacLiteInstPtr); EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId); return XST_FAILURE; } } /* * Transmit an Ethernet frame. */ Status = EmacLiteSendFrame(EmacLiteInstPtr, EMACLITE_TEST_FRAME_SIZE); if (Status != XST_SUCCESS) { if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) { /* * Disable the MAC Loop back in the PHY and * disable/disconnect the EmacLite Interrupts. */ EmacLiteDisablePhyLoopBack(EmacLiteInstPtr, PhyAddress); XEmacLite_DisableInterrupts(EmacLiteInstPtr); EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId); return XST_FAILURE; } } /* * Wait for the frame to be transmitted. */ while (TransmitComplete == FALSE); /* * If the MDIO is not configured in the core then return XST_SUCCESS * as the frame has been transmitted. */ if (!XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) { /* * Disable and disconnect the EmacLite Interrupts. */ XEmacLite_DisableInterrupts(EmacLiteInstPtr); EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId); return XST_SUCCESS; } /* * Wait for the frame to be received. */ while (RecvFrameLength == 0); /* * Check the received frame. */ Status = EmacLiteRecvFrame(EMACLITE_TEST_FRAME_SIZE); /* * Diasble the Loop Back. */ if (XEmacLite_IsMdioConfigured(EmacLiteInstPtr)) { /* * Disable the MAC Loop back in the PHY. */ Status |= EmacLiteDisablePhyLoopBack(EmacLiteInstPtr, PhyAddress); } /* * Disable and disconnect the EmacLite Interrupts. */ XEmacLite_DisableInterrupts(EmacLiteInstPtr); EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId); if ((Status != XST_SUCCESS) && (Status != XST_NO_DATA)) { return XST_FAILURE; } return XST_SUCCESS; }
int main( void ) { xil_printf( "Hello from Freertos\r\n" ); if (XGpio_Initialize(&gpio_leds, XPAR_GPIO_LEDS_DEVICE_ID) != XST_SUCCESS) { xil_printf( "ERR: Xgpio Leds init failed\r\n" ); } else { XGpio_SetDataDirection(&gpio_leds, 1, 0xFFFFFF00); } if (XGpio_Initialize(&gpio_btns, XPAR_GPIO_BTNS_DEVICE_ID) != XST_SUCCESS) { xil_printf( "ERR: Xgpio Btns init failed\r\n" ); } else { XGpio_SetDataDirection(&gpio_btns, 1, 0xFFFFFFFF); } if (XEmacLite_Initialize(&emac, XPAR_EMACLITE_0_DEVICE_ID) != XST_SUCCESS) { xil_printf( "ERR: emacline init failed\r\n" ); } XEmacLite_SetMacAddress(&emac, LocalAddress); XEmacLite_FlushReceive(&emac); RecvFrameLength = 0; if (XEmacLite_TxBufferAvailable(&emac) != TRUE) { xil_printf( "ERR: Xemac TxBuffer not available\r\n" ); } // XEmacLite_EnableLoopBack(&emac); XEmacLite_DisableLoopBack(&emac); /* Create the two tasks. The Tx task is given a lower priority than the Rx task, so the Rx task will leave the Blocked state and pre-empt the Tx task as soon as the Tx task places an item in the queue. */ xTaskCreate( prvTxTask, /* The function that implements the task. */ ( const char * ) "Tx", /* Text name for the task, provided to assist debugging only. */ configMINIMAL_STACK_SIZE, /* The stack allocated to the task. */ NULL, /* The task parameter is not used, so set to NULL. */ tskIDLE_PRIORITY, /* The task runs at the idle priority. */ NULL ); xTaskCreate( prvRxTask, ( const char * ) "GB", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL ); /* Create the queue used by the tasks. The Rx task has a higher priority than the Tx task, so will preempt the Tx task and remove values from the queue as soon as the Tx task writes to the queue - therefore the queue can never have more than one item in it. */ xQueue = xQueueCreate( 1, /* There is only one space in the queue. */ sizeof( HWstring ) ); /* Each space in the queue is large enough to hold a uint32_t. */ /* Check the queue was created. */ configASSERT( xQueue ); /* Start the tasks and timer running. */ vTaskStartScheduler(); /* If all is well, the scheduler will now be running, and the following line will never be reached. If the following line does execute, then there was insufficient FreeRTOS heap memory available for the idle and/or timer tasks to be created. See the memory management section on the FreeRTOS web site for more details. */ for( ;; ); }
/** * * The main entry point for the EmacLite driver in interrupt mode example. * * @param IntcInstancePtr is a pointer to the instance of the Intc. * @param EmacLiteInstPtr is a pointer to the instance of the EmacLite. * @param EmacLiteDeviceId is device ID of the XEmacLite Device , typically * XPAR_<EMACLITE_instance>_DEVICE_ID value from xparameters.h. * @param EmacLiteIntrId is the interrupt ID and is typically * XPAR_<INTC_instance>_<EMACLITE_instance>_IP2INTC_IRPT_INTR * value from xparameters.h. * * @return XST_SUCCESS if successful, otherwise XST_FAILURE. * * @note None. * ******************************************************************************/ XStatus EmacLiteExample(XIntc *IntcInstancePtr, XEmacLite *EmacLiteInstPtr, Xuint16 EmacLiteDeviceId, Xuint16 EmacLiteIntrId) { XStatus Status; /* * Initialize the EmacLite device. */ Status = XEmacLite_Initialize(EmacLiteInstPtr, EmacLiteDeviceId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Set the MAC address. */ XEmacLite_SetMacAddress(EmacLiteInstPtr, LocalAddress); /* * Set up the interrupt infrastructure. */ Status = EmacLiteSetupIntrSystem(IntcInstancePtr, EmacLiteInstPtr, EmacLiteIntrId); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Setup the EmacLite handlers. */ XEmacLite_SetRecvHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr), (XEmacLite_Handler) EmacLiteRecvHandler); XEmacLite_SetSendHandler((EmacLiteInstPtr), (void *)(EmacLiteInstPtr), (XEmacLite_Handler) EmacLiteSendHandler); /* * Empty any existing receive frames. */ XEmacLite_FlushReceive(EmacLiteInstPtr); /* * Enable the interrupts in the EmacLite controller. */ XEmacLite_EnableInterrupts(EmacLiteInstPtr); /* * Check if there is a Tx buffer available, if there isn't it is an error. */ if (XEmacLite_TxBufferAvailable(EmacLiteInstPtr) != XTRUE) { return XST_FAILURE; } /* * Transmit a ethernet frame. */ Status = EmacLiteSendFrame(EmacLiteInstPtr, EMACLITE_TEST_FRAME_SIZE, RemoteAddress); if (Status != XST_SUCCESS) { return XST_FAILURE; } /* * Wait for the frame to be transmitted. */ while (TransmitComplete == XFALSE); /* * Disable and disconnect the EmacLite Interrupts. */ XEmacLite_DisableInterrupts(EmacLiteInstPtr); EmacLiteDisableIntrSystem(IntcInstancePtr, EmacLiteIntrId); return XST_SUCCESS; }
static err_t low_level_init(struct netif *netif) { struct xemac_s *xemac; XEmacLite_Config *config; XEmacLite *xemaclitep; struct xtopology_t *xtopologyp; xemacliteif_s *xemacliteif; xemaclitep = mem_malloc(sizeof *xemaclitep); if (xemaclitep == NULL) { LWIP_DEBUGF(NETIF_DEBUG, ("xemacliteif_init: out of memory\r\n")); return ERR_MEM; } xemac = mem_malloc(sizeof *xemac); if (xemac == NULL) { LWIP_DEBUGF(NETIF_DEBUG, ("xemacliteif_init: out of memory\r\n")); return ERR_MEM; } xemacliteif = mem_malloc(sizeof *xemacliteif); if (xemac == NULL) { LWIP_DEBUGF(NETIF_DEBUG, ("xemacliteif_init: out of memory\r\n")); return ERR_MEM; } /* obtain pointer to topology structure for this emac */ xemac->topology_index = xtopology_find_index((unsigned)(netif->state)); xtopologyp = &xtopology[xemac->topology_index]; /* obtain config of this emaclite */ config = xemaclite_lookup_config((unsigned)(netif->state)); /* maximum transfer unit */ netif->mtu = XEL_MTU_SIZE; /* broadcast capability */ netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; /* initialize the mac */ XEmacLite_Initialize(xemaclitep, config->DeviceId); xemaclitep->NextRxBufferToUse = 0; #if NO_SYS XIntc_RegisterHandler(xtopologyp->intc_baseaddr, xtopologyp->intc_emac_intr, (XInterruptHandler)XEmacLite_InterruptHandler, xemaclitep); #else #include "xmk.h" register_int_handler(xtopologyp->intc_emac_intr, (XInterruptHandler)XEmacLite_InterruptHandler, xemaclitep); enable_interrupt(xtopologyp->intc_emac_intr); #endif /* set mac address */ XEmacLite_SetMacAddress(xemaclitep, (Xuint8*)(netif->hwaddr)); /* flush any frames already received */ XEmacLite_FlushReceive(xemaclitep); /* set Rx, Tx interrupt handlers */ XEmacLite_SetRecvHandler(xemaclitep, (void *)(xemac), xemacif_recv_handler); XEmacLite_SetSendHandler(xemaclitep, (void *)(xemac), xemacif_send_handler); /* enable Rx, Tx interrupts */ XEmacLite_EnableInterrupts(xemaclitep); #if !NO_SYS xemac->sem_rx_data_available = sys_sem_new(0); #endif /* replace the state in netif (currently the base address of emaclite) * with the xemacliteif instance pointer. * this contains a pointer to the config table entry */ xemac->type = xemac_type_xps_emaclite; xemac->state = (void *)xemacliteif; netif->state = (void *)xemac; xemacliteif->instance = xemaclitep; xemacliteif->recv_q = pq_create_queue(); if (!xemacliteif->recv_q) return ERR_MEM; xemacliteif->send_q = pq_create_queue(); if (!xemacliteif->send_q) return ERR_MEM; return ERR_OK; }