On Time RTOS-32 Documentation
Welcome
RTTarget-32
RTKernel-32
RTFiles-32
RTIP-32
RTIP-32 Programming Manual
Introduction
TCP/IP Networking
Programming with RTIP-32
Initialization
Berkeley Socket API
RTIP-32 Native API
Winsock 1.1 Compatibility
Diagnostics and Callbacks
Device Drivers
Recompiling RTIP-32 Driver Source Files
Using Jumbo Ethernet Frames
Encrypted (SSL/TLS) Network Communication
Demo Programs
PPP
DHCP Client
DHCP Server
FTP Client
FTP Server
TFTP Client
TFTP Server
Telnet Client
Telnet Server
Web Server
SNMP Agent
POP3 Client
SMTP Client
SNTP Client
SMB Server
SMB Client
SMB3 Server
SMB3 Client
WLAN Driver
RTIP-32 Reference Manual
RTPEG-32
RTUSB-32
|
Initialization
The initialization of RTIP-32 will usually consist of these steps:
- Initialize RTKernel-32 and it's supplemental modules (if any).
- Set configuration parameters (CFG_...), if required.
- Register all required RTIP-32 add-ons with XN_REGISTER... calls.
- Call xn_rtip_init.
- Call one or more xn_bind_... functions to initialize all required device drivers.
- For each required interface, call xn_interface_open_config.
- For DHCP Clients, call xn_dhcp.
- If no DHCP Client is used, call xn_set_ip.
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");
Berkeley Socket API
|