| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- `timescale 1ns/1ps
- module prod2u_6400_command_controller_tb;
- reg clk = 1'b0;
- reg rst_n = 1'b0;
- reg frame_valid = 1'b0;
- reg [7:0] frame_type = 8'd0;
- reg [7:0] frame_length = 8'd0;
- wire frame_ready;
- wire accept;
- wire [7:0] payload_addr;
- wire [7:0] payload_data;
- wire wr_en;
- wire [4:0] wr_addr;
- wire [7:0] wr_data;
- wire commit;
- wire temp_start;
- reg temp_done = 1'b0;
- wire tx_start;
- wire [7:0] tx_type;
- wire [7:0] tx_len;
- reg tx_done = 1'b0;
- wire busy;
- integer i;
- integer commit_count;
- integer cycles;
- reg [7:0] mem [0:31];
- always #1 clk = ~clk;
- assign payload_data = (payload_addr < 8'd32) ? mem[payload_addr[4:0]] : 8'hFF;
- prod2u_6400_command_controller dut (
- .clk(clk), .rst_n(rst_n), .frame_valid(frame_valid),
- .frame_ready(frame_ready), .frame_accept_enable(accept),
- .frame_type(frame_type), .frame_length(frame_length),
- .payload_read_addr(payload_addr), .payload_read_data(payload_data),
- .target_wr_en(wr_en), .target_wr_addr(wr_addr), .target_wr_data(wr_data),
- .valid_set_all_commit(commit), .temperature_start(temp_start),
- .temperature_done(temp_done), .tx_start(tx_start),
- .tx_frame_type(tx_type), .tx_payload_length(tx_len),
- .tx_done(tx_done), .busy(busy)
- );
- always @(posedge clk) begin
- if (commit)
- commit_count = commit_count + 1;
- end
- task issue_set;
- begin
- @(posedge clk);
- frame_type <= 8'h01;
- frame_length <= 8'd32;
- frame_valid <= 1'b1;
- @(posedge clk);
- frame_valid <= 1'b0;
- cycles = 0;
- while (!busy && cycles < 8) begin
- @(posedge clk);
- cycles = cycles + 1;
- end
- cycles = 0;
- while (busy && cycles < 80) begin
- @(posedge clk);
- cycles = cycles + 1;
- end
- @(posedge clk);
- end
- endtask
- initial begin
- commit_count = 0;
- for (i = 0; i < 32; i = i + 1) mem[i] = 8'd0;
- repeat (4) @(posedge clk);
- rst_n <= 1'b1;
- repeat (2) @(posedge clk);
- issue_set();
- if (commit_count !== 1) $fatal(1, "all-zero SET must commit once, got %0d", commit_count);
- for (i = 0; i < 32; i = i + 1) mem[i] = 8'd100;
- issue_set();
- if (commit_count !== 2) $fatal(1, "all-100 SET commit count %0d", commit_count);
- mem[0] = 8'd101;
- issue_set();
- if (commit_count !== 2) $fatal(1, "first-byte 101 committed");
- mem[0] = 8'd0;
- mem[16] = 8'd101;
- issue_set();
- if (commit_count !== 2) $fatal(1, "mid-byte 101 committed");
- mem[16] = 8'd0;
- mem[31] = 8'd101;
- issue_set();
- if (commit_count !== 2) $fatal(1, "last-byte 101 committed");
- mem[31] = 8'd0;
- begin : reject_lengths
- integer li;
- for (li = 0; li < 4; li = li + 1) begin
- @(posedge clk);
- frame_type <= 8'h01;
- if (li == 0) frame_length <= 8'd11;
- else if (li == 1) frame_length <= 8'd14;
- else if (li == 2) frame_length <= 8'd31;
- else frame_length <= 8'd33;
- frame_valid <= 1'b1;
- @(posedge clk);
- frame_valid <= 1'b0;
- repeat (8) @(posedge clk);
- end
- end
- @(posedge clk);
- frame_type <= 8'h03;
- frame_length <= 8'd0;
- frame_valid <= 1'b1;
- @(posedge clk);
- frame_valid <= 1'b0;
- repeat (8) @(posedge clk);
- if (commit_count !== 2) $fatal(1, "length/type rejects committed");
- if (tx_start) $fatal(1, "SET path produced TX");
- begin : one_hot
- integer idx;
- integer saw_addr;
- integer saw_data;
- integer writes;
- for (idx = 0; idx < 32; idx = idx + 1) begin
- for (i = 0; i < 32; i = i + 1) mem[i] = 8'd0;
- mem[idx] = 8'd77;
- writes = 0;
- saw_addr = -1;
- saw_data = -1;
- fork
- begin
- issue_set();
- end
- begin
- repeat (80) begin
- @(posedge clk);
- if (wr_en) begin
- writes = writes + 1;
- if (wr_data === 8'd77) begin
- saw_addr = wr_addr;
- saw_data = wr_data;
- end
- end
- end
- end
- join
- if (saw_addr !== idx) $fatal(1, "one-hot addr idx=%0d saw=%0d", idx, saw_addr);
- if (writes !== 32) $fatal(1, "one-hot writes=%0d idx=%0d", writes, idx);
- end
- end
- if (commit_count !== 34) $fatal(1, "one-hot commit count %0d", commit_count);
- $display("prod2u_6400_command_controller_tb PASS");
- $finish;
- end
- endmodule
|