VxWorks Tips

用过一段时间VxWorks/Tornado,知道一点皮毛。希望这些Tips能对初学者能有所帮助。 如何制作VxWorks的启动盘(软盘)1.网卡的设置。 VxWorks支持的网卡(即目标机可用网卡)有限,主要有: Eagle/Novell NE2000 interface? 3COM EtherLink III interface? SMC 91c9x Ethernet interface? Intel Ether Express PRO100B PCI? 对于其它网卡,需要相应的驱动程序。 1.1选择相应的网卡(假设使用的是NE2000网卡(NE2000 compatible)) 假设Tornado目录为C:/Tornado/ 修改C:/Tornado/target/config/pcPentium/config.h,选择相应的网卡(define你想要的网卡,把其它网卡undef掉) 例如: /* Network driver options */ #define INCLUDE_END /* Use Enhanced Network Drivers */ #undef INCLUDE_ULTRA /* include SMC Elite16 Ultra interface */ #define INCLUDE_ENE /* include Eagle/Novell NE2000 interface */ #undef INCLUDE_ELT /* include 3COM EtherLink III interface */ #undef INCLUDE_ESMC /* include SMC 91c9x Ethernet interface */ #undef INCLUDE_FEI /* include Intel Ether Express PRO100B PCI */ #define INCLUDE_SLIP /* include serial line interface */ #define SLIP_TTY 1 /* serial line IP channel COM2 */ #undef INCLUDE_ELC /* include SMC Elite16 interface */ #undef INCLUDE_EEX /* include INTEL EtherExpress interface */ #undef INCLUDE_EEX32 /* include INTEL EtherExpress flash 32 */ #undef INCLUDE_EX /* include Excelan Ethernet interface */ #undef INCLUDE_ENP /* include CMC Ethernet interface*/ #undef INCLUDE_SM_NET /* include backplane net interface */ #undef INCLUDE_SM_SEQ_ADDR /* shared memory network auto address setup */ #undef INCLUDE_EL_3C90X_END /* 3com fast etherLink XL PCI */ #undef INCLUDE_LN_97X_END /* AMD 79C972 END DRIVER */ 1.2 若是ISA网卡(如NE2000),要设置I/O地址和中断级(若是PCI网卡(如Intel82557),则不需要。): Use the configuration program supplied by the manufacturer to set the I/O address;? in some cases you can set IRQ levels with the same configuration program. (一般可用默认值,若不行,则要设置网卡的中断号和 I/O地址设置) 网卡的IO地址和中断级在C:/Tornado/target/config/pcPentium/config.h: #define IO_ADRS_ENE 0x300 #define INT_LVL_ENE 0x05? /* Hardware jumper is used to set */ /* RJ45(Twisted Pair) AUI(Thick) BNC(Thin) */ 2.修改“DEFAULT_BOOT_LINE”: //--------------------------------------------------------------------------------------------- #define DEFAULT_BOOT_LINE / "fd=0,0(0,0)host:/fd0/vxWorks h=192.168.0.15 e=192.168.0.50 u=target o=ene" /* 从软盘起 */ 或 #define DEFAULT_BOOT_LINE / "ene(0,0)hello:vxWorks h=192.168.2.1 e=192.168.2.3 u=zhuwei pw=123" /* 从网络起 */ 3.Build bootroom. 然后选择菜单中的build->build boot rom生成:C:/Tornado/target/config/pcPentium/bootrom_uncmp 或C:/Tornado/target/config/pcPentium/bootrom 3.Build bootable VxWorks image. 3.1 在Tornado中新建bootimage工程,在向导的第二步“base your project on”应选中“A BSP”,并选择相应 的BSP(即在步骤2中做过修改的BSP),建立bootimage工程。 3.2 include VxWorks image中想要的功能。 例如: 修改tornado环境vxWorks页中的Project0 VxWorks->development tool components->symbol table components include: initialize symbol table 可include: target shell components 然后点右键菜单中的'Build VxWorks'生成C:/Tornado/target/proj/Project0/default/vxworks。(假设工程名为Project0) 4.制作启动盘: 将C:/Tornado/target/config/pcPentium/bootrom_uncmp 或C:/Tornado/target/config/pcPentium/bootrom拷贝到C:/Tornado/host/x86-win32/bin 执行Dos命令 c: cd C:/Tornado/host/x86-win32/bin mkboot a: bootrom 若是从软盘起的则应将C:/Tornado/target/proj/Project0/default/vxworks拷贝入A:。 (copy C:/Tornado/target/proj/Project0/default/vxworks a:/) 注:可建立一个批处理文件完成步骤4中的功能: 例如: auto_make.bat ------------------------------ rem *************************************************** rem * 制作VxWorks启动盘的批处理文件 * rem * * rem * 注意对不同的BSP应设置不同的BSP_DIR * rem *************************************************** set WIND_BASE=D:/Tornado set WIND_HOST_TYPE=x86-win32 set BSP_DIR=pc486_2fei copy %WIND_BASE%/target/config/%BSP_DIR%/bootrom %WIND_BASE%/host/%WIND_HOST_TYPE%/bin/ set path=%WIND_BASE%/host/%WIND_HOST_TYPE%/bin;%path% mkboot a: bootrom pause ------------------------------  vxWorks下的多网卡以双网卡为例: 1.1 若是ISA的网卡(以ne2000(ene)为例): BSP如下配置: bsp/config.h: #define IO_ADRS_ENE 0x320 #define INT_LVL_ENE 0x05 #define IO_ADRS_ENE1 0x300 #define INT_LVL_ENE1 0x9 #define INT_VEC_ENE1 (INT_VEC_GET (INT_LVL_ENE1)) bsp/confignet.h: #ifdef INCLUDE_ENE_END {0,END_ENE_LOAD_FUNC,END_ENE_LOAD_STRING,END_ENE_BUFF_LOAN, NULL, FALSE}, {1, END_ENE_LOAD_FUNC,END_ENE_LOAD_STRING, END_ENE_BUFF_LOAN, NULL, FALSE}, #endif /* INCLUDE_ENE_END */ bsp/sysNe2000End.c if (pParamStr[0] == '0') sprintf (cp, ne2000ParamTemplate, IO_ADRS_ENE, INT_VEC_ENE, INT_LVL_ENE, ENE_BYTE_ACCESS, ENE_USE_ENET_PROM, ENE_OFFSET); else if (pParamStr[0] == '1') sprintf (cp, ne2000ParamTemplate, IO_ADRS_ENE1, INT_VEC_ENE1, INT_LVL_ENE1, ENE_BYTE_ACCESS, ENE_USE_ENET_PROM, ENE_OFFSET); printf ("ne2000EndLoad: %s./n", paramStr); if ((pEnd = ne2000EndLoad (paramStr)) == (END_OBJ *)ERROR) { printf ("Error: NE2000 device failed ne2000EndLoad routine./n"); } In the Project Menu, find the object name IP_MAX_UNITS, change it to 2. and build it . 1.2 若是PCI的网卡(以intel82557(FEI)为例) BSP如下配置: bsp/confignet.h: #ifdef INCLUDE_FEI_END { 0, FEI82557_LOAD_FUNC, FEI82557_LOAD_STRING, FEI82557_BUFF_LOAN, NULL, FALSE}, { 1, FEI82557_LOAD_FUNC, FEI82557_LOAD_STRING, FEI82557_BUFF_LOAN, NULL, FALSE}, #endif /* INCLUDE_FEI_END */ 2. 设置第二块网卡的地址: ipAttach 1, "fei" ifMaskSet "fei1", 0xffffff00 ifAddrSet "fei1","xxx.xxx.xxx.xxx" /* substitute your IP */ 注意点: 1).新建bootimage工程向导的第二步“base your project on”应选中“A BSP”,并选择相应 的BSP(即在步骤1中做过修改的BSP) 2).应将bootimage工程中的IP_MAX_UNITS设为相应的值(若是双网卡,则应大于等于2) 3).两块网卡的IP应在不同的子网中。 解决Tornado2.0在Win2000下启动时的问题:方法一: > "Simon DiMaio" wrote in message > news:Pine.SUN.3.95.1000901211732.23944G-100000@salcudean.ece.ubc.ca... > > Hi > > > > I have done a full install of Tornado 2.0 under Windows 2000. Upon running > > Tornado, I receive the following message: > > > > couldn't read file "TRY=localhost/host/resource/tcl/WindView.win32.tcl": > > no such file or directory > > > > Tornado runs fine, but WindView is not available. The base directory for > > my Tornado installation is C:/Tornado, so I don't know where the > > "TRY=localhost" has come from. > > > > Has anybody experienced a similar error message? > > > > Any ideas for a remedy would be greatly appreciated. > > > > Thanks in advance, > > Simon DiMaio Simon, - Go to the Tools menu in Tornado and choose Options, then pick 'Tornado Registry' all the way over at the right. Change the Tornado registry from local machine to remote machine and type in the IP address of your Windows 2000 machine. This should make the error go away. The "localhost" is coming from the WIND_REGISTRY setting. 方法二:安装Tornado for Win2k的Patch。 VxWorks的串口启动If one serial line connects the host and target, and boot target by serial connect. at the config.h end: /* add by frank */ #undef WDB_COMM_TYPE #define WDB_COMM_TYPE WDB_COMM_SERIAL #undef CONSOLE_TTY? #define CONSOLE_TTY 0? #undef WDB_TTY_CHANNEL? #define WDB_TTY_CHANNEL 0 /* should be 1 */ #undef WDB_TTY_BAUD #define WDB_TTY_BAUD 38400 /* default baud rate is 9600*/ #define INCLUDE_TSFS_BOOT /*end by frank */ ----------------------------------------------------------------------------------------------- in the tornado/target/config/all/bootconfig.c, undefine the tsfs_boot_vio_console by : 找到: #ifdef INCLUDE_TSFS_BOOT /* boot via Target Server File System */ #if ((WDB_COMM_TYPE == WDB_COMM_SERIAL) && / (CONSOLE_TTY == NONE || CONSOLE_TTY == WDB_TTY_CHANNEL)) #define INCLUDE_TSFS_BOOT_VIO_CONSOLE /* needed for Target Server Console */ #endif 改为: #ifdef INCLUDE_TSFS_BOOT /* boot via Target Server File System */ #if ((WDB_COMM_TYPE == WDB_COMM_SERIAL) && / (CONSOLE_TTY == NONE || CONSOLE_TTY == WDB_TTY_CHANNEL)) #undef INCLUDE_TSFS_BOOT_VIO_CONSOLE /* needed for Target Server Console */ #endif please note the value of wdb_tty_baud . To avoid some error of networking, could undefine the INCLUDE_END. ----------------------------------------------------------------------------------------------- config.h中的boot line: #define DEFAULT_BOOT_LINE / "tsfs(0,0)hello:vxWorks h=192.168.99.3 e=192.168.99.5 u=target" 当bootrom启动了之后,要在host边开tsfs服务。具体设置如下: 1.选择tool->target server->configure...,在Back End项中,选择wdbserial,选择对应的com口及波特率。 2.在Core File and Symbols项中,File栏指定对应的Vxworks文件。 //在Core File and Symbols项中选File Path From Target 3.在Target Server File System项中,选中Enable File System,Root中选择对应的Vxworks所在目录。 4.根据需要对Console and Redirection项中的重定位进行选择。(不选) 5.最后,点击Launch,启动target server的tsfs.  如何安装RTL8139网卡驱动:方法一: 主要分两步: step1:编译代码并加入静态库。首先将rtl81x9.c(.h)文件放到相应的位置,.c放在 Tornado/target/src/drv/end/下,.h在Tornado/target/h/drv/end/unsupported/下(unsupported目录自己 建立);然后用tornado建立一个downloadable项目,(如果要做80486 BSP,建立项目时选择pc486 BSP), 将.c加入项目,修改该项目编译规则。有两处修改:1)在“rules”项中选择“archive”;2)在“macro” 中选择“archive”项并修改其value,将静态库的路径写入,例如d:/tornado/target/lib/libI80486gnuvx.a 。(注意:参数修改后,要点击“add/set”和“apply”按钮) 最后rebuild all(libI80486gnuvx.a) (或编译成.o文件后用ar386命令将rtl81x9.o加入libI80486gnuvx.a中) step2:将sysRtl81x9End.c复制到Tornado/target/config/pc486/下,并修改该目录下三个文件: config.h,configNet.h,sysLib.c。根据所给的三个文件,查找其中带有rtl的任何宏,然后相应复制到要修改 的文件中。也就是说,参考所给的这三个文件中关于rtl的定义或修改,并相应地修改自己的文件中。 方法二: 不必修改 libI80486gnuvx.a 文件 1.config.h,configNet.h,sysLib.c同样要做修改 2.将编译生成的 rtl81x9.o 文件拷贝到BSP目录下,修改该目录中的MakeFile文件:MACH_EXTRA =? rtl81x9.o ,编译BootRoom 3.将rtl81x9.o 文件拷贝到BootImage的工程目录下(最好不要放在Default目录里,因为重新编译时会被删除 ),修改MakeFile文件: EXTRA_MODULES = ../rtl81x9.o (或者在Tornado环境下的Builds页中双击Default,在Macros页中的 Macros选中EXTRA_MODULES,加入 ../rtl81x9.o,记得要点击“add/set”和“apply”按钮),然后编译BootImage。 VxWorks硬盘启动1。在config.h中将INCLUDE_ATA包括进去;? 2。修改config.h里的? #define DEFAULT_BOOT_LINE "ata=0,0(0,0)host:/ata0/vxWorks "? 3。将目标硬盘格式化,用vxsys.exe(在host/x86_win32/bin/下)做盘;? 4。把bootrom.sys做在软盘上,拷到目标硬盘上;? 5。把你生成的vxworks文件拷到目标硬盘上;重新启动就OK。另:和安装其它操作系统是一样的,记得要把那个分区设为活动分区。 一些网络编程(主要是网络协议的实现)方面的提示:VxWorks下如何实现字节对齐举例如下(这个例子也演示了如何构造报文): #include #include #define BYTE unsigned char /* 1 byte */? #define WORD unsigned short /* 2 bytes */ #define DWORD unsigned long /* 4 bytes */ #define PACKED __attribute__((__packed__))? typedef struct { BYTE foo_field_1; WORD foo_field_2; DWORD foo_field_3; }PACKED foo_msg_t; void print_size() { printf("sizeof foo_msg_t:%d/n",sizeof(foo_msg_t)); } void construct() { foo_msg_t foo_msg; int i; BYTE *pfoo; foo_msg.foo_field_1 = 0x01; foo_msg.foo_field_2 = htons(0x2345); foo_msg.foo_field_3 = htonl(0x6789abcd); pfoo = (BYTE *)&foo_msg; for(i=0;i #include "taskLib.h" #define STATE_NUM 5 #define EVENT_NUM 6 enum state_s { state1, state2, state3, state4, state5 }; enum event_s { event1, event2, event3, event4, event5, event6 }; /* * process function table for state transition: * ----------------------------------------------------------- * event1 event2 event3 event4 event5 event6 * state1 state3 - state4 state2 - - * state2 - state1 state3 - state1 state4 * state3 state5 - - - state2 - * state4 state2 state2 state5 - - - * state5 - - - state4 state3 state2 * ----------------------------------------------------------- * note:"-" means the state has no change. */ int state_trans_table[STATE_NUM][EVENT_NUM]= { {2,0,3,1,0,0}, {1,0,2,1,0,3}, {4,2,2,2,1,2}, {1,1,4,3,3,3}, {4,4,4,3,2,1} }; /* * process function table for state transition: * ----------------------------------------------------------- * event1 event2 event3 event4 event5 event6 * state1 func_3 - func_1 func_4 - - * state2 - func_1 func_2 - func_1 func_4 * state3 func_4 - - - func_1 - * state4 func_3 func_3 func_1 - - - * state5 - - - func_3 unc_2 func_1 * ----------------------------------------------------------- * note:"-" means ignore the event,ie. func_0 */ int state_proc_table[STATE_NUM][EVENT_NUM]= { {3,0,1,4,0,0}, {0,1,2,0,1,4}, {4,0,0,0,1,0}, {3,3,1,0,0,0}, {0,0,0,3,2,1} }; struct parameter_s { char c; void* para; }; int func_0(struct parameter_s); int func_1(struct parameter_s); int func_2(struct parameter_s); int func_3(struct parameter_s); int func_4(struct parameter_s); /* * you can have at most (STATE_NUM * EVENT_NUM) process functions. */ int (*state_process_func[5])(struct parameter_s p)= { func_0, /* 0 */ func_1, /* 1 */ func_2, /* 2 */ func_3, /* 3 */ func_4, /* 4 */ }; int func_0(struct parameter_s p) /* ignore */ { return 0; } int func_1(struct parameter_s p) { logMsg("%c/n",p.c); return 1;? } int func_2(struct parameter_s p) { logMsg("%c/n",p.c); return 1; } int func_3(struct parameter_s p) { logMsg("%c/n",p.c); return 1; } int func_4(struct parameter_s p) { logMsg("%c/n",p.c); return 1; } int index=0; char stdin_input() { char* c; /* read (STD_IN, &c, 1); */? c = "adeacegafdbbsecebxacefbdaeq"; return c[index++]; } void state_machine() { enum state_s state = state1; /* initial state */ enum event_s event; int func_index = 0; char input; struct parameter_s p; while(1) { input = stdin_input(); if(input == 'q') return; switch(input) { case 'a': event = event1; p.c='a'; break; case 'b': event = event2; p.c='b'; break; case 'c': event = event3; p.c='c'; break; case 'd': event = event4; p.c='d'; break; case 'e': event = event5; p.c='e'; break; case 'f': event = event6; p.c='f'; break; default: continue; } func_index = state_proc_table[state][event]; state_process_func[func_index](p); state = state_trans_table[state][event]; } } void ww() { taskSpawn ("ww", 90, VX_FP_TASK, 20000, (FUNCPTR)state_machine, 0,0, 0,0, 0, 0, 0, 0, 0, 0); }带有事件驱动和定时器以及输入接口的“大循环”:举例如下: #include #include /* struct timeval */ #include "selectLib.h" #include "fcntl.h" #include "taskLib.h" #define MAX_DATA 1024 int LOOP_TASK_ID; int fd; struct timeval _timer; struct timeval get_timer() { struct timeval tv; int t,r=sysClkRateGet(); t=tickGet(); tv.tv_usec = t % r; tv.tv_sec = t / r; return tv; } void loop_on_timer() { struct timeval timer = get_timer(); if(timer.tv_sec - _timer.tv_sec >= 5) { logMsg("on timer process(%u).../n",timer.tv_sec); _timer = timer; }? } void loop_process_input(char buffer[MAX_DATA]) { logMsg ("process input : %s/n", buffer); } void loop_main() { struct fd_set /*write_set,*/read_set; struct timeval sleep; char buffer[MAX_DATA]; sleep.tv_sec=5; setbuf(stdin,NULL); if((fd = open ("/pipe/1", O_RDONLY,0))==ERROR) { logMsg("error/n"); return; } FOREVER? { loop_on_timer(); /* timer implement */ FD_ZERO (&read_set); FD_SET(fd,&read_set); if(select(fd+1,&read_set,NULL,NULL,/* NULL*/&sleep) <= 0)continue; if (FD_ISSET (fd, &read_set))? { read (fd, buffer, MAX_DATA); /* this line should not be omitted. */? loop_process_input(buffer); /* input implement */ } } } void aa() { _timer.tv_usec = 0; _timer.tv_sec = 0; pipeDevCreate("/pipe/1", 5, 1024); LOOP_TASK_ID=taskSpawn ("big_loop", 90, VX_FP_TASK, 20000, (FUNCPTR)loop_main,0,0, 0,0, 0, 0, 0, 0, 0, 0); } void bb() { taskDelete(LOOP_TASK_ID); } void cc() { char buf[]="hello"; write(fd,buf,sizeof(buf)); }几个常用的函数:/************************************************************************ * ntohl Convert a long from network to host byte ordering. (#include )? * byte 1234->4321 eg:0x12345678 -> 0x78563412 ~~~~~~~~~~~~~~ htons The Windows Sockets htons function converts a u_short from host to TCP/IP network byte order (which is big-endian). u_short htons ( u_short hostshort? ); ~~~~~~~~~~~~~~~~~~~~ htonl The Windows Sockets htonl function converts a u_long from host to TCP/IP network byte order (which is big-endian). u_long htonl ( u_long hostlong? ); ~~~~~~~~~~~~~~~ ntohl The Windows Sockets ntohl function converts a u_long from TCP/IP network order to host byte order (which is big-endian). u_long ntohl ( u_long netlong? ); ~~~~~~~~~~~~~~~~~~~ ntohs The Windows Sockets ntohs function converts a u_short from TCP/IP network byte order to host byte order (which is big-endian). u_short ntohs ( u_short netshort? ); *----------------------------------------------------------------------- * inet_addr? * function converts a string containing an (Ipv4) Internet Protocol dotted address into a proper address for the * IN_ADDR structure. * eg:inet_addr("192.168.1.3"); (=0x0301a8c0) *-----------------------------------------------------------------------? * inet_ntoa * converts an (Ipv4) Internet network address into a string in Internet standard dotted format. *----------------------------------------------------------------------- ((struct sockaddr_in*)addr)->sin_port = htons(dest->port); ((struct sockaddr_in*)addr)->sin_addr.s_addr = htonl(dest->addr.u.ipv4); */几个链接:奥索BBS论坛嵌入开发技术论-坛精彩下载嵌入开发网 VxWorks and Tornado II FAQ论坛内容VxWorks FAQ Indexcomp.os.vxworks Frequently Asked Questions (FAQ) [LONG] http--www-csg.lbl.gov-vxworks-vxwexplo-archive0009 VxWorks Exploder Google Search comp.os.vxworks 嵌入实时操作系统之Tornado-VxWorksIPSec - RouterWare Product Line 奥索汉泰WindSurfReal-Time Research Repository Papers 电子产品世界电子设计世界--bbsArbeitskreis Teleservice Teleservice Links Reliable RTOS Technology, QNX Software Systems Embedded Systems Programming - Embedded.com 程序示例嵌入式软件开发论坛 程序员的个人主页 Tornado 2.0 Online ManualsReal-Time Experiments Table of Contents 微码科技Micrium, Home of uC-OS RTOS and uC-GUI Embedded GUI麦克泰技术http--www.virtualinformation.com-drivers-EthernetSupport.htmpso
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值