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];
The operation you're looking for for a non-reflected CRC with truncated polynomial
0x07is the following, wherecis the exclusive-or of the previous CRC value and the data byte, andcp("c prime"), is the next CRC value: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 thea[7]in that step (that represents the polynomial0x07, which has the low three bits set). Repeat eight times, and you get the expressions above.