﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-依睛(IT blog) 我回来了，PHP&lt;--&gt;C/C++ LINUX-随笔分类-VXworks资料</title><link>http://www.cnitblog.com/guopingleee/category/5744.html</link><description>笨鸟
</description><language>zh-cn</language><lastBuildDate>Mon, 03 Oct 2011 11:24:50 GMT</lastBuildDate><pubDate>Mon, 03 Oct 2011 11:24:50 GMT</pubDate><ttl>60</ttl><item><title>VxWorks 操作系统学习笔记</title><link>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30203.html</link><dc:creator>向左向右走</dc:creator><author>向左向右走</author><pubDate>Wed, 18 Jul 2007 12:40:00 GMT</pubDate><guid>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30203.html</guid><wfw:comment>http://www.cnitblog.com/guopingleee/comments/30203.html</wfw:comment><comments>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30203.html#Feedback</comments><slash:comments>20</slash:comments><wfw:commentRss>http://www.cnitblog.com/guopingleee/comments/commentRss/30203.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/guopingleee/services/trackbacks/30203.html</trackback:ping><description><![CDATA[
		<div>
				<br />
				<table cellspacing="0" cellpadding="0" width="92%" align="center" border="0">
						<tbody>
								<tr>
										<td>
												<table cellspacing="0" cellpadding="0" width="100%" border="0">
														<tbody>
																<tr>
																		<td>
																				<table class="seyle4" cellspacing="0" cellpadding="0" width="100%" border="0">
																						<tbody>
																								<tr>
																										<td> </td>
																								</tr>
																								<tr>
																										<td class="content9" valign="center">
																												<strong>VxWorks 操作系统学习笔记</strong>
																										</td>
																								</tr>
																								<tr>
																										<td>
																												<div align="right"> </div>
																										</td>
																								</tr>
																						</tbody>
																				</table>
																				<table cellspacing="0" cellpadding="0" width="100%" border="0">
																						<tbody>
																								<tr>
																										<td height="3"> </td>
																								</tr>
																						</tbody>
																				</table>
																				<table style="TABLE-LAYOUT: fixed" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
																						<tbody>
																								<tr>
																										<td>
																												<span class="oblog_text">
																														<div class="content" id="fontzoom">
																																<p>
																																</p>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">1.<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">       </span>任务</span>VxWorks</div>
																																<div>任务：在执行时每个程序都被称之为任务。VxWorks操作系统中，任务可以直接地或者以共享方式访问大多数系统资源，为了维护各自的线程，每个任务必须保持有足够的上下文环境。</div>
																																<div> </div>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(1)<span style="FONT: 12pt 'Times New Roman'">    </span>任务状态：</div>
																																<div>就绪（READY）：该状态时任务仅等待CPU的状态，不等待其他任何资源。</div>
																																<div>阻塞（PEND）：任务由于一些资源不可用而被阻塞时的状态。</div>
																																<div>睡眠（DELAY）：出于睡眠的任务状态。</div>
																																<div>挂起（SUSPEND）：该状态时任务不执行，主要用于调试用。挂起仅仅约束任务的执行，并不约束状态的转换，因此pended-suspended状态时任务可以解锁，delayed-suspended状态时任务可以唤醒。</div>
																																<div>DELAY+S：既处于睡眠又处于挂起的任务状态。</div>
																																<div>PEND+S：既处于阻塞又处于挂起的任务状态。</div>
																																<div>PEND+T：带有超时值处于阻塞的任务状态。</div>
																																<div>PEND+S+T：带有超时值处于阻塞，同时又处于挂起的任务状态。</div>
																																<div>state+I：任务处于state且带有一个继承优先级。</div>
																																<div>----------------------------------------------------------------------------------------</div>
																																<div>|      ready | ——&gt; | pended      | semTake () / msgQReceive () |</div>
																																<div>|      ready | ——&gt; | delayed      | taskDelay ()               |</div>
																																<div>|      ready | ——&gt; | suspended    | taskSuspend ()             |</div>
																																<div>|     pended | ——&gt; | ready       | semGive () / msgQSend ()    |</div>
																																<div>|     pended | ——&gt; | suspended   | taskSuspend ()             |</div>
																																<div>|    delayed | ——&gt; | ready        | expired delay              |</div>
																																<div>|    delayed | ——&gt; | suspended    | taskSuspend ()             |</div>
																																<div>| suspended | ——&gt; | ready       | taskResume () / taskActivate () |</div>
																																<div>| suspended | ——&gt; | pended      | taskResume ()             |</div>
																																<div>| suspended | ——&gt; | delayed     | taskResume()              |</div>
																																<div>---------------------------------------------------------------------------------------</div>
																																<div> </div>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(2)<span style="FONT: 7pt 'Times New Roman'">    </span>Wind任务调度</div>
																																<div>在Wind内核中，默认算法是基于优先级的抢占式调度算法，也可以使用轮转调度算法。</div>
																																<div>任务调度控制函数：</div>
																																<div>----------------------------------------------------------------------------------------</div>
																																<div>|          调用           |            描述                |</div>
																																<div>|      kernelTimeSlice()    |        控制轮转调度            |</div>
																																<div>|      taskPrioritySet()      |       改变任务优先级           |</div>
																																<div>|      taskLock()          |        禁止任务调度            |</div>
																																<div>|      taskUnlock()        |        允许任务调度            |</div>
																																<div>----------------------------------------------------------------------------------------</div>
																																<div> </div>
																																<div>基于优先级的抢占式任务调度：</div>
																																<div>当一个新任务优先级高于系统当前执行任务的优先级时，它将抢占CPU执行。因此，系统内核将确保CPU分配给处于就绪状态的具有最高优先级的任务执行。</div>
																																<div>缺点：当多个相同优先级的任务需要共享一台处理器时，如果某个执行的任务永不阻塞，那么它将一直独占处理器，其他相同优先级的任务就没有机会执行。</div>
																																<div> </div>
																																<div>轮转式调度：</div>
																																<div>当所有相同优先级的任务处于就绪状态时，轮转算法倾向于平均使用CPU，对于所有相同优先级的任务，通过时间片获得相同的CPU处理时间。</div>
																																<div> </div>
																																<div>抢占上锁：</div>
																																<div>通过调用taskLock()和taskUnlock()函数，可以禁止使用Wind内核调度程序或启用Wind内核调度程序。当禁止使用调度程序时，若该任务正在执行，不会发生基于优先级的抢占。</div>
																																<div>抢占上锁只能阻止任务的上下文切换，并不禁止中断。</div>
																																<div> </div>
																																<div>taskLock()和intLock()比较</div>
																																<div> </div>
																																<div>任务优先级：所有应用任务的优先级应该在100-250之间；但是驱动程序支持的任务（与中断服务程序关联的任务）优先级能够位于51-99。</div>
																																<div> </div>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(3)<span style="FONT: 12pt 'Times New Roman'">    </span>任务异常处理：</div>
																																<div> </div>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(4)<span style="FONT: 12pt 'Times New Roman'">    </span>共享代码和重入</div>
																																<div>VxWorks操作系统中，大多数函数是可重入的。但若存在一个对应于命名为someName_r()的函数，someName() 因作为函数重入的版本将认为是不可重入的。例如，ldiv() 有一个对应函数ldiv_r()，则ldiv() 是不可重入的。</div>
																																<div> </div>
																																<div>重入技术：</div>
																																<div>. 动态堆栈变量</div>
																																<div>. 被信号保护的全局和静态变量</div>
																																<div>. 任务变量：taskVarAdd(), taskVarDelete()和taskVarGet()</div>
																																<div> </div>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(5)<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">    </span>操作系统任务</span>VxWorks</div>
																																<div>. tUserRoot：内核执行的首个任务，入口点是安装目录/target/config/all/usrConfig.c下函数usrRoot()，可初始化VxWorks操作系统的大部分程序，发起诸如日志任务、异常处理任务、网络任务和tRlogind后台程序。正常情况下根任务在所有初始化结束后，终止任务并且被删除。</div>
																																<div>. tLogTask：日志任务</div>
																																<div>. tExcTask：异常处理任务，必须拥有系统的最高优先级。</div>
																																<div>. tNetTask：网络任务，用于VxWorks网络任务级程序处理。通常配置INCLUDE_NET_LIB组件的VxWorks操作系统可以发起网络任务。</div>
																																<div>. tWdbTask：目标代理任务，用INCLUDE_WDB组件配置的VxWorks操作系统包括目标代理功能。</div>
																																<div>. 可选组建的任务</div>
																																<div>. tShell</div>
																																<div>. tRlogind</div>
																																<div>. tTelnetd</div>
																																<div>. tPortmapd</div>
																																<div> </div>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">2.<span style="FONT: 12pt 'Times New Roman'">       </span>任务间通信</div>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(1)<span style="FONT: 12pt 'Times New Roman'">    </span>共享内存，数据的简单共享</div>
																																<div>在VxWorks操作系统中所有任务存在于一个单独的线性地址空间中，所以任务间共享数据结构是很容易实现的。全局变量、线性缓冲、环形缓冲、连接链和指针都可以被运行在不同上下文中的代码直接引用。</div>
																																<div> </div>
																																<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(2)<span style="FONT: 12pt 'Times New Roman'">    </span>信号量，基本的互斥和同步</div>
																																<div>. 实现资源互斥访问的方法包括：</div>
																																<div style="TEXT-INDENT: 31.5pt">中断上锁（中断上锁时不要调用VxWorks操作系统函数，强行使用会导致意外的中断）：intLock() 和intUnlock()</div>
																																<div style="TEXT-INDENT: 31.5pt">抢占上锁：taskLock() 和taskUnlock()</div>
																																<div style="TEXT-INDENT: 31.5pt">信号量对资源的上锁</div>
																																<div style="TEXT-INDENT: 31.5pt"> </div>
																																<div>. VxWorks操作系统中的信号量类型</div>
																																<div>      二进制，最快最通用的信号量，适用于同步和互斥。</div>
																																<div style="TEXT-INDENT: 31.5pt">互斥，为解决内在互斥问题、优先级继承、删除安全以及递归问题等而最优化的一种特殊二进制信号量。</div>
																																<div style="TEXT-INDENT: 31.5pt">计数，类似于二进制信号量，但其跟踪信号量被释放的次数，适用于单个资源多个实例需要保护的情况。</div>
																																<div style="TEXT-INDENT: 31.5pt"> </div>
																																<div>. 队列类型：</div>
																																<div>      SEM_Q_PRIORITY：根据优先级顺序</div>
																																<div>      SEM_Q_FIFO：根据先进先出顺序</div>
																																<div> </div>
																																<div>. 二进制信号量</div>
																														</div>
																												</span>
																										</td>
																								</tr>
																						</tbody>
																				</table>
																		</td>
																</tr>
														</tbody>
												</table>
										</td>
								</tr>
						</tbody>
				</table>
				<br />
				<br />
				<br />
				<br />. 互斥信号量</div>
		<div>      基本行为与二进制信号量一致，不同之处如下：</div>
		<div>      仅用于互斥；</div>
		<div>      仅能由提取它（即调用semTake()）的任务释放；</div>
		<div>      不能在中断服务程序中释放；</div>
		<div>      semFlush()函数操作非法；</div>
		<div>      .. 优先级倒置：互斥信号量选项SEM_INVERSION_SAF能够继承优先级算法，优先级继承协议确保在资源阻塞的所有任务中优先级最高的且拥有资源执行资格的任务将优先执行。一旦任务的优先级被提高，它以提高后的优先级执行；直到释放其占有的全部互斥信号量后，该任务将返回到正常或者标准的优先级。该选项要求与优先级队列（SEM_Q_PRIORITY）一起使用。</div>
		<div>      .. 删除安全：一个受信号量保护的临界区域内经常需要保护执行任务避免被意外地删除。删除一个在临界区执行的任务可能会导致意想不到的后果。原语semSafe()和semUnsafe()提供了一种任务安全的方法。但是在使用互斥信号量选项SEM_DELETE_SAFE时，每次使用semTake()将隐含调用taskSafe()，使用semGive()将隐含调用taskUnsafe()。使用这种方式，任务在占用信号量时不会被删除。</div>
		<div>      .. 递归资源访问：互斥信号量能够递归获得。在释放信号量前，递归获取的互斥信号量被释放和提取的次数应该相等，这通过一个计数器跟踪实现。</div>
		<div> </div>
		<div>. 计数器信号量</div>
		<div>      是实现任务同步和互斥的另一种手段，适用于保护多份复制的资源。</div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(3)<span style="FONT: 12pt 'Times New Roman'">    </span>消息队列</div>
		<div>在VxWorks操作系统里，单个CPU里任务间的主要通信方式使用消息队列。</div>
		<div>------------------------------------------------------------------------------------</div>
		<div>|      调用         |           描述                    |</div>
		<div>| msgQCreate()      | 分配并初始化一个消息队列         |</div>
		<div>| msgQDelete()      | 终止并释放一个消息队列           |</div>
		<div>| msgQSend()       | 向一个消息队列发送消息           |</div>
		<div>| msgQReceive()    |   从一个消息队列接收消息           |</div>
		<div>------------------------------------------------------------------------------------</div>
		<div>消息的优先级：MSG_PRI_NORMAL和MSG_PRI_URGENT</div>
		<div>中断服务程序能够向消息管道中写入，但不能从消息管道中读取。</div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(4)<span style="FONT: 12pt 'Times New Roman'">    </span>管道</div>
		<div>管道使用VxWorks操作系统中的I/O系统，并提供替换消息队列的接口。管道是由驱动程序pipeDrv管理的虚拟I/O设备，任务能够使用标准I/O 对管道进行打开、读取或写入等操作，另外也可以调用函数ioctl。</div>
		<div>与消息管道类似，中断服务程序能够向管道写入，但不能从管道读取。</div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(5)<span style="FONT: 12pt 'Times New Roman'">    </span>任务间网络通信</div>
		<div>套接字Sockets</div>
		<div> </div>
		<div>远程程序调用RPC</div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(6)<span style="FONT: 12pt 'Times New Roman'">    </span>信号</div>
		<div>VxWorks支持软件信号功能。信号可以异步改变任务的控制流程。任何任务或中断服务程序可以向指定任务发送信号。接收到信号的任务立即挂起当前的执行线程，在下次调度执行时转而执行指定的信号处理程序。信号处理程序在接收任务的上下文中执行，并使用任务的堆栈。即使在任务被阻塞时，仍可调用信号处理程序。</div>
		<div>通常信号处理程序可作为中断处理程序看待，任何导致调用程序阻塞的函数均不能在信号处理程序中调用。</div>
		<div>Wind内核支持两种类型的信号接口：UNIX BSD风格的信号和POSIX兼容信号。为了简化设计，建议在一个应用程序中使用一种类型接口，不要混合使用不同接口。</div>
		<div> </div>
		<div>基本信号函数：</div>
		<div>----------------------------------------------------------------------------------------------------------</div>
		<div>| POSIX 1003.1b兼容调用|UNIX BSD兼容调用|     描述                     |</div>
		<div>|    signal()            |      signal()     | 指定信号的处理程序           |</div>
		<div>|    kill()              |       kill()      | 向任务发送信号               |</div>
		<div>|    raise()             |       N/A       | 向自身发送信号               |</div>
		<div>|    sigaction()         |     sigvec()     | 检查或设置信号的处理程序     |</div>
		<div>|    sigsuspend()        |       pause()    | 挂起任务直至任务提交         |</div>
		<div>|    sigpending()        |       N/A     | 恢复一组用于传递而被阻塞的信号|</div>
		<div>|    sigemptyset() ------- | ------------------------ | ---------------------------------------------|     </div>
		<div>|    sigfillset()   ------- |                 |                              |</div>
		<div>|    sigaddset() -------- |     sigsetmask() | 设置信号屏蔽                 |</div>
		<div>|    sigdelset() --------   |                |                              |</div>
		<div>|   sigismember() -------  |--------------------- ---|---------------------------------------------|</div>
		<div>|    sigprocmask()      |     sigsetmask() | 设置阻塞信号的屏蔽           |</div>
		<div>|    sigprocmask()      |     sigblock()    | 增加到一组阻塞的信号中       |</div>
		<div>----------------------------------------------------------------------------------------------------------</div>
		<div>信号发生通常与硬件中断相联系。例如总线出错、非法指令以及浮点数异常都可能产生某种信号。</div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">3.<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">       </span>事件</span>VxWorks</div>
		<div>VxWorks事件是一种在任务和中断处理程序间，或任务和VxWorks结构体间的通信方式。在VxWorks事件上下文中，这些结构体被用作为资源，包括信号量和消息队列。只有任务能够接收事件；然而任务、中断处理程序或资源都可以发送事件。</div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(1)<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">    </span>事件</span>pSOS</div>
		<div>. 发送和接收事件</div>
		<div>任务、中断服务程序以及资源都使用同一个应用编程接口ev_send()来发送事件。</div>
		<div>对于从资源接收事件的任务来说，任务必须用资源寄存，而且请求资源在空闲时发送一系列指定的事件；这种资源可以使信号量，也可以是消息队列。</div>
		<div> </div>
		<div>. 等待事件</div>
		<div>任务能够从一个或多个资源等待多个事件。每个资源可以发送多个事件，同样任务也可以等待接收一个或多个事件。</div>
		<div> </div>
		<div>. 事件的寄存</div>
		<div>从资源接收事件时，资源只能寄存一个任务。如果另一个任务随后用同样的资源寄存，那么不会通知原先寄存的任务就自动解除原有的寄存。VxWorks事件寄存的处理与pPOS事件则不同。</div>
		<div> </div>
		<div>. 空闲资源</div>
		<div>当资源给任务发送事件表明空闲时，不意味着资源的空闲状态可以保留。因此，从资源等待事件的任务在资源空闲时被解除阻塞；但同时资源也可能被取走。</div>
		<div>对于两个或两个以上的任务持续交换资源所有权的情况，资源虽然被释放，但并不处于空闲状态，所以资源将不会发送事件。</div>
		<div> </div>
		<div>. 应用编程接口</div>
		<div>------------------------------------------------------------------------------------------------</div>
		<div>| 函数      |                     描述                        |</div>
		<div>| ev_send()     | 给任务发送事件                                  |</div>
		<div>| ev_receive()   | 等待事件                                        |</div>
		<div>| sm_notify()   | 寄存一个被信号量告知可用的任务                   |</div>
		<div>| q_notify()     | 寄存一个被消息队列告知有消息到来的任务          |</div>
		<div>| q_vnoify     | 寄存一个被可变长度的消息队列告知有消息到来的任务 |</div>
		<div>------------------------------------------------------------------------------------------------</div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(2)<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">    </span>事件</span>VxWorks</div>
		<div>VxWorks事件执行以pPOS事件为基石。</div>
		<div> </div>
		<div>. 空闲资源定义</div>
		<div>     互斥信号量：当一个互斥信号量被释放并且在其上没有任务阻塞</div>
		<div>     二进制信号量：当没有任务占有或等待一个二进制信号量</div>
		<div>     计数器信号量：一个计数器信号量在其计数值非零且其上没有阻塞任务时</div>
		<div>     消息队列：队列中有消息存在，且没有等待该队列中消息而阻塞的任务</div>
		<div> </div>
		<div>. VxWorks对pPOS事件的扩展</div>
		<div>     单任务资源寄存：在pPOS系统中一个任务用资源寄存发送pSOS事件时，它会无意地取消另一个已用该资源寄存的任务寄存，第一个用该资源寄存的任务将无限期地被阻止。VxWorks事件则提供了一个选项，在该选项中如果另一个任务已经用某个资源寄存了，则不允许第二个任务用该资源再寄存。如果第二个任务用该资源寄存，将返回一个错误。</div>
		<div>     立即发送选项：当一个pPOS任务用资源寄存时，即使寄存时资源处于空闲状态，也不会立即给任务发送时间。对于VxWorks事件，默认行为与之相同。然而，VxWorks事件提供了一个选项，即若该资源在寄存时处于空闲状态，该选项允许任务请求资源立即给其发送事件。</div>
		<div>     自动取消寄存选项：pPOS执行过程序要任务在从资源接收任务后明确地取消寄存。VxWorks执行提供一个选项，该选项可以通知资源仅发送一次事件，然后在发送后自动取消寄存。</div>
		<div>     自动解除资源堵塞：当删除资源（一个信号量或者消息队列时），调用函数semDelete()和msgQDelete()解除所有任务的挂起。在任务等待被删除资源发送事件时，该措施保护任务避免无限期地堵塞。然后任务继续执行，导致任务挂起的函数eventReceive()返回一个ERROR值。</div>
		<div> </div>
		<div>事件25到32（VXEV25或0x01000000到VXEV32或0x80000000）用作系统保留用，VxWorks用户不可以使用这些事件。</div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">(3)<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">    </span>比较</span>API</div>
		<div>------------------------------------------------------------------------------------------------------------------</div>
		<div>| VxWorks函数 | pPOS函数 |            注释                             |</div>
		<div>|   eventSend    |   ev_send    | 直接端口                                   |</div>
		<div>|   eventReceive | ev_receive   | 直接端口                                    |</div>
		<div>|   eventClear    |             | VxWorks中的新功能                         |</div>
		<div>|   semEvStart    | sm_notify   | SemEvStart等价于用非零事件参数调用sm_notify |</div>
		<div>|   semEvStop    | sm_notify   | SemEvStop等价于用事件参数为0调用sm_notify |</div>
		<div>|   msgQEvStart | q_vnotify   | msgQEvStart等价于用非零事件参数调用q_notify |</div>
		<div>|   msgQEvStop | q_vnotify   | msgQEvStop等价于用事件参数为0调用q_notify |</div>
		<div>|                | q_notify    | VxWorks没有一个固定长度的消息队列机制     |</div>
		<div>------------------------------------------------------------------------------------------------------------------</div>
		<div> </div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">4.<span style="FONT: 12pt 'Times New Roman'">       </span>看门狗定时器</div>
		<div>VxWorks包括一个看门狗定时器机制，允许任何C函数与一个特定的时间延时器联系。看门狗定时器作为系统时钟中断服务程序的一部分来维护。被看门狗定时器调用的函数通常作为系统时钟中断级的中断服务代码来执行。但如果内核由于某种原因不能立即执行能够函数（例如一个优先中断或者内核状态），函数将放在tExcTask工作队列中。tExcTask工作队列中的函数以tExcTask（通常是0）优先级来执行。</div>
		<div>-------------------------------------------------------------------------------------------</div>
		<div>|    调用    |                 描述                          |</div>
		<div>| wdCreate() | 分配并初始化一个看门狗定时器                  |</div>
		<div>| wdDelete() | 终止并释放一个看门狗定时器                    |</div>
		<div>| wdStart() | 启动一个看门狗定时器                          |</div>
		<div>| wdCancel() | 取消当前的一个计数的看门狗定时器             |</div>
		<div>-------------------------------------------------------------------------------------------</div>
		<div> </div>
		<div> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">5.<span style="FONT: 12pt 'Times New Roman'">       </span>中断服务代码</div>
		<div>为了尽快地响应中断，VxWorks中断处理程序在所有任务上下文之外的一个特殊上下文内执行。因此，中断处理不涉及到任务上下文的切换。</div>
		<div>--------------------------------------------------------------------------------------------</div>
		<div>|    调用        |                 描述                       |</div>
		<div>| intConnect()    |    设置中断处理的C程序                   |</div>
		<div>| intContext()    |    如果是从中断级调用，返回真              |</div>
		<div>| intCount()      |    获得当前中断嵌套深度                   |</div>
		<div>| intLevelSet()   |    设置处理器的中断屏蔽级                  |</div>
		<div>| intLock()      |    禁止中断                                |</div>
		<div>| intUnlock()     |    重新允许中断                           |</div>
		<div>| intVecBaseSet() |   设置向量基地址                          |</div>
		<div>| intVecBaseGet() |   得到向量基地址                         |</div>
		<div>| intVecSet()      |   设置异常向量                           |</div>
		<div>| intVecGet()      |   获得异常向量                           |</div>
		<div>--------------------------------------------------------------------------------------------</div>
		<div> </div>
		<div>调用中断服务程序函数存在着很多的限制。例如，在应用中断服务程序时不能使用printf(), malloc()和semTake()函数，但是可以使用semGive(), logMsg(), msgQSend()和bcopy()这样的函数。</div>
		<div>产生这些限制的原因是由于中断服务程序不在一个固定的任务上下文中执行，而且没有任务控制块，因此所有中断服务程序必须共享一个单独的堆栈。</div>
		<div> </div>
		<div>. 中断服务程序基本限制为禁止调用导致调用者堵塞的函数。</div>
		<div>. malloc()和free()都要求获得信号量，中断服务程序不能调用任何用于创建或删除的函数。</div>
		<div>. 中断服务程序不能通过VxWorks驱动程序来执行I/O操作，因为大多数的设备驱动器可能会堵塞等待设备的调用者，因此它们需要一个任务上下文。但VxWorks管道驱动器是个例外，它设计用于中断服务程序的写操作。</div>
		<div>. VxWorks提供了一个记录功能，允许向系统任务平台打印文本信息。这个机制是专门为中断服务程序使用而设计的，同时它也是从中断服务程序打印信息的最常用方法。</div>
		<div>. 中断服务程序同时禁止调用浮点协处理器函数。在VxWorks操作系统中，由intConnect()函数建立的中断驱动代码不能保存和恢复浮点寄存器。若中断服务程序需要使用浮点指令，则必须明确地保存和恢复fppArchLib中函数浮点协处理器的寄存器。</div>
		<div>. 所有VxWorks函数库，像连接链和环形缓冲器，都可以被中断服务程序使用。</div>
