Home |
Initialization Recompiling RTIP-32 Driver Source Files |
InitializationThe initialization of RTIP-32 will usually consist of these steps:
Here is an example used by most RTIP-32 demo programs: RTKernelInit(0); // get the kernel going CLKSetTimerIntVal(10*1000); // 10 millisecond tick RTKDelay(1); RTCMOSSetSystemTime(); // get the right time-of-day #ifdef DHCP XN_REGISTER_DHCP_CLI() // and optionally the DHCP client #endif Result = xn_rtip_init(); // Initialize the RTIP-32 stack if (Result == SOCKET_ERROR) Error("xn_rtip_init failed"); Result = BIND_DRIVER(DEVICE_MINOR); // bind driver we want (see netcfg.h) if (Result == SOCKET_ERROR) Error("driver initialization failed"); // Open the interface int interface = xn_interface_open_config(DEVICE_ID, DEVICE_MINOR, ED_IO_ADD, ED_IRQ, ED_MEM_ADD); if (interface == SOCKET_ERROR) Error("xn_interface_open_config failed"); #ifdef DHCP { DHCP_param param[] = {{SUBNET_MASK,1}, {DNS_OP,1}, {ROUTER_OPTION,1}}; DHCP_session DS; DHCP_conf DC; xn_init_dhcp_conf(&DC); // load default DHCP options DC.plist = param; // add MASK, DNS, and gateway options DC.plist_entries = sizeof(param) / sizeof(param[0]); printf("Contacting DHCP server, please wait...\n"); Result = xn_dhcp(interface, &DS, &DC); // contact DHCP server if (Result == SOCKET_ERROR) Error("xn_dhcp failed"); printf("My IP address is: %i.%i.%i.%i\n", DS.client_ip[0], DS.client_ip[1], DS.client_ip[2], DS.client_ip[3]); } #else // Set the IP address and interface printf("Using static IP address %i.%i.%i.%i\n", TargetIP[0], TargetIP[1], TargetIP[2], TargetIP[3]); Result = xn_set_ip(interface, TargetIP, NetMask); // define default gateway and DNS server xn_rt_add(RT_DEFAULT, ip_ffaddr, DefaultGateway, 1, interface, RT_INF); xn_set_server_list((DWORD*)DNSServer, 1); #endif if (Result != 0) Error("TCP/IP stack initialization failed");
|