| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- `timescale 1ns/1ps
- // Normal BMC shell model at nominal 115200 8N1. The 43-byte command must
- // arrive through the real UART pin before echo/data/prompt are transmitted.
- module bmc_uart_normal_bfm #(
- parameter integer RESPOND_ROUNDS = 1
- ) (
- input wire rx_from_fpga,
- output reg tx_to_fpga = 1,
- output reg [31:0] commands_seen = 0,
- output reg [31:0] replies_sent = 0
- );
- localparam real BIT_NS = 1000000000.0 / 115200.0;
- localparam [8*43-1:0] COMMAND =
- {"ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03", 8'h0a};
- localparam [8*13-1:0] PROMPT = "root@test:~# ";
- reg [7:0] captured;
- integer bit_index, command_index = 0;
- event command_complete;
- function [7:0] expected_temperature;
- input integer index;
- begin
- case (index)
- 0: expected_temperature = 0;
- 1: expected_temperature = 40;
- 2: expected_temperature = 42;
- 3: expected_temperature = 43;
- 4: expected_temperature = 8'hff;
- default: expected_temperature = 30 + index;
- endcase
- end
- endfunction
- function [7:0] hex_digit;
- input [3:0] digit;
- begin
- hex_digit = digit < 10 ? 8'h30 + digit : 8'h41 + digit - 10;
- end
- endfunction
- task send_char;
- input [7:0] ch;
- integer b;
- begin
- tx_to_fpga = 0;
- #(BIT_NS);
- for (b = 0; b < 8; b = b + 1) begin
- tx_to_fpga = ch[b];
- #(BIT_NS);
- end
- tx_to_fpga = 1;
- #(BIT_NS);
- end
- endtask
- task send_hex;
- input [7:0] value;
- begin
- send_char(hex_digit(value[7:4]));
- send_char(hex_digit(value[3:0]));
- end
- endtask
- initial begin
- forever begin
- @(negedge rx_from_fpga);
- #(1.5 * BIT_NS);
- for (bit_index = 0; bit_index < 8; bit_index = bit_index + 1) begin
- captured[bit_index] = rx_from_fpga;
- #(BIT_NS);
- end
- if (rx_from_fpga !== 1'b1) $fatal(1, "BMC command UART stop bit error");
- if (captured !== COMMAND[8*(42-command_index) +: 8])
- $fatal(1, "BMC physical TX command byte %0d=%h expected=%h",
- command_index, captured, COMMAND[8*(42-command_index) +: 8]);
- command_index = command_index + 1;
- if (command_index == 43) begin
- #(0.5 * BIT_NS);
- command_index = 0;
- commands_seen = commands_seen + 1;
- -> command_complete;
- end
- end
- end
- integer i;
- reg [7:0] fraction;
- initial begin
- forever begin
- @command_complete;
- if (commands_seen <= RESPOND_ROUNDS) begin
- #(2.13 * BIT_NS);
- // Full command echo, then three lines of sixteen hex tokens.
- for (i = 0; i < 43; i = i + 1)
- send_char(COMMAND[8*(42-i) +: 8]);
- for (i = 0; i < 24; i = i + 1) begin
- send_hex(expected_temperature(i));
- send_char(" ");
- fraction = i == 4 ? 8'hff : (i*7)%100;
- send_hex(fraction);
- if ((i % 8) == 7) begin
- send_char(8'h0d); send_char(8'h0a);
- end else send_char(" ");
- end
- for (i = 0; i < 13; i = i + 1)
- send_char(PROMPT[8*(12-i) +: 8]);
- replies_sent = replies_sent + 1;
- end // later commands are received but the BMC sends no reply
- end
- end
- endmodule
|