/****************************************************************************** * * Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * Use of the Software is limited solely to applications: * (a) running on a Xilinx device, or * (b) that interact with a Xilinx device through a bus or interconnect. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Except as contained in this notice, the name of the Xilinx shall not be used * in advertising or otherwise to promote the sale, use or other dealings in * this Software without prior written authorization from Xilinx. * ******************************************************************************/ #include #include "xparameters.h" #include "netif/xadapter.h" #include "platform.h" #include "platform_config.h" #if defined (__arm__) || defined(__aarch64__) #include "xil_printf.h" #endif #include "lwip/tcp.h" #include "lwip/udp.h" #include "xil_cache.h" const int udp_data_size = 32768; /* defined by each RAW mode application */ void print_app_header(); int start_application(); int transfer_data(); void tcp_fasttmr(void); void tcp_slowtmr(void); /* missing declaration in lwIP */ void lwip_init(); extern volatile int TcpFastTmrFlag; extern volatile int TcpSlowTmrFlag; static struct netif server_netif; struct netif *echo_netif; void print_ip(char *msg, struct ip_addr *ip) { print(msg); xil_printf("%d.%d.%d.%d\n\r", ip4_addr1(ip), ip4_addr2(ip), ip4_addr3(ip), ip4_addr4(ip)); } void print_ip_settings(struct ip_addr *ip, struct ip_addr *mask, struct ip_addr *gw) { print_ip("Board IP: ", ip); print_ip("Netmask : ", mask); print_ip("Gateway : ", gw); } #if defined (__arm__) || defined(__aarch64__) #if XPAR_GIGE_PCS_PMA_SGMII_CORE_PRESENT == 1 || XPAR_GIGE_PCS_PMA_1000BASEX_CORE_PRESENT == 1 int ProgramSi5324(void); int ProgramSfpPhy(void); #endif #endif int main() { #if __aarch64__ Xil_DCacheDisable(); #endif /* --- UDP --- */ err_t udp_error; unsigned short port_rmt = 1010; struct udp_pcb *udppcb; struct pbuf *udp_buff;// = /*pbuf_alloc(PBUF_TRANSPORT, adc_data_size, PBUF_RAM);//*/malloc(sizeof(struct pbuf)); char *udp_data; int udp_tx_en = 1; int gpio_counter = 0; struct ip_addr ipaddr, netmask, gw, rmt_ip; /* the mac address of the board. this should be unique per board */ unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 }; echo_netif = &server_netif; #if defined (__arm__) || defined(__aarch64__) #if XPAR_GIGE_PCS_PMA_SGMII_CORE_PRESENT == 1 || XPAR_GIGE_PCS_PMA_1000BASEX_CORE_PRESENT == 1 ProgramSi5324(); ProgramSfpPhy(); #endif #endif init_platform(); /* initliaze IP addresses to be used */ IP4_ADDR(&ipaddr, 192, 168, 1, 10); IP4_ADDR(&netmask, 255, 255, 255, 0); IP4_ADDR(&gw, 192, 168, 1, 1); IP4_ADDR(&rmt_ip, 192, 168, 1, 66); print_app_header(); lwip_init(); /* Add network interface to the netif_list, and set it as default */ if (!xemac_add(echo_netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) { xil_printf("Error adding N/W interface\n\r"); return -1; } netif_set_default(echo_netif); /* now enable interrupts */ platform_enable_interrupts(); /* specify that the network if is up */ netif_set_up(echo_netif); print_ip_settings(&ipaddr, &netmask, &gw); /* start the application (web server, rxtest, txtest, etc..) */ start_application(); /* --- UDP --- */ udp_data = (char *) malloc(udp_data_size); memset(udp_data, 0xAA, udp_data_size); udppcb = (struct udp_pcb *) udp_new(); if(!udppcb) { return (int) udppcb; } udp_error = udp_connect(udppcb, &rmt_ip, port_rmt); if(ERR_OK != udp_error) { return udp_error; } /* receive and process packets */ while (1) { // 1000 -> Ethernet traffic 700 Mbit/s // 500 -> 810 Mbit/s gpio_counter++; if(gpio_counter == 300) { udp_buff = pbuf_alloc(PBUF_TRANSPORT, udp_data_size, PBUF_RAM); if(!udp_buff) { return (int) udppcb; } udp_buff->payload = udp_data; udp_error = udp_send(udppcb, udp_buff); if(ERR_OK != udp_error) { break; } pbuf_free(udp_buff); gpio_counter = 0; } xemacif_input(echo_netif); } /* never reached */ cleanup_platform(); return 0; }