<img src ="http://www.cnitblog.com/guopingleee/aggbug/30203.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/guopingleee/" target="_blank">向左向右走</a> 2007-07-18 20:40 <a href="http://www.cnitblog.com/guopingleee/archive/2007/07/18/30203.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VxWorks 操作系统学习笔记</title><link>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30202.html</link><dc:creator>向左向右走</dc:creator><author>向左向右走</author><pubDate>Wed, 18 Jul 2007 12:34:00 GMT</pubDate><guid>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30202.html</guid><wfw:comment>http://www.cnitblog.com/guopingleee/comments/30202.html</wfw:comment><comments>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30202.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/guopingleee/comments/commentRss/30202.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/guopingleee/services/trackbacks/30202.html</trackback:ping><description><![CDATA[
		<p style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">1.<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">       </span>任务</span>VxWorks</font>
		</p>
		<div>
				<font color="#009900" size="5">任务：在执行时每个程序都被称之为任务。VxWorks操作系统中，任务可以直接地或者以共享方式访问大多数系统资源，为了维护各自的线程，每个任务必须保持有足够的上下文环境。</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">(1)<span style="FONT: 12pt 'Times New Roman'">    </span>任务状态：</font>
		</div>
		<div>
				<font color="#009900" size="5">就绪（READY）：该状态时任务仅等待CPU的状态，不等待其他任何资源。</font>
		</div>
		<div>
				<font color="#009900" size="5">阻塞（PEND）：任务由于一些资源不可用而被阻塞时的状态。</font>
		</div>
		<div>
				<font color="#009900" size="5">睡眠（DELAY）：出于睡眠的任务状态。</font>
		</div>
		<div>
				<font color="#009900" size="5">挂起（SUSPEND）：该状态时任务不执行，主要用于调试用。挂起仅仅约束任务的执行，并不约束状态的转换，因此pended-suspended状态时任务可以解锁，delayed-suspended状态时任务可以唤醒。</font>
		</div>
		<div>
				<font color="#009900" size="5">DELAY+S：既处于睡眠又处于挂起的任务状态。</font>
		</div>
		<div>
				<font color="#009900" size="5">PEND+S：既处于阻塞又处于挂起的任务状态。</font>
		</div>
		<div>
				<font color="#009900" size="5">PEND+T：带有超时值处于阻塞的任务状态。</font>
		</div>
		<div>
				<font color="#009900" size="5">PEND+S+T：带有超时值处于阻塞，同时又处于挂起的任务状态。</font>
		</div>
		<div>
				<font color="#009900" size="5">state+I：任务处于state且带有一个继承优先级。</font>
		</div>
		<div>
				<font color="#009900" size="5">----------------------------------------------------------------------------------------</font>
		</div>
		<div>
				<font color="#009900" size="5">|      ready | ——&gt; | pended      | semTake () / msgQReceive () |</font>
		</div>
		<div>
				<font color="#009900" size="5">|      ready | ——&gt; | delayed      | taskDelay ()               |</font>
		</div>
		<div>
				<font color="#009900" size="5">|      ready | ——&gt; | suspended    | taskSuspend ()             |</font>
		</div>
		<div>
				<font color="#009900" size="5">|     pended | ——&gt; | ready       | semGive () / msgQSend ()    |</font>
		</div>
		<div>
				<font color="#009900" size="5">|     pended | ——&gt; | suspended   | taskSuspend ()             |</font>
		</div>
		<div>
				<font color="#009900" size="5">|    delayed | ——&gt; | ready        | expired delay              |</font>
		</div>
		<div>
				<font color="#009900" size="5">|    delayed | ——&gt; | suspended    | taskSuspend ()             |</font>
		</div>
		<div>
				<font color="#009900" size="5">| suspended | ——&gt; | ready       | taskResume () / taskActivate () |</font>
		</div>
		<div>
				<font color="#009900" size="5">| suspended | ——&gt; | pended      | taskResume ()             |</font>
		</div>
		<div>
				<font color="#009900" size="5">| suspended | ——&gt; | delayed     | taskResume()              |</font>
		</div>
		<div>
				<font color="#009900" size="5">---------------------------------------------------------------------------------------</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">(2)<span style="FONT: 7pt 'Times New Roman'">    </span>Wind任务调度</font>
		</div>
		<div>
				<font color="#009900" size="5">在Wind内核中，默认算法是基于优先级的抢占式调度算法，也可以使用轮转调度算法。</font>
		</div>
		<div>
				<font color="#009900" size="5">任务调度控制函数：</font>
		</div>
		<div>
				<font color="#009900" size="5">----------------------------------------------------------------------------------------</font>
		</div>
		<div>
				<font color="#009900" size="5">|          调用           |            描述                |</font>
		</div>
		<div>
				<font color="#009900" size="5">|      kernelTimeSlice()    |        控制轮转调度            |</font>
		</div>
		<div>
				<font color="#009900" size="5">|      taskPrioritySet()      |       改变任务优先级           |</font>
		</div>
		<div>
				<font color="#009900" size="5">|      taskLock()          |        禁止任务调度            |</font>
		</div>
		<div>
				<font color="#009900" size="5">|      taskUnlock()        |        允许任务调度            |</font>
		</div>
		<div>
				<font color="#009900" size="5">----------------------------------------------------------------------------------------</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div>
				<font color="#009900" size="5">基于优先级的抢占式任务调度：</font>
		</div>
		<div>
				<font color="#009900" size="5">当一个新任务优先级高于系统当前执行任务的优先级时，它将抢占CPU执行。因此，系统内核将确保CPU分配给处于就绪状态的具有最高优先级的任务执行。</font>
		</div>
		<div>
				<font color="#009900" size="5">缺点：当多个相同优先级的任务需要共享一台处理器时，如果某个执行的任务永不阻塞，那么它将一直独占处理器，其他相同优先级的任务就没有机会执行。</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div>
				<font color="#009900" size="5">轮转式调度：</font>
		</div>
		<div>
				<font color="#009900" size="5">当所有相同优先级的任务处于就绪状态时，轮转算法倾向于平均使用CPU，对于所有相同优先级的任务，通过时间片获得相同的CPU处理时间。</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div>
				<font color="#009900" size="5">抢占上锁：</font>
		</div>
		<div>
				<font color="#009900" size="5">通过调用taskLock()和taskUnlock()函数，可以禁止使用Wind内核调度程序或启用Wind内核调度程序。当禁止使用调度程序时，若该任务正在执行，不会发生基于优先级的抢占。</font>
		</div>
		<div>
				<font color="#009900" size="5">抢占上锁只能阻止任务的上下文切换，并不禁止中断。</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div>
				<font color="#009900" size="5">taskLock()和intLock()比较</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div>
				<font color="#009900" size="5">任务优先级：所有应用任务的优先级应该在100-250之间；但是驱动程序支持的任务（与中断服务程序关联的任务）优先级能够位于51-99。</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">(3)<span style="FONT: 12pt 'Times New Roman'">    </span>任务异常处理：</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">(4)<span style="FONT: 12pt 'Times New Roman'">    </span>共享代码和重入</font>
		</div>
		<div>
				<font color="#009900" size="5">VxWorks操作系统中，大多数函数是可重入的。但若存在一个对应于命名为someName_r()的函数，someName() 因作为函数重入的版本将认为是不可重入的。例如，ldiv() 有一个对应函数ldiv_r()，则ldiv() 是不可重入的。</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div>
				<font color="#009900" size="5">重入技术：</font>
		</div>
		<div>
				<font color="#009900" size="5">. 动态堆栈变量</font>
		</div>
		<div>
				<font color="#009900" size="5">. 被信号保护的全局和静态变量</font>
		</div>
		<div>
				<font color="#009900" size="5">. 任务变量：taskVarAdd(), taskVarDelete()和taskVarGet()</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">(5)<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">    </span>操作系统任务</span>VxWorks</font>
		</div>
		<div>
				<font color="#009900" size="5">. tUserRoot：内核执行的首个任务，入口点是安装目录/target/config/all/usrConfig.c下函数usrRoot()，可初始化VxWorks操作系统的大部分程序，发起诸如日志任务、异常处理任务、网络任务和tRlogind后台程序。正常情况下根任务在所有初始化结束后，终止任务并且被删除。</font>
		</div>
		<div>
				<font color="#009900" size="5">. tLogTask：日志任务</font>
		</div>
		<div>
				<font color="#009900" size="5">. tExcTask：异常处理任务，必须拥有系统的最高优先级。</font>
		</div>
		<div>
				<font color="#009900" size="5">. tNetTask：网络任务，用于VxWorks网络任务级程序处理。通常配置INCLUDE_NET_LIB组件的VxWorks操作系统可以发起网络任务。</font>
		</div>
		<div>
				<font color="#009900" size="5">. tWdbTask：目标代理任务，用INCLUDE_WDB组件配置的VxWorks操作系统包括目标代理功能。</font>
		</div>
		<div>
				<font color="#009900" size="5">. 可选组建的任务</font>
		</div>
		<div>
				<font color="#009900" size="5">. tShell</font>
		</div>
		<div>
				<font color="#009900" size="5">. tRlogind</font>
		</div>
		<div>
				<font color="#009900" size="5">. tTelnetd</font>
		</div>
		<div>
				<font color="#009900" size="5">. tPortmapd</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">2.<span style="FONT: 12pt 'Times New Roman'">       </span>任务间通信</font>
		</div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">(1)<span style="FONT: 12pt 'Times New Roman'">    </span>共享内存，数据的简单共享</font>
		</div>
		<div>
				<font color="#009900" size="5">在VxWorks操作系统中所有任务存在于一个单独的线性地址空间中，所以任务间共享数据结构是很容易实现的。全局变量、线性缓冲、环形缓冲、连接链和指针都可以被运行在不同上下文中的代码直接引用。</font>
		</div>
		<div>
				<font color="#009900" size="5">
				</font> </div>
		<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
				<font color="#009900" size="5">(2)<span style="FONT: 12pt 'Times New Roman'">    </span>信号量，基本的互斥和同步</font>
		</div>
		<div>
				<font color="#009900" size="5">. 实现资源互斥访问的方法包括：</font>
		</div>
		<div style="TEXT-INDENT: 31.5pt">
				<font color="#009900" size="5">中断上锁（中断上锁时不要调用VxWorks操作系统函数，强行使用会导致意外的中断）：intLock() 和intUnlock()</font>
		</div>
		<div style="TEXT-INDENT: 31.5pt">
				<font color="#009900" size="5">抢占上锁：taskLock() 和taskUnlock()</font>
		</div>
		<div style="TEXT-INDENT: 31.5pt">
				<font color="#009900" size="5">信号量对资源的上锁</font>
		</div>
		<div style="TEXT-INDENT: 31.5pt">
				<font color="#009900" size="5">
				</font> </div>
		<div>
				<font color="#009900" size="5">. VxWorks操作系统中的信号量类型</font>
		</div>
		<div>
				<font color="#009900" size="5">      二进制，最快最通用的信号量，适用于同步和互斥。</font>
		</div>
		<div style="TEXT-INDENT: 31.5pt">
				<font color="#009900" size="5">互斥，为解决内在互斥问题、优先级继承、删除安全以及递归问题等而最优化的一种特殊二进制信号量。</font>
		</div>
		<div style="TEXT-INDENT: 31.5pt">
				<font color="#009900" size="5">计数，类似于二进制信号量，但其跟踪信号量被释放的次数，适用于单个资源多个实例需要保护的情况。</font>
		</div>
		<div style="TEXT-INDENT: 31.5pt">
				<font color="#009900" size="5">
				</font> </div>
		<div>
				<font color="#009900" size="5">. 队列类型：</font>
		</div>
		<div>
				<font color="#009900" size="5">      SEM_Q_PRIORITY：根据优先级顺序</font>
		</div>
		<div>
				<font color="#009900" size="5">      SEM_Q_FIFO：根据先进先出顺序</font>
		</div>
		<div>
				<br />
				<div>
						<font color="#009900" size="5">. 互斥信号量</font>
				</div>
				<div>
						<font color="#009900" size="5">      基本行为与二进制信号量一致，不同之处如下：</font>
				</div>
				<div>
						<font color="#009900" size="5">      仅用于互斥；</font>
				</div>
				<div>
						<font color="#009900" size="5">      仅能由提取它（即调用semTake()）的任务释放；</font>
				</div>
				<div>
						<font color="#009900" size="5">      不能在中断服务程序中释放；</font>
				</div>
				<div>
						<font color="#009900" size="5">      semFlush()函数操作非法；</font>
				</div>
				<div>
						<font color="#009900" size="5">      .. 优先级倒置：互斥信号量选项SEM_INVERSION_SAF能够继承优先级算法，优先级继承协议确保在资源阻塞的所有任务中优先级最高的且拥有资源执行资格的任务将优先执行。一旦任务的优先级被提高，它以提高后的优先级执行；直到释放其占有的全部互斥信号量后，该任务将返回到正常或者标准的优先级。该选项要求与优先级队列（SEM_Q_PRIORITY）一起使用。</font>
				</div>
				<div>
						<font color="#009900" size="5">      .. 删除安全：一个受信号量保护的临界区域内经常需要保护执行任务避免被意外地删除。删除一个在临界区执行的任务可能会导致意想不到的后果。原语semSafe()和semUnsafe()提供了一种任务安全的方法。但是在使用互斥信号量选项SEM_DELETE_SAFE时，每次使用semTake()将隐含调用taskSafe()，使用semGive()将隐含调用taskUnsafe()。使用这种方式，任务在占用信号量时不会被删除。</font>
				</div>
				<div>
						<font color="#009900" size="5">      .. 递归资源访问：互斥信号量能够递归获得。在释放信号量前，递归获取的互斥信号量被释放和提取的次数应该相等，这通过一个计数器跟踪实现。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">. 计数器信号量</font>
				</div>
				<div>
						<font color="#009900" size="5">      是实现任务同步和互斥的另一种手段，适用于保护多份复制的资源。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">(3)<span style="FONT: 12pt 'Times New Roman'">    </span>消息队列</font>
				</div>
				<div>
						<font color="#009900" size="5">在VxWorks操作系统里，单个CPU里任务间的主要通信方式使用消息队列。</font>
				</div>
				<div>
						<font color="#009900" size="5">------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">|      调用         |           描述                    |</font>
				</div>
				<div>
						<font color="#009900" size="5">| msgQCreate()      | 分配并初始化一个消息队列         |</font>
				</div>
				<div>
						<font color="#009900" size="5">| msgQDelete()      | 终止并释放一个消息队列           |</font>
				</div>
				<div>
						<font color="#009900" size="5">| msgQSend()       | 向一个消息队列发送消息           |</font>
				</div>
				<div>
						<font color="#009900" size="5">| msgQReceive()    |   从一个消息队列接收消息           |</font>
				</div>
				<div>
						<font color="#009900" size="5">------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">消息的优先级：MSG_PRI_NORMAL和MSG_PRI_URGENT</font>
				</div>
				<div>
						<font color="#009900" size="5">中断服务程序能够向消息管道中写入，但不能从消息管道中读取。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">(4)<span style="FONT: 12pt 'Times New Roman'">    </span>管道</font>
				</div>
				<div>
						<font color="#009900" size="5">管道使用VxWorks操作系统中的I/O系统，并提供替换消息队列的接口。管道是由驱动程序pipeDrv管理的虚拟I/O设备，任务能够使用标准I/O 对管道进行打开、读取或写入等操作，另外也可以调用函数ioctl。</font>
				</div>
				<div>
						<font color="#009900" size="5">与消息管道类似，中断服务程序能够向管道写入，但不能从管道读取。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">(5)<span style="FONT: 12pt 'Times New Roman'">    </span>任务间网络通信</font>
				</div>
				<div>
						<font color="#009900" size="5">套接字Sockets</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">远程程序调用RPC</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">(6)<span style="FONT: 12pt 'Times New Roman'">    </span>信号</font>
				</div>
				<div>
						<font color="#009900" size="5">VxWorks支持软件信号功能。信号可以异步改变任务的控制流程。任何任务或中断服务程序可以向指定任务发送信号。接收到信号的任务立即挂起当前的执行线程，在下次调度执行时转而执行指定的信号处理程序。信号处理程序在接收任务的上下文中执行，并使用任务的堆栈。即使在任务被阻塞时，仍可调用信号处理程序。</font>
				</div>
				<div>
						<font color="#009900" size="5">通常信号处理程序可作为中断处理程序看待，任何导致调用程序阻塞的函数均不能在信号处理程序中调用。</font>
				</div>
				<div>
						<font color="#009900" size="5">Wind内核支持两种类型的信号接口：UNIX BSD风格的信号和POSIX兼容信号。为了简化设计，建议在一个应用程序中使用一种类型接口，不要混合使用不同接口。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">基本信号函数：</font>
				</div>
				<div>
						<font color="#009900" size="5">----------------------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">| POSIX 1003.1b兼容调用|UNIX BSD兼容调用|     描述                     |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    signal()            |      signal()     | 指定信号的处理程序           |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    kill()              |       kill()      | 向任务发送信号               |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    raise()             |       N/A       | 向自身发送信号               |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigaction()         |     sigvec()     | 检查或设置信号的处理程序     |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigsuspend()        |       pause()    | 挂起任务直至任务提交         |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigpending()        |       N/A     | 恢复一组用于传递而被阻塞的信号|</font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigemptyset() ------- | ------------------------ | ---------------------------------------------|     </font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigfillset()   ------- |                 |                              |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigaddset() -------- |     sigsetmask() | 设置信号屏蔽                 |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigdelset() --------   |                |                              |</font>
				</div>
				<div>
						<font color="#009900" size="5">|   sigismember() -------  |--------------------- ---|---------------------------------------------|</font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigprocmask()      |     sigsetmask() | 设置阻塞信号的屏蔽           |</font>
				</div>
				<div>
						<font color="#009900" size="5">|    sigprocmask()      |     sigblock()    | 增加到一组阻塞的信号中       |</font>
				</div>
				<div>
						<font color="#009900" size="5">----------------------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">信号发生通常与硬件中断相联系。例如总线出错、非法指令以及浮点数异常都可能产生某种信号。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">3.<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">       </span>事件</span>VxWorks</font>
				</div>
				<div>
						<font color="#009900" size="5">VxWorks事件是一种在任务和中断处理程序间，或任务和VxWorks结构体间的通信方式。在VxWorks事件上下文中，这些结构体被用作为资源，包括信号量和消息队列。只有任务能够接收事件；然而任务、中断处理程序或资源都可以发送事件。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">(1)<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">    </span>事件</span>pSOS</font>
				</div>
				<div>
						<font color="#009900" size="5">. 发送和接收事件</font>
				</div>
				<div>
						<font color="#009900" size="5">任务、中断服务程序以及资源都使用同一个应用编程接口ev_send()来发送事件。</font>
				</div>
				<div>
						<font color="#009900" size="5">对于从资源接收事件的任务来说，任务必须用资源寄存，而且请求资源在空闲时发送一系列指定的事件；这种资源可以使信号量，也可以是消息队列。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">. 等待事件</font>
				</div>
				<div>
						<font color="#009900" size="5">任务能够从一个或多个资源等待多个事件。每个资源可以发送多个事件，同样任务也可以等待接收一个或多个事件。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">. 事件的寄存</font>
				</div>
				<div>
						<font color="#009900" size="5">从资源接收事件时，资源只能寄存一个任务。如果另一个任务随后用同样的资源寄存，那么不会通知原先寄存的任务就自动解除原有的寄存。VxWorks事件寄存的处理与pPOS事件则不同。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">. 空闲资源</font>
				</div>
				<div>
						<font color="#009900" size="5">当资源给任务发送事件表明空闲时，不意味着资源的空闲状态可以保留。因此，从资源等待事件的任务在资源空闲时被解除阻塞；但同时资源也可能被取走。</font>
				</div>
				<div>
						<font color="#009900" size="5">对于两个或两个以上的任务持续交换资源所有权的情况，资源虽然被释放，但并不处于空闲状态，所以资源将不会发送事件。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">. 应用编程接口</font>
				</div>
				<div>
						<font color="#009900" size="5">------------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">| 函数      |                     描述                        |</font>
				</div>
				<div>
						<font color="#009900" size="5">| ev_send()     | 给任务发送事件                                  |</font>
				</div>
				<div>
						<font color="#009900" size="5">| ev_receive()   | 等待事件                                        |</font>
				</div>
				<div>
						<font color="#009900" size="5">| sm_notify()   | 寄存一个被信号量告知可用的任务                   |</font>
				</div>
				<div>
						<font color="#009900" size="5">| q_notify()     | 寄存一个被消息队列告知有消息到来的任务          |</font>
				</div>
				<div>
						<font color="#009900" size="5">| q_vnoify     | 寄存一个被可变长度的消息队列告知有消息到来的任务 |</font>
				</div>
				<div>
						<font color="#009900" size="5">------------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">(2)<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">    </span>事件</span>VxWorks</font>
				</div>
				<div>
						<font color="#009900" size="5">VxWorks事件执行以pPOS事件为基石。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">. 空闲资源定义</font>
				</div>
				<div>
						<font color="#009900" size="5">     互斥信号量：当一个互斥信号量被释放并且在其上没有任务阻塞</font>
				</div>
				<div>
						<font color="#009900" size="5">     二进制信号量：当没有任务占有或等待一个二进制信号量</font>
				</div>
				<div>
						<font color="#009900" size="5">     计数器信号量：一个计数器信号量在其计数值非零且其上没有阻塞任务时</font>
				</div>
				<div>
						<font color="#009900" size="5">     消息队列：队列中有消息存在，且没有等待该队列中消息而阻塞的任务</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">. VxWorks对pPOS事件的扩展</font>
				</div>
				<div>
						<font color="#009900" size="5">     单任务资源寄存：在pPOS系统中一个任务用资源寄存发送pSOS事件时，它会无意地取消另一个已用该资源寄存的任务寄存，第一个用该资源寄存的任务将无限期地被阻止。VxWorks事件则提供了一个选项，在该选项中如果另一个任务已经用某个资源寄存了，则不允许第二个任务用该资源再寄存。如果第二个任务用该资源寄存，将返回一个错误。</font>
				</div>
				<div>
						<font color="#009900" size="5">     立即发送选项：当一个pPOS任务用资源寄存时，即使寄存时资源处于空闲状态，也不会立即给任务发送时间。对于VxWorks事件，默认行为与之相同。然而，VxWorks事件提供了一个选项，即若该资源在寄存时处于空闲状态，该选项允许任务请求资源立即给其发送事件。</font>
				</div>
				<div>
						<font color="#009900" size="5">     自动取消寄存选项：pPOS执行过程序要任务在从资源接收任务后明确地取消寄存。VxWorks执行提供一个选项，该选项可以通知资源仅发送一次事件，然后在发送后自动取消寄存。</font>
				</div>
				<div>
						<font color="#009900" size="5">     自动解除资源堵塞：当删除资源（一个信号量或者消息队列时），调用函数semDelete()和msgQDelete()解除所有任务的挂起。在任务等待被删除资源发送事件时，该措施保护任务避免无限期地堵塞。然后任务继续执行，导致任务挂起的函数eventReceive()返回一个ERROR值。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">事件25到32（VXEV25或0x01000000到VXEV32或0x80000000）用作系统保留用，VxWorks用户不可以使用这些事件。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">(3)<span style="FONT: 7pt 'Times New Roman'"><span style="FONT-SIZE: 12pt">    </span>比较</span>API</font>
				</div>
				<div>
						<font color="#009900" size="5">------------------------------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">| VxWorks函数 | pPOS函数 |            注释                             |</font>
				</div>
				<div>
						<font color="#009900" size="5">|   eventSend    |   ev_send    | 直接端口                                   |</font>
				</div>
				<div>
						<font color="#009900" size="5">|   eventReceive | ev_receive   | 直接端口                                    |</font>
				</div>
				<div>
						<font color="#009900" size="5">|   eventClear    |             | VxWorks中的新功能                         |</font>
				</div>
				<div>
						<font color="#009900" size="5">|   semEvStart    | sm_notify   | SemEvStart等价于用非零事件参数调用sm_notify |</font>
				</div>
				<div>
						<font color="#009900" size="5">|   semEvStop    | sm_notify   | SemEvStop等价于用事件参数为0调用sm_notify |</font>
				</div>
				<div>
						<font color="#009900" size="5">|   msgQEvStart | q_vnotify   | msgQEvStart等价于用非零事件参数调用q_notify |</font>
				</div>
				<div>
						<font color="#009900" size="5">|   msgQEvStop | q_vnotify   | msgQEvStop等价于用事件参数为0调用q_notify |</font>
				</div>
				<div>
						<font color="#009900" size="5">|                | q_notify    | VxWorks没有一个固定长度的消息队列机制     |</font>
				</div>
				<div>
						<font color="#009900" size="5">------------------------------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">4.<span style="FONT: 12pt 'Times New Roman'">       </span>看门狗定时器</font>
				</div>
				<div>
						<font color="#009900" size="5">VxWorks包括一个看门狗定时器机制，允许任何C函数与一个特定的时间延时器联系。看门狗定时器作为系统时钟中断服务程序的一部分来维护。被看门狗定时器调用的函数通常作为系统时钟中断级的中断服务代码来执行。但如果内核由于某种原因不能立即执行能够函数（例如一个优先中断或者内核状态），函数将放在tExcTask工作队列中。tExcTask工作队列中的函数以tExcTask（通常是0）优先级来执行。</font>
				</div>
				<div>
						<font color="#009900" size="5">-------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">|    调用    |                 描述                          |</font>
				</div>
				<div>
						<font color="#009900" size="5">| wdCreate() | 分配并初始化一个看门狗定时器                  |</font>
				</div>
				<div>
						<font color="#009900" size="5">| wdDelete() | 终止并释放一个看门狗定时器                    |</font>
				</div>
				<div>
						<font color="#009900" size="5">| wdStart() | 启动一个看门狗定时器                          |</font>
				</div>
				<div>
						<font color="#009900" size="5">| wdCancel() | 取消当前的一个计数的看门狗定时器             |</font>
				</div>
				<div>
						<font color="#009900" size="5">-------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div style="MARGIN: 0cm 0cm 0pt 18pt; TEXT-INDENT: -18pt">
						<font color="#009900" size="5">5.<span style="FONT: 12pt 'Times New Roman'">       </span>中断服务代码</font>
				</div>
				<div>
						<font color="#009900" size="5">为了尽快地响应中断，VxWorks中断处理程序在所有任务上下文之外的一个特殊上下文内执行。因此，中断处理不涉及到任务上下文的切换。</font>
				</div>
				<div>
						<font color="#009900" size="5">--------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">|    调用        |                 描述                       |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intConnect()    |    设置中断处理的C程序                   |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intContext()    |    如果是从中断级调用，返回真              |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intCount()      |    获得当前中断嵌套深度                   |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intLevelSet()   |    设置处理器的中断屏蔽级                  |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intLock()      |    禁止中断                                |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intUnlock()     |    重新允许中断                           |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intVecBaseSet() |   设置向量基地址                          |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intVecBaseGet() |   得到向量基地址                         |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intVecSet()      |   设置异常向量                           |</font>
				</div>
				<div>
						<font color="#009900" size="5">| intVecGet()      |   获得异常向量                           |</font>
				</div>
				<div>
						<font color="#009900" size="5">--------------------------------------------------------------------------------------------</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">调用中断服务程序函数存在着很多的限制。例如，在应用中断服务程序时不能使用printf(), malloc()和semTake()函数，但是可以使用semGive(), logMsg(), msgQSend()和bcopy()这样的函数。</font>
				</div>
				<div>
						<font color="#009900" size="5">产生这些限制的原因是由于中断服务程序不在一个固定的任务上下文中执行，而且没有任务控制块，因此所有中断服务程序必须共享一个单独的堆栈。</font>
				</div>
				<div>
						<font color="#009900" size="5">
						</font> </div>
				<div>
						<font color="#009900" size="5">. 中断服务程序基本限制为禁止调用导致调用者堵塞的函数。</font>
				</div>
				<div>
						<font color="#009900" size="5">. malloc()和free()都要求获得信号量，中断服务程序不能调用任何用于创建或删除的函数。</font>
				</div>
				<div>
						<font color="#009900" size="5">. 中断服务程序不能通过VxWorks驱动程序来执行I/O操作，因为大多数的设备驱动器可能会堵塞等待设备的调用者，因此它们需要一个任务上下文。但VxWorks管道驱动器是个例外，它设计用于中断服务程序的写操作。</font>
				</div>
				<div>
						<font color="#009900" size="5">. VxWorks提供了一个记录功能，允许向系统任务平台打印文本信息。这个机制是专门为中断服务程序使用而设计的，同时它也是从中断服务程序打印信息的最常用方法。</font>
				</div>
				<div>
						<font color="#009900" size="5">. 中断服务程序同时禁止调用浮点协处理器函数。在VxWorks操作系统中，由intConnect()函数建立的中断驱动代码不能保存和恢复浮点寄存器。若中断服务程序需要使用浮点指令，则必须明确地保存和恢复fppArchLib中函数浮点协处理器的寄存器。</font>
				</div>
				<div>
						<font color="#009900" size="5">. 所有VxWorks函数库，像连接链和环形缓冲器，都可以被中断服务程序使用。</font>
				</div>
				<br />
		</div>
