prod2u_6400_command_controller_tb.v 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. `timescale 1ns/1ps
  2. module prod2u_6400_command_controller_tb;
  3. reg clk = 1'b0;
  4. reg rst_n = 1'b0;
  5. reg frame_valid = 1'b0;
  6. reg [7:0] frame_type = 8'd0;
  7. reg [7:0] frame_length = 8'd0;
  8. wire frame_ready;
  9. wire accept;
  10. wire [7:0] payload_addr;
  11. wire [7:0] payload_data;
  12. wire wr_en;
  13. wire [4:0] wr_addr;
  14. wire [7:0] wr_data;
  15. wire commit;
  16. wire temp_start;
  17. reg temp_done = 1'b0;
  18. wire tx_start;
  19. wire [7:0] tx_type;
  20. wire [7:0] tx_len;
  21. reg tx_done = 1'b0;
  22. wire busy;
  23. integer i;
  24. integer commit_count;
  25. integer cycles;
  26. reg [7:0] mem [0:31];
  27. always #1 clk = ~clk;
  28. assign payload_data = (payload_addr < 8'd32) ? mem[payload_addr[4:0]] : 8'hFF;
  29. prod2u_6400_command_controller dut (
  30. .clk(clk), .rst_n(rst_n), .frame_valid(frame_valid),
  31. .frame_ready(frame_ready), .frame_accept_enable(accept),
  32. .frame_type(frame_type), .frame_length(frame_length),
  33. .payload_read_addr(payload_addr), .payload_read_data(payload_data),
  34. .target_wr_en(wr_en), .target_wr_addr(wr_addr), .target_wr_data(wr_data),
  35. .valid_set_all_commit(commit), .temperature_start(temp_start),
  36. .temperature_done(temp_done), .tx_start(tx_start),
  37. .tx_frame_type(tx_type), .tx_payload_length(tx_len),
  38. .tx_done(tx_done), .busy(busy)
  39. );
  40. always @(posedge clk) begin
  41. if (commit)
  42. commit_count = commit_count + 1;
  43. end
  44. task issue_set;
  45. begin
  46. @(posedge clk);
  47. frame_type <= 8'h01;
  48. frame_length <= 8'd32;
  49. frame_valid <= 1'b1;
  50. @(posedge clk);
  51. frame_valid <= 1'b0;
  52. cycles = 0;
  53. while (!busy && cycles < 8) begin
  54. @(posedge clk);
  55. cycles = cycles + 1;
  56. end
  57. cycles = 0;
  58. while (busy && cycles < 80) begin
  59. @(posedge clk);
  60. cycles = cycles + 1;
  61. end
  62. @(posedge clk);
  63. end
  64. endtask
  65. initial begin
  66. commit_count = 0;
  67. for (i = 0; i < 32; i = i + 1) mem[i] = 8'd0;
  68. repeat (4) @(posedge clk);
  69. rst_n <= 1'b1;
  70. repeat (2) @(posedge clk);
  71. issue_set();
  72. if (commit_count !== 1) $fatal(1, "all-zero SET must commit once, got %0d", commit_count);
  73. for (i = 0; i < 32; i = i + 1) mem[i] = 8'd100;
  74. issue_set();
  75. if (commit_count !== 2) $fatal(1, "all-100 SET commit count %0d", commit_count);
  76. mem[0] = 8'd101;
  77. issue_set();
  78. if (commit_count !== 2) $fatal(1, "first-byte 101 committed");
  79. mem[0] = 8'd0;
  80. mem[16] = 8'd101;
  81. issue_set();
  82. if (commit_count !== 2) $fatal(1, "mid-byte 101 committed");
  83. mem[16] = 8'd0;
  84. mem[31] = 8'd101;
  85. issue_set();
  86. if (commit_count !== 2) $fatal(1, "last-byte 101 committed");
  87. mem[31] = 8'd0;
  88. begin : reject_lengths
  89. integer li;
  90. for (li = 0; li < 4; li = li + 1) begin
  91. @(posedge clk);
  92. frame_type <= 8'h01;
  93. if (li == 0) frame_length <= 8'd11;
  94. else if (li == 1) frame_length <= 8'd14;
  95. else if (li == 2) frame_length <= 8'd31;
  96. else frame_length <= 8'd33;
  97. frame_valid <= 1'b1;
  98. @(posedge clk);
  99. frame_valid <= 1'b0;
  100. repeat (8) @(posedge clk);
  101. end
  102. end
  103. @(posedge clk);
  104. frame_type <= 8'h03;
  105. frame_length <= 8'd0;
  106. frame_valid <= 1'b1;
  107. @(posedge clk);
  108. frame_valid <= 1'b0;
  109. repeat (8) @(posedge clk);
  110. if (commit_count !== 2) $fatal(1, "length/type rejects committed");
  111. if (tx_start) $fatal(1, "SET path produced TX");
  112. begin : one_hot
  113. integer idx;
  114. integer saw_addr;
  115. integer saw_data;
  116. integer writes;
  117. for (idx = 0; idx < 32; idx = idx + 1) begin
  118. for (i = 0; i < 32; i = i + 1) mem[i] = 8'd0;
  119. mem[idx] = 8'd77;
  120. writes = 0;
  121. saw_addr = -1;
  122. saw_data = -1;
  123. fork
  124. begin
  125. issue_set();
  126. end
  127. begin
  128. repeat (80) begin
  129. @(posedge clk);
  130. if (wr_en) begin
  131. writes = writes + 1;
  132. if (wr_data === 8'd77) begin
  133. saw_addr = wr_addr;
  134. saw_data = wr_data;
  135. end
  136. end
  137. end
  138. end
  139. join
  140. if (saw_addr !== idx) $fatal(1, "one-hot addr idx=%0d saw=%0d", idx, saw_addr);
  141. if (writes !== 32) $fatal(1, "one-hot writes=%0d idx=%0d", writes, idx);
  142. end
  143. end
  144. if (commit_count !== 34) $fatal(1, "one-hot commit count %0d", commit_count);
  145. $display("prod2u_6400_command_controller_tb PASS");
  146. $finish;
  147. end
  148. endmodule