Chinaunix首页 | 论坛 | 博客
  • 博客访问: 322666
  • 博文数量: 85
  • 博客积分: 3433
  • 博客等级: 中校
  • 技术积分: 844
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-29 01:11
文章分类

全部博文(85)

文章存档

2013年(1)

2012年(12)

2011年(13)

2010年(59)

我的朋友

分类: LINUX

2010-10-31 17:05:36

Vxworks 是美国风河公司推出的针对时实比较高的操作系统,主要应用于实时性高的航空,航天,通讯等领域。笔者也是很早就听说过该系统,一直没有机会系统的学习和了解其中的精髓。最近得到朋友的帮助终于把平台搭建好了,终于可以好好的学习学习了:

 

1、Multitasking (多任务)

 

       A task's context includes:

  • a thread of execution; that is, the task's program counter
  • the CPU registers and (optionally) floating-point registers
  • a stack for dynamic variables and function calls
  • I/O assignments for standard input, output, and error
  • a delay timer
  • a time-slice timer
  • kernel control structures signal handlers
  • debugging and performance monitoring val

 

        Task Scheduler Control Routines

              Wind Task Scheduling (任务调度)


Call
Description

kernelTimeSlice( )
Controls round-robin scheduling.
taskPrioritySet( )
Changes the priority of a task.
taskLock( )
intLock( )
Disables task rescheduling.
mutual exclusion task rescheduling
taskUnlock( )
Enables task rescheduling.

     在实在的调度算法的时候,大家都知道是按任务的优先级调度,如果有许多任务的优先级相同,那么Vxworks是怎么调度的呢?通过学习知道是利用Round-Robin Scheduling  (循环调度)算法,也就是每个任务拥有相同的时间片来利用系统资源,当在处理相同优先级任务的时候,如果有高优先级的任务需要处理,系统将停止正在处理的任务而切换到高优先级的任务处理。

 

 2、 Task Creation and Activation (任务的创建和激活)

       Vxworks 创建任务和激活任务是通过以下系统接口函数:

 

         Task Creation Routines


Call
Description

taskSpawn( )
Spawns (creates and activates) a new task.
taskInit( )
Initializes a new task.
taskActivate( )
Activates an initialized task.

     Vxworks 创建一个任务和Linux下创建一个进程有点类似,

id taskSpawn (namepriorityoptionsstacksizemainarg1arg10 );

tid = taskSpawn ("tMyTask", 90, VX_FP_TASK, 20000, myFunc, 2387, 0, 0, 0, 0, 0, 0, 0, 0, 0);

 

     只不过在Linux 下创建一个进程是不需要用户为其分配空间,系统会自动为其分配空间,而Vxworks需要为创建的任务分派相应的堆栈空间来运行这个任务,一般很难很准确的为任务分派大小合适的空间,不过我们可以周期性的检测我们分派的堆栈空间是否有过大过小的问题来动态调整其空间大小。

一般使用: checkStack() 来监控我们分派的空间。

 

 3、Task Names and IDs (任务名字和ID)
 

 Task Name and ID Routines


Call
Description

taskName( )
Gets the task name associated with a task ID.
taskNameToId( )
Looks up the task ID associated with a task name.
taskIdSelf( )
Gets the calling task's ID.
taskIdVerify( )
Verifies the existence of a specified task.

从创建任务函数接口你可以知道,中间含有很多参数,其中很多从参数的字面含义你也许就会该传入什么参数,但是 Options 参数是什么呢 ?
 4、Task Options
 
   Task Options

Name
Hex Value
Description

VX_FP_TASK
0x0008
Executes with the floating-point coprocessor.
VX_NO_STACK_FILL
0x0100
Does not fill the stack with 0xee.
VX_PRIVATE_ENV
0x0080
Executes a task with a private environment.
VX_UNBREAKABLE
0x0002
Disables breakpoints for the task.
VX_DSP_TASK
0x0200
1 = DSP coprocessor support.
VX_ALTIVEC_TASK
0x0400
1 = ALTIVEC coprocessor support.

You must include the VX_FP_TASK option when creating a task that:
 
 从这个表可以看出,这些Options 参数其实Vxworks预先定义好的一组宏,你可以选择其中一个也可以用 “ | ” 操作选取多个。但是其中:VX_FP_TASK 是必须的。这些参数也可以动态的修改,利用依以下程序:
 
  

 Task Option Routines

Call
Description

taskOptionsGet( )
Examines task options.
taskOptionsSet( )
Sets task options.

5、Task Information (任务的相关信息)

   Task Information Routines


     Call
     Description

taskIdListGet( )
Fills an array with the IDs of all active tasks.
taskInfoGet( )
Gets information about a task.
taskPriority( )
Examines the priority of a task.
taskRegsGet( )
Examines a task's registers (cannot be used with the current task).
taskRegsSet( )
Sets a task's registers (cannot be used with the current task).
taskIsSuspend )  
Checks whether a task is suspended.
taskIsReady( )
Checks whether a task is ready to run.
taskTcb( )
Gets a pointer to a task's control block.
 

6、Task Deletion and Deletion Safety (任务的删除)  

   在Vxworks系统中我们可以动态的删除一个任务,当然系统也提供一些保护措施以防止意外删除造成不可预知的结果。

  Task-Deletion Routines


Call
Description

exit( )   
Terminates the calling task and frees memory
(task stacks and task control blocks only).1
taskDel( )   
Terminates a specified task and frees memory
(task stacks and task control blocks only).*
taskSafe( )
Protects the calling task from deletion.
taskUnsaf( )
Undoes a taskSafe( ) (makes the calling task available for deletion).

 

 


 

NOTE:        You can use VxWorks events to send an event when a task finishes executing. For more information, see
 
7、 Task Control (任务控制)

   Task Control Routines


Call
Description
taskSuspend( )
Suspends a task.
taskResume( )
Resumes a task.
taskRestart( )
Restarts a task.
taskDelay( )
Delays a task; delay units are ticks, resolution in ticks.
nanosleep( )
Delays a task; delay units are nanoseconds, resolution in ticks.

阅读(2552) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-10-31 19:07:41

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com