bmc_uart_normal_bfm.v 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. `timescale 1ns/1ps
  2. // Normal BMC shell model at nominal 115200 8N1. The 43-byte command must
  3. // arrive through the real UART pin before echo/data/prompt are transmitted.
  4. module bmc_uart_normal_bfm #(
  5. parameter integer RESPOND_ROUNDS = 1
  6. ) (
  7. input wire rx_from_fpga,
  8. output reg tx_to_fpga = 1,
  9. output reg [31:0] commands_seen = 0,
  10. output reg [31:0] replies_sent = 0
  11. );
  12. localparam real BIT_NS = 1000000000.0 / 115200.0;
  13. localparam [8*43-1:0] COMMAND =
  14. {"ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03", 8'h0a};
  15. localparam [8*13-1:0] PROMPT = "root@test:~# ";
  16. reg [7:0] captured;
  17. integer bit_index, command_index = 0;
  18. event command_complete;
  19. function [7:0] expected_temperature;
  20. input integer index;
  21. begin
  22. case (index)
  23. 0: expected_temperature = 0;
  24. 1: expected_temperature = 40;
  25. 2: expected_temperature = 42;
  26. 3: expected_temperature = 43;
  27. 4: expected_temperature = 8'hff;
  28. default: expected_temperature = 30 + index;
  29. endcase
  30. end
  31. endfunction
  32. function [7:0] hex_digit;
  33. input [3:0] digit;
  34. begin
  35. hex_digit = digit < 10 ? 8'h30 + digit : 8'h41 + digit - 10;
  36. end
  37. endfunction
  38. task send_char;
  39. input [7:0] ch;
  40. integer b;
  41. begin
  42. tx_to_fpga = 0;
  43. #(BIT_NS);
  44. for (b = 0; b < 8; b = b + 1) begin
  45. tx_to_fpga = ch[b];
  46. #(BIT_NS);
  47. end
  48. tx_to_fpga = 1;
  49. #(BIT_NS);
  50. end
  51. endtask
  52. task send_hex;
  53. input [7:0] value;
  54. begin
  55. send_char(hex_digit(value[7:4]));
  56. send_char(hex_digit(value[3:0]));
  57. end
  58. endtask
  59. initial begin
  60. forever begin
  61. @(negedge rx_from_fpga);
  62. #(1.5 * BIT_NS);
  63. for (bit_index = 0; bit_index < 8; bit_index = bit_index + 1) begin
  64. captured[bit_index] = rx_from_fpga;
  65. #(BIT_NS);
  66. end
  67. if (rx_from_fpga !== 1'b1) $fatal(1, "BMC command UART stop bit error");
  68. if (captured !== COMMAND[8*(42-command_index) +: 8])
  69. $fatal(1, "BMC physical TX command byte %0d=%h expected=%h",
  70. command_index, captured, COMMAND[8*(42-command_index) +: 8]);
  71. command_index = command_index + 1;
  72. if (command_index == 43) begin
  73. #(0.5 * BIT_NS);
  74. command_index = 0;
  75. commands_seen = commands_seen + 1;
  76. -> command_complete;
  77. end
  78. end
  79. end
  80. integer i;
  81. reg [7:0] fraction;
  82. initial begin
  83. forever begin
  84. @command_complete;
  85. if (commands_seen <= RESPOND_ROUNDS) begin
  86. #(2.13 * BIT_NS);
  87. // Full command echo, then three lines of sixteen hex tokens.
  88. for (i = 0; i < 43; i = i + 1)
  89. send_char(COMMAND[8*(42-i) +: 8]);
  90. for (i = 0; i < 24; i = i + 1) begin
  91. send_hex(expected_temperature(i));
  92. send_char(" ");
  93. fraction = i == 4 ? 8'hff : (i*7)%100;
  94. send_hex(fraction);
  95. if ((i % 8) == 7) begin
  96. send_char(8'h0d); send_char(8'h0a);
  97. end else send_char(" ");
  98. end
  99. for (i = 0; i < 13; i = i + 1)
  100. send_char(PROMPT[8*(12-i) +: 8]);
  101. replies_sent = replies_sent + 1;
  102. end // later commands are received but the BMC sends no reply
  103. end
  104. end
  105. endmodule