Abstract: Introduced that is suitable for 8/16 monolithic integrated circuit’s embedded TCP/IP agreement stack (uIP) in the generator long-distance observation system’s application. Key elaborated that the uIP function characteristic, the architecture and the related connection, and introduced in detail how to realize an embedded Web server on this agreement stack. At present uIP transplanted successfully to 51 monolithic integrated circuits on.
Key word: TCP/IP agreement stack embedded Web server long-distance monitor
At present, along with Internet’s development, more and more industry observation equipment already took the network turning on function its default disposition, realizes equipment’s long-distance monitoring and information distributional processing. The author once participated in some generator radio frequency monitoring meter’s development, this equipment mainly uses in diagnosing and the early warning generator incipient failure, and through the RS232 connection fixed time power output and the condition data, the scene supposes PC to make the receive, the demonstration and the memory specially. Every year must have the expert to make the inspection and the diagnosis to various power plants to the former data, burdensome. Therefore has the necessity to design RS232 to the Internet data transmission module, in order to make the long-distance monitor to generator’s movement condition. How designs this module the key to lie to realize an embedded TCP/IP agreement stack, according to the former experience, oneself designs an agreement stack’s difficulty very possibly to surpass applies itself, but uses commercial the agreement stack not to be as if also essential
(function to be too complex), finally the author selects one kind of function simple free TCP/IP agreement stack uIP 0.9 to take the design core.
1 embedded TCP/IP agreement stack
At present, in the market the nearly all embedded TCP/IP agreement stack is agreement stack rewrites according to BSD version’s TCP/IP. In the commercial embedded TCP/IP agreement stack quite expensive situation, many people transfer mostly use some source code public free agreement stack, and transforms the application. At present the more famous free agreement stack includes:
lwIP (Light weight TCP/IP Stack) - - the support agreement is quite complete, generally the need multi-duty environment support, the code takes ROM>40KB, does not suit 8 machine systems, does not have the complete application documents;
uC/IP (TCP/IP stack for uC/OS) - based on the uC/OS task management, the connection is complex, has not explained the documents.
The author uses the agreement stack is Sweden Computer science Research institute Adam Dunkels development uIP0.9. Its function characteristic summary is as follows:
* the complete showing documents and the public source code (use C language compilation completely, and attaches detailed annotation);
* the extremely few codes take the quantity and the RAM resources request, especially is suitable in 8/16 monolithic integrated circuit (see Table 1);
* configurable, adapts the different resources condition and the application situation highly;
* supports ARP, IP, ICMP, TCP, UDP (to be possible to choose) and so on essential function characteristic;
* supports many initiative connections and the passive connection is concurrent, support link dynamic allocation and release;
* the simple application layer connection and the equipment actuate the level connection;
* the consummation demonstration procedure and the application agreement realize the model.
Table 1 uIP the code and RAM takes the situation on ATMEL AVR
| Agreement module | Code size /B | Use RAM/B |
| ARP | 1324 | 118 |
| IP/ICMP/TCP | 3304 | 360 |
| HTTP | 994 | 110 |
| Verification and function | 636 | 0 |
| Data packet buffer | 0 | 400 |
| Sum total | 6258 | 988 |
Note: The disposition is 1 TCP listens to the port, 10 connections, 10 ARP table item, 400 byte data package of buffer.
Is precisely because uIP has the outstanding feature, is transplanted since 0.6 edition to many kinds of processors on, including MSP430, AVR and Z80 and so on. The author uses uIP0.9 is the edition which in November, 2003 issued. At present, the author has succeeded it transplants to MCS-51 on.
2 uIP0.9 architectures
uIP0.9 is one is suitable for 8/16 machine on small embedded TCP/IP agreement stack, simple easy to use, the resources take few are its design feature. It has removed in many entire function agreement stack not the commonly used function, but retains the network message center essential agreement mechanism. Its design key places IP, ICMP and on TCP agreement realization, gathers these three modules is an organic whole, but realizes UDP and the ARP agreement the achievement to be possible to elect the module. UIP0.9 architecture as shown in Figure 1.
UIP0.9 is in the network service the intermediate level, its upper formation agreement is called in here it the application procedure, but the lower level hardware or the firmware were called that it actuates the network equipment. Obviously, uIP0.9 is not aims at the ethernet design merely, by has the media independency.
In order to save the resources to take, simplified application connection, uIP0.9, in the interior realized on has made special processing.
①Pays attention to various modules the fusion, reduces the processing function the integer and the transfer number of times, enhances the code multiplying rate, reduces ROM to take.
②Based on the sole overall situation array’s receiving and dispatching data buffer, does not support the memory dynamic allocation, is responsible by the application to process receiving and dispatching the data.
③Based on event driven’s application program interface, each concurrent connection uses the wheel to follow processing, when only the network event occurs, arouses the application program processing by the uIP essence. Thus, the uIP user only need pay attention to the specific application to be possible. Traditional TCP/IP realizes must generally based on the multitasking environment, but the majority 8 machine systems do not meet this requirement.
④The application procedure initiative participation partial agreement stack function realizes (for example the TCP reproduction mechanism, data packet partition and flow control), by the uIP essence establishment reproduction event, the application procedure generated data submission transmission, has exempted massive internal buffer occupancy again. Causes these based on event driven’s application connection to realize is simpler.
3 uIP device driver connections
in the uIP essence has two function direct requirement first floor device driver support.
First, uip_input(). When the establishment driver receives from the network level when a data packet must transfer this function, the device driver must store beforehand the data packet in uip_buf[], Bao Chang puts uip_len, then hands over by uip_input() processes. When function returns, if uip_len is not 0, then indicates has outside the belt the data (for example SYN, ACK and so on) to transmit. When needs the ARP support, but also needs to consider that renews the ARP expression or sends out the ARP request and the response, the demonstration is as follows:
#define BUF ((struct uip_eth_hdr*) &uip_buf[0])
uip_len=ethernet_devicedriver_poll(); // receive ethernet data packet (device driver)
if(uip_len>0) {// receives the data
if (BUF->type= =HTONS(UIP_ETHTYPE_IP)) {// is the IP package?
uip_arp_ipin(); // elimination ethernet knot knot, renews the ARP table
uip_input(); //IP package of processing
if(uip_len>0) {// has outside the belt to respond the data
uip_arp_out(); // adds an ethernet structure, when initiative connection possibly must construct the ARP request
ethernet_devicedriver_send(); // transmission data to ethernet (device driver)
}
} else if(BUF->type==HTONS(UIP_ETHTYPE_ARP)) {
// is the ARP request package
uip_arp_arpin(); // like is ARP responds, renews the ARP table; If is the request, structure response data packet
if(uip_len>0) {// is ARP requested that must transmit the response
ethernet_devicedriver_send(); // sends ARP to respond on the ethernet
}
}
Another need driver support’s function is uip_periodie (conn). This function uses in the uIP essence deciding the hour wheel to each connection to follow, therefore needs a hardware support the procedure fixed time periodically to turn with it follows each connection, generally uses in inspecting the main engine whether to have the data to transmit, if has, then constructs the IP package. The use demonstration is as follows:
for (i=0; i<UIP_CONNS; i ) {
uip_periodic(i);
if(uip_len>0) {
uip_arp_out();
ethernet_devicedriver_send();
}
}
In essence, uip_input() and uip_periodic() in the interior are a function, namely uip_process (u8t flag), the UIP designer defines uip_process(UIP_DATA) uip_input(), but defines uip_process(UIP_TIMER) uip_periodic(), therefore realized from the code on is the complete multiplying.
4 uIP application program interfaces
For hangs user’s application procedure receives in uIP, must () define great UIP_APPCALL the actual application procedure letter proper name, when like this some uIP event occurs, the essence will transfer this application procedure to carry on processing. If must join application program state, must define great UIP_APPSTATE_SIZE the application program state syntagma the length. In the application procedure function, depends upon the uIP event detection function to decide processing the method, moreover may differentiate the processing different connection through the judgment current connection port number. The following demonstration procedure is a Web server application frame which the author realizes.
#define UIP_APPCALL uip51_appcall
#define UIP_APPSTATE_SIZE sizeof (struct uip51app_state)
struct uip51app_state {
unsigned char * dataptr;
unsigned int dataleft;
};
void uip51_initapp {// establishment host address
u16_t ipaddr[2];
uip_ipaddr(ipaddr,202,120,127,192);
uip_sethostaddr(ipaddr);
uip_listen(HTTP_PORT); //HTTP WEB PORT (80);
}
void uip51_appcall(void) {
struct uip51app_state *s;
s= (struct uip51lapp_state *) uip_conn->appstate; // gains the current connection condition indicator
if(uip_connected()) {
… // has a client to be connected including the above
}
if(uip_newdat()||uip_rexmit()) {// receives the recent data or needs to reissue
if(uip_datalen()>0) {
if(uip_conn->lport==80) {// receives GET the HTTP request
update_table_data(); // according to level condition data sheet dynamic production homepage
s->dataptr=newpage;
s->dataleft=2653;
uip_send(s->dataptr, s->dataleft); // transmission length is the 2653B homepage
}
}
}
if(uip_acked()) {// receives client’s ACK
if(s->dataleft>uip_mss()&&uip_conn->lport==80) {// transmission length > when biggest section chief
s->dataptr =uip_conn->len; // continues the data which transmits is left over
s->dataleft-=uip-conn->len;
uip_send(s->dataptr, s->dataleft);
}
return;
}
if(uip_poll())
{… // serial port buffer data reproduction level condition data sheet
return;
}
if(uip_timedout()|| // reissues the confirmation overtime
the uip_closed()|| // client has closed the connection
uip_aborted()) {// client interrupt connection
return;}
}
5 uIP0.9 in electrical machinery long-distance observation system’s application
The author has designed embedded Web module UIPWEB51, uses in the generator radio frequency monitor meter serial port output data surfer, realizes to the generator active status long-distance monitor, at present has obtained the preliminary success. This module’s hardware diagram as shown in Figure 2.
What the monolithic integrated circuit uses is Atmel AT89C55WD, its built-in 20KB procedure Flash,512 byte RAM,3/the counter, worked by now when 22.1184MHz has approximately the 2MIPS processing speed. What the network card chip uses similarly is low cost RTL8019AS, was a section of NE2000 compatible network card chip, outside the system expanded 32KB SRAM, used in the serial port data and the network data cushion, in addition has deposited the uIP many global variable.
The UIPWEB51 master routine uses the interrupt to add the way which the wheel follows, sends out the data with the interrupt triggering way receive generator radio frequency monitor meter, opened establishes a receive formation to temporarily store these data. Does the wheel follow a network data package of input whether there is in the procedure, if has, then transfers uIP the related processing function (for example on uip_input() use demonstration); If does not have, then examines fixed time the wheel to follow interrupts whether to occur. Here supposes T2 is uIP decides the hour wheel to follow the counter, establishes the wheel in the T2 interrupt to follow the symbol, once the master routine examines this symbol to transfer the uip_periodic() wheel to follow each connection (for example on uip_periodic() use demonstration).
The UIPWeb51 application procedure (for example the uIP application program interface demonstration), this Web server first opens 80 port’s monitors, once has the client request to be connected including the above, the uIP interior will give it to assign one connection item, after will then wait will receive the client IE browser to send out “GET HTTP ……” the request, the generator level and in the condition data formation’s data fills in the homepage template, will produce a new homepage to issue the client. Because this homepage’s size already surpassed uIP biggest section chief (MSS), therefore first time has sent actually only out a MSS byte in the uIP essence, in the connection is in the idle time (uip_poll()), the application procedure may read out the primary data from the serial port formation, after form processing saves again to the electrical machinery level and in the condition data formation, but is preserving the current 1min equipment operational data in this formation, so that time next time renewal homepage uses. Increased in the homepage renewed the button, once the browser user occupied has struck the button, the browser will send out CGI to request automatically, after UIPWEB51 received, transmitted immediately contains the most recent data the homepage. If uIP receives the ACK overtime, its automatic setup reproduction symbol, in the application procedure might use uip_rexmit() to examine this sign, will produce the homepage and transmits. Once the user has closed the browser, uIP automatic detection this event (in the application procedure might also use uip_closed () examination), and will release this connection item.
Figure 3 is the UIPWEB51 overall procedure structure drawing.
6 test results
Disposes uIP0.9 permits 4 concurrent connections, 1 monitor end, 10 end ARP table item, removes the UDP support, UIP_ZBUFSIZE=1500 and other optimized option. With KEIL the C translation, the entire uIP0.9 essence pattern code quantity is smaller than 8KB (including Web application procedure), the essence takes to RAM is smaller than 2KB (does not contain homepage). The overall system procedure’s code quantity is smaller than 12KB, takes RAM is smaller than 10KB. Moreover, has tested this pattern transmission speed on the public network, is bigger than 20Kbps, has met the requirements regarding this application. At present, this module is preparing to apply in new generation’s generator radio frequency observation system.