BeagleBoardQNX1.docx
《BeagleBoardQNX1.docx》由会员分享,可在线阅读,更多相关《BeagleBoardQNX1.docx(13页珍藏版)》请在冰豆网上搜索。
![BeagleBoardQNX1.docx](https://file1.bdocx.com/fileroot1/2023-4/19/7004b243-8e25-4129-a0eb-872217f3ba75/7004b243-8e25-4129-a0eb-872217f3ba751.gif)
BeagleBoardQNX1
实验1在VMWareQNX虚拟机上面运行简单的互斥量例子
1.1实验环境:
IDE:
QNXMomentics6.5
目标机:
VMware虚拟机软件+x86平台QNX虚拟机
1.2目标板环境建立
由于我们使用qnx公司提供的虚拟机设备进行实验,所以过程非常简单,只需要把虚拟机使用VMware打开就可以了。
A.路径:
虚拟机的目录在“实验\beagleboard_qnx\Neutrino650Target”下面
B.打开:
您可以使用VMware直接打开
C.启动:
默认启动就可以。
默认的的是带Photon的桌面环境。
D.登录:
用户名为root。
没有设置密码。
当然可以使用passwd命令给用户添加密码。
如图所示,登陆界面
如图所示Photon环境:
1.3IDE安装
Momentics6.5
它是基于Eclipse开发的为QNX项目提供帮助的IDE。
上面集成了像Cplugin等一些列支持QNX开发的插件。
特点:
使用非常地方便,无论是在编辑、编译还是在调试的时候。
安装
Windows下面的安装过程是很简单。
A.安装程序路径:
“实验\beagleboard_qnx\qnxsdp-6.5.0-201007091524-win32.exe”B.运行:
双击运行。
(注意事项:
因为是基于Eclipse的,那么,需要在主机上运行有相应的Java环境。
)
C.安装过程:
“下一步”就可以解决问题。
一般会把安装好的默认路径设C:
\QNX650
D.激活:
激活码如下图所示,这是个人申请的非商用激活码,仅供实验使用。
如果需要开发商业软件,请到QNX官网:
申请。
1.4建立工程
完成安装方面的工作,我们在IDE中开发相应的x86程序。
A.新建:
点击“File->New->QNXCProject”选择QNXC工程,然后“下一步”。
B.工程名:
输入相应的工程名称,点击“下一步”。
C.体系结构:
在BuildVariants当中选择x86体系。
QNX相应的工具链已经在IDE中。
点击“Finish”。
1.5编辑/编译
A.编辑:
在编辑区域中,修改代码(本节末附)
B.编译:
右击你的工程目录,选择“BuildMakeTarget”,直接编译运行。
1.6主机和虚拟机连接
A.打开目标板的连接:
在x86虚拟机上面输入命令qconn
B.查看目标板的IP:
输入命令ifconfig查看,实例是192.168.23.147
C.建立连接工程:
点击“File->Other->QNXTargetSystemProject”,然后“下一步”。
D.在“HostnameorIP”中填入目标机的IP地址。
点击“Finish”完成。
E.主机和目标机连接:
将主机网卡激活(一般方式将插上网线,指示灯亮)。
将主机IP设置成和目标板IP在一个网段。
这里介绍Windows7下的设置方式。
在桌面点击“Windows图标—>控制面板->网络和共享中心”,找到“本地连接”,点击打开。
进入“本地连接”后,选择“属性->Internet协议版本”
将IP地址改为如图所示,这里IP要和目标板在同一个网段,因此设置成“192.168.23.xxx”(xxx代表可选)。
子网掩码一般都是“255.255.255.0”。
默认网关是“192.168.23.1”(最后一位是1)。
点击“确定”返回。
F.在主机运行”cmd”打开终端。
运行“ipconfig”查看当前主机的IP,检查是否分配到IP。
使用“ping目标板IP”命令查看两台机器是否相连。
G.如果没有“ping”成功修改QNX虚拟机设置。
网络连接方式改为“Bridge”(桥接)。
1.7调试
A.返回到IDE,在视图中选择目标板系统,图中最右边的那一个
B.这时候在左下角的地方可以看见一个列表。
这个列表列出了现在目标板上面运行的进程。
可以双击查看。
C.回到“C/C++perspective”这个视图中选中同步—互斥量工程,点击“debug”的小虫子下拉菜单,选中“DebugConfiguration”。
D.选择“C/C++QNXQconn(IP)”,点击“New”。
E.右边出现你现在的工程。
在“C/C++Application”中点击“SearchProject”找到你需要调试的程序。
一般选择_g的因为在编译的时候使用了-g命令,有相关的调试信息在其中。
F.选择好目标板
G.点击“Apply”应用,然后点击“Debug”。
自动进入到“Debug”视图。
点击运行的绿色箭头可以运行程序。
在下方的控制台可以查看打印信息。
H.调试技巧:
调试包括设置断点、单步跟踪等等,也有相应的快捷键。
这里不再赘述。
1.8附录(互斥量示例程序)
#include
#include
#include
#include
#include
voidbushchanger_nomutex();
voidkerrychanger_nomutex();
voidbushchanger_mutex();
voidkerrychanger_mutex();
char*firstname;
char*lastname;
pthread_mutex_tpresidentmutex;
intmain(intargc,char*argv[]){
inti;
pthread_tt1,t2;
firstname=malloc(32);
lastname=malloc(32);
printf("Thepresidentmixer\n");
printf("Demonstratingtheusageofmutexes\n");
printf("\nStartingthreadsWITHOUTmutexusage!
!
\n");
pthread_create(&t1,NULL,(void*)&bushchanger_nomutex,NULL);
pthread_create(&t2,NULL,(void*)&kerrychanger_nomutex,NULL);
for(i=0;i<40;i++){
delay(500);
printf("%s%sforpresident!
\n",firstname,lastname);
}
pthread_detach(t1);//don'tcareaboutreturn
pthread_detach(t2);//valuesofthreads1&2
pthread_abort(t1);//killthread1
pthread_abort(t2);//killthread2
printf("\nNowinvokingfunctionsWITHmutexusage!
!
\n");
pthread_mutex_init(&presidentmutex,NULL);
pthread_create(&t1,NULL,(void*)&bushchanger_mutex,NULL);
pthread_create(&t2,NULL,(void*)&kerrychanger_mutex,NULL);
for(i=0;i<40;i++){
delay(500);
pthread_mutex_lock(&presidentmutex);
printf("%s%sforpresident!
\n",firstname,lastname);
pthread_mutex_unlock(&presidentmutex);
}
returnEXIT_SUCCESS;}
voidbushchanger_nomutex(){
while
(1){
strcpy(firstname,"George");
delay(55);
strcpy(lastname,"Bush");
delay(55);
}
}
voidkerrychanger_nomutex(){
while
(1){
strcpy(firstname,"John");
delay(77);
strcpy(lastname,"Kerry");
delay(77);
}
}
voidbushchanger_mutex(){
while
(1){
pthread_mutex_lock(&presidentmutex);
strcpy(firstname,"George");
delay(55);//delaytomaketheproblemmorevisible
strcpy(lastname,"Bush");
pthread_mutex_unlock(&presidentmutex);
delay(55);
}
}
voidkerrychanger_mutex(){
while
(1){
pthread_mutex_lock(&presidentmutex);
strcpy(firstname,"John");
delay(77);//delaytomaketheproblemmorevisible
strcpy(lastname,"Kerry");
pthread_mutex_unlock(&presidentmutex);
delay(77);}}