| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- `timescale 1ns/1ps
- // Historical stand-alone arbitration-model test for Prod2U6400V2.
- // The queue logic below is copied into the TB; only temp_ram is production RTL.
- // Passing this file does not verify arbitration inside the production top.
- // External CT/BMC acquisition coverage is provided by the acquisition BFM.
- // Verifies:
- // 1. Cycle N: BMC + CT0 simultaneous write -> BMC has priority, CT0 buffered.
- // 2. Cycle N+1: CT1 write + pending CT0 retirement -> CT0 written to RAM, CT1 buffered.
- // 3. Cycle N+2: BMC + CT2 write + pending CT1 -> BMC written to RAM, CT1 & CT2 buffered.
- // 4. Cycle N+3..N+4: CT1 and CT2 retire in order to RAM.
- // 5. Read RAM verify all BMC and CT writes committed correctly in order.
- // 6. Queue overflow detection when overloaded.
- module prod2u_6400_v2_temp_arb_tb;
- reg clk = 1'b0;
- reg rst_n = 1'b0;
- always #20 clk = ~clk; // 25 MHz clock (40ns period)
- reg bmc_wr_en;
- reg [5:0] bmc_wr_addr;
- reg [7:0] bmc_wr_data;
- reg ct_wr_en;
- reg [5:0] ct_wr_addr;
- reg [7:0] ct_wr_data;
- // Arbiter internal queue state & RAM write signals under test
- reg [5:0] q_addr [0:3];
- reg [7:0] q_data [0:3];
- reg [1:0] q_head;
- reg [1:0] q_tail;
- reg [2:0] q_count;
- reg q_overflow;
- wire push_ct = ct_wr_en && (bmc_wr_en || (q_count > 3'd0));
- wire pop_ct = !bmc_wr_en && (q_count > 3'd0);
- always @(posedge clk or negedge rst_n) begin
- if (!rst_n) begin
- q_head <= 2'd0;
- q_tail <= 2'd0;
- q_count <= 3'd0;
- q_overflow <= 1'b0;
- end else begin
- case ({push_ct, pop_ct})
- 2'b10: begin
- if (q_count < 3'd4) begin
- q_addr[q_tail] <= ct_wr_addr;
- q_data[q_tail] <= ct_wr_data;
- q_tail <= q_tail + 2'd1;
- q_count <= q_count + 3'd1;
- end else begin
- q_overflow <= 1'b1;
- end
- end
- 2'b01: begin
- q_head <= q_head + 2'd1;
- q_count <= q_count - 3'd1;
- end
- 2'b11: begin
- q_head <= q_head + 2'd1;
- q_addr[q_tail] <= ct_wr_addr;
- q_data[q_tail] <= ct_wr_data;
- q_tail <= q_tail + 2'd1;
- end
- default: ;
- endcase
- end
- end
- wire temp_wr_en = bmc_wr_en | (q_count > 3'd0) | ct_wr_en;
- wire [5:0] temp_wr_addr = bmc_wr_en ? bmc_wr_addr :
- (q_count > 3'd0) ? q_addr[q_head] : ct_wr_addr;
- wire [7:0] temp_wr_data = bmc_wr_en ? bmc_wr_data :
- (q_count > 3'd0) ? q_data[q_head] : ct_wr_data;
- // Instantiate temperature RAM
- reg [5:0] rd_addr;
- wire [7:0] rd_data;
- wire rd_valid;
- temp_ram #(
- .CT_ACTIVE_COUNT(6'd9)
- ) u_temp_ram (
- .clk(clk),
- .rst_n(rst_n),
- .wr_en(temp_wr_en),
- .wr_addr(temp_wr_addr),
- .wr_data(temp_wr_data),
- .rd_addr(rd_addr),
- .rd_data(rd_data),
- .rd_valid(rd_valid)
- );
- initial begin
- bmc_wr_en = 1'b0;
- bmc_wr_addr = 6'd0;
- bmc_wr_data = 8'd0;
- ct_wr_en = 1'b0;
- ct_wr_addr = 6'd0;
- ct_wr_data = 8'd0;
- rd_addr = 6'd0;
- // Reset pulse
- rst_n = 1'b0;
- repeat (5) @(posedge clk);
- rst_n = 1'b1;
- repeat (2) @(posedge clk);
- $display("=== [TEST 1] Cycle N..N+3 Priority Arbitration & Orderly Retirement ===");
-
- // Cycle N: BMC + CT0
- // BMC writes to addr 0 with 0x25, CT0 writes to addr 32 with 0x30
- @(posedge clk);
- bmc_wr_en <= 1'b1;
- bmc_wr_addr <= 6'd0;
- bmc_wr_data <= 8'h25;
- ct_wr_en <= 1'b1;
- ct_wr_addr <= 6'd32;
- ct_wr_data <= 8'h30;
- #1;
- if (temp_wr_en !== 1'b1 || temp_wr_addr !== 6'd0 || temp_wr_data !== 8'h25) begin
- $display("[FAIL] Cycle N: BMC did not win RAM write! addr=%d data=%h", temp_wr_addr, temp_wr_data);
- $finish(1);
- end
- // Cycle N+1: CT1 write + pending CT0 retirement (BMC idle)
- @(posedge clk);
- bmc_wr_en <= 1'b0;
- ct_wr_en <= 1'b1;
- ct_wr_addr <= 6'd33;
- ct_wr_data <= 8'h31;
- #1;
- if (temp_wr_en !== 1'b1 || temp_wr_addr !== 6'd32 || temp_wr_data !== 8'h30) begin
- $display("[FAIL] Cycle N+1: Pending CT0 did not retire to RAM! addr=%d data=%h", temp_wr_addr, temp_wr_data);
- $finish(1);
- end
- // Cycle N+2: BMC + CT2 write + pending CT1
- @(posedge clk);
- bmc_wr_en <= 1'b1;
- bmc_wr_addr <= 6'd1;
- bmc_wr_data <= 8'h26;
- ct_wr_en <= 1'b1;
- ct_wr_addr <= 6'd34;
- ct_wr_data <= 8'h32;
- #1;
- if (temp_wr_en !== 1'b1 || temp_wr_addr !== 6'd1 || temp_wr_data !== 8'h26) begin
- $display("[FAIL] Cycle N+2: BMC did not win RAM write! addr=%d data=%h", temp_wr_addr, temp_wr_data);
- $finish(1);
- end
- // Cycle N+3: Idle inputs -> pending CT1 retires
- @(posedge clk);
- bmc_wr_en <= 1'b0;
- ct_wr_en <= 1'b0;
- #1;
- if (temp_wr_en !== 1'b1 || temp_wr_addr !== 6'd33 || temp_wr_data !== 8'h31) begin
- $display("[FAIL] Cycle N+3: Pending CT1 did not retire to RAM! addr=%d data=%h", temp_wr_addr, temp_wr_data);
- $finish(1);
- end
- // Cycle N+4: Idle inputs -> pending CT2 retires
- @(posedge clk);
- bmc_wr_en <= 1'b0;
- ct_wr_en <= 1'b0;
- #1;
- if (temp_wr_en !== 1'b1 || temp_wr_addr !== 6'd34 || temp_wr_data !== 8'h32) begin
- $display("[FAIL] Cycle N+4: Pending CT2 did not retire to RAM! addr=%d data=%h", temp_wr_addr, temp_wr_data);
- $finish(1);
- end
- // Cycle N+5: Queue should now be empty
- @(posedge clk);
- #1;
- if (q_count !== 3'd0) begin
- $display("[FAIL] Cycle N+5: Queue should be empty! count=%d", q_count);
- $finish(1);
- end
- // Verify RAM readback for all written addresses
- $display("=== [TEST 2] Verifying RAM readback contents ===");
- @(posedge clk); rd_addr <= 6'd0; @(posedge clk); #1;
- if (rd_data !== 8'h25) begin $display("[FAIL] RAM[0] != 0x25, got %h", rd_data); $finish(1); end
-
- @(posedge clk); rd_addr <= 6'd1; @(posedge clk); #1;
- if (rd_data !== 8'h26) begin $display("[FAIL] RAM[1] != 0x26, got %h", rd_data); $finish(1); end
- @(posedge clk); rd_addr <= 6'd32; @(posedge clk); #1;
- if (rd_data !== 8'h30) begin $display("[FAIL] RAM[32] != 0x30, got %h", rd_data); $finish(1); end
- @(posedge clk); rd_addr <= 6'd33; @(posedge clk); #1;
- if (rd_data !== 8'h31) begin $display("[FAIL] RAM[33] != 0x31, got %h", rd_data); $finish(1); end
- @(posedge clk); rd_addr <= 6'd34; @(posedge clk); #1;
- if (rd_data !== 8'h32) begin $display("[FAIL] RAM[34] != 0x32, got %h", rd_data); $finish(1); end
- $display("=== [TEST 3] Queue Overflow Detection ===");
- // Hold BMC high for 5 cycles while pushing 5 CT writes
- @(posedge clk);
- bmc_wr_en <= 1'b1; bmc_wr_addr <= 6'd2; bmc_wr_data <= 8'h50;
- ct_wr_en <= 1'b1; ct_wr_addr <= 6'd40; ct_wr_data <= 8'hA1; // entry 0
- @(posedge clk);
- ct_wr_addr <= 6'd41; ct_wr_data <= 8'hA2; // entry 1
- @(posedge clk);
- ct_wr_addr <= 6'd42; ct_wr_data <= 8'hA3; // entry 2
- @(posedge clk);
- ct_wr_addr <= 6'd43; ct_wr_data <= 8'hA4; // entry 3 (full)
- @(posedge clk);
- ct_wr_addr <= 6'd44; ct_wr_data <= 8'hA5; // 5th write request
- @(posedge clk);
- #1;
- if (q_overflow !== 1'b1) begin
- $display("[FAIL] Overflow flag not asserted on 5th write! q_count=%d", q_count);
- $finish(1);
- end
- $display("[PASS] Queue overflow asserted correctly without memory corruption: q_overflow=%b", q_overflow);
- @(posedge clk);
- bmc_wr_en <= 1'b0;
- ct_wr_en <= 1'b0;
- repeat (10) @(posedge clk);
- $display("\n=======================================================");
- $display("ALL 6400 V2.0 TEMPERATURE ARBITRATION TESTS PASSED OK!");
- $display("=======================================================\n");
- $finish(0);
- end
- endmodule
|