// SPDX-License-Identifier: Apache-2.0 // Replays a session recorded from the host's software model (`wai-quantum-landscape-fpga gen-tb landscape_tb.script`) against the RTL, // through the EMIO port and its synchroniser, with the PS side deliberately off the PL clock. // Every read must return what the model returned. A mismatch names the script line. `timescale 1ns/1ps module tb; reg clk = 0; always #5 clk = ~clk; // pl_clk0, 100 MHz reg [94:0] emio_o = 95'd0; wire [94:0] emio_i; `ifdef MULTI landscape_multi #(.K(4)) dut (.clk(clk), .emio_o(emio_o), .emio_i(emio_i)); `else landscape_port dut (.clk(clk), .emio_o(emio_o), .emio_i(emio_i)); `endif integer fd, r, errors, reads, line, t; reg [31:0] op, a, d, m, got; reg req; task txn(input we, input [15:0] addr, input [31:0] wdata, output [31:0] rdata); reg ack0; begin ack0 = emio_i[82]; emio_o[31:0] = wdata; #37; // a PS bus write, some time before the next req = ~req; emio_o[81] = we; emio_o[79:64] = addr; emio_o[80] = req; t = 0; while (emio_i[82] == ack0) begin #13; t = t + 1; if (t > 20000) begin $display("TIMEOUT waiting for ack at script line %0d", line); $finish; end end rdata = emio_i[63:32]; #29; end endtask initial begin errors = 0; reads = 0; line = 0; req = 0; #3000; // past the port's power-on hold-off fd = $fopen("landscape_tb.script", "r"); if (fd == 0) begin $display("no script"); $finish; end r = $fscanf(fd, "%s", op); while (r == 1) begin line = line + 1; if (op == "W") begin r = $fscanf(fd, " %h %h", a, d); txn(1'b1, a[15:0], d, got); end else if (op == "R") begin r = $fscanf(fd, " %h %h %h", a, d, m); txn(1'b0, a[15:0], 32'd0, got); reads = reads + 1; if ((got & m) !== (d & m)) begin errors = errors + 1; if (errors <= 25) $display("MISMATCH line %0d: R %h got %h want %h", line, a[15:0], got, d); end end else if (op == "I") begin t = 0; while (emio_i[83]) begin #50; t = t + 1; if (t > 2000000) begin $display("TIMEOUT busy at line %0d", line); $finish; end end #20; end else begin $display("bad op at line %0d", line); $finish; end r = $fscanf(fd, "%s", op); end $display("TB DONE: %0d lines, %0d checked reads, %0d mismatches, sim time %0t", line, reads, errors, $time); $finish; end endmodule