<img src ="http://www.cnitblog.com/guopingleee/aggbug/30202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/guopingleee/" target="_blank">向左向右走</a> 2007-07-18 20:34 <a href="http://www.cnitblog.com/guopingleee/archive/2007/07/18/30202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VxWork介绍及编程</title><link>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30188.html</link><dc:creator>向左向右走</dc:creator><author>向左向右走</author><pubDate>Wed, 18 Jul 2007 09:17:00 GMT</pubDate><guid>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30188.html</guid><wfw:comment>http://www.cnitblog.com/guopingleee/comments/30188.html</wfw:comment><comments>http://www.cnitblog.com/guopingleee/archive/2007/07/18/30188.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/guopingleee/comments/commentRss/30188.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/guopingleee/services/trackbacks/30188.html</trackback:ping><description><![CDATA[
		<p>
				<strong>
						<font lang="ZH-CN" face="宋体" size="5">一.嵌入式操作系统VxWorks简介</font>
						<a name="begin">
						</a>
				</strong>
		</p>
		<p style="LINE-HEIGHT: 150%">
				<font size="3">
						<strong>VxWorks</strong>操作系统是美国WindRiver公司于1983年设计开发的一种嵌入式实时操作系统（RTOS），是嵌入式开发环境的关键组成部分。良好的持续发展能力、高性能的内核以及友好的用户开发环境，在嵌入式实时操作系统领域占据一席之地。</font>
				<font lang="ZH-CN" face="System">它以其良好的可靠性和卓越的实时性被广泛地应用在通信、军事、航空、航天等高精尖技术及实时性要求极高的领域中，如卫星通讯、军事演习、弹道制导、飞机导航等。在美国的</font>
				<font lang="ZH-CN" face="宋体">F-16</font>
				<font lang="ZH-CN" face="System">、</font>
				<font lang="ZH-CN" face="宋体">FA-18 </font>
				<font lang="ZH-CN" face="System">战斗机、</font>
				<font lang="ZH-CN" face="宋体">B-2 </font>
				<font lang="ZH-CN" face="System">隐形轰炸机和爱国者导弹上，甚至连</font>
				<font lang="ZH-CN" face="宋体">1997</font>
				<font lang="ZH-CN" face="System">年</font>
				<font lang="ZH-CN" face="宋体">4</font>
				<font lang="ZH-CN" face="System">月在火星表面登陆的火星探测器上也使用到了</font>
				<font lang="ZH-CN" face="宋体">VxWorks</font>
				<font lang="ZH-CN" face="System">。</font>
		</p>
		<blockquote>
				<p>
						<a href="http://www.windriver.com/" target="_blank">WindRiver公司网址</a>
				</p>
		</blockquote>
		<p>　</p>
		<p>
				<font lang="ZH-CN" face="宋体" size="3">
						<strong>实时操作系统和分时操作系统的区别</strong>
				</font>
		</p>
		<blockquote>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="System">     从操作系统能否满足实时性要求来区分，可把操作系统分成分时操作系统和实时操作系统。</font>
				</p>
				<font lang="ZH-CN" face="System">
						<p style="LINE-HEIGHT: 150%">  分时操作系统按照相等的时间片调度进程轮流运行，分时操作系统由调度程序自动计算进程的优先级，而不是由用户控制进程的优先级。这样的系统无法实时响应外部异步事件。</p>
				</font>
				<font lang="ZH-CN" face="System">
						<p style="LINE-HEIGHT: 150%">    实时操作系统能够在限定的时间内执行完所规定的功能，并能在限定的时间内对外部的异步事件作出响应。</p>
				</font>
				<font face="宋体, MS Song">
				</font>
				<font lang="ZH-CN" face="System">分时系统主要应用于科学计算和一般实时性要求不高的场合。实时性系统主要应用于过程控制、数据采集、通信、多媒体信息处理等对时间敏感的场合。</font>
		</blockquote>
		<p style="LINE-HEIGHT: 150%">
				<font lang="ZH-CN" face="宋体" size="4">
						<strong>VxWorks的特点</strong>
				</font>
		</p>
		<ul>
				<li>
						<p style="LINE-HEIGHT: 150%">
								<font lang="ZH-CN" face="宋体" size="3">
										<strong>可靠性</strong>
								</font>
						</p>
				</li>
		</ul>
		<blockquote>
				<font lang="ZH-CN" face="System">
						<p style="LINE-HEIGHT: 150%">    操作系统的用户希望在一个工作稳定，可以信赖的环境中工作，所以操作系统的可靠性是用户首先要考虑的问题。而稳定、可靠一直是VxWorks的一个突出优点。自从对中国的销售解禁以来，</p>
				</font>
				<font lang="ZH-CN" face="宋体">VxWorks</font>
				<font lang="ZH-CN" face="System">以其良好的可靠性在中国赢得了越来越多的用户。</font>
				<font lang="ZH-CN" face="宋体">
				</font>
		</blockquote>
		<ul>
				<li>
						<p style="LINE-HEIGHT: 150%">
								<font lang="ZH-CN" face="宋体" size="3">
										<strong>实时性</strong>
								</font>
						</p>
				</li>
		</ul>
		<blockquote>
				<font lang="ZH-CN" face="System">
						<p style="LINE-HEIGHT: 150%">   实时性是指能够在限定时间内执行完规定的功能并对外部的异步事件作出响应的能力。实时性的强弱是以完成规定功能和作出响应时间的长短来衡量的。</p>
				</font>
		</blockquote>
		<blockquote>
				<font lang="ZH-CN" face="宋体">
						<p style="LINE-HEIGHT: 150%">    VxWorks </p>
				</font>
				<font lang="ZH-CN" face="System">的实时性做得非常好，其系统本身的开销很小，进程调度、进程间通信、中断处理等系统公用程序精练而有效，它们造成的延迟很短。</font>
				<font lang="ZH-CN" face="宋体">VxWorks </font>
				<font lang="ZH-CN" face="System">提供的多任务机制中对任务的控制采用了优先级抢占（</font>
				<font lang="ZH-CN" face="宋体">Preemptive Priority Scheduling</font>
				<font lang="ZH-CN" face="System">）和轮转调度（</font>
				<font lang="ZH-CN" face="宋体">Round-Robin Scheduling</font>
				<font lang="ZH-CN" face="System">）机制，也充分保证了可靠的实时性，使同样的硬件配置能满足更强的实时性要求，为应用的开发留下更大的余地。</font>
				<font lang="ZH-CN" face="宋体">
				</font>
		</blockquote>
		<ul>
				<li>
						<p style="LINE-HEIGHT: 150%">
								<font lang="ZH-CN" face="宋体" size="3">
										<strong>可裁减性</strong>
								</font>
						</p>
				</li>
		</ul>
		<blockquote>
				<font lang="ZH-CN" face="System">
						<p style="LINE-HEIGHT: 150%">   用户在使用操作系统时，并不是操作系统中的每一个部件都要用到。例如图形显示、文件系统以及一些设备驱动在某些嵌入系统中往往并不使用。</p>
				</font>
				<font lang="ZH-CN" face="宋体">
						<p style="LINE-HEIGHT: 150%">  VxWorks </p>
				</font>
				<font lang="ZH-CN" face="System">由一个体积很小的内核及一些可以根据需要进行定制的系统模块组成。</font>
				<font lang="ZH-CN" face="宋体">VxWorks </font>
				<font lang="ZH-CN" face="System">内核最小为</font>
				<font lang="ZH-CN" face="宋体">8kB</font>
				<font lang="ZH-CN" face="System">，即便加上其它必要模块，所占用的空间也很小，且不失其实时、多任务的系统特征。由于它的高度灵活性，用户可以很容易地对这一操作系统进行定制或作适当开发，来满足自己的实际应用需要。</font>
				<font lang="ZH-CN" face="宋体">
				</font>
		</blockquote>
		<p style="LINE-HEIGHT: 150%">
				<strong>
						<font lang="ZH-CN" face="宋体" size="3">对一个实时内核的要求</font>
						<font lang="ZH-CN" face="宋体">
								<big>
										<big>
												<font size="5">
												</font>
										</big>
								</big>
						</font>
				</strong>
		</p>
		<blockquote>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="System">一个实时操作系统内核需满足许多特定的实时环境所提出的基本要求，这些包括：</font>
				</p>
		</blockquote>
		<blockquote>
				<p style="LINE-HEIGHT: 150%">
						<strong>
								<font lang="ZH-CN" face="宋体" size="3">多任务</font>
								<font lang="ZH-CN" face="System">：</font>
						</strong>由于真实世界的事件的异步性，能够运行许多并发进程或任务是很重要的。多任务提供了一个较好的对真实世界的匹配，因为它允许对应于许多外部事件的多线程执行。系统内核分配<font lang="ZH-CN" face="宋体">CPU</font>给这些任务来获得并发性。</p>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="宋体" size="3">
								<strong>抢占调度</strong>
						</font>
						<font lang="ZH-CN" face="System">：真实世界的事件具有继承的优先级，在分配<font lang="ZH-CN" face="宋体">CPU</font>的时候要注意到这些优先级。基于优先级的抢占调度，任务都被指定了优先级，在能够执行的任务（没有被挂起或正在等待资源）中，优先级最高的任务被分配<font lang="ZH-CN" face="宋体">CPU</font>资源。换句话说，当一个高优先级的任务变为可执行态，它会立即抢占当前正在运行的较低优先级的任务。<font lang="ZH-CN" face="宋体"></font></font>
				</p>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="宋体" size="3">
								<strong>任务间的通讯与同步</strong>
						</font>
						<font lang="ZH-CN" face="System">：在一个实时系统中，可能有许多任务作为一个应用的一部分执行。系统必须提供这些任务间的快速且功能强大的通信机制。内核也要提供为了有效地共享不可抢占的资源或临界区所需的同步机制。</font>
				</p>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="宋体" size="3">
								<strong>任务与中断之间的通信</strong>
						</font>
						<font lang="ZH-CN" face="System">：尽管真实世界的事件通常作为中断方式到来，但为了提供有效的排队、优先化和减少中断延时，我们通常希望在任务级处理相应的工作。所以需要杂任务级和中断级之间存在通信。</font>
				</p>
				<p style="LINE-HEIGHT: 150%" align="right">　</p>
		</blockquote>
		<p style="LINE-HEIGHT: 150%">
				<font lang="ZH-CN" face="宋体" size="5">
						<strong>二.系统编程方法</strong>
				</font>
		</p>
		<p style="LINE-HEIGHT: 150%">　</p>
		<font lang="ZH-CN" face="System">
				<p style="LINE-HEIGHT: 150%">实时系统主要包括</p>
		</font>
		<font lang="ZH-CN" face="宋体">:</font>
		<font lang="ZH-CN" face="System">多任务调度（采用优先级抢占方式），任务间的同步和进程间通信机制</font>
		<font lang="ZH-CN" face="宋体">.</font>
		<font lang="ZH-CN" face="System">
				<blockquote>
						<p style="LINE-HEIGHT: 150%">一个多任务环境允许实时应用程序以一套独立任务的方式构筑，每个任务拥有独立的执行线程和它自己的一套系统资源。进程间通信机制使得这些任务的行为同步、协调。</p>
				</blockquote>
		</font>
		<font face="宋体, MS Song">
		</font>
		<font lang="ZH-CN" face="System">wind使用中断驱动和优先级的方式。它缩短了上下文转换的时间开销和中断的时延。在</font>
		<font face="宋体, MS Song">
		</font>
		<font lang="ZH-CN" face="System">VxWorks 中，任何例程都可以被启动为一个单独的任务，拥有它自己的上下文和堆栈。还有一些其它的任务机制可以使任务挂起、继续、删除、延时或改变优先级。</font>
		<font face="宋体, MS Song">
		</font>
		<font lang="ZH-CN" face="System">
				<p style="LINE-HEIGHT: 150%">另一个重要内容是:硬件中断处理。硬件产生中断,统治系统调用相应的中断历程(ISR),位是系统得到尽快的响应,ISR在它自己独立的上下文和堆栈中运行.它的优先级高于任何任务优先级.</p>
				<h4 class="EntityTitle">
						<a name="93407">
								<font class="sans" face="Helvetica, sans-serif" size="-1">Task State Transitions</font>
						</a>
				</h4>
				<dl class="margin">
						<div class="Anchor">
						</div>
				</dl>
				<p style="LINE-HEIGHT: 150%">　</p>
				<p style="LINE-HEIGHT: 150%">　</p>
		</font>
		<blockquote>
				<p style="LINE-HEIGHT: 150%">
						<strong>
								<font lang="ZH-CN" face="宋体" size="4">中断延迟</font>
								<font lang="ZH-CN" face="System">(Interrupt Latency) </font>
						</strong>中断延迟是指从硬件中断发生到开始执行中断处理程序第一条指令之间的这段时间。 </p>
				<p style="LINE-HEIGHT: 150%">
						<strong>
								<font lang="ZH-CN" face="宋体" size="4">优先级驱动</font>
								<font lang="ZH-CN" face="System">(Priority-Driven)  </font>
						</strong>优先级驱动是指多任务系统中，当前运行任务总是具有最高优先级的就绪任务。 </p>
		</blockquote>
		<ul>
				<li>
						<p style="LINE-HEIGHT: 150%">
								<strong>
										<font lang="ZH-CN" size="5">多任务调度</font>
								</strong>
						</p>
				</li>
		</ul>
		<font lang="ZH-CN" face="System">
				<blockquote>
						<p style="LINE-HEIGHT: 150%">两种方式: 优先抢占和轮转调度(Preemptive Priority,Round-Robin Scheduling).</p>
				</blockquote>
		</font>
		<strong>
				<blockquote>
						<p style="LINE-HEIGHT: 150%">
								<font lang="ZH-CN">优先抢占</font>
						</p>
				</blockquote>
		</strong>
		<font lang="ZH-CN" face="System">(Preemptive Priority): 每一个任务都有一个优先级,系统核心保证优先级最高的任务运行于CPU.如果有任务优先级高于当前的任务优先级,系统立刻保存当前任务的上下文,切换到优先级高的上下文. </font>
		<h4 class="EntityTitle">
				<a name="83848">
						<font class="sans" face="Helvetica, sans-serif" size="-1">Priority Preemption</font>
				</a>
		</h4>
		<dl class="margin">
				<div class="Anchor">
				</div>
		</dl>
		<p style="LINE-HEIGHT: 150%">　 </p>
		<p style="LINE-HEIGHT: 150%">　 </p>
		<blockquote>
				<b>
						<blockquote>
								<p style="LINE-HEIGHT: 150%">
										<font lang="ZH-CN">抢占(Preemptive):</font>
										<font lang="ZH-CN" face="System">
										</font>
								</p>
						</blockquote>
				</b>
				<font lang="ZH-CN">抢占是指当系统处于核心态运行时, 允许任务的重新调度。换句话说就是指正在执行的任务可以被打断，让另一个任务运行。抢占提高了应用对异步事件的响应性能力。操作系统内核可抢占，并不是说任务调度在任何时候都可以发生。例如当一个任务正在通过一个系统调用访问共享数据时，重新调度和中断都被禁止.</font>
		</blockquote>
		<blockquote>
				<p style="LINE-HEIGHT: 150%">
						<strong>
								<font lang="ZH-CN">任务上下文(Task Context):</font>
						</strong>
						<b>
								<font lang="ZH-CN" face="System">
								</font>
						</b>
						<font lang="ZH-CN">任务上下文是指任务运行的环境。例如，针对x86的CPU，任务上下文可包括程序计数器、堆栈指针、通用寄存器的内容.</font>
				</p>
		</blockquote>
		<blockquote>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN">
								<strong>上下文切换（Context Switching）:</strong> 多任务系统中，上下文切换是指CPU的控制权由运行任务转移到另外一个就绪任务时所发生的事件，当前运行任务转为就绪（或者挂起、删除）状态，另一个被选定的就绪任务成为当前任务。上下文切换包括保存当前任务的运行环境，恢复将要运行任务的运行环境。上下文的内容依赖于具体的CPU.</font>
				</p>
				<font lang="ZH-CN" face="System">
						<p style="LINE-HEIGHT: 150%">　</p>
				</font>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN">
								<strong>
										<big>
												<font size="4">轮转调度(</font>
										</big>Round-Robin Scheduling):</strong>使所有相同优先级,状态为ready的任务公平分享CPU(分配一定的时间间隔,使个任务轮流享有CPU).</font>
				</p>
				<h4 class="EntityTitle">
						<a name="83915">
								<font class="sans" face="Helvetica, sans-serif" size="-1">Round-Robin Scheduling</font>
						</a>
				</h4>
				<p style="LINE-HEIGHT: 150%"> </p>
				<font lang="ZH-CN" face="System">
						<p style="LINE-HEIGHT: 150%">系统由256个优先级,从0到255,0为最高,255为最低. 任务在被创建时设定了优先级.也可用<big><b><font size="4"><i>taskPrioritySet</i>  ( )</font></b></big> 来改变任务优先级.</p>
						<p style="LINE-HEIGHT: 150%">任务的主要状态: READY,PEND,DELAY,SUSPEND...</p>
				</font>
		</blockquote>
		<dir>
				<dir>
						<blockquote>
								<pre class="Code" style="LINE-HEIGHT: 100%">
										<big>
												<span class="Code">
														<font lang="ZH-CN">
																<font size="4">
																		<b>
																		</b>
																</font>
														</font>
												</span>
										</big>
										<big>
												<font lang="ZH-CN">
												</font>
										</big>　</pre>
						</blockquote>
						<font lang="ZH-CN" face="System">
								<strong>
										<blockquote>
												<p style="LINE-HEIGHT: 150%">轮转调度</p>
										</blockquote>
								</strong>
						</font>
						<font face="宋体, MS Song">
						</font>
						<font lang="ZH-CN" face="System">(Round-Robin): 轮转调度可以扩充到优先抢占方式中,当多个任务优先级相同的情况下,轮转调度算法使任务按平等的时间片运行于CPU,共享CPU.避免一个任务长时间占用CPU,而导致其他任务不能运行.可以用</font>
						<font face="宋体, MS Song">
						</font>
						<font lang="ZH-CN" face="System">
								<b>
										<i>kernelTimeSlice</i>(　)</b> 来定义时间长度.<b><i><blockquote><p style="LINE-HEIGHT: 150%">taskLock</p></blockquote></i>  ( )</b>和</font>
						<font face="宋体, MS Song">
						</font>
						<font lang="ZH-CN" face="System">
								<b>
										<i>taskUnlock</i> ( )</b> 用来取消优先抢占方式</font>
						<font face="宋体, MS Song">
						</font>
						<font lang="ZH-CN" face="System">和恢复优先抢占方式.
