Board logo

标题: EDK中为什么不能实现中断? [打印本页]

作者: li_yuling2    时间: 2008-3-27 10:51     标题: EDK中为什么不能实现中断?

程序源代码如下:

#include "xparameters.h"

#include "stdio.h"
#include "xintc_l.h"
#include "xutil.h"
#include "xgpio_l.h"
#include "mb_interface.h"
//====================================================

#define XPAR_GPIO_REG_BASE XPAR_LEDS_8BIT_BASEADDR
#define LED_DELAY 2500000
#define LED_CHANNEL 1

Xuint8 Data=0xaa;
Xuint8 Data2=0x0f;

void switch_int_handler(void *baseaddr_p)
{
Data=0x00;
Data2=0x00;
XGpio_mWriteReg(XPAR_DIP_SWITCHES_4BIT_BASEADDR,XGPIO_ISR_OFFSET,0x00000001);
microblaze_disable_interrupts();
}


int main()
{

volatile int Delay;

/* Set the direction of gpio */
XGpio_mSetDataDirection(XPAR_GPIO_REG_BASE, LED_CHANNEL, 0x0);
XGpio_mSetDataDirection(XPAR_DIP_SWITCHES_4BIT_BASEADDR,1,0xffffffff);

// Initializing the interrupt vector
/*
* Enable the Interrupts on the Microblaze
*/
microblaze_enable_interrupts();

/*
* Register the switch_gpio interrupt handler in the vector table
*/
XIntc_RegisterHandler(XPAR_OPB_INTC_0_BASEADDR,
XPAR_OPB_INTC_0_DIP_SWITCHES_4BIT_IP2INTC_IRPT_INTR,
(XInterruptHandler)switch_int_handler,
(void *)XPAR_DIP_SWITCHES_4BIT_BASEADDR);

/*
* Start the interrupt controller
*/
XIntc_mMasterEnable(XPAR_OPB_INTC_0_BASEADDR);

/*
* Set the master enable bit.

XIntc_Out32(XPAR_OPB_INTC_0_BASEADDR + XIN_MER_OFFSET,
XIN_INT_MASTER_ENABLE_MASK);*/

/*
* Enable timer and uart interrupt requests in the interrupt controller
*/

XIntc_mEnableIntr(XPAR_OPB_INTC_0_BASEADDR,
XPAR_DIP_SWITCHES_4BIT_IP2INTC_IRPT_MASK);

// Enable interrupt of GPIO
XGpio_mWriteReg(XPAR_DIP_SWITCHES_4BIT_BASEADDR,XGPIO_GIER_OFFSET,0x80000000);
XGpio_mWriteReg(XPAR_DIP_SWITCHES_4BIT_BASEADDR,XGPIO_IER_OFFSET,0x00000001);

while (1)
{
if (XGpio_mGetDataReg(XPAR_DIP_SWITCHES_4BIT_BASEADDR,1)&1)
{
XGpio_mSetDataReg(XPAR_GPIO_REG_BASE, LED_CHANNEL,~Data);
}
else
{
XGpio_mSetDataReg(XPAR_GPIO_REG_BASE, LED_CHANNEL,Data);
}
/* Wait a small amount of time so the LED is visible */
for (Delay = 0; Delay < LED_DELAY; Delay++);

if (XGpio_mGetDataReg(XPAR_DIP_SWITCHES_4BIT_BASEADDR,1)&1)
{
XGpio_mSetDataReg(XPAR_GPIO_REG_BASE, LED_CHANNEL, Data2);
}
else
{
XGpio_mSetDataReg(XPAR_GPIO_REG_BASE, LED_CHANNEL,~Data2);
}

for (Delay = 0; Delay < LED_DELAY; Delay++);
}

return 0;
}

MHS文件如下:


PARAMETER VERSION = 2.1.0


PORT fpga_0_LEDs_8Bit_GPIO_d_out_pin = fpga_0_LEDs_8Bit_GPIO_d_out, DIR = O, VEC = [0:7]
PORT fpga_0_DIP_Switches_4Bit_GPIO_in_pin = fpga_0_DIP_Switches_4Bit_GPIO_in, DIR = I, VEC = [0:3]
PORT sys_clk_pin = dcm_clk_s, DIR = I, SIGIS = CLK, CLK_FREQ = 50000000
PORT sys_rst_pin = sys_rst_s, DIR = I, RST_POLARITY = 1, SIGIS = RST


BEGIN microblaze
PARAMETER INSTANCE = microblaze_0
PARAMETER HW_VER = 6.00.a
PARAMETER C_USE_FPU = 0
PARAMETER C_DEBUG_ENABLED = 1
PARAMETER C_NUMBER_OF_PC_BRK = 2
PARAMETER C_AREA_OPTIMIZED = 1
BUS_INTERFACE DLMB = dlmb
BUS_INTERFACE ILMB = ilmb
BUS_INTERFACE DOPB = mb_opb
BUS_INTERFACE IOPB = mb_opb
PORT DBG_CAPTURE = DBG_CAPTURE_s
PORT DBG_CLK = DBG_CLK_s
PORT DBG_REG_EN = DBG_REG_EN_s
PORT DBG_TDI = DBG_TDI_s
PORT DBG_TDO = DBG_TDO_s
PORT DBG_UPDATE = DBG_UPDATE_s
PORT Interrupt = Interrupt
END

BEGIN opb_v20
PARAMETER INSTANCE = mb_opb
PARAMETER HW_VER = 1.10.c
PARAMETER C_EXT_RESET_HIGH = 1
PORT SYS_Rst = sys_rst_s
PORT OPB_Clk = sys_clk_s
END

