VxWorks for lpc2210 Network Application Programming Practice ZZ

Source: Internet
Author: User
Tags 0xc0

Sender: gdtyy (gdtyy), email area: embedded
Title: VxWorks for lpc2210 Network Application Programming Practice
Mailing station: shuimu community (Mon Jun 25 23:26:20 2007), within the station

***************************************
* VxWorks for lpc2210 network application programming practices *
***************************************
------ Choose "ECOs value-added package" and choose VxWorks network application programming practices
Asdjf@163.com www.armecos.com

VxWorks provides excellent network support, stability, and efficiency. The clever use of the memory pool enables "zero-memory copy"
The use of the netjobadd function reduces the interruption delay time. You only need to implement the network driver to run the complete
TCP/IP protocol stack. Download and Debug programs over the network much faster than the serial port. We have transplanted easyarm2200 and
The VxWorks Network Driver BSP on smartarm2200. The following uses demo3.c as an example to describe VxWorks
Network Application Programming.

In this example, the webpage demonstration program on the Development Board is transplanted on VxWorks and passed the actual test (
Smartarm2200), fast response (0.09 s on average), Ping test (74 byte packet) average response time
It is 3 ms, and the ARP response time is 3 ms. The source code is as follows:

# Include "socklib. H"
# Include "inetlib. H"

# Define stack_size 2000

Void webserver_test (INT Arg );

Unsigned char httpweb [] = {
"HTTP/1.0 200 OK/R/N"
"Date: Mon, 24 Nov 2003 01:24:17 GMT/R/N"
"Server: microhttp/1.0 zlgmcu Corporation/R/N"
"Accept-ranges: Bytes/R/N"
"Connection: Keep-close/R/N"
"Content-Type: text/html/R/N"
"/R/N"
};

Unsigned char web [] = {
"<HTML>/R/N"
"<Head>/R/N"
"<Title> arm_net demo webpage (Zhou ligong MCU) </title>/R/N"
"<Body alink = green background =/100.bmp bgcolor = # f1f1dd link = red/R/N"
"Vlink = # 321afd>/R/N"
"<H1> Hello welcome to easyarm webserver "<Ul>/R/N"
"<Li> <a href =/" http://www.zlgmcu.com // "> Zhou ligong MCU website </a>/R/N"
"<Li> <a href =/" http://www.zlg.cn // "> Zhou ligong MCU internal BBS </a>/R/N"
"<Li> <a href =/" http://www.zlgmcu.cn // "> Zhou ligong microcontroller </a>/R/N"
"</Ul>/R/N"
"</Body>/R/N"
"</Html>/R/N"
};

Unsigned char httpgif [] = {
"HTTP/1.0 200 OK/R/N"
"Date: Mon, 24 Nov 2003 01:24:17 GMT/R/N"
"Server: microhttp/1.0 zlgmcu Corporation/R/N"
"Accept-ranges: Bytes/R/N"
"Connection: Keep-close/R/N"
"Content-Type: image/BMP/R/N"
"/R/N"
};

Unsigned char BMP [442] = {
0x42, 0x4d, 0xb6, 0x01,0 X, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0x00,
0 x, 0x00, 0x1a, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0x00,
0 x, 0 x, 0 x, 0 x, 0 x, 0x00, 0xc4, 0x0e, 0 x, 0x00, 0xc4, 0x0e, 0 x, 0 x, 0 x, 0x00,
0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0x80, 0 x, 0 x, 0 x, 0x80,
0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0 x, 0x80, 0x80, 0x80, 0 x, 0x80, 0x80,
0 x, 0x00, 0xc0, 0xc0, 0xc0, 0 x, 0x80, 0x80, 0x80, 0 x, 0 x, 0x00, 0xff, 0 x, 0x00, 0xff,
0x00,0x00,0x00, 0xff, 0xff, 0x00, 0xff, 0x00,0x00,0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0xff,
0x00,0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf6, 0x66, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0x66,0x66, 0x6f, 0x6f, 0xff, 0x66,0x66,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xf6, 0xff, 0xff, 0x6f, 0xf6, 0xff, 0xf6,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xff, 0x6f, 0xf6, 0xff, 0xf6,
0xff, 0xff, 0xff, 0 x, 0 x, 0x00, 0xff, 0xff, 0xff, 0xff, 0xf6, 0xff, 0xf6, 0xff, 0xff,
0x6f, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xf6, 0xff, 0x6f, 0xff,
0x6f, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xf6, 0x66,0x66, 0xf6, 0xff, 0xf6, 0x66,
0x6f, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x6f, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00,0x00,0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0 x, 0 x, 0 x, 0x00
};

