You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

  1. `timescale 1ns / 1ps
  2. module crc_gen #(
  3. parameter int CRC_SIZE = 24,
  4. parameter int DATA_WIDTH = 140,
  5. parameter bit [63 : 0] INIT = 'h0
  6. )(
  7. input clk_i,
  8. input rst_n,
  9. input [24:0] POLY,
  10. input [DATA_WIDTH - 1 : 0] data_i, // Input Information bit
  11. output reg [CRC_SIZE - 1 : 0] crc_o // output CRC of information Input
  12. );
  13. logic [CRC_SIZE - 1 : 0] crc = 0;
  14. logic [CRC_SIZE - 1 : 0] crc_next;
  15. logic [CRC_SIZE - 1 : 0] crc_prev;
  16. always_ff @( posedge clk_i )
  17. if( !rst_n )
  18. crc_o <= INIT[CRC_SIZE - 1 : 0];
  19. else
  20. begin
  21. crc_o <= crc_prev;
  22. end
  23. generate
  24. always_comb
  25. begin
  26. crc_next = crc;
  27. crc_prev = crc;
  28. for( int i = 0; i < DATA_WIDTH; i ++ )
  29. begin
  30. crc_next[0] = crc_prev[CRC_SIZE - 1] ^ data_i[DATA_WIDTH - 1 - i];
  31. for( int j = 1; j < CRC_SIZE; j++ )
  32. if( POLY[j] )
  33. crc_next[j] = crc_prev[j - 1] ^ crc_prev[CRC_SIZE - 1] ^ data_i[DATA_WIDTH - 1 - i];
  34. else
  35. crc_next[j] = crc_prev[j - 1];
  36. crc_prev = crc_next;
  37. end
  38. end
  39. endgenerate
  40. endmodule