I try to create a CRC module on Verilog.
The CRC calculating use an LFSR and can be fully-sequential (with two cycles), semi-sequential (with one cycle) or parallel. I have already made sequential module. And I try to create a fully-parallel. There is some code-generators for fixed methods (like "CRC-16 modbus" or "CRC-32 Ethernet"). But I want to create an universal parametrizade parallel module.
With for-loop expression I create a prametrized LFSR.
module main
#(
parameter LFSR_SIZE = 16,
parameter START_VALUE = 'hFFFF,
parameter POLYNOME = 'h8005)
(
input clk,
input n_reset,
output reg [LFSR_SIZE-1:0]lfsr);
integer lfsr_index;
always @(posedge clk) begin
if(n_reset) begin
lfsr[0] <= lfsr[LFSR_SIZE - 1];
for(lfsr_index = 1; lfsr_index < LFSR_SIZE; lfsr_index = lfsr_index + 1) begin
if( ((1 << lfsr_index) & POLYNOME) == 0) begin
lfsr[lfsr_index] <= lfsr[lfsr_index - 1];
end
else begin
lfsr[lfsr_index] <= lfsr[lfsr_index - 1] ^ lfsr[LFSR_SIZE - 1];
end
end
end
else begin
lfsr <= START_VALUE;
end
end
endmodule
Is it possible to generate number of shifts of the LFSR with a nested loop (two loops, one inside other)? If answer is "no" does the nested loop usefull expression in some case?