建设一个机械公司网站多少钱1688官网首页
web/
2025/10/7 21:57:45/
文章来源:
建设一个机械公司网站多少钱,1688官网首页,求个网站带图片素材,如何做网页设计视频播放中断处理是整个运行系统中优先级最高的代码#xff0c;可以抢占任何任务级代码运行。中断机制是多任务环境运行的基础#xff0c;是系统实时性的保证。几乎所有的实时多任务操作系统都需要一个周期性系统时钟中断的支持#xff0c;用以完成时间片调度和延时处理。VxWorks 提…中断处理是整个运行系统中优先级最高的代码可以抢占任何任务级代码运行。中断机制是多任务环境运行的基础是系统实时性的保证。几乎所有的实时多任务操作系统都需要一个周期性系统时钟中断的支持用以完成时间片调度和延时处理。VxWorks 提供tickAnnounce()由系统时钟中断调用周期性地触发内核。 为了快速响应中断VxWorks的中断服务程序ISR运行在特定的空间。不同于一般的任务中断服务程序没有任务上下文不包含任务控制块所有的中断服务程序使用同一中断堆栈它在系统启动时就已根据具体的配置参数进行了分配和初始化。在ISR中能使用的函数类型与在一般任务中能使用的有些不同主要体现在 1ISR中不能调用可能导致blocking的函数例如 (a)不能以semTake获取信号量因如果该信号量不可利用内核会试图让调用者切换到blocking态 (b)malloc和free可能导致blocking因此也不能使用 (c)应避免进行VxWorks I/O系统操作除管道外 (d)应避免在ISR中进行浮点操作。 2在ISR中应以logMsg打印消息避免使用printf 3理想的ISR仅仅调用semGive等函数其它的事情交给semTake这个信号量的任务去做。一个ISR通常作为通信或同步的发起者它采用发送信号量或向消息队列发送一个消息的方式触发相关任务至就绪态。ISR几乎不能作为信息的接收者它不可以等待接收消息或信号量。 11.中断服务程序 VxWorks中与中断相关的重要API函数或宏有 1intConnect()中断连接将中断向量与ISR入口函数绑定
SYNOPSIS STATUS intConnect ( VOIDFUNCPTR * vector,/* interrupt vector to attach to */ VOIDFUNCPTR routine, /* routine to be called */ int parameter /* parameter to be passed to routine */ );
intConnect只是调用了下文将要介绍的intHandlerCreate()和intVecSet()函数。 2INUM_TO_IVEC(intNum)将中断号转化为中断向量的宏。与INUM_TO_IVEC对应的还有一个IVEC_TO_INUM(intVec)实现相反的过程。INUM_TO_IVEC和IVEC_TO_INUM的具体定义与特定的BSP有关例如
/* macros to convert interrupt vectors - interrupt numbers */ #define IVEC_TO_INUM(intVec) ((int) (intVec)) #define INUM_TO_IVEC(intNum) ((VOIDFUNCPTR *) (intNum)) 结合1、2可知一般挂接一个中断服务程序的调用为
intConnect(INUM_TO_IVEC(INTERRUPT_LEVEL),(VOIDFUNCPTR)interruptHandler,i); 例1中断服务程序
/* includes */ #include vxWorks.h #include intLib.h #include taskLib.h #include sysLib.h #include logLib.h /* function prototypes */ void interruptHandler(int); void interruptCatcher(void); /* globals */ #define INTERRUPT_NUM 2 #define INTERRUPT_LEVEL 65 #define ITER1 40 #define LONG_TIME 1000000 #define PRIORITY 100 #define ONE_SECOND 100 void interruptGenerator(void) /* task to generate the SIGINT signal */ { int i, j, taskId, priority; STATUS taskAlive; if ((taskId taskSpawn(interruptCatcher, PRIORITY, 0x100, 20000, (FUNCPTR) interruptCatcher, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) ERROR) logMsg(taskSpawn interruptCatcher failedn, 0, 0, 0, 0, 0, 0); for (i 0; i ITER1; i) { taskDelay(ONE_SECOND); /* suspend interruptGenerator for one second */ /* check to see if interruptCatcher task is alive! */ if ((taskAlive taskIdVerify(taskId)) OK) { logMsg(Interrupt generatedn, 0, 0, 0, 0, 0, 0); /* generate hardware interrupt 2 */ if ((sysBusIntGen(INTERRUPT_NUM, INTERRUPT_LEVEL)) ERROR) logMsg(Interrupt not generatedn, 0, 0, 0, 0, 0, 0); } else /* interruptCatcher is dead */ break; } logMsg(n***************interruptGenerator Exited***************nnnn, 0, 0, 0, 0, 0, 0); } void interruptCatcher(void) /* task to handle the interrupt */ { int i, j; STATUS connected; /* connect the interrupt vector, INTERRUPT_LEVEL, to a specific interrupt handler routine ,interruptHandler, and pass an argument, i */ if ((connected intConnect(INUM_TO_IVEC(INTERRUPT_LEVEL), (VOIDFUNCPTR) interruptHandler, i)) ERROR) logMsg(intConnect failedn, 0, 0, 0, 0, 0, 0); for (i 0; i ITER1; i) { for (j 0; j LONG_TIME; j) ; logMsg(Normal processing in interruptCatchern, 0, 0, 0, 0, 0, 0); } logMsg(ninterruptCatcher Exitedn, 0, 0, 0, 0, 0, 0); } void interruptHandler(int arg) /* signal handler code */ { int i; logMsg(-------------------------------interrupt caughtn, 0, 0, 0, 0, 0, 0); for (i 0; i 5; i) logMsg(interrupt processingn, 0, 0, 0, 0, 0, 0); } 程序中的sysBusIntGen()调用将产生一个bus中断这个函数与特定的BSP密切相关其原型为 STATUS sysBusIntGen ( int intLevel, /* bus interrupt level to generate */ int vector /* interrupt vector to generate (0-255) */ ); 为了在同一中断源的几种中断服务程序中进行切换我们应使用如下方式
vector INUM_TO_IVEC(some_int_vec_num); oldfunc intVecGet (vector); newfunc intHandlerCreate (routine, parameter); intVecSet (vector, newfunc); ... intVecSet (vector, oldfunc); /* use original routine */ ... intVecSet (vector, newfunc); /* reconnect new routine */ 其中intHandlerCreate函数的原型为
FUNCPTR intHandlerCreate ( FUNCPTR routine, /* routine to be called */ int parameter /* parameter to be passed to routine */ ); 它被用于创建一个中断服务程序在此之后通过intVecSet()函数我们就可以将intHandlerCreate()创建的结果与中断向量绑定intVecSet()函数的原型为
void intVecSet ( FUNCPTR * vector, /* vector offset */ FUNCPTR function /* address to place in vector */ ); 12.中断控制12.1中断执行过程 硬件中断发生时代码运行的上下文会发生切换在进入中断处理前需要保存当前运行的上下文。对于一些无RTOS的单片机系统这些工作由硬件和编译器共同完成向量表在编译完成后就填充完成再写入存储器中系统运行时不能修改向量表来重新绑定中断入口函数。在VxWorks系统中除了需要保存通常的寄存器环境外还需要完成栈切换等另外还要求中断入口运行时绑定、平台移植性、中断嵌套等所以VxWorks本身也参与中断封装的管理。VxWorks进行中断封装的伪代码如下
* 00 e8 kk kk kk kk call _intEnt * 通知内核 * 05 50 pushl %eax * 保存寄存器 * 06 52 pushl %edx * 07 51 pushl %ecx * 08 68 pp pp pp pp pushl $_parameterBoi * push BOI param * 13 e8 rr rr rr rr call _routineBoi * call BOI routine * 18 68 pp pp pp pp pushl $_parameter * 传中断入口参数 * 23 e8 rr rr rr rr call _routine * 调用中断处理C函数 * 28 68 pp pp pp pp pushl $_parameterEoi * push EOI param * 33 e8 rr rr rr rr call _routineEoi * call EOI routine * 38 83 c4 0c addl ?, %esp * pop param * 41 59 popl %ecx * 恢复寄存器 * 42 5a popl %edx * 43 58 popl %eax * 44 e9 kk kk kk kk jmp _intExit * 通过内核退出 12.2中断使能/禁止 VxWorks提供两个重要API 1intLock()使中断禁止 2intUnlock()开中断 可以用intLock/intUnlock提供最高级别的互斥机制以保护临界区域不被打断例如
oldlevel intLock(); /* 写XXX寄存器 */ XXX_REG_WRITE(pChan, XXX_UBRDIV, XXX_CNT0_115200 | XXX_CNT1_VAL); intUnlock(oldlevel); 用intLock()禁止中断后当前执行的任务将一直继续中断处理和任务调度得不到执行直到该任务主动调用intUnLock解锁中断为止。对于intLock和unLock的使用我们要注意如下几点 1不要在中断禁止期间调用vxWorks系统函数否则有可能意外使能中断违反临界代码的设计意图。另外intLock也不能屏蔽调度如果在中断禁止代码区使用系统调用就可能出现任务调度其他任务的运行可能会解锁中断 2中断禁止对系统的实时性有很大的影响在解决执行代码和中断处理互斥问题才可使用并且应使中断禁止时间尽可能的短。对于任务间的互斥问题可以使用taskLock()和taskUnLock()来解决 3有些CPU中断是分级我们可以用intLockLevelSet()和intLockLevelGet()来操作中断闭锁的级别。缺省情况下taskLock禁止所有等级的中断。 至此我们可以对“互斥”问题进行一个系统的总结主要有如下几种方法 1intLock禁止中断解决任务和ISR之间的互斥问题 int lock intLock(); //. . critical region that cannot be interrupted intUnlock(lock); 2taskLock禁止优先级抢占调度当当前任务正在运行时除了中断服务程序外高优先级的任务也不允许抢占CPU taskLock(); //. . critical region that cannot be interrupted . taskUnlock(); 3二进制信号量或互斥信号量。
semTake (semMutex, WAIT_FOREVER); //. . critical region, only accessible by a single task at a time . semGive (semMutex); 总的来说在实时系统中采取“禁止中断”的方法会影响系统对外部中断及时响应和处理的能力而“禁止优先级抢占调度”方法阻止了高优先级的任务抢先运行在实时系统中也是不适合的。因此信号量无疑是解决互斥问题的最好方法。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/88714.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!