Void demo3 (void)
{
Printf ("demo3 start.../N ");

Taskspawn ("webserver_test", 90, 0, stack_size, webserver_test, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0 );
}

Void
Webserver_test (INT Arg)
{
Struct sockaddr_in host, client;
Int S, SA, e_source, Len, sockaddrsize;
Unsigned char Buf [400];

S = socket (af_inet, sock_stream, 0 );
If (S <0 ){
Return;
}

/* Set up host address */
Sockaddrsize = sizeof (struct sockaddr_in );
Host. sin_family = af_inet;
Host. sin_len = sizeof (host );
Host. sin_addr.s_addr = inaddr_any;
Host. sin_port = ntohs (80 );

If (BIND (S, (struct sockaddr *) & host, sizeof (host) <0 ){
Return;
}

Listen (S, somaxconn );

While (1 ){
Memset (BUF, 0, sizeof (BUF ));

If (SA = accept (S, (struct sockaddr *) & client, & sockaddrsize) <0 ){
Printf ("Accept error! /N ");
Continue;
}

Printf ("server: http request arrived from % s: % d/N ",
Inet_ntoa (client. sin_addr), ntohs (client. sin_port ));

Len = read (SA, Buf, sizeof (BUF ));

If (BUF [5] = ''){
Len = write (SA, httpweb, sizeof (httpweb)-1 );
Len = write (SA, web, sizeof (Web ));
}
Else if (BUF [5] = '1 '){
Len = write (SA, httpgif, sizeof (httpgif)-1 );
Len = write (SA, BMP, sizeof (BMP ));
}

Close (SA );
}
}

The following figure shows how to use it:
Similar to the method described in "VxWorks for lpc2210 application programming practices", the only difference is that
Set target server to wdbrpc.
The following describes the settings of different parts.

Set target server and use network RPC for communication. the IP address of the target machine is 192.168.0.2, timeout and retry.
If the network speed is slow during debugging (because debugging information is added), the default value may be used.
The connection fails, and the network speed is very fast during normal operation. This problem does not exist. Note: Core File and symbols
The file must be consistent with the VxWorks file written in flash, that is, the ELF File With debugging information.
(Vxworks_romresident ). If the connection is successful, a success message is displayed, and a target icon is displayed in the tray.

[Img] http://www.armecos.com/pic21ic/y1.gif#/img]
[Img] http://www.armecos.com/pic21ic/y2.gif#/img]

Other operations are the same as those described in VxWorks for lpc2210 application programming practices.
.

The running information displayed on the Super Terminal.

[Img] http://www.armecos.com/pic21ic/y3.gif#/img]

You can use IE to access 192.168.0.2 to view the built-in web page. The response speed is quite fast (0.09 seconds ).

The Network RPC-based debugging shell is much faster than the serial port-based debugging shell. After "I" is input, it is almost a burst of tasks.
Status list information.

[Img] http://www.armecos.com/pic21ic/y5.gif#/img]

This is the result of the ping test. Through sniffer packet capture analysis, the average response time of the ping test (74-byte packet) is
3 ms, ARP response time is 3 ms. It seems that VxWorks is really good.

[Img] http://www.armecos.com/pic21ic/y6.gif#/img]
--

※Source: · Shui Mu community http://newsmth.net · [from: 61.149.56. *]
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.