Parallel CRC polynomial

87 views Asked by At

I want to write a parallel CRC for the CRC_8_ATM polynomial. I found this code for polynomial = 0x1021 but I do not understand the XORs positions and why they are like this so that I can change it to my desired polynomial

assign crc_out = crc_reg;
// CRC Control logic
always @ (posedge clk)
if (reset) begin
  crc_reg <= 16'hFFFF;
end else if (enable) begin
  if (init) begin
     crc_reg <= 16'hFFFF;
  end else begin
     crc_reg <= next_crc;
  end
end
// I do not understand this part
assign next_crc[0] = data_in[7] ^ data_in[0] ^ crc_reg[4] ^ crc_reg[11];
assign next_crc[1] = data_in[1] ^ crc_reg[5];
assign next_crc[2] = data_in[2] ^ crc_reg[6];
assign next_crc[3] = data_in[3] ^ crc_reg[7];
assign next_crc[4] = data_in[4] ^ crc_reg[8];
assign next_crc[5] = data_in[7] ^ data_in[5] ^ data_in[0] ^ crc_reg[4] ^ crc_reg[9] ^ crc_reg[11];
assign next_crc[6] = data_in[6] ^ data_in[1] ^ crc_reg[5] ^ crc_reg[10];
assign next_crc[7] = data_in[7] ^ data_in[2] ^ crc_reg[6] ^ crc_reg[11];
assign next_crc[8] = data_in[3] ^ crc_reg[0] ^ crc_reg[7];
assign next_crc[9] = data_in[4] ^ crc_reg[1] ^ crc_reg[8];
assign next_crc[10] = data_in[5] ^ crc_reg[2] ^ crc_reg[9];
assign next_crc[11] = data_in[6] ^ crc_reg[3] ^ crc_reg[10];

1

There are 1 answers

0
Mark Adler On

The operation you're looking for for a non-reflected CRC with truncated polynomial 0x07 is the following, where c is the exclusive-or of the previous CRC value and the data byte, and cp ("c prime"), is the next CRC value:

assign cp[0] = c[0] ^ c[6] ^ c[7];
assign cp[1] = c[0] ^ c[1] ^ c[6];
assign cp[2] = c[0] ^ c[1] ^ c[2] ^ c[6];
assign cp[3] = c[1] ^ c[2] ^ c[3] ^ c[7];
assign cp[4] = c[2] ^ c[3] ^ c[4];
assign cp[5] = c[3] ^ c[4] ^ c[5];
assign cp[6] = c[4] ^ c[5] ^ c[6];
assign cp[7] = c[5] ^ c[6] ^ c[7];

This is computed by taking the eight bits at each step, a[0]..a[7] symbolically, shifting them up one bit, and exclusive-oring the low three bits with the a[7] in that step (that represents the polynomial 0x07, which has the low three bits set). Repeat eight times, and you get the expressions above.