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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [boards/] [xilinx/] [atlys/] [rtl/] [verilog/] [lfsr/] [lfsr.v] - Blame information for rev 627

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 627 stekern
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Linear feedback shift register with Wishbone interface       ////
4
////                                                              ////
5
//// Description                                                  ////
6
//// Simple LFSR module (feedback hardcoded)                      ////
7
//// Two accessible registers:                                    ////
8
//// Address 0: LFSR Register (R/W)                               ////
9
//// Address 4: Control register, active high, self resetting (WO)////
10
////            Bit[0]: lfsr shift enable                         ////
11
////            Bit[1]: lfsr reset                                ////
12
////                                                              ////
13
////  To Do:                                                      ////
14
////        Perhaps make feedback parameterisable                 ////
15
////                                                              ////
16
////  Author(s):                                                  ////
17
////      - Julius Baxter, julius.baxter@orsoc.se                 ////
18
////                                                              ////
19
////                                                              ////
20
//////////////////////////////////////////////////////////////////////
21
////                                                              ////
22
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
23
////                                                              ////
24
//// This source file may be used and distributed without         ////
25
//// restriction provided that this copyright statement is not    ////
26
//// removed from the file and that any derivative work contains  ////
27
//// the original copyright notice and the associated disclaimer. ////
28
////                                                              ////
29
//// This source file is free software; you can redistribute it   ////
30
//// and/or modify it under the terms of the GNU Lesser General   ////
31
//// Public License as published by the Free Software Foundation; ////
32
//// either version 2.1 of the License, or (at your option) any   ////
33
//// later version.                                               ////
34
////                                                              ////
35
//// This source is distributed in the hope that it will be       ////
36
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
37
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
38
//// PURPOSE.  See the GNU Lesser General Public License for more ////
39
//// details.                                                     ////
40
////                                                              ////
41
//// You should have received a copy of the GNU Lesser General    ////
42
//// Public License along with this source; if not, download it   ////
43
//// from http://www.opencores.org/lgpl.shtml                     ////
44
////                                                              ////
45
//////////////////////////////////////////////////////////////////////
46
module wb_lfsr( wb_clk, wb_rst, wb_adr_i, wb_dat_i, wb_cyc_i, wb_stb_i, wb_we_i,
47
                wb_dat_o, wb_ack_o);
48
 
49
   parameter width = 32;
50
   parameter lfsr_rst_value = 32'b0011_0001_0000_1010;
51
 
52
   input wb_clk;
53
   input wb_rst;
54
   input [2:0] wb_adr_i;
55
   input [width-1:0] wb_dat_i;
56
   input             wb_cyc_i, wb_stb_i, wb_we_i;
57
 
58
   output [width-1:0] wb_dat_o;
59
   output reg         wb_ack_o;
60
 
61
   wire               wb_req;
62
   assign wb_req = wb_stb_i & wb_cyc_i;
63
 
64
   reg [width-1:0]    lfsr;
65
   wire                   lfsr_feedback;
66
 
67
   assign wb_dat_o = lfsr;
68
 
69
   // Only 2 registers here, the lfsr itself and 
70
   wire                   lfsr_sel;
71
   assign lfsr_sel = !wb_adr_i[2];
72
   wire                   lfsr_control_reg_sel;
73
   assign lfsr_control_reg_sel = wb_adr_i[2];
74
 
75
   // [0]: shift enable, [1]: reset
76
   reg [1:0]               lfsr_control_reg;
77
   wire                   lfsr_control_enable;
78
   wire                   lfsr_control_rst;
79
 
80
   // Load the control reg when required, 
81
   always @(posedge wb_clk)
82
     begin
83
        if (wb_rst)
84
          lfsr_control_reg <= 0;
85
        else if (wb_req & wb_we_i & lfsr_control_reg_sel & wb_ack_o)
86
          lfsr_control_reg <= wb_dat_i;
87
 
88
        if (lfsr_control_reg[0])
89
          lfsr_control_reg[0] <= 0;
90
        if (lfsr_control_reg[1])
91
          lfsr_control_reg[1] <= 0;
92
     end // always @ (posedge wb_clk)
93
 
94
   assign lfsr_control_enable = lfsr_control_reg[0];
95
   assign lfsr_control_rst = lfsr_control_reg[1];
96
 
97
   assign lfsr_feedback = !(((lfsr[27] ^ lfsr[13]) ^ lfsr[8]) ^ lfsr[5]);
98
 
99
   always @(posedge wb_clk)
100
     if (wb_rst)
101
       lfsr <= lfsr_rst_value;
102
     else if (lfsr_control_rst)
103
       lfsr <= lfsr_rst_value;
104
     else if (wb_req & wb_we_i & lfsr_sel & wb_ack_o) // Set lfsr
105
       lfsr <= wb_dat_i;
106
     else if (lfsr_control_enable)
107
       lfsr <= {lfsr[width-2:0], lfsr_feedback};
108
 
109
   always @(posedge wb_clk)
110
     if (wb_rst)
111
       wb_ack_o <= 0;
112
     else if (wb_req & !wb_ack_o)
113
       wb_ack_o <= 1;
114
     else if (wb_ack_o)
115
       wb_ack_o <= 0;
116
 
117
 
118
endmodule // lfsr

powered by: WebSVN 2.1.0

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