V13.6.2 Split the Driver

MediumImplement30 minIcarus · browser samples / server checksReview the topic

Write the hardware side of a split driver: a BFM whose tasks turn one call into bus cycles. Every wait is on a clock edge. The given test side only calls those tasks.

Hardware context: A two-top bench and the hybrid's transactor checked by the judge's Yosys flow. The timed half of a split driver.

A bench that could go into an emulator has two tops. The HDL top holds the design, the clock, the reset and the timed parts of each transactor. The test top holds the test, which calls tasks of those timed parts and never waits on its own.

Write bus_bfm, the timed part of the driver. Its tasks are the whole link: wait_reset, write, read and idle. Each wait inside them is a rising edge of clk; no # delay is allowed. A transfer starts by raising sel with we, addr and wdata. Hold all four until the edge where ready is 1, then take rdata and err and drop sel.

The test top calls hdl.bfm.write, read and idle from scripts. A checker in the HDL top counts edges where a waiting transfer changed its signals. It also counts edges where sel was high during reset.

Signals in the Timeline

SignalWidthRole
scenario4input of each check
Full specification
The ports and tasks (keep them)
module bus_bfm(input logic clk, resetn, output logic sel, we, output logic [7:0] addr, output logic [31:0] wdata,
               input logic [31:0] rdata, input logic ready, err);
  task automatic wait_reset();
  task automatic write(input logic [7:0] a, input logic [31:0] d, output logic e);
  task automatic read(input logic [7:0] a, output logic [31:0] d, output logic e);
  task automatic idle(input int n);
endmodule
Target addressAnswer
0x00 to 0x3Fready after one cycle
0x40 to 0x7Fready after four cycles
0x80 and above, or not word-alignedready with err = 1
The HDL top (given)
// The HDL side of the bench (given). Clock and reset are made here; the target answers on the bus.
module reg_target(input logic clk, resetn, sel, we, input logic [7:0] addr, input logic [31:0] wdata,
                  output logic [31:0] rdata, output logic ready, err);
  logic [31:0] r [0:15];
  int wait_left;
  always_ff @(posedge clk or negedge resetn)
    if (!resetn) begin ready <= 0; err <= 0; rdata <= 0; wait_left <= -1; for (int i = 0; i < 16; i++) r[i] <= 0; end
    else begin
      ready <= 0; err <= 0;
      if (sel && !ready) begin
        if (wait_left < 0) wait_left <= addr >= 8'h40 && addr < 8'h80 ? 3 : 0;
        else if (wait_left > 0) wait_left <= wait_left - 1;
        else begin
          ready <= 1; wait_left <= -1;
          if (addr >= 8'h80 || addr[1:0] != 0) err <= 1;
          else if (we) r[addr[5:2]] <= wdata;
          else rdata <= r[addr[5:2]];
        end
      end
    end
endmodule

module hdl_top;
  logic clk = 0, resetn = 0, sel, we, ready, err;
  logic [7:0] addr; logic [31:0] wdata, rdata;
  int violations;
  always #5 clk = ~clk;
  initial begin violations = 0; #63 resetn = 1; end
  reg_target target(.clk, .resetn, .sel, .we, .addr, .wdata, .rdata, .ready, .err);
  bus_bfm bfm(.clk, .resetn, .sel, .we, .addr, .wdata, .rdata, .ready, .err);
  // The bus rule, checked at every rising edge: while a transfer waits, the BFM holds sel, we, addr and wdata.
  logic sel_q, we_q, waiting; logic [7:0] addr_q; logic [31:0] wdata_q;
  always @(posedge clk) begin
    if (waiting && (sel !== 1'b1 || we !== we_q || addr !== addr_q || (we_q && wdata !== wdata_q))) violations++;
    if (!resetn && sel === 1'b1) violations++;
    waiting = sel === 1'b1 && !ready; we_q = we; addr_q = addr; wdata_q = wdata;
  end
endmodule

The site's simulator elaborates one root module, so the test top here instantiates hdl_top and reaches it only through hdl.bfm. In co-emulation the two tops are separate roots; the rule that the test side touches only the BFM's tasks is the same.

Examples

Example 1

Write and Read Back
Input
w(8'h0, 32'h11223344); w(8'h4, 32'hcafef00d); r(8'h0); r(8'h4);
Output
xor_read = 0xdbdcc349, errors = 0, reads = 2, violations = 0

Two writes and two reads, each ready after one cycle.

Example 2

Slow Registers
Input
w(8'h40, 32'ha0b0c0d); r(8'h40); w(8'h8, 32'h5); r(8'h44); r(8'h8);
Output
xor_read = 0xc0f5fc05, errors = 0, reads = 3, violations = 0

Registers from 0x40 wait four cycles; the BFM must hold the request all that time.

Example 3

An Error Answer
Input
w(8'hc, 32'h77); r(8'h90); r(8'hc); w(8'h2, 32'h1);
Output
xor_read = 0x77, errors = 2, reads = 2, violations = 0

A read of 0x90 and a write to 0x02 come back with err; the read in between is good.

Constraints and Contract

  • Keep the module name, the ports and the four tasks.
  • No # delay anywhere in the module.
  • Never change sel, we, addr or wdata while a transfer waits for ready.

Hints

Hint 1

Drive the bus with nonblocking assignments after a rising edge, so the target sees stable values at the next one.

Hint 2

Loop on rising edges until ready is 1: do @(posedge clk); while (!ready);

Hint 3

read and write are the same handshake. Write it once.

What the grader checks: Six scripts check the data read back, the errors and the bus rule at every rising edge. A text rule refuses any # delay in your module. The grader cannot compile your BFM for an emulator. The co-emulation flow in the UVM Cookbook accepts BFM tasks with clock waits; our Yosys does not. So this problem is graded in simulation.

6 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Write and Read Back

Input
w(8'h0, 32'h11223344); w(8'h4, 32'hcafef00d); r(8'h0); r(8'h4);
Expected output
xor_read = 0xdbdcc349, errors = 0, reads = 2, violations = 0

Two writes and two reads, each ready after one cycle.

Run samples executes all 3 public checks. Check all tests runs 6 checks on the server.

Icarus · browser samples / server checks