VxWorks入门(一):VxWorks Vs Linux

来源:互联网 发布:收费炒股软件知乎 编辑:程序博客网 时间:2024/05/18 16:40

1, VxWorks的特点:

幻灯片 4.O{font-size:149%;}<!--.sld{left:0px !important;width:6.0in !important;height:4.5in !important;font-size:103% !important;}-->

All functions exist in the same "space".
Name clashes may appear between different modules (libraries).
Use unique names (with prefix) for global functions!
Wrong: config, test, read_bi
Right: drvXyConfig, fooTest, devAbc_read_bi
Or make functions static.
vxWorks has no main function.
Every function (including the shell) can call any other function.
You don’t start programs from the shell, you call functions.
When name clash happens, you might call the wrong function.

幻灯片 5.O{font-size:149%;}<!--.sld{left:0px !important;width:6.0in !important;height:4.5in !important;font-size:103% !important;}-->

Ending a thread does not clean up system resources.

2, VxWorks中不同模块下相同名字的全局变量仍占用同一块内存;

static可让变量仅在一个源文件中生效;

可能的内存问题:

幻灯片 6.O{font-size:149%;}<!--.sld{left:0px !important;width:6.0in !important;height:4.5in !important;font-size:103% !important;}-->

Pro: Functions and threads can easily
exchange large amounts of data by reference (pointers).
access any hardware register (e.g. VME bus).
Con: Functions and threads can easily
overrun allocated memory or stack size (esp. with arrays)
overwrite system tables. (e.g. interrupt handler table at NULL)
overwrite program code.
modify global variables of other modules (e.g. drivers).


3, 入门指导:

幻灯片 9.O{font-size:149%;}<!--.sld{left:0px !important;width:6.0in !important;height:4.5in !important;font-size:103% !important;}-->

Online help: http://vxworks.web.psi.ch
Important for beginners:
VxWorks Programmer's Guide, Chapter 2
All about tasks, semaphores, watchdog timers, interrupts
Always helpful:
vxWorks Reference Manual
All vxWorks system functions
Run-time help: Type help on the vxWorks shell.

4,VxWorks shell使用注意:
1)最多只能传10个参数;
2)PPC结构中float和double无效;
3)可以直接使用shell创建全局变量;
5,写程序应注意以下错误处理:
Error checking is the key to a stable system.
Stability is limited by the weakest point!
Check arguments to API functions (esp. shell functions)
Never trust a user! Not even yourself.
Always check pointer arguments for validity.
Writing to NULL overwrites the interrupt handler table!
Check results of system functions (malloc, fopen, )
System functions may fail and return NULL or ERROR.
Using these values unchecked may crash the system much later.
Check for "impossible" values (e.g. in case constructs
幻灯片 17.O{font-size:149%;}<!--.sld{left:0px !important;width:6.0in !important;height:4.5in !important;font-size:103% !important;}-->

原创粉丝点击