<blockquote><p style="LINE-HEIGHT: 150%">注意: 一个任务可以调用<b><i>taskDelete</i> ( )</b> 删除另一个任务,但是如果一个当前正在运行的任务被删除后,该任务的内存没有释放,而其他任务不知道,依然在等待,结果导致系统stop.用</p></blockquote></font>
						<font face="宋体, MS Song">
						</font>
						<font lang="ZH-CN" face="System">
								<b>
										<i>taskSafe</i> ( )</b> 和</font>
						<font face="宋体, MS Song">
						</font>
						<font lang="ZH-CN" face="System">
								<b>
										<i>taskUnsafe</i> ( )</b> 来保证正在运行的任务不被删除.
<blockquote><p style="LINE-HEIGHT: 150%">用法如下:</p></blockquote></font>
						<b>
								<font face="Courier New">
										<p style="LINE-HEIGHT: 150%">taskSafe (); <br />semTake (semId, WAIT_FOREVER);<br />/* Block until semaphore available */ <br />. .</p>
								</font>
								<font lang="ZH-CN" face="System">　</font>
								<font face="Courier New">. .</font>
								<font lang="ZH-CN" face="System">　</font>
								<font face="Courier New">
										<i>critical region </i>. <br />semGive (semId);</font>
								<font lang="ZH-CN" face="System">　</font>
								<font face="Courier New">semGive (semId);</font>
								<font lang="ZH-CN" face="System">　　<br /></font>
								<font face="Courier New">/* Release semaphore */ <br /><a name="BM84245">taskUnsafe ();</a></font>
								<p style="LINE-HEIGHT: 150%">　</p>
						</b>
				</dir>
		</dir>
		<ul>
				<li>
						<p style="LINE-HEIGHT: 150%">
								<big>
										<big>
												<font size="5">
														<strong>
																<font lang="ZH-CN">任务间的同步和进程间协调</font>
														</strong>
												</font>
										</big>
								</big>
						</p>
				</li>
		</ul>
		<font lang="ZH-CN" face="System">
				<blockquote>
						<p style="LINE-HEIGHT: 150%">信号量作为任务间同步和互斥的机制。在</p>
				</blockquote>
		</font>
		<font face="宋体, MS Song">
		</font>
		<font lang="ZH-CN" face="System">wind 核中有几种类型的信号量，它们分别针对不同的应用需求：二进制信号量、计数信号量、互斥信号量和</font>
		<font face="宋体, MS Song">
		</font>
		<font lang="ZH-CN" face="System">POSIX 信号量。所有的这些信号量是快速和高效的，它们除了被应用在开发设计过程中外，还被广泛地应用在VxWorks 高层应用系统中。对于进程间通信，wind 核也提供了诸如消息队列、管道、套接字和信号等机制。</font>
		<font face="宋体, MS Song">
		</font>
		<font lang="ZH-CN" face="System">
				<blockquote>
						<p style="LINE-HEIGHT: 150%">任务间的同步和进程间协调的几种方式:</p>
				</blockquote>
				<ol>
						<ol>
								<li>
										<p style="LINE-HEIGHT: 150%">内存共享(Shared Memory),对简单的数据共享而言. </p>
								</li>
								<li>
										<p style="LINE-HEIGHT: 150%">信号量(Semaphore),基本的互斥和同步. </p>
								</li>
								<li>
										<p style="LINE-HEIGHT: 150%">消息队列(Message queues)和管道(Pipe),单个CPU中,任务间的信息传递. </p>
								</li>
								<li>
										<p style="LINE-HEIGHT: 150%">套结字(Socket)和远程调用(Remote procedure calls),相对于网络任务间的通信. </p>
								</li>
								<li>
										<p style="LINE-HEIGHT: 150%">信号(Signals),出错处理(Exception handling). </p>
								</li>
						</ol>
				</ol>
		</font>
		<p style="LINE-HEIGHT: 150%">　</p>
		<p style="LINE-HEIGHT: 150%">     <b><font face="宋体"><font lang="ZH-CN">内存共享(Shared Memory)</font></font></b>   <font lang="ZH-CN" face="宋体"><b>      </b></font></p>
		<blockquote>
				<blockquote>
						<p style="LINE-HEIGHT: 150%">
								<font lang="ZH-CN" face="宋体">任务间通信最通常的方式是通过共享的数据结构进行通信,因为所有VxWorks的任务存在于一个单一的线性地址空间，<span style="FONT-SIZE: 12pt; FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">任务间共享数据。全局变量、线性队列、环形队列、链表、指针都可被运行在不同上下文的代码所指向。</span></font>
						</p>
						<h4 class="EntityTitle">
								<a name="84955">
										<font class="sans" face="Helvetica, sans-serif" size="-1">Shared Data Structures</font>
								</a>
						</h4>
						<dl class="margin">
								<div class="Anchor">
										<a name="84952">
										</a>
								</div>
						</dl>
						<p style="LINE-HEIGHT: 150%">　</p>
				</blockquote>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="宋体" size="4">
								<strong>互斥</strong>
						</font>
						<font lang="ZH-CN" face="System" size="4">
								<b>(Mutual Exclusion)</b>
						</font>
				</p>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="System">互斥是用来控制多任务对共享数据进行串行访问的同步机制。在多任务应用中，当两个或多个任务同时访问共享数据时，可能会造成数据破坏。互斥使它们串行地访问数据，从而达到保护数据的目的.</font>
				</p>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="System">解决互斥的几种方法:</font>
				</p>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="System">1. 关闭中断的方法(intLock): 能解决任务和中断ISR之间产生的互斥. </font>
				</p>
				<blockquote>
						<pre class="Code" style="LINE-HEIGHT: 100%">
						</pre>
						<p style="LINE-HEIGHT: 150%">
								<font lang="ZH-CN" face="System">但在实时系统中采取这个办法会影响系统对外部中断及时响应和处理的能力.</font>
						</p>
				</blockquote>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="System">2. 关闭系统优先级(taskLock): 关闭系统优先级,这样在当前任务执行时,除了中断外,不会有其他优先级高的任务来抢占CPU,影响当前程序运行. </font>
				</p>
				<blockquote>
						<b>
								<a name="84977">
										<p style="LINE-HEIGHT: 100%">funcA () </p>
								</a>
						</b>
						<p style="LINE-HEIGHT: 100%">
								<b>
										<a name="84977">{ taskLock ();</a>
								</b>
						</p>
						<p style="LINE-HEIGHT: 100%">
								<b>
										<a name="84977">. .  <i class="i">critical region that cannot be interrupted </i>.</a>
								</b>
						</p>
						<p style="LINE-HEIGHT: 100%">
								<b>
										<a name="84977">taskUnlock (); }</a>
								</b>
						</p>
				</blockquote>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" face="System">这种方法阻止了高优先级的任务抢先运行,在实时系统中也是不适合的,除非关闭优先级的时间特别短.</font>
				</p>
		</blockquote>
		<p style="LINE-HEIGHT: 150%">
				<font lang="ZH-CN" face="System">
				</font>
		</p>
		<blockquote>
				<p style="LINE-HEIGHT: 150%">
						<font lang="ZH-CN" size="4">
								<b>
										<font face="宋体">信号量</font>
								</b>
								<font face="System">
										<strong>(Semaphore):</strong>
								</font>
						</font>
						<font lang="ZH-CN" face="System">信号量是</font>
						<font lang="ZH-CN">解决<strong>互斥</strong></font>
						<font lang="ZH-CN" face="System">和</font>
						<strong>
								<font lang="ZH-CN">同步协调进程</font>
						</strong>
						<font lang="ZH-CN" face="System">最好的方法</font>
				</p>
				<blockquote>
						<p class="ae" style="LINE-HEIGHT: 150%; tab-stops: 18.0pt">
								<span lang="EN-US" style="FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Times New Roman'">VxWorks</span>
								<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">信号量提供最快速的任务间通信机制，它主要用于解决任务间的互斥和同步。针对不同类型的问题，有以下三种信号量：</span>
								<span lang="EN-US" style="FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Times New Roman'">
										<?XML:NAMESPACE PREFIX = O /?>
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="ae" style="MARGIN-LEFT: 0cm; TEXT-INDENT: 0cm; LINE-HEIGHT: 150%; tab-stops: 18.0pt; mso-list: l28 level1 lfo23">
								<span lang="EN-US" style="FONT-FAMILY: Wingdings">Ÿ<span style="FONT: 7pt 'Times New Roman'">         </span></span>
								<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">二进制信号量<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">（</span><span lang="EN-US"><span style="mso-tab-count: 1"><i class="term">binary)</i></span>使用最快捷、最广泛，主要用于同步或互斥；</span></span>
								<span lang="EN-US" style="FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Times New Roman'">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="ae" style="MARGIN-LEFT: 0cm; TEXT-INDENT: 0cm; LINE-HEIGHT: 150%; tab-stops: 18.0pt; mso-list: l55 level1 lfo24">
								<span lang="EN-US" style="FONT-FAMILY: Wingdings">Ÿ<span style="FONT: 7pt 'Times New Roman'">         </span></span>
								<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">互斥信号量<span lang="EN-US"><span style="mso-tab-count: 2">(<i class="term">mutual exclusion</i>)  </span><span style="mso-tab-count: 2">特殊的</span></span>二进制信号量，<span lang="EN-US">主要用于优先级继承、安全删除和回溯；</span></span>
								<span lang="EN-US" style="FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Times New Roman'">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="ae" style="MARGIN-LEFT: 0cm; TEXT-INDENT: 0cm; LINE-HEIGHT: 150%; tab-stops: 18.0pt; mso-list: l8 level1 lfo25">
								<span lang="EN-US" style="FONT-FAMILY: Wingdings">Ÿ<span style="FONT: 7pt 'Times New Roman'">         </span></span>
								<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">计数器信号量(counting) 和二进制信号量类似，保持信号量被释放（gaven)的次数</span>
								<span lang="EN-US" style="FONT-FAMILY: 'Courier New'; mso-bidi-font-family: 'Times New Roman'">
										<o:p>
										</o:p>,主要用于保护一个资源的多个例程（multiple instances of a resource）</span>
						</p>
						<p style="LINE-HEIGHT: 150%">
								<b>
										<font lang="ZH-CN" face="宋体">信号量控制，函数介绍:</font>
								</b>
						</p>
						<blockquote>
								<p style="LINE-HEIGHT: 150%">
										<b class="routine">
												<i class="routine">semBCreate</i>
										</b>
										<b>( ) </b>分配并初始化一个<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">二进制信号量</span></p>
								<p style="LINE-HEIGHT: 150%">
										<b class="routine">
												<i class="routine">semMCreate</i>
										</b>
										<b>( ) </b>分配并初始化一个互斥<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">信号量</span></p>
								<p style="LINE-HEIGHT: 150%">
										<b class="routine">
												<i class="routine">semCCreate</i>
										</b>
										<b>( ) </b>分配并初始化一个<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">计数信号量</span></p>
								<p style="LINE-HEIGHT: 150%">
										<b class="routine">
												<i class="routine">semDelete</i>
										</b>
										<b>( ) </b>终止一个自由的信号量</p>
								<p style="LINE-HEIGHT: 150%">
										<b class="routine">
												<i class="routine">emTake</i>
										</b>
										<b>( ) </b>占有一个信号量</p>
								<p style="LINE-HEIGHT: 150%">
										<b class="routine">
												<i class="routine">semGive</i>
										</b>
										<b>( ) </b>释放一个信号量</p>
								<p style="LINE-HEIGHT: 150%">
										<b class="routine">
												<i class="routine">semFlush</i>
										</b>
										<b>( ) </b>解锁所有等待信号量的任务</p>
								<p style="LINE-HEIGHT: 150%">
										<b class="routine">
												<i class="routine">semBCreate</i>
										</b>
										<b>( )</b>, <b class="routine"><i class="routine">semMCreate</i></b><b>( )</b>, and <b class="routine"><i class="routine">semCCreate</i></b><b>( )</b>返回一个信号量<b>ID</b>作为其它后续任务使用该信号量的的句柄。当一个信号量被创建，它的队列（queue)类型就被确定。等待信号量的任务队列以优先级的高低排列(<b class="symbol_UC">SEM_Q_PRIORITY</b>)，或者一先到先得的方式排列<b>（SEM_Q_FIFO).</b></p>
								<ul>
										<li>
												<p style="LINE-HEIGHT: 150%">
														<font lang="ZH-CN" face="System">当一个Semaphore创建时,指定了任务队列的种类</font>
												</p>
										</li>
								</ul>
								<ol type="A">
										<li>
												<p style="LINE-HEIGHT: 150%">
														<font lang="ZH-CN" face="System">semBCreat( SEM_Q_PRIORITY, SEM_FULL),   SEM_Q_PRIORITY 指明处于等待状态的任务在等待队列中以优先级的顺序排列</font>
												</p>
										</li>
										<li>
												<p style="LINE-HEIGHT: 150%">
														<font lang="ZH-CN" face="System">semBCreat(SEM_Q_FIFO,SEM_FULL),   SEM_Q_FIFO指明 处于等待状态的任务在等待队列中以先进先出的顺序排列</font>
												</p>
										</li>
								</ol>
								<p style="LINE-HEIGHT: 150%">
										<b class="symbol_UC">                        </b>
								</p>
						</blockquote>
						<ol>
								<li>
										<p style="LINE-HEIGHT: 150%">
												<font face="宋体">
														<b>
																<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">二进制信号量<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">（</span><span lang="EN-US" style="mso-tab-count: 1"><i class="term">binary)</i></span></span>
																<font lang="ZH-CN"> </font>
														</b>
												</font>
										</p>
								</li>
						</ol>
						<div class="frame">
								<h4 class="EntityTitle">
										<a name="90612">
												<font class="sans" face="Helvetica, sans-serif" size="-1">Taking a Semaphore</font>
										</a>
								</h4>
						</div>
						<div class="frame">
								<h4 class="EntityTitle">
										<a name="90676">
												<font class="sans" face="Helvetica, sans-serif" size="-1"> Giving a Semaphore</font>
										</a>
								</h4>
						</div>
						<p style="LINE-HEIGHT: 150%"> </p>
						<blockquote>
								<p style="LINE-HEIGHT: 150%">
										<font lang="ZH-CN">
												<strong>互斥进程<i>（<a name="85180">Mutual Exclusion</a>）</i></strong>
										</font>
								</p>
								<p style="LINE-HEIGHT: 150%">
										<font lang="ZH-CN">互斥</font>
										<font face="宋体">
												<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">信号量<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">有效的内锁对共享资源的进入，与屏蔽中断(disabling interrupts)和优先级锁定（preemptive locks）相比，</span></span>
										</font>
										<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">二进制信号量将互斥的范围限制在仅与其有关的资源上。从技术上说，创建一个信号量来保护(guarding)资源。信号量初始化位可用的（FULL）</span>
										<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">。</span>
								</p>
								<p style="LINE-HEIGHT: 150%">
										<font lang="ZH-CN" face="System">当一个Semaphore创建时,指定了这个semaphore是用在解决互斥还是用来同步任务</font>
								</p>
								<ol type="A">
										<li>
												<p style="LINE-HEIGHT: 150%">
														<font lang="ZH-CN" face="System">semBCreat( SEM_Q_FIFO, SEM_FULL) ,  SEM_FULL 指明用于任务间互斥.</font>
												</p>
										</li>
								</ol>
								<blockquote>
										<a name="85183">
												<b>
														<p style="LINE-HEIGHT: 150%">SEM_ID semMutex;</p>
												</b>
										</a>
										<p style="LINE-HEIGHT: 150%">
												<a name="85183">
														<b>semMutex = semBCreate (SEM_Q_PRIORITY, SEM_FULL);</b>
												</a>
										</p>
										<p style="LINE-HEIGHT: 150%">   <font lang="ZH-CN" face="System"> 当一个任务要进入资源，首先要得到一个信号量（take that semaphore），只要有任务在使用这个信号量，其它的要进入资源的任务要停止执行（blocked from execution），当这个任务完成了对资源的使用，它会释放信号量，允许另一个任务来使用资源。</font></p>
										<b>
												<a name="85194">
														<p style="LINE-HEIGHT: 150%">semTake (semMutex, WAIT_FOREVER);</p>
												</a>
										</b>
										<p style="LINE-HEIGHT: 150%">
												<b>
														<a name="85194">. .  <i class="i">critical region, only accessible by a single task at a time</i> . </a>
												</b>
										</p>
										<p style="LINE-HEIGHT: 150%">
												<b>
														<a name="85194">semGive (semMutex);</a>
												</b>
										</p>
								</blockquote>
								<p style="LINE-HEIGHT: 150%">　</p>
								<p style="LINE-HEIGHT: 150%">
										<strong>
												<font lang="ZH-CN">同步协调进程<i>（<a name="85199">Synchronization</a>）</i></font>
										</strong>   <strong><font lang="ZH-CN"> </font></strong></p>
						</blockquote>
						<blockquote>
								<blockquote>
										<ol type="A" start="2">
												<li>
														<p style="LINE-HEIGHT: 150%">
																<font lang="ZH-CN" face="System">semBCreat(SEM_Q_FIFO,SEM_EMPTY),  SEM_EMPTY 指明用于任务间同步.</font>
														</p>
												</li>
										</ol>
								</blockquote>
						</blockquote>
						<blockquote>
								<blockquote>
										<blockquote>
												<pre class="Code" style="LINE-HEIGHT: 100%">
														<big>
														</big>
												</pre>
										</blockquote>
								</blockquote>
						</blockquote>
						<font lang="ZH-CN" face="System">
								<p style="LINE-HEIGHT: 150%">       semTake(semID,time out)--------有Semaphore空闲,就Take, 如果没有,由time out 定,超时则向下执行</p>
						</font>
				</blockquote>
		</blockquote>
		<p style="LINE-HEIGHT: 150%">　</p>
		<blockquote>
				<blockquote>
						<ol start="2">
								<li>
										<p style="LINE-HEIGHT: 150%">
												<font face="宋体">
														<b>
																<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">互斥信号量</span>
														</b>
												</font>
										</p>
								</li>
						</ol>
						<blockquote>
								<p style="LINE-HEIGHT: 150%">
										<font face="宋体">
												<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">互斥信号量是一个特殊的</span>
												<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">二进制信号量，设计用于优先级继承，安全删除和回归。</span>
										</font>
								</p>
								<p style="LINE-HEIGHT: 150%">
										<font face="宋体">
												<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">互斥信号量的使用基本和</span>
												<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: 'Times New Roman'">二进制信号量是类似的。但有以下不同：</span>
										</font>
								</p>
								<ul>
										<li>
												<p style="LINE-HEIGHT: 150%">
														<font face="宋体">
																<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">仅仅被用做互斥。</span>
														</font>
												</p>
										</li>
										<li>
												<p style="LINE-HEIGHT: 150%">
														<font face="宋体">
																<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">只能被使用它的任务释放.(It can be given only by the task that took it.)</span>
														</font>
												</p>
										</li>
										<li>
												<p style="LINE-HEIGHT: 150%">
														<font face="宋体">
																<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">ISR 不能释放它。</span>
														</font>
												</p>
										</li>
										<li>
												<p style="LINE-HEIGHT: 150%">
														<font face="宋体">
																<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman">不能使用函数<i class="routine"><b class="routine">semFlush</b></i><b>( )</b>。</span>
														</font>
												</p>
										</li>
								</ul>
						</blockquote>
				</blockquote>
				<font lang="ZH-CN" face="System">
						<p style="LINE-HEIGHT: 150%">
						</p>
						<blockquote>
								<blockquote>
										<p style="LINE-HEIGHT: 150%">
												<strong>
														<font lang="ZH-CN" face="宋体" size="4">优先级反转</font>(Priority Inversion) </strong>
										</p>
										<blockquote>
												<p style="LINE-HEIGHT: 150%">优先级反转是指一个任务等待比它优先级低的任务释放资源而被阻塞，如果这时有中等优先级的就绪任务，阻塞会进一步恶化。优先级继承技术可用来解决优先级反转问题。 </p>
												<dl class="margin">
														<div class="Anchor">
																<a name="91094">
																</a>
														</div>
												</dl>
												<p style="LINE-HEIGHT: 150%">　 </p>
										</blockquote>
										<blockquote>
												<p style="LINE-HEIGHT: 150%">
														<font size="3">Priority </font>inversion arises when a higher-priority task is forced to wait an indefinite period of time for a lower-priority task to complete.</p>
										</blockquote>
								</blockquote>
						</blockquote>
				</font>
				<p style="LINE-HEIGHT: 150%">
						<strong>
								<font lang="ZH-CN" face="宋体" size="4">优先级继承</font>
								<font lang="ZH-CN" face="System">(Priority Inheritance)</font>
						</strong>
				</p>
				<font lang="ZH-CN" face="System">
						<blockquote>
								<p style="LINE-HEIGHT: 150%">优先级继承可用来解决优先级反转问题。当优先级反转发生时，优先级较低的任务被暂时地提高它的优先级，使得该任务能尽快执行，释放出优先级较高的任务所需要的资源。</p>
								<h4 class="EntityTitle">
										<a name="91101">
												<font class="sans" face="Helvetica, sans-serif" size="-1">Priority Inheritance</font>
										</a>
								</h4>
								<dl class="margin">
										<div class="Anchor">
												<a name="91135">
												</a>
										</div>
								</dl>
								<p style="LINE-HEIGHT: 150%">　</p>
						</blockquote>
						<blockquote>
								<p style="LINE-HEIGHT: 150%">The mutual-exclusion semaphore has the option SEM_INVERSION_SAFE, which enables a priority-inheritance algorithm. The priority-inheritance protocol assures that a task that owns a resource executes at the priority of the highest-priority task blocked on that resource. Once the task priority has been elevated, it remains at the higher level until all mutual-exclusion semaphores that the task owns are released; then the task returns to its normal, or standard, priority. Hence, the "inheriting" task is protected from preemption by any intermediate-priority tasks. This option must be used in conjunction with a priority queue (SEM_Q_PRIORITY).</p>
						</blockquote>
				</font>
		</blockquote>
		<p style="LINE-HEIGHT: 150%">
		</p>
		<ol start="3">
				<li>
						<p style="LINE-HEIGHT: 150%">
								<b>计数信号量</b>
								<i>
										<b>（<a name="85413">Counting Semaphores</a>）</b>
								</i>
						</p>
				</li>
		</ol>
		<blockquote>
				<p style="LINE-HEIGHT: 150%">计数信号量是任务同步和互斥的另一种实现方式.计数信号量除了保留信号量被释放的次数以外和二进制信号量是一样的。每次信号量被释放（gaven)一次，计数增加；每次信号量被占用（taken)一次，计数减少;当计数减少为0时，要求得到信号量的任务被阻塞（blocked)。二进制信号量是如果一个信号量被释放，有一个任务阻塞等待，则这个任务就被unblock.而计数信号量如果一个信号量被释放，没有任务阻塞等待，则计数增加。这说明一个被释放两次的计数信号量可以被占用(taken)两次,没有阻塞。</p>
				<p style="LINE-HEIGHT: 150%">
						<a name="85488">
						</a>Counting semaphores are useful for guarding multiple copies of resources. For example, the use of five tape drives might be coordinated using a counting semaphore with an initial count of 5, or a ring buffer with 256 entries might be implemented using a counting semaphore with an initial count of 256. The initial count is specified as an argument to the <b class="routine"><i class="routine">semCCreate</i></b><b>( )</b> routine.</p>
		</blockquote>
		<h4 class="EntityTitle" align="left">
				<a name="91146">
						<font class="sans" face="Helvetica, sans-serif" size="-1">Counting Semaphore Example</font>
				</a>
		</h4>
		<table cellspacing="0" cellpadding="0" border="0">
				<tbody>
						<tr>
								<td colspan="20">
										<hr class="tablerule" />
								</td>
						</tr>
						<tr valign="center">
								<th>
										<div class="CellHeading">
												<p align="left">
														<b>
																<a name="91152">
																</a>
																<font class="sans" face="Helvetica, sans-serif" size="-1">Semaphore Call</font>
														</b>
												</p>
										</div>
								</th>
								<th>
										<div class="CellHeadingC" align="center">
												<p align="left">
														<a name="91154">
														</a>
														<b>
																<font class="sans" face="Helvetica, sans-serif" size="-1">Count after Call</font>
														</b>
												</p>
										</div>
								</th>
								<th>
										<div class="CellHeading">
												<p align="left">
														<b>
																<a name="91156">
																</a>
																<font class="sans" face="Helvetica, sans-serif" size="-1">Resulting Behavior</font>
														</b>
												</p>
										</div>
								</th>
						</tr>
						<tr>
								<td colspan="20">
										<hr class="tablerule2" />
								</td>
						</tr>
						<tr valign="top">
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91158">
														</a>
														<b class="routine">
																<i class="routine">semCCreate</i>
														</b>
														<b>( )</b>   </p>
										</div>
								</td>
								<td>
										<div class="CellBodyC" align="center">
												<p align="left">
														<a name="91160">
														</a>3 </p>
										</div>
								</td>
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91162">
														</a>Semaphore initialized with initial count of 3.  </p>
										</div>
								</td>
						</tr>
						<tr valign="top">
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91164">
														</a>
														<b class="routine">
																<i class="routine">semTake</i>
														</b>
														<b>( )</b>  </p>
										</div>
								</td>
								<td>
										<div class="CellBodyC" align="center">
												<p align="left">
														<a name="91166">
														</a>2 </p>
										</div>
								</td>
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91168">
														</a>Semaphore taken.  </p>
										</div>
								</td>
						</tr>
						<tr valign="top">
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91170">
														</a>
														<b class="routine">
																<i class="routine">semTake</i>
														</b>
														<b>( )</b>  </p>
										</div>
								</td>
								<td>
										<div class="CellBodyC" align="center">
												<p align="left">
														<a name="91172">
														</a>1 </p>
										</div>
								</td>
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91174">
														</a>Semaphore taken.  </p>
										</div>
								</td>
						</tr>
						<tr valign="top">
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91176">
														</a>
														<b class="routine">
																<i class="routine">semTake</i>
														</b>
														<b>( )</b>  </p>
										</div>
								</td>
								<td>
										<div class="CellBodyC" align="center">
												<p align="left">
														<a name="91178">
														</a>0 </p>
										</div>
								</td>
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91180">
														</a>Semaphore taken.  </p>
										</div>
								</td>
						</tr>
						<tr valign="top">
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91182">
														</a>
														<b class="routine">
																<i class="routine">semTake</i>
														</b>
														<b>( )</b>  </p>
										</div>
								</td>
								<td>
										<div class="CellBodyC" align="center">
												<p align="left">
														<a name="91184">
														</a>0 </p>
										</div>
								</td>
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91186">
														</a>Task blocks waiting for semaphore to be available.  </p>
										</div>
								</td>
						</tr>
						<tr valign="top">
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91188">
														</a>
														<b class="routine">
																<i class="routine">semGive</i>
														</b>
														<b>( )</b>  </p>
										</div>
								</td>
								<td>
										<div class="CellBodyC" align="center">
												<p align="left">
														<a name="91190">
														</a>0 </p>
										</div>
								</td>
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91192">
														</a>Task waiting is given semaphore.  </p>
										</div>
								</td>
						</tr>
						<tr valign="top">
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91194">
														</a>
														<b class="routine">
																<i class="routine">semGive</i>
														</b>
														<b>( )</b>  </p>
										</div>
								</td>
								<td>
										<div class="CellBodyC" align="center">
												<p align="left">
														<a name="91196">
														</a>1 </p>
										</div>
								</td>
								<td>
										<div class="CellBody">
												<p align="left">
														<a name="91198">
														</a>No task waiting for semaphore; count incremented.  </p>
										</div>
								</td>
						</tr>
						<tr>
								<td colspan="20">
										<hr class="tablerule" />
								</td>
						</tr>
						<tr valign="center">
								<td colspan="20">
										<p align="left">
										</p>
								</td>
						</tr>
				</tbody>
		</table>
		<p style="LINE-HEIGHT: 150%">
				<font lang="ZH-CN" face="System">        </font>
		</p>
		<font lang="ZH-CN" face="宋体" size="4">
				<b>消息队列(Message queues)</b>
		</font>
		<blockquote>
				<blockquote>
						<p style="LINE-HEIGHT: 150%">
								<font size="3">
										<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">现实的实时应用由一系列互相独立又协同工作的任务组成。信号量为任务间同步和联锁提供了高效机制。在VxWorks中，用于但一CPU任务之间通信主要（primary）的机制是消息队列。</span>
								</font>
						</p>
						<h4 class="EntityTitle">
								<a name="85857">
										<font class="sans" face="Helvetica, sans-serif" size="-1">Full Duplex Communication Using Message Queues</font>
								</a>
						</h4>
						<dl class="margin">
								<div class="Anchor">
										<a name="85854">
										</a>
								</div>
						</dl>
						<p style="LINE-HEIGHT: 150%">　</p>
						<p style="LINE-HEIGHT: 150%">
								<font size="3">
										<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">消息队列允许一定数量不同长度的消息进行排列。任何任务或中断服务程序(ISR)能够发送消息给消息队列。任何任务可以从消息队列接受消息。多任务可以从同意消息队列发送和接受消息。两个任务之间的全双工（Full-duplex）通信需要针对不同方向的两个消息队列。</span>
								</font>
						</p>
						<p style="LINE-HEIGHT: 150%">
								<b>
										<font lang="ZH-CN" face="宋体">消息队列函数介绍</font>
								</b>
								<font lang="ZH-CN" face="System">    </font>
						</p>
						<p style="LINE-HEIGHT: 150%">
								<b class="routine">
										<i class="routine">msgQCreate</i>
								</b>
								<b>( )  </b>创建斌初始化一个消息队列</p>
						<p style="LINE-HEIGHT: 150%">
								<b class="routine">
										<i class="routine">msgQDelete</i>
								</b>
								<b>( ) </b>终止并释放一个消息队列</p>
						<p style="LINE-HEIGHT: 150%">
								<b class="routine">
										<i class="routine">msgQSend</i>
								</b>
								<b>( )</b>  发送一个消息到消息队列</p>
						<p style="LINE-HEIGHT: 150%">
								<b class="routine">
										<i class="routine">msgQReceive</i>
								</b>
								<b>( ) </b>从消息队列接受一个消息</p>
						<p style="LINE-HEIGHT: 150%">消息队列是由函数<font face="宋体"><b>msgQCreate (MAX_MSGS, MAX_MSG_LEN, MSG_Q_PRIORITY)</b></font>创建。它的参数<font face="宋体"><b>MAX_MSGS</b></font>指定了消息队列中可允许最多可以排列的消息数和每个消息允许的最大的字节数<font face="宋体"><b>MAX_MSG_LEN</b></font>。</p>
						<p style="LINE-HEIGHT: 150%">一个任务或中断服务程序(ISR)用函数<b class="routine"><i class="routine">msgQSend</i></b><b>( )</b>发送一个消息到消息队列。如果没有任务等待消息队列的消息，这个消息被添加消息缓存的队列里。如果某些任务已经在等待消息队列中的消息，消息立刻被传递给第一个等待的消息的任务。</p>
						<p style="LINE-HEIGHT: 150%">一个任务用函数<b class="routine"><i class="routine">msgQReceive</i></b><b>( )</b>从消息队列得到一个消息。如果消息队列缓存中有消息存在，第一个消息立刻出列并回到调用处(caller).如果没有消息存在，则任务（calling task）停止（blocks)并被添加到等待消息的任务队列中。这个等待的任务队列按照优先级或先进先出（FIFO)规则排列，这个规则有消息队列创建时所指定。</p>
						<p style="LINE-HEIGHT: 150%">
								<b>等待时间限制（time out)</b>
						</p>
						<p style="LINE-HEIGHT: 150%">
								<b class="routine">
										<i class="routine">msgQSend</i>
								</b>
								<b>( )</b> 和 <b class="routine"><i class="routine">msgQReceive</i></b><b>( )</b>都有时间限制参数。当发送一个消息，如果消息队列缓存这时没有空间，这个参数指定允许等待的时间（ticks数），直到队列缓存有空间来接收消息。当接收消息时，如果消息队列没有消息，这个参数指定允许等待的时间（ticks数），直到消息队列有消息。</p>
						<p style="LINE-HEIGHT: 150%">　</p>
				</blockquote>
				<p style="LINE-HEIGHT: 150%">
						<b>
								<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">
										<font size="4">管道（<i><a name="86337">Pipes</a>）</i></font>
								</span>
						</b>
				</p>
				<blockquote>
						<p style="LINE-HEIGHT: 150%">
								<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">
										<font size="4">管道对消息队列提供了一个可供选择的接口，</font>
								</span>
								<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">
										<font size="4">
												<span lang="EN-US" style="FONT-FAMILY: Courier New; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">VxWorks</span>的<span lang="EN-US" style="FONT-FAMILY: Courier New; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 宋体">I/O</span>系统。管道是虚拟的I/O设备，由驱动<b class="library">pipeDrv</b>管理。函数<i class="routine"><b class="routine">pipeDevCreate</b></i><b>()</b>创建一个管道设备，这个调用指定管道的名字，能被排列的最多的消息数，和每个消息允许的长度。</font>
								</span>
						</p>
						<p style="LINE-HEIGHT: 150%">
								<b>
										<a name="86340">
												<i class="textVariable">status</i> = pipeDevCreate ("<i class="textVariable">/pipe/name</i>", <i class="textVariable">max_msgs</i>, <i class="textVariable">max_length</i>);</a>
								</b>
						</p>
						<p style="LINE-HEIGHT: 150%">被创建的管道是一个通常命名（named)的I/O设备,任务能用标准的I/O函数打开，读，写管道，并能调用ioctl例程。<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA"><font size="4">当任务试图从一个空的管道中读取数据，或向一个满的管道中写入数据时，任务被阻塞。和消息队列一样，ISR可以向管道写入，但不能从管道读取。</font></span></p>
						<p style="LINE-HEIGHT: 150%">
								<font size="4">
										<span style="FONT-FAMILY: 宋体; mso-hansi-font-family: Times New Roman; mso-bidi-font-size: 10.0pt; mso-bidi-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA">做为I/O设备，管道提供了消息队列所没有的重要特性，调用<i><b>select()</b></i></span>
								</font>
						</p>
				</blockquote>
		</blockquote>
		<br />
<img src ="http://www.cnitblog.com/guopingleee/aggbug/30188.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/guopingleee/" target="_blank">向左向右走</a> 2007-07-18 17:17 <a href="http://www.cnitblog.com/guopingleee/archive/2007/07/18/30188.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>