1 |
2 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// WISHBONE revB.2 compliant Xgate Coprocessor - Test Bench
|
4 |
|
|
//
|
5 |
|
|
// Author: Bob Hayes
|
6 |
|
|
// rehayes@opencores.org
|
7 |
|
|
//
|
8 |
|
|
// Downloaded from: http://www.opencores.org/projects/xgate.....
|
9 |
|
|
//
|
10 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
11 |
|
|
// Copyright (c) 2009, Robert Hayes
|
12 |
|
|
//
|
13 |
|
|
// This source file is free software: you can redistribute it and/or modify
|
14 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
15 |
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
16 |
|
|
// (at your option) any later version.
|
17 |
|
|
//
|
18 |
|
|
// Supplemental terms.
|
19 |
|
|
// * Redistributions of source code must retain the above copyright
|
20 |
|
|
// notice, this list of conditions and the following disclaimer.
|
21 |
|
|
// * Neither the name of the <organization> nor the
|
22 |
|
|
// names of its contributors may be used to endorse or promote products
|
23 |
|
|
// derived from this software without specific prior written permission.
|
24 |
|
|
//
|
25 |
|
|
// THIS SOFTWARE IS PROVIDED BY Robert Hayes ''AS IS'' AND ANY
|
26 |
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
27 |
|
|
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
28 |
|
|
// DISCLAIMED. IN NO EVENT SHALL Robert Hayes BE LIABLE FOR ANY
|
29 |
|
|
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
30 |
|
|
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
31 |
|
|
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
32 |
|
|
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
33 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
34 |
|
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35 |
|
|
//
|
36 |
|
|
// You should have received a copy of the GNU General Public License
|
37 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
38 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
`include "timescale.v"
|
43 |
|
|
|
44 |
|
|
module tst_bench_top();
|
45 |
|
|
|
46 |
|
|
parameter MAX_CHANNEL = 127; // Max XGATE Interrupt Channel Number
|
47 |
5 |
rehayes |
parameter STOP_ON_ERROR = 1'b0;
|
48 |
60 |
rehayes |
parameter MAX_VECTOR = 8000;
|
49 |
21 |
rehayes |
|
50 |
41 |
rehayes |
parameter L_BYTE = 2'b01;
|
51 |
|
|
parameter H_BYTE = 2'b10;
|
52 |
36 |
rehayes |
parameter WORD = 2'b11;
|
53 |
21 |
rehayes |
|
54 |
2 |
rehayes |
|
55 |
|
|
// Name Address Locations
|
56 |
54 |
rehayes |
parameter XGATE_BASE = 24'h1000;
|
57 |
41 |
rehayes |
parameter XGATE_XGMCTL = XGATE_BASE + 6'h00;
|
58 |
|
|
parameter XGATE_XGCHID = XGATE_BASE + 6'h02;
|
59 |
|
|
parameter XGATE_XGISPHI = XGATE_BASE + 6'h04;
|
60 |
|
|
parameter XGATE_XGISPLO = XGATE_BASE + 6'h06;
|
61 |
|
|
parameter XGATE_XGVBR = XGATE_BASE + 6'h08;
|
62 |
|
|
parameter XGATE_XGIF_7 = XGATE_BASE + 6'h0a;
|
63 |
|
|
parameter XGATE_XGIF_6 = XGATE_BASE + 6'h0c;
|
64 |
|
|
parameter XGATE_XGIF_5 = XGATE_BASE + 6'h0e;
|
65 |
|
|
parameter XGATE_XGIF_4 = XGATE_BASE + 6'h10;
|
66 |
|
|
parameter XGATE_XGIF_3 = XGATE_BASE + 6'h12;
|
67 |
|
|
parameter XGATE_XGIF_2 = XGATE_BASE + 6'h14;
|
68 |
|
|
parameter XGATE_XGIF_1 = XGATE_BASE + 6'h16;
|
69 |
|
|
parameter XGATE_XGIF_0 = XGATE_BASE + 6'h18;
|
70 |
|
|
parameter XGATE_XGSWT = XGATE_BASE + 6'h1a;
|
71 |
|
|
parameter XGATE_XGSEM = XGATE_BASE + 6'h1c;
|
72 |
|
|
parameter XGATE_RES1 = XGATE_BASE + 6'h1e;
|
73 |
|
|
parameter XGATE_XGCCR = XGATE_BASE + 6'h20;
|
74 |
|
|
parameter XGATE_XGPC = XGATE_BASE + 6'h22;
|
75 |
|
|
parameter XGATE_RES2 = XGATE_BASE + 6'h24;
|
76 |
|
|
parameter XGATE_XGR1 = XGATE_BASE + 6'h26;
|
77 |
|
|
parameter XGATE_XGR2 = XGATE_BASE + 6'h28;
|
78 |
|
|
parameter XGATE_XGR3 = XGATE_BASE + 6'h2a;
|
79 |
|
|
parameter XGATE_XGR4 = XGATE_BASE + 6'h2c;
|
80 |
|
|
parameter XGATE_XGR5 = XGATE_BASE + 6'h2e;
|
81 |
|
|
parameter XGATE_XGR6 = XGATE_BASE + 6'h30;
|
82 |
|
|
parameter XGATE_XGR7 = XGATE_BASE + 6'h32;
|
83 |
21 |
rehayes |
|
84 |
11 |
rehayes |
// Define bits in XGATE Control Register
|
85 |
|
|
parameter XGMCTL_XGEM = 16'h8000;
|
86 |
|
|
parameter XGMCTL_XGFRZM = 16'h4000;
|
87 |
|
|
parameter XGMCTL_XGDBGM = 15'h2000;
|
88 |
|
|
parameter XGMCTL_XGSSM = 15'h1000;
|
89 |
|
|
parameter XGMCTL_XGFACTM = 15'h0800;
|
90 |
|
|
parameter XGMCTL_XGBRKIEM = 15'h0400;
|
91 |
|
|
parameter XGMCTL_XGSWEIFM = 15'h0200;
|
92 |
|
|
parameter XGMCTL_XGIEM = 15'h0100;
|
93 |
|
|
parameter XGMCTL_XGE = 16'h0080;
|
94 |
|
|
parameter XGMCTL_XGFRZ = 16'h0040;
|
95 |
|
|
parameter XGMCTL_XGDBG = 15'h0020;
|
96 |
|
|
parameter XGMCTL_XGSS = 15'h0010;
|
97 |
|
|
parameter XGMCTL_XGFACT = 15'h0008;
|
98 |
|
|
parameter XGMCTL_XGBRKIE = 15'h0004;
|
99 |
|
|
parameter XGMCTL_XGSWEIF = 15'h0002;
|
100 |
|
|
parameter XGMCTL_XGIE = 15'h0001;
|
101 |
2 |
rehayes |
|
102 |
5 |
rehayes |
parameter CHECK_POINT = 16'h8000;
|
103 |
|
|
parameter CHANNEL_ACK = CHECK_POINT + 2;
|
104 |
|
|
parameter CHANNEL_ERR = CHECK_POINT + 4;
|
105 |
36 |
rehayes |
|
106 |
54 |
rehayes |
parameter SYS_RAM_BASE = 24'h0000_0000;
|
107 |
36 |
rehayes |
|
108 |
|
|
//
|
109 |
|
|
// wires && regs
|
110 |
|
|
//
|
111 |
|
|
reg mstr_test_clk;
|
112 |
|
|
reg [19:0] vector;
|
113 |
|
|
reg [15:0] error_count;
|
114 |
|
|
reg [ 7:0] test_num;
|
115 |
|
|
|
116 |
|
|
reg [15:0] q, qq;
|
117 |
21 |
rehayes |
|
118 |
36 |
rehayes |
reg rstn;
|
119 |
|
|
reg sync_reset;
|
120 |
|
|
reg por_reset_b;
|
121 |
|
|
reg stop_mode;
|
122 |
|
|
reg wait_mode;
|
123 |
|
|
reg debug_mode;
|
124 |
|
|
reg scantestmode;
|
125 |
21 |
rehayes |
|
126 |
54 |
rehayes |
wire [15:0] dat_i;
|
127 |
|
|
wire ack;
|
128 |
36 |
rehayes |
|
129 |
|
|
reg [MAX_CHANNEL:0] channel_req; // XGATE Interrupt inputs
|
130 |
|
|
wire [MAX_CHANNEL:0] xgif; // XGATE Interrupt outputs
|
131 |
|
|
wire [ 7:0] xgswt; // XGATE Software Trigger outputs
|
132 |
|
|
wire xg_sw_irq; // Xgate Software Error interrupt
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
wire [15:0] wbm_dat_o; // WISHBONE Master Mode data output from XGATE
|
136 |
|
|
wire [15:0] wbm_dat_i; // WISHBONE Master Mode data input to XGATE
|
137 |
|
|
wire [15:0] wbm_adr_o; // WISHBONE Master Mode address output from XGATE
|
138 |
|
|
wire [ 1:0] wbm_sel_o;
|
139 |
|
|
|
140 |
|
|
reg mem_wait_state_enable;
|
141 |
|
|
|
142 |
|
|
wire [15:0] tb_ram_out;
|
143 |
|
|
|
144 |
11 |
rehayes |
// Registers used to mirror internal registers
|
145 |
36 |
rehayes |
reg [15:0] data_xgmctl;
|
146 |
|
|
reg [15:0] data_xgchid;
|
147 |
|
|
reg [15:0] data_xgvbr;
|
148 |
|
|
reg [15:0] data_xgswt;
|
149 |
|
|
reg [15:0] data_xgsem;
|
150 |
2 |
rehayes |
|
151 |
36 |
rehayes |
wire sys_cyc;
|
152 |
|
|
wire sys_stb;
|
153 |
|
|
wire sys_we;
|
154 |
|
|
wire [ 1:0] sys_sel;
|
155 |
54 |
rehayes |
wire [23:0] sys_adr;
|
156 |
36 |
rehayes |
wire [15:0] sys_dout;
|
157 |
54 |
rehayes |
wire [15:0] sys_din;
|
158 |
36 |
rehayes |
|
159 |
|
|
wire host_ack;
|
160 |
|
|
wire [15:0] host_dout;
|
161 |
|
|
wire host_cyc;
|
162 |
|
|
wire host_stb;
|
163 |
|
|
wire host_we;
|
164 |
|
|
wire [ 1:0] host_sel;
|
165 |
54 |
rehayes |
wire [23:0] host_adr;
|
166 |
36 |
rehayes |
wire [15:0] host_din;
|
167 |
|
|
|
168 |
|
|
wire xgate_ack;
|
169 |
|
|
wire [15:0] xgate_dout;
|
170 |
|
|
wire xgate_cyc;
|
171 |
|
|
wire xgate_stb;
|
172 |
|
|
wire xgate_we;
|
173 |
|
|
wire [ 1:0] xgate_sel;
|
174 |
|
|
wire [15:0] xgate_adr;
|
175 |
|
|
wire [15:0] xgate_din;
|
176 |
|
|
|
177 |
|
|
wire xgate_s_stb;
|
178 |
|
|
wire xgate_s_ack;
|
179 |
|
|
wire [15:0] xgate_s_dout;
|
180 |
|
|
|
181 |
|
|
wire slv2_stb;
|
182 |
54 |
rehayes |
wire ram_sel;
|
183 |
36 |
rehayes |
wire [15:0] ram_dout;
|
184 |
|
|
|
185 |
2 |
rehayes |
// initial values and testbench setup
|
186 |
|
|
initial
|
187 |
|
|
begin
|
188 |
|
|
mstr_test_clk = 0;
|
189 |
|
|
vector = 0;
|
190 |
|
|
test_num = 0;
|
191 |
|
|
por_reset_b = 0;
|
192 |
36 |
rehayes |
stop_mode = 0;
|
193 |
|
|
wait_mode = 0;
|
194 |
2 |
rehayes |
debug_mode = 0;
|
195 |
|
|
scantestmode = 0;
|
196 |
5 |
rehayes |
error_count = 0;
|
197 |
11 |
rehayes |
mem_wait_state_enable = 0;
|
198 |
2 |
rehayes |
// channel_req = 0;
|
199 |
|
|
|
200 |
|
|
`ifdef WAVES
|
201 |
|
|
$shm_open("waves");
|
202 |
|
|
$shm_probe("AS",tst_bench_top,"AS");
|
203 |
|
|
$display("\nINFO: Signal dump enabled ...\n\n");
|
204 |
|
|
`endif
|
205 |
|
|
|
206 |
|
|
`ifdef WAVES_V
|
207 |
|
|
$dumpfile ("xgate_wave_dump.lxt");
|
208 |
|
|
$dumpvars (0, tst_bench_top);
|
209 |
|
|
$dumpon;
|
210 |
|
|
$display("\nINFO: VCD Signal dump enabled ...\n\n");
|
211 |
|
|
`endif
|
212 |
|
|
|
213 |
|
|
end
|
214 |
|
|
|
215 |
|
|
// generate clock
|
216 |
|
|
always #20 mstr_test_clk = ~mstr_test_clk;
|
217 |
|
|
|
218 |
5 |
rehayes |
// Keep a count of how many clocks we've simulated
|
219 |
2 |
rehayes |
always @(posedge mstr_test_clk)
|
220 |
11 |
rehayes |
begin
|
221 |
|
|
vector <= vector + 1;
|
222 |
|
|
if (vector > MAX_VECTOR)
|
223 |
21 |
rehayes |
begin
|
224 |
|
|
error_count <= error_count + 1;
|
225 |
|
|
$display("\n ------ !!!!! Simulation Timeout at vector=%d\n -------", vector);
|
226 |
|
|
wrap_up;
|
227 |
|
|
end
|
228 |
11 |
rehayes |
end
|
229 |
2 |
rehayes |
|
230 |
50 |
rehayes |
// Add up errors that come from WISHBONE read compares
|
231 |
36 |
rehayes |
always @host.cmp_error_detect
|
232 |
21 |
rehayes |
begin
|
233 |
|
|
error_count <= error_count + 1;
|
234 |
|
|
end
|
235 |
11 |
rehayes |
|
236 |
54 |
rehayes |
always @(posedge error_pulse) //channel_ack_wrt
|
237 |
2 |
rehayes |
begin
|
238 |
54 |
rehayes |
#1;
|
239 |
5 |
rehayes |
error_count = error_count + 1;
|
240 |
|
|
if (STOP_ON_ERROR == 1'b1)
|
241 |
21 |
rehayes |
wrap_up;
|
242 |
5 |
rehayes |
end
|
243 |
|
|
|
244 |
2 |
rehayes |
wire [ 6:0] current_active_channel = xgate.risc.xgchid;
|
245 |
54 |
rehayes |
always @(posedge ack_pulse) //channel_ack_wrt
|
246 |
2 |
rehayes |
clear_channel(current_active_channel);
|
247 |
21 |
rehayes |
|
248 |
36 |
rehayes |
|
249 |
2 |
rehayes |
|
250 |
36 |
rehayes |
// Testbench RAM for Xgate program storage and Load/Store instruction tests
|
251 |
|
|
ram p_ram
|
252 |
|
|
(
|
253 |
|
|
// Outputs
|
254 |
|
|
.ram_out( ram_dout ),
|
255 |
|
|
// inputs
|
256 |
54 |
rehayes |
.address( sys_adr[15:0] ),
|
257 |
36 |
rehayes |
.ram_in( sys_dout ),
|
258 |
|
|
.we( sys_we ),
|
259 |
54 |
rehayes |
.ce( ram_sel ),
|
260 |
36 |
rehayes |
.stb( mstr_test_clk ),
|
261 |
54 |
rehayes |
.sel( sys_sel )
|
262 |
36 |
rehayes |
);
|
263 |
|
|
|
264 |
|
|
// hookup wishbone master model
|
265 |
54 |
rehayes |
wb_master_model #(.dwidth(16), .awidth(24))
|
266 |
36 |
rehayes |
host(
|
267 |
|
|
// Outputs
|
268 |
|
|
.cyc( host_cyc ),
|
269 |
|
|
.stb( host_stb ),
|
270 |
|
|
.we( host_we ),
|
271 |
|
|
.sel( host_sel ),
|
272 |
|
|
.adr( host_adr ),
|
273 |
|
|
.dout( host_dout ),
|
274 |
|
|
// inputs
|
275 |
54 |
rehayes |
.din(sys_din),
|
276 |
36 |
rehayes |
.clk(mstr_test_clk),
|
277 |
|
|
.ack(host_ack),
|
278 |
|
|
.rst(rstn),
|
279 |
|
|
.err(1'b0),
|
280 |
|
|
.rty(1'b0)
|
281 |
|
|
);
|
282 |
|
|
|
283 |
|
|
bus_arbitration #(.dwidth(16),
|
284 |
54 |
rehayes |
.awidth(24),
|
285 |
|
|
.ram_base(0),
|
286 |
|
|
.ram_size(17'h10000),
|
287 |
|
|
.slv1_base(XGATE_BASE),
|
288 |
|
|
.slv1_size(64),
|
289 |
|
|
.slv2_base(CHECK_POINT),
|
290 |
|
|
.slv2_size(8))
|
291 |
36 |
rehayes |
arb(
|
292 |
|
|
// System bus I/O
|
293 |
|
|
.sys_cyc( sys_cyc ),
|
294 |
|
|
.sys_stb( sys_stb ),
|
295 |
|
|
.sys_we( sys_we ),
|
296 |
|
|
.sys_sel( sys_sel ),
|
297 |
|
|
.sys_adr( sys_adr ),
|
298 |
|
|
.sys_dout( sys_dout ),
|
299 |
54 |
rehayes |
.sys_din( sys_din ),
|
300 |
36 |
rehayes |
// Host bus I/O
|
301 |
|
|
.host_ack( host_ack ),
|
302 |
|
|
.host_dout( host_din ),
|
303 |
|
|
.host_cyc( host_cyc ),
|
304 |
|
|
.host_stb( host_stb ),
|
305 |
|
|
.host_we( host_we ),
|
306 |
|
|
.host_sel( host_sel ),
|
307 |
|
|
.host_adr( host_adr ),
|
308 |
|
|
.host_din( host_dout ),
|
309 |
|
|
// Alternate Bus Master #1 Bus I/O
|
310 |
|
|
.alt1_ack( xgate_ack ),
|
311 |
|
|
.alt1_cyc( wbm_cyc_o ),
|
312 |
|
|
.alt1_stb( wbm_stb_o ),
|
313 |
|
|
.alt1_we( wbm_we_o ),
|
314 |
|
|
.alt1_sel( wbm_sel_o ),
|
315 |
54 |
rehayes |
.alt1_adr( {8'h00, wbm_adr_o} ),
|
316 |
36 |
rehayes |
.alt1_din( wbm_dat_o ),
|
317 |
54 |
rehayes |
// RAM
|
318 |
|
|
.ram_sel( ram_sel ),
|
319 |
|
|
.ram_dout( ram_dout ),
|
320 |
36 |
rehayes |
// Slave #1 Bus I/O
|
321 |
|
|
.slv1_stb( xgate_s_stb ),
|
322 |
|
|
.slv1_ack( xgate_s_ack ),
|
323 |
|
|
.slv1_din( xgate_s_dout ),
|
324 |
|
|
// Slave #2 Bus I/O
|
325 |
|
|
.slv2_stb( slv2_stb ),
|
326 |
54 |
rehayes |
.slv2_ack( test_reg_ack ),
|
327 |
36 |
rehayes |
.slv2_din( ram_dout ),
|
328 |
|
|
// Miscellaneous
|
329 |
|
|
.host_clk( mstr_test_clk ),
|
330 |
|
|
.risc_clk( mstr_test_clk ),
|
331 |
|
|
.rst( rstn ), // No Connect
|
332 |
|
|
.err( 1'b0 ), // No Connect
|
333 |
|
|
.rty( 1'b0 ) // No Connect
|
334 |
|
|
);
|
335 |
54 |
rehayes |
|
336 |
5 |
rehayes |
// hookup XGATE core - Parameters take all default values
|
337 |
54 |
rehayes |
xgate_top #(.SINGLE_CYCLE(1'b0),
|
338 |
21 |
rehayes |
.MAX_CHANNEL(MAX_CHANNEL)) // Max XGATE Interrupt Channel Number
|
339 |
2 |
rehayes |
xgate(
|
340 |
5 |
rehayes |
// Wishbone slave interface
|
341 |
|
|
.wbs_clk_i( mstr_test_clk ),
|
342 |
|
|
.wbs_rst_i( 1'b0 ), // sync_reset
|
343 |
|
|
.arst_i( rstn ), // async resetn
|
344 |
41 |
rehayes |
.wbs_adr_i( sys_adr[5:1] ),
|
345 |
36 |
rehayes |
.wbs_dat_i( sys_dout ),
|
346 |
|
|
.wbs_dat_o( xgate_s_dout ),
|
347 |
|
|
.wbs_we_i( sys_we ),
|
348 |
|
|
.wbs_stb_i( xgate_s_stb ),
|
349 |
|
|
.wbs_cyc_i( sys_cyc ),
|
350 |
|
|
.wbs_sel_i( sys_sel ),
|
351 |
|
|
.wbs_ack_o( xgate_s_ack ),
|
352 |
54 |
rehayes |
.wbs_err_o( wbs_err_o ),
|
353 |
2 |
rehayes |
|
354 |
5 |
rehayes |
// Wishbone master Signals
|
355 |
21 |
rehayes |
.wbm_dat_o( wbm_dat_o ),
|
356 |
5 |
rehayes |
.wbm_we_o( wbm_we_o ),
|
357 |
|
|
.wbm_stb_o( wbm_stb_o ),
|
358 |
|
|
.wbm_cyc_o( wbm_cyc_o ),
|
359 |
|
|
.wbm_sel_o( wbm_sel_o ),
|
360 |
21 |
rehayes |
.wbm_adr_o( wbm_adr_o ),
|
361 |
54 |
rehayes |
.wbm_dat_i( sys_din ),
|
362 |
|
|
.wbm_ack_i( xgate_ack ),
|
363 |
5 |
rehayes |
|
364 |
21 |
rehayes |
.xgif( xgif ), // XGATE Interrupt Flag output
|
365 |
|
|
.xg_sw_irq( xg_sw_irq ), // XGATE Software Error Interrupt Flag output
|
366 |
|
|
.xgswt( xgswt ),
|
367 |
2 |
rehayes |
.risc_clk( mstr_test_clk ),
|
368 |
21 |
rehayes |
.chan_req_i( {channel_req[MAX_CHANNEL:40], xgswt, channel_req[31:0]} ),
|
369 |
2 |
rehayes |
.scantestmode( scantestmode )
|
370 |
|
|
);
|
371 |
|
|
|
372 |
54 |
rehayes |
tb_slave #(.DWIDTH(16),
|
373 |
|
|
.SINGLE_CYCLE(1'b1))
|
374 |
|
|
tb_slave_regs(
|
375 |
|
|
// wishbone interface
|
376 |
|
|
.wb_clk_i( mstr_test_clk ),
|
377 |
|
|
.wb_rst_i( 1'b0 ),
|
378 |
|
|
.arst_i( rstn ),
|
379 |
|
|
.wb_adr_i( sys_adr[3:1] ),
|
380 |
|
|
.wb_dat_i( sys_dout ),
|
381 |
|
|
.wb_dat_o(),
|
382 |
|
|
.wb_we_i( sys_we ),
|
383 |
|
|
.wb_stb_i( slv2_stb ),
|
384 |
|
|
.wb_cyc_i( sys_cyc ),
|
385 |
|
|
.wb_sel_i( sys_sel ),
|
386 |
|
|
.wb_ack_o( test_reg_ack ),
|
387 |
2 |
rehayes |
|
388 |
54 |
rehayes |
.ack_pulse( ack_pulse ),
|
389 |
|
|
.error_pulse( error_pulse ),
|
390 |
|
|
.vector( vector )
|
391 |
|
|
);
|
392 |
2 |
rehayes |
|
393 |
54 |
rehayes |
|
394 |
|
|
|
395 |
2 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
396 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
397 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
398 |
|
|
|
399 |
54 |
rehayes |
// Main Test Program
|
400 |
2 |
rehayes |
initial
|
401 |
|
|
begin
|
402 |
36 |
rehayes |
$display("\nstatus at time: %t Testbench started", $time);
|
403 |
2 |
rehayes |
|
404 |
36 |
rehayes |
// reset system
|
405 |
|
|
rstn = 1'b1; // negate reset
|
406 |
|
|
channel_req = 1; //
|
407 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
408 |
|
|
sync_reset = 1'b1; // Make the sync reset 1 clock cycle long
|
409 |
|
|
#2; // move the async reset away from the clock edge
|
410 |
|
|
rstn = 1'b0; // assert async reset
|
411 |
|
|
#5; // Keep the async reset pulse with less than a clock cycle
|
412 |
|
|
rstn = 1'b1; // negate async reset
|
413 |
|
|
por_reset_b = 1'b1;
|
414 |
|
|
channel_req = 0; //
|
415 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
416 |
|
|
sync_reset = 1'b0;
|
417 |
|
|
channel_req = 0; //
|
418 |
2 |
rehayes |
|
419 |
36 |
rehayes |
$display("\nstatus at time: %t done reset", $time);
|
420 |
21 |
rehayes |
|
421 |
36 |
rehayes |
test_inst_set;
|
422 |
21 |
rehayes |
|
423 |
36 |
rehayes |
test_debug_mode;
|
424 |
2 |
rehayes |
|
425 |
36 |
rehayes |
test_debug_bit;
|
426 |
21 |
rehayes |
|
427 |
36 |
rehayes |
test_chid_debug;
|
428 |
21 |
rehayes |
|
429 |
41 |
rehayes |
reg_test_16;
|
430 |
|
|
|
431 |
54 |
rehayes |
//host_ram;
|
432 |
|
|
|
433 |
36 |
rehayes |
// End testing
|
434 |
|
|
wrap_up;
|
435 |
2 |
rehayes |
end
|
436 |
|
|
|
437 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
438 |
21 |
rehayes |
// Test CHID Debug mode operation
|
439 |
|
|
task test_chid_debug;
|
440 |
|
|
begin
|
441 |
|
|
test_num = test_num + 1;
|
442 |
|
|
$display("\nTEST #%d Starts at vector=%d, test_chid_debug", test_num, vector);
|
443 |
36 |
rehayes |
$readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
|
444 |
21 |
rehayes |
|
445 |
|
|
data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
|
446 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Enable interrupt on BRK instruction
|
447 |
21 |
rehayes |
|
448 |
|
|
activate_thread_sw(3);
|
449 |
|
|
|
450 |
|
|
wait_debug_set; // Debug Status bit is set by BRK instruction
|
451 |
|
|
|
452 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h20c6, WORD); // See Program code (BRK).
|
453 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'h0001, WORD); // See Program code.R3 = 1
|
454 |
|
|
host.wb_cmp(0, XGATE_XGCHID, 16'h0003, WORD); // Check for Correct CHID
|
455 |
21 |
rehayes |
|
456 |
|
|
channel_req[5] = 1'b1; //
|
457 |
|
|
repeat(7) @(posedge mstr_test_clk);
|
458 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGCHID, 16'h0003, WORD); // Check for Correct CHID
|
459 |
21 |
rehayes |
|
460 |
41 |
rehayes |
host.wb_write(0, XGATE_XGCHID, 16'h000f, H_BYTE); // Check byte select lines
|
461 |
|
|
repeat(4) @(posedge mstr_test_clk);
|
462 |
|
|
host.wb_cmp(0, XGATE_XGCHID, 16'h0003, WORD); // Verify CHID is unchanged
|
463 |
|
|
|
464 |
|
|
host.wb_write(0, XGATE_XGCHID, 16'h000f, L_BYTE); // Change CHID
|
465 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGCHID, 16'h000f, WORD); // Check for Correct CHID
|
466 |
21 |
rehayes |
|
467 |
36 |
rehayes |
host.wb_write(0, XGATE_XGCHID, 16'h0000, WORD); // Change CHID to 00, RISC should go to IDLE state
|
468 |
21 |
rehayes |
|
469 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
470 |
|
|
|
471 |
36 |
rehayes |
host.wb_write(0, XGATE_XGCHID, 16'h0004, WORD); // Change CHID
|
472 |
21 |
rehayes |
|
473 |
|
|
repeat(8) @(posedge mstr_test_clk);
|
474 |
|
|
|
475 |
|
|
data_xgmctl = XGMCTL_XGDBGM;
|
476 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Clear Debug Mode Control Bit
|
477 |
21 |
rehayes |
|
478 |
|
|
wait_debug_set; // Debug Status bit is set by BRK instruction
|
479 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGCHID, 16'h0004, WORD); // Check for Correct CHID
|
480 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Clear Debug Mode Control Bit (Excape from Break State and run)
|
481 |
21 |
rehayes |
|
482 |
|
|
wait_debug_set; // Debug Status bit is set by BRK instruction
|
483 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGCHID, 16'h0005, WORD); // Check for Correct CHID
|
484 |
21 |
rehayes |
activate_channel(6);
|
485 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Clear Debug Mode Control Bit (Excape from Break State and run)
|
486 |
21 |
rehayes |
|
487 |
|
|
wait_debug_set; // Debug Status bit is set by BRK instruction
|
488 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGCHID, 16'h0006, WORD); // Check for Correct CHID
|
489 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h211c, WORD); // See Program code (BRK)
|
490 |
21 |
rehayes |
data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
|
491 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step
|
492 |
21 |
rehayes |
repeat(8) @(posedge mstr_test_clk);
|
493 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h211e, WORD); // See Program code (BRA)
|
494 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step
|
495 |
21 |
rehayes |
repeat(8) @(posedge mstr_test_clk);
|
496 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h2122, WORD); // See Program code ()
|
497 |
21 |
rehayes |
|
498 |
|
|
repeat(20) @(posedge mstr_test_clk);
|
499 |
|
|
|
500 |
|
|
data_xgmctl = XGMCTL_XGDBGM;
|
501 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Clear Debug Mode Control Bit
|
502 |
21 |
rehayes |
|
503 |
|
|
repeat(50) @(posedge mstr_test_clk);
|
504 |
|
|
|
505 |
36 |
rehayes |
p_ram.dump_ram(0);
|
506 |
|
|
|
507 |
41 |
rehayes |
read_ram_cmp(16'h0000,16'h7b55);
|
508 |
|
|
read_ram_cmp(16'h0004,16'h7faa);
|
509 |
|
|
read_ram_cmp(16'h0006,16'h6f55);
|
510 |
|
|
read_ram_cmp(16'h0008,16'h00c3);
|
511 |
|
|
read_ram_cmp(16'h000a,16'h5f66);
|
512 |
|
|
read_ram_cmp(16'h000c,16'h0003);
|
513 |
|
|
read_ram_cmp(16'h0022,16'hccxx);
|
514 |
|
|
read_ram_cmp(16'h0026,16'hxx99);
|
515 |
|
|
read_ram_cmp(16'h0032,16'h1fcc);
|
516 |
|
|
read_ram_cmp(16'h0038,16'h2f99);
|
517 |
|
|
read_ram_cmp(16'h0042,16'h33xx);
|
518 |
|
|
read_ram_cmp(16'h0046,16'hxx55);
|
519 |
|
|
read_ram_cmp(16'h0052,16'hxx66);
|
520 |
|
|
read_ram_cmp(16'h0058,16'h99xx);
|
521 |
|
|
read_ram_cmp(16'h0062,16'h1faa);
|
522 |
|
|
read_ram_cmp(16'h0068,16'h2fcc);
|
523 |
|
|
|
524 |
21 |
rehayes |
end
|
525 |
|
|
endtask
|
526 |
|
|
|
527 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
528 |
11 |
rehayes |
// Test Debug bit operation
|
529 |
|
|
task test_debug_bit;
|
530 |
2 |
rehayes |
begin
|
531 |
11 |
rehayes |
test_num = test_num + 1;
|
532 |
21 |
rehayes |
$display("\nTEST #%d Starts at vector=%d, test_debug_bit", test_num, vector);
|
533 |
36 |
rehayes |
$readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
|
534 |
21 |
rehayes |
|
535 |
11 |
rehayes |
data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
|
536 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Enable interrupt on BRK instruction
|
537 |
11 |
rehayes |
|
538 |
|
|
activate_thread_sw(2);
|
539 |
21 |
rehayes |
|
540 |
11 |
rehayes |
repeat(25) @(posedge mstr_test_clk);
|
541 |
|
|
|
542 |
|
|
data_xgmctl = XGMCTL_XGDBGM | XGMCTL_XGDBG;
|
543 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Set Debug Mode Control Bit
|
544 |
21 |
rehayes |
repeat(5) @(posedge mstr_test_clk);
|
545 |
|
|
|
546 |
36 |
rehayes |
host.wb_read(1, XGATE_XGR3, q, WORD);
|
547 |
21 |
rehayes |
data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
|
548 |
|
|
qq = q;
|
549 |
|
|
|
550 |
|
|
// The Xgate test program is in an infinate loop incrementing R3
|
551 |
|
|
while (qq == q) // Look for change in R3 register
|
552 |
|
|
begin
|
553 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step
|
554 |
54 |
rehayes |
repeat(7) @(posedge mstr_test_clk);
|
555 |
36 |
rehayes |
host.wb_read(1, XGATE_XGR3, q, WORD);
|
556 |
21 |
rehayes |
end
|
557 |
|
|
if (q != (qq+1))
|
558 |
|
|
begin
|
559 |
|
|
$display("Error! - Unexpected value of R3 at vector=%d", vector);
|
560 |
|
|
error_count = error_count + 1;
|
561 |
|
|
end
|
562 |
|
|
|
563 |
|
|
|
564 |
54 |
rehayes |
host.wb_write(1, XGATE_XGPC, 16'h2094, WORD); // Write to PC to force exit from infinite loop
|
565 |
|
|
repeat(10) @(posedge mstr_test_clk);
|
566 |
21 |
rehayes |
|
567 |
|
|
data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
|
568 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (Load ADDL instruction)
|
569 |
54 |
rehayes |
repeat(10) @(posedge mstr_test_clk);
|
570 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGR4, 16'h0002, WORD); // See Program code.(R4 <= R4 + 1)
|
571 |
21 |
rehayes |
|
572 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (Load ADDL instruction)
|
573 |
54 |
rehayes |
repeat(10) @(posedge mstr_test_clk);
|
574 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGR4, 16'h0003, WORD); // See Program code.(R4 <= R4 + 1)
|
575 |
21 |
rehayes |
|
576 |
|
|
data_xgmctl = XGMCTL_XGDBGM;
|
577 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Clear Debug Mode Control Bit
|
578 |
11 |
rehayes |
// Should be back in Run Mode
|
579 |
21 |
rehayes |
|
580 |
|
|
// data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
|
581 |
36 |
rehayes |
// host.wb_write(0, XGATE_XGMCTL, data_xgmctl); // Clear Software Interrupt and BRK Interrupt Enable Bit
|
582 |
11 |
rehayes |
repeat(15) @(posedge mstr_test_clk);
|
583 |
21 |
rehayes |
|
584 |
2 |
rehayes |
end
|
585 |
|
|
endtask
|
586 |
|
|
|
587 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
588 |
11 |
rehayes |
// Test Debug mode operation
|
589 |
|
|
task test_debug_mode;
|
590 |
2 |
rehayes |
begin
|
591 |
11 |
rehayes |
test_num = test_num + 1;
|
592 |
|
|
$display("\nTEST #%d Starts at vector=%d, test_debug_mode", test_num, vector);
|
593 |
36 |
rehayes |
$readmemh("../../../bench/verilog/debug_test.v", p_ram.ram_8);
|
594 |
21 |
rehayes |
|
595 |
11 |
rehayes |
data_xgmctl = XGMCTL_XGBRKIEM | XGMCTL_XGBRKIE;
|
596 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Enable interrupt on BRK instruction
|
597 |
11 |
rehayes |
|
598 |
|
|
activate_thread_sw(1);
|
599 |
21 |
rehayes |
|
600 |
11 |
rehayes |
wait_debug_set; // Debug Status bit is set by BRK instruction
|
601 |
|
|
|
602 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h203a, WORD); // See Program code (BRK).
|
603 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'h0001, WORD); // See Program code.R3 = 1
|
604 |
11 |
rehayes |
|
605 |
|
|
data_xgmctl = XGMCTL_XGSSM | XGMCTL_XGSS;
|
606 |
|
|
|
607 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (Load ADDL instruction)
|
608 |
11 |
rehayes |
repeat(5) @(posedge mstr_test_clk);
|
609 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h203c, WORD); // PC + 2.
|
610 |
11 |
rehayes |
|
611 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (Load NOP instruction)
|
612 |
|
|
repeat(5) @(posedge mstr_test_clk); // Execute ADDL instruction
|
613 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'h0002, WORD); // See Program code.(R3 <= R3 + 1)
|
614 |
|
|
host.wb_cmp(0, XGATE_XGCCR, 16'h0000, WORD); // See Program code.
|
615 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h203e, WORD); // PC + 2.
|
616 |
11 |
rehayes |
repeat(5) @(posedge mstr_test_clk);
|
617 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h203e, WORD); // Still no change.
|
618 |
11 |
rehayes |
|
619 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (Load BRA instruction)
|
620 |
|
|
repeat(9) @(posedge mstr_test_clk); // Execute NOP instruction
|
621 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h2040, WORD); // See Program code.
|
622 |
11 |
rehayes |
|
623 |
|
|
|
624 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step
|
625 |
|
|
repeat(5) @(posedge mstr_test_clk); // Execute BRA instruction
|
626 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h2064, WORD); // PC = Branch destination.
|
627 |
|
|
// Load ADDL instruction
|
628 |
21 |
rehayes |
|
629 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (Load LDW R7 instruction)
|
630 |
|
|
repeat(5) @(posedge mstr_test_clk); // Execute ADDL instruction
|
631 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h2066, WORD); // PC + 2.
|
632 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'h0003, WORD); // See Program code.(R3 <= R3 + 1)
|
633 |
11 |
rehayes |
|
634 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (LDW R7)
|
635 |
11 |
rehayes |
repeat(5) @(posedge mstr_test_clk);
|
636 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h2068, WORD); // PC + 2.
|
637 |
|
|
host.wb_cmp(0, XGATE_XGR7, 16'h00c3, WORD); // See Program code
|
638 |
11 |
rehayes |
|
639 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
640 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (BRA)
|
641 |
11 |
rehayes |
repeat(9) @(posedge mstr_test_clk);
|
642 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h2048, WORD); // See Program code.
|
643 |
11 |
rehayes |
|
644 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (STW R3)
|
645 |
11 |
rehayes |
repeat(5) @(posedge mstr_test_clk);
|
646 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h204a, WORD); // PC + 2.
|
647 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'h0003, WORD); // See Program code.(R3 <= R3 + 1)
|
648 |
11 |
rehayes |
|
649 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Do a Single Step (R3 <= R3 + 1)
|
650 |
11 |
rehayes |
repeat(5) @(posedge mstr_test_clk);
|
651 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGPC, 16'h204c, WORD); // PC + 2.
|
652 |
11 |
rehayes |
|
653 |
|
|
repeat(5) @(posedge mstr_test_clk);
|
654 |
|
|
|
655 |
|
|
data_xgmctl = XGMCTL_XGDBGM;
|
656 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Clear Debug Mode Control Bit
|
657 |
|
|
// Should be back in Run Mode
|
658 |
11 |
rehayes |
wait_irq_set(1);
|
659 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
|
660 |
21 |
rehayes |
|
661 |
11 |
rehayes |
data_xgmctl = XGMCTL_XGSWEIFM | XGMCTL_XGSWEIF | XGMCTL_XGBRKIEM;
|
662 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Clear Software Interrupt and BRK Interrupt Enable Bit
|
663 |
11 |
rehayes |
repeat(15) @(posedge mstr_test_clk);
|
664 |
21 |
rehayes |
|
665 |
2 |
rehayes |
end
|
666 |
|
|
endtask
|
667 |
|
|
|
668 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
669 |
11 |
rehayes |
// Test instruction set
|
670 |
|
|
task test_inst_set;
|
671 |
|
|
begin
|
672 |
36 |
rehayes |
$readmemh("../../../bench/verilog/inst_test.v", p_ram.ram_8);
|
673 |
11 |
rehayes |
test_num = test_num + 1;
|
674 |
|
|
$display("\nTEST #%d Starts at vector=%d, inst_test", test_num, vector);
|
675 |
21 |
rehayes |
repeat(1) @(posedge mstr_test_clk);
|
676 |
11 |
rehayes |
|
677 |
|
|
activate_thread_sw(1);
|
678 |
|
|
wait_irq_set(1);
|
679 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0002, WORD);
|
680 |
21 |
rehayes |
|
681 |
11 |
rehayes |
activate_thread_sw(2);
|
682 |
|
|
wait_irq_set(2);
|
683 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0004, WORD);
|
684 |
11 |
rehayes |
|
685 |
|
|
activate_thread_sw(3);
|
686 |
|
|
wait_irq_set(3);
|
687 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0008, WORD);
|
688 |
21 |
rehayes |
|
689 |
11 |
rehayes |
activate_thread_sw(4);
|
690 |
|
|
wait_irq_set(4);
|
691 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0010, WORD);
|
692 |
21 |
rehayes |
|
693 |
11 |
rehayes |
activate_thread_sw(5);
|
694 |
|
|
wait_irq_set(5);
|
695 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0020, WORD);
|
696 |
21 |
rehayes |
|
697 |
11 |
rehayes |
activate_thread_sw(6);
|
698 |
|
|
wait_irq_set(6);
|
699 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0040, WORD);
|
700 |
21 |
rehayes |
|
701 |
11 |
rehayes |
activate_thread_sw(7);
|
702 |
|
|
wait_irq_set(7);
|
703 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0080, WORD);
|
704 |
21 |
rehayes |
|
705 |
11 |
rehayes |
activate_thread_sw(8);
|
706 |
|
|
wait_irq_set(8);
|
707 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0100, WORD);
|
708 |
21 |
rehayes |
|
709 |
11 |
rehayes |
activate_thread_sw(9);
|
710 |
|
|
wait_irq_set(9);
|
711 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0200, WORD);
|
712 |
21 |
rehayes |
|
713 |
36 |
rehayes |
host.wb_write(1, XGATE_XGSEM, 16'h5050, WORD);
|
714 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h0050, WORD); //
|
715 |
11 |
rehayes |
activate_thread_sw(10);
|
716 |
|
|
wait_irq_set(10);
|
717 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'h0400, WORD);
|
718 |
21 |
rehayes |
|
719 |
36 |
rehayes |
host.wb_write(1, XGATE_XGSEM, 16'hff00, WORD); // clear the old settings
|
720 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h0000, WORD); //
|
721 |
|
|
host.wb_write(1, XGATE_XGSEM, 16'ha0a0, WORD); // Verify that bits were unlocked by RISC
|
722 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h00a0, WORD); // Verify bits were set
|
723 |
|
|
host.wb_write(1, XGATE_XGSEM, 16'hff08, WORD); // Try to set the bit that was left locked by the RISC
|
724 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h0000, WORD); // Verify no bits were set
|
725 |
21 |
rehayes |
|
726 |
11 |
rehayes |
repeat(20) @(posedge mstr_test_clk);
|
727 |
|
|
|
728 |
36 |
rehayes |
p_ram.dump_ram(0);
|
729 |
41 |
rehayes |
|
730 |
|
|
read_ram_cmp(16'h0000,16'haa55);
|
731 |
|
|
read_ram_cmp(16'h0004,16'h7faa);
|
732 |
|
|
read_ram_cmp(16'h0006,16'h6f55);
|
733 |
|
|
read_ram_cmp(16'h000a,16'h5f66);
|
734 |
|
|
read_ram_cmp(16'h0032,16'h1fcc);
|
735 |
|
|
read_ram_cmp(16'h0038,16'h2f99);
|
736 |
|
|
read_ram_cmp(16'h0062,16'h1faa);
|
737 |
|
|
read_ram_cmp(16'h0068,16'h2fcc);
|
738 |
|
|
read_ram_cmp(16'h0022,16'hccxx);
|
739 |
|
|
read_ram_cmp(16'h0026,16'hxx99);
|
740 |
|
|
read_ram_cmp(16'h0052,16'hxx66);
|
741 |
|
|
read_ram_cmp(16'h0058,16'h99xx);
|
742 |
50 |
rehayes |
|
743 |
|
|
data_xgmctl = 16'hff00;
|
744 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Disable XGATE
|
745 |
|
|
|
746 |
11 |
rehayes |
end
|
747 |
|
|
endtask
|
748 |
|
|
|
749 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
750 |
2 |
rehayes |
// check register bits - reset, read/write
|
751 |
|
|
task reg_test_16;
|
752 |
|
|
begin
|
753 |
|
|
test_num = test_num + 1;
|
754 |
|
|
$display("TEST #%d Starts at vector=%d, reg_test_16", test_num, vector);
|
755 |
41 |
rehayes |
|
756 |
|
|
system_reset;
|
757 |
|
|
|
758 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGMCTL, 16'h0000, WORD); // verify reset
|
759 |
|
|
host.wb_cmp(0, XGATE_XGCHID, 16'h0000, WORD); // verify reset
|
760 |
|
|
host.wb_cmp(0, XGATE_XGISPHI, 16'h0000, WORD); // verify reset
|
761 |
|
|
host.wb_cmp(0, XGATE_XGISPLO, 16'h0000, WORD); // verify reset
|
762 |
41 |
rehayes |
host.wb_cmp(0, XGATE_XGVBR, 16'hfe00, WORD); // verify reset
|
763 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGIF_7, 16'h0000, WORD); // verify reset
|
764 |
|
|
host.wb_cmp(0, XGATE_XGIF_6, 16'h0000, WORD); // verify reset
|
765 |
|
|
host.wb_cmp(0, XGATE_XGIF_5, 16'h0000, WORD); // verify reset
|
766 |
|
|
host.wb_cmp(0, XGATE_XGIF_4, 16'h0000, WORD); // verify reset
|
767 |
|
|
host.wb_cmp(0, XGATE_XGIF_3, 16'h0000, WORD); // verify reset
|
768 |
|
|
host.wb_cmp(0, XGATE_XGIF_2, 16'h0000, WORD); // verify reset
|
769 |
|
|
host.wb_cmp(0, XGATE_XGIF_1, 16'h0000, WORD); // verify reset
|
770 |
41 |
rehayes |
host.wb_cmp(0, XGATE_XGIF_0, 16'h0001, WORD); // verify reset
|
771 |
36 |
rehayes |
host.wb_cmp(0, XGATE_XGSWT, 16'h0000, WORD); // verify reset
|
772 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h0000, WORD); // verify reset
|
773 |
|
|
host.wb_cmp(0, XGATE_XGCCR, 16'h0000, WORD); // verify reset
|
774 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h0000, WORD); // verify reset
|
775 |
|
|
host.wb_cmp(0, XGATE_XGR1, 16'h0000, WORD); // verify reset
|
776 |
|
|
host.wb_cmp(0, XGATE_XGR2, 16'h0000, WORD); // verify reset
|
777 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'h0000, WORD); // verify reset
|
778 |
|
|
host.wb_cmp(0, XGATE_XGR4, 16'h0000, WORD); // verify reset
|
779 |
|
|
host.wb_cmp(0, XGATE_XGR5, 16'h0000, WORD); // verify reset
|
780 |
|
|
host.wb_cmp(0, XGATE_XGR6, 16'h0000, WORD); // verify reset
|
781 |
|
|
host.wb_cmp(0, XGATE_XGR7, 16'h0000, WORD); // verify reset
|
782 |
2 |
rehayes |
|
783 |
41 |
rehayes |
/*
|
784 |
|
|
parameter XGMCTL_XGDBGM = 15'h2000;
|
785 |
|
|
parameter XGMCTL_XGSSM = 15'h1000;
|
786 |
|
|
parameter XGMCTL_XGBRKIEM = 15'h0400;
|
787 |
|
|
parameter XGMCTL_XGSWEIFM = 15'h0200;
|
788 |
|
|
parameter XGMCTL_XGIEM = 15'h0100;
|
789 |
2 |
rehayes |
|
790 |
41 |
rehayes |
parameter XGMCTL_XGDBG = 15'h0020;
|
791 |
|
|
parameter XGMCTL_XGSS = 15'h0010;
|
792 |
|
|
parameter XGMCTL_XGBRKIE = 15'h0004;
|
793 |
|
|
parameter XGMCTL_XGSWEIF = 15'h0002;
|
794 |
|
|
parameter XGMCTL_XGIE = 15'h0001;
|
795 |
|
|
*/
|
796 |
|
|
// Test bits in the Xgate Control Register (XGMCTL)
|
797 |
|
|
data_xgmctl = XGMCTL_XGEM | XGMCTL_XGFRZM | XGMCTL_XGFACTM | XGMCTL_XGFRZ | XGMCTL_XGFACT | XGMCTL_XGE;
|
798 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); //
|
799 |
|
|
data_xgmctl = XGMCTL_XGFRZ | XGMCTL_XGFACT | XGMCTL_XGE;
|
800 |
|
|
host.wb_cmp( 0, XGATE_XGMCTL, data_xgmctl, WORD);
|
801 |
2 |
rehayes |
|
802 |
41 |
rehayes |
data_xgmctl = XGMCTL_XGEM;
|
803 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); //
|
804 |
|
|
data_xgmctl = XGMCTL_XGFRZ | XGMCTL_XGFACT;
|
805 |
|
|
host.wb_cmp( 0, XGATE_XGMCTL, data_xgmctl, WORD);
|
806 |
2 |
rehayes |
|
807 |
41 |
rehayes |
data_xgmctl = XGMCTL_XGFRZM | XGMCTL_XGFACTM;
|
808 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); //
|
809 |
|
|
data_xgmctl = 16'h0000;
|
810 |
|
|
host.wb_cmp( 0, XGATE_XGMCTL, data_xgmctl, WORD);
|
811 |
|
|
|
812 |
|
|
data_xgmctl = 16'hffff;
|
813 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, H_BYTE); //
|
814 |
|
|
data_xgmctl = 16'h0000;
|
815 |
|
|
host.wb_cmp( 0, XGATE_XGMCTL, data_xgmctl, WORD);
|
816 |
|
|
|
817 |
|
|
data_xgmctl = 16'hffff;
|
818 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, L_BYTE); //
|
819 |
|
|
data_xgmctl = 16'h0000;
|
820 |
|
|
host.wb_cmp( 0, XGATE_XGMCTL, data_xgmctl, WORD);
|
821 |
|
|
|
822 |
|
|
// Test the Xgate Vector Base Address Register (XGVBR)
|
823 |
|
|
host.wb_write(0, XGATE_XGVBR, 16'h5555, WORD);
|
824 |
|
|
host.wb_cmp(0, XGATE_XGVBR, 16'h5554, WORD);
|
825 |
|
|
|
826 |
|
|
host.wb_write(0, XGATE_XGVBR, 16'hAAAA, WORD);
|
827 |
|
|
host.wb_cmp(0, XGATE_XGVBR, 16'hAAAA, WORD);
|
828 |
|
|
|
829 |
|
|
host.wb_write(0, XGATE_XGVBR, 16'hFF55, L_BYTE);
|
830 |
|
|
host.wb_cmp(0, XGATE_XGVBR, 16'hAA54, WORD);
|
831 |
|
|
|
832 |
|
|
host.wb_write(0, XGATE_XGVBR, 16'h55AA, H_BYTE);
|
833 |
|
|
host.wb_cmp(0, XGATE_XGVBR, 16'h5554, WORD);
|
834 |
|
|
|
835 |
|
|
data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
|
836 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); //
|
837 |
|
|
data_xgmctl = XGMCTL_XGE;
|
838 |
|
|
host.wb_cmp( 0, XGATE_XGMCTL, data_xgmctl, WORD);
|
839 |
|
|
host.wb_write(0, XGATE_XGVBR, 16'hFFFF, WORD);
|
840 |
|
|
host.wb_cmp(0, XGATE_XGVBR, 16'h5554, WORD);
|
841 |
|
|
|
842 |
|
|
data_xgmctl = XGMCTL_XGEM;
|
843 |
|
|
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); //
|
844 |
|
|
|
845 |
|
|
// Test the Xgate Software Trigger Register (XGSWT)
|
846 |
|
|
host.wb_write(0, XGATE_XGSWT, 16'hFFFF, WORD);
|
847 |
|
|
host.wb_cmp(0, XGATE_XGSWT, 16'h00FF, WORD);
|
848 |
|
|
host.wb_write(0, XGATE_XGSWT, 16'hFF00, WORD);
|
849 |
|
|
host.wb_cmp(0, XGATE_XGSWT, 16'h0000, WORD);
|
850 |
|
|
|
851 |
|
|
host.wb_write(0, XGATE_XGSWT, 16'hFF55, L_BYTE);
|
852 |
|
|
host.wb_cmp(0, XGATE_XGSWT, 16'h0000, WORD);
|
853 |
|
|
host.wb_write(0, XGATE_XGSWT, 16'hFF55, H_BYTE);
|
854 |
|
|
host.wb_cmp(0, XGATE_XGSWT, 16'h0000, WORD);
|
855 |
|
|
|
856 |
|
|
// Test the Xgate Semaphore Register (XGSEM)
|
857 |
|
|
host.wb_write(0, XGATE_XGSEM, 16'hFFFF, WORD);
|
858 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h00FF, WORD);
|
859 |
|
|
host.wb_write(0, XGATE_XGSEM, 16'hFF00, WORD);
|
860 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h0000, WORD);
|
861 |
|
|
|
862 |
|
|
host.wb_write(0, XGATE_XGSEM, 16'hFFFF, L_BYTE);
|
863 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h0000, WORD);
|
864 |
|
|
host.wb_write(0, XGATE_XGSEM, 16'hFFFF, H_BYTE);
|
865 |
|
|
host.wb_cmp(0, XGATE_XGSEM, 16'h0000, WORD);
|
866 |
|
|
|
867 |
|
|
// Test the Xgate Condition Code Register (XGCCR)
|
868 |
|
|
host.wb_write(0, XGATE_XGCCR, 16'hFFFF, L_BYTE);
|
869 |
|
|
host.wb_cmp(0, XGATE_XGCCR, 16'h000F, WORD);
|
870 |
|
|
host.wb_write(0, XGATE_XGCCR, 16'hFFF0, WORD);
|
871 |
|
|
host.wb_cmp(0, XGATE_XGCCR, 16'h0000, WORD);
|
872 |
|
|
|
873 |
|
|
// Test the Xgate Program Counter Register (XGPC)
|
874 |
|
|
host.wb_write(0, XGATE_XGPC, 16'hFF55, L_BYTE);
|
875 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h0055, WORD);
|
876 |
|
|
host.wb_write(0, XGATE_XGPC, 16'hAAFF, H_BYTE);
|
877 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'hAA55, WORD);
|
878 |
|
|
host.wb_write(0, XGATE_XGPC, 16'h9966, WORD);
|
879 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h9966, WORD);
|
880 |
|
|
|
881 |
|
|
// Test the Xgate Register #1 (XGR1)
|
882 |
|
|
host.wb_write(0, XGATE_XGR1, 16'hFF33, L_BYTE);
|
883 |
|
|
host.wb_cmp(0, XGATE_XGR1, 16'h0033, WORD);
|
884 |
|
|
host.wb_write(0, XGATE_XGR1, 16'hccFF, H_BYTE);
|
885 |
|
|
host.wb_cmp(0, XGATE_XGR1, 16'hcc33, WORD);
|
886 |
|
|
host.wb_write(0, XGATE_XGR1, 16'hf11f, WORD);
|
887 |
|
|
host.wb_cmp(0, XGATE_XGR1, 16'hf11f, WORD);
|
888 |
|
|
|
889 |
|
|
// Test the Xgate Register #2 (XGR2)
|
890 |
|
|
host.wb_write(0, XGATE_XGR2, 16'hFF11, L_BYTE);
|
891 |
|
|
host.wb_cmp(0, XGATE_XGR2, 16'h0011, WORD);
|
892 |
|
|
host.wb_write(0, XGATE_XGR2, 16'h22FF, H_BYTE);
|
893 |
|
|
host.wb_cmp(0, XGATE_XGR2, 16'h2211, WORD);
|
894 |
|
|
host.wb_write(0, XGATE_XGR2, 16'hddee, WORD);
|
895 |
|
|
host.wb_cmp(0, XGATE_XGR2, 16'hddee, WORD);
|
896 |
|
|
|
897 |
|
|
// Test the Xgate Register #3 (XGR3)
|
898 |
|
|
host.wb_write(0, XGATE_XGR3, 16'hFF43, L_BYTE);
|
899 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'h0043, WORD);
|
900 |
|
|
host.wb_write(0, XGATE_XGR3, 16'h54FF, H_BYTE);
|
901 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'h5443, WORD);
|
902 |
|
|
host.wb_write(0, XGATE_XGR3, 16'habbc, WORD);
|
903 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'habbc, WORD);
|
904 |
|
|
|
905 |
|
|
// Test the Xgate Register #4 (XGR4)
|
906 |
|
|
host.wb_write(0, XGATE_XGR4, 16'hFF54, L_BYTE);
|
907 |
|
|
host.wb_cmp(0, XGATE_XGR4, 16'h0054, WORD);
|
908 |
|
|
host.wb_write(0, XGATE_XGR4, 16'h65FF, H_BYTE);
|
909 |
|
|
host.wb_cmp(0, XGATE_XGR4, 16'h6554, WORD);
|
910 |
|
|
host.wb_write(0, XGATE_XGR4, 16'h9aab, WORD);
|
911 |
|
|
host.wb_cmp(0, XGATE_XGR4, 16'h9aab, WORD);
|
912 |
|
|
|
913 |
|
|
// Test the Xgate Register #5 (XGR5)
|
914 |
|
|
host.wb_write(0, XGATE_XGR5, 16'hFF65, L_BYTE);
|
915 |
|
|
host.wb_cmp(0, XGATE_XGR5, 16'h0065, WORD);
|
916 |
|
|
host.wb_write(0, XGATE_XGR5, 16'h76FF, H_BYTE);
|
917 |
|
|
host.wb_cmp(0, XGATE_XGR5, 16'h7665, WORD);
|
918 |
|
|
host.wb_write(0, XGATE_XGR5, 16'h899a, WORD);
|
919 |
|
|
host.wb_cmp(0, XGATE_XGR5, 16'h899a, WORD);
|
920 |
|
|
|
921 |
|
|
// Test the Xgate Register #6 (XGR6)
|
922 |
|
|
host.wb_write(0, XGATE_XGR6, 16'hFF76, L_BYTE);
|
923 |
|
|
host.wb_cmp(0, XGATE_XGR6, 16'h0076, WORD);
|
924 |
|
|
host.wb_write(0, XGATE_XGR6, 16'h87FF, H_BYTE);
|
925 |
|
|
host.wb_cmp(0, XGATE_XGR6, 16'h8776, WORD);
|
926 |
|
|
host.wb_write(0, XGATE_XGR6, 16'h7889, WORD);
|
927 |
|
|
host.wb_cmp(0, XGATE_XGR6, 16'h7889, WORD);
|
928 |
|
|
|
929 |
|
|
// Test the Xgate Register #7 (XGR7)
|
930 |
|
|
host.wb_write(0, XGATE_XGR7, 16'hFF87, L_BYTE);
|
931 |
|
|
host.wb_cmp(0, XGATE_XGR7, 16'h0087, WORD);
|
932 |
|
|
host.wb_write(0, XGATE_XGR7, 16'h98FF, H_BYTE);
|
933 |
|
|
host.wb_cmp(0, XGATE_XGR7, 16'h9887, WORD);
|
934 |
|
|
host.wb_write(0, XGATE_XGR7, 16'h6778, WORD);
|
935 |
|
|
host.wb_cmp(0, XGATE_XGR7, 16'h6778, WORD);
|
936 |
|
|
|
937 |
|
|
host.wb_cmp(0, XGATE_XGPC, 16'h9966, WORD);
|
938 |
|
|
host.wb_cmp(0, XGATE_XGR1, 16'hf11f, WORD);
|
939 |
|
|
host.wb_cmp(0, XGATE_XGR2, 16'hddee, WORD);
|
940 |
|
|
host.wb_cmp(0, XGATE_XGR3, 16'habbc, WORD);
|
941 |
|
|
host.wb_cmp(0, XGATE_XGR4, 16'h9aab, WORD);
|
942 |
|
|
host.wb_cmp(0, XGATE_XGR5, 16'h899a, WORD);
|
943 |
|
|
host.wb_cmp(0, XGATE_XGR6, 16'h7889, WORD);
|
944 |
|
|
host.wb_cmp(0, XGATE_XGR7, 16'h6778, WORD);
|
945 |
|
|
|
946 |
2 |
rehayes |
end
|
947 |
|
|
endtask
|
948 |
|
|
|
949 |
|
|
|
950 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
951 |
|
|
// check RAM Read/Write from host
|
952 |
|
|
task host_ram;
|
953 |
|
|
begin
|
954 |
|
|
test_num = test_num + 1;
|
955 |
|
|
$display("TEST #%d Starts at vector=%d, host_ram", test_num, vector);
|
956 |
|
|
|
957 |
|
|
host.wb_write(1, SYS_RAM_BASE, 16'h5555, WORD);
|
958 |
|
|
host.wb_cmp( 0, SYS_RAM_BASE, 16'h5555, WORD);
|
959 |
|
|
|
960 |
|
|
repeat(5) @(posedge mstr_test_clk);
|
961 |
|
|
p_ram.dump_ram(0);
|
962 |
|
|
|
963 |
|
|
end
|
964 |
|
|
endtask
|
965 |
|
|
|
966 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
967 |
11 |
rehayes |
// Poll for XGATE Interrupt set
|
968 |
|
|
task wait_irq_set;
|
969 |
|
|
input [ 6:0] chan_val;
|
970 |
|
|
begin
|
971 |
|
|
while(!xgif[chan_val])
|
972 |
|
|
@(posedge mstr_test_clk); // poll it until it is set
|
973 |
|
|
$display("XGATE Interrupt Request #%d set detected at vector =%d", chan_val, vector);
|
974 |
|
|
end
|
975 |
|
|
endtask
|
976 |
2 |
rehayes |
|
977 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
978 |
11 |
rehayes |
// Poll for debug bit set
|
979 |
|
|
task wait_debug_set;
|
980 |
|
|
begin
|
981 |
36 |
rehayes |
host.wb_read(1, XGATE_XGMCTL, q, WORD);
|
982 |
11 |
rehayes |
while(~|(q & XGMCTL_XGDBG))
|
983 |
36 |
rehayes |
host.wb_read(1, XGATE_XGMCTL, q, WORD); // poll it until it is set
|
984 |
11 |
rehayes |
$display("DEBUG Flag set detected at vector =%d", vector);
|
985 |
|
|
end
|
986 |
|
|
endtask
|
987 |
2 |
rehayes |
|
988 |
11 |
rehayes |
|
989 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
990 |
2 |
rehayes |
task system_reset; // reset system
|
991 |
|
|
begin
|
992 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
993 |
|
|
sync_reset = 1'b1; // Make the sync reset 1 clock cycle long
|
994 |
|
|
#2; // move the async reset away from the clock edge
|
995 |
|
|
rstn = 1'b0; // assert async reset
|
996 |
|
|
#5; // Keep the async reset pulse with less than a clock cycle
|
997 |
|
|
rstn = 1'b1; // negate async reset
|
998 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
999 |
|
|
sync_reset = 1'b0;
|
1000 |
|
|
|
1001 |
|
|
$display("\nstatus: %t System Reset Task Done", $time);
|
1002 |
|
|
test_num = test_num + 1;
|
1003 |
|
|
|
1004 |
|
|
repeat(2) @(posedge mstr_test_clk);
|
1005 |
|
|
end
|
1006 |
|
|
endtask
|
1007 |
|
|
|
1008 |
|
|
|
1009 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
1010 |
2 |
rehayes |
task activate_channel;
|
1011 |
|
|
input [ 6:0] chan_val;
|
1012 |
|
|
begin
|
1013 |
21 |
rehayes |
$display("Activating Channel %d", chan_val);
|
1014 |
2 |
rehayes |
|
1015 |
21 |
rehayes |
channel_req[chan_val] = 1'b1; //
|
1016 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
1017 |
2 |
rehayes |
end
|
1018 |
|
|
endtask
|
1019 |
|
|
|
1020 |
|
|
|
1021 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
1022 |
2 |
rehayes |
task clear_channel;
|
1023 |
|
|
input [ 6:0] chan_val;
|
1024 |
|
|
begin
|
1025 |
21 |
rehayes |
$display("Clearing Channel interrupt input #%d", chan_val);
|
1026 |
2 |
rehayes |
|
1027 |
21 |
rehayes |
channel_req[chan_val] = 1'b0; //
|
1028 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
1029 |
|
|
end
|
1030 |
2 |
rehayes |
endtask
|
1031 |
|
|
|
1032 |
|
|
|
1033 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
1034 |
2 |
rehayes |
task clear_irq_flag;
|
1035 |
|
|
input [ 6:0] chan_val;
|
1036 |
|
|
begin
|
1037 |
|
|
$display("Clearing Channel interrupt flag #%d", chan_val);
|
1038 |
|
|
if (0 < chan_val < 16)
|
1039 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_0, 16'hffff, WORD);
|
1040 |
2 |
rehayes |
if (15 < chan_val < 32)
|
1041 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_1, 16'hffff, WORD);
|
1042 |
2 |
rehayes |
if (31 < chan_val < 48)
|
1043 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_2, 16'hffff, WORD);
|
1044 |
2 |
rehayes |
if (47 < chan_val < 64)
|
1045 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_3, 16'hffff, WORD);
|
1046 |
2 |
rehayes |
if (63 < chan_val < 80)
|
1047 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_4, 16'hffff, WORD);
|
1048 |
2 |
rehayes |
if (79 < chan_val < 96)
|
1049 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_5, 16'hffff, WORD);
|
1050 |
2 |
rehayes |
if (95 < chan_val < 112)
|
1051 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_6, 16'hffff, WORD);
|
1052 |
2 |
rehayes |
if (111 < chan_val < 128)
|
1053 |
36 |
rehayes |
host.wb_write(1, XGATE_XGIF_7, 16'hffff, WORD);
|
1054 |
2 |
rehayes |
|
1055 |
21 |
rehayes |
channel_req[chan_val] = 1'b0; //
|
1056 |
2 |
rehayes |
repeat(1) @(posedge mstr_test_clk);
|
1057 |
|
|
end
|
1058 |
|
|
endtask
|
1059 |
|
|
|
1060 |
|
|
|
1061 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
1062 |
2 |
rehayes |
task activate_thread_sw;
|
1063 |
|
|
input [ 6:0] chan_val;
|
1064 |
|
|
begin
|
1065 |
50 |
rehayes |
$display("Activating Software Thread - Channel #%d", chan_val);
|
1066 |
2 |
rehayes |
|
1067 |
11 |
rehayes |
data_xgmctl = XGMCTL_XGEM | XGMCTL_XGE;
|
1068 |
36 |
rehayes |
host.wb_write(0, XGATE_XGMCTL, data_xgmctl, WORD); // Enable XGATE
|
1069 |
2 |
rehayes |
|
1070 |
21 |
rehayes |
channel_req[chan_val] = 1'b1; //
|
1071 |
2 |
rehayes |
repeat(1) @(posedge mstr_test_clk);
|
1072 |
|
|
end
|
1073 |
|
|
endtask
|
1074 |
|
|
|
1075 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
1076 |
41 |
rehayes |
task read_ram_cmp;
|
1077 |
|
|
input [15:0] address;
|
1078 |
|
|
input [15:0] value;
|
1079 |
|
|
reg [15:0] q;
|
1080 |
|
|
begin
|
1081 |
|
|
|
1082 |
|
|
// BIGENDIAN
|
1083 |
|
|
q = {p_ram.ram_8[address], p_ram.ram_8[address+1]};
|
1084 |
|
|
// "X" compares don't work, "X" in value or q always match
|
1085 |
|
|
if (value != q)
|
1086 |
|
|
begin
|
1087 |
|
|
error_count = error_count + 1;
|
1088 |
|
|
$display("RAM Data compare error at address %h. Received %h, expected %h at time %t", address, q, value, $time);
|
1089 |
|
|
end
|
1090 |
|
|
end
|
1091 |
|
|
endtask
|
1092 |
|
|
|
1093 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
1094 |
5 |
rehayes |
task wrap_up;
|
1095 |
|
|
begin
|
1096 |
21 |
rehayes |
test_num = test_num + 1;
|
1097 |
|
|
repeat(10) @(posedge mstr_test_clk);
|
1098 |
5 |
rehayes |
$display("\nSimulation Finished!! - vector =%d", vector);
|
1099 |
|
|
if (error_count == 0)
|
1100 |
|
|
$display("Simulation Passed");
|
1101 |
|
|
else
|
1102 |
21 |
rehayes |
$display("Simulation Failed --- Errors =%d", error_count);
|
1103 |
5 |
rehayes |
|
1104 |
|
|
$finish;
|
1105 |
|
|
end
|
1106 |
|
|
endtask
|
1107 |
|
|
|
1108 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
1109 |
2 |
rehayes |
function [15:0] four_2_16;
|
1110 |
|
|
input [3:0] vector;
|
1111 |
|
|
begin
|
1112 |
|
|
case (vector)
|
1113 |
|
|
4'h0 : four_2_16 = 16'b0000_0000_0000_0001;
|
1114 |
|
|
4'h1 : four_2_16 = 16'b0000_0000_0000_0010;
|
1115 |
|
|
4'h2 : four_2_16 = 16'b0000_0000_0000_0100;
|
1116 |
|
|
4'h3 : four_2_16 = 16'b0000_0000_0000_1000;
|
1117 |
|
|
4'h4 : four_2_16 = 16'b0000_0000_0001_0000;
|
1118 |
|
|
4'h5 : four_2_16 = 16'b0000_0000_0010_0000;
|
1119 |
|
|
4'h6 : four_2_16 = 16'b0000_0000_0100_0000;
|
1120 |
|
|
4'h7 : four_2_16 = 16'b0000_0000_1000_0000;
|
1121 |
|
|
4'h8 : four_2_16 = 16'b0000_0001_0000_0000;
|
1122 |
|
|
4'h9 : four_2_16 = 16'b0000_0010_0000_0000;
|
1123 |
|
|
4'ha : four_2_16 = 16'b0000_0100_0000_0000;
|
1124 |
|
|
4'hb : four_2_16 = 16'b0000_1000_0000_0000;
|
1125 |
|
|
4'hc : four_2_16 = 16'b0001_0000_0000_0000;
|
1126 |
|
|
4'hd : four_2_16 = 16'b0010_0000_0000_0000;
|
1127 |
|
|
4'he : four_2_16 = 16'b0100_0000_0000_0000;
|
1128 |
|
|
4'hf : four_2_16 = 16'b1000_0000_0000_0000;
|
1129 |
|
|
endcase
|
1130 |
|
|
end
|
1131 |
|
|
endfunction
|
1132 |
|
|
|
1133 |
|
|
endmodule // tst_bench_top
|
1134 |
|
|
|
1135 |
36 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
1136 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
1137 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
1138 |
54 |
rehayes |
module bus_arbitration #(parameter dwidth = 16,
|
1139 |
|
|
parameter awidth = 24,
|
1140 |
|
|
parameter ram_base = 0,
|
1141 |
|
|
parameter ram_size = 16'hffff,
|
1142 |
|
|
parameter slv1_base = 0,
|
1143 |
|
|
parameter slv1_size = 1,
|
1144 |
|
|
parameter slv2_base = 0,
|
1145 |
|
|
parameter slv2_size = 1)
|
1146 |
36 |
rehayes |
(
|
1147 |
|
|
// System bus I/O
|
1148 |
54 |
rehayes |
output reg sys_cyc,
|
1149 |
|
|
output reg sys_stb,
|
1150 |
|
|
output reg sys_we,
|
1151 |
|
|
output reg [dwidth/8 -1:0] sys_sel,
|
1152 |
|
|
output reg [awidth -1:0] sys_adr,
|
1153 |
|
|
output reg [dwidth -1:0] sys_dout,
|
1154 |
|
|
output [dwidth -1:0] sys_din,
|
1155 |
36 |
rehayes |
|
1156 |
|
|
// Host bus I/O
|
1157 |
|
|
output host_ack,
|
1158 |
|
|
output [dwidth -1:0] host_dout,
|
1159 |
|
|
input host_cyc,
|
1160 |
|
|
input host_stb,
|
1161 |
|
|
input host_we,
|
1162 |
|
|
input [dwidth/8 -1:0] host_sel,
|
1163 |
|
|
input [awidth -1:0] host_adr,
|
1164 |
|
|
input [dwidth -1:0] host_din,
|
1165 |
|
|
|
1166 |
|
|
// Alternate Bus Master #1 Bus I/O
|
1167 |
|
|
output alt1_ack,
|
1168 |
|
|
output [dwidth -1:0] alt1_dout,
|
1169 |
|
|
input alt1_cyc,
|
1170 |
|
|
input alt1_stb,
|
1171 |
|
|
input alt1_we,
|
1172 |
|
|
input [dwidth/8 -1:0] alt1_sel,
|
1173 |
|
|
input [awidth -1:0] alt1_adr,
|
1174 |
|
|
input [dwidth -1:0] alt1_din,
|
1175 |
|
|
|
1176 |
54 |
rehayes |
// System RAM memory signals
|
1177 |
|
|
output ram_sel,
|
1178 |
|
|
input [dwidth -1:0] ram_dout,
|
1179 |
|
|
|
1180 |
36 |
rehayes |
// Slave #1 Bus I/O
|
1181 |
|
|
output slv1_stb,
|
1182 |
|
|
input slv1_ack,
|
1183 |
|
|
input [dwidth -1:0] slv1_din,
|
1184 |
|
|
|
1185 |
|
|
// Slave #2 Bus I/O
|
1186 |
|
|
output slv2_stb,
|
1187 |
|
|
input slv2_ack,
|
1188 |
|
|
input [dwidth -1:0] slv2_din,
|
1189 |
|
|
|
1190 |
|
|
// Miscellaneous
|
1191 |
|
|
input host_clk,
|
1192 |
|
|
input risc_clk,
|
1193 |
|
|
input rst, // No Connect
|
1194 |
|
|
input err, // No Connect
|
1195 |
|
|
input rty // No Connect
|
1196 |
|
|
);
|
1197 |
|
|
|
1198 |
60 |
rehayes |
// States for bus arbitration
|
1199 |
54 |
rehayes |
parameter [1:0] BUS_IDLE = 2'b00,
|
1200 |
|
|
HOST_OWNS = 2'b10,
|
1201 |
|
|
RISC_OWNS = 2'b11;
|
1202 |
60 |
rehayes |
|
1203 |
|
|
parameter max_bus_hold = 5; // Max number of cycles any bus master can hold the system bus
|
1204 |
|
|
parameter ram_wait_states = 0; // Number between 0 and 15
|
1205 |
36 |
rehayes |
//////////////////////////////////////////////////////////////////////////////
|
1206 |
|
|
//
|
1207 |
|
|
// Local Wires and Registers
|
1208 |
|
|
//
|
1209 |
54 |
rehayes |
wire ram_ack; //
|
1210 |
|
|
wire any_ack; //
|
1211 |
|
|
reg host_wait; // Host bus in wait state, Hold the bus till the transaction complets
|
1212 |
36 |
rehayes |
reg [3:0] host_cycle_cnt; // Used to count the cycle the host and break the lock if the risc needs access
|
1213 |
|
|
|
1214 |
|
|
wire risc_lock; // RISC has the slave bus
|
1215 |
54 |
rehayes |
reg risc_wait; // RISC bus in wait state, Hold the bus till the transaction complets
|
1216 |
36 |
rehayes |
reg [3:0] risc_cycle_cnt; // Used to count the cycle the risc and break the lock if the host needs access
|
1217 |
54 |
rehayes |
|
1218 |
|
|
reg [1:0] owner_state;
|
1219 |
|
|
reg [1:0] owner_ns;
|
1220 |
|
|
|
1221 |
|
|
wire host_timeout;
|
1222 |
|
|
wire risc_timeout;
|
1223 |
36 |
rehayes |
|
1224 |
60 |
rehayes |
wire ram_ack_dly; // Delayed bus ack to simulate bus wait states
|
1225 |
|
|
reg [3:0] ack_dly_cnt; // Counter to delay bus ack to master modules
|
1226 |
54 |
rehayes |
|
1227 |
|
|
|
1228 |
|
|
//
|
1229 |
36 |
rehayes |
always @(posedge host_clk or negedge rst)
|
1230 |
|
|
if (!rst)
|
1231 |
54 |
rehayes |
owner_state <= BUS_IDLE;
|
1232 |
36 |
rehayes |
else
|
1233 |
54 |
rehayes |
owner_state <= owner_ns;
|
1234 |
|
|
|
1235 |
|
|
//
|
1236 |
|
|
always @*
|
1237 |
|
|
case (owner_state)
|
1238 |
|
|
BUS_IDLE :
|
1239 |
|
|
begin
|
1240 |
|
|
if (host_cyc)
|
1241 |
|
|
owner_ns = HOST_OWNS;
|
1242 |
|
|
else if (alt1_cyc)
|
1243 |
|
|
owner_ns = RISC_OWNS;
|
1244 |
|
|
end
|
1245 |
|
|
HOST_OWNS :
|
1246 |
|
|
begin
|
1247 |
|
|
if (!host_cyc && !alt1_cyc)
|
1248 |
|
|
owner_ns = BUS_IDLE;
|
1249 |
|
|
else if (alt1_cyc && (!host_cyc || host_timeout))
|
1250 |
|
|
owner_ns = RISC_OWNS;
|
1251 |
|
|
end
|
1252 |
|
|
RISC_OWNS :
|
1253 |
|
|
begin
|
1254 |
|
|
if (!host_cyc && !alt1_cyc)
|
1255 |
|
|
owner_ns = BUS_IDLE;
|
1256 |
|
|
else if (host_cyc && (!alt1_cyc || risc_timeout))
|
1257 |
|
|
owner_ns = HOST_OWNS;
|
1258 |
|
|
end
|
1259 |
|
|
default : owner_ns = BUS_IDLE;
|
1260 |
|
|
endcase
|
1261 |
36 |
rehayes |
|
1262 |
54 |
rehayes |
|
1263 |
60 |
rehayes |
assign host_timeout = (owner_state == HOST_OWNS) && (host_cycle_cnt > max_bus_hold) && any_ack;
|
1264 |
|
|
assign risc_timeout = (owner_state == RISC_OWNS) && (risc_cycle_cnt > max_bus_hold) && any_ack;
|
1265 |
54 |
rehayes |
|
1266 |
|
|
// Start counting cycles that the host has the bus, if the risc is also requesting the bus
|
1267 |
36 |
rehayes |
always @(posedge host_clk or negedge rst)
|
1268 |
|
|
if (!rst)
|
1269 |
|
|
host_cycle_cnt <= 0;
|
1270 |
54 |
rehayes |
else if ((owner_state != HOST_OWNS) || !alt1_cyc)
|
1271 |
|
|
host_cycle_cnt <= 0;
|
1272 |
|
|
else if (&host_cycle_cnt && !host_timeout) // Don't allow rollover
|
1273 |
|
|
host_cycle_cnt <= host_cycle_cnt;
|
1274 |
|
|
else if ((owner_state == HOST_OWNS) && alt1_cyc)
|
1275 |
|
|
host_cycle_cnt <= host_cycle_cnt + 1'b1;
|
1276 |
36 |
rehayes |
|
1277 |
54 |
rehayes |
// Start counting cycles that the risc has the bus, if the host is also requesting the bus
|
1278 |
36 |
rehayes |
always @(posedge host_clk or negedge rst)
|
1279 |
|
|
if (!rst)
|
1280 |
|
|
risc_cycle_cnt <= 0;
|
1281 |
54 |
rehayes |
else if ((owner_state != RISC_OWNS) || !host_cyc)
|
1282 |
|
|
risc_cycle_cnt <= 0;
|
1283 |
|
|
else if (&risc_cycle_cnt && !risc_timeout) // Don't allow rollover
|
1284 |
|
|
risc_cycle_cnt <= risc_cycle_cnt;
|
1285 |
|
|
else if ((owner_state == RISC_OWNS) && host_cyc)
|
1286 |
|
|
risc_cycle_cnt <= risc_cycle_cnt + 1'b1;
|
1287 |
36 |
rehayes |
|
1288 |
54 |
rehayes |
// Aribartration Logic for System Bus access
|
1289 |
|
|
assign any_ack = slv1_ack || slv2_ack || ram_ack;
|
1290 |
|
|
assign host_ack = (owner_state == HOST_OWNS) && any_ack && host_cyc;
|
1291 |
|
|
assign alt1_ack = (owner_state == RISC_OWNS) && any_ack && alt1_cyc;
|
1292 |
36 |
rehayes |
|
1293 |
54 |
rehayes |
|
1294 |
|
|
// Address decoding for different Slave module instances
|
1295 |
|
|
assign slv1_stb = sys_stb && (sys_adr >= slv1_base) && (sys_adr < (slv1_base + slv1_size));
|
1296 |
|
|
assign slv2_stb = sys_stb && (sys_adr >= slv2_base) && (sys_adr < (slv2_base + slv2_size));
|
1297 |
36 |
rehayes |
|
1298 |
|
|
// Address decoding for Testbench access to RAM
|
1299 |
54 |
rehayes |
assign ram_sel = sys_cyc && sys_stb && !(slv1_stb || slv2_stb) &&
|
1300 |
|
|
(sys_adr >= ram_base) &&
|
1301 |
|
|
(sys_adr < (ram_base + ram_size));
|
1302 |
|
|
|
1303 |
60 |
rehayes |
// Throw in some wait states from the memory
|
1304 |
|
|
always @(posedge host_clk)
|
1305 |
|
|
if ((ack_dly_cnt == ram_wait_states) || !ram_sel)
|
1306 |
|
|
ack_dly_cnt <= 0;
|
1307 |
|
|
else if (ram_sel)
|
1308 |
|
|
ack_dly_cnt <= ack_dly_cnt + 1'b1;
|
1309 |
36 |
rehayes |
|
1310 |
60 |
rehayes |
assign ram_ack_dly = (ack_dly_cnt == ram_wait_states);
|
1311 |
|
|
assign ram_ack = ram_sel && ram_ack_dly;
|
1312 |
36 |
rehayes |
|
1313 |
60 |
rehayes |
|
1314 |
54 |
rehayes |
// Create the System Read Data Bus from the Slave output data buses
|
1315 |
|
|
assign sys_din = ({dwidth{slv1_stb}} & slv1_din) |
|
1316 |
|
|
({dwidth{slv2_stb}} & slv2_din) |
|
1317 |
|
|
({dwidth{ram_sel}} & ram_dout);
|
1318 |
36 |
rehayes |
|
1319 |
54 |
rehayes |
// Mux for System Bus access
|
1320 |
|
|
always @*
|
1321 |
|
|
case (owner_state)
|
1322 |
|
|
BUS_IDLE :
|
1323 |
|
|
begin
|
1324 |
|
|
sys_cyc = 0;
|
1325 |
|
|
sys_stb = 0;
|
1326 |
|
|
sys_we = 0;
|
1327 |
|
|
sys_sel = 0;
|
1328 |
|
|
sys_adr = 0;
|
1329 |
|
|
sys_dout = 0;
|
1330 |
|
|
end
|
1331 |
|
|
HOST_OWNS :
|
1332 |
|
|
begin
|
1333 |
|
|
sys_cyc = host_cyc;
|
1334 |
|
|
sys_stb = host_stb;
|
1335 |
|
|
sys_we = host_we;
|
1336 |
|
|
sys_sel = host_sel;
|
1337 |
|
|
sys_adr = host_adr;
|
1338 |
|
|
sys_dout = host_din;
|
1339 |
|
|
end
|
1340 |
|
|
RISC_OWNS :
|
1341 |
|
|
begin
|
1342 |
|
|
sys_cyc = alt1_cyc;
|
1343 |
|
|
sys_stb = alt1_stb;
|
1344 |
|
|
sys_we = alt1_we;
|
1345 |
|
|
sys_sel = alt1_sel;
|
1346 |
|
|
sys_adr = alt1_adr;
|
1347 |
|
|
sys_dout = alt1_din;
|
1348 |
|
|
end
|
1349 |
|
|
default :
|
1350 |
|
|
begin
|
1351 |
|
|
sys_cyc = 0;
|
1352 |
|
|
sys_stb = 0;
|
1353 |
|
|
sys_we = 0;
|
1354 |
|
|
sys_sel = 0;
|
1355 |
|
|
sys_adr = 0;
|
1356 |
|
|
sys_dout = 0;
|
1357 |
|
|
end
|
1358 |
|
|
endcase
|
1359 |
36 |
rehayes |
|
1360 |
54 |
rehayes |
endmodule // bus_arbitration
|
1361 |
36 |
rehayes |
|
1362 |
54 |
rehayes |
////////////////////////////////////////////////////////////////////////////////
|
1363 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
1364 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
1365 |
|
|
module tb_slave #(parameter SINGLE_CYCLE = 1'b0, // No bus wait state added
|
1366 |
|
|
parameter DWIDTH = 16) // Data bus width
|
1367 |
|
|
(
|
1368 |
|
|
// Wishbone Signals
|
1369 |
|
|
output [DWIDTH-1:0] wb_dat_o, // databus output
|
1370 |
|
|
output wb_ack_o, // bus cycle acknowledge output
|
1371 |
|
|
input wb_clk_i, // master clock input
|
1372 |
|
|
input wb_rst_i, // synchronous active high reset
|
1373 |
|
|
input arst_i, // asynchronous reset
|
1374 |
|
|
input [2:0] wb_adr_i, // lower address bits
|
1375 |
|
|
input [DWIDTH-1:0] wb_dat_i, // databus input
|
1376 |
|
|
input wb_we_i, // write enable input
|
1377 |
|
|
input wb_stb_i, // stobe/core select signal
|
1378 |
|
|
input wb_cyc_i, // valid bus cycle input
|
1379 |
|
|
input [1:0] wb_sel_i, // Select byte in word bus transaction
|
1380 |
|
|
// PIT IO Signals
|
1381 |
|
|
output reg error_pulse, // Error detected output pulse
|
1382 |
|
|
output reg ack_pulse, // Thread ack output pulse
|
1383 |
|
|
input [19:0] vector
|
1384 |
|
|
);
|
1385 |
|
|
|
1386 |
|
|
wire async_rst_b; // Asyncronous reset
|
1387 |
|
|
wire sync_reset; // Syncronous reset
|
1388 |
|
|
|
1389 |
|
|
// Wishbone Bus interface
|
1390 |
|
|
// registers
|
1391 |
|
|
reg bus_wait_state; // Holdoff wb_ack_o for one clock to add wait state
|
1392 |
|
|
reg [DWIDTH-1:0] rd_data_mux; // Pseudo Register, WISHBONE Read Data Mux
|
1393 |
|
|
reg [DWIDTH-1:0] rd_data_reg; // Latch for WISHBONE Read Data
|
1394 |
36 |
rehayes |
|
1395 |
54 |
rehayes |
reg [15:0] check_point_reg;
|
1396 |
|
|
reg [15:0] channel_ack_reg;
|
1397 |
|
|
reg [15:0] channel_err_reg;
|
1398 |
36 |
rehayes |
|
1399 |
54 |
rehayes |
event check_point_wrt;
|
1400 |
|
|
event channel_ack_wrt;
|
1401 |
|
|
event channel_err_wrt;
|
1402 |
36 |
rehayes |
|
1403 |
54 |
rehayes |
// Wires
|
1404 |
|
|
wire module_sel; // This module is selected for bus transaction
|
1405 |
|
|
wire wb_wacc; // WISHBONE Write Strobe
|
1406 |
|
|
wire wb_racc; // WISHBONE Read Access (Clock gating signal)
|
1407 |
36 |
rehayes |
|
1408 |
54 |
rehayes |
//
|
1409 |
|
|
// module body
|
1410 |
|
|
//
|
1411 |
36 |
rehayes |
|
1412 |
54 |
rehayes |
// generate internal resets
|
1413 |
|
|
|
1414 |
|
|
|
1415 |
|
|
// generate wishbone signals
|
1416 |
|
|
assign module_sel = wb_cyc_i && wb_stb_i;
|
1417 |
|
|
assign wb_wacc = module_sel && wb_we_i && (wb_ack_o || SINGLE_CYCLE);
|
1418 |
|
|
assign wb_racc = module_sel && !wb_we_i;
|
1419 |
|
|
assign wb_ack_o = SINGLE_CYCLE ? module_sel : bus_wait_state;
|
1420 |
|
|
assign wb_dat_o = SINGLE_CYCLE ? rd_data_mux : rd_data_reg;
|
1421 |
|
|
|
1422 |
|
|
// generate acknowledge output signal, By using register all accesses takes two cycles.
|
1423 |
|
|
// Accesses in back to back clock cycles are not possable.
|
1424 |
|
|
always @(posedge wb_clk_i or negedge arst_i)
|
1425 |
|
|
if (!arst_i)
|
1426 |
|
|
bus_wait_state <= 1'b0;
|
1427 |
|
|
else if (wb_rst_i)
|
1428 |
|
|
bus_wait_state <= 1'b0;
|
1429 |
|
|
else
|
1430 |
|
|
bus_wait_state <= module_sel && !bus_wait_state;
|
1431 |
|
|
|
1432 |
|
|
// assign data read bus -- DAT_O
|
1433 |
|
|
always @(posedge wb_clk_i)
|
1434 |
|
|
if ( wb_racc ) // Clock gate for power saving
|
1435 |
|
|
rd_data_reg <= rd_data_mux;
|
1436 |
|
|
|
1437 |
|
|
// WISHBONE Read Data Mux
|
1438 |
|
|
always @*
|
1439 |
|
|
case (wb_adr_i) // synopsys parallel_case
|
1440 |
|
|
3'b000: rd_data_mux = check_point_reg;
|
1441 |
|
|
3'b001: rd_data_mux = channel_ack_reg;
|
1442 |
|
|
3'b010: rd_data_mux = channel_err_reg;
|
1443 |
|
|
3'b011: rd_data_mux = 16'b0;
|
1444 |
|
|
endcase
|
1445 |
|
|
|
1446 |
|
|
// generate wishbone write register strobes
|
1447 |
|
|
always @(posedge wb_clk_i or negedge arst_i)
|
1448 |
|
|
begin
|
1449 |
|
|
if (!arst_i)
|
1450 |
|
|
begin
|
1451 |
|
|
check_point_reg <= 0;
|
1452 |
|
|
channel_ack_reg <= 0;
|
1453 |
|
|
channel_err_reg <= 0;
|
1454 |
|
|
ack_pulse <= 0;
|
1455 |
|
|
error_pulse <= 0;
|
1456 |
|
|
end
|
1457 |
|
|
else if (wb_wacc)
|
1458 |
|
|
case (wb_adr_i) // synopsys parallel_case
|
1459 |
|
|
3'b000 :
|
1460 |
|
|
begin
|
1461 |
|
|
check_point_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : check_point_reg[ 7:0];
|
1462 |
|
|
check_point_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : check_point_reg[15:8];
|
1463 |
|
|
-> check_point_wrt;
|
1464 |
|
|
end
|
1465 |
|
|
3'b001 :
|
1466 |
|
|
begin
|
1467 |
|
|
channel_ack_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : channel_ack_reg[ 7:0];
|
1468 |
|
|
channel_ack_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : channel_ack_reg[15:8];
|
1469 |
|
|
ack_pulse <= 1;
|
1470 |
|
|
-> channel_ack_wrt;
|
1471 |
|
|
end
|
1472 |
|
|
3'b010 :
|
1473 |
|
|
begin
|
1474 |
|
|
channel_err_reg[ 7:0] <= wb_sel_i[0] ? wb_dat_i[ 7:0] : channel_err_reg[ 7:0];
|
1475 |
|
|
channel_err_reg[15:8] <= wb_sel_i[1] ? wb_dat_i[15:8] : channel_err_reg[15:8];
|
1476 |
|
|
error_pulse <= 1'b1;
|
1477 |
|
|
-> channel_err_wrt;
|
1478 |
|
|
end
|
1479 |
|
|
3'b011 :
|
1480 |
|
|
begin
|
1481 |
|
|
end
|
1482 |
|
|
default: ;
|
1483 |
|
|
endcase
|
1484 |
|
|
else
|
1485 |
|
|
begin
|
1486 |
|
|
ack_pulse <= 0;
|
1487 |
|
|
error_pulse <= 1'b0;
|
1488 |
|
|
end
|
1489 |
|
|
end
|
1490 |
|
|
|
1491 |
|
|
always @check_point_wrt
|
1492 |
|
|
begin
|
1493 |
|
|
#1;
|
1494 |
|
|
$display("\nSoftware Checkpoint #%h -- at vector=%d\n", check_point_reg, vector);
|
1495 |
|
|
end
|
1496 |
|
|
|
1497 |
|
|
always @channel_err_wrt
|
1498 |
|
|
begin
|
1499 |
|
|
#1;
|
1500 |
|
|
$display("\n ------ !!!!! Software Checkpoint Error #%d -- at vector=%d\n -------", channel_err_reg, vector);
|
1501 |
|
|
end
|
1502 |
|
|
|
1503 |
|
|
|
1504 |
|
|
endmodule // tb_slave
|
1505 |
|
|
|