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

Subversion Repositories rf68000

[/] [rf68000/] [trunk/] [rtl/] [cpu/] [rf68000_plic.sv] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2013-2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
7
//       ||
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
//
36
//              Encodes discrete interrupt request signals into five
37
//      bit code using a priority encoder.
38
//
39
//      reg
40
//      0x00    - encoded request number (read / write)
41
//                      This register contains the number identifying
42
//                      the current requester in bits 0 to 4
43
//                      If there is no
44
//                      active request, then this number will be
45
//                      zero.
46
//          bits 8 to 15 set the base number for the vector
47
//
48
//      0x04    - request enable (read / write)
49
//                      this register contains request enable bits
50
//                      for each request line. 1 = request
51
//                      enabled, 0 = request disabled. On reset this
52
//                      register is set to zero (disable all ints).
53
//                      bit zero is specially reserved for nmi
54
//
55
//      0x08   - write only
56
//                      this register disables the interrupt indicated
57
//                      by the low order five bits of the input data
58
//
59
//      0x0C    - write only
60
//                      this register enables the interrupt indicated
61
//                      by the low order five bits of the input data
62
//
63
//      0x10    - write only
64
//                      this register indicates which interrupt inputs are
65
//                      edge sensitive
66
//
67
//  0x14        - write only
68
//                      This register resets the edge sense circuitry
69
//                      indicated by the low order five bits of the input data.
70
//
71
//  0x18  - write only
72
//      This register triggers the interrupt indicated by the low
73
//      order five bits of the input data.
74
//
75
//  0x80    - irq control for irq #0
76
//  0x84    - irq control for irq #1
77
//            bits 0 to 7  = cause code to issue
78
//            bits 8 to 11 = irq level to issue
79
//            bit 16 = irq enable
80
//            bit 17 = edge sensitivity
81
//                                              bit 18 = respond to inta
82
//                                              bit 24 to 29 target core
83
//=============================================================================
84
 
85
module rf68000_plic
86
(
87
        input rst_i,            // reset
88
        input clk_i,            // system clock
89
        input cs_i,
90
        input cyc_i,
91
        input stb_i,
92
        output ack_o,       // controller is ready
93
        output reg vpa_o,
94
        input wr_i,                     // write
95
        input [2:0] fc_i,
96
        input [31:0] adr_i,     // address
97
        input [31:0] dat_i,
98
        output reg [31:0] dat_o,
99
        output vol_o,           // volatile register selected
100
        input i1, i2, i3, i4, i5, i6, i7,
101
                i8, i9, i10, i11, i12, i13, i14, i15,
102
                i16, i17, i18, i19, i20, i21, i22, i23,
103
                i24, i25, i26, i27, i28, i29, i30, i31,
104
        output reg [3:0] irqo,  // normally connected to the processor irq
105
        input nmii,             // nmi input connected to nmi requester
106
        output reg nmio,        // normally connected to the nmi of cpu
107
        output reg [7:0] causeo,
108
        output reg [5:0] core_o
109
);
110
 
111
wire clk;
112
reg [31:0] trig;
113
reg [31:0] ie;          // interrupt enable register
114
reg rdy1;
115
reg [4:0] irqenc;
116
wire [31:0] i = {   i31,i30,i29,i28,i27,i26,i25,i24,i23,i22,i21,i20,i19,i18,i17,i16,
117
                    i15,i14,i13,i12,i11,i10,i9,i8,i7,i6,i5,i4,i3,i2,i1,nmii};
118
reg [31:0] ib;
119
reg [31:0] iedge;
120
reg [31:0] rste;
121
reg [31:0] es;
122
reg [3:0] irq [0:31];
123
reg [7:0] cause [0:31];
124
reg [5:0] core [0:31];
125
reg [31:0] intar;
126
integer n,n1,n2;
127
 
