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 |
|
|
|
48 |
|
|
//
|
49 |
|
|
// wires && regs
|
50 |
|
|
//
|
51 |
|
|
reg mstr_test_clk;
|
52 |
|
|
reg [19:0] vector;
|
53 |
|
|
reg [ 7:0] test_num;
|
54 |
|
|
reg [15:0] wb_temp;
|
55 |
|
|
reg rstn;
|
56 |
|
|
reg sync_reset;
|
57 |
|
|
reg por_reset_b;
|
58 |
|
|
reg stop_mode;
|
59 |
|
|
reg wait_mode;
|
60 |
|
|
reg debug_mode;
|
61 |
|
|
reg scantestmode;
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
wire [31:0] adr;
|
65 |
|
|
wire [15:0] dat_i, dat_o, dat0_i, dat1_i, dat2_i, dat3_i;
|
66 |
|
|
wire we;
|
67 |
|
|
wire stb;
|
68 |
|
|
wire cyc;
|
69 |
|
|
wire ack, ack_1, ack_2, ack_3, ack_4;
|
70 |
|
|
wire inta_1, inta_2, inta_3, inta_4;
|
71 |
|
|
wire count_en_1;
|
72 |
|
|
wire count_flag_1;
|
73 |
|
|
|
74 |
|
|
reg [15:0] q, qq;
|
75 |
|
|
|
76 |
|
|
reg [ 7:0] ram_8 [65535:0];
|
77 |
|
|
wire write_mem_strb_l;
|
78 |
|
|
wire write_mem_strb_h;
|
79 |
|
|
reg [127:0] channel_req;
|
80 |
|
|
wire [ 7:0] xgswt; // XGATE Software Triggers
|
81 |
|
|
wire [MAX_CHANNEL:0] xgif; // Max XGATE Interrupt Channel Number
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
wire [15:0] xgate_address;
|
85 |
|
|
wire [15:0] write_mem_data;
|
86 |
|
|
wire [15:0] read_mem_data;
|
87 |
|
|
|
88 |
|
|
wire scl, scl0_o, scl0_oen, scl1_o, scl1_oen;
|
89 |
|
|
wire sda, sda0_o, sda0_oen, sda1_o, sda1_oen;
|
90 |
|
|
|
91 |
|
|
// Name Address Locations
|
92 |
|
|
parameter XGATE_XGMCTL = 5'h00;
|
93 |
|
|
parameter XGATE_XGCHID = 5'h01;
|
94 |
|
|
parameter XGATE_XGISPHI = 5'h02;
|
95 |
|
|
parameter XGATE_XGISPLO = 5'h03;
|
96 |
|
|
parameter XGATE_XGVBR = 5'h04;
|
97 |
|
|
parameter XGATE_XGIF_7 = 5'h05;
|
98 |
|
|
parameter XGATE_XGIF_6 = 5'h06;
|
99 |
|
|
parameter XGATE_XGIF_5 = 5'h07;
|
100 |
|
|
parameter XGATE_XGIF_4 = 5'h08;
|
101 |
|
|
parameter XGATE_XGIF_3 = 5'h09;
|
102 |
|
|
parameter XGATE_XGIF_2 = 5'h0a;
|
103 |
|
|
parameter XGATE_XGIF_1 = 5'h0b;
|
104 |
|
|
parameter XGATE_XGIF_0 = 5'h0c;
|
105 |
|
|
parameter XGATE_XGSWT = 5'h0d;
|
106 |
|
|
parameter XGATE_XGSEM = 5'h0e;
|
107 |
|
|
parameter XGATE_RES1 = 5'h0f;
|
108 |
|
|
parameter XGATE_XGCCR = 5'h10;
|
109 |
|
|
parameter XGATE_XGPC = 5'h11;
|
110 |
|
|
parameter XGATE_RES1 = 5'h12;
|
111 |
|
|
parameter XGATE_XGR1 = 5'h13;
|
112 |
|
|
parameter XGATE_XGR2 = 5'h14;
|
113 |
|
|
parameter XGATE_XGR3 = 5'h15;
|
114 |
|
|
parameter XGATE_XGR4 = 5'h16;
|
115 |
|
|
parameter XGATE_XGR5 = 5'h17;
|
116 |
|
|
parameter XGATE_XGR6 = 5'h18;
|
117 |
|
|
parameter XGATE_XGR7 = 5'h19;
|
118 |
|
|
|
119 |
|
|
parameter COP_CNTRL = 5'b0_0000;
|
120 |
|
|
|
121 |
|
|
parameter COP_CNTRL_COP_EVENT = 16'h0100; // COP Enable interrupt request
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
// initial values and testbench setup
|
125 |
|
|
initial
|
126 |
|
|
begin
|
127 |
|
|
mstr_test_clk = 0;
|
128 |
|
|
vector = 0;
|
129 |
|
|
test_num = 0;
|
130 |
|
|
por_reset_b = 0;
|
131 |
|
|
stop_mode = 0;
|
132 |
|
|
wait_mode = 0;
|
133 |
|
|
debug_mode = 0;
|
134 |
|
|
scantestmode = 0;
|
135 |
|
|
// channel_req = 0;
|
136 |
|
|
|
137 |
|
|
`ifdef WAVES
|
138 |
|
|
$shm_open("waves");
|
139 |
|
|
$shm_probe("AS",tst_bench_top,"AS");
|
140 |
|
|
$display("\nINFO: Signal dump enabled ...\n\n");
|
141 |
|
|
`endif
|
142 |
|
|
|
143 |
|
|
`ifdef WAVES_V
|
144 |
|
|
$dumpfile ("xgate_wave_dump.lxt");
|
145 |
|
|
$dumpvars (0, tst_bench_top);
|
146 |
|
|
$dumpon;
|
147 |
|
|
$display("\nINFO: VCD Signal dump enabled ...\n\n");
|
148 |
|
|
`endif
|
149 |
|
|
|
150 |
|
|
end
|
151 |
|
|
|
152 |
|
|
// generate clock
|
153 |
|
|
always #20 mstr_test_clk = ~mstr_test_clk;
|
154 |
|
|
|
155 |
|
|
always @(posedge mstr_test_clk)
|
156 |
|
|
vector = vector + 1;
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
// Write memory interface to RAM
|
160 |
|
|
always @(posedge mstr_test_clk)
|
161 |
|
|
begin
|
162 |
|
|
if (write_mem_strb_l && !write_mem_strb_h)
|
163 |
|
|
ram_8[xgate_address] = write_mem_data[7:0];
|
164 |
|
|
if (write_mem_strb_h && !write_mem_strb_l)
|
165 |
|
|
ram_8[xgate_address] = write_mem_data[7:0];
|
166 |
|
|
if (write_mem_strb_h && write_mem_strb_l)
|
167 |
|
|
begin
|
168 |
|
|
ram_8[xgate_address] = write_mem_data[15:8];
|
169 |
|
|
ram_8[xgate_address+1] = write_mem_data[7:0];
|
170 |
|
|
end
|
171 |
|
|
end
|
172 |
|
|
|
173 |
|
|
parameter CHECK_POINT = 16'h8000;
|
174 |
|
|
parameter CHANNEL_ACK = CHECK_POINT + 2;
|
175 |
|
|
parameter CHANNEL_ERR = CHECK_POINT + 4;
|
176 |
|
|
reg [ 7:0] check_point_reg;
|
177 |
|
|
reg [ 7:0] channel_ack_reg;
|
178 |
|
|
reg [ 7:0] channel_err_reg;
|
179 |
|
|
// Special Memory Mapped Testbench Registers
|
180 |
|
|
always @(posedge mstr_test_clk or negedge rstn)
|
181 |
|
|
begin
|
182 |
|
|
if (!rstn)
|
183 |
|
|
begin
|
184 |
|
|
check_point_reg = 0;
|
185 |
|
|
channel_ack_reg = 0;
|
186 |
|
|
channel_err_reg = 0;
|
187 |
|
|
end
|
188 |
|
|
if (write_mem_strb_l && (xgate_address == CHECK_POINT))
|
189 |
|
|
check_point_reg = write_mem_data[7:0];
|
190 |
|
|
if (write_mem_strb_l && (xgate_address == CHANNEL_ACK))
|
191 |
|
|
channel_ack_reg = write_mem_data[7:0];
|
192 |
|
|
if (write_mem_strb_l && (xgate_address == CHANNEL_ERR))
|
193 |
|
|
channel_err_reg = write_mem_data[7:0];
|
194 |
|
|
end
|
195 |
|
|
|
196 |
|
|
always @check_point_reg
|
197 |
|
|
$display("\nSoftware Checkpoint #%d -- at vector=%d\n", check_point_reg, vector);
|
198 |
|
|
|
199 |
|
|
wire [ 6:0] current_active_channel = xgate.risc.xgchid;
|
200 |
|
|
always @channel_ack_reg
|
201 |
|
|
clear_channel(current_active_channel);
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
// hookup wishbone master model
|
205 |
|
|
wb_master_model #(.dwidth(16), .awidth(32))
|
206 |
|
|
u0 (
|
207 |
|
|
.clk(mstr_test_clk),
|
208 |
|
|
.rst(rstn),
|
209 |
|
|
.adr(adr),
|
210 |
|
|
.din(dat_i),
|
211 |
|
|
.dout(dat_o),
|
212 |
|
|
.cyc(cyc),
|
213 |
|
|
.stb(stb),
|
214 |
|
|
.we(we),
|
215 |
|
|
.sel(),
|
216 |
|
|
.ack(ack),
|
217 |
|
|
.err(1'b0),
|
218 |
|
|
.rty(1'b0)
|
219 |
|
|
);
|
220 |
|
|
|
221 |
|
|
|
222 |
|
|
// Address decoding for different XGATE module instances
|
223 |
|
|
wire stb0 = stb && ~adr[6] && ~adr[5];
|
224 |
|
|
wire stb1 = stb && ~adr[6] && adr[5];
|
225 |
|
|
wire stb2 = stb && adr[6] && ~adr[5];
|
226 |
|
|
wire stb3 = stb && adr[6] && adr[5];
|
227 |
|
|
|
228 |
|
|
assign dat1_i = 16'h0000;
|
229 |
|
|
assign dat2_i = 16'h0000;
|
230 |
|
|
assign dat3_i = 16'h0000;
|
231 |
|
|
assign ack_2 = 1'b0;
|
232 |
|
|
assign ack_3 = 1'b0;
|
233 |
|
|
assign ack_4 = 1'b0;
|
234 |
|
|
|
235 |
|
|
// Create the Read Data Bus
|
236 |
|
|
assign dat_i = ({16{stb0}} & dat0_i) |
|
237 |
|
|
({16{stb1}} & dat1_i) |
|
238 |
|
|
({16{stb2}} & dat2_i) |
|
239 |
|
|
({16{stb3}} & {8'b0, dat3_i[7:0]});
|
240 |
|
|
|
241 |
|
|
assign ack = ack_1 || ack_2 || ack_3 || ack_4;
|
242 |
|
|
|
243 |
|
|
assign read_mem_data = {ram_8[xgate_address], ram_8[xgate_address+1]};
|
244 |
|
|
|
245 |
|
|
// hookup wishbone_COP_master core - Parameters take all default values
|
246 |
|
|
// Async Reset, 16 bit Bus, 16 bit Granularity
|
247 |
|
|
xgate_top #(.SINGLE_CYCLE(1'b0),
|
248 |
|
|
.MAX_CHANNEL(MAX_CHANNEL)) // Max XGATE Interrupt Channel Number
|
249 |
|
|
xgate(
|
250 |
|
|
// wishbone interface
|
251 |
|
|
.wbs_clk_i(mstr_test_clk),
|
252 |
|
|
.wbs_rst_i(1'b0), // sync_reset
|
253 |
|
|
.arst_i(rstn), // rstn
|
254 |
|
|
.wbs_adr_i(adr[4:0]),
|
255 |
|
|
.wbs_dat_i(dat_o),
|
256 |
|
|
.wbs_dat_o(dat0_i),
|
257 |
|
|
.wbs_we_i(we),
|
258 |
|
|
.wbs_stb_i(stb0),
|
259 |
|
|
.wbs_cyc_i(cyc),
|
260 |
|
|
.wbs_sel_i( 2'b11 ),
|
261 |
|
|
.wbs_ack_o(ack_1),
|
262 |
|
|
|
263 |
|
|
.xgif( xgif ), // XGATE Interrupt Flag
|
264 |
|
|
.risc_clk( mstr_test_clk ),
|
265 |
|
|
.xgswt( xgswt),
|
266 |
|
|
.chan_req_i( {channel_req[127:40], xgswt, channel_req[31:0]} ),
|
267 |
|
|
.xgate_address( xgate_address ),
|
268 |
|
|
.write_mem_strb_l( write_mem_strb_l ),
|
269 |
|
|
.write_mem_strb_h( write_mem_strb_h ),
|
270 |
|
|
.write_mem_data( write_mem_data ),
|
271 |
|
|
.read_mem_data( read_mem_data ),
|
272 |
|
|
.scantestmode( scantestmode )
|
273 |
|
|
);
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
278 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
279 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
280 |
|
|
|
281 |
|
|
// Test Program
|
282 |
|
|
initial
|
283 |
|
|
begin
|
284 |
|
|
$readmemh("../../../bench/verilog/jump_mem.v", ram_8);
|
285 |
|
|
$display("\nstatus at time: %t Testbench started", $time);
|
286 |
|
|
|
287 |
|
|
// reset system
|
288 |
|
|
rstn = 1'b1; // negate reset
|
289 |
|
|
channel_req = 1; //
|
290 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
291 |
|
|
sync_reset = 1'b1; // Make the sync reset 1 clock cycle long
|
292 |
|
|
#2; // move the async reset away from the clock edge
|
293 |
|
|
rstn = 1'b0; // assert async reset
|
294 |
|
|
#5; // Keep the async reset pulse with less than a clock cycle
|
295 |
|
|
rstn = 1'b1; // negate async reset
|
296 |
|
|
por_reset_b = 1'b1;
|
297 |
|
|
channel_req = 0; //
|
298 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
299 |
|
|
sync_reset = 1'b0;
|
300 |
|
|
channel_req = 0; //
|
301 |
|
|
|
302 |
|
|
$display("\nstatus at time: %t done reset", $time);
|
303 |
|
|
test_num = test_num + 1;
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
activate_thread_sw(1);
|
307 |
|
|
wait_irq_set(1);
|
308 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0002);
|
309 |
|
|
|
310 |
|
|
activate_thread_sw(2);
|
311 |
|
|
wait_irq_set(2);
|
312 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0004);
|
313 |
|
|
|
314 |
|
|
activate_thread_sw(3);
|
315 |
|
|
wait_irq_set(3);
|
316 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0008);
|
317 |
|
|
|
318 |
|
|
activate_thread_sw(4);
|
319 |
|
|
wait_irq_set(4);
|
320 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0010);
|
321 |
|
|
|
322 |
|
|
activate_thread_sw(5);
|
323 |
|
|
wait_irq_set(5);
|
324 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0020);
|
325 |
|
|
|
326 |
|
|
activate_thread_sw(6);
|
327 |
|
|
wait_irq_set(6);
|
328 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0040);
|
329 |
|
|
|
330 |
|
|
activate_thread_sw(7);
|
331 |
|
|
wait_irq_set(7);
|
332 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0080);
|
333 |
|
|
|
334 |
|
|
activate_thread_sw(8);
|
335 |
|
|
wait_irq_set(8);
|
336 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0100);
|
337 |
|
|
|
338 |
|
|
activate_thread_sw(9);
|
339 |
|
|
wait_irq_set(9);
|
340 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0200);
|
341 |
|
|
|
342 |
|
|
u0.wb_write(1, XGATE_XGSEM, 16'h5050);
|
343 |
|
|
u0.wb_cmp(0, XGATE_XGSEM, 16'h0050); //
|
344 |
|
|
activate_thread_sw(10);
|
345 |
|
|
wait_irq_set(10);
|
346 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'h0400);
|
347 |
|
|
u0.wb_write(1, XGATE_XGSEM, 16'hff00); // clear the old settings
|
348 |
|
|
u0.wb_cmp(0, XGATE_XGSEM, 16'h0000); //
|
349 |
|
|
u0.wb_write(1, XGATE_XGSEM, 16'ha0a0); // Verify that bits were unlocked by RISC
|
350 |
|
|
u0.wb_cmp(0, XGATE_XGSEM, 16'h00a0); // Verify bits were set
|
351 |
|
|
u0.wb_write(1, XGATE_XGSEM, 16'hff08); // Try to set the bit that was left locked by the RISC
|
352 |
|
|
u0.wb_cmp(0, XGATE_XGSEM, 16'h0000); // Verify no bits were set
|
353 |
|
|
|
354 |
|
|
repeat(2) @(posedge mstr_test_clk);
|
355 |
|
|
|
356 |
|
|
activate_channel(33);
|
357 |
|
|
repeat(20) @(posedge mstr_test_clk);
|
358 |
|
|
activate_channel(20);
|
359 |
|
|
repeat(20) @(posedge mstr_test_clk);
|
360 |
|
|
|
361 |
|
|
dump_ram(0);
|
362 |
|
|
$display("\nTestbench done at vector=%d\n", vector);
|
363 |
|
|
$finish;
|
364 |
|
|
//
|
365 |
|
|
// program core
|
366 |
|
|
//
|
367 |
|
|
|
368 |
|
|
reg_test_16;
|
369 |
|
|
|
370 |
|
|
repeat(10) @(posedge mstr_test_clk);
|
371 |
|
|
|
372 |
|
|
$display("\nTestbench done at vector=%d\n", vector);
|
373 |
|
|
$finish;
|
374 |
|
|
end
|
375 |
|
|
|
376 |
|
|
// Poll for XGATE Interrupt set
|
377 |
|
|
task wait_irq_set;
|
378 |
|
|
input [ 6:0] chan_val;
|
379 |
|
|
begin
|
380 |
|
|
while(!xgif[chan_val])
|
381 |
|
|
@(posedge mstr_test_clk); // poll it until it is set
|
382 |
|
|
$display("XGATE Interrupt Request set detected at vector =%d", vector);
|
383 |
|
|
end
|
384 |
|
|
endtask
|
385 |
|
|
|
386 |
|
|
// Poll for flag set
|
387 |
|
|
task wait_flag_set;
|
388 |
|
|
begin
|
389 |
|
|
u0.wb_read(1, COP_CNTRL, q);
|
390 |
|
|
while(~|(q & COP_CNTRL_COP_EVENT))
|
391 |
|
|
u0.wb_read(1, COP_CNTRL, q); // poll it until it is set
|
392 |
|
|
$display("COP Flag set detected at vector =%d", vector);
|
393 |
|
|
end
|
394 |
|
|
endtask
|
395 |
|
|
|
396 |
|
|
// check register bits - reset, read/write
|
397 |
|
|
task reg_test_16;
|
398 |
|
|
begin
|
399 |
|
|
test_num = test_num + 1;
|
400 |
|
|
$display("TEST #%d Starts at vector=%d, reg_test_16", test_num, vector);
|
401 |
|
|
u0.wb_cmp(0, XGATE_XGMCTL, 16'h0000); // verify reset
|
402 |
|
|
u0.wb_cmp(0, XGATE_XGCHID, 16'h0000); // verify reset
|
403 |
|
|
u0.wb_cmp(0, XGATE_XGISPHI, 16'h0000); // verify reset
|
404 |
|
|
u0.wb_cmp(0, XGATE_XGISPLO, 16'h0000); // verify reset
|
405 |
|
|
u0.wb_cmp(0, XGATE_XGVBR, 16'h0000); // verify reset
|
406 |
|
|
u0.wb_cmp(0, XGATE_XGIF_7, 16'h0000); // verify reset
|
407 |
|
|
u0.wb_cmp(0, XGATE_XGIF_6, 16'h0000); // verify reset
|
408 |
|
|
u0.wb_cmp(0, XGATE_XGIF_5, 16'h0000); // verify reset
|
409 |
|
|
u0.wb_cmp(0, XGATE_XGIF_4, 16'h0000); // verify reset
|
410 |
|
|
u0.wb_cmp(0, XGATE_XGIF_3, 16'h0000); // verify reset
|
411 |
|
|
u0.wb_cmp(0, XGATE_XGIF_2, 16'h0000); // verify reset
|
412 |
|
|
u0.wb_cmp(0, XGATE_XGIF_1, 16'h0000); // verify reset
|
413 |
|
|
u0.wb_cmp(0, XGATE_XGIF_0, 16'h0000); // verify reset
|
414 |
|
|
u0.wb_cmp(0, XGATE_XGSWT, 16'h0000); // verify reset
|
415 |
|
|
u0.wb_cmp(0, XGATE_XGSEM, 16'h0000); // verify reset
|
416 |
|
|
u0.wb_cmp(0, XGATE_XGCCR, 16'h0000); // verify reset
|
417 |
|
|
u0.wb_cmp(0, XGATE_XGPC, 16'h0000); // verify reset
|
418 |
|
|
u0.wb_cmp(0, XGATE_XGR1, 16'h0000); // verify reset
|
419 |
|
|
u0.wb_cmp(0, XGATE_XGR2, 16'h0000); // verify reset
|
420 |
|
|
u0.wb_cmp(0, XGATE_XGR3, 16'h0000); // verify reset
|
421 |
|
|
u0.wb_cmp(0, XGATE_XGR4, 16'h0000); // verify reset
|
422 |
|
|
u0.wb_cmp(0, XGATE_XGR5, 16'h0000); // verify reset
|
423 |
|
|
u0.wb_cmp(0, XGATE_XGR6, 16'h0000); // verify reset
|
424 |
|
|
u0.wb_cmp(0, XGATE_XGR7, 16'h0000); // verify reset
|
425 |
|
|
|
426 |
|
|
u0.wb_write(1, XGATE_XGR1, 16'h5555);
|
427 |
|
|
u0.wb_cmp( 0, XGATE_XGR1, 16'h5555);
|
428 |
|
|
u0.wb_write(1, XGATE_XGR2, 16'haaaa);
|
429 |
|
|
u0.wb_cmp( 0, XGATE_XGR2, 16'haaaa);
|
430 |
|
|
u0.wb_write(1, XGATE_XGR3, 16'h9999);
|
431 |
|
|
u0.wb_cmp( 0, XGATE_XGR3, 16'h9999);
|
432 |
|
|
u0.wb_write(1, XGATE_XGR4, 16'hcccc);
|
433 |
|
|
u0.wb_cmp( 0, XGATE_XGR4, 16'hcccc);
|
434 |
|
|
u0.wb_write(1, XGATE_XGR5, 16'h3333);
|
435 |
|
|
u0.wb_cmp( 0, XGATE_XGR5, 16'h3333);
|
436 |
|
|
u0.wb_write(1, XGATE_XGR6, 16'h6666);
|
437 |
|
|
u0.wb_cmp( 0, XGATE_XGR6, 16'h6666);
|
438 |
|
|
u0.wb_write(1, XGATE_XGR7, 16'ha5a5);
|
439 |
|
|
u0.wb_cmp( 0, XGATE_XGR7, 16'ha5a5);
|
440 |
|
|
|
441 |
|
|
u0.wb_write(1, XGATE_XGPC, 16'h5a5a);
|
442 |
|
|
u0.wb_cmp( 0, XGATE_XGPC, 16'h5a5a);
|
443 |
|
|
|
444 |
|
|
u0.wb_write(1, XGATE_XGCCR, 16'hfffa);
|
445 |
|
|
u0.wb_cmp( 0, XGATE_XGCCR, 16'h000a);
|
446 |
|
|
u0.wb_write(1, XGATE_XGCCR, 16'hfff5);
|
447 |
|
|
u0.wb_cmp( 0, XGATE_XGCCR, 16'h0005);
|
448 |
|
|
|
449 |
|
|
end
|
450 |
|
|
endtask
|
451 |
|
|
|
452 |
|
|
|
453 |
|
|
|
454 |
|
|
|
455 |
|
|
task system_reset; // reset system
|
456 |
|
|
begin
|
457 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
458 |
|
|
sync_reset = 1'b1; // Make the sync reset 1 clock cycle long
|
459 |
|
|
#2; // move the async reset away from the clock edge
|
460 |
|
|
rstn = 1'b0; // assert async reset
|
461 |
|
|
#5; // Keep the async reset pulse with less than a clock cycle
|
462 |
|
|
rstn = 1'b1; // negate async reset
|
463 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
464 |
|
|
sync_reset = 1'b0;
|
465 |
|
|
|
466 |
|
|
$display("\nstatus: %t System Reset Task Done", $time);
|
467 |
|
|
test_num = test_num + 1;
|
468 |
|
|
|
469 |
|
|
repeat(2) @(posedge mstr_test_clk);
|
470 |
|
|
end
|
471 |
|
|
endtask
|
472 |
|
|
|
473 |
|
|
|
474 |
|
|
task activate_channel;
|
475 |
|
|
input [ 6:0] chan_val;
|
476 |
|
|
begin
|
477 |
|
|
$display("Activating Channel %d", chan_val);
|
478 |
|
|
|
479 |
|
|
channel_req[chan_val] = 1'b1; //
|
480 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
481 |
|
|
end
|
482 |
|
|
endtask
|
483 |
|
|
|
484 |
|
|
|
485 |
|
|
task clear_channel;
|
486 |
|
|
input [ 6:0] chan_val;
|
487 |
|
|
begin
|
488 |
|
|
$display("Clearing Channel interrupt input #%d", chan_val);
|
489 |
|
|
|
490 |
|
|
channel_req[chan_val] = 1'b0; //
|
491 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
492 |
|
|
end
|
493 |
|
|
endtask
|
494 |
|
|
|
495 |
|
|
|
496 |
|
|
task clear_irq_flag;
|
497 |
|
|
input [ 6:0] chan_val;
|
498 |
|
|
begin
|
499 |
|
|
$display("Clearing Channel interrupt flag #%d", chan_val);
|
500 |
|
|
if (0 < chan_val < 16)
|
501 |
|
|
u0.wb_write(1, XGATE_XGIF_0, 16'hffff);
|
502 |
|
|
if (15 < chan_val < 32)
|
503 |
|
|
u0.wb_write(1, XGATE_XGIF_1, 16'hffff);
|
504 |
|
|
if (31 < chan_val < 48)
|
505 |
|
|
u0.wb_write(1, XGATE_XGIF_2, 16'hffff);
|
506 |
|
|
if (47 < chan_val < 64)
|
507 |
|
|
u0.wb_write(1, XGATE_XGIF_3, 16'hffff);
|
508 |
|
|
if (63 < chan_val < 80)
|
509 |
|
|
u0.wb_write(1, XGATE_XGIF_4, 16'hffff);
|
510 |
|
|
if (79 < chan_val < 96)
|
511 |
|
|
u0.wb_write(1, XGATE_XGIF_5, 16'hffff);
|
512 |
|
|
if (95 < chan_val < 112)
|
513 |
|
|
u0.wb_write(1, XGATE_XGIF_6, 16'hffff);
|
514 |
|
|
if (111 < chan_val < 128)
|
515 |
|
|
u0.wb_write(1, XGATE_XGIF_7, 16'hffff);
|
516 |
|
|
|
517 |
|
|
channel_req[chan_val] = 1'b0; //
|
518 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
519 |
|
|
end
|
520 |
|
|
endtask
|
521 |
|
|
|
522 |
|
|
|
523 |
|
|
task activate_thread_sw;
|
524 |
|
|
input [ 6:0] chan_val;
|
525 |
|
|
begin
|
526 |
|
|
$display("Activating Sofrware Thread - Channel #%d", chan_val);
|
527 |
|
|
|
528 |
|
|
u0.wb_write(0, XGATE_XGMCTL, 16'h8080); // Enable XGATE
|
529 |
|
|
|
530 |
|
|
channel_req[chan_val] = 1'b1; //
|
531 |
|
|
repeat(1) @(posedge mstr_test_clk);
|
532 |
|
|
end
|
533 |
|
|
endtask
|
534 |
|
|
|
535 |
|
|
task dump_ram;
|
536 |
|
|
input [15:0] start_address;
|
537 |
|
|
reg [15:0] dump_address;
|
538 |
|
|
integer i, j;
|
539 |
|
|
begin
|
540 |
|
|
$display("Dumping RAM - Starting Address #%h", start_address);
|
541 |
|
|
|
542 |
|
|
dump_address = start_address;
|
543 |
|
|
while (dump_address <= start_address + 16'h0080)
|
544 |
|
|
begin
|
545 |
|
|
$write("Address = %h", dump_address);
|
546 |
|
|
for (i = 0; i < 16; i = i + 1)
|
547 |
|
|
begin
|
548 |
|
|
$write(" %h", ram_8[dump_address]);
|
549 |
|
|
dump_address = dump_address + 1;
|
550 |
|
|
end
|
551 |
|
|
$write("\n");
|
552 |
|
|
end
|
553 |
|
|
|
554 |
|
|
end
|
555 |
|
|
endtask
|
556 |
|
|
|
557 |
|
|
function [15:0] four_2_16;
|
558 |
|
|
input [3:0] vector;
|
559 |
|
|
begin
|
560 |
|
|
case (vector)
|
561 |
|
|
4'h0 : four_2_16 = 16'b0000_0000_0000_0001;
|
562 |
|
|
4'h1 : four_2_16 = 16'b0000_0000_0000_0010;
|
563 |
|
|
4'h2 : four_2_16 = 16'b0000_0000_0000_0100;
|
564 |
|
|
4'h3 : four_2_16 = 16'b0000_0000_0000_1000;
|
565 |
|
|
4'h4 : four_2_16 = 16'b0000_0000_0001_0000;
|
566 |
|
|
4'h5 : four_2_16 = 16'b0000_0000_0010_0000;
|
567 |
|
|
4'h6 : four_2_16 = 16'b0000_0000_0100_0000;
|
568 |
|
|
4'h7 : four_2_16 = 16'b0000_0000_1000_0000;
|
569 |
|
|
4'h8 : four_2_16 = 16'b0000_0001_0000_0000;
|
570 |
|
|
4'h9 : four_2_16 = 16'b0000_0010_0000_0000;
|
571 |
|
|
4'ha : four_2_16 = 16'b0000_0100_0000_0000;
|
572 |
|
|
4'hb : four_2_16 = 16'b0000_1000_0000_0000;
|
573 |
|
|
4'hc : four_2_16 = 16'b0001_0000_0000_0000;
|
574 |
|
|
4'hd : four_2_16 = 16'b0010_0000_0000_0000;
|
575 |
|
|
4'he : four_2_16 = 16'b0100_0000_0000_0000;
|
576 |
|
|
4'hf : four_2_16 = 16'b1000_0000_0000_0000;
|
577 |
|
|
endcase
|
578 |
|
|
end
|
579 |
|
|
endfunction
|
580 |
|
|
|
581 |
|
|
endmodule // tst_bench_top
|
582 |
|
|
|