Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

encoder_crc_attachment_rtl.sv 5.0 KiB

3 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company: BITSILICA PRIVATE LIMITED
  4. // Design Name: ENCODER CRC ATTACHMENT
  5. // Module Name: encoder_crc_attachment_rtl
  6. // Project Name: POLAR ENCODER-DECODER
  7. // Target Devices: Zynq UltraScale+ ZCU111 Evaluation Platform (xczu28dr-ffvg1517-2-e)
  8. // Tool Versions: VIVADO 2020.1
  9. // Description: RTL code for calculation and attachment of CRC to a given message, according to selected polynomial.
  10. //
  11. //~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~//
  12. // If the CRC width i.e., P = X, //
  13. // it means that we are going to use a X degree polynomial of length X+1 bits, //
  14. // the crc_out is of X bits. //
  15. // CRC POLYNOMIALS used in Polar IP //
  16. // CRC6 =0x21 == 010_0001 //
  17. // CRC11 =0x621 == 0110_0010_0001 //
  18. // CRC16 =0x1021 == 0_0001_0000_0010_0001 //
  19. // CRC24C =0xB2B117 == 0_1011_0010_1011_0001_0001_0111 //
  20. //~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~^~~~~~//
  21. //
  22. // encoder_crc_attachment_rtl is written to calculate and attach CRC for a given message input.
  23. //
  24. //////////////////////////////////////////////////////////////////////////////////
  25. module encoder_crc_attachment_rtl
  26. #(
  27. parameter PUCCH = 0, // Uplink Channel enable
  28. parameter PBCH = 0, // Broadcast Channel enable
  29. parameter N = 512,
  30. parameter A = 140, // Message width A if no segmentation needed, A'=A/2 if segmentation is needed.
  31. parameter P=24,
  32. parameter K = A+P // Message width after CRC is appended
  33. )
  34. (
  35. input wire clock_i, // System clock
  36. input wire reset_ni, // System reset,active low synchronous
  37. input wire [A-1:0] msg_i, // Input message bits
  38. output reg [K-1:0] msg_o // total message = message input + CRC bits
  39. );
  40. integer i; // looping variable
  41. wire [P:0] polynomial; // polynomial using which CRC needs to be calculated
  42. reg [K-1:0] polynomial_1='d0; // polynomial_1 is to store the right shifted polynomial in each step
  43. reg [K-1:0] msg_1='d0; // msg_1 is to hold the modified message in between the XOR operations
  44. reg [P-1:0] crc_out='d0; // Calculated CRC output for given msg_i
  45. reg [K-1:0] msg_2; // msg_2 is to hold the output msg after msg_i is appended with crc_out
  46. generate
  47. if (P == 'd6) //CRC-6
  48. assign polynomial = 'h21;
  49. else if (P == 'd11) //CRC-11
  50. assign polynomial = 'h621;
  51. else if (P == 'd24) //CRC-24C
  52. assign polynomial = 'h1d11a9b;
  53. else //CRC-16
  54. assign polynomial = 'h1021;
  55. endgenerate
  56. // Procedural block to calculate CRC for input message bits.
  57. always@(*) begin
  58. polynomial_1 = { {(A-1){1'b0}}, polynomial[P:0] }; // initialization of polynomial_1
  59. msg_1 = { {P{1'b0}}, msg_i[A-1:0] }; // initialization of msg_1
  60. for (i = 0; i < A; i = i+1) begin // calculating CRC and storing in temporary internal register(A number of times)
  61. msg_1 = ( msg_1[i] )? ( msg_1 ^ polynomial_1 ) : ( msg_1 ^ {K{1'b0}} ); // exor with polynomial if message bit is 1, else exor with 0's.
  62. polynomial_1 = polynomial_1 << 1'b1; // left shifting the polynomial for each message bit
  63. end
  64. crc_out = msg_1[K-1 : A]; // assigning the internal register to CRC output
  65. msg_2 = { crc_out[P-1 : 0], msg_i[A-1 : 0] }; // the final message output
  66. end
  67. // instantiating a register(group of FF's) to hold the output and synchronize the module w.r.t clock and reset signals
  68. register #(
  69. .WIDTH(K), // overriding the width of register with the length of output to be registered
  70. .SR(2'b01), // overriding SR inputs of the register
  71. .RST_VAL({N{1'b0}}) // overriding the reset value with expected value in the output when reset is applied
  72. ) REG (
  73. .clk(clock_i), // connecting clock ports
  74. .rstb(reset_ni), // connecting reset ports
  75. .din(msg_2), // connecting input of register with the value that needs to be registered
  76. .dout(msg_o) // connecting the registered output with the output port of current module
  77. );
  78. endmodule