毕业论文(设计)基于uCLinux 和S3C4510B 的网络通信设计.doc

上传人:文库蛋蛋多 文档编号:4149464 上传时间:2023-04-07 格式:DOC 页数:10 大小:442.50KB
返回 下载 相关 举报
毕业论文(设计)基于uCLinux 和S3C4510B 的网络通信设计.doc_第1页
第1页 / 共10页
毕业论文(设计)基于uCLinux 和S3C4510B 的网络通信设计.doc_第2页
第2页 / 共10页
毕业论文(设计)基于uCLinux 和S3C4510B 的网络通信设计.doc_第3页
第3页 / 共10页
毕业论文(设计)基于uCLinux 和S3C4510B 的网络通信设计.doc_第4页
第4页 / 共10页
毕业论文(设计)基于uCLinux 和S3C4510B 的网络通信设计.doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《毕业论文(设计)基于uCLinux 和S3C4510B 的网络通信设计.doc》由会员分享,可在线阅读,更多相关《毕业论文(设计)基于uCLinux 和S3C4510B 的网络通信设计.doc(10页珍藏版)》请在三一办公上搜索。

1、基于uCLinux和S3C4510B的网络通信设计作者:马学文朱名日程小辉文章来源:单片机及嵌入式系统应用引言Linux是一种很受欢迎的操作系统,与UNIX系统兼容,开放源代码。它原本被设计为桌面系统,现在广泛应用于嵌入式设备。uCLinux正是在这种氛围下产生的。在uCLinux这个英文单词中,u表示Micro,是“小”的意思;C表示Control,是“控制”的意思,所以uCLinux就是Micro-Control-Linux,字面上的理解就是“针对微控制领域而设计的Linux系统”。它也是针对无MMU(内存管理单元模块)的微处理器设计的操作系统。S3C4510B就是属于该类的微处理器。Sa

2、msung公司的S3C4510B是基于以太网应用系统高性价比16/32位RISC微控制器,内含一个由ARM公司设计16/32位ARM7TDMI RISC处理器核。ARM7TDMI为低功耗、高性能的16/32核,最适合用于对价格及功耗敏感的应用场合。除了ARM7TDMI核以外,S3C4510B还有许多重要的片内外围功能模块,其中就有1个以太网控制器,用于S3C4510B系统与其它设备的网络通信工程。在S3C4510B的网络控制平台上移植了uCLinux操作系统,并在这个嵌入式平台上实现网络控制的各项功能。本文的叙述的网络通信工程就是其中最主要的功能。1 基于S3C4510B以太网电路的设计思路与

3、实现作为一款优秀的网络控制器,基于S3C4510B的系统若没有以太网接口,其应用价值就会大打折扣,因此,就整个系统而言,以太网接口电路应是必不可少的,但同时也是相对较复杂的。从硬件的角度看,以太网接口电路主要由MAC控制器和物理层接口(Physical Layer,PHY)两大部分构成。S3C4510B内嵌一个以太网控制器,支持媒体独立接口(Media Independent Interface,MII)和带缓冲DMA接口(Buffered DMA Interface,BDI),可在半双工或全双工模式下提供情报0M/100Mbps的以太网接入。在半双工模式下,控制器支持CSMA/CD协议,在全

4、双工模式下支持IEEE802.3MAC控制层协议。因此,S3C4510B内部实际上已包含了以太网MAC控制,但并未提供物理层接口,故需外接一片物理层芯片,以提供以太网的接入通道。常用的单口10M/100Mbps高速以太网物理层接口器件主要有RTL8201、DM9161等,均提供MII接口和传统7线制网络接口,可方便地与S3C4510B接口。以太网物理层接口器件主要功能一般包括:物理编码子层、物理媒体附件、双绞线物理媒体子层、10BASE-TX编码/解码器和双绞线媒体访问单元等。在该设计中,使用DP9161作为以太网的物理层接口。DM9161是一款低功耗、高性能的CMOS芯片,支持10M和100

