| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- `timescale 1ns/1ps
- module stimulus_reload_priority_tb;
- reg clk = 0;
- reg rst_n = 0;
- reg tick_1s = 0;
- reg stimulus_wr_en = 0;
- reg [4:0] stimulus_wr_addr = 0;
- reg [7:0] stimulus_wr_data = 0;
- reg stimulus_commit = 0;
- reg [7:0] stimulus_duration = 0;
- wire [4:0] bmc_rd_index;
- wire stimulus_active;
- integer i;
- always #5 clk = ~clk;
- thermal_control_core #(.ENABLE_STIMULUS(1)) dut (
- .clk(clk), .rst_n(rst_n), .tick_1s(tick_1s),
- .target_commit(1'b0), .target_celsius(8'd0),
- .stimulus_wr_en(stimulus_wr_en),
- .stimulus_wr_addr(stimulus_wr_addr),
- .stimulus_wr_data(stimulus_wr_data),
- .stimulus_commit(stimulus_commit),
- .stimulus_duration_seconds(stimulus_duration),
- .bmc_epoch(16'd0), .bmc_stale(1'b0),
- .bmc_valid_mask(24'hff_ffff), .bmc_rd_index(bmc_rd_index),
- .bmc_rd_raw(16'd0), .bmc_rd_valid(1'b1),
- .ct_epoch(16'd0), .ct_stale(1'b0),
- .ct_valid_mask(27'h7ff_ffff), .snapshot_lock(1'b0),
- .snapshot_lock_bank(1'b0), .pwm_rd_addr(5'd0),
- .pwm_rd_data(), .snapshot_output_bank(1'b0),
- .snapshot_rd_addr(5'd0), .snapshot_requested_data(),
- .snapshot_applied_data(), .active_output_bank(),
- .control_state(), .current_target_celsius(),
- .host_target_seen(), .control_epoch(), .safety_override_mask(),
- .lane_fault_mask(), .global_fault(), .output_commit(),
- .stimulus_active(stimulus_active), .pwm_phase_boundary(1'b0),
- .pwm_scan_idle(1'b1), .boot_init_complete()
- );
- task stage_vector;
- input [7:0] base;
- begin
- for (i = 0; i < 32; i = i + 1) begin
- @(negedge clk);
- stimulus_wr_en = 1;
- stimulus_wr_addr = i[4:0];
- stimulus_wr_data = base + i[7:0];
- end
- @(negedge clk);
- stimulus_wr_en = 0;
- end
- endtask
- task commit_vector;
- input [7:0] duration;
- input with_tick;
- begin
- @(negedge clk);
- stimulus_duration = duration;
- stimulus_commit = 1;
- tick_1s = with_tick;
- @(negedge clk);
- stimulus_commit = 0;
- tick_1s = 0;
- end
- endtask
- initial begin
- repeat (2) @(negedge clk);
- rst_n = 1;
- stage_vector(8'd10);
- commit_vector(8'd1, 1'b0);
- if (!stimulus_active || dut.stimulus_remaining !== 8'd1)
- $fatal(1, "initial one-second stimulus did not start");
- stage_vector(8'd50);
- // The last tick of vector A and the legal commit of vector B share
- // one edge. Commit must win so the fresh 7-second duration survives.
- commit_vector(8'd7, 1'b1);
- if (!stimulus_active)
- $fatal(1, "same-cycle reload was overwritten by expiry");
- if (dut.stimulus_remaining !== 8'd7)
- $fatal(1, "reload remaining=%0d expected=7", dut.stimulus_remaining);
- $display("PASS: stimulus commit wins over same-cycle expiry tick");
- $finish;
- end
- endmodule
|