1 |
350 |
julius |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// OR1200's Tick Timer ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// This file is part of the OpenRISC 1200 project ////
|
6 |
|
|
//// http://www.opencores.org/cores/or1k/ ////
|
7 |
|
|
//// ////
|
8 |
|
|
//// Description ////
|
9 |
|
|
//// TT according to OR1K architectural specification. ////
|
10 |
|
|
//// ////
|
11 |
|
|
//// To Do: ////
|
12 |
|
|
//// None ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// Author(s): ////
|
15 |
|
|
//// - Damjan Lampret, lampret@opencores.org ////
|
16 |
|
|
//// ////
|
17 |
|
|
//////////////////////////////////////////////////////////////////////
|
18 |
|
|
//// ////
|
19 |
|
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
20 |
|
|
//// ////
|
21 |
|
|
//// This source file may be used and distributed without ////
|
22 |
|
|
//// restriction provided that this copyright statement is not ////
|
23 |
|
|
//// removed from the file and that any derivative work contains ////
|
24 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
25 |
|
|
//// ////
|
26 |
|
|
//// This source file is free software; you can redistribute it ////
|
27 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
28 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
29 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
30 |
|
|
//// later version. ////
|
31 |
|
|
//// ////
|
32 |
|
|
//// This source is distributed in the hope that it will be ////
|
33 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
34 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
35 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
36 |
|
|
//// details. ////
|
37 |
|
|
//// ////
|
38 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
39 |
|
|
//// Public License along with this source; if not, download it ////
|
40 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
41 |
|
|
//// ////
|
42 |
|
|
//////////////////////////////////////////////////////////////////////
|
43 |
|
|
//
|
44 |
|
|
// CVS Revision History
|
45 |
|
|
//
|
46 |
|
|
// $Log: or1200_tt.v,v $
|
47 |
|
|
// Revision 2.0 2010/06/30 11:00:00 ORSoC
|
48 |
|
|
// No update
|
49 |
|
|
//
|
50 |
|
|
// Revision 1.5 2004/06/08 18:17:36 lampret
|
51 |
|
|
// Non-functional changes. Coding style fixes.
|
52 |
|
|
//
|
53 |
|
|
// Revision 1.4 2002/03/29 15:16:56 lampret
|
54 |
|
|
// Some of the warnings fixed.
|
55 |
|
|
//
|
56 |
|
|
// Revision 1.3 2002/02/12 01:33:47 lampret
|
57 |
|
|
// No longer using async rst as sync reset for the counter.
|
58 |
|
|
//
|
59 |
|
|
// Revision 1.2 2002/01/28 01:16:00 lampret
|
60 |
|
|
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
|
61 |
|
|
//
|
62 |
|
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
63 |
|
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
64 |
|
|
//
|
65 |
|
|
// Revision 1.10 2001/11/13 10:00:49 lampret
|
66 |
|
|
// Fixed tick timer interrupt reporting by using TTCR[IP] bit.
|
67 |
|
|
//
|
68 |
|
|
// Revision 1.9 2001/11/10 03:43:57 lampret
|
69 |
|
|
// Fixed exceptions.
|
70 |
|
|
//
|
71 |
|
|
// Revision 1.8 2001/10/21 17:57:16 lampret
|
72 |
|
|
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
|
73 |
|
|
//
|
74 |
|
|
// Revision 1.7 2001/10/14 13:12:10 lampret
|
75 |
|
|
// MP3 version.
|
76 |
|
|
//
|
77 |
|
|
// Revision 1.1.1.1 2001/10/06 10:18:35 igorm
|
78 |
|
|
// no message
|
79 |
|
|
//
|
80 |
|
|
// Revision 1.2 2001/08/09 13:39:33 lampret
|
81 |
|
|
// Major clean-up.
|
82 |
|
|
//
|
83 |
|
|
// Revision 1.1 2001/07/20 00:46:23 lampret
|
84 |
|
|
// Development version of RTL. Libraries are missing.
|
85 |
|
|
//
|
86 |
|
|
//
|
87 |
|
|
|
88 |
|
|
// synopsys translate_off
|
89 |
|
|
`include "timescale.v"
|
90 |
|
|
// synopsys translate_on
|
91 |
|
|
`include "or1200_defines.v"
|
92 |
|
|
|
93 |
|
|
module or1200_tt(
|
94 |
|
|
// RISC Internal Interface
|
95 |
|
|
clk, rst, du_stall,
|
96 |
|
|
spr_cs, spr_write, spr_addr, spr_dat_i, spr_dat_o,
|
97 |
|
|
intr
|
98 |
|
|
);
|
99 |
|
|
|
100 |
|
|
//
|
101 |
|
|
// RISC Internal Interface
|
102 |
|
|
//
|
103 |
|
|
input clk; // Clock
|
104 |
|
|
input rst; // Reset
|
105 |
|
|
input du_stall; // DU stall
|
106 |
|
|
input spr_cs; // SPR CS
|
107 |
|
|
input spr_write; // SPR Write
|
108 |
|
|
input [31:0] spr_addr; // SPR Address
|
109 |
|
|
input [31:0] spr_dat_i; // SPR Write Data
|
110 |
|
|
output [31:0] spr_dat_o; // SPR Read Data
|
111 |
|
|
output intr; // Interrupt output
|
112 |
|
|
|
113 |
|
|
`ifdef OR1200_TT_IMPLEMENTED
|
114 |
|
|
|
115 |
|
|
//
|
116 |
|
|
// TT Mode Register bits (or no register)
|
117 |
|
|
//
|
118 |
|
|
`ifdef OR1200_TT_TTMR
|
119 |
|
|
reg [31:0] ttmr; // TTMR bits
|
120 |
|
|
`else
|
121 |
|
|
wire [31:0] ttmr; // No TTMR register
|
122 |
|
|
`endif
|
123 |
|
|
|
124 |
|
|
//
|
125 |
|
|
// TT Count Register bits (or no register)
|
126 |
|
|
//
|
127 |
|
|
`ifdef OR1200_TT_TTCR
|
128 |
|
|
reg [31:0] ttcr; // TTCR bits
|
129 |
|
|
`else
|
130 |
|
|
wire [31:0] ttcr; // No TTCR register
|
131 |
|
|
`endif
|
132 |
|
|
|
133 |
|
|
//
|
134 |
|
|
// Internal wires & regs
|
135 |
|
|
//
|
136 |
|
|
wire ttmr_sel; // TTMR select
|
137 |
|
|
wire ttcr_sel; // TTCR select
|
138 |
|
|
wire match; // Asserted when TTMR[TP]
|
139 |
|
|
// is equal to TTCR[27:0]
|
140 |
|
|
wire restart; // Restart counter when asserted
|
141 |
|
|
wire stop; // Stop counter when asserted
|
142 |
|
|
reg [31:0] spr_dat_o; // SPR data out
|
143 |
|
|
|
144 |
|
|
//
|
145 |
|
|
// TT registers address decoder
|
146 |
|
|
//
|
147 |
|
|
assign ttmr_sel = (spr_cs && (spr_addr[`OR1200_TTOFS_BITS] == `OR1200_TT_OFS_TTMR)) ? 1'b1 : 1'b0;
|
148 |
|
|
assign ttcr_sel = (spr_cs && (spr_addr[`OR1200_TTOFS_BITS] == `OR1200_TT_OFS_TTCR)) ? 1'b1 : 1'b0;
|
149 |
|
|
|
150 |
|
|
//
|
151 |
|
|
// Write to TTMR or update of TTMR[IP] bit
|
152 |
|
|
//
|
153 |
|
|
`ifdef OR1200_TT_TTMR
|
154 |
358 |
julius |
always @(posedge clk or `OR1200_RST_EVENT rst)
|
155 |
|
|
if (rst == `OR1200_RST_VALUE)
|
156 |
350 |
julius |
ttmr <= 32'b0;
|
157 |
|
|
else if (ttmr_sel && spr_write)
|
158 |
|
|
ttmr <= spr_dat_i;
|
159 |
|
|
else if (ttmr[`OR1200_TT_TTMR_IE])
|
160 |
|
|
ttmr[`OR1200_TT_TTMR_IP] <= ttmr[`OR1200_TT_TTMR_IP] | (match & ttmr[`OR1200_TT_TTMR_IE]);
|
161 |
|
|
`else
|
162 |
|
|
assign ttmr = {2'b11, 30'b0}; // TTMR[M] = 0x3
|
163 |
|
|
`endif
|
164 |
|
|
|
165 |
|
|
//
|
166 |
|
|
// Write to or increment of TTCR
|
167 |
|
|
//
|
168 |
|
|
`ifdef OR1200_TT_TTCR
|
169 |
358 |
julius |
always @(posedge clk or `OR1200_RST_EVENT rst)
|
170 |
|
|
if (rst == `OR1200_RST_VALUE)
|
171 |
350 |
julius |
ttcr <= 32'b0;
|
172 |
|
|
else if (restart)
|
173 |
|
|
ttcr <= 32'b0;
|
174 |
|
|
else if (ttcr_sel && spr_write)
|
175 |
|
|
ttcr <= spr_dat_i;
|
176 |
|
|
else if (!stop)
|
177 |
|
|
ttcr <= ttcr + 32'd1;
|
178 |
|
|
`else
|
179 |
|
|
assign ttcr = 32'b0;
|
180 |
|
|
`endif
|
181 |
|
|
|
182 |
|
|
//
|
183 |
|
|
// Read TT registers
|
184 |
|
|
//
|
185 |
|
|
always @(spr_addr or ttmr or ttcr)
|
186 |
|
|
case (spr_addr[`OR1200_TTOFS_BITS]) // synopsys parallel_case
|
187 |
|
|
`ifdef OR1200_TT_READREGS
|
188 |
|
|
`OR1200_TT_OFS_TTMR: spr_dat_o = ttmr;
|
189 |
|
|
`endif
|
190 |
|
|
default: spr_dat_o = ttcr;
|
191 |
|
|
endcase
|
192 |
|
|
|
193 |
|
|
//
|
194 |
|
|
// A match when TTMR[TP] is equal to TTCR[27:0]
|
195 |
|
|
//
|
196 |
|
|
assign match = (ttmr[`OR1200_TT_TTMR_TP] == ttcr[27:0]) ? 1'b1 : 1'b0;
|
197 |
|
|
|
198 |
|
|
//
|
199 |
|
|
// Restart when match and TTMR[M]==0x1
|
200 |
|
|
//
|
201 |
|
|
assign restart = match && (ttmr[`OR1200_TT_TTMR_M] == 2'b01);
|
202 |
|
|
|
203 |
|
|
//
|
204 |
|
|
// Stop when match and TTMR[M]==0x2 or when TTMR[M]==0x0 or when RISC is stalled by debug unit
|
205 |
|
|
//
|
206 |
|
|
assign stop = match & (ttmr[`OR1200_TT_TTMR_M] == 2'b10) | (ttmr[`OR1200_TT_TTMR_M] == 2'b00) | du_stall;
|
207 |
|
|
|
208 |
|
|
//
|
209 |
|
|
// Generate an interrupt request
|
210 |
|
|
//
|
211 |
|
|
assign intr = ttmr[`OR1200_TT_TTMR_IP];
|
212 |
|
|
|
213 |
|
|
`else
|
214 |
|
|
|
215 |
|
|
//
|
216 |
|
|
// When TT is not implemented, drive all outputs as would when TT is disabled
|
217 |
|
|
//
|
218 |
|
|
assign intr = 1'b0;
|
219 |
|
|
|
220 |
|
|
//
|
221 |
|
|
// Read TT registers
|
222 |
|
|
//
|
223 |
|
|
`ifdef OR1200_TT_READREGS
|
224 |
|
|
assign spr_dat_o = 32'b0;
|
225 |
|
|
`endif
|
226 |
|
|
|
227 |
|
|
`endif
|
228 |
|
|
|
229 |
|
|
endmodule
|