BEGIN opb_mdm
PARAMETER INSTANCE = debug_module
PARAMETER HW_VER = 2.00.a
PARAMETER C_MB_DBG_PORTS = 1
PARAMETER C_USE_UART = 1
PARAMETER C_UART_WIDTH = 8
PARAMETER C_BASEADDR = 0x41400000
PARAMETER C_HIGHADDR = 0x4140ffff
BUS_INTERFACE SOPB = mb_opb
PORT DBG_CAPTURE_0 = DBG_CAPTURE_s
PORT DBG_CLK_0 = DBG_CLK_s
PORT DBG_REG_EN_0 = DBG_REG_EN_s
PORT DBG_TDI_0 = DBG_TDI_s
PORT DBG_TDO_0 = DBG_TDO_s
PORT DBG_UPDATE_0 = DBG_UPDATE_s
END

BEGIN lmb_v10
PARAMETER INSTANCE = ilmb
PARAMETER HW_VER = 1.00.a
PARAMETER C_EXT_RESET_HIGH = 1
PORT SYS_Rst = sys_rst_s
PORT LMB_Clk = sys_clk_s
END

BEGIN lmb_v10
PARAMETER INSTANCE = dlmb
PARAMETER HW_VER = 1.00.a
PARAMETER C_EXT_RESET_HIGH = 1
PORT SYS_Rst = sys_rst_s
PORT LMB_Clk = sys_clk_s
END

BEGIN lmb_bram_if_cntlr
PARAMETER INSTANCE = dlmb_cntlr
PARAMETER HW_VER = 2.00.a
PARAMETER C_BASEADDR = 0x00000000
PARAMETER C_HIGHADDR = 0x00001fff
BUS_INTERFACE SLMB = dlmb
BUS_INTERFACE BRAM_PORT = dlmb_port
END

BEGIN lmb_bram_if_cntlr
PARAMETER INSTANCE = ilmb_cntlr
PARAMETER HW_VER = 2.00.a
PARAMETER C_BASEADDR = 0x00000000
PARAMETER C_HIGHADDR = 0x00001fff
BUS_INTERFACE SLMB = ilmb
BUS_INTERFACE BRAM_PORT = ilmb_port
END

BEGIN bram_block
PARAMETER INSTANCE = lmb_bram
PARAMETER HW_VER = 1.00.a
BUS_INTERFACE PORTA = ilmb_port
BUS_INTERFACE PORTB = dlmb_port
END

BEGIN opb_gpio
PARAMETER INSTANCE = LEDs_8Bit
PARAMETER HW_VER = 3.01.b
PARAMETER C_GPIO_WIDTH = 8
PARAMETER C_IS_DUAL = 0
PARAMETER C_IS_BIDIR = 0
PARAMETER C_ALL_INPUTS = 0
PARAMETER C_BASEADDR = 0x40020000
PARAMETER C_HIGHADDR = 0x4002ffff
BUS_INTERFACE SOPB = mb_opb
PORT GPIO_d_out = fpga_0_LEDs_8Bit_GPIO_d_out
END

BEGIN opb_gpio
PARAMETER INSTANCE = DIP_Switches_4Bit
PARAMETER HW_VER = 3.01.b
PARAMETER C_INTERRUPT_PRESENT = 1
PARAMETER C_GPIO_WIDTH = 4
PARAMETER C_IS_DUAL = 0
PARAMETER C_IS_BIDIR = 0
PARAMETER C_ALL_INPUTS = 1
PARAMETER C_BASEADDR = 0x40000000
PARAMETER C_HIGHADDR = 0x4000ffff
BUS_INTERFACE SOPB = mb_opb
PORT IP2INTC_Irpt = DIP_Switches_4Bit_IP2INTC_Irpt
PORT GPIO_in = fpga_0_DIP_Switches_4Bit_GPIO_in
END

BEGIN opb_intc
PARAMETER INSTANCE = opb_intc_0
PARAMETER HW_VER = 1.00.c
PARAMETER C_BASEADDR = 0x41200000
PARAMETER C_HIGHADDR = 0x4120ffff
BUS_INTERFACE SOPB = mb_opb
PORT Irq = Interrupt
PORT Intr = DIP_Switches_4Bit_IP2INTC_Irpt
END

BEGIN dcm_module
PARAMETER INSTANCE = dcm_0
PARAMETER HW_VER = 1.00.a
PARAMETER C_CLK0_BUF = TRUE
PARAMETER C_CLKIN_PERIOD = 20.000000
PARAMETER C_CLK_FEEDBACK = 1X
PARAMETER C_EXT_RESET_HIGH = 1
PORT CLKIN = dcm_clk_s
PORT CLK0 = sys_clk_s
PORT CLKFB = sys_clk_s
PORT RST = net_gnd
PORT LOCKED = dcm_0_lock
END


作者: zaiming    时间: 2008-4-1 20:35

/*
* Register the switch_gpio interrupt handler in the vector table
*/
XIntc_RegisterHandler(XPAR_OPB_INTC_0_BASEADDR,
XPAR_OPB_INTC_0_DIP_SWITCHES_4BIT_IP2INTC_IRPT_INTR,
(XInterruptHandler)switch_int_handler,
(void *)XPAR_DIP_SWITCHES_4BIT_BASEADDR);

//感觉这个之前要先进行中断初始化,就是xintc_inint...的一个命令






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0