#include "tx_api.h" #include "nx_api.h" #include "xil_cache.h" #include "xil_mmu.h" /* Define the ThreadX and NetX object control blocks... */ TX_THREAD thread_0; NX_PACKET_POOL pool_0; NX_IP ip_0; //NX_PACKET TX_packet; //NX_PACKET RX_packet; NX_UDP_SOCKET udp_socket,client_socket,socket_0; static NX_PACKET packet; NX_PACKET *RX_packet_ptr,*TX_packet_ptr = &packet ; NX_UDP_SOCKET *udp_socket_ptr = &udp_socket; ULONG slave_address = IP_ADDRESS(192,168,1,1); /* Define the counters used in the demo application... */ ULONG error_counter; /* Define a 8K space for the HTTP thread stack.*/ ULONG http_thread_stack_area[8 * 1024 / sizeof(ULONG)]; /* Define a 4K space for the IPerf Thread stack. */ ULONG iperf_thread_stack_area[4 * 1024 / sizeof(ULONG)]; /* Define the packet pool area */ ULONG packet_pool_area[(1536 + sizeof(NX_PACKET)) * 100 / sizeof(ULONG) + 8] __attribute__ ((aligned (32))); /* Define the stack area */ ULONG ip_thread_stack_area[8 * 1024 / sizeof(ULONG)]; ULONG thread0_stack_area[4 * 1024 / sizeof(ULONG)]; ULONG arp_stack_area[1024 / sizeof(ULONG)]; ULONG iperf_stack_area[2*1024 / sizeof(ULONG)]; /* Define thread prototypes. */ VOID thread_0_entry(ULONG thread_input); extern VOID nx_iperf_entry(NX_PACKET_POOL *pool_ptr, NX_IP *ip_ptr, UCHAR* http_stack, ULONG http_stack_size, UCHAR *iperf_stack, ULONG iperf_stack_size); /***** Substitute your ethernet driver entry function here *********/ extern VOID nx_driver_zynq(NX_IP_DRIVER*); VOID hardware_setup(void); int main(int argc, char ** argv) { Xil_SetTlbAttributes(0x0FF00000, 0xc02); Xil_DCacheEnable(); Xil_ICacheEnable(); /* Setup the hardware. */ hardware_setup(); /* Enter the ThreadX kernel. */ tx_kernel_enter(); } /* Define what the initial system looks like. */ void tx_application_define(void *first_unused_memory) { UINT status; /* Initialize the NetX system. */ nx_system_initialize(); /* Create a packet pool. */ status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 1536,(VOID*)(((UINT)(&packet_pool_area) + 31) & (~31)), sizeof(packet_pool_area) - 32); /* Check for pool creation error. */ if (status) error_counter++; /* Create an IP instance. */ status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(192, 168, 1 , 2), IP_ADDRESS(255, 255, 255 , 0), &pool_0, nx_driver_zynq,&ip_thread_stack_area, sizeof(ip_thread_stack_area), 1); /* Check for IP create errors. */ if (status) error_counter++; status = nx_ip_fragment_enable(&ip_0); if (status) error_counter++; /* Enable ARP and supply ARP cache memory for IP Instance 0. */ status = nx_arp_enable(&ip_0, arp_stack_area, sizeof(arp_stack_area)); /* Check for ARP enable errors. */ if (status) error_counter++; /* Enable ICMP */ status = nx_icmp_enable(&ip_0); /* Check for ICMP enable errors. */ if(status) error_counter++; /* Enable UDP traffic. */ status = nx_udp_enable(&ip_0); /* Check for UDP enable errors. */ if (status) error_counter++; /* Create the main thread. */ tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0, thread0_stack_area, sizeof(thread0_stack_area), 1, 1, TX_NO_TIME_SLICE, TX_AUTO_START); } /* Define the test threads. */ void thread_0_entry(ULONG thread_input) { int status; UCHAR buffer[512]; ULONG bytes_copied; NXD_ADDRESS ipv4_addr; ipv4_addr.nxd_ip_version = NX_IP_VERSION_V4; ipv4_addr.nxd_ip_address.v4 = slave_address; status = nx_udp_socket_create(&ip_0, &udp_socket,"Sample UDP Socket", NX_IP_NORMAL,NX_FRAGMENT_OKAY,NX_IP_TIME_TO_LIVE, 2048); if (status) error_counter++; status = nx_udp_socket_bind(&udp_socket, 5001, 300); if (status) error_counter++; status = nx_udp_socket_checksum_disable(&udp_socket); if (status) error_counter++; status = nx_packet_allocate(&pool_0, &TX_packet_ptr, NX_UDP_PACKET, 1000); if (status) error_counter++; status = nx_packet_data_append(TX_packet_ptr, "Hello_and_Goodbye", sizeof("Hello_and_Goodbye"), &pool_0, 5); if (status) error_counter++; status = nxd_udp_socket_send(&udp_socket, TX_packet_ptr, &ipv4_addr, 5004); if (status) error_counter++; nx_packet_transmit_release(TX_packet_ptr); if (status) error_counter++; //// status = nx_udp_free_port_find(&ip_0, 1,&free_port); // status = nx_udp_socket_create(&ip_0, &udp_socket,"Sample UDP Socket", NX_IP_NORMAL,NX_FRAGMENT_OKAY,NX_IP_TIME_TO_LIVE, 512); // if (status) error_counter++; // // status = nx_udp_socket_bind(udp_socket_ptr, 11000, 300); // if (status) error_counter++; // // // status = nx_packet_allocate(&pool_0, &TX_packet_ptr, NX_UDP_PACKET, NX_WAIT_FOREVER); // // /* Append "abcd" to the specified packet. */ //// status = nx_packet_data_append(&packet_ptr, packet_test, 5, &pool_0, 5); // // status = nx_udp_socket_checksum_enable(&udp_socket); // // // while (1) // { //#if 0 // status = nx_packet_allocate(&pool_0, &RX_packet_ptr, NX_UDP_PACKET, NX_WAIT_FOREVER); // if (status) error_counter++; // status = nx_udp_socket_receive(udp_socket_ptr, &RX_packet_ptr, NX_WAIT_FOREVER); // if (status) error_counter++; // status = nx_packet_data_retrieve(RX_packet_ptr, buffer, &bytes_copied); // nx_packet_release(RX_packet_ptr); // if (status) error_counter++; //// tx_thread_sleep(4); //#endif // while(1) // { // status = nx_packet_allocate(&pool_0, &TX_packet_ptr, NX_UDP_PACKET, NX_WAIT_FOREVER); // if (status) error_counter++; // status = nx_packet_data_append(TX_packet_ptr, buffer,bytes_copied, &pool_0, 5); // if (status) error_counter++; // status = nx_udp_socket_send(udp_socket_ptr, TX_packet_ptr, slave_address, 53901); // if (status) error_counter++; // nx_packet_transmit_release(TX_packet_ptr); // if (status) error_counter++; //// tx_thread_sleep(2); // } // // } }