`timescale 1ns/1ps module crc16_serial_tb; reg clk = 1'b0; reg rst_n = 1'b0; reg start = 1'b0; reg data_valid = 1'b0; reg [7:0] data = 8'd0; wire busy; wire data_done; wire [15:0] crc; always #1 clk = ~clk; crc16_serial dut ( .clk(clk), .rst_n(rst_n), .start(start), .data_valid(data_valid), .data(data), .busy(busy), .data_done(data_done), .crc(crc) ); task feed; input [7:0] value; begin while (busy) @(posedge clk); data = value; data_valid = 1'b1; @(posedge clk); data_valid = 1'b0; while (!data_done) @(posedge clk); end endtask initial begin repeat (3) @(posedge clk); rst_n = 1'b1; start = 1'b1; @(posedge clk); start = 1'b0; feed(8'h02); feed(8'h00); if (crc !== 16'h7B6D) $fatal(1, "CRC mismatch: %h", crc); $display("crc16_serial_tb PASS"); $finish; end endmodule