`timescale 1ns/1ps module prod2u_6400_host_e2e_tb; reg clk=0;always #20 clk=~clk; reg scl=1,master_low=0; reg rs_rx=1,ttl_rx=1,bmc_rx=1,use_ttl=0,bmc_done=0; wire rs_tx,ttl_tx; tri1 sda,temp_scl,temp_sda; assign sda=master_low ? 1'b0 : 1'bz; wire [23:0] ptc; wire [3:0] front_fan,rear_fan; prod2u_6400_v1_top dut(.sys_clk(clk),.host_rs232_rx(rs_rx),.host_rs232_tx(rs_tx), .host_ttl_rx(ttl_rx),.host_ttl_tx(ttl_tx),.bmc_rs232_rx(bmc_rx),.bmc_rs232_tx(), .host_i2c_scl(scl),.host_i2c_sda(sda),.temp_scl(temp_scl),.temp_sda(temp_sda), .ptc_pwm_out(ptc),.front_fan_pwm_out(front_fan),.rear_fan_pwm_out(rear_fan)); integer half_ns=1250; `include "tests/sim/i2c_master_tasks.vh" reg [7:0] value; integer i; reg [7:0] payload [0:31],serial_response [0:1023]; integer serial_count=0,rx_bit,transport; reg [7:0] rx_byte; wire selected_tx=use_ttl ? ttl_tx : rs_tx; // Decode actual 27-clock/bit TX, including every physical stop bit. always begin @(negedge selected_tx);#540; if(selected_tx!==0) $fatal(1,"UART start bit"); for(rx_bit=0;rx_bit<8;rx_bit=rx_bit+1) begin #1080;rx_byte[rx_bit]=selected_tx;end #1080; if(selected_tx!==1 || !dut.u_host_select.locked) $fatal(1,"Host released before final stop bit"); serial_response[serial_count]=rx_byte;serial_count=serial_count+1; end function [15:0] crc_byte(input [15:0] old_crc,input [7:0] b); integer k;reg [15:0] c; begin c=old_crc^{b,8'd0};for(k=0;k<8;k=k+1) c=c[15] ? (c<<1)^16'h1021 : c<<1;crc_byte=c;end endfunction task host_byte(input [7:0] b); integer k; begin if(use_ttl) ttl_rx=0;else rs_rx=0;#1085; // nominal 921600, not a byte bypass for(k=0;k<8;k=k+1) begin if(use_ttl) ttl_rx=b[k];else rs_rx=b[k];#1085;end if(use_ttl) ttl_rx=1;else rs_rx=1;#1085; end endtask task host_frame(input [7:0] kind,input integer n); integer k;reg [15:0] c; begin serial_count=0;c=crc_byte(crc_byte(crc_byte(16'hFFFF,kind),n[7:0]),n[15:8]); host_byte(8'hA5);host_byte(8'h5A);host_byte(kind);host_byte(n[7:0]);host_byte(n[15:8]); for(k=0;k=11);#2160;check_serial_frame(0,8'h80,4); if(serial_response[5]!=1 || serial_response[6]!=0) $fatal(1,"6400 UART SET_ALL rejected"); host_frame(2,0);wait(serial_count>=217);#2160; check_serial_frame(0,8'h80,4);check_serial_frame(11,8'h81,199); if(serial_response[16+182]!=45+transport || serial_response[16+190]!=49+transport || serial_response[16+154]!=23) $fatal(1,"6400 physical UART Snapshot mismatch"); end wait(bmc_done);#10000; if(dut.bmc_valid_mask!==24'hFFFFFF) $fatal(1,"6400 BMC lost concurrent 24-channel line"); if(dut.ct_epoch==0 || dut.ct_valid_mask!=0) $fatal(1,"6400 absent CT scan hung"); $display("prod2u_6400_host_e2e_tb PASS");$finish; end initial begin #50000000;$fatal(1,"6400 production transport deadline");end endmodule