2018-08-13 22:17:36 +00:00
|
|
|
|
2018-02-15 18:31:32 +00:00
|
|
|
`ifndef LFSR_V
|
|
|
|
`define LFSR_V
|
2017-11-15 00:12:52 +00:00
|
|
|
|
2018-10-01 16:30:47 +00:00
|
|
|
/*
|
|
|
|
Configurable Linear Feedback Shift Register.
|
|
|
|
*/
|
|
|
|
|
2018-07-31 18:41:27 +00:00
|
|
|
module LFSR(clk, reset, enable, lfsr);
|
2018-02-14 01:04:52 +00:00
|
|
|
|
2018-07-31 18:41:27 +00:00
|
|
|
parameter TAPS = 8'b11101; // bitmask for taps
|
|
|
|
parameter INVERT = 0; // invert feedback bit?
|
|
|
|
localparam NBITS = $size(TAPS); // bit width (derived from TAPS)
|
2018-02-14 01:04:52 +00:00
|
|
|
|
|
|
|
input clk, reset;
|
2018-07-31 18:41:27 +00:00
|
|
|
input enable; // only perform shift when enable=1
|
|
|
|
output reg [NBITS-1:0] lfsr; // shift register
|
2018-02-14 01:04:52 +00:00
|
|
|
|
|
|
|
wire feedback = lfsr[NBITS-1] ^ INVERT;
|
|
|
|
|
|
|
|
always @(posedge clk)
|
|
|
|
begin
|
2018-07-15 04:29:27 +00:00
|
|
|
if (reset)
|
2018-09-08 13:59:21 +00:00
|
|
|
lfsr <= {lfsr[NBITS-2:0], 1'b1}; // reset loads with all 1s
|
2018-02-14 01:04:52 +00:00
|
|
|
else if (enable)
|
|
|
|
lfsr <= {lfsr[NBITS-2:0], 1'b0} ^ (feedback ? TAPS : 0);
|
|
|
|
end
|
|
|
|
|
2018-02-15 18:31:32 +00:00
|
|
|
endmodule
|
2017-11-15 00:12:52 +00:00
|
|
|
|
2018-02-15 18:31:32 +00:00
|
|
|
`endif
|