stoppeddream 发表于 2012-10-10 00:10:07

请教搞xilinx的高手,关于microblaze的io中断

XIntc gInterruptControllerInst;
XGpio gGpioFieldirqInst;

void Field_IRQ_interrupt(void)
{
        XGpio_Initialize(&gGpioFieldirqInst, XPAR_FIELD_INT_DEVICE_ID);
        XGpio_InterruptDisable(&gGpioFieldirqInst,0xf);
        XGpio_InterruptClear(&gGpioFieldirqInst,0xffff);
        XGpio_InterruptEnable(&gGpioFieldirqInst,0xf);

}

int main()
{
    XGpio_Initialize(&gGpioFieldirqInst, XPAR_FIELD_INT_DEVICE_ID);
    XIntc_Connect(&gInterruptControllerInst,XPAR_INTC_0_GPIO_0_VEC_ID,(XInterruptHandler)Field_IRQ_interrupt,&gGpioFieldirqInst);
    XIntc_MasterEnable(XPAR_INTC_0_GPIO_0_VEC_ID);
    XIntc_Start(&gInterruptControllerInst,XIN_REAL_MODE);
    XIntc_Enable(&gInterruptControllerInst,XPAR_INTC_0_GPIO_0_VEC_ID);
    microblaze_enable_interrupts();
    XGpio_InterruptEnable(&gGpioFieldirqInst,0xf);
    XGpio_InterruptGlobalEnable(&gGpioFieldirqInst);

    while(1);
}

这段代码到XIntc_Connect(&gInterruptControllerInst,XPAR_INTC_0_GPIO_0_VEC_ID,(XInterruptHandler)Field_IRQ_interrupt,&gGpioFieldirqInst);
注册失败,怎么回事,都调了好几天,饭也吃不好,觉也睡不香的,好痛苦
到底能是哪里出问题了或者谁有好使的代码呢

pocker5200 发表于 2012-10-12 10:39:58

本帖最后由 pocker5200 于 2012-10-12 10:51 编辑

以前项目留下的一部分代码,定时器中断和GPIO中断。
mhs文件部分是IP核的配置,后面是软件部分。
注释不多,主要看个流程,
整理了一下发上来,希望能有帮助。
编辑备注:MB核采用PLB4.6总线

//      *.mhs文件部分
BEGIN xps_intc
PARAMETER INSTANCE = xps_intc_0
PARAMETER HW_VER = 2.01.a
PARAMETER C_BASEADDR = 0x81800000
PARAMETER C_HIGHADDR = 0x8180ffff
BUS_INTERFACE SPLB = mb_plb
PORT Intr = DIP_Switches_4Bit_IP2INTC_Irpt & nRF24l01_IRQ_IP2INTC_Irpt & xps_timer_0_Interrupt
PORT Irq = microblaze_0_Interrupt
END

BEGIN xps_gpio
PARAMETER INSTANCE = DIP_Switches_4Bit
PARAMETER C_ALL_INPUTS = 1
PARAMETER C_GPIO_WIDTH = 2
PARAMETER C_INTERRUPT_PRESENT = 1
PARAMETER C_IS_DUAL = 0
PARAMETER HW_VER = 2.00.a
PARAMETER C_BASEADDR = 0x814e0000
PARAMETER C_HIGHADDR = 0x814effff
BUS_INTERFACE SPLB = mb_plb
PORT IP2INTC_Irpt = DIP_Switches_4Bit_IP2INTC_Irpt
PORT GPIO_IO_I = fpga_0_DIP_Switches_4Bit_GPIO_IO_I_pin
END

BEGIN xps_timer
PARAMETER INSTANCE = xps_timer_0
PARAMETER C_COUNT_WIDTH = 32
PARAMETER C_ONE_TIMER_ONLY = 1
PARAMETER HW_VER = 1.02.a
PARAMETER C_BASEADDR = 0x83c00000
PARAMETER C_HIGHADDR = 0x83c0ffff
BUS_INTERFACE SPLB = mb_plb
PORT Interrupt = xps_timer_0_Interrupt
END
///////////////////////////////////////////////////////////////////////////
// main.c

#include <stdio.h>
#include "xparameters.h"
#include "xintc.h"
#include "xbasic_types.h"
#include "xgpio.h"
#include "xbasic_types.h"
#include "xgpio.h"
#include "xtmrctr.h"

