Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

implement interrupt by using custom component?

I want to implement interrupt by using custom component,fist I write a verilog HDL code;second ,i add it in Sopcbulider;at last,I write programme in IDE.

but i found that the interrupt can't happen.

whether you can give me some suggest or example code on iterrupt,Thank all

verilog HDL code(this is very small code )

module test(

clk,

reset,

write,

writedata,

irq

);

//inpnt signal

input clk;

input reset;

input write;

input [31:0]writedata;

//output signal

output irq;

//Parameter

parameter countval = 32'h0000_0010;

reg [31:0]count;

reg [31:0]ctl_reg;

wire irq_enable;

wire time_over;

assign irq = irq_enable && time_over;

always@(posedge clk or negedge reset)

begin

if(~reset)

count = 0;

else if(count >=countval)

count = 0;

else

count = count +1;

end

always @(posedge clk or negedge reset)

begin

if (~reset)

ctl_reg <= 0;

else if (write)

ctl_reg <= writedata;

end

assign irq_enable = ctl_reg;

assign time_over = (count >=countval);

endmodule

___________________________________________________________

NIOS IDE C code# include <stdio.h># include <io.h># include "system.h"# include "sys/alt_irq.h"

void test_interrupt(void* context, alt_u32 id)

{

IOWR(TEST_0_BASE,0,0x0); // CLEAR INTERRUPT

printf("Hello!\n");

IOWR(TEST_0_BASE,0,0x1);

}

int main()

{

int u;

printf("Hello from Nios II!\n");

u=alt_irq_register(TEST_0_IRQ,0,test_interrupt);

//alt_irq_enabled();

IOWR(TEST_0_BASE,0,0x1); // enable interrupt

printf("Nios II!=%d\n",u);

while(1);

return 0;

}

-------------------------------------------------

I found it never interrupt ; what wrong with my work? I need help
No RepliesBe the first to reply