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

Subversion Repositories systemc_rng

[/] [systemc_rng/] [trunk/] [rtl/] [verilog/] [rng.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 jcastillo
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Random Number Generator                                     ////
4
////                                                              ////
5
////  This file is part of the SystemC RNG                        ////
6
////                                                              ////
7
////  Description:                                                ////
8
////                                                              ////
9
////  Implementation of random number generator                   ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////   - done                                                     ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15 11 jcastillo
////      - Javier Castillo, javier.castillo@urjc.es              ////
16 7 jcastillo
////                                                              ////
17 11 jcastillo
////  This core is provided by Universidad Rey Juan Carlos        ////
18
////  http://www.escet.urjc.es/~jmartine                          ////
19
////                                                              ////
20 7 jcastillo
//////////////////////////////////////////////////////////////////////
21
////                                                              ////
22
//// Copyright (C) 2000 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
//
47
// CVS Revision History
48
//
49
// $Log: not supported by cvs2svn $
50 11 jcastillo
// Revision 1.3  2005/07/30 20:07:26  jcastillo
51
// Correct bit 28. Correct assignation to bit 31
52
//
53 10 jcastillo
// Revision 1.2  2005/07/29 09:13:06  jcastillo
54
// Correct bit 28 of CASR
55
//
56 9 jcastillo
// Revision 1.1  2004/09/23 09:43:06  jcastillo
57
// Verilog first import
58
//
59 7 jcastillo
 
60
`timescale 10ns/1ns
61
 
62
module rng(clk,reset,loadseed_i,seed_i,number_o);
63
input clk;
64
input reset;
65
input loadseed_i;
66
input [31:0] seed_i;
67
output [31:0] number_o;
68
 
69
reg [31:0] number_o;
70
 
71
reg [42:0] LFSR_reg;
72
reg [36:0] CASR_reg;
73
 
74
 
75
//CASR:
76
reg[36:0] CASR_varCASR,CASR_outCASR;
77
always @(posedge clk or negedge reset)
78
 
79
   begin
80
 
81
 
82
 
83
 
84
   if (!reset )
85
 
86
      begin
87
 
88
      CASR_reg  = (1);
89
 
90
      end
91
 
92
   else
93
 
94
      begin
95
 
96
      if (loadseed_i )
97
 
98
         begin
99
 
100 10 jcastillo
         CASR_varCASR [36:32]=0;
101 7 jcastillo
         CASR_varCASR [31:0]=seed_i ;
102
         CASR_reg  = (CASR_varCASR );
103
 
104
 
105
         end
106
 
107
      else
108
 
109
         begin
110
 
111
         CASR_varCASR =CASR_reg ;
112
 
113
         CASR_outCASR [36]=CASR_varCASR [35]^CASR_varCASR [0];
114
         CASR_outCASR [35]=CASR_varCASR [34]^CASR_varCASR [36];
115
         CASR_outCASR [34]=CASR_varCASR [33]^CASR_varCASR [35];
116
         CASR_outCASR [33]=CASR_varCASR [32]^CASR_varCASR [34];
117
         CASR_outCASR [32]=CASR_varCASR [31]^CASR_varCASR [33];
118
         CASR_outCASR [31]=CASR_varCASR [30]^CASR_varCASR [32];
119
         CASR_outCASR [30]=CASR_varCASR [29]^CASR_varCASR [31];
120
         CASR_outCASR [29]=CASR_varCASR [28]^CASR_varCASR [30];
121 10 jcastillo
         CASR_outCASR [28]=CASR_varCASR [27]^CASR_varCASR [29];
122
         CASR_outCASR [27]=CASR_varCASR [26]^CASR_varCASR [27]^CASR_varCASR [28];
123 7 jcastillo
         CASR_outCASR [26]=CASR_varCASR [25]^CASR_varCASR [27];
124
         CASR_outCASR [25]=CASR_varCASR [24]^CASR_varCASR [26];
125
         CASR_outCASR [24]=CASR_varCASR [23]^CASR_varCASR [25];
126
         CASR_outCASR [23]=CASR_varCASR [22]^CASR_varCASR [24];
127
         CASR_outCASR [22]=CASR_varCASR [21]^CASR_varCASR [23];
128
         CASR_outCASR [21]=CASR_varCASR [20]^CASR_varCASR [22];
129
         CASR_outCASR [20]=CASR_varCASR [19]^CASR_varCASR [21];
130
         CASR_outCASR [19]=CASR_varCASR [18]^CASR_varCASR [20];
131
         CASR_outCASR [18]=CASR_varCASR [17]^CASR_varCASR [19];
132
         CASR_outCASR [17]=CASR_varCASR [16]^CASR_varCASR [18];
133
         CASR_outCASR [16]=CASR_varCASR [15]^CASR_varCASR [17];
134
         CASR_outCASR [15]=CASR_varCASR [14]^CASR_varCASR [16];
135
         CASR_outCASR [14]=CASR_varCASR [13]^CASR_varCASR [15];
136
         CASR_outCASR [13]=CASR_varCASR [12]^CASR_varCASR [14];
137
         CASR_outCASR [12]=CASR_varCASR [11]^CASR_varCASR [13];
138
         CASR_outCASR [11]=CASR_varCASR [10]^CASR_varCASR [12];
139
         CASR_outCASR [10]=CASR_varCASR [9]^CASR_varCASR [11];
140
         CASR_outCASR [9]=CASR_varCASR [8]^CASR_varCASR [10];
141
         CASR_outCASR [8]=CASR_varCASR [7]^CASR_varCASR [9];
142
         CASR_outCASR [7]=CASR_varCASR [6]^CASR_varCASR [8];
143
         CASR_outCASR [6]=CASR_varCASR [5]^CASR_varCASR [7];
144
         CASR_outCASR [5]=CASR_varCASR [4]^CASR_varCASR [6];
145
         CASR_outCASR [4]=CASR_varCASR [3]^CASR_varCASR [5];
146
         CASR_outCASR [3]=CASR_varCASR [2]^CASR_varCASR [4];
147
         CASR_outCASR [2]=CASR_varCASR [1]^CASR_varCASR [3];
148
         CASR_outCASR [1]=CASR_varCASR [0]^CASR_varCASR [2];
149
         CASR_outCASR [0]=CASR_varCASR [36]^CASR_varCASR [1];
150
 
151
         CASR_reg  = (CASR_outCASR );
152
 
153
         end
154
 
155
 
156
      end
157
 
158
 
159
   end
160
//LFSR:
161
reg[42:0] LFSR_varLFSR;
162
reg outbitLFSR;
163
always @(posedge clk or negedge reset)
164
 
165
   begin
166
 
167
 
168
   if (!reset )
169
 
170
      begin
171
 
172
      LFSR_reg  = (1);
173
 
174
      end
175
 
176
   else
177
 
178
      begin
179
 
180
      if (loadseed_i )
181
 
182
         begin
183
 
184 10 jcastillo
         LFSR_varLFSR [42:32]=0;
185 7 jcastillo
         LFSR_varLFSR [31:0]=seed_i ;
186
         LFSR_reg  = (LFSR_varLFSR );
187
 
188
 
189
         end
190
 
191
      else
192
 
193
         begin
194
 
195
         LFSR_varLFSR =LFSR_reg ;
196
 
197
         outbitLFSR =LFSR_varLFSR [42];
198
         LFSR_varLFSR [42]=LFSR_varLFSR [41];
199
         LFSR_varLFSR [41]=LFSR_varLFSR [40]^outbitLFSR ;
200
         LFSR_varLFSR [40]=LFSR_varLFSR [39];
201
         LFSR_varLFSR [39]=LFSR_varLFSR [38];
202
         LFSR_varLFSR [38]=LFSR_varLFSR [37];
203
         LFSR_varLFSR [37]=LFSR_varLFSR [36];
204
         LFSR_varLFSR [36]=LFSR_varLFSR [35];
205
         LFSR_varLFSR [35]=LFSR_varLFSR [34];
206
         LFSR_varLFSR [34]=LFSR_varLFSR [33];
207
         LFSR_varLFSR [33]=LFSR_varLFSR [32];
208
         LFSR_varLFSR [32]=LFSR_varLFSR [31];
209
         LFSR_varLFSR [31]=LFSR_varLFSR [30];
210
         LFSR_varLFSR [30]=LFSR_varLFSR [29];
211
         LFSR_varLFSR [29]=LFSR_varLFSR [28];
212
         LFSR_varLFSR [28]=LFSR_varLFSR [27];
213
         LFSR_varLFSR [27]=LFSR_varLFSR [26];
214
         LFSR_varLFSR [26]=LFSR_varLFSR [25];
215
         LFSR_varLFSR [25]=LFSR_varLFSR [24];
216
         LFSR_varLFSR [24]=LFSR_varLFSR [23];
217
         LFSR_varLFSR [23]=LFSR_varLFSR [22];
218
         LFSR_varLFSR [22]=LFSR_varLFSR [21];
219
         LFSR_varLFSR [21]=LFSR_varLFSR [20];
220
         LFSR_varLFSR [20]=LFSR_varLFSR [19]^outbitLFSR ;
221
         LFSR_varLFSR [19]=LFSR_varLFSR [18];
222
         LFSR_varLFSR [18]=LFSR_varLFSR [17];
223
         LFSR_varLFSR [17]=LFSR_varLFSR [16];
224
         LFSR_varLFSR [16]=LFSR_varLFSR [15];
225
         LFSR_varLFSR [15]=LFSR_varLFSR [14];
226
         LFSR_varLFSR [14]=LFSR_varLFSR [13];
227
         LFSR_varLFSR [13]=LFSR_varLFSR [12];
228
         LFSR_varLFSR [12]=LFSR_varLFSR [11];
229
         LFSR_varLFSR [11]=LFSR_varLFSR [10];
230
         LFSR_varLFSR [10]=LFSR_varLFSR [9];
231
         LFSR_varLFSR [9]=LFSR_varLFSR [8];
232
         LFSR_varLFSR [8]=LFSR_varLFSR [7];
233
         LFSR_varLFSR [7]=LFSR_varLFSR [6];
234
         LFSR_varLFSR [6]=LFSR_varLFSR [5];
235
         LFSR_varLFSR [5]=LFSR_varLFSR [4];
236
         LFSR_varLFSR [4]=LFSR_varLFSR [3];
237
         LFSR_varLFSR [3]=LFSR_varLFSR [2];
238
         LFSR_varLFSR [2]=LFSR_varLFSR [1];
239
         LFSR_varLFSR [1]=LFSR_varLFSR [0]^outbitLFSR ;
240
         LFSR_varLFSR [0]=LFSR_varLFSR [42];
241
 
242
         LFSR_reg  = (LFSR_varLFSR );
243
 
244
         end
245
 
246
 
247
      end
248
 
249
 
250
   end
251
//combinate:
252
always @(posedge clk or negedge reset)
253
 
254
   begin
255
 
256
   if (!reset )
257
 
258
      begin
259
 
260
      number_o  = (0);
261
 
262
      end
263
 
264
   else
265
 
266
      begin
267
 
268
      number_o  = (LFSR_reg [31:0]^CASR_reg[31:0]);
269
 
270
      end
271
 
272
 
273
   end
274
 
275
endmodule

powered by: WebSVN 2.1.0

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