static int timer_count = 1;
static int dip_count = 1;
static XIntc xps_intc_0;
static XTmrCtr xps_timer_0;
static XGpio xps_dip_4bit_switch;

//********************** 1. Device initialization and configuration *************************
        //xil_printf("Setting up peripherals...\r\n");
        //Initialize and configuring the timer
        XTmrCtr_Initialize(&xps_timer_0, XPAR_XPS_TIMER_0_DEVICE_ID);
        XTmrCtr_SelfTest(&xps_timer_0, 0);
        XTmrCtr_SetOptions(&xps_timer_0, 0 , XTC_INT_MODE_OPTION | \
                XTC_DOWN_COUNT_OPTION | XTC_AUTO_RELOAD_OPTION);
        XTmrCtr_SetHandler(&xps_timer_0, (XTmrCtr_Handler)timer_init_handler, NULL);


        //Initialize and configure the gpios
        XGpio_Initialize(&xps_dip_4bit_switch, XPAR_DIP_SWITCHES_4BIT_DEVICE_ID);
               
        XGpio_SetDataDirection(&xps_dip_4bit_switch, 1, 0xFFFF);
       

        XGpio_Initialize(&xps_led, XPAR_LEDS_4BIT_DEVICE_ID);
       
        XGpio_SetDataDirection(&xps_led, 1, 0x0);

        XGpio_InterruptEnable(&xps_dip_4bit_switch, 0xFFFF);

        XGpio_InterruptGlobalEnable(&xps_dip_4bit_switch);

        //*************** 2. Interrupt controller initialization and configuration ******************
        //xil_printf("Setting up interrupt controller...\r\n");

        //Attach the ISRs to the interrupt controller driver.
        //NOTE: The timer is weird. You have to attach "XTmrCtr_InterruptHandler," which is nested
        //deep within the timer driver. It in turn calls the callback you provide during the
        //configuration above.
        XIntc_Initialize(&xps_intc_0, XPAR_XPS_INTC_0_DEVICE_ID);
        XIntc_Connect(&xps_intc_0,
                                        XPAR_XPS_INTC_0_XPS_TIMER_0_INTERRUPT_INTR,
                                        (XInterruptHandler)XTmrCtr_InterruptHandler,
                                        &xps_timer_0);
        XIntc_Connect(&xps_intc_0,
                                        XPAR_XPS_INTC_0_DIP_SWITCHES_4BIT_IP2INTC_IRPT_INTR,
                                        (XInterruptHandler)gpio_init_handler,
                                        &xps_dip_4bit_switch);
       
                XIntc_Start(&xps_intc_0, XIN_REAL_MODE);
        XIntc_Enable(&xps_intc_0, XPAR_XPS_INTC_0_XPS_TIMER_0_INTERRUPT_INTR);
        XIntc_Enable(&xps_intc_0, XPAR_XPS_INTC_0_DIP_SWITCHES_4BIT_IP2INTC_IRPT_INTR);
       
        //Set the timer to expire every 6 seconds
        XTmrCtr_SetResetValue(&xps_timer_0, (Xuint8)0, RESET_VALUE);
        XTmrCtr_Start(&xps_timer_0, (Xuint8)0);

        microblaze_enable_interrupts();

        //************************** Interrupts init complete *******************************

//interrupt handler
XTmrCtr_Handler timer_init_handler(void * baseaddr_p) {
        xil_printf("Timer interrupt occured %d \r\n", timer_count++);
                //timer_count++;
        XIntc_Acknowledge(&xps_intc_0, XPAR_XPS_INTC_0_XPS_TIMER_0_INTERRUPT_INTR);
}

void gpio_init_handler(void * baseaddr_p) {
        xil_printf("Dip_4Bit interrupt occured %d .\r\n", dip_count++);
        XGpio_InterruptClear(&xps_dip_4bit_switch, 0xFFFF);
    XIntc_Acknowledge(&xps_intc_0,XPAR_XPS_INTC_0_DIP_SWITCHES_4BIT_IP2INTC_IRPT_INTR);
}

wangshaosh123 发表于 2012-10-12 12:15:24

本帖最后由 wangshaosh123 于 2012-10-12 12:16 编辑

io 方向设置了吗?另外GPIO有输入中断和输出中断之分

判断FPGA硬件是否正常,可以去生产一个外围设备测试的代码,
页: [1]
查看完整版本: 请教搞xilinx的高手,关于microblaze的io中断