void wait_for_network(void) { if (connection_is_active()) { xemacif_input(netif); } }
void xemacif_input_thread(struct netif *netif) { while (1) { xemacif_input(netif); yield(); } }
int main() { struct netif *netif, server_netif; struct ip_addr ipaddr, netmask, gw; /* the mac address of the board. this should be unique per board */ unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 }; netif = &server_netif; 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); print_app_header(); print_ip_settings(&ipaddr, &netmask, &gw); lwip_init(); /* Add network interface to the netif_list, and set it as default */ if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) { xil_printf("Error adding N/W interface\n\r"); return -1; } netif_set_default(netif); /* Create a new DHCP client for this interface. * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at * the predefined regular intervals after starting the client. */ /* dhcp_start(netif); */ /* now enable interrupts */ platform_enable_interrupts(); /* specify that the network if is up */ netif_set_up(netif); /* start the application (web server, rxtest, txtest, etc..) */ start_application(); /* receive and process packets */ while (1) { xemacif_input(netif); transfer_data(); } /* never reached */ cleanup_platform(); return 0; }
/* * The input thread calls lwIP to process any received packets. * This thread waits until a packet is received (sem_rx_data_available), * and then calls xemacif_input which processes 1 packet at a time. */ void xemacif_input_thread(struct netif *netif) { struct xemac_s *emac = (struct xemac_s *)netif->state; while (1) { /* sleep until there are packets to process * This semaphore is set by the packet receive interrupt * routine. */ sys_sem_wait(&emac->sem_rx_data_available); /* move all received packets to lwIP */ xemacif_input(netif); } }
char *receive_data(int *len, int expected) { char *pack; if((expected != 0) && (expected > MAX_PACKET)) { pack = (char *)calloc(expected, 1); if(pack == NULL) { return NULL; } int received = 0; do { char *chunk = calloc(MAX_PACKET, 1); int t = 0; do { while (1) { xemacif_input(netif); if(ret) { break; } } ret = 0; int j; for(j=0;j<packet->len;j++) { chunk[j] = *(unsigned char*)(packet->payload + j); } t += packet->len; pbuf_free(packet); } while(t < MAX_PACKET); if((received + t) > expected) { memcpy(pack + (unsigned)received, chunk, (expected - received)); } else { memcpy(pack + (unsigned)received, chunk, t); } free(chunk); received += t; /* send an acknowledge flag */ int ack = (ENDIAN_FLIP(ACK)); send_data((void *)&ack, 4, 1); } while(received < expected); *len = expected; } else { while (1) { xemacif_input(netif); if(ret) { break; } } ret = 0; int j; *len = packet->len; pack = (char *)calloc(packet->len, 1); if(pack == NULL) { return NULL; } for(j=0;j<packet->len;j++) { pack[j] = *(unsigned char*)(packet->payload + j); } pbuf_free(packet); } return pack; }
int main() { struct ip_addr ipaddr, netmask, gw; /* 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 (ARMR5) #if XPAR_GIGE_PCS_PMA_SGMII_CORE_PRESENT == 1 || XPAR_GIGE_PCS_PMA_1000BASEX_CORE_PRESENT == 1 ProgramSi5324(); ProgramSfpPhy(); #endif #endif init_platform(); #if LWIP_DHCP==1 ipaddr.addr = 0; gw.addr = 0; netmask.addr = 0; #else /* 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); #endif 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); #if (LWIP_DHCP==1) /* Create a new DHCP client for this interface. * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at * the predefined regular intervals after starting the client. */ dhcp_start(echo_netif); dhcp_timoutcntr = 24; while(((echo_netif->ip_addr.addr) == 0) && (dhcp_timoutcntr > 0)) xemacif_input(echo_netif); if (dhcp_timoutcntr <= 0) { if ((echo_netif->ip_addr.addr) == 0) { xil_printf("DHCP Timeout\r\n"); xil_printf("Configuring default IP of 192.168.1.10\r\n"); IP4_ADDR(&(echo_netif->ip_addr), 192, 168, 1, 10); IP4_ADDR(&(echo_netif->netmask), 255, 255, 255, 0); IP4_ADDR(&(echo_netif->gw), 192, 168, 1, 1); } } ipaddr.addr = echo_netif->ip_addr.addr; gw.addr = echo_netif->gw.addr; netmask.addr = echo_netif->netmask.addr; #endif print_ip_settings(&ipaddr, &netmask, &gw); /* start the application (web server, rxtest, txtest, etc..) */ start_application(); /* receive and process packets */ while (1) { if (TcpFastTmrFlag) { tcp_fasttmr(); TcpFastTmrFlag = 0; } if (TcpSlowTmrFlag) { tcp_slowtmr(); TcpSlowTmrFlag = 0; } xemacif_input(echo_netif); transfer_data(); } /* never reached */ cleanup_platform(); return 0; }
int main() { struct netif *netif, server_netif; struct ip_addr ipaddr, netmask, gw; /* the mac address of the board. this should be unique per board */ unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x01, 0x02 }; netif = &server_netif; if (init_platform() < 0) { xil_printf("ERROR initializing platform.\r\n"); return -1; } xil_printf("\r\n\r\n"); xil_printf("-----lwIP RAW Mode Demo Application ------\r\n"); /* initliaze IP addresses to be used */ #if (LWIP_DHCP==0) IP4_ADDR(&ipaddr, 192, 168, 1, 10); IP4_ADDR(&netmask, 255, 255, 255, 0); IP4_ADDR(&gw, 192, 168, 1, 1); print_ip_settings(&ipaddr, &netmask, &gw); #endif lwip_init(); #if (LWIP_DHCP==1) ipaddr.addr = 0; gw.addr = 0; netmask.addr = 0; #endif /* Add network interface to the netif_list, and set it as default */ if (!xemac_add(netif, &ipaddr, &netmask, &gw, mac_ethernet_address, PLATFORM_EMAC_BASEADDR)) { xil_printf("Error adding N/W interface\r\n"); return -1; } netif_set_default(netif); /* specify that the network if is up */ netif_set_up(netif); /* now enable interrupts */ platform_enable_interrupts(); #if (LWIP_DHCP==1) /* Create a new DHCP client for this interface. * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at * the predefined regular intervals after starting the client. */ dhcp_start(netif); dhcp_timoutcntr = 24; TxPerfConnMonCntr = 0; while(((netif->ip_addr.addr) == 0) && (dhcp_timoutcntr > 0)) { xemacif_input(netif); if (TcpFastTmrFlag) { tcp_fasttmr(); TcpFastTmrFlag = 0; } if (TcpSlowTmrFlag) { tcp_slowtmr(); TcpSlowTmrFlag = 0; } } if (dhcp_timoutcntr <= 0) { if ((netif->ip_addr.addr) == 0) { xil_printf("DHCP Timeout\r\n"); xil_printf("Configuring default IP of 192.168.1.10\r\n"); IP4_ADDR(&(netif->ip_addr), 192, 168, 1, 10); IP4_ADDR(&(netif->netmask), 255, 255, 255, 0); IP4_ADDR(&(netif->gw), 192, 168, 1, 1); } } /* receive and process packets */ print_ip_settings(&(netif->ip_addr), &(netif->netmask), &(netif->gw)); #endif /* start the application (web server, rxtest, txtest, etc..) */ start_applications(); print_headers(); while (1) { if (TcpFastTmrFlag) { tcp_fasttmr(); TcpFastTmrFlag = 0; } if (TcpSlowTmrFlag) { tcp_slowtmr(); TcpSlowTmrFlag = 0; } xemacif_input(netif); transfer_data(); } /* never reached */ cleanup_platform(); return 0; }
int main() { struct ip_addr ipaddr, netmask, gw; unsigned FPGA_port_number; char *FPGA_ip_address; char *FPGA_netmask; char *FPGA_gateway; unsigned integer_ip; unsigned int FPGA_ip_address_a1,FPGA_ip_address_a2,FPGA_ip_address_a3,FPGA_ip_address_a4; unsigned int FPGA_netmask_a1,FPGA_netmask_a2,FPGA_netmask_a3,FPGA_netmask_a4; unsigned int FPGA_gateway_a1,FPGA_gateway_a2,FPGA_gateway_a3,FPGA_gateway_a4; //EXAMPLE: set FPGA IP and port number FPGA_ip_address=FPGA_IP; FPGA_netmask=FPGA_NM; FPGA_gateway=FPGA_GW; FPGA_port_number=FPGA_PORT; //extract FPGA IP address from string if (ip_to_int (FPGA_ip_address,&FPGA_ip_address_a1,&FPGA_ip_address_a2,&FPGA_ip_address_a3,&FPGA_ip_address_a4) == INVALID) { printf ("'%s' is not a valid IP address for FPGA server.\n", FPGA_ip_address); return 1; } //extract FPGA netmask address from string if (ip_to_int (FPGA_netmask,&FPGA_netmask_a1,&FPGA_netmask_a2,&FPGA_netmask_a3,&FPGA_netmask_a4) == INVALID) { printf ("'%s' is not a valid netmask address for FPGA server.\n", FPGA_netmask); return 1; } //extract FPGA gateway address from string if (ip_to_int (FPGA_gateway,&FPGA_gateway_a1,&FPGA_gateway_a2,&FPGA_gateway_a3,&FPGA_gateway_a4) == INVALID) { printf ("'%s' is not a valid gateway address for FPGA server.\n", FPGA_gateway); return 1; } /* 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; init_platform(); Xil_DCacheDisable(); /* initliaze IP addresses to be used */ IP4_ADDR(&ipaddr, FPGA_ip_address_a4, FPGA_ip_address_a3, FPGA_ip_address_a2, FPGA_ip_address_a1); IP4_ADDR(&netmask, FPGA_netmask_a4, FPGA_netmask_a3, FPGA_netmask_a2, FPGA_netmask_a1); IP4_ADDR(&gw, FPGA_gateway_a4, FPGA_gateway_a3, FPGA_gateway_a2, FPGA_gateway_a1); print_app_header(); print_ip_settings(&ipaddr, &netmask, &gw); 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); /* specify that the network if is up */ netif_set_up(echo_netif); /* now enable interrupts */ platform_enable_interrupts(); /* start the application (web server, rxtest, txtest, etc..) */ start_application(); /* receive and process packets */ while (1) { xemacif_input(echo_netif); transfer_data(); } /* never reached */ cleanup_platform(); return 0; }
/****************************************************************************** * Name: main * Description: Program entry point * * Returns: int - returns 0 if no errors ******************************************************************************/ int main() { /* declare a network interface and network addresses */ struct netif *netif, server_netif; struct ip_addr ipaddr, netmask, gw; /* specify a unique MAC address for the board */ #ifdef XPAR_CPU_PPC440_CORE_CLOCK_FREQ_HZ /* set MAC on ML507 board */ unsigned char mac_ethernet_address[] = {0x00, 0x0a, 0x35, 0x01, 0xC9, 0x76}; #else /* set MAC on ML410 board */ unsigned char mac_ethernet_address[] = {0x00, 0x0a, 0x35, 0x01, 0x9A, 0xFE}; #endif /* set the network interface pointer */ netif = &server_netif; /* enable caches */ XCache_EnableICache( INSTR_CACHE ); XCache_EnableDCache( DATA_CACHE ); /* setup interrupts */ setup_interrupts(); /* initliaze network addresses to be used */ IP4_ADDR( &ipaddr, 192, 168, 1, 15 ); IP4_ADDR( &netmask, 255, 255, 255, 0 ); IP4_ADDR( &gw, 192, 168, 1, 1 ); /* print the application header and IP settings */ print_app_header(); print_ip_settings(&ipaddr, &netmask, &gw); /* initialize lwip */ lwip_init(); /* add network interface to the netif_list, and set it as default */ if( !xemac_add( netif, &ipaddr, &netmask, &gw, mac_ethernet_address, EMAC_BASEADDR ) ) { xil_printf( "Error adding N/W interface\n\r" ); return -1; } netif_set_default( netif ); /* now enable interrupts */ enable_interrupts(); /* specify that the network if is up */ netif_set_up( netif ); /* start the application */ start_application(); /* print debug header if debug mode set */ #ifdef QMFIR_DEBUG debug_menu(); while( 1) { qmfir_debug(); } #endif /* receive and process packets */ while( 1 ) { xemacif_input( netif ); } /* disable caches */ XCache_DisableDCache(); XCache_DisableICache(); return 0; } /* main */
int main() { // disable caches -- still fast enough for copies, no worries about coherency Xil_DCacheDisable(); struct ip_addr ipaddr, netmask, gw; /* the mac address of the board. this should be unique per board */ unsigned char mac_ethernet_address[] = { 0x00, 0x0a, 0x35, 0x00, 0x05, 0x12 }; echo_netif = &server_netif; #if XPAR_GIGE_PCS_PMA_CORE_PRESENT == 1 ProgramSi5324(); ProgramSfpPhy(); #endif init_platform(); /* initliaze IP addresses to be used */ /* 129.241.110.214 */ ipaddr.addr=0; netmask.addr=0; gw.addr=0; /*IP4_ADDR(&ipaddr, 129, 241, 110, 240); IP4_ADDR(&netmask, 255, 255, 254, 0); IP4_ADDR(&gw, 129, 241, 110, 1);*/ print_app_header(); print_ip_settings(&ipaddr, &netmask, &gw); 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); /* Create a new DHCP client for this interface. * Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at * the predefined regular intervals after starting the client. */ /* dhcp_start(echo_netif); */ dhcp_start(echo_netif); /* now enable interrupts */ platform_enable_interrupts(); /* specify that the network if is up */ netif_set_up(echo_netif); /* start the application (web server, rxtest, txtest, etc..) */ start_application(); /* receive and process packets */ int msg = 0; while (!finished) { xemacif_input(echo_netif); transfer_data(); if(!msg && echo_netif->ip_addr.addr) { msg=1; xil_printf("Acquired DHCP address!\n"); print_ip("",&(echo_netif->ip_addr)); } } xil_printf("Cheetah finished, exiting..\n"); cleanup_platform(); return 0; }