Skip to content

Commit d3279a5

Browse files
thomasahleclaude
andcommitted
Fix always-ff testbench: remove tasks to work around LLHD task-wait bug
LLHD interpreter does not wake @(posedge clk) waits inside tasks called from initial blocks (confirmed by process state showing proc 2 stuck at 'func.call(do_write)' through all 100 clock cycles). Inline do_write/do_read logic directly so @(posedge clk) is at the top level of the initial block, matching the pattern that works in sva/concurrent-sim. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 9a9a524 commit d3279a5

1 file changed

Lines changed: 34 additions & 23 deletions

File tree

  • src/lessons/sv/always-ff

src/lessons/sv/always-ff/tb.sv

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,49 @@ module tb;
1111

1212
int fail = 0;
1313

14-
// Clock generator: period = 10 time units (finite repeat for simulator compatibility)
15-
initial repeat(200) #5 clk = ~clk;
14+
// Clock generator: period = 10 time units
15+
always #5 clk = ~clk;
1616

1717
// Connect all ports by name (shorthand: .port matches variable of same name)
1818
sram_core dut(.*);
1919

20-
// Write one byte: assert we, drive addr/wdata, wait for rising edge
21-
task do_write(input [3:0] a, input [7:0] d);
22-
we = 1; addr = a; wdata = d;
23-
@(posedge clk); #1;
24-
we = 0;
25-
endtask
26-
27-
// Read one byte and check result; print PASS or FAIL
28-
task do_read(input [3:0] a, input [7:0] expected);
29-
addr = a; @(posedge clk); #1;
30-
if (rdata === expected)
31-
$display("PASS mem[%0d] = %0d", a, rdata);
20+
initial begin
21+
// Write addr=2, data=42
22+
we = 1; addr = 4'd2; wdata = 8'd42;
23+
@(posedge clk); #1; we = 0;
24+
25+
// Write addr=7, data=99
26+
we = 1; addr = 4'd7; wdata = 8'd99;
27+
@(posedge clk); #1; we = 0;
28+
29+
// Write addr=0, data=13
30+
we = 1; addr = 4'd0; wdata = 8'd13;
31+
@(posedge clk); #1; we = 0;
32+
33+
// Read and check each address (1-cycle read latency)
34+
addr = 4'd2; @(posedge clk); #1;
35+
if (rdata === 8'd42)
36+
$display("PASS mem[2] = %0d", rdata);
3237
else begin
33-
$display("FAIL mem[%0d] = %0d (expected %0d)", a, rdata, expected);
38+
$display("FAIL mem[2] = %0d (expected 42)", rdata);
3439
fail++;
3540
end
36-
endtask
3741

38-
initial begin
39-
do_write(4'd2, 8'd42);
40-
do_write(4'd7, 8'd99);
41-
do_write(4'd0, 8'd13);
42+
addr = 4'd7; @(posedge clk); #1;
43+
if (rdata === 8'd99)
44+
$display("PASS mem[7] = %0d", rdata);
45+
else begin
46+
$display("FAIL mem[7] = %0d (expected 99)", rdata);
47+
fail++;
48+
end
4249

43-
do_read(4'd2, 8'd42);
44-
do_read(4'd7, 8'd99);
45-
do_read(4'd0, 8'd13);
50+
addr = 4'd0; @(posedge clk); #1;
51+
if (rdata === 8'd13)
52+
$display("PASS mem[0] = %0d", rdata);
53+
else begin
54+
$display("FAIL mem[0] = %0d (expected 13)", rdata);
55+
fail++;
56+
end
4657

4758
if (fail == 0) $display("PASS");
4859
$finish;

0 commit comments

Comments
 (0)