`timescale 1ns / 1ps
|
`timescale 1ns / 1ps
|
//=============================================================================
|
//=============================================================================
|
// (C) 2013 Robert Finch
|
// (C) 2013 Robert Finch
|
// All rights reserved.
|
// All rights reserved.
|
// robfinch@Opencores.org
|
// robfinch<remove>@Opencores.org
|
//
|
//
|
// RTF65002PIC.v
|
// RTF65002PIC.v
|
//
|
//
|
//
|
//
|
// This source file is free software: you can redistribute it and/or modify
|
// This source file is free software: you can redistribute it and/or modify
|
// it under the terms of the GNU Lesser General Public License as published
|
// it under the terms of the GNU Lesser General Public License as published
|
// by the Free Software Foundation, either version 3 of the License, or
|
// by the Free Software Foundation, either version 3 of the License, or
|
// (at your option) any later version.
|
// (at your option) any later version.
|
//
|
//
|
// This source file is distributed in the hope that it will be useful,
|
// This source file is distributed in the hope that it will be useful,
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// GNU General Public License for more details.
|
// GNU General Public License for more details.
|
//
|
//
|
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
//
|
//
|
//
|
//
|
// Encodes discrete interrupt request signals into four
|
// Encodes discrete interrupt request signals into four
|
// bit code using a priority encoder.
|
// bit code using a priority encoder.
|
//
|
//
|
// reg
|
// reg
|
// 0 - encoded request number (read only)
|
// 0 - encoded request number (read only)
|
// This register contains the number identifying
|
// This register contains the number identifying
|
// the current requester.
|
// the current requester.
|
// the actual number is shifted left three times
|
// the actual number is shifted left three times
|
// before being placed into this register so it may
|
// before being placed into this register so it may
|
// be used directly as an index in OS software. The
|
// be used directly as an index in OS software. The
|
// index may be a mailbox id or index into a jump
|
// index may be a mailbox id or index into a jump
|
// table as desired by the OS. If there is no
|
// table as desired by the OS. If there is no
|
// active request, then this number will be
|
// active request, then this number will be
|
// zero.
|
// zero.
|
// 1 - request enable (read / write)
|
// 1 - request enable (read / write)
|
// this register contains request enable bits
|
// this register contains request enable bits
|
// for each request line. 1 = request
|
// for each request line. 1 = request
|
// enabled, 0 = request disabled. On reset this
|
// enabled, 0 = request disabled. On reset this
|
// register is set to zero (disable all ints).
|
// register is set to zero (disable all ints).
|
// bit zero is specially reserved for nmi
|
// bit zero is specially reserved for nmi
|
//
|
//
|
// 2 - write only
|
// 2 - write only
|
// this register disables the interrupt indicated
|
// this register disables the interrupt indicated
|
// by the low order four bits of the input data
|
// by the low order four bits of the input data
|
//
|
//
|
// 3 - write only
|
// 3 - write only
|
// this register enables the interrupt indicated
|
// this register enables the interrupt indicated
|
// by the low order four bits of the input data
|
// by the low order four bits of the input data
|
//
|
//
|
|
// 4 - write only
|
|
// this register indicates which interrupt inputs are
|
|
// edge sensitive
|
|
//
|
|
// 5 - write only
|
|
// This register resets the edge sense circuitry
|
|
// indicated by the low order four bits of the input data.
|
|
//
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// |WISHBONE Datasheet
|
// |WISHBONE Datasheet
|
// |WISHBONE SoC Architecture Specification, Revision B.3
|
// |WISHBONE SoC Architecture Specification, Revision B.3
|
// |
|
// |
|
// |Description: Specifications:
|
// |Description: Specifications:
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// |General Description: simple programmable interrupt controller
|
// |General Description: simple programmable interrupt controller
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// |Supported Cycles: SLAVE,READ/WRITE
|
// |Supported Cycles: SLAVE,READ/WRITE
|
// | SLAVE,BLOCK READ/WRITE
|
// | SLAVE,BLOCK READ/WRITE
|
// | SLAVE,RMW
|
// | SLAVE,RMW
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// |Data port, size: 32 bit
|
// |Data port, size: 32 bit
|
// |Data port, granularity: 32 bit
|
// |Data port, granularity: 32 bit
|
// |Data port, maximum operand size: 32 bit
|
// |Data port, maximum operand size: 32 bit
|
// |Data transfer ordering: Undefined
|
// |Data transfer ordering: Undefined
|
// |Data transfer sequencing: Undefined
|
// |Data transfer sequencing: Undefined
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// |Clock frequency constraints: none
|
// |Clock frequency constraints: none
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// |Supported signal list and Signal Name WISHBONE equiv.
|
// |Supported signal list and Signal Name WISHBONE equiv.
|
// |cross reference to equivalent ack_o ACK_O
|
// |cross reference to equivalent ack_o ACK_O
|
// |WISHBONE signals adr_i(2:1) ADR_I()
|
// |WISHBONE signals adr_i(2:1) ADR_I()
|
// | clk_i CLK_I
|
// | clk_i CLK_I
|
// | dat_i(15:0) DAT_I()
|
// | dat_i(15:0) DAT_I()
|
// | dat_o(15:0) DAT_O()
|
// | dat_o(15:0) DAT_O()
|
// | cyc_i CYC_I
|
// | cyc_i CYC_I
|
// | stb_i STB_I
|
// | stb_i STB_I
|
// | we_i WE_I
|
// | we_i WE_I
|
// |
|
// |
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// |Special requirements:
|
// |Special requirements:
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
//
|
//
|
// Spartan3-4
|
// Spartan3-4
|
// 105 LUTs / 58 slices / 163MHz
|
// 105 LUTs / 58 slices / 163MHz
|
//=============================================================================
|
//=============================================================================
|
|
|
module RTF65002PIC
|
module RTF65002PIC
|
(
|
(
|
input rst_i, // reset
|
input rst_i, // reset
|
input clk_i, // system clock
|
input clk_i, // system clock
|
input cyc_i, // cycle valid
|
input cyc_i, // cycle valid
|
input stb_i, // strobe
|
input stb_i, // strobe
|
output ack_o, // transfer acknowledge
|
output ack_o, // transfer acknowledge
|
input we_i, // write
|
input we_i, // write
|
input [33:0] adr_i, // address
|
input [33:0] adr_i, // address
|
input [31:0] dat_i,
|
input [31:0] dat_i,
|
output reg [31:0] dat_o,
|
output reg [31:0] dat_o,
|
output vol_o, // volatile register selected
|
output vol_o, // volatile register selected
|
input i1, i2, i3, i4, i5, i6, i7,
|
input i1, i2, i3, i4, i5, i6, i7,
|
i8, i9, i10, i11, i12, i13, i14, i15,
|
i8, i9, i10, i11, i12, i13, i14, i15,
|
output irqo, // normally connected to the processor irq
|
output irqo, // normally connected to the processor irq
|
input nmii, // nmi input connected to nmi requester
|
input nmii, // nmi input connected to nmi requester
|
output nmio, // normally connected to the nmi of cpu
|
output nmio, // normally connected to the nmi of cpu
|
output [8:0] vecno
|
output [8:0] vecno
|
);
|
);
|
parameter pVECNO = 9'd448;
|
parameter pVECNO = 9'd448;
|
parameter pIOAddress = 32'hFFDC_0FF0;
|
parameter pIOAddress = 32'hFFDC_0FF0;
|
|
|
reg [15:0] ie; // interrupt enable register
|
reg [15:0] ie; // interrupt enable register
|
reg ack1;
|
reg ack1;
|
reg [3:0] irqenc;
|
reg [3:0] irqenc;
|
|
wire [15:0] i = {i15,i14,i13,i12,i11,i10,i9,i8,i7,i6,i5,i4,i3,i2,i1,nmii};
|
|
reg [15:0] ib;
|
|
reg [15:0] iedge;
|
|
reg [15:0] rste;
|
|
reg [15:0] es;
|
|
|
wire cs = cyc_i && stb_i && adr_i[33:6]==pIOAddress[31:4];
|
wire cs = cyc_i && stb_i && adr_i[33:6]==pIOAddress[31:4];
|
assign vol_o = cs;
|
assign vol_o = cs;
|
|
|
always @(posedge clk_i)
|
always @(posedge clk_i)
|
ack1 <= cs;
|
ack1 <= cs;
|
assign ack_o = cs ? (we_i ? 1'b1 : ack1) : 1'b0;
|
assign ack_o = cs ? (we_i ? 1'b1 : ack1) : 1'b0;
|
|
|
// write registers
|
// write registers
|
always @(posedge clk_i)
|
always @(posedge clk_i)
|
if (rst_i)
|
if (rst_i) begin
|
ie <= 16'h0;
|
ie <= 16'h0;
|
else if (cs & we_i)
|
rste <= 16'h0;
|
case (adr_i[3:2])
|
end
|
2'd0,2'd1:
|
else begin
|
|
rste <= 16'h0;
|
|
if (cs & we_i) begin
|
|
case (adr_i[4:2])
|
|
3'd0,3'd1:
|
begin
|
begin
|
ie[15:0] <= dat_i[15:0];
|
ie[15:0] <= dat_i[15:0];
|
end
|
end
|
2'd2,2'd3:
|
3'd2,3'd3:
|
ie[dat_i[3:0]] <= adr_i[2];
|
ie[dat_i[3:0]] <= adr_i[2];
|
|
3'd4: es <= dat_i[15:0];
|
|
3'd5: rste[dat_i[3:0]] <= 1'b1;
|
endcase
|
endcase
|
|
end
|
|
end
|
|
|
// read registers
|
// read registers
|
always @(posedge clk_i)
|
always @(posedge clk_i)
|
begin
|
begin
|
if (irqenc!=4'd0)
|
if (irqenc!=4'd0)
|
$display("PIC: %d",irqenc);
|
$display("PIC: %d",irqenc);
|
if (cs)
|
if (cs)
|
case (adr_i[3:2])
|
case (adr_i[3:2])
|
2'd0: dat_o <= {28'b0,irqenc};
|
2'd0: dat_o <= {28'b0,irqenc};
|
default: dat_o <= ie;
|
default: dat_o <= ie;
|
endcase
|
endcase
|
else
|
else
|
dat_o <= 32'h0000;
|
dat_o <= 32'h0000;
|
end
|
end
|
|
|
assign irqo = irqenc != 4'h0;
|
assign irqo = irqenc != 4'h0;
|
assign nmio = nmii & ie[0];
|
assign nmio = nmii & ie[0];
|
|
|
// irq requests are latched on every clock edge to prevent
|
// Edge detect circuit
|
|
integer n;
|
|
always @(posedge clk_i)
|
|
begin
|
|
for (n = 1; n < 16; n = n + 1)
|
|
begin
|
|
ib[n] <= i[n];
|
|
if (i[n] & !ib[n]) iedge[n] <= 1'b1;
|
|
if (rste[n]) iedge[n] <= 1'b0;
|
|
end
|
|
end
|
|
|
|
// irq requests are latched on every rising clock edge to prevent
|
// misreads
|
// misreads
|
// nmi is not encoded
|
// nmi is not encoded
|
always @(posedge clk_i)
|
always @(posedge clk_i)
|
case (1'b1)
|
begin
|
i1&ie[1]: irqenc <= 4'd1;
|
irqenc <= 4'd0;
|
i2&ie[2]: irqenc <= 4'd2;
|
for (n = 15; n > 0; n = n - 1)
|
i3&ie[3]: irqenc <= 4'd3;
|
if (ie[n] & (es[n] ? iedge[n] : i[n])) irqenc <= n;
|
i4&ie[4]: irqenc <= 4'd4;
|
end
|
i5&ie[5]: irqenc <= 4'd5;
|
|
i6&ie[6]: irqenc <= 4'd6;
|
|
i7&ie[7]: irqenc <= 4'd7;
|
|
i8&ie[8]: irqenc <= 4'd8;
|
|
i9&ie[9]: irqenc <= 4'd9;
|
|
i10&ie[10]: irqenc <= 4'd10;
|
|
i11&ie[11]: irqenc <= 4'd11;
|
|
i12&ie[12]: irqenc <= 4'd12;
|
|
i13&ie[13]: irqenc <= 4'd13;
|
|
i14&ie[14]: irqenc <= 4'd14;
|
|
i15&ie[15]: irqenc <= 4'd15;
|
|
default: irqenc <= 4'd0;
|
|
endcase
|
|
|
|
assign vecno = pVECNO|irqenc;
|
assign vecno = pVECNO|irqenc;
|
|
|
endmodule
|
endmodule
|
|
|