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.

crc_gen.sv 2.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 [7:0] a_in, // Number of valid bits on input
  11. input [7:0] k_in, // Number of valid bits on output
  12. input [DATA_WIDTH - 1 : 0] data_i, // Input Information bit
  13. output reg [CRC_SIZE - 1 : 0] crc_o // output CRC of information Input
  14. );
  15. logic [CRC_SIZE - 1 : 0] crc = 0;
  16. logic [CRC_SIZE - 1 : 0] crc_next;
  17. logic [CRC_SIZE - 1 : 0] crc_prev;
  18. reg [24:0] POLY = 'h1B2B117;
  19. reg [DATA_WIDTH-1:0]valid_data;
  20. reg [7:0]valid_count = 0;
  21. always_ff @( posedge clk_i )
  22. if( !rst_n )begin
  23. crc_o <= INIT[CRC_SIZE - 1 : 0];
  24. valid_data <= 'b0;
  25. end
  26. else
  27. begin
  28. // crc_o <= crc_prev;
  29. for(valid_count = 0; valid_count < 140; valid_count = valid_count + 1)
  30. if(valid_count <= a_in)
  31. valid_data[valid_count] = data_i[valid_count];//;data_i[1*a_in +: 1];
  32. else
  33. valid_data[valid_count] = 1'b0;
  34. crc_o <= crc_prev;
  35. end
  36. generate
  37. always_comb
  38. begin
  39. crc_next = crc;
  40. crc_prev = crc;
  41. for( int i = 0; i < DATA_WIDTH; i ++ )
  42. begin
  43. $display("Inside for Loop");
  44. crc_next[0] = crc_prev[CRC_SIZE - 1] ^ valid_data[DATA_WIDTH - 1 - i];
  45. $display("crc_next[%d] = %b",i,crc_next[i]);
  46. for( int j = 1; j < CRC_SIZE; j++ )
  47. if( POLY[j] )
  48. crc_next[j] = crc_prev[j - 1] ^ crc_prev[CRC_SIZE - 1] ^ valid_data[DATA_WIDTH - 1 - i];
  49. else
  50. crc_next[j] = crc_prev[j - 1];
  51. crc_prev = crc_next;
  52. end
  53. end
  54. endgenerate
  55. endmodule