128
wire cs = cyc_i && stb_i && cs_i;
129
wire cs_inta = cyc_i && stb_i && adr_i[31:4]=={28{1'b1}} && fc_i==3'b111;
130
assign vol_o = cs;
131
 
132
assign clk = clk_i;
133
//BUFH ucb1 (.I(clk_i), .O(clk));
134
 
135
always_ff @(posedge clk)
136
        rdy1 <= cs | (cs_inta & intar[irqenc]);
137
assign ack_o = (cs | (cs_inta & intar[irqenc])) ? (wr_i ? 1'b1 : rdy1) : 1'b0;
138
 
139
// write registers
140
always_ff @(posedge clk)
141
        if (rst_i) begin
142
                ie <= 32'h0;
143
                rste <= 32'h0;
144
                trig <= 32'h0;
145
                es <= 32'hFFFFFFFF;
146
                rste <= 32'h0;
147
                intar <= 32'hFFFFFFFF;
148
                for (n1 = 0; n1 < 32; n1 = n1 + 1) begin
149
                        cause[n1] <= 8'h00;
150
                        irq[n1] <= 4'h8;
151
                        core[n1] <= 'd0;
152
                end
153
        end
154
        else begin
155
                rste <= 32'h0;
156
                trig <= 32'h0;
157
                if (cs & wr_i) begin
158
                        casez (adr_i[7:2])
159
                        6'd0: ;
160
                        6'd1:
161
                                begin
162
                                        ie[31:0] <= dat_i[31:0];
163
                                end
164
                        6'd2,6'd3:
165
                                ie[dat_i[4:0]] <= adr_i[2];
166
                        6'd4:   es <= dat_i[31:0];
167
                        6'd5:   rste[dat_i[4:0]] <= 1'b1;
168
                        6'd6:   trig[dat_i[4:0]] <= 1'b1;
169
                        6'b1?????:
170
                             begin
171
                                 cause[adr_i[6:2]] <= dat_i[7:0];
172
                                 irq[adr_i[6:2]] <= dat_i[11:8];
173
                                 ie[adr_i[6:2]] <= dat_i[16];
174
                                 es[adr_i[6:2]] <= dat_i[17];
175
                                 intar[adr_i[6:2]] <= dat_i[18];
176
                                 core[adr_i[6:2]] <= dat_i[29:24];
177
                             end
178
                        endcase
179
                end
180
        end
181
 
182
// read registers
183
always_ff @(posedge clk)
184
begin
185
        if (irqenc!=5'd0)
186
                $display("PIC: %d",irqenc);
187
        if (cs)
188
                casez (adr_i[7:2])
189
                6'd0:   dat_o <= cause[irqenc];
190
                6'b1?????: dat_o <= {es[adr_i[6:2]],ie[adr_i[6:2]],4'b0,irq[adr_i[6:2]],cause[adr_i[6:2]]};
191
                default:        dat_o <= ie;
192
                endcase
193
        else if (cs_inta & intar[irqenc]) begin
194
                if (adr_i[3:1] <= irq[irqenc])
195
                        dat_o <= {4{cause[irqenc]}};
196
                else
197
                        dat_o <= {4{8'd24}};    // spurious interrupt
198
        end
199
        else
200
                dat_o <= 32'h0000;
201
end
202
always_ff @(posedge clk)
203
        if (cs_inta & ~intar[irqenc])
204
                vpa_o <= 1'b1;
205
        else
206
                vpa_o <= 1'b0;
207
 
208
always_ff @(posedge clk)
209
  irqo <= (irqenc == 5'h0) ? 4'd0 : irq[irqenc] & {4{ie[irqenc]}};
210
always_ff @(posedge clk)
211
  causeo <= (irqenc == 5'h0) ? 8'd0 : cause[irqenc];
212
always_ff @(posedge clk)
213
  core_o <= (irqenc == 5'h0) ? 6'd0 : core[irqenc];
214
always_ff @(posedge clk)
215
  nmio <= nmii & ie[0];
216
 
217
// Edge detect circuit
218
always_ff @(posedge clk)
219
begin
220
        for (n = 1; n < 32; n = n + 1)
221
        begin
222
                ib[n] <= i[n];
223
                if (trig[n]) iedge[n] <= 1'b1;
224
                if (i[n] & !ib[n]) iedge[n] <= 1'b1;
225
                if (rste[n]) iedge[n] <= 1'b0;
226
        end
227
end
228
 
229
// irq requests are latched on every rising clock edge to prevent
230
// misreads
231
// nmi is not encoded
232
always_ff @(posedge clk)
233
begin
234
        irqenc <= 5'd0;
235
        for (n2 = 31; n2 > 0; n2 = n2 - 1)
236
                if ((es[n2] ? iedge[n2] : i[n2])) irqenc <= n2;
237
end
238
 
239
endmodule

powered by: WebSVN 2.1.0

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