OpenCores
URL https://opencores.org/ocsvn/scalable_arbiter/scalable_arbiter/trunk

Subversion Repositories scalable_arbiter

[/] [scalable_arbiter/] [trunk/] [rtl/] [verilog/] [lfsr.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 kendallc
/*
2
 * Copyright (c) 2009, Kendall Correll
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
 
17
`timescale 1ns / 1ps
18
 
19
module lfsr #(
20
        parameter width = 0,
21
        parameter reset_value = {width{1'b1}}
22
)(
23
        input enable,
24
        input load,
25
        input in,
26
        output reg [width-1:0] out,
27
 
28
        input clock,
29
        input reset
30
);
31
 
32
// it's assumed that the msb is a tap so it need not be in this table,
33
// indexes are 0-based, you can add cases for any other widths
34
function is_tap (
35
        input integer width, index
36
);
37
begin
38
        case(width)
39
        3:   is_tap = index == 1;
40
        4:   is_tap = index == 2;
41
        5:   is_tap = index == 2;
42
        6:   is_tap = index == 4;
43
        7:   is_tap = index == 5;
44
        8:   is_tap = index == 5   || index == 4   || index == 3;
45
        15:  is_tap = index == 13;
46
        16:  is_tap = index == 14  || index == 12  || index == 3;
47
        31:  is_tap = index == 27;
48
        32:  is_tap = index == 21  || index == 1   || index == 0;
49
        63:  is_tap = index == 61;
50
        64:  is_tap = index == 62  || index == 60  || index == 59;
51
        127: is_tap = index == 125;
52
        128: is_tap = index == 125 || index == 100 || index == 98;
53
        default: is_tap = 0;
54
        endcase
55
end
56
endfunction
57
 
58
// combine the taps to compute the next lsb
59
function [0:0] feedback (
60
        input [width-1:0] value
61
);
62
integer i;
63
begin
64
        // always include the msb
65
        feedback = value[width-1];
66
 
67
        // include the other taps specified by the table
68
        for(i = 0; i < width - 1; i = i + 1)
69
        begin
70
                if(is_tap(width, i))
71
                        feedback = feedback ^ value[i];
72
        end
73
end
74
endfunction
75
 
76
// the shift register
77
always @(posedge clock, posedge reset)
78
begin
79
        if(reset)
80
                out <= reset_value;
81
        else
82
        begin
83
                if(enable)
84
                        out <= {out[width-2:0], load ? in : feedback(out)};
85
        end
86
end
87
 
88
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.