5、M的以太网传输,它起编码、译码输入和输出数据的作用。它与S3C4510B的引脚连线如图图1所示。由于S3C4510B片内已民用有带MII接口的MAC控制器,而DM9161也提供了MII接口,各种信号的定义也很明确,因此DM9161与S3C4510B的连接时序衔接,可以达到很好的网络信号传递的目的。图2为DM9161在本系统中的实际应用电路(图中右下方的1、2、3以及14、15、16分别与网络隔离变压器相应引脚相连)。S3C4510B的MAC控制器可通过MDC/MDIO管理接口控制多达斡尔1个DM9161,每个DM9161应有不同的PHY地址(可从00001B11111B)。当系统复位时,DM9

6、161锁存引脚9、10、12、13、15的初始状态作为与S3C4510B管理接口通信工程的PHY地址;但该地址不能设为00000B,否则DM9161进入掉电模式。信号的发送和接收端应通过网络隔离变压器和RJ45接口接入传输媒体,实际应用电路如图书室所示。2 Linux下的网络编程协议分析Linux下的TCP/IP网络协议栈的各层之间是通过一系列互相连接层的软件来实现Internet地址族的,结构层次如图4所示。其中BSD socket层由专门用来处理BSD socket的通用套接字管理软件来处理,它由INET socket层来支持。INET socket为基于IP的协议TCP和UDP管理传输端

7、点。UDP(用户数据报协议)是一个无连接协议,而TCP(传输控制协议)是一个可靠的端对端协议。传输UDP包的时候,Linux不知道也不关心它们是否安全到达了目的地。TCP则不同。在TCP连接的两端都需要加上一个编号,以保证传输的数据被正确接收。在IP层,实现了Internet协议代码,这些代码要给传输的数据加上一个IP头,并且知道如何把传入的IP包送给TCP或者UDP协议。在IP层以下,就是网络设备来支持所有的Linux网络工作,如PLIP、SLIP和以太网。3 uClinux环境下的socket编程网络的socket数据b传输是一种特殊的I/O,socket也是一种文件描述符,也具有一个类似

8、文件的函数调用socket()。该函数返回一个整型的socket描述符,随后的连接建立、数据传输等操作都是通过该socket函数实现的。常用的socket类型有两种:流式socket和数据报式socket。两者的区别在于:前者对应于TCP服务,后者对应于UDP服务。31 uCLinux中socket编程中用到的函数(1) socket函数为了执行I/O,一个进程必须做的第一件事情就是调用socket函数,指定期望的通信协议类型(使用IPv4的TCP、使用IPv6的UDP、Unix域字节流协议等),其函数结构如下:int socket(int family,int type,int protoc

9、ol);/*返回:非负描述字成功,-1出错*/代码中的family指明协议族。套接口的类型type是某个常值。一般来说,函数socket的参数protocol主设置为0,socket函数成功时返回一个小的非负整数值。为了得到这个数值,我们指定协议族(IPv4IP、v6或Unix)和套接口类型(字节流、数据报或原始套接口)。(2)connect函数TCP客户用connect函数来建立一个与TCP服务器的连接。Int connect(int sockfd,const struct sockaddr* servaddr,socklen_t addrlen);/*返回:0成功,-1出错*/Sockfd

10、由socket函数返回数值,第二、第三个参数分别是一个批晌套接口地址结构的指针和该结构的大小。套接口叶址结构必须含有服务器的IP地址和端口号。(3)bind函数函数bind给套接口分配一个本地协议地址。对于网际协议,协议地址是非颠倒2位IPv4地址16位的TCP或UDP端口号的组合。Int bind(int sockfd,const struct sockaddr* myaddr,socklen_t addrlen);/*返回:0成功,-1出错*/第二个参数量个指向特定于协议地址结构的指针,第三个参数是该地址结构的长度。对于TCP,调用函数bind可以指定一个端口,指定一个IP地址。可以两者都

