bmc_dimm_frame_parser_tb.v 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. `timescale 1ns/1ps
  2. module bmc_dimm_frame_parser_tb;
  3. reg clk;
  4. reg rst_n;
  5. reg raw_valid;
  6. reg [7:0] raw_integer_byte;
  7. reg [7:0] raw_fraction_byte;
  8. reg [4:0] raw_pair_index;
  9. reg [15:0] frame_seq;
  10. reg [15:0] sample_seq_base;
  11. reg [15:0] age_ms;
  12. reg frame_bad_length;
  13. reg sample_stale;
  14. reg sample_ready;
  15. wire raw_ready;
  16. wire dimm_valid;
  17. wire [2:0] source_id;
  18. wire [15:0] dimm_frame_seq;
  19. wire [15:0] dimm_sample_seq;
  20. wire [4:0] raw_pair_index_out;
  21. wire [4:0] dimm_id;
  22. wire [4:0] channel;
  23. wire [7:0] raw_integer_byte_out;
  24. wire [7:0] raw_fraction_byte_out;
  25. wire signed [17:0] temp_q;
  26. wire [15:0] temp_c_x100;
  27. wire missing;
  28. wire fault;
  29. wire stale;
  30. wire [15:0] age_ms_out;
  31. wire [7:0] raw_status;
  32. wire [7:0] parser_status;
  33. bmc_dimm_frame_parser dut (
  34. .clk(clk),
  35. .rst_n(rst_n),
  36. .raw_valid(raw_valid),
  37. .raw_ready(raw_ready),
  38. .raw_integer_byte(raw_integer_byte),
  39. .raw_fraction_byte(raw_fraction_byte),
  40. .raw_pair_index(raw_pair_index),
  41. .frame_seq(frame_seq),
  42. .sample_seq_base(sample_seq_base),
  43. .age_ms(age_ms),
  44. .frame_bad_length(frame_bad_length),
  45. .sample_stale(sample_stale),
  46. .sample_ready(sample_ready),
  47. .dimm_valid(dimm_valid),
  48. .source_id(source_id),
  49. .dimm_frame_seq(dimm_frame_seq),
  50. .dimm_sample_seq(dimm_sample_seq),
  51. .raw_pair_index_out(raw_pair_index_out),
  52. .dimm_id(dimm_id),
  53. .channel(channel),
  54. .raw_integer_byte_out(raw_integer_byte_out),
  55. .raw_fraction_byte_out(raw_fraction_byte_out),
  56. .temp_q(temp_q),
  57. .temp_c_x100(temp_c_x100),
  58. .missing(missing),
  59. .fault(fault),
  60. .stale(stale),
  61. .age_ms_out(age_ms_out),
  62. .raw_status(raw_status),
  63. .parser_status(parser_status)
  64. );
  65. initial begin
  66. clk = 1'b0;
  67. forever #5 clk = ~clk;
  68. end
  69. task send_pair;
  70. input [7:0] integer_byte;
  71. input [7:0] fraction_byte;
  72. input [4:0] index;
  73. begin
  74. @(negedge clk);
  75. raw_integer_byte = integer_byte;
  76. raw_fraction_byte = fraction_byte;
  77. raw_pair_index = index;
  78. raw_valid = 1'b1;
  79. @(posedge clk);
  80. #1;
  81. raw_valid = 1'b0;
  82. end
  83. endtask
  84. initial begin
  85. rst_n = 1'b0;
  86. raw_valid = 1'b0;
  87. raw_integer_byte = 8'd0;
  88. raw_fraction_byte = 8'd0;
  89. raw_pair_index = 5'd0;
  90. frame_seq = 16'd7;
  91. sample_seq_base = 16'd100;
  92. age_ms = 16'd0;
  93. frame_bad_length = 1'b0;
  94. sample_stale = 1'b0;
  95. sample_ready = 1'b1;
  96. repeat (4) @(negedge clk);
  97. rst_n = 1'b1;
  98. send_pair(8'h3c, 8'h4b, 5'd0);
  99. if (!dimm_valid || temp_c_x100 !== 16'd6075 || temp_q !== 18'sd61 ||
  100. dimm_sample_seq !== 16'd100 || source_id !== 3'd5 || fault) begin
  101. $display(
  102. "BMC parser normal temperature mismatch valid=%0d temp_c_x100=%0d temp_q=%0d sample_seq=%0d source=%0d fault=%0d",
  103. dimm_valid,
  104. temp_c_x100,
  105. temp_q,
  106. dimm_sample_seq,
  107. source_id,
  108. fault
  109. );
  110. $fatal;
  111. end
  112. send_pair(8'hff, 8'hff, 5'd6);
  113. if (!missing || fault || raw_status[0] !== 1'b1 || channel !== 5'd6) begin
  114. $display("BMC parser missing DIMM mismatch");
  115. $fatal;
  116. end
  117. sample_stale = 1'b1;
  118. age_ms = 16'd3500;
  119. send_pair(8'h40, 8'h32, 5'd1);
  120. if (!stale || raw_status[3] !== 1'b1 || age_ms_out !== 16'd3500) begin
  121. $display("BMC parser stale field mismatch");
  122. $fatal;
  123. end
  124. sample_stale = 1'b0;
  125. frame_bad_length = 1'b1;
  126. send_pair(8'h40, 8'h32, 5'd2);
  127. if (!fault || parser_status !== 8'd1 || raw_status[1] !== 1'b1) begin
  128. $display("BMC parser bad length mismatch");
  129. $fatal;
  130. end
  131. $display("PASS: bmc_dimm_frame_parser_tb");
  132. $finish;
  133. end
  134. endmodule