首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

ucos ii下的硬中断服务问题

ucos ii下的硬中断服务问题

前天在做实验时,想在ucos ii 系统下触发一下外部中断玩玩,可没想到,按常归的中断要求编写完中断服务例程后,程序竟然跑飞了,触发按键中断后,我调试了一下,程序在一个默认的异常服务死循环里出不来了,我就郁闷了,想了之后,以为当OS 控制系统后在不同优先级任务间切换,不能再响应来自外部事件触发的中断呢,所以程序崩溃了呢,后来才发现,这是一个多么可笑的想法啊,呵呵,现在终于弄明白了,写点心得记录下来,以便完全理解。       看了ucos ii对中断的要求后才发现错哪了,任务调度之所以分为任务级任务调度和中断级任务调度,就是因为这个原因,学那么长时间了,竟然还不知道中断级任务调度是怎么调用了,悲剧啊,思而不学则殆,学而不思则惘,唉,把状态改了,以作警示,很明显,任务级任务调度是在任务间切换时调用的,具体什么时候调用呢?当一个任务有延时时,就会调用以便让一个更高优先级的任务进入就绪状态。而中断级任务调度呢,当然是在中断时调用以便让……这么简单的道理,怎么想不到呢?好像从来没想过这个问题……。
      查资料后发现了这两个函数:OSIntEnter()和OSIntExit(),这两个函数是用来干啥呢?看源码吧!
  void  OSIntEnter (void)
{
    if (OSRunning == TRUE)
        {
        if (OSIntNesting < 255)
             {
            OSIntNesting++;                      /* Increment ISR nesting level                        */
           }
        }
}
这个函数的源码真简单啊,不就是让一个变量加1吗?再来看一下注释:  
Description: This function is used to notify uC/OS-II that you are about to service an interrupt
*              service routine (ISR).  This allows uC/OS-II to keep track of interrupt nesting and thus
*              only perform rescheduling at the last nested ISR.
* .
* Arguments  : none
*
* Returns    : none
*
* Notes      : 1) This function should be called with interrupts already disabled
*              2) Your ISR can directly increment OSIntNesting without calling this function because
*                 OSIntNesting has been declared 'global'.  
*              3) You MUST still call OSIntExit() even though you increment OSIntNesting directly.
*              4) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
*                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
*                 end of the ISR.
*              5) You are allowed to nest interrupts up to 255 levels deep.
*              6) I removed the OS_ENTER_CRITICAL() and OS_EXIT_CRITICAL() around the increment because
*                 OSIntEnter() is always called with interrupts disabled.
继承事业,薪火相传
返回列表