在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!)    创芯人才网--重磅上线啦!
查看: 2781|回复: 0

中断执行后,为何没有返回到主程序中?

[复制链接]
发表于 2006-8-25 09:58:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
中断执行后,为何没有返回到主程序中?

中断执行后,为何没有返回到主程序main()中?

我试着编了一个timer中断的小程序,当计到某一数值时可以调用一个中断,但调用中断后,为何没能返回到我的主程序main()继续执行下面的程序呢?请大侠过来看看。
    #include "xparameters.h"
#include "stdio.h"
#include "xgpio_l.h"
#include "xtmrctr_l.h"
#include "xintc_l.h"
#include "xgpio.h"
#include "xexception_l.h"
XGpio Gpio;
int intc_command=0;
#define timer_count   0x4000000
#define  GPIO_EXAMPLE_DEVICE_ID  XPAR_GENERIC_GPIO_DEVICE_ID


/* Timer interrupt service routine */
void  timeinthandle(void * baseaddr_p)   //
{
        int csr;
        /* Read timer 0 CSR to see if it requested the interrupt */
        csr = XTmrCtr_mGetControlStatusReg(XPAR_OPB_TIMER_0_BASEADDR, 0);
        if(csr&XTC_CSR_INT_OCCURED_MASK)
        {   
             XGpio_SetDataDirection(&Gpio, 1, 0x0);
             XGpio_mSetDataReg(XPAR_GENERIC_GPIO_BASEADDR, 1, \
                             (0x03 ^ XGpio_mGetDataReg(XPAR_GENERIC_GPIO_BASEADDR, 1)));                  
    }                                       
        
        /* Clear the timer interrupt */
        XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_0_BASEADDR, 0, csr);        
        intc_command = XTRUE;        
}

/* Interrupt test routine */
void InterruptTest(void)
{
        int tmrvalue;
        print("-- Entering InterruptTest() --\r\n");
        /* Initialize exception handling */
        XExc_Init();
        /* Register external interrupt handler */
        XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT,
        (XExceptionHandler)XIntc_DeviceInterruptHandler,
        (void *)XPAR_OPB_INTC_0_DEVICE_ID);
        
        /* Start the interrupt controller */
        XIntc_mMasterEnable(XPAR_OPB_INTC_0_BASEADDR);
        /* Set the gpio for LEDs as output 1 is the channel used*/
        XGpio_Initialize(&Gpio, GPIO_EXAMPLE_DEVICE_ID);
        XGpio_SetDataDirection(&Gpio, 1, 0x0);
        /* Set the number of cycles the timer counts before interrupting */
        XTmrCtr_mSetLoadReg(XPAR_OPB_TIMER_0_BASEADDR, 0, timer_count);
        
        /* Reset the timers, and clear interrupts */
        XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_0_BASEADDR, 0,
                      XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
        
        // clear the load bit
        XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_0_BASEADDR, 0,0x0 );
        
        /* Enable timer   interrupt requests in the interrupt controller */
        XIntc_mEnableIntr(XPAR_OPB_INTC_0_BASEADDR,
                          XPAR_OPB_TIMER_0_INTERRUPT_MASK);
        
        /* Start the timers */
        XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_0_BASEADDR, 0,
                                    XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK |
                                    XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);
        
        
        /* Enable PPC non-critical interrupts */
        XExc_mEnableExceptions(XEXC_NON_CRITICAL);
        //wait the interrupt to occur
    while(!intc_command)
        {
              xil_printf("Main Program\n");
        }

        
        xil_printf("Main Program Continue\n");        
        
        /* Disable PPC non-critical interrupts */
        XTmrCtr_mSetControlStatusReg(XPAR_OPB_TIMER_0_BASEADDR, 0,
                                             XTC_CSR_IN T_OCCURED_MASK );
        XExc_mDisableExceptions(XEXC_NON_CRITICAL);        
        print("-- Exiting InterruptTest() --\r\n");
}
/* End user-supplied interrupt test routine */
//====================================================
int main (void)
{
        print("-- Entering main() --\r\n");
        InterruptTest();
        print("-- Exiting main() --\r\n");
        return 0;
}


    执行到蓝色部分时,会调用中断服务程序void  timeinthandle(void * baseaddr_p) ,在这个程序程序 中令intc_command=XTRUE,这样就不再去执行中断了,但它却继续执行,而为什么没有退出到while((!intc_command)去执行下面的程序呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /3 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-24 07:48 , Processed in 0.018198 second(s), 9 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表