首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Microblaze多中断代码不工作

Microblaze多中断代码不工作
EN

Stack Overflow用户
提问于 2014-10-25 19:16:30
回答 2查看 3.7K关注 0票数 3

我有一个简单的microblaze设置与两个Gpio (按钮和开关)。我想处理这两个设备的中断。

下面是我当前不工作的代码。

代码语言:javascript
复制
#include<xparameters.h>
#include<xgpio.h>
#include<xintc.h>
#include<xil_exception.h>

static XGpio PushBt;
static XGpio sw;
static XIntc myIntc;
int delay, limit=3000000;

void pb_int_handler(void *baseaddr_p) {
        Xuint32 dsr;

        //DSR contains the INFORMATION of which button was depressed, so we can switch
        //on its value.
        dsr = XGpio_DiscreteRead(&PushBt, 1);
        switch(dsr) {

            case 0x01:
                xil_printf("Up\r\n");
                for(delay=0;delay<limit;delay++){}; // delay cycle
                break;

            case 0x02:
                xil_printf("Left\r\n");
                for(delay=0;delay<limit;delay++){}; // delay cycle
                break;

            case 0x08:
                xil_printf("Right\r\n");
                for(delay=0;delay<limit;delay++){}; // delay cycle
                break;

            case 0x04:
                xil_printf("Down\r\n");
                for(delay=0;delay<limit;delay++){}; // delay cycle
                break;

            default : {}

        }
        //Clear the interrupt both in the Gpio instance as well as the interrupt controller
        XGpio_InterruptClear(&PushBt, 0x3);
        XIntc_Acknowledge(&myIntc,XPAR_AXI_INTC_0_PUSH_IP2INTC_IRPT_INTR);
    }

void sw_int_handler(void *baseaddr_p) {
        Xuint32 dsr;

        //DSR contains the INFORMATION of which button was depressed, so we can switch
        //on its value.
        dsr = XGpio_DiscreteRead(&sw, 1);
        switch(dsr) {

            case 0x00:
                xil_printf("Switches 00 \r\n");
                for(delay=0;delay<limit;delay++){}; // delay cycle
                break;

            case 0x01:
                xil_printf("Switches 01 \r\n");
                for(delay=0;delay<limit;delay++){}; // delay cycle
                break;

            case 0x02:
                xil_printf("Switches 02 \r\n");
                for(delay=0;delay<limit;delay++){}; // delay cycle
                break;

            case 0x03:
                xil_printf("Switches 03 \r\n");
                for(delay=0;delay<limit;delay++){}; // delay cycle
                break;

            default : {}

        }
        //Clear the interrupt both in the Gpio instance as well as the interrupt controller
        XGpio_InterruptClear(&sw, 0x3);
        XIntc_Acknowledge(&myIntc,XPAR_AXI_INTC_0_SW_IP2INTC_IRPT_INTR);
    }

