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

Subversion Repositories rtf65002

[/] [rtf65002/] [trunk/] [rtl/] [verilog/] [RTF65002PIC.v] - Blame information for rev 32

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 robfinch
`timescale 1ns / 1ps
2
//=============================================================================
3
//      (C) 2013  Robert Finch
4
//      All rights reserved.
5 30 robfinch
//      robfinch<remove>@Opencores.org
6 10 robfinch
//
7
//      RTF65002PIC.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
//      0        - 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
//      1       - 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
//      2   - write only
46
//                      this register disables the interrupt indicated
47
//                      by the low order four bits of the input data
48
//                      
49
//      3       - write only
50
//                      this register enables the interrupt indicated
51
//                      by the low order four bits of the input data
52
//
53 30 robfinch
//      4       - write only
54
//                      this register indicates which interrupt inputs are
55
//                      edge sensitive
56
//
57
//  5   - write only
58
//                      This register resets the edge sense circuitry
59
//                      indicated by the low order four bits of the input data.
60
//
61 10 robfinch
//      +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 13 robfinch
//      |Data port, size:                                       32 bit
74
//      |Data port, granularity:                        32 bit
75
//      |Data port, maximum operand size:       32 bit
76 10 robfinch
//      |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 RTF65002PIC
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 [33: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 [8:0] vecno
117
);
118
parameter pVECNO = 9'd448;
119
parameter pIOAddress = 32'hFFDC_0FF0;
120
 
121
reg [15:0] ie;           // interrupt enable register
122
reg ack1;
123
reg [3:0] irqenc;
124 30 robfinch
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 10 robfinch
 
130
wire cs = cyc_i && stb_i && adr_i[33:6]==pIOAddress[31:4];
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 30 robfinch
        if (rst_i) begin
140 10 robfinch
                ie <= 16'h0;
141 30 robfinch
                rste <= 16'h0;
142
        end
143
        else begin
144
                rste <= 16'h0;
145
                if (cs & we_i) begin
146
                        case (adr_i[4:2])
147
                        3'd0,3'd1:
148
                                begin
149
                                        ie[15:0] <= dat_i[15:0];
150
                                end
151
                        3'd2,3'd3:
152
                                ie[dat_i[3:0]] <= adr_i[2];
153
                        3'd4:   es <= dat_i[15:0];
154
                        3'd5:   rste[dat_i[3:0]] <= 1'b1;
155
                        endcase
156
                end
157
        end
158 10 robfinch
 
159
// read registers
160
always @(posedge clk_i)
161
begin
162
        if (irqenc!=4'd0)
163
                $display("PIC: %d",irqenc);
164
        if (cs)
165
                case (adr_i[3:2])
166
                2'd0:   dat_o <= {28'b0,irqenc};
167
                default:        dat_o <= ie;
168
                endcase
169
        else
170
                dat_o <= 32'h0000;
171
end
172
 
173
assign irqo = irqenc != 4'h0;
174
assign nmio = nmii & ie[0];
175
 
176 30 robfinch
// Edge detect circuit
177
integer n;
178
always @(posedge clk_i)
179
begin
180
        for (n = 1; n < 16; n = n + 1)
181
        begin
182
                ib[n] <= i[n];
183
                if (i[n] & !ib[n]) iedge[n] <= 1'b1;
184
                if (rste[n]) iedge[n] <= 1'b0;
185
        end
186
end
187
 
188
// irq requests are latched on every rising clock edge to prevent
189 10 robfinch
// misreads
190
// nmi is not encoded
191
always @(posedge clk_i)
192 30 robfinch
begin
193
        irqenc <= 4'd0;
194
        for (n = 15; n > 0; n = n - 1)
195
                if (ie[n] & (es[n] ? iedge[n] : i[n])) irqenc <= n;
196
end
197 10 robfinch
 
198
assign vecno = pVECNO|irqenc;
199
 
200
endmodule

powered by: WebSVN 2.1.0

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