Subversion Repositories ngs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 lvd 1
// part of NeoGS project (c) 2007-2008 NedoPC
2
//
3
// interrupt controller for Z80
4
 
5
module interrupts(
6
 
7
        clk_24mhz,
8
        clk_z80,
9
 
10
        m1_n,
11
        iorq_n,
12
 
13
        int_n
14
);
15
 
16
        parameter MAX_INT_LEN = 100;
17
 
18
        input clk_24mhz;
19
        input clk_z80;
20
 
21
        input m1_n;
22
        input iorq_n;
23
 
24
        output reg int_n;
25
 
26
 
27
 
28
        reg [9:0] ctr640;
29
        reg int_24;
30
 
31
        reg int_sync1,int_sync2,int_sync3;
32
 
33
        reg int_ack_sync,int_ack;
34
 
35
        reg int_gen;
36
 
37
 
38
        // generate int signal
39
 
40
        always @(posedge clk_24mhz)
41
        begin
42
 
43
                if( ctr640 == 10'd639 )
44
                        ctr640 <= 10'd0;
45
                else
46
                        ctr640 <= ctr640 + 10'd1;
47
 
48
 
49
                if( ctr640 == 10'd0 )
50
                        int_24 <= 1'b1;
51
                else if( ctr640 == MAX_INT_LEN )
52
                        int_24 <= 1'b0;
53
 
54
        end
55
 
56
 
57
 
58
        // generate interrupt signal in clk_z80 domain
59
        always @(negedge clk_z80)
60
        begin
61
                int_sync3 <= int_sync2;
62
                int_sync2 <= int_sync1;
63
                int_sync1 <= int_24;    // sync in from 24mhz, allow for edge detection (int_sync3!=int_sync2)
64
 
65
                int_ack_sync <= ~(m1_n | iorq_n);
66
                int_ack <= int_ack_sync;          // interrupt acknowledge from Z80
67
 
68
                // control interrupt generation signal
69
                if( int_ack || ( int_sync3 && (!int_sync2) ) )
70
                        int_gen <= 1'b0;
71
                else if( (!int_sync3) && int_sync2 )
72
                        int_gen <= 1'b1;
73
        end
74
 
75
        always @(posedge clk_z80)
76
        begin
77
                int_n <= ~int_gen;
78
        end
79
 
80
endmodule
81