| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573 |
- `timescale 1ns/1ps
- // 6400 V2.0 End-to-End Simulation Testbench
- //
- // Drives the 6400 V2.0 top module (prod2u_6400_v2_top) over CON12 TTL UART
- // (J4 RX, K2 TX) at 921600 8N1 (27 clocks/bit at 25 MHz) and verifies:
- // 1. SSR1, SSR2, SSR4 outputs (F3, F1, G4) reset to zero.
- // 2. SET_ALL (35 bytes) -> receives valid SET_ACK (81 00).
- // 3. GET_ALL (0 bytes) -> receives GET_ACK (82 00) followed by GET_DATA (42 56):
- // - 24 PTC duties match set duties.
- // - 4 Front and 4 Rear fan duties match set duties.
- // - CT sensor channels 9..26 (offsets 65..82) return 0xFF.
- // 4. GET returns the expected duty-bank bytes after each SET.
- // 5. SSRs follow the100/0/100 commands at the explicit checkpoints.
- // This test uses integer UART timing and response-header checks. It does not
- // verify response CRCs, physical ADC mapping or the first PWM commit edge.
- module prod2u_6400_v2_tb;
- localparam integer CLKS_PER_BIT = 27;
- localparam integer BIT_CLKS = CLKS_PER_BIT;
- reg clk;
- initial begin
- clk = 0;
- forever #20 clk = ~clk; // 25 MHz (40 ns)
- end
- // DUT signals
- reg host_ttl_rx;
- wire host_ttl_tx;
- reg host_rs232_rx;
- wire host_rs232_tx;
- reg bmc_rs232_rx;
- wire bmc_rs232_tx;
- wire [23:0] ptc_pwm_out;
- wire [3:0] front_fan_pwm_out;
- wire [3:0] rear_fan_pwm_out;
- wire temp_scl;
- wire temp_sda;
- wire ssr1_out;
- wire ssr2_out;
- wire ssr4_out;
- reg estop_btn_in;
- reg hood_open_btn_in;
- reg hood_close_btn_in;
- wire buzzer_out;
- pullup(temp_scl);
- pullup(temp_sda);
- prod2u_6400_v2_top #(
- .FAN_BOARD_INVERT_MASK(8'hFF)
- ) u_dut (
- .sys_clk(clk),
- .host_ttl_rx(host_ttl_rx),
- .host_ttl_tx(host_ttl_tx),
- .host_rs232_rx(host_rs232_rx),
- .host_rs232_tx(host_rs232_tx),
- .bmc_rs232_rx(bmc_rs232_rx),
- .bmc_rs232_tx(bmc_rs232_tx),
- .ptc_pwm_out(ptc_pwm_out),
- .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_sda_alt(),
- .ssr1_out(ssr1_out),
- .ssr2_out(ssr2_out),
- .ssr4_out(ssr4_out),
- .ssr_unused_zero(),
- .ptc_spare_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)
- );
- // Frame buffers
- reg [7:0] frame_bytes [0:255];
- integer frame_len;
- // Independent CRC calculation
- function [15:0] crc_over_frame;
- input integer count;
- integer i, b;
- reg [15:0] c;
- reg [7:0] d;
- begin
- c = 16'hFFFF;
- for (i = 2; i < count; i = i + 1) begin
- d = frame_bytes[i];
- for (b = 7; b >= 0; b = b - 1)
- c = (c[15] ^ d[b]) ? ({c[14:0], 1'b0} ^ 16'h1021)
- : {c[14:0], 1'b0};
- end
- crc_over_frame = c;
- end
- endfunction
- // UART transmit via CON12 TTL RX
- task uart_send_byte;
- input [7:0] value;
- integer b;
- begin
- host_ttl_rx = 1'b0; // start bit
- repeat (BIT_CLKS) @(posedge clk);
- for (b = 0; b < 8; b = b + 1) begin
- host_ttl_rx = value[b];
- repeat (BIT_CLKS) @(posedge clk);
- end
- host_ttl_rx = 1'b1; // stop bit
- repeat (BIT_CLKS) @(posedge clk);
- end
- endtask
- task uart_send_frame;
- input integer n;
- integer i;
- reg [15:0] c;
- begin
- c = crc_over_frame(n);
- for (i = 0; i < n; i = i + 1)
- uart_send_byte(frame_bytes[i]);
- uart_send_byte(c[7:0]);
- uart_send_byte(c[15:8]);
- end
- endtask
- // UART transmit via CON134 RS-232 RX
- task uart_send_byte_rs232;
- input [7:0] value;
- integer b;
- begin
- host_rs232_rx = 1'b0; // start bit
- repeat (BIT_CLKS) @(posedge clk);
- for (b = 0; b < 8; b = b + 1) begin
- host_rs232_rx = value[b];
- repeat (BIT_CLKS) @(posedge clk);
- end
- host_rs232_rx = 1'b1; // stop bit
- repeat (BIT_CLKS) @(posedge clk);
- end
- endtask
- task uart_send_frame_rs232;
- input integer n;
- integer i;
- reg [15:0] c;
- begin
- c = crc_over_frame(n);
- for (i = 0; i < n; i = i + 1)
- uart_send_byte_rs232(frame_bytes[i]);
- uart_send_byte_rs232(c[7:0]);
- uart_send_byte_rs232(c[15:8]);
- end
- endtask
- task uart_send_frame_rs232_bad_crc;
- input integer n;
- integer i;
- begin
- for (i = 0; i < n; i = i + 1)
- uart_send_byte_rs232(frame_bytes[i]);
- uart_send_byte_rs232(8'hDE); // corrupted CRC
- uart_send_byte_rs232(8'hAD);
- end
- endtask
- task uart_send_byte_bad_stop;
- input [7:0] value;
- integer b;
- begin
- host_ttl_rx = 1'b0; // start bit
- repeat (BIT_CLKS) @(posedge clk);
- for (b = 0; b < 8; b = b + 1) begin
- host_ttl_rx = value[b];
- repeat (BIT_CLKS) @(posedge clk);
- end
- host_ttl_rx = 1'b0; // bad stop bit
- repeat (BIT_CLKS) @(posedge clk);
- host_ttl_rx = 1'b1; // return to idle
- repeat (BIT_CLKS) @(posedge clk);
- end
- endtask
- // UART receive sampler on CON12 TTL TX
- reg [7:0] rx_bytes [0:255];
- integer rx_count;
- reg [3:0] rx_bit;
- reg [7:0] rx_shift;
- integer rx_clk_cnt;
- reg rx_busy;
- initial begin
- rx_busy = 0;
- rx_clk_cnt = 0;
- rx_count = 0;
- forever begin
- @(posedge clk);
- if (!rx_busy && host_ttl_tx === 1'b0) begin
- rx_busy = 1;
- 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;
- rx_clk_cnt = BIT_CLKS - 1;
- end else begin
- rx_bytes[rx_count] = rx_shift;
- rx_count = rx_count + 1;
- rx_busy = 0;
- end
- end else begin
- rx_clk_cnt = rx_clk_cnt - 1;
- end
- end
- end
- end
- // UART receive sampler on CON134 RS-232 TX (broadcast check)
- reg [7:0] rs232_rx_bytes [0:255];
- integer rs232_rx_count;
- reg [3:0] rs232_rx_bit;
- reg [7:0] rs232_rx_shift;
- integer rs232_rx_clk_cnt;
- reg rs232_rx_busy;
- initial begin
- rs232_rx_busy = 0;
- rs232_rx_clk_cnt = 0;
- rs232_rx_count = 0;
- forever begin
- @(posedge clk);
- if (!rs232_rx_busy && host_rs232_tx === 1'b0) begin
- rs232_rx_busy = 1;
- rs232_rx_clk_cnt = BIT_CLKS + (BIT_CLKS / 2) - 1;
- rs232_rx_bit = 0;
- end else if (rs232_rx_busy) begin
- if (rs232_rx_clk_cnt == 0) begin
- if (rs232_rx_bit < 8) begin
- rs232_rx_shift[rs232_rx_bit] = host_rs232_tx;
- rs232_rx_bit = rs232_rx_bit + 1;
- rs232_rx_clk_cnt = BIT_CLKS - 1;
- end else begin
- rs232_rx_bytes[rs232_rx_count] = rs232_rx_shift;
- rs232_rx_count = rs232_rx_count + 1;
- rs232_rx_busy = 0;
- end
- end else begin
- rs232_rx_clk_cnt = rs232_rx_clk_cnt - 1;
- end
- end
- end
- end
- integer failures = 0;
- integer i;
- initial begin
- host_ttl_rx = 1'b1;
- host_rs232_rx = 1'b1;
- bmc_rs232_rx = 1'b1;
- estop_btn_in = 1'b0;
- hood_open_btn_in = 1'b0;
- hood_close_btn_in = 1'b0;
- repeat (3000) @(posedge clk);
- // Check 1: SSR1, SSR2, SSR4 and buzzer reset defaults are zero
- if (ssr1_out !== 1'b0 || ssr2_out !== 1'b0 || ssr4_out !== 1'b0 || buzzer_out !== 1'b0) begin
- $display("FAIL: SSR/buzzer boot outputs not zero: %b %b %b %b", ssr1_out, ssr2_out, ssr4_out, buzzer_out);
- failures = failures + 1;
- end else begin
- $display("PASS: SSR1, SSR2, SSR4 and buzzer are zero at boot");
- end
- // Check 2: Build and send SET_ALL (36 bytes: 35 duties + buzzer=1)
- // PTC 0..23 = 50%, Front 0..3 = 40%, Rear 0..3 = 60%, SSR = 100/0/100, buzzer = 1
- frame_bytes[0] = 8'hA5;
- frame_bytes[1] = 8'h5A;
- frame_bytes[2] = 8'h01; // SET_ALL
- frame_bytes[3] = 8'd36; // LEN
- for (i = 0; i < 24; i = i + 1) frame_bytes[4 + i] = 8'd50;
- for (i = 0; i < 4; i = i + 1) frame_bytes[28 + i] = 8'd40;
- for (i = 0; i < 4; i = i + 1) frame_bytes[32 + i] = 8'd60;
- frame_bytes[36] = 100; frame_bytes[37] = 0; frame_bytes[38] = 100;
- frame_bytes[39] = 1; // buzzer ON
- frame_len = 40;
- $display("Sending SET_ALL (36B, buzzer=1) via CON12 TTL...");
- rx_count = 0;
- rs232_rx_count = 0;
- uart_send_frame(frame_len);
- // Expect SET_ACK (A5 5A 81 00 A6 35 = 6 bytes)
- while (rx_count < 6) @(posedge clk);
- if (rx_bytes[0] !== 8'hA5 || rx_bytes[1] !== 8'h5A ||
- rx_bytes[2] !== 8'h81 || rx_bytes[3] !== 8'h00) begin
- $display("FAIL: SET_ACK header incorrect: %02h %02h %02h %02h",
- rx_bytes[0], rx_bytes[1], rx_bytes[2], rx_bytes[3]);
- failures = failures + 1;
- end else begin
- $display("PASS: Received SET_ACK (81 00)");
- end
- begin : check_bz_wave
- integer bz_hi, bz_lo, bz_k;
- bz_hi = 0; bz_lo = 0;
- for (bz_k = 0; bz_k < 6250; bz_k = bz_k + 1) begin
- @(posedge clk);
- if (buzzer_out === 1'b1) bz_hi = bz_hi + 1;
- else if (buzzer_out === 1'b0) bz_lo = bz_lo + 1;
- end
- if (bz_hi !== 5000 || bz_lo !== 1250) begin
- $display("FAIL: buzzer_out 4000Hz 80%% mismatch: high=%0d low=%0d", bz_hi, bz_lo);
- failures = failures + 1;
- end else begin
- $display("PASS: buzzer_out 4000Hz 80%% duty verified (5000 HIGH / 1250 LOW)");
- end
- end
- // Check 3: Press EPB1 (F8)=1, SB1 (C11)=1, SB2 (A11)=0 and send GET_ALL (A5 5A 02 00 6D 7B)
- estop_btn_in = 1'b1;
- hood_open_btn_in = 1'b1;
- hood_close_btn_in = 1'b0;
- repeat (10) @(posedge clk);
- frame_bytes[0] = 8'hA5;
- frame_bytes[1] = 8'h5A;
- frame_bytes[2] = 8'h02; // GET_ALL
- frame_bytes[3] = 8'd0;
- frame_len = 4;
- $display("Sending GET_ALL via CON12 TTL...");
- rx_count = 0;
- rs232_rx_count = 0;
- uart_send_frame(frame_len);
- // Expect GET_ACK (6 bytes) + GET_DATA (96 bytes: A5 5A 42 5A ... CRC) = 102 bytes total
- while (rx_count < 102) @(posedge clk);
- // Check GET_ACK
- if (rx_bytes[0] !== 8'hA5 || rx_bytes[1] !== 8'h5A ||
- rx_bytes[2] !== 8'h82 || rx_bytes[3] !== 8'h00) begin
- $display("FAIL: GET_ACK incorrect: %02h %02h %02h %02h",
- rx_bytes[0], rx_bytes[1], rx_bytes[2], rx_bytes[3]);
- failures = failures + 1;
- end else begin
- $display("PASS: Received GET_ACK (82 00)");
- end
- // Check GET_DATA header (90 bytes = 0x5A)
- if (rx_bytes[6] !== 8'hA5 || rx_bytes[7] !== 8'h5A ||
- rx_bytes[8] !== 8'h42 || rx_bytes[9] !== 8'd90) begin
- $display("FAIL: GET_DATA header incorrect: %02h %02h %02h %02h",
- rx_bytes[6], rx_bytes[7], rx_bytes[8], rx_bytes[9]);
- failures = failures + 1;
- end else begin
- $display("PASS: Received GET_DATA (42 5A)");
- // Verify PTC duties (offsets 10..33) match 50
- for (i = 0; i < 24; i = i + 1) begin
- if (rx_bytes[10 + i] !== 8'd50) begin
- $display("FAIL: PTC[%0d] = %0d, expected 50", i, rx_bytes[10 + i]);
- failures = failures + 1;
- end
- end
- // Verify Front fan duties (offsets 34..37) match 40
- for (i = 0; i < 4; i = i + 1) begin
- if (rx_bytes[34 + i] !== 8'd40) begin
- $display("FAIL: FrontFan[%0d] = %0d, expected 40", i, rx_bytes[34 + i]);
- failures = failures + 1;
- end
- end
- // Verify Rear fan duties (offsets 38..41) match 60
- for (i = 0; i < 4; i = i + 1) begin
- if (rx_bytes[38 + i] !== 8'd60) begin
- $display("FAIL: RearFan[%0d] = %0d, expected 60", i, rx_bytes[38 + i]);
- failures = failures + 1;
- end
- end
- // Verify CT sensor unwritten channels 9..26 (offsets 66+9..66+26 = 75..92) are 0xFF
- for (i = 9; i < 27; i = i + 1) begin
- if (rx_bytes[66 + i] !== 8'hFF) begin
- $display("FAIL: CT[%0d] (offset %0d) = %02h, expected 0xFF", i, 66 + i, rx_bytes[66 + i]);
- failures = failures + 1;
- end
- end
- // Verify EPB1(86->96), SB1(87->97), SB2(88->98), buzzer(89->99)
- if (rx_bytes[96] !== 8'd1 || rx_bytes[97] !== 8'd1 ||
- rx_bytes[98] !== 8'd0 || rx_bytes[99] !== 8'd1) begin
- $display("FAIL: buttons/buzzer mismatch: epb=%02h sb1=%02h sb2=%02h bz=%02h",
- rx_bytes[96], rx_bytes[97], rx_bytes[98], rx_bytes[99]);
- failures = failures + 1;
- end
- $display("PASS: Verified GET_DATA content (PTC 50%%, Front 40%%, Rear 60%%, CT9..26 0xFF, EPB1=1, SB1=1, SB2=0, buzzer=1)");
- end
- // Verify EPB1=1 caused NO CPLD safety interlock before releasing buttons
- if (ssr1_out !== 1'b1 || ssr2_out !== 1'b0 || ssr4_out !== 1'b1) begin
- $display("FAIL: SSR altered while EPB1=1: %b %b %b", ssr1_out, ssr2_out, ssr4_out);
- failures = failures + 1;
- end else begin
- $display("PASS: SSRs follow 100/0/100 command with no EPB1 interlock");
- end
- estop_btn_in = 1'b0;
- hood_open_btn_in = 1'b0;
- hood_close_btn_in = 1'b0;
- // Check 5: Broadcast verification - RS-232 TX received same GET_ACK/GET_DATA as TTL TX
- if (rs232_rx_count < 102) begin
- $display("FAIL: RS-232 TX did not receive full broadcast reply (%0d < 102)", rs232_rx_count);
- failures = failures + 1;
- end else if (rs232_rx_bytes[0] !== 8'hA5 || rs232_rx_bytes[1] !== 8'h5A ||
- rs232_rx_bytes[2] !== 8'h82) begin
- $display("FAIL: RS-232 TX broadcast mismatch");
- failures = failures + 1;
- end else begin
- $display("PASS: Verified TX broadcast on both CON12 TTL and CON134 RS-232");
- end
- // Check 6: CON134 RS-232 legacy 35B SET_ALL (PTC 70, Front 30, Rear 80; buzzer defaults 0)
- frame_bytes[0] = 8'hA5;
- frame_bytes[1] = 8'h5A;
- frame_bytes[2] = 8'h01; // SET_ALL
- frame_bytes[3] = 8'd35;
- for (i = 0; i < 24; i = i + 1) frame_bytes[4 + i] = 8'd70;
- for (i = 0; i < 4; i = i + 1) frame_bytes[28 + i] = 8'd30;
- for (i = 0; i < 4; i = i + 1) frame_bytes[32 + i] = 8'd80;
- frame_bytes[36] = 100; frame_bytes[37] = 0; frame_bytes[38] = 100;
- frame_len = 39;
- $display("Sending SET_ALL via CON134 RS-232...");
- rx_count = 0;
- rs232_rx_count = 0;
- uart_send_frame_rs232(frame_len);
- while (rs232_rx_count < 6) @(posedge clk);
- if (rs232_rx_bytes[2] !== 8'h81 || rs232_rx_bytes[3] !== 8'h00) begin
- $display("FAIL: CON134 SET_ACK incorrect: %02h %02h", rs232_rx_bytes[2], rs232_rx_bytes[3]);
- failures = failures + 1;
- end else begin
- $display("PASS: Received SET_ACK via CON134 RS-232");
- end
- if (buzzer_out !== 1'b0) begin
- $display("FAIL: buzzer_out not cleared on legacy 35B SET_ALL");
- failures = failures + 1;
- end
- // Check 7: CON134 RS-232 GET_ALL to verify newly applied duties & released buttons=0
- frame_bytes[0] = 8'hA5;
- frame_bytes[1] = 8'h5A;
- frame_bytes[2] = 8'h02; // GET_ALL
- frame_bytes[3] = 8'd0;
- frame_len = 4;
- $display("Sending GET_ALL via CON134 RS-232...");
- rx_count = 0;
- rs232_rx_count = 0;
- uart_send_frame_rs232(frame_len);
- while (rs232_rx_count < 102) @(posedge clk);
- if (rs232_rx_bytes[2] !== 8'h82 || rs232_rx_bytes[8] !== 8'h42 ||
- rs232_rx_bytes[10] !== 8'd70 || rs232_rx_bytes[34] !== 8'd30 ||
- rs232_rx_bytes[38] !== 8'd80 || rs232_rx_bytes[96] !== 8'd0 ||
- rs232_rx_bytes[97] !== 8'd0 || rs232_rx_bytes[98] !== 8'd0 ||
- rs232_rx_bytes[99] !== 8'd0) begin
- $display("FAIL: CON134 GET_DATA values incorrect");
- failures = failures + 1;
- end else begin
- $display("PASS: CON134 GET_DATA confirmed applied duties (PTC 70%%, Front 30%%, Rear 80%%, buttons=0, buzzer=0)");
- end
- // Check 8: Bad CRC on CON134 RS-232 is discarded and does not produce ACK/NACK
- $display("Sending Bad-CRC frame via CON134 RS-232...");
- rx_count = 0;
- rs232_rx_count = 0;
- uart_send_frame_rs232_bad_crc(frame_len);
- repeat (10000) @(posedge clk);
- if (rs232_rx_count != 0) begin
- $display("FAIL: Bad CRC frame produced unexpected reply (%0d bytes)", rs232_rx_count);
- failures = failures + 1;
- end else begin
- $display("PASS: Bad CRC frame safely discarded without reply");
- end
- // Check 9: Bad stop bit on CON12 TTL is discarded and recoverable
- $display("Sending Bad-Stop-Bit byte via CON12 TTL...");
- rx_count = 0;
- uart_send_byte_bad_stop(8'hA5);
- repeat (2000) @(posedge clk);
- if (rx_count != 0) begin
- $display("FAIL: Bad stop bit produced unexpected reply");
- failures = failures + 1;
- end else begin
- $display("PASS: Bad stop bit discarded cleanly");
- end
- // Check 10: Inter-byte timeout recovery (half frame abandoned after timeout)
- $display("Testing Inter-byte timeout recovery on CON12 TTL...");
- uart_send_byte(8'hA5);
- uart_send_byte(8'h5A);
- uart_send_byte(8'h01); // partial header
- // Wait for inter-byte timeout (> 250,000 cycles = 10 ms)
- repeat (260000) @(posedge clk);
- $display(" Inter-byte timeout elapsed; sending valid GET_ALL to verify recovery...");
- rx_count = 0;
- rs232_rx_count = 0;
- frame_bytes[0] = 8'hA5;
- frame_bytes[1] = 8'h5A;
- frame_bytes[2] = 8'h02;
- frame_bytes[3] = 8'd0;
- frame_len = 4;
- uart_send_frame(frame_len);
- while (rx_count < 102) @(posedge clk);
- if (rx_bytes[2] !== 8'h82) begin
- $display("FAIL: Failed to recover after inter-byte timeout");
- failures = failures + 1;
- end else begin
- $display("PASS: Successfully recovered from inter-byte timeout");
- end
- // Check 11: Cross-port switching: CON12 TTL SET_ALL followed by CON134 RS-232 GET_ALL
- $display("Testing Cross-port switching: CON12 TTL SET -> CON134 RS-232 GET...");
- frame_bytes[0] = 8'hA5;
- frame_bytes[1] = 8'h5A;
- frame_bytes[2] = 8'h01;
- frame_bytes[3] = 8'd36;
- for (i = 0; i < 24; i = i + 1) frame_bytes[4 + i] = 8'd25;
- for (i = 0; i < 4; i = i + 1) frame_bytes[28 + i] = 8'd55;
- for (i = 0; i < 4; i = i + 1) frame_bytes[32 + i] = 8'd75;
- frame_bytes[36] = 100; frame_bytes[37] = 0; frame_bytes[38] = 100;
- frame_bytes[39] = 0;
- frame_len = 40;
- rx_count = 0;
- rs232_rx_count = 0;
- uart_send_frame(frame_len); // via CON12 TTL
- while (rx_count < 6) @(posedge clk);
- // Immediate next transaction via CON134 RS-232
- frame_bytes[0] = 8'hA5;
- frame_bytes[1] = 8'h5A;
- frame_bytes[2] = 8'h02;
- frame_bytes[3] = 8'd0;
- frame_len = 4;
- rx_count = 0;
- rs232_rx_count = 0;
- uart_send_frame_rs232(frame_len); // via CON134 RS-232
- while (rs232_rx_count < 102) @(posedge clk);
- if (rs232_rx_bytes[10] !== 8'd25 || rs232_rx_bytes[34] !== 8'd55 || rs232_rx_bytes[38] !== 8'd75) begin
- $display("FAIL: Cross-port switching duty mismatch");
- failures = failures + 1;
- end else begin
- $display("PASS: Cross-port switching verified cleanly (PTC 25%%, Front 55%%, Rear 75%%)");
- end
- #2000;
- if (failures == 0) begin
- $display("prod2u_6400_v2_tb PASS");
- end else begin
- $fatal(1, "prod2u_6400_v2_tb FAIL (%0d errors)", failures);
- end
- $finish;
- end
- initial begin
- #30000000; // 30 ms timeout
- $fatal(1, "prod2u_6400_v2_tb TIMEOUT");
- end
- endmodule
|