11、指定,也可以一个也不指定。(4)listen函数函数listen仅被除数TCP服务器调用。它做两件事件事情,当函数socket创建一个套接口时,被假设为一个主动套接口。也就是说,它是一个将调用connect发起连接的客户套接口,函数listen将未连接的套接口转换成被动套接口,指示内核应接受指向此套接口的连接请求。根据TCP状态转换调用函数listen导致套接口从CLOSED状态转换到LISEN状态。函数的第二个参数规定了内核为此套接口排队的最大连接个数。Int listen(int sockfd,int backlog);/*返回:0成功,-1出错*/一般来说,此函数应在调用函数socket

12、和bind之后,调用函数accept之前调用。(5)accept函数accept函数由TCP服务器调用,从已完成连接队列头返回下一个已完成连接。若已完成连接队列为空,则进程睡眠。(假定套接口噗缺省的阻塞方式)int accept(int sockfd,struct sockaddr*cliaddr,socklen_t*addrlen);/*返回非负数值OK,-1出错*/参数cliaddr和addrlen用来返回连接对方进程(客户)的协议地址。Addrlen是结果参数,调用前,将由*addrlen所指示的整数值置为由cliaddr所旨的套接口地址结构的长度,返回时,此整数值即为由内核存在此套接口

13、地址结构内的准确字节数。32 uClinux中网络通信编程的实现在uCLinux中进行socket编程,一般按照图书资料所示流程编写网络应用程序。除了熟悉前文提出的函数外,还应知道两个重要的数据结构。因为在计算机中,数据存储有两种字节优先顺序:高位字节优先和低位字节优先。在互联网上,数据是以高位字节优先顺序传输的,所以对于在内部以低位字节优先方式存储的数据,需要进行转换才能在互联网上传输。*struct sockaddr:用来保存socket信息struct sockaddrunsigned short sa_family;/*地址族,AF_xxx*/char sa_data14; /*14字

14、节的协议地址*/;*struct sockaddr_in;和来进行数据类型的转换struct sockaddr_inshort int sin_family; /*地址族*/unsigned short int sin_port; /*端口号*/sruct in_addr sin_addr; /*IP地址*/unsigned cha sin_zero8; /*填充0,以保持与struct sockaddr同样大小*/;至此,可经编出uCLinux的网络通信工程程序。在此给出部分uCLinux下实现网络通信源代码及其Makefile文件的编写实例。main()函数中部分代码如下:int sock

15、fd;unsigned int uiip;char szsendbuf1024;char head8;int*phead=head+4,nsize=1024,allsize=0;struct sockaddr_in servaddr;sockfd=socket(AF_INET,SOCK_STREAM,0);/*创建socket*/bzero(&servaddr,sizeof(struct sockaddr_in);servaddr.sin_family=AF_INET;servaddr.sin_port=8888;/htons(8888); /*指定通信端口*/将命令行输入的字符串IP转换为c

16、onnect函数可识别的整数uiip。本来在Linux上开发时可以使用C库函数inet_pton(),但在uCLinux的库中不支持该函数,因此只好自己实现该函数的功能。aiptoi()如下所示:aiptoi(argv1,&uiip);servaddr.sin_addr.s_addr=uiip; /*指定连接的对端IP*/connect(sockfd,(struct sockaddr)&servaddr,sizeof(struct sockaddr);/*连接对端接收代码*/fp=fopen(kongzhi.htm,r); /*打开控制页面*/while(nsize=1024)bzero(sz

17、sendbuf,1024); /*每次从文件中读取巧024个字节发送出去,若读出少于1024字节结束*/nsize=phead=fread(szsendbuf,1,1024,fp);/*从文件中读取并填入发送BUFFER中*/write(sockfd,head,8);/*发送协议头*/nsize=write(sockfd,szsendbuf,nsize);/*发送*/fclose(fp);uCLinux中的Makefile需做的修改如下:CC=gccCOFF2FLAT=/uclinux/coff2flt-0.3/coff2fltCFLAGS=-I/uclinux/uC-libc-pic/inc

18、ludeLDFLAGS=/uclinux/uC-libc-pic/libc.aethernet:Ethernet.o$(CC)-o $.coff ethernet.c $(CFLAGS)$(LDFLAGS)$(COFF2FLAT)-o Ethernet ethernet.coffcp Ethernet /Ethernetclean:rm -f Ethernet Ethernet.o需要注意的是:uCLinux中不带有pthread库,在编写网络程序要切记;在uCLinux环境下,处理器(硬件)和内核黄素(软件)均不提供内存管理机制,所以程序的地址空间等同于内存的物理地址空间。在程序中可直接对I

19、/O地址进行操作,而不需要申请和释放I/O空间,但需要用户自己来检查所操作的I/O地址的占用情况。结语由于网络通信工程广泛应用在嵌入式设备中,以往的文章只是泛泛地叙述网络通信设计的某一个方面。本文结合实际工程项目,从硬件电路的搭建、应用软件的设计要点。这对于在嵌入式设备中,特别是基于uCLinux的系统中应用网络通信有重要的参考意义。Editors note: Judson Jones is a meteorologist, journalist and photographer. He has freelanced with CNN for four years, covering seve

20、re weather from tornadoes to typhoons. Follow him on Twitter: jnjonesjr (CNN) - I will always wonder what it was like to huddle around a shortwave radio and through the crackling static from space hear the faint beeps of the worlds first satellite - Sputnik. I also missed watching Neil Armstrong ste

21、p foot on the moon and the first space shuttle take off for the stars. Those events were way before my time.As a kid, I was fascinated with what goes on in the sky, and when NASA pulled the plug on the shuttle program I was heartbroken. Yet the privatized space race has renewed my childhood dreams t

22、o reach for the stars.As a meteorologist, Ive still seen many important weather and space events, but right now, if you were sitting next to me, youd hear my foot tapping rapidly under my desk. Im anxious for the next one: a space capsule hanging from a crane in the New Mexico desert.Its like the se

23、t for a George Lucas movie floating to the edge of space.You and I will have the chance to watch a man take a leap into an unimaginable free fall from the edge of space - live.The (lack of) air up there Watch man jump from 96,000 feet Tuesday, I sat at work glued to the live stream of the Red Bull S

24、tratos Mission. I watched the balloons positioned at different altitudes in the sky to test the winds, knowing that if they would just line up in a vertical straight line we would be go for launch.I feel this mission was created for me because I am also a journalist and a photographer, but above all

25、 I live for taking a leap of faith - the feeling of pushing the envelope into uncharted territory.The guy who is going to do this, Felix Baumgartner, must have that same feeling, at a level I will never reach. However, it did not stop me from feeling his pain when a gust of swirling wind kicked up a

26、nd twisted the partially filled balloon that would take him to the upper end of our atmosphere. As soon as the 40-acre balloon, with skin no thicker than a dry cleaning bag, scraped the ground I knew it was over.How claustrophobia almost grounded supersonic skydiverWith each twist, you could see the

27、 wrinkles of disappointment on the face of the current record holder and capcom (capsule communications), Col. Joe Kittinger. He hung his head low in mission control as he told Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunday.The weather play

28、s an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-

29、day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause), he can expect a

30、lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet (22.7 miles/36.53 kilometers). Here, Fearless Felix will unclip. He will roll back the door.Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes

31、 the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end.Skydiver preps for the big jumpWhen he jumps, he is ex

32、pected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a s

33、tabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (27

34、7 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 f

35、eet (7,620 meters).It might not be the moon, but Kittinger free fell from 102,800 feet in 1960 - at the dawn of an infamous space race that captured the hearts of many. Baumgartner will attempt to break that record, a feat that boggles the mind. This is one of those monumental moments I will always remember, because there is no way Id miss this.

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号