int main(void) {

    xil_printf("Setting up peripherals...\r\n");
    for(delay=0;delay<limit;delay++){}; // delay cycle

    xil_printf("Setting up push buttons...\r\n");
    for(delay=0;delay<limit;delay++){}; // delay cycle

        XGpio_Initialize(&PushBt, XPAR_PUSH_DEVICE_ID);
        XGpio_SetDataDirection(&PushBt,1,1); //set pb as input port
        XGpio_InterruptEnable(&PushBt, XPAR_PUSH_IP2INTC_IRPT_MASK);
        XGpio_InterruptGlobalEnable(&PushBt);

    xil_printf("Setting up switches...\r\n");
    for(delay=0;delay<limit;delay++){}; // delay cycle

        XGpio_Initialize(&sw, XPAR_SW_DEVICE_ID);
        XGpio_SetDataDirection(&sw,1,1); //set sw as input port
        XGpio_InterruptEnable(&sw, XPAR_SW_IP2INTC_IRPT_MASK);
        XGpio_InterruptGlobalEnable(&sw);

    xil_printf("Setting up interrupt controller...\r\n");
    for(delay=0;delay<limit;delay++){}; // delay cycle
    XIntc_Initialize(&myIntc, XPAR_INTC_0_DEVICE_ID);

    xil_printf("Register the interrupt...\r\n");
    for(delay=0;delay<limit;delay++){}; // delay cycle
    XIntc_Connect(&myIntc, XPAR_AXI_INTC_0_PUSH_IP2INTC_IRPT_INTR,
                              (XInterruptHandler)pb_int_handler,
                                   &PushBt);
    XIntc_Connect(&myIntc, XPAR_AXI_INTC_0_SW_IP2INTC_IRPT_INTR,
                                  (XInterruptHandler)sw_int_handler,
                                       &sw);

    xil_printf("Enable individual interrupt...\r\n");
    for(delay=0;delay<limit;delay++){}; // delay cycle
    XIntc_EnableIntr(&myIntc,XPAR_PUSH_IP2INTC_IRPT_MASK | XPAR_SW_IP2INTC_IRPT_MASK);

    xil_printf("Start the interrupt controller...\r\n");
    for(delay=0;delay<limit;delay++){}; // delay cycle
    XIntc_Start(&myIntc, XIN_REAL_MODE);
    XIntc_MasterEnable(&myIntc);
    microblaze_enable_interrupts();

    xil_printf("Setting up exceptions...\r\n");
    for(delay=0;delay<limit;delay++){}; // delay cycle
    Xil_ExceptionInit();

    Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_M_AXI_I_EXCEPTION,
            (XExceptionHandler)XIntc_InterruptHandler,
                         &myIntc);
    Xil_ExceptionEnable();

    while(1) {
        xil_printf("Entering loop...\r\n");
        for(delay=0;delay<limit;delay++){}; // delay cycle
    }
}

有什么帮助解释正确的中断代码序列吗?

  • 我设置了处理程序。
  • 我初始化了中断控制器。
  • 我把处理程序连接起来了。
  • 我启用了中断掩码。
  • 我启动了中断控制器。
  • 我启用了主中断控制器。

那我忘了什么?或者怎么了?谢谢

EN

回答 2

Stack Overflow用户

发布于 2014-11-14 12:29:43

找到解决方案:更改这些行

代码语言:javascript
复制
XGpio_InterruptEnable(&PushBt, XPAR_PUSH_IP2INTC_IRPT_MASK);

代码语言:javascript
复制
XGpio_InterruptEnable(&PushBt, 0xff);

代码语言:javascript
复制
XGpio_InterruptEnable(&sw, XPAR_SW_IP2INTC_IRPT_MASK);

代码语言:javascript
复制
XGpio_InterruptEnable(&sw, 0xff);

所以现在代码可以工作了,但是我将研究为什么:)这是一个中断掩码问题

票数 0
EN

Stack Overflow用户

发布于 2018-07-04 12:23:03

您正在将错误的值传递给Mask函数的XGpio_InterruptEnable参数。

XPAR_PUSH_IP2INTC_IRPT_MASKXPAR_SW_IP2INTC_IRPT_MASK是中断控制器外围设备的中断掩码值,而不是GPIO外围设备的中断掩码值。

这是C:\Xilinx\14.7\ISE_DS\EDK\sw\XilinxProcessorIPLib\drivers\gpio_v3_01_a\src\xgpio_l.h的摘录,向您展示GPIO外围设备的正确掩码值:

代码语言:javascript
复制
/** @name Interrupt Status and Enable Register bitmaps and masks
 *
 * Bit definitions for the interrupt status register and interrupt enable
 * registers.
 * @{
 */
#define XGPIO_IR_MASK       0x3 /**< Mask of all bits */
#define XGPIO_IR_CH1_MASK   0x1 /**< Mask for the 1st channel */
#define XGPIO_IR_CH2_MASK   0x2 /**< Mask for the 2nd channel */
/*@}*/

所以,你应该改变你的台词

代码语言:javascript
复制
XGpio_InterruptEnable(&PushBt, XPAR_PUSH_IP2INTC_IRPT_MASK);
XGpio_InterruptEnable(&sw, XPAR_SW_IP2INTC_IRPT_MASK);

代码语言:javascript
复制
XGpio_InterruptEnable(&PushBt, XGPIO_IR_CH1_MASK);
XGpio_InterruptEnable(&sw, XGPIO_IR_CH1_MASK);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26566252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档