| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- `timescale 1ns/1ps
- // 1:1 Physical-Circuit PTY Bridge Testbench for 6400 V2.0 Closed-Loop Co-Simulation.
- // Connects production prod2u_6400_v2_top (with real CT7428 U6 I2C BFM, real BMC
- // 115200 UART BFM, 2N7002 NMOS fan output inverters, SSR1/2/4, V3.0 buttons
- // (EPB1=F8, SB1=C11, SB2=A11), and 4000Hz 80% buzzer H6) to Linux host software
- // over a non-blocking VPI PTY.
- module pty_6400_v2_bridge_tb;
- localparam integer CLOCK_HZ = 25000000;
- localparam integer BIT_CLKS = 27; // Production 921600 baud @ 25 MHz (8x faster & 1:1 production rate)
- reg sys_clk = 1'b0;
- reg host_ttl_rx = 1'b1;
- wire host_ttl_tx;
- wire host_rs232_tx;
- wire bmc_rx;
- wire bmc_tx;
- tri1 temp_scl;
- tri1 temp_sda;
- wire temp_scl_alt;
- wire temp_sda_alt;
- wire [23:0] ptc_pwm_out;
- wire [10:0] ptc_spare_zero;
- wire [3:0] front_fan_pwm_out;
- wire [3:0] rear_fan_pwm_out;
- wire ssr1_out, ssr2_out, ssr4_out;
- wire [2:0] ssr_unused_zero;
- reg estop_btn_in = 1'b0;
- reg hood_open_btn_in = 1'b0;
- reg hood_close_btn_in = 1'b0;
- wire buzzer_out;
- // 1:1 physical PCB 2N7002 NMOS fan-PWM inverting stage (+5V pullup on connector)
- wire [3:0] front_fan_connector_pwm;
- wire [3:0] rear_fan_connector_pwm;
- genvar gi;
- generate
- for (gi = 0; gi < 4; gi = gi + 1) begin : g_fan_nmos
- pullup p_front(front_fan_connector_pwm[gi]);
- nmos q_front(front_fan_connector_pwm[gi], 1'b0, front_fan_pwm_out[gi]);
- pullup p_rear(rear_fan_connector_pwm[gi]);
- nmos q_rear(rear_fan_connector_pwm[gi], 1'b0, rear_fan_pwm_out[gi]);
- end
- endgenerate
- always #20 sys_clk = ~sys_clk; // 25 MHz (40 ns)
- prod2u_6400_v2_top #(
- .HOST_BAUD(921600),
- .FAN_BOARD_INVERT_MASK(8'hFF)
- ) dut (
- .sys_clk(sys_clk),
- .host_ttl_rx(host_ttl_rx),
- .host_ttl_tx(host_ttl_tx),
- .host_rs232_rx(1'b1),
- .host_rs232_tx(host_rs232_tx),
- .bmc_rs232_rx(bmc_rx),
- .bmc_rs232_tx(bmc_tx),
- .ptc_pwm_out(ptc_pwm_out),
- .ptc_spare_zero(ptc_spare_zero),
- .front_fan_pwm_out(front_fan_pwm_out),
- .rear_fan_pwm_out(rear_fan_pwm_out),
- .temp_scl(temp_scl),
- .temp_sda(temp_sda),
- .temp_scl_alt(temp_scl_alt),
- .temp_sda_alt(temp_sda_alt),
- .ssr1_out(ssr1_out),
- .ssr2_out(ssr2_out),
- .ssr4_out(ssr4_out),
- .ssr_unused_zero(ssr_unused_zero),
- .estop_btn_in(estop_btn_in),
- .hood_open_btn_in(hood_open_btn_in),
- .hood_close_btn_in(hood_close_btn_in),
- .buzzer_out(buzzer_out)
- );
- // Timer-only elaboration acceleration for BMC poll so live BMC temperatures
- // appear quickly in PTY co-simulation without changing UART/I2C timing.
- defparam dut.u_bmc_poll.POLL_SECONDS = 0;
- defparam dut.u_bmc_poll.ROUND_TIMEOUT_CLKS = 750000;
- wire [31:0] ct_reads, bmc_commands, bmc_replies;
- wire [8:0] ct_registers;
- ct7428_normal_slave_bfm #(
- .I2C_ADDRESS(7'h49),
- .DIAGNOSTIC_REGISTERS(1)
- ) ct_u6 (
- .scl(temp_scl),
- .sda(temp_sda),
- .completed_reads(ct_reads),
- .registers_seen(ct_registers)
- );
- bmc_uart_normal_bfm #(
- .RESPOND_ROUNDS(100)
- ) bmc (
- .rx_from_fpga(bmc_tx),
- .tx_to_fpga(bmc_rx),
- .commands_seen(bmc_commands),
- .replies_sent(bmc_replies)
- );
- // Physical board stimulus: detect 4000 Hz 80% buzzer_out pulses (LOW phase is 1250 clks)
- // to stably assert EPB1=1 & SB1=1 (SB2=0) when buzzer is active so host Python co-sim
- // verifies boot=0/0/0, active=1/1/0, and zero CPLD safety interlock on EPB1.
- reg [11:0] buzzer_low_cnt = 12'd0;
- always @(posedge sys_clk) begin
- if (buzzer_out) begin
- buzzer_low_cnt <= 12'd0;
- estop_btn_in <= 1'b1;
- hood_open_btn_in <= 1'b1;
- hood_close_btn_in <= 1'b0;
- end else if (buzzer_low_cnt < 12'd2500) begin
- buzzer_low_cnt <= buzzer_low_cnt + 12'd1;
- end else begin
- estop_btn_in <= 1'b0;
- hood_open_btn_in <= 1'b0;
- hood_close_btn_in <= 1'b0;
- end
- end
- reg sim_ready = 1'b0;
- reg [1023:0] pty_path_str = "/workspace/tmp/m6400_v2_pty_slave";
- initial begin
- host_ttl_rx = 1'b1;
- if (!$value$plusargs("PTY_PATH=%s", pty_path_str)) begin
- pty_path_str = "/workspace/tmp/m6400_v2_pty_slave";
- end
- $pty_init(pty_path_str);
- // Wait for POR + initial CT7428 U6 scan (9 regs) so real sensor temps exist
- repeat (2000) @(posedge sys_clk);
- sim_ready = 1'b1;
- $display("[TB-6400V2] sim_ready=1 at time %0t (pty_path=%0s)", $time, pty_path_str);
- end
- // UART TX BFM (PTY -> host_ttl_rx @ 115200 8N1)
- integer pty_byte;
- integer pty_valid;
- integer b_tx;
- initial begin
- host_ttl_rx = 1'b1;
- wait (sim_ready);
- forever begin
- repeat (20) @(posedge sys_clk);
- $pty_poll_read(pty_byte, pty_valid);
- if (pty_valid != 0) begin
- host_ttl_rx = 1'b0;
- repeat (BIT_CLKS) @(posedge sys_clk);
- for (b_tx = 0; b_tx < 8; b_tx = b_tx + 1) begin
- host_ttl_rx = pty_byte[b_tx];
- repeat (BIT_CLKS) @(posedge sys_clk);
- end
- host_ttl_rx = 1'b1;
- repeat (BIT_CLKS) @(posedge sys_clk);
- end
- end
- end
- // UART RX BFM (host_ttl_tx -> PTY @ 115200 8N1)
- integer rx_clk_cnt = 0;
- reg [3:0] rx_bit = 0;
- reg [7:0] rx_shift = 0;
- reg rx_busy = 0;
- always @(posedge sys_clk) begin
- if (!rx_busy && host_ttl_tx === 1'b0) begin
- rx_busy <= 1'b1;
- rx_clk_cnt <= BIT_CLKS + (BIT_CLKS / 2) - 1;
- rx_bit <= 0;
- end else if (rx_busy) begin
- if (rx_clk_cnt == 0) begin
- if (rx_bit < 8) begin
- rx_shift[rx_bit] <= host_ttl_tx;
- rx_bit <= rx_bit + 1'b1;
- rx_clk_cnt <= BIT_CLKS - 1;
- end else begin
- $pty_send_byte(rx_shift);
- rx_busy <= 1'b0;
- end
- end else begin
- rx_clk_cnt <= rx_clk_cnt - 1;
- end
- end
- end
- endmodule
|