1 |
3 |
robfinch |
`timescale 1ns / 1ps
|
2 |
|
|
//=============================================================================
|
3 |
|
|
// (C) 2013,2015 Robert Finch
|
4 |
|
|
// All rights reserved.
|
5 |
|
|
// robfinch<remove>@Finitron.ca
|
6 |
|
|
//
|
7 |
|
|
// Thor_pic.v
|
8 |
|
|
//
|
9 |
|
|
//
|
10 |
|
|
// This source file is free software: you can redistribute it and/or modify
|
11 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
12 |
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
13 |
|
|
// (at your option) any later version.
|
14 |
|
|
//
|
15 |
|
|
// This source file is distributed in the hope that it will be useful,
|
16 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
// GNU General Public License for more details.
|
19 |
|
|
//
|
20 |
|
|
// You should have received a copy of the GNU General Public License
|
21 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
22 |
|
|
//
|
23 |
|
|
//
|
24 |
|
|
// Encodes discrete interrupt request signals into four
|
25 |
|
|
// bit code using a priority encoder.
|
26 |
|
|
//
|
27 |
|
|
// reg
|
28 |
|
|
// 0x00 - encoded request number (read only)
|
29 |
|
|
// This register contains the number identifying
|
30 |
|
|
// the current requester.
|
31 |
|
|
// the actual number is shifted left three times
|
32 |
|
|
// before being placed into this register so it may
|
33 |
|
|
// be used directly as an index in OS software. The
|
34 |
|
|
// index may be a mailbox id or index into a jump
|
35 |
|
|
// table as desired by the OS. If there is no
|
36 |
|
|
// active request, then this number will be
|
37 |
|
|
// zero.
|
38 |
|
|
// 0x08 - request enable (read / write)
|
39 |
|
|
// this register contains request enable bits
|
40 |
|
|
// for each request line. 1 = request
|
41 |
|
|
// enabled, 0 = request disabled. On reset this
|
42 |
|
|
// register is set to zero (disable all ints).
|
43 |
|
|
// bit zero is specially reserved for nmi
|
44 |
|
|
//
|
45 |
|
|
// 0x10 - write only
|
46 |
|
|
// this register disables the interrupt indicated
|
47 |
|
|
// by the low order four bits of the input data
|
48 |
|
|
//
|
49 |
|
|
// 0x18 - write only
|
50 |
|
|
// this register enables the interrupt indicated
|
51 |
|
|
// by the low order four bits of the input data
|
52 |
|
|
//
|
53 |
|
|
// 0x20 - write only
|
54 |
|
|
// this register indicates which interrupt inputs are
|
55 |
|
|
// edge sensitive
|
56 |
|
|
//
|
57 |
|
|
// 0x28 - write only
|
58 |
|
|
// This register resets the edge sense circuitry
|
59 |
|
|
// indicated by the low order four bits of the input data.
|
60 |
|
|
//
|
61 |
|
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
62 |
|
|
// |WISHBONE Datasheet
|
63 |
|
|
// |WISHBONE SoC Architecture Specification, Revision B.3
|
64 |
|
|
// |
|
65 |
|
|
// |Description: Specifications:
|
66 |
|
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
67 |
|
|
// |General Description: simple programmable interrupt controller
|
68 |
|
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
69 |
|
|
// |Supported Cycles: SLAVE,READ/WRITE
|
70 |
|
|
// | SLAVE,BLOCK READ/WRITE
|
71 |
|
|
// | SLAVE,RMW
|
72 |
|
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
73 |
|
|
// |Data port, size: 32 bit
|
74 |
|
|
// |Data port, granularity: 32 bit
|
75 |
|
|
// |Data port, maximum operand size: 32 bit
|
76 |
|
|
// |Data transfer ordering: Undefined
|
77 |
|
|
// |Data transfer sequencing: Undefined
|
78 |
|
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
79 |
|
|
// |Clock frequency constraints: none
|
80 |
|
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
81 |
|
|
// |Supported signal list and Signal Name WISHBONE equiv.
|
82 |
|
|
// |cross reference to equivalent ack_o ACK_O
|
83 |
|
|
// |WISHBONE signals adr_i(2:1) ADR_I()
|
84 |
|
|
// | clk_i CLK_I
|
85 |
|
|
// | dat_i(15:0) DAT_I()
|
86 |
|
|
// | dat_o(15:0) DAT_O()
|
87 |
|
|
// | cyc_i CYC_I
|
88 |
|
|
// | stb_i STB_I
|
89 |
|
|
// | we_i WE_I
|
90 |
|
|
// |
|
91 |
|
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
92 |
|
|
// |Special requirements:
|
93 |
|
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
94 |
|
|
//
|
95 |
|
|
// Spartan3-4
|
96 |
|
|
// 105 LUTs / 58 slices / 163MHz
|
97 |
|
|
//=============================================================================
|
98 |
|
|
|
99 |
|
|
module Thor_pic
|
100 |
|
|
(
|
101 |
|
|
input rst_i, // reset
|
102 |
|
|
input clk_i, // system clock
|
103 |
|
|
input cyc_i, // cycle valid
|
104 |
|
|
input stb_i, // strobe
|
105 |
|
|
output ack_o, // transfer acknowledge
|
106 |
|
|
input we_i, // write
|
107 |
|
|
input [31:0] adr_i, // address
|
108 |
|
|
input [31:0] dat_i,
|
109 |
|
|
output reg [31:0] dat_o,
|
110 |
|
|
output vol_o, // volatile register selected
|
111 |
|
|
input i1, i2, i3, i4, i5, i6, i7,
|
112 |
|
|
i8, i9, i10, i11, i12, i13, i14, i15,
|
113 |
|
|
output irqo, // normally connected to the processor irq
|
114 |
|
|
input nmii, // nmi input connected to nmi requester
|
115 |
|
|
output nmio, // normally connected to the nmi of cpu
|
116 |
|
|
output [7:0] vecno
|
117 |
|
|
);
|
118 |
|
|
parameter pVECNO = 8'd192;
|
119 |
|
|
parameter pIOAddress = 32'hFFDC_0FC0;
|
120 |
|
|
|
121 |
|
|
reg [15:0] ie; // interrupt enable register
|
122 |
|
|
reg ack1;
|
123 |
|
|
reg [3:0] irqenc;
|
124 |
|
|
wire [15:0] i = {i15,i14,i13,i12,i11,i10,i9,i8,i7,i6,i5,i4,i3,i2,i1,nmii};
|
125 |
|
|
reg [15:0] ib;
|
126 |
|
|
reg [15:0] iedge;
|
127 |
|
|
reg [15:0] rste;
|
128 |
|
|
reg [15:0] es;
|
129 |
|
|
|
130 |
|
|
wire cs = cyc_i && stb_i && adr_i[31:6]==pIOAddress[31:6];
|
131 |
|
|
assign vol_o = cs;
|
132 |
|
|
|
133 |
|
|
always @(posedge clk_i)
|
134 |
|
|
ack1 <= cs;
|
135 |
|
|
assign ack_o = cs ? (we_i ? 1'b1 : ack1) : 1'b0;
|
136 |
|
|
|
137 |
|
|
// write registers
|
138 |
|
|
always @(posedge clk_i)
|
139 |
|
|
if (rst_i) begin
|
140 |
|
|
ie <= 16'h0;
|
141 |
|
|
rste <= 16'h0;
|
142 |
|
|
end
|
143 |
|
|
else begin
|
144 |
18 |
robfinch |
rste <= 16'h0;
|
145 |
3 |
robfinch |
if (cs & we_i) begin
|
146 |
|
|
case (adr_i[5:3])
|
147 |
|
|
3'd0,3'd1:
|
148 |
|
|
begin
|
149 |
|
|
ie[15:0] <= dat_i[15:0];
|
150 |
|
|
end
|
151 |
|
|
3'd2,3'd3:
|
152 |
18 |
robfinch |
ie[dat_i[3:0]] <= adr_i[3];
|
153 |
3 |
robfinch |
3'd4: es <= dat_i[15:0];
|
154 |
|
|
3'd5: rste[dat_i[3:0]] <= 1'b1;
|
155 |
18 |
robfinch |
default: ;
|
156 |
3 |
robfinch |
endcase
|
157 |
|
|
end
|
158 |
|
|
end
|
159 |
|
|
|
160 |
|
|
// read registers
|
161 |
|
|
always @(posedge clk_i)
|
162 |
|
|
begin
|
163 |
|
|
if (irqenc!=4'd0)
|
164 |
|
|
$display("PIC: %d",irqenc);
|
165 |
|
|
if (cs)
|
166 |
|
|
case (adr_i[4:3])
|
167 |
|
|
2'd0: dat_o <= {28'b0,irqenc};
|
168 |
|
|
default: dat_o <= ie;
|
169 |
|
|
endcase
|
170 |
|
|
else
|
171 |
|
|
dat_o <= 32'h0000;
|
172 |
|
|
end
|
173 |
|
|
|
174 |
|
|
assign irqo = irqenc != 4'h0;
|
175 |
|
|
assign nmio = nmii & ie[0];
|
176 |
|
|
|
177 |
|
|
// Edge detect circuit
|
178 |
|
|
integer n;
|
179 |
|
|
always @(posedge clk_i)
|
180 |
|
|
begin
|
181 |
|
|
for (n = 1; n < 16; n = n + 1)
|
182 |
|
|
begin
|
183 |
|
|
ib[n] <= i[n];
|
184 |
|
|
if (i[n] & !ib[n]) iedge[n] <= 1'b1;
|
185 |
|
|
if (rste[n]) iedge[n] <= 1'b0;
|
186 |
|
|
end
|
187 |
|
|
end
|
188 |
|
|
|
189 |
|
|
// irq requests are latched on every rising clock edge to prevent
|
190 |
|
|
// misreads
|
191 |
|
|
// nmi is not encoded
|
192 |
|
|
always @(posedge clk_i)
|
193 |
|
|
begin
|
194 |
|
|
irqenc <= 4'd0;
|
195 |
|
|
for (n = 15; n > 0; n = n - 1)
|
196 |
|
|
if (ie[n] & (es[n] ? iedge[n] : i[n])) irqenc <= n;
|
197 |
|
|
end
|
198 |
|
|
|
199 |
|
|
assign vecno = pVECNO|irqenc;
|
200 |
|
|
|
201 |
|
|
endmodule
|