// crc_serial.sv // Bit-serial CRC: one message bit per clock, MSB first, no reflection. // This is the shift-register form that crc.sv unrolls eight times. // Defaults: CRC-16/IBM-3740 (CRC-16/CCITT-FALSE), check 0x29B1. `timescale 1ns/1ps module crc_serial #( parameter int W = 16, parameter logic [W-1:0] POLY = 16'h1021, parameter logic [W-1:0] INIT = 16'hFFFF ) ( input logic clk, input logic rst, // synchronous, active high input logic start, // load INIT input logic bit_valid, input logic bit_in, output logic [W-1:0] crc_out ); logic fb; assign fb = crc_out[W-1] ^ bit_in; always_ff @(posedge clk) begin if (rst || start) begin crc_out <= INIT; end else if (bit_valid) begin crc_out <= fb ? ((crc_out << 1) ^ POLY) : (crc_out << 1); end end endmodule