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

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

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

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

中断执行后,为何没有返回到主程序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");
        /* 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)去执行下面的程序呢?
返回列表