|
|
@@ -0,0 +1,463 @@
|
|
|
+`timescale 1ns/1ps
|
|
|
+
|
|
|
+// =============================================================================
|
|
|
+// 1:1 UART High-Baud Clock-Skew, Burst, Framing-Error & Dual-Port Stress TB
|
|
|
+// Verifies host_uart_endpoint at ALL four production baud divisors (25 MHz):
|
|
|
+// - 921600 bps (CLKS_PER_BIT = 27, actual 925926 bps, +0.47%)
|
|
|
+// - 460800 bps (CLKS_PER_BIT = 54)
|
|
|
+// - 230400 bps (CLKS_PER_BIT = 109)
|
|
|
+// - 115200 bps (CLKS_PER_BIT = 217)
|
|
|
+// Under:
|
|
|
+// 1) Nominal baud timing + back-to-back burst frames (0 idle gap between frames)
|
|
|
+// 2) +2.0% faster host clock skew and -2.0% slower host clock skew
|
|
|
+// 3) Framing-error injection (bad stop bit) followed by clean immediate recovery
|
|
|
+// 4) Byte-level 0xA5 RS232 <-> TTL port handoff + idle noise rejection
|
|
|
+// 5) Full-duplex simultaneous TX reply broadcast on both RS232 and TTL
|
|
|
+// =============================================================================
|
|
|
+module uart_921600_skew_tb;
|
|
|
+ reg clk = 1'b0;
|
|
|
+ always #20 clk = ~clk; // 25 MHz (40 ns period)
|
|
|
+
|
|
|
+ integer total_failures = 0;
|
|
|
+
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
+ // Shared CRC-16/CCITT-FALSE reference function
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
+ function [15:0] crc16_step;
|
|
|
+ input [15:0] crc_in;
|
|
|
+ input [7:0] data_byte;
|
|
|
+ integer k;
|
|
|
+ reg [15:0] c;
|
|
|
+ begin
|
|
|
+ c = crc_in ^ {data_byte, 8'h00};
|
|
|
+ for (k = 0; k < 8; k = k + 1) begin
|
|
|
+ if (c[15]) c = {c[14:0], 1'b0} ^ 16'h1021;
|
|
|
+ else c = {c[14:0], 1'b0};
|
|
|
+ end
|
|
|
+ crc16_step = c;
|
|
|
+ end
|
|
|
+ endfunction
|
|
|
+
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
+ // Instantiate 4 endpoints (one per production baud rate)
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
+ reg rst_n = 1'b0;
|
|
|
+
|
|
|
+ // 921600 (div 27)
|
|
|
+ reg rs232_rx_921 = 1'b1, ttl_rx_921 = 1'b1;
|
|
|
+ wire rs232_tx_921, ttl_tx_921;
|
|
|
+ wire req_valid_921; reg req_ready_921 = 1'b0;
|
|
|
+ wire [7:0] req_type_921, req_len_921;
|
|
|
+ wire ram_we_921; wire [7:0] ram_wa_921, ram_wd_921;
|
|
|
+ wire [7:0] ram_ra_921;
|
|
|
+ reg tx_start_921 = 1'b0; reg [7:0] tx_type_921 = 8'd0, tx_len_921 = 8'd0;
|
|
|
+ wire tx_busy_921, tx_done_921;
|
|
|
+ wire [7:0] tx_ra_921;
|
|
|
+ reg [7:0] req_mem_921 [0:127];
|
|
|
+ reg [7:0] tx_mem_921 [0:127];
|
|
|
+ reg [7:0] tx_rd_921 = 8'd0;
|
|
|
+ always @(posedge clk) begin
|
|
|
+ if (ram_we_921 && ram_wa_921 < 8'd128) req_mem_921[ram_wa_921] <= ram_wd_921;
|
|
|
+ tx_rd_921 <= tx_mem_921[tx_ra_921[6:0]];
|
|
|
+ end
|
|
|
+ host_uart_endpoint #(.CLKS_PER_BIT(27), .INTER_BYTE_TIMEOUT_CYCLES(5000)) dut_921 (
|
|
|
+ .clk(clk), .rst_n(rst_n),
|
|
|
+ .rs232_rx(rs232_rx_921), .rs232_tx(rs232_tx_921),
|
|
|
+ .ttl_rx(ttl_rx_921), .ttl_tx(ttl_tx_921),
|
|
|
+ .req_valid(req_valid_921), .req_ready(req_ready_921),
|
|
|
+ .req_type(req_type_921), .req_length(req_len_921),
|
|
|
+ .req_ram_wr_en(ram_we_921), .req_ram_wr_addr(ram_wa_921), .req_ram_wr_data(ram_wd_921),
|
|
|
+ .req_ram_rd_addr(ram_ra_921), .req_ram_rd_data(8'd0),
|
|
|
+ .tx_start(tx_start_921), .tx_type(tx_type_921), .tx_length(tx_len_921),
|
|
|
+ .tx_busy(tx_busy_921), .tx_done(tx_done_921),
|
|
|
+ .tx_ram_rd_addr(tx_ra_921), .tx_ram_rd_data(tx_rd_921)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 460800 (div 54)
|
|
|
+ reg rs232_rx_460 = 1'b1, ttl_rx_460 = 1'b1;
|
|
|
+ wire rs232_tx_460, ttl_tx_460;
|
|
|
+ wire req_valid_460; reg req_ready_460 = 1'b0;
|
|
|
+ wire [7:0] req_type_460, req_len_460;
|
|
|
+ wire ram_we_460; wire [7:0] ram_wa_460, ram_wd_460, ram_ra_460, tx_ra_460;
|
|
|
+ wire tx_busy_460, tx_done_460;
|
|
|
+ host_uart_endpoint #(.CLKS_PER_BIT(54), .INTER_BYTE_TIMEOUT_CYCLES(10000)) dut_460 (
|
|
|
+ .clk(clk), .rst_n(rst_n),
|
|
|
+ .rs232_rx(rs232_rx_460), .rs232_tx(rs232_tx_460),
|
|
|
+ .ttl_rx(ttl_rx_460), .ttl_tx(ttl_tx_460),
|
|
|
+ .req_valid(req_valid_460), .req_ready(req_ready_460),
|
|
|
+ .req_type(req_type_460), .req_length(req_len_460),
|
|
|
+ .req_ram_wr_en(ram_we_460), .req_ram_wr_addr(ram_wa_460), .req_ram_wr_data(ram_wd_460),
|
|
|
+ .req_ram_rd_addr(ram_ra_460), .req_ram_rd_data(8'd0),
|
|
|
+ .tx_start(1'b0), .tx_type(8'd0), .tx_length(8'd0),
|
|
|
+ .tx_busy(tx_busy_460), .tx_done(tx_done_460),
|
|
|
+ .tx_ram_rd_addr(tx_ra_460), .tx_ram_rd_data(8'd0)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 230400 (div 109)
|
|
|
+ reg rs232_rx_230 = 1'b1, ttl_rx_230 = 1'b1;
|
|
|
+ wire rs232_tx_230, ttl_tx_230;
|
|
|
+ wire req_valid_230; reg req_ready_230 = 1'b0;
|
|
|
+ wire [7:0] req_type_230, req_len_230;
|
|
|
+ wire ram_we_230; wire [7:0] ram_wa_230, ram_wd_230, ram_ra_230, tx_ra_230;
|
|
|
+ wire tx_busy_230, tx_done_230;
|
|
|
+ host_uart_endpoint #(.CLKS_PER_BIT(109), .INTER_BYTE_TIMEOUT_CYCLES(20000)) dut_230 (
|
|
|
+ .clk(clk), .rst_n(rst_n),
|
|
|
+ .rs232_rx(rs232_rx_230), .rs232_tx(rs232_tx_230),
|
|
|
+ .ttl_rx(ttl_rx_230), .ttl_tx(ttl_tx_230),
|
|
|
+ .req_valid(req_valid_230), .req_ready(req_ready_230),
|
|
|
+ .req_type(req_type_230), .req_length(req_len_230),
|
|
|
+ .req_ram_wr_en(ram_we_230), .req_ram_wr_addr(ram_wa_230), .req_ram_wr_data(ram_wd_230),
|
|
|
+ .req_ram_rd_addr(ram_ra_230), .req_ram_rd_data(8'd0),
|
|
|
+ .tx_start(1'b0), .tx_type(8'd0), .tx_length(8'd0),
|
|
|
+ .tx_busy(tx_busy_230), .tx_done(tx_done_230),
|
|
|
+ .tx_ram_rd_addr(tx_ra_230), .tx_ram_rd_data(8'd0)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 115200 (div 217)
|
|
|
+ reg rs232_rx_115 = 1'b1, ttl_rx_115 = 1'b1;
|
|
|
+ wire rs232_tx_115, ttl_tx_115;
|
|
|
+ wire req_valid_115; reg req_ready_115 = 1'b0;
|
|
|
+ wire [7:0] req_type_115, req_len_115;
|
|
|
+ wire ram_we_115; wire [7:0] ram_wa_115, ram_wd_115, ram_ra_115, tx_ra_115;
|
|
|
+ wire tx_busy_115, tx_done_115;
|
|
|
+ host_uart_endpoint #(.CLKS_PER_BIT(217), .INTER_BYTE_TIMEOUT_CYCLES(40000)) dut_115 (
|
|
|
+ .clk(clk), .rst_n(rst_n),
|
|
|
+ .rs232_rx(rs232_rx_115), .rs232_tx(rs232_tx_115),
|
|
|
+ .ttl_rx(ttl_rx_115), .ttl_tx(ttl_tx_115),
|
|
|
+ .req_valid(req_valid_115), .req_ready(req_ready_115),
|
|
|
+ .req_type(req_type_115), .req_length(req_len_115),
|
|
|
+ .req_ram_wr_en(ram_we_115), .req_ram_wr_addr(ram_wa_115), .req_ram_wr_data(ram_wd_115),
|
|
|
+ .req_ram_rd_addr(ram_ra_115), .req_ram_rd_data(8'd0),
|
|
|
+ .tx_start(1'b0), .tx_type(8'd0), .tx_length(8'd0),
|
|
|
+ .tx_busy(tx_busy_115), .tx_done(tx_done_115),
|
|
|
+ .tx_ram_rd_addr(tx_ra_115), .tx_ram_rd_data(8'd0)
|
|
|
+ );
|
|
|
+
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
+ // Precise real-time UART byte driver (supports arbitrary baud skew in ns!)
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
+ task automatic send_uart_byte_921;
|
|
|
+ input use_ttl;
|
|
|
+ input [7:0] b;
|
|
|
+ input real bit_ns;
|
|
|
+ input bad_stop;
|
|
|
+ integer bit_i;
|
|
|
+ begin
|
|
|
+ if (use_ttl) ttl_rx_921 = 1'b0; else rs232_rx_921 = 1'b0;
|
|
|
+ #(bit_ns);
|
|
|
+ for (bit_i = 0; bit_i < 8; bit_i = bit_i + 1) begin
|
|
|
+ if (use_ttl) ttl_rx_921 = b[bit_i]; else rs232_rx_921 = b[bit_i];
|
|
|
+ #(bit_ns);
|
|
|
+ end
|
|
|
+ if (use_ttl) ttl_rx_921 = bad_stop ? 1'b0 : 1'b1;
|
|
|
+ else rs232_rx_921 = bad_stop ? 1'b0 : 1'b1;
|
|
|
+ #(bit_ns);
|
|
|
+ if (bad_stop) begin
|
|
|
+ if (use_ttl) ttl_rx_921 = 1'b1; else rs232_rx_921 = 1'b1;
|
|
|
+ #(bit_ns * 2.0);
|
|
|
+ end
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+
|
|
|
+ task automatic send_frame_921;
|
|
|
+ input use_ttl;
|
|
|
+ input [7:0] ftype;
|
|
|
+ input [7:0] flen;
|
|
|
+ input [7:0] seed;
|
|
|
+ input real bit_ns;
|
|
|
+ integer idx;
|
|
|
+ reg [15:0] crc;
|
|
|
+ reg [7:0] val;
|
|
|
+ begin
|
|
|
+ crc = 16'hFFFF;
|
|
|
+ crc = crc16_step(crc, ftype);
|
|
|
+ crc = crc16_step(crc, flen);
|
|
|
+ send_uart_byte_921(use_ttl, 8'hA5, bit_ns, 1'b0);
|
|
|
+ send_uart_byte_921(use_ttl, 8'h5A, bit_ns, 1'b0);
|
|
|
+ send_uart_byte_921(use_ttl, ftype, bit_ns, 1'b0);
|
|
|
+ send_uart_byte_921(use_ttl, flen, bit_ns, 1'b0);
|
|
|
+ for (idx = 0; idx < flen; idx = idx + 1) begin
|
|
|
+ val = seed + idx[7:0];
|
|
|
+ crc = crc16_step(crc, val);
|
|
|
+ send_uart_byte_921(use_ttl, val, bit_ns, 1'b0);
|
|
|
+ end
|
|
|
+ send_uart_byte_921(use_ttl, crc[7:0], bit_ns, 1'b0);
|
|
|
+ send_uart_byte_921(use_ttl, crc[15:8], bit_ns, 1'b0);
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+
|
|
|
+ task automatic send_byte_aux;
|
|
|
+ input integer which; // 0=460, 1=230, 2=115
|
|
|
+ input [7:0] b;
|
|
|
+ input real bit_ns;
|
|
|
+ integer bit_i;
|
|
|
+ begin
|
|
|
+ case (which)
|
|
|
+ 0: rs232_rx_460 = 1'b0;
|
|
|
+ 1: rs232_rx_230 = 1'b0;
|
|
|
+ 2: rs232_rx_115 = 1'b0;
|
|
|
+ endcase
|
|
|
+ #(bit_ns);
|
|
|
+ for (bit_i = 0; bit_i < 8; bit_i = bit_i + 1) begin
|
|
|
+ case (which)
|
|
|
+ 0: rs232_rx_460 = b[bit_i];
|
|
|
+ 1: rs232_rx_230 = b[bit_i];
|
|
|
+ 2: rs232_rx_115 = b[bit_i];
|
|
|
+ endcase
|
|
|
+ #(bit_ns);
|
|
|
+ end
|
|
|
+ case (which)
|
|
|
+ 0: rs232_rx_460 = 1'b1;
|
|
|
+ 1: rs232_rx_230 = 1'b1;
|
|
|
+ 2: rs232_rx_115 = 1'b1;
|
|
|
+ endcase
|
|
|
+ #(bit_ns);
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+
|
|
|
+ task automatic send_ping_aux;
|
|
|
+ input integer which;
|
|
|
+ input real bit_ns;
|
|
|
+ begin
|
|
|
+ // A5 5A 03 00 5C 48 (valid 0B HEARTBEAT)
|
|
|
+ send_byte_aux(which, 8'hA5, bit_ns);
|
|
|
+ send_byte_aux(which, 8'h5A, bit_ns);
|
|
|
+ send_byte_aux(which, 8'h03, bit_ns);
|
|
|
+ send_byte_aux(which, 8'h00, bit_ns);
|
|
|
+ send_byte_aux(which, 8'h5C, bit_ns);
|
|
|
+ send_byte_aux(which, 8'h48, bit_ns);
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+
|
|
|
+ task wait_and_ack_921;
|
|
|
+ input [7:0] exp_type;
|
|
|
+ input [7:0] exp_len;
|
|
|
+ input [7:0] exp_seed;
|
|
|
+ input [8*32-1:0] label;
|
|
|
+ integer guard;
|
|
|
+ integer k;
|
|
|
+ begin
|
|
|
+ guard = 0;
|
|
|
+ while (!req_valid_921 && guard < 20000) begin
|
|
|
+ @(posedge clk);
|
|
|
+ guard = guard + 1;
|
|
|
+ end
|
|
|
+ if (!req_valid_921) begin
|
|
|
+ $display("FAIL %0s: timeout waiting for req_valid_921", label);
|
|
|
+ total_failures = total_failures + 1;
|
|
|
+ end else begin
|
|
|
+ if (req_type_921 !== exp_type || req_len_921 !== exp_len) begin
|
|
|
+ $display("FAIL %0s: type=%02h len=%0d expected %02h/%0d",
|
|
|
+ label, req_type_921, req_len_921, exp_type, exp_len);
|
|
|
+ total_failures = total_failures + 1;
|
|
|
+ end
|
|
|
+ for (k = 0; k < exp_len; k = k + 1) begin
|
|
|
+ if (req_mem_921[k] !== (exp_seed + k[7:0])) begin
|
|
|
+ $display("FAIL %0s: payload[%0d]=%02h expected %02h",
|
|
|
+ label, k, req_mem_921[k], (exp_seed + k[7:0]));
|
|
|
+ total_failures = total_failures + 1;
|
|
|
+ end
|
|
|
+ end
|
|
|
+ @(negedge clk);
|
|
|
+ req_ready_921 = 1'b1;
|
|
|
+ @(posedge clk);
|
|
|
+ @(negedge clk);
|
|
|
+ req_ready_921 = 1'b0;
|
|
|
+ end
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
+ // TX byte-capture monitor for 921600 RS232 & TTL mirror verification
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
+ reg [7:0] rx_cap_rs232 [0:31];
|
|
|
+ reg [7:0] rx_cap_ttl [0:31];
|
|
|
+ integer cap_cnt_rs232 = 0;
|
|
|
+ integer cap_cnt_ttl = 0;
|
|
|
+
|
|
|
+ task automatic capture_tx_byte;
|
|
|
+ input is_ttl;
|
|
|
+ output [7:0] out_b;
|
|
|
+ integer bit_i;
|
|
|
+ real bit_ns;
|
|
|
+ begin
|
|
|
+ bit_ns = 1080.0; // 27 * 40ns = 1080ns exact FPGA TX bit period
|
|
|
+ if (is_ttl) @(negedge ttl_tx_921);
|
|
|
+ else @(negedge rs232_tx_921);
|
|
|
+ #(bit_ns * 1.5);
|
|
|
+ for (bit_i = 0; bit_i < 8; bit_i = bit_i + 1) begin
|
|
|
+ out_b[bit_i] = is_ttl ? ttl_tx_921 : rs232_tx_921;
|
|
|
+ #(bit_ns);
|
|
|
+ end
|
|
|
+ end
|
|
|
+ endtask
|
|
|
+
|
|
|
+ // Nominal 921600 bit period = 1e9 / 921600 = 1085.0694 ns
|
|
|
+ // +2.0% faster host clock = 1085.0694 / 1.02 = 1063.79 ns
|
|
|
+ // -2.0% slower host clock = 1085.0694 * 1.02 = 1106.77 ns
|
|
|
+ real bit_921_nom;
|
|
|
+ real bit_921_fast;
|
|
|
+ real bit_921_slow;
|
|
|
+ integer i, guard;
|
|
|
+ reg [7:0] b_rs, b_tl;
|
|
|
+ reg [15:0] tx_crc;
|
|
|
+
|
|
|
+ initial begin
|
|
|
+ bit_921_nom = 1000000000.0 / 921600.0;
|
|
|
+ bit_921_fast = bit_921_nom / 1.02;
|
|
|
+ bit_921_slow = bit_921_nom * 1.02;
|
|
|
+
|
|
|
+ for (i = 0; i < 128; i = i + 1) begin
|
|
|
+ req_mem_921[i] = 8'd0;
|
|
|
+ tx_mem_921[i] = 8'hA0 + i[7:0];
|
|
|
+ end
|
|
|
+
|
|
|
+ repeat (10) @(posedge clk);
|
|
|
+ rst_n = 1'b1;
|
|
|
+ repeat (10) @(posedge clk);
|
|
|
+
|
|
|
+ // 1. 921600 nominal (real PC 921600 vs FPGA 925926 +0.47%): 36B SET_ALL on RS232
|
|
|
+ fork
|
|
|
+ send_frame_921(1'b0, 8'h01, 8'd36, 8'h10, bit_921_nom);
|
|
|
+ wait_and_ack_921(8'h01, 8'd36, 8'h10, "921600_nom_RS232_36B");
|
|
|
+ join
|
|
|
+
|
|
|
+ // 2. 921600 +2.0% faster host skew: 69B SET_ALL on TTL (immediate RS232->TTL handoff!)
|
|
|
+ fork
|
|
|
+ send_frame_921(1'b1, 8'h01, 8'd69, 8'h20, bit_921_fast);
|
|
|
+ wait_and_ack_921(8'h01, 8'd69, 8'h20, "921600_plus2pct_TTL_69B");
|
|
|
+ join
|
|
|
+
|
|
|
+ // 3. 921600 -2.0% slower host skew: 36B SET_ALL back on RS232 (TTL->RS232 handoff!)
|
|
|
+ fork
|
|
|
+ send_frame_921(1'b0, 8'h01, 8'd36, 8'h40, bit_921_slow);
|
|
|
+ wait_and_ack_921(8'h01, 8'd36, 8'h40, "921600_minus2pct_RS232_36B");
|
|
|
+ join
|
|
|
+
|
|
|
+ // 4. Back-to-back 0-gap burst of 4 frames on 921600 while simultaneously transmitting TX reply!
|
|
|
+ tx_crc = crc16_step(crc16_step(16'hFFFF, 8'h83), 8'd4);
|
|
|
+ tx_crc = crc16_step(crc16_step(crc16_step(crc16_step(tx_crc, 8'hA0), 8'hA1), 8'hA2), 8'hA3);
|
|
|
+ @(negedge clk);
|
|
|
+ tx_type_921 = 8'h83;
|
|
|
+ tx_len_921 = 8'd4;
|
|
|
+ tx_start_921 = 1'b1;
|
|
|
+ @(posedge clk);
|
|
|
+ @(negedge clk);
|
|
|
+ tx_start_921 = 1'b0;
|
|
|
+
|
|
|
+ fork
|
|
|
+ begin
|
|
|
+ send_frame_921(1'b0, 8'h03, 8'd4, 8'h51, bit_921_nom);
|
|
|
+ send_frame_921(1'b0, 8'h02, 8'd0, 8'h00, bit_921_nom);
|
|
|
+ send_frame_921(1'b0, 8'h03, 8'd4, 8'h61, bit_921_nom);
|
|
|
+ send_frame_921(1'b0, 8'h01, 8'd32, 8'h71, bit_921_nom);
|
|
|
+ end
|
|
|
+ begin
|
|
|
+ wait_and_ack_921(8'h03, 8'd4, 8'h51, "921600_burst_0");
|
|
|
+ wait_and_ack_921(8'h02, 8'd0, 8'h00, "921600_burst_1");
|
|
|
+ wait_and_ack_921(8'h03, 8'd4, 8'h61, "921600_burst_2");
|
|
|
+ wait_and_ack_921(8'h01, 8'd32, 8'h71, "921600_burst_3");
|
|
|
+ end
|
|
|
+ begin : cap_rs
|
|
|
+ integer i_rs;
|
|
|
+ for (i_rs = 0; i_rs < 10; i_rs = i_rs + 1) begin
|
|
|
+ capture_tx_byte(1'b0, b_rs);
|
|
|
+ rx_cap_rs232[i_rs] = b_rs;
|
|
|
+ end
|
|
|
+ end
|
|
|
+ begin : cap_tl
|
|
|
+ integer i_tl;
|
|
|
+ for (i_tl = 0; i_tl < 10; i_tl = i_tl + 1) begin
|
|
|
+ capture_tx_byte(1'b1, b_tl);
|
|
|
+ rx_cap_ttl[i_tl] = b_tl;
|
|
|
+ end
|
|
|
+ end
|
|
|
+ join
|
|
|
+
|
|
|
+ // Verify full-duplex mirrored TX frame (A5 5A 83 04 A0 A1 A2 A3 CRC_LO CRC_HI)
|
|
|
+ if (rx_cap_rs232[0] !== 8'hA5 || rx_cap_rs232[1] !== 8'h5A ||
|
|
|
+ rx_cap_rs232[2] !== 8'h83 || rx_cap_rs232[3] !== 8'h04 ||
|
|
|
+ rx_cap_rs232[4] !== 8'hA0 || rx_cap_rs232[7] !== 8'hA3 ||
|
|
|
+ rx_cap_rs232[8] !== tx_crc[7:0] || rx_cap_rs232[9] !== tx_crc[15:8]) begin
|
|
|
+ $display("FAIL 921600_tx_rs232: got %02h %02h %02h %02h ... %02h %02h exp crc %02h %02h",
|
|
|
+ rx_cap_rs232[0], rx_cap_rs232[1], rx_cap_rs232[2], rx_cap_rs232[3],
|
|
|
+ rx_cap_rs232[8], rx_cap_rs232[9], tx_crc[7:0], tx_crc[15:8]);
|
|
|
+ total_failures = total_failures + 1;
|
|
|
+ end
|
|
|
+ for (i = 0; i < 10; i = i + 1) begin
|
|
|
+ if (rx_cap_ttl[i] !== rx_cap_rs232[i]) begin
|
|
|
+ $display("FAIL 921600_tx_mirror[%0d]: ttl=%02h rs232=%02h",
|
|
|
+ i, rx_cap_ttl[i], rx_cap_rs232[i]);
|
|
|
+ total_failures = total_failures + 1;
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ // 5. Framing-error injection mid-frame on RS232 + noise on TTL -> clean recovery on next frame
|
|
|
+ send_uart_byte_921(1'b0, 8'hA5, bit_921_nom, 1'b0);
|
|
|
+ send_uart_byte_921(1'b0, 8'h5A, bit_921_nom, 1'b0);
|
|
|
+ send_uart_byte_921(1'b0, 8'h01, bit_921_nom, 1'b1); // bad stop bit!
|
|
|
+ // Non-A5 garbage on TTL should NOT lock ownership
|
|
|
+ send_uart_byte_921(1'b1, 8'h00, bit_921_nom, 1'b0);
|
|
|
+ send_uart_byte_921(1'b1, 8'hFF, bit_921_nom, 1'b0);
|
|
|
+ #(bit_921_nom * 4.0);
|
|
|
+ if (req_valid_921) begin
|
|
|
+ $display("FAIL framing_err: spurious req_valid after framing error");
|
|
|
+ total_failures = total_failures + 1;
|
|
|
+ end
|
|
|
+ // Immediate clean frame on TTL must succeed without waiting 10 ms!
|
|
|
+ fork
|
|
|
+ send_frame_921(1'b1, 8'h03, 8'd4, 8'h90, bit_921_nom);
|
|
|
+ wait_and_ack_921(8'h03, 8'd4, 8'h90, "921600_post_ferr_TTL_recovery");
|
|
|
+ join
|
|
|
+
|
|
|
+ // 6. Verify 460800 / 230400 / 115200 fallback baud rates at +/-2.0% skew in parallel!
|
|
|
+ fork
|
|
|
+ begin : blk_460
|
|
|
+ integer g460;
|
|
|
+ send_ping_aux(0, (1000000000.0 / 460800.0) * 1.02);
|
|
|
+ g460 = 0; while (!req_valid_460 && g460 < 40000) begin @(posedge clk); g460 = g460 + 1; end
|
|
|
+ if (!req_valid_460 || req_type_460 !== 8'h03) begin
|
|
|
+ $display("FAIL 460800_minus2pct"); total_failures = total_failures + 1;
|
|
|
+ end else begin @(negedge clk); req_ready_460 = 1'b1; @(posedge clk); @(negedge clk); req_ready_460 = 1'b0; end
|
|
|
+ send_ping_aux(0, (1000000000.0 / 460800.0) / 1.02);
|
|
|
+ g460 = 0; while (!req_valid_460 && g460 < 40000) begin @(posedge clk); g460 = g460 + 1; end
|
|
|
+ if (!req_valid_460 || req_type_460 !== 8'h03) begin
|
|
|
+ $display("FAIL 460800_plus2pct"); total_failures = total_failures + 1;
|
|
|
+ end else begin @(negedge clk); req_ready_460 = 1'b1; @(posedge clk); @(negedge clk); req_ready_460 = 1'b0; end
|
|
|
+ end
|
|
|
+ begin : blk_230
|
|
|
+ integer g230;
|
|
|
+ send_ping_aux(1, (1000000000.0 / 230400.0) * 1.02);
|
|
|
+ g230 = 0; while (!req_valid_230 && g230 < 80000) begin @(posedge clk); g230 = g230 + 1; end
|
|
|
+ if (!req_valid_230 || req_type_230 !== 8'h03) begin
|
|
|
+ $display("FAIL 230400_minus2pct"); total_failures = total_failures + 1;
|
|
|
+ end else begin @(negedge clk); req_ready_230 = 1'b1; @(posedge clk); @(negedge clk); req_ready_230 = 1'b0; end
|
|
|
+ send_ping_aux(1, (1000000000.0 / 230400.0) / 1.02);
|
|
|
+ g230 = 0; while (!req_valid_230 && g230 < 80000) begin @(posedge clk); g230 = g230 + 1; end
|
|
|
+ if (!req_valid_230 || req_type_230 !== 8'h03) begin
|
|
|
+ $display("FAIL 230400_plus2pct"); total_failures = total_failures + 1;
|
|
|
+ end else begin @(negedge clk); req_ready_230 = 1'b1; @(posedge clk); @(negedge clk); req_ready_230 = 1'b0; end
|
|
|
+ end
|
|
|
+ begin : blk_115
|
|
|
+ integer g115;
|
|
|
+ send_ping_aux(2, (1000000000.0 / 115200.0) * 1.02);
|
|
|
+ g115 = 0; while (!req_valid_115 && g115 < 160000) begin @(posedge clk); g115 = g115 + 1; end
|
|
|
+ if (!req_valid_115 || req_type_115 !== 8'h03) begin
|
|
|
+ $display("FAIL 115200_minus2pct"); total_failures = total_failures + 1;
|
|
|
+ end else begin @(negedge clk); req_ready_115 = 1'b1; @(posedge clk); @(negedge clk); req_ready_115 = 1'b0; end
|
|
|
+ send_ping_aux(2, (1000000000.0 / 115200.0) / 1.02);
|
|
|
+ g115 = 0; while (!req_valid_115 && g115 < 160000) begin @(posedge clk); g115 = g115 + 1; end
|
|
|
+ if (!req_valid_115 || req_type_115 !== 8'h03) begin
|
|
|
+ $display("FAIL 115200_plus2pct"); total_failures = total_failures + 1;
|
|
|
+ end else begin @(negedge clk); req_ready_115 = 1'b1; @(posedge clk); @(negedge clk); req_ready_115 = 1'b0; end
|
|
|
+ end
|
|
|
+ join
|
|
|
+
|
|
|
+ if (total_failures == 0) begin
|
|
|
+ $display("uart_921600_skew_tb PASS: 921600/460800/230400/115200 +/-2%% skew, burst, framing-error recovery, and RS232<->TTL handoff verified");
|
|
|
+ end else begin
|
|
|
+ $fatal(1, "uart_921600_skew_tb FAIL (%0d errors)", total_failures);
|
|
|
+ end
|
|
|
+ $finish;
|
|
|
+ end
|
|
|
+endmodule
|