TCP/IP??51??????????????????
??????1????????1
??1 ???????????????????? ??? 300071 ??
??????????51?????????internet??????????51???????TCP/IP??????????塣????????zlIP?????????51?????????????KeilC51????????д??TCP/IP?????д?????С?????BSD?????(socket)??????????zlIP1.0???????????????zlIP2.0????????????????????????????????????51??????????TCP/IP????????????????汾?????????????????????TCP/IP??????????????????????TCP/IP???????????С??????С????????????????????Щ?????????????????????????????Щ???ɡ?????????????????????????????????????????????????TCP/IP????ò????????????????????????????????????????????????濽?????????????????????????????
??????TCP/IP?????????zlIP
????????? ????????A ???±???1006-8740??2003??-00-0000-00
1 ????
?????????????????????????????豸????Internet?????????????????豸?????ж???????????????????????????????ARM??Linux???Щ???TCP/IP??о????????????????Analog
Devices?????Internet Modem??1??????51??е????????TCP/IPЭ?????????????????????????????????????????TCP/IP????????к????????Щ????????????????????й?????????????
2 TCP/IP???????????????
2.1 ?????
???????????51????????紫???????????TCP/IP?????????????????????????????????????ó????????????RAM??????TCPУ??????RAM?е?????????????????豸?????????????????????????????ο??????1????12??2??24??????????????TCPУ??????16??????????????12M???????????紫??????25K???/????????????????????zlIP???????????11.752K???/??
???????????????????????????Winbond?????77E58????AVR??????????????????????????????????У????KeilC??????????????Reentrant??????Reentrant?????????????????????????????Щ??????????????????????Reentrant???????????????????????????????á?????洢??????????memory-specific
pointer??(2)??????Э??????????????????????????????zlIP??TCP???????????????????????????????????IP??·??????????????????????????????????У??????濽????????
2.2 ????洢??????RAM?????
???TCP/IPЭ????????????RAM???洢?????????TCP????????漲???????б????????????TCP??????????????????TCP????
????СRAM???????????洢?????????TCP??????3?????????????????·???????????????2????????????????????????????洢???????????EEPROM?е?html??????????????????????????????????TCPIP????ò?????????????????????????????ò????2??????????????TCP????????????????????ò???ò?????д???????????????????????2???????ò????á?????????????
2.3??????
TCP/IP??????C?????????????д????KeilC516.0?????????????X8086?????????????KeilC????????????????????????????????????????????????generic
pointer????ó????????????????????????ú??????????????????????????(Call tree)?????????????????????????????????????????????????????????????????????????
3 zlIP????????????
3.1
???
??????TCP/IP??lwIP??uIP??ucIP??tinyTCP???????lwIP??uIP??tinyTCP?????????????????????lwIP?????????????????TCP/IPЭ?????lwIP????????棬???????????????????????????lwip+ucOSII???????60K??4????uIP???????С???????????AVR????????????????5K????????СRAM???????100??????????uIP?????????????????????????RAM??÷???????к?BSD???????????????ò????????zlIP????uIP??lwIP???????????????????е????????RAM??????????????????ò???????е??????????????xdata????????????????洢???????????????????????????reentant?????KeilC??С???±??????12M????KeilC????????89C52????2??????????????£?
??1??zlIP????????(Technical parameter of zlIP)
zlIP??汾 |
???????????? |
??RAM??????????? |
???????????/?? |
1.0 |
6791 |
20K |
11.752K |
2.0 |
14464 |
4K |
5.892K |
2.0??????????У????????????????TCP???????????????豸??????????????????????????????????????ping??????TCP????????????????????????????
3.2 zlIP???TCP/IP?????????
3.2.1??????????
zlIP????????????BSD????????????????????????????У?
l
TCPSocket()??????????socket
* TCPSocket(IP_ADDR ScrIP)????????????????????ScrIP??????????????IP?????????socket????????????????????NULL??
l
TCPConnect()??????????BOOL
TCPConnect(socket * pTCB, IP_ADDR DestIP, WORD DestPort,void (* recv)(void *
buf,WORD size),void (* close)(socket * pSocket))?????????IP????DestIP?????????DestPort???????????????recv??close????????????????????????????TCP???????????????????????????????TRUE????????FALSE??
l
TCPSend()??????????BOOL
TCPSend(socket * pTCB,void *buf,WORD DataSize)?????????????????????????TCP??????????????pTCB???????????????????????????buf????С?DataSize????????????TRUE????????FALSE??
l
TCPListen()??????????BOOL
TCPListen(socket *pTCB,WORD ScrPort,void (* accept)(socket *pNewTCB)) ???????????????pTCB??ScrPort????????????accept????п?????????????????????????????????????
l
TCPClose()??????????void
TCPClose(socket *pTCB)??????????????????????????TCPClose????????????????????pTCB??????????TCPClose??????????TCP???????????????????????з?????????
l
TCPAbort()??????????void
TCPAbort(socket *pTCB)?????????????????????????????TCPAbort????????????????????????
TCP/IPЭ???????У??????????????????????????????????????????????????Щ?????????????????ò?????????????????????????·??(1)TCP/IP??????????????bRecv????????????????????ò???????????????????????TRUE??????????????????????????????????????????????????ò???????????(2)???????????????TCP???????????????????OnReceive(pTCB,buf,size)?????????????????ò?????????????OnReceive????????????OnReceive?????д????????????(3)????????????????????溯?????recv????????????TCP????recv????????????????????????????????????????????????????????zlIP???????????·????????????????У?
l
recv????????void
(* recv)(void * buf,WORD size)??TCP???????????????????????????????????????????buf????С?size??
l
close????????void (* close)(socket * pSocket)??TCP????????????????????????????pSocket???????????????
l
accept????????void (* accept)(socket *pNewTCB)??TCP????????????????????????????????????????pNewTCB??????????TCP???????????????accept()?????л??????pNewTCB???????????recv??close??
3.2.2 zlIP???????????????
???????????TCP/IPЭ???????zlIP??????Э?????????????ò?TCP??IP????????豸?????1??????zlIP?????????????????????????????????????????TCP?????unsend???У?????????????????????У??????????????????????????????????????????????дTCP????????IP????????????????豸?????????????????IP??y??????????????????????????????????????????Output???????????zlIP????NetIfAdd????????????????????????豸???????????Timer???????????????????Input??????IP???ж?IP?汾??IPУ?????ж???????????????????????IP?????protocol??ν?????????????????TCP??????ж?TCPУ????????????е???????в?????ж????????????????????????????ж?TCP??????????????????????????????????????????????????TCP?????????????????????????????????recv??????????£?????????TCP??????????????????????????????????????TCP?????????????????????????????????????????????????????????TCP????
3.2.3 ??????????TCP/IP??????????
???1?????????????????Timer??????????????????????????TCPTimer??????TCPTimer???????TCP?????????????????????????????????????Input???????????????????????Timer?????????????????????20ms???????????Σ???????????????TCP?????????????Timer??????????????????????????????ж?????Timer???????????????÷??????????????????
(1)?????????(5)
??????????????????????????????????????????bTimerOut???????ж??н?bTimerOut??????棬??ò???????????з??????bTimerOut?????棬???????Timer???????????bTimerOut????????????????????????2???????????????????????????????????д???????????????ò?Э???????bTimeOut??
???????Timer?????????????????????????????????????????ε???????20ms??????????ó?????д???????????????????????????????????е????????£?????????????????????????????
(2)?????????
??????????????????Timer??????????????????20ms????????Ρ?????????????????????
???????????ж??е???Timer???????? ??ò???????
???????????????????????????????ó?????????????ù?????????????????????д??????????????????ζ???Щ???????????????Щ???????????reentrant??????????????????????
?????????????????豸?????????????????????NE2K????????????????????????????????????????????ü???????????????????????????????????????????????ж????????????????????????????????????????????ж??????????????????????y???ж???????λ???????????????????
3.2.4??????????????????????????????
TCP/IP??????????????????????????????????????????
(1)???????(6)????滮??????128????С??С???????1536????С??????????????????????????????????memFlag????????????????????????????????????????????membFlag????????????е?????????????????Ч??????????β?????????????????????????????????????????memFlag???????????FALSE????Э????????????????????????????????????????????????????????????????????????????С?????????????????С??????????????????
(2)???????????????????????????С?????????С?????顣???3????????????????????????used??α???????????????????pSstart??pEend????????????Ч??????????????????????????????????????????????з????????????????飬?????????С???????鱻???????????н??????????????????????з???????????????μ????飬???????????????????used?????????pNext????pPre?????????????е????????????????????????(7)????Э?????????????????????????????????????????????????????????С???????????????
?????????????????????????RAM??????????????豸????????????ο????????????????????????????????????????????????
(1)???????????統(tǒng)??ò?DataSize??С????ò????????TCP??????????????????????DataSize??TCPHeadSize??С??????????дTCP????????????????????TCP??????С????????????TCP???????TCPHeadSize??С????棬??????TCPHead?????????????ò???????????????????????????????治???????????????У???????????????????????
(2)??????????ò??DataSize??С????????????????????????????DataSize??AllHeadSize??????AllHeadSize???????Э???????С??????????ò????????????????AllHeadSize??С????????????????pStart???????????????Ч?????????????????ò???????ò?????????????????ò?????????????TCP?????TCP??????pStart-TCPHeadSize??????????????TCP??????ɡ???????????????С????????ò????????????????Э?????С????Υ?????2?Э?????????????
3.2.5?????????????????????
zlIP???????л??????????????????е???????????????????????е?????????????????????????ooSeq????(7)?????????????TCP??????????????????????????????????????????????????????????????????????????????ooSeq???С??????????????TCP??????????????ooSeq?????????????TCP??????????????????????????????????????????????????unacked???У??????????????TCP?????????????????unacked???У????????????????????????TCP??????????unacked???е????TCP???????????????????·????????????????漲??????????????????????unsend???У????????????????С???????????????????????????????????????????unsend???У???????????TCP?????μ?????С???????ж??????????????????unsend???в?????????£??????ò???????????????????????unsend???С??????TCP??????С??????????????С??
3.2.6 ??????????
???????????????????????????TCP?????????????????????????????????????????????????????????????????????????????????????????????????????
?ο?????
[1] (????????)?й???????.ADI????TCP/IP?????Modem[Z].http://www.21ic.com.2000-10-11.
[2] (????????)?1?Keil???.Cx51 Compiler[Z].http://www.keil.com.2001-5.103??110.
[3] (????????)Adam Dunkels.uIP - A Free
Small TCP/IP Stack[Z].http://dunkels.com/adam/uip/index.html.2002-1-15.1
[4] (????????)Adam Dunkels.lwIP - News
Archive[Z].http://www.sics.se/~adam/lwip/news.html.2001-1-9.
[5] (???)jean j labrosse.??c/os-II?????????????????????.?????????.[M]???????й??????????磬2001.
29??30.
[6] (???)Douglas E Comer??
David L stevens.??TCP/IP????????????????[M]?????????????????? ??2000.24??25.
[7] (????????)Adam Dunkels.Design and
Implementation of the lwIP TCP/IP Stack[Z].http://www.sics.se/~adam/lwip/
documentation.html.2001-2-20.10-19.
??????TCP/IP????????/products_serial_server.htm
The specialty and
method in implementation
of TCP/IP in 51 serial MCU
Li Zhanglin1,Zhang Limin1
(1
ABSTRACT??In order to connect a 51 serial MCU to internet, it??s
necessary to develop a TCP/IP especially for 51 serial MCU. So We developed
zlIP, a TCP/IP designed especially for 51 serial MCU with KeilC51. Its
specialties include small code size, compatibility with BSD socket interface
etc. In order to test different aspects in implementation TCP/IP on 51, zlIP
1.0 emphasized on speed while zlIP 2.0 emphasized on facility of user
interface. The thesis analyzed specialties, which include speed, code size, ram
usage and complier, by comparing the tow editions of zlIP and absorbing the
strong points of other TCPIP. The thesis promoted and summarized some methods according
to these specialties and compared these methods. Finally, the thesis analyzed
some key techniques: TCP/IP user interface design, comparison of back-front and
multithread programming structure, memory management and avoidance of redundant
copy of packets, realization of packets arrangement, resending and window
control.
Key word:TCPIP;
MCU; zlIP