还剩6页未读,继续阅读
文本内容:
实验六多线程实验和实验AD嵌入式系统原理及应用实验报告院(系)小组成员指导教师一实验要求参考实验指导书多线程实验和实验,分析源码
1.AD编写采集多线程程序,实现以下功能AD.线程在循环中对指定的通道进行转换和显示,显示格式为二火火火21:AD ADxo其中为通道号初始值为每循环一次延时
3.x0-2,0300ms线程:接受用户输入,当输入数值时表示指定通道线程的通道号要随指
4.20-2AD1定值改变;当输入字符时显示暂停;输入时程序终止退出输入其他键值S ESC时维持原状扩展部分将线程分为个线程,一个用来计算,一个用来显示12实验步骤
2.1将编成完的程序打包放入虚拟机
1192.
168.010/arm2410s;将挂载到开发板中新建的文件夹里2arm2410s hostWi串口连接开发板・Xshell2QFile EditView ToolsWindow Help]苞白▼皆|国塞昆|依|昌|▼|瑞多|
⑦•©Address[*]cd/mnt/yaffs/[/mnt/yaffs]mount-t nfs
192.
168.
0.10:/arm2410s/mnt/yaffs/host/[/mnt/yaffs]Is485control hostkbd_gpm pcmcia-mod ucosQtopiada iccardlib sdcardvideoad expide lost+found serial_8250webbluetooth£pga init.sh motorsound wirelesscangps_gprs irdamplayer touchscreen[/mnt/yaffs]cd host/[/mnt/yaffs/host]Is busybox-l.00-pre10exam03kernel-2410sdemos expmicrowindowsdoc gdbminiguiexamOl imgrootexam02insight-
6.0sh进入到虚拟机的文件夹里生成文件make,Last login:ThuJan413:00:102018[root@localhost root]#cd..[root@localhost/]#132017arm2410sbinbootdevetchomeinitrdliblost+foundniscmntoptprocrootsbintftpboottmpusrvarwang[root@localhost/]#cdarm2410s/[root@localhostbusybox-l.00-prel0demosdocexamOlexam02exam03expgdbimginsight-
6.0kernel-24103microwindowsminiguirootsh[root@localhost ann2410s]#cdexpexp]#[root@localhost cdbasic/basic]#cd[root@localhost04_ad_0/[root@localhost04_ad_0]#makearmv41-unknown-linux-gcc-c-omain.omain.carmv41-unknown-linux-gcc-o../bin/admain.o-Ipthreadarmv41-unknown-linux-gcc-oadmain.o-Ipthread[root@localhost04_ad_0]♦ann2410s]#13[/mnt/yaffs/host]cd exexamOl/exam02/夕Open▼牛I事口连接开发板牛2网法连接虚拟机examO3Zexp/[/mnt/yaffs/host]cd expConnectedto
192.
168.
0.1[0/m:22n.t/yaffs/host/exp]IsMakefileRules.makbasic[/mnt/yaffs/host/exp]cdbasic/[/mnt/yaffs/host/exp/basic]Is bootloaderdrivers01_hello05_da10_dcmotor Makefilereadme.txt02_pthread0€_can ll_stepmotor Rules.mak03_tty07_gps121485bin041ad08_gprs13_iccardtest bluetooth041ad_009_httpd iQedkeyboard[/mnt/yaffs/host/exp/basic]cd041ad_0/[/mnt/yaffs/ho3t/exp/basic/04__ad2o]ls04_ad a二hardware.h main.o s3c2410-adc.h arcMakefilebin main.c readme.txt进入串口连接开发板中运行3三实验程序!***********************************************[/mnt/yaffs/host/exp/ba3ic/04_ad_0]./adby threewater\***********************************************/#include stdio.h#include unistd.h#include sys/types.h#include sys/ipc.h#include sys/ioctl.h#include pthread.h#include fcntl.h#include s3c2410-adc.h#define ADC_DEV/dev/adc/Orawstatic int adc_fd=-1;static int init_ADdevicevoidifadc_fd=openADC_DEV,O_RDWR0{printfError opening%s adcdevice\n,ADC_DEV;return-1;static intGetADresultint channel二int PRESCALEOXFF;int data=ADC_WRITEchannel,PRESCALE;writeadc_fd,data,sizeofdata;readadc_fd,data,sizeofdata;return data;static intstop=0;intadc_num;int ch;出*******//******escstatic void*comMonitorvoid*datawhilel stop=1;⑴;exit break;return NULL;}/*****采样路值*******/0-2A/Dint adn;int pausenum=0;void*showvoid*datafloat d;while adn==0||adn==l||adn==2{〃采样路值〜2A/D whilestop==0{whilepausenum==Od=floatGetADresultadn*
3.3/
1024.0;printfCH%d=%
8.4fv\t,,,adn,d;usleepl;printf\r;break;显示路大…//***a,b,c0~2void*inputvoid*data charchr;pthread_t th_show;whilel scanf%c,chr;chr=getchar;路if chr==48||chr==49||chr==50//a,b,c-0-2adc_num=chr;adn=adc_num-48;//adc_num=chr;adn=adc_num-48;//}*//*if chr==43{adc_num=chr;adn=O;}if chr==38{adc_num=chr;adn=l;}if chr==77{adc_num=chr;停止adn=2;}*/else ifchr==115//s{pausenum=1;退出else ifchr==27//esc{ch=chr;stop=l;〃任意键继续else ifchr!=115{pausenum=0;//break;/*******************/int mainvoid{inti;float d;pthread_t th_com,th_show,th_input;void*retval;//set s3c44b0AD registerand startADifinit_ADdevice0return-1;/*Create thethreads*/pthread_createth_com,NULL,comMonitor,0;pthread_createth_input,NULL,input,0;printf\nget thekey input\n;pthread_createth_show,NULL,show,0;/.Wai.unti.produce.an.consume.finish*/pthreadjointh_input,retval;pthreadjointh_show,retval;pthreadjointh_com,retval;printf\n;return0;三实验结果用串口连接开发板・Xshell2QFile EditView ToolsWindow HelpAddressCH0=O.hOOOvCH0=O.OOOOwCH1=
3.2968jCH2=h
3.2968vCH0=O.OOOOwCH1=3j2968vCH2=
3.2968WgH2=
3.2968VCH2=
3.2968shH2=
3.2968VrH2=
3.2968VCHO=O.OOOOvOvCHO=O.OOOOv[/mnt/yaffs/control/exp/basic/04_ad2]cd..[/mnt/yaffs/control/exp/basic]cd..[/mnt/yaffs/control/exp]cd..[/mnt/yaffs/control]cd..[/mnt/yaffs]mount-t nfs
192.
168.
0.10:/ann2410s/mnt/yaffs/control[/mnt/yaffs]cd control/[/mnt/yaffs/control/exp/basic]Is01_hello04_adl08_gprs13_iccardtesr bluetooth02_pthread09_httpd lOedkeyboard02_pthreadl05_da10_dcmotor Makefilereadme.txt03_tty06_can ll_3tepmotor Rules.mak04_ad07_gps二bin[/mnt/yaffs/control/exp/basic]cd04_ad212425[/mnt/yaffs/control/exp/basic/04_ad2]./adget thekey inputC10=O.OOOOwCH1=322968VCH2=
3.2968WCHO=
0.00001CH1=322968VCH2=
3.2960VCHO=O.sOOOvCHO=O.OOOOv gCHO=
0.[00vCHO=O.OOOOv[/mnt/yaffs/control/exp/basic/04_ad2]JOpen▼中工网关连接去拟机够2里口连接开实验总结I实验完成效果
4.1可以实现多线程采样效果;♦♦AD当输入数值时表示指定通道线程的通道号要随指定值改变;当输入字符时AD1s显示暂停;当输入任意字符时重新开始;输入时程序终止退出输入其他键ESC值时维持原状;可以实现暂停、重新开始、退出功能;分为个线程,一个用来获取键值,一个用来显示,一个用来退出3实验总结
4.2在本次实验过程中,遇到了许多问题,开始时,不能实现键入数字来指定通道AD线程的通道号,只能实现通过字母、、来指定通道线程的通道号,原因是获取h jk AD键值的字符串,开始时设置为整型,后面将其改为字符来获取键值后,就可以通char过键入数字来指定通道线程的通道号AD通过本次实验,提高了我使用软件编程(语言)的能力,使我的逻辑思维更加清晰,C也让我体会到了编程的乐趣;设计之前要构思好大致方向,设计中出现错误要反复调试,可以设计一小部分,然后调试一小部分,可以使问题简单化;在课堂上学习的知识只是一小部分,真正来实现的时候我们就会发现在这个过程中它涉及的知识其实更广,实现起来并不是那么的容易,因此我们需要不断的自主学习,以扩宽知识量;在这次课程设计中,我感觉收获最大的就是学到了一种分析问题、解决问题的方法同时加深了对嵌入式原理的理解,也给我今后处理类似问题提供了一个处理方法。
个人认证
优秀文档
获得点赞 0