| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- `timescale 1ns/1ps
- module stimulus_atomic_bank_tb;
- reg clk = 0;
- reg rst_n = 0;
- reg write_enable = 0;
- reg [4:0] write_address = 0;
- reg [7:0] write_data = 0;
- reg stimulus_commit = 0;
- wire commit_applied;
- wire active_bank;
- reg read_bank = 0;
- reg [4:0] read_address = 0;
- wire [7:0] read_data;
- integer i;
- always #5 clk = ~clk;
- stimulus_atomic_bank dut (
- .clk(clk), .rst_n(rst_n), .write_enable(write_enable),
- .write_address(write_address), .write_data(write_data),
- .stimulus_commit(stimulus_commit), .commit_applied(commit_applied),
- .active_bank(active_bank),
- .read_bank(read_bank), .read_address(read_address), .read_data(read_data)
- );
- task write_inactive;
- input [4:0] address;
- input [7:0] data;
- begin
- @(negedge clk);
- write_enable = 1;
- write_address = address;
- write_data = data;
- @(negedge clk);
- write_enable = 0;
- end
- endtask
- task commit_bank;
- begin
- @(negedge clk);
- stimulus_commit = 1;
- @(negedge clk);
- stimulus_commit = 0;
- end
- endtask
- task expect_active;
- input [7:0] base;
- begin
- read_bank = active_bank;
- for (i = 0; i < 32; i = i + 1) begin
- read_address = i[4:0];
- #1;
- if (read_data !== base + i[7:0]) begin
- $display("FAIL: active[%0d]=%0d expected=%0d", i, read_data, base + i);
- $fatal(1);
- end
- end
- end
- endtask
- initial begin
- repeat (2) @(negedge clk);
- rst_n = 1;
- // A complete legal command stages vector A without exposing a byte.
- for (i = 0; i < 32; i = i + 1)
- write_inactive(i[4:0], 8'd10 + i[7:0]);
- if (active_bank !== 0)
- $fatal(1, "inactive staging changed pointer before commit");
- commit_bank();
- if (active_bank !== 1) $fatal(1, "first commit did not flip pointer");
- expect_active(8'd10);
- // An invalid/partial command may dirty the inactive bank, but without
- // stimulus_commit it cannot alter either the pointer or active data.
- for (i = 0; i < 12; i = i + 1)
- write_inactive(i[4:0], 8'd80 + i[7:0]);
- // A raw commit after a partial command is rejected inside the bank.
- commit_bank();
- if (active_bank !== 1) $fatal(1, "partial command changed pointer");
- expect_active(8'd10);
- // The next complete legal command overwrites all 32 inactive bytes;
- // one commit exposes the entire B vector atomically.
- for (i = 0; i < 32; i = i + 1)
- write_inactive(i[4:0], 8'd40 + i[7:0]);
- expect_active(8'd10);
- commit_bank();
- if (active_bank !== 0) $fatal(1, "second commit did not flip pointer");
- expect_active(8'd40);
- $display("PASS: stimulus atomic bank inactive staging and pointer commit");
- $finish;
- end
- endmodule
|