OpenCores
URL https://opencores.org/ocsvn/spicc/spicc/trunk

Subversion Repositories spicc

[/] [spicc/] [trunk/] [wb_picc.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mcupro
 
2
module top (  input clk,
3
    input ir0,
4
    input ir1,
5
    input ir2,
6
    input ir3,
7
    input ir4,
8
    input ir5,
9
    input ir6,
10
    input rst,
11
    input wb_cyc,
12
    input wb_sel,
13
    input wb_std,
14
    input wb_we,
15
    input [7:0] wb_addr,
16
    input [7:0] wb_din,
17
    output wb_ack,
18
    output wb_irq,
19
    output [7:0] wb_dout
20
    );
21
 
22
    wire [2:0] irq_no;
23
    wire [7:0] w_mask;
24
    wire [2:0] w_pir;
25
 
26
    pri_rslv1 U1
27
              (
28
                  .int_o(wb_irq),
29
                  .ir0(ir0),
30
                  .ir1(ir1),
31
                  .ir2(ir2),
32
                  .ir3(ir3),
33
                  .ir4(ir4),
34
                  .ir5(ir5),
35
                  .ir6(ir6),
36
                  .ir7(ir6),
37
                  .irq_no(irq_no),
38
                  .mask_in(w_mask),
39
                  .pri_in(w_pir)
40
              );
41
 
42
    wb_if U2
43
          (
44
              .clk(clk),
45
              .irq_no(irq_no),
46
              .mask(w_mask),
47
              .pri_no_reg(w_pir),
48
              .ret(rst),
49
              .wb_ack(wb_ack),
50
              .wb_addr(wb_addr[7:0]),
51
              .wb_cyc(wb_cyc),
52
              .wb_din(wb_din),
53
              .wb_dout(wb_dout),
54
              .wb_sel(wb_sel),
55
              .wb_std(wb_std),
56
              .wb_we(wb_we)
57
          );
58
 
59
endmodule
60
 
61
 
62
`define ADDR_MASK_REG 0
63
`define ADDR_PRI_NO_REG 1
64
`define ADDR_IRQ_NO_REG 2
65
`define WB_B2
66
//`define WB_B3
67
 
68
module wb_if(
69
        input clk,
70
        input rst,
71
 
72
        input [7:0] wb_din,
73
        output reg [7:0] wb_dout,
74
        input wb_sel,
75
        input wb_std,
76
        input wb_we,
77
        input wb_cyc,
78
        input [1:0] wb_addr,
79
        output reg wb_ack,
80
 
81
        input  [2:0] irq_no,
82
        output reg [7:0] mask,
83
        output reg [2:0] pri_no_reg
84
    );
85
 
86
    /*
87
    latch the irq_no input
88
    */
89
    reg [2:0] irq_no_reg ;
90
    always@(posedge clk)
91
                if (ret)irq_no_reg<=3'bxxx;
92
        irq_no_reg<=irq_no;
93
 
94
    reg [7:0] mask_reg ;
95
        /* the bit bit 0 is the mask of ir0
96
        for exmple the bit 0 is the mask of ir0.
97
        so when you clear bit 0 ,the ir0 interrupt request will be ignored
98
        */
99
 
100
    assign wb_access = wb_sel & wb_std & wb_cyc ;
101
 
102
    assign sel_mask = wb_addr == `ADDR_MASK_REG && wb_access ;
103
    assign sel_irq_no_reg = wb_addr == `ADDR_IRQ_NO_REG&& wb_access ;
104
    assign sel_pri_no_reg = wb_addr == `ADDR_PRI_NO_REG && wb_access ;
105
        /*
106
 
107
        */
108
 
109
`ifdef WB_B2
110
                always@(posedge clk)//WISHBONE B2        
111
`else
112
                always@(*) //WISHBONE B3
113
`endif
114
          wb_ack = wb_access ;
115
 
116
    assign wr_mask = sel_mask & wb_we ;
117
    assign wr_irq_no_reg = sel_irq_no_reg & wb_we ;
118
    assign wr_pri_no_reg = sel_pri_no_reg& wb_we ;
119
 
120
    always@(posedge clk)
121
    case({sel_mask,sel_irq_no_reg,sel_pri_no_reg})
122
        1: wb_dout<={5'bxxxxx,pri_no_reg[2:0]} ; /*read the pripority number setted by WISHHONE bus before */
123
        2: wb_dout<={5'bxxxxx,irq_no_reg[2:0]};   /*read which line has a interrupt request*/
124
        4: wb_dout<=mask_reg;/*read mask setted by WISHHONE bus before*/
125
        default :
126
            wb_dout<=8'bxxxx_xxxx;      /*WISHBONE bus does not want to read this device after all and will ignore the output_data*/
127
    endcase
128
 
129
    always@(posedge clk)
130
    if (rst)begin
131
        mask_reg<=0;//disable all interrput
132
        pri_no_reg <=3'bxxx;
133
    end else
134
    case ({wr_mask,wr_pri_no_reg})
135
        2:mask_reg <= wb_din; //write mask register
136
        1:pri_no_reg <= wb_din[2:0]; //write priory number register
137
    endcase
138
endmodule
139
 
140
 
141
module pri_rslv1(
142
        input ir0,
143
        input ir1,
144
        input ir2,
145
        input ir3,
146
        input ir4,
147
        input ir5,
148
        input ir6,
149
        input ir7,
150
        input [7:0] mask_in,
151
        input [2:0] pri_in,
152
        output reg [2:0] irq_no,
153
        output reg int_o
154
    );
155
 
156
    wire [7:0] valid_ir_data= {ir7,ir6,ir5,ir4,ir3,ir2,ir1,ir0} & mask_in;
157
    /*mask here used to disable some interrupt request which we do not care about*/
158
 
159
    reg [3:0] int_pri_ir;
160
    /*to indicate  priority of the current legal interruput*/
161
 
162
    always @(*)
163
    casex( valid_ir_data )
164
        /*
165
        8-3 Line Priority Encoder which is similar with 74LS148 device
166
        the ir0 has the highest pripority while the ir7 has the lowwest one
167
        */
168
        {8'bxxxxxxx1}: int_pri_ir = 7;
169
        {8'bxxxxxx10}: int_pri_ir = 6;
170
        {8'bxxxxx100}: int_pri_ir = 5;
171
        {8'bxxxx1000}: int_pri_ir = 4;
172
        {8'bxxx10000}: int_pri_ir = 3;
173
        {8'bxx100000}: int_pri_ir = 2;
174
        {8'bx1000000}: int_pri_ir = 1;
175
        {8'b10000000}: int_pri_ir = 0;
176
        default
177
        int_pri_ir<=3'bxxx;
178
        /*
179
        each interrupt request bit is 0 ,namely,there are not bits setted
180
        the int_o =0 && (pri_in < int_pri_ir) =0,(see below)
181
        so we can safly set  int_pri_ir = 3'bxxx as default to reduce the logic resource usage.
182
        */
183
    endcase
184
 
185
/*
186
if there is a interruput and the priority is greater than the current
187
interrupt priority,the generate a gloable interrput request signal.
188
*/
189
    always@(*)
190
        int_o  =  (valid_ir_data!=0)&&(pri_in < int_pri_ir);
191
 
192
/*
193
there bits interrupt number
194
*/
195
    always@(*)
196
        irq_no = int_pri_ir[2:0] ;
197
 
198
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.