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

Subversion Repositories versatile_library

[/] [versatile_library/] [trunk/] [rtl/] [verilog/] [versatile_library_altera.v] - Blame information for rev 34

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Versatile library, clock and reset                          ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Logic related to clock and reset                            ////
7
////                                                              ////
8
////                                                              ////
9
////  To Do:                                                      ////
10
////   - add more different registers                             ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - Michael Unneback, unneback@opencores.org              ////
14
////        ORSoC AB                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
// Global buffer
43
// usage:
44
// use to enable global buffers for high fan out signals such as clock and reset
45 21 unneback
//altera
46 33 unneback
module vl_gbuf ( i, o);
47
input i;
48
output o;
49
assign o = i;
50
endmodule
51 6 unneback
 // ALTERA
52
 //ACTEL
53
// sync reset
54 17 unneback
// input active lo async reset, normally from external reset generator and/or switch
55 6 unneback
// output active high global reset sync with two DFFs 
56
`timescale 1 ns/100 ps
57
module vl_sync_rst ( rst_n_i, rst_o, clk);
58
input rst_n_i, clk;
59
output rst_o;
60 18 unneback
reg [1:0] tmp;
61 6 unneback
always @ (posedge clk or negedge rst_n_i)
62
if (!rst_n_i)
63 17 unneback
        tmp <= 2'b11;
64 6 unneback
else
65 33 unneback
        tmp <= {1'b0,tmp[1]};
66 17 unneback
vl_gbuf buf_i0( .i(tmp[0]), .o(rst_o));
67 6 unneback
endmodule
68
// vl_pll
69 32 unneback
///////////////////////////////////////////////////////////////////////////////
70
`timescale 1 ps/1 ps
71
module vl_pll ( clk_i, rst_n_i, lock, clk_o, rst_o);
72
parameter index = 0;
73
parameter number_of_clk = 1;
74
parameter period_time_0 = 20000;
75
parameter period_time_1 = 20000;
76
parameter period_time_2 = 20000;
77
parameter period_time_3 = 20000;
78
parameter period_time_4 = 20000;
79
parameter lock_delay = 2000000;
80
input clk_i, rst_n_i;
81
output lock;
82
output reg [0:number_of_clk-1] clk_o;
83
output [0:number_of_clk-1] rst_o;
84 33 unneback
`ifdef SIM_PLL
85 32 unneback
always
86
     #((period_time_0)/2) clk_o[0] <=  (!rst_n_i) ? 0 : ~clk_o[0];
87
generate if (number_of_clk > 1)
88
always
89
     #((period_time_1)/2) clk_o[1] <=  (!rst_n_i) ? 0 : ~clk_o[1];
90
endgenerate
91
generate if (number_of_clk > 2)
92
always
93
     #((period_time_2)/2) clk_o[2] <=  (!rst_n_i) ? 0 : ~clk_o[2];
94
endgenerate
95 33 unneback
generate if (number_of_clk > 3)
96 32 unneback
always
97
     #((period_time_3)/2) clk_o[3] <=  (!rst_n_i) ? 0 : ~clk_o[3];
98
endgenerate
99 33 unneback
generate if (number_of_clk > 4)
100 32 unneback
always
101
     #((period_time_4)/2) clk_o[4] <=  (!rst_n_i) ? 0 : ~clk_o[4];
102
endgenerate
103
genvar i;
104
generate for (i=0;i<number_of_clk;i=i+1) begin: clock
105
     vl_sync_rst rst_i0 ( .rst_n_i(rst_n_i | lock), .rst_o(rst_o[i]), .clk(clk_o[i]));
106
end
107
endgenerate
108 33 unneback
//assign #lock_delay lock = rst_n_i;
109
assign lock = rst_n_i;
110 32 unneback
endmodule
111 33 unneback
`else
112
`ifdef VL_PLL0
113
`ifdef VL_PLL0_CLK1
114
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]));
115
`endif
116
`ifdef VL_PLL0_CLK2
117
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]));
118
`endif
119
`ifdef VL_PLL0_CLK3
120
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]));
121
`endif
122
`ifdef VL_PLL0_CLK4
123
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]));
124
`endif
125
`ifdef VL_PLL0_CLK5
126
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]), .c4(clk_o[4]));
127
`endif
128
`endif
129
`ifdef VL_PLL1
130
`ifdef VL_PLL1_CLK1
131
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]));
132
`endif
133
`ifdef VL_PLL1_CLK2
134
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]));
135
`endif
136
`ifdef VL_PLL1_CLK3
137
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]));
138
`endif
139
`ifdef VL_PLL1_CLK4
140
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]));
141
`endif
142
`ifdef VL_PLL1_CLK5
143
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]), .c4(clk_o[4]));
144
`endif
145
`endif
146
`ifdef VL_PLL2
147
`ifdef VL_PLL2_CLK1
148
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]));
149
`endif
150
`ifdef VL_PLL2_CLK2
151
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]));
152
`endif
153
`ifdef VL_PLL2_CLK3
154
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]));
155
`endif
156
`ifdef VL_PLL2_CLK4
157
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]));
158
`endif
159
`ifdef VL_PLL2_CLK5
160
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]), .c4(clk_o[4]));
161
`endif
162
`endif
163
`ifdef VL_PLL3
164
`ifdef VL_PLL3_CLK1
165
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]));
166
`endif
167
`ifdef VL_PLL3_CLK2
168
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]));
169
`endif
170
`ifdef VL_PLL3_CLK3
171
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]));
172
`endif
173
`ifdef VL_PLL3_CLK4
174
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]));
175
`endif
176
`ifdef VL_PLL3_CLK5
177
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]), .c4(clk_o[4]));
178
`endif
179
`endif
180 32 unneback
genvar i;
181
generate for (i=0;i<number_of_clk;i=i+1) begin: clock
182 33 unneback
        vl_sync_rst rst_i0 ( .rst_n_i(rst_n_i | lock), .rst_o(rst_o[i]), .clk(clk_o[i]));
183 32 unneback
end
184
endgenerate
185
endmodule
186 33 unneback
`endif
187 32 unneback
///////////////////////////////////////////////////////////////////////////////
188 6 unneback
 //altera
189
 //actel
190
//////////////////////////////////////////////////////////////////////
191
////                                                              ////
192
////  Versatile library, registers                                ////
193
////                                                              ////
194
////  Description                                                 ////
195
////  Different type of registers                                 ////
196
////                                                              ////
197
////                                                              ////
198
////  To Do:                                                      ////
199
////   - add more different registers                             ////
200
////                                                              ////
201
////  Author(s):                                                  ////
202
////      - Michael Unneback, unneback@opencores.org              ////
203
////        ORSoC AB                                              ////
204
////                                                              ////
205
//////////////////////////////////////////////////////////////////////
206
////                                                              ////
207
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
208
////                                                              ////
209
//// This source file may be used and distributed without         ////
210
//// restriction provided that this copyright statement is not    ////
211
//// removed from the file and that any derivative work contains  ////
212
//// the original copyright notice and the associated disclaimer. ////
213
////                                                              ////
214
//// This source file is free software; you can redistribute it   ////
215
//// and/or modify it under the terms of the GNU Lesser General   ////
216
//// Public License as published by the Free Software Foundation; ////
217
//// either version 2.1 of the License, or (at your option) any   ////
218
//// later version.                                               ////
219
////                                                              ////
220
//// This source is distributed in the hope that it will be       ////
221
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
222
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
223
//// PURPOSE.  See the GNU Lesser General Public License for more ////
224
//// details.                                                     ////
225
////                                                              ////
226
//// You should have received a copy of the GNU Lesser General    ////
227
//// Public License along with this source; if not, download it   ////
228
//// from http://www.opencores.org/lgpl.shtml                     ////
229
////                                                              ////
230
//////////////////////////////////////////////////////////////////////
231 18 unneback
module vl_dff ( d, q, clk, rst);
232 6 unneback
        parameter width = 1;
233
        parameter reset_value = 0;
234
        input [width-1:0] d;
235
        input clk, rst;
236
        output reg [width-1:0] q;
237
        always @ (posedge clk or posedge rst)
238
        if (rst)
239
                q <= reset_value;
240
        else
241
                q <= d;
242
endmodule
243 18 unneback
module vl_dff_array ( d, q, clk, rst);
244 6 unneback
        parameter width = 1;
245
        parameter depth = 2;
246
        parameter reset_value = 1'b0;
247
        input [width-1:0] d;
248
        input clk, rst;
249
        output [width-1:0] q;
250
        reg  [0:depth-1] q_tmp [width-1:0];
251
        integer i;
252
        always @ (posedge clk or posedge rst)
253
        if (rst) begin
254
            for (i=0;i<depth;i=i+1)
255
                q_tmp[i] <= {width{reset_value}};
256
        end else begin
257
            q_tmp[0] <= d;
258
            for (i=1;i<depth;i=i+1)
259
                q_tmp[i] <= q_tmp[i-1];
260
        end
261
    assign q = q_tmp[depth-1];
262
endmodule
263 18 unneback
module vl_dff_ce ( d, ce, q, clk, rst);
264 6 unneback
        parameter width = 1;
265
        parameter reset_value = 0;
266
        input [width-1:0] d;
267
        input ce, clk, rst;
268
        output reg [width-1:0] q;
269
        always @ (posedge clk or posedge rst)
270
        if (rst)
271
                q <= reset_value;
272
        else
273
                if (ce)
274
                        q <= d;
275
endmodule
276 18 unneback
module vl_dff_ce_clear ( d, ce, clear, q, clk, rst);
277 8 unneback
        parameter width = 1;
278
        parameter reset_value = 0;
279
        input [width-1:0] d;
280 10 unneback
        input ce, clear, clk, rst;
281 8 unneback
        output reg [width-1:0] q;
282
        always @ (posedge clk or posedge rst)
283
        if (rst)
284
            q <= reset_value;
285
        else
286
            if (ce)
287
                if (clear)
288
                    q <= {width{1'b0}};
289
                else
290
                    q <= d;
291
endmodule
292 24 unneback
module vl_dff_ce_set ( d, ce, set, q, clk, rst);
293
        parameter width = 1;
294
        parameter reset_value = 0;
295
        input [width-1:0] d;
296
        input ce, set, clk, rst;
297
        output reg [width-1:0] q;
298
        always @ (posedge clk or posedge rst)
299
        if (rst)
300
            q <= reset_value;
301
        else
302
            if (ce)
303
                if (set)
304
                    q <= {width{1'b1}};
305
                else
306
                    q <= d;
307
endmodule
308 29 unneback
module vl_spr ( sp, r, q, clk, rst);
309
        parameter width = 1;
310
        parameter reset_value = 0;
311
        input sp, r;
312
        output reg q;
313
        input clk, rst;
314
        always @ (posedge clk or posedge rst)
315
        if (rst)
316
            q <= reset_value;
317
        else
318
            if (sp)
319
                q <= 1'b1;
320
            else if (r)
321
                q <= 1'b0;
322
endmodule
323
module vl_srp ( s, rp, q, clk, rst);
324
        parameter width = 1;
325
        parameter reset_value = 0;
326
        input s, rp;
327
        output reg q;
328
        input clk, rst;
329
        always @ (posedge clk or posedge rst)
330
        if (rst)
331
            q <= reset_value;
332
        else
333
            if (rp)
334
                q <= 1'b0;
335
            else if (s)
336
                q <= 1'b1;
337
endmodule
338 6 unneback
// megafunction wizard: %LPM_FF%
339
// GENERATION: STANDARD
340
// VERSION: WM1.0
341
// MODULE: lpm_ff 
342
// ============================================================
343
// File Name: dff_sr.v
344
// Megafunction Name(s):
345
//                      lpm_ff
346
//
347
// Simulation Library Files(s):
348
//                      lpm
349
// ============================================================
350
// ************************************************************
351
// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
352
//
353
// 9.1 Build 304 01/25/2010 SP 1 SJ Full Version
354
// ************************************************************
355
//Copyright (C) 1991-2010 Altera Corporation
356
//Your use of Altera Corporation's design tools, logic functions 
357
//and other software and tools, and its AMPP partner logic 
358
//functions, and any output files from any of the foregoing 
359
//(including device programming or simulation files), and any 
360
//associated documentation or information are expressly subject 
361
//to the terms and conditions of the Altera Program License 
362
//Subscription Agreement, Altera MegaCore Function License 
363
//Agreement, or other applicable license agreement, including, 
364
//without limitation, that your use is for the sole purpose of 
365
//programming logic devices manufactured by Altera and sold by 
366
//Altera or its authorized distributors.  Please refer to the 
367
//applicable agreement for further details.
368
// synopsys translate_off
369
`timescale 1 ps / 1 ps
370
// synopsys translate_on
371 18 unneback
module vl_dff_sr (
372 6 unneback
        aclr,
373
        aset,
374
        clock,
375
        data,
376
        q);
377
        input     aclr;
378
        input     aset;
379
        input     clock;
380
        input     data;
381
        output    q;
382
        wire [0:0] sub_wire0;
383
        wire [0:0] sub_wire1 = sub_wire0[0:0];
384
        wire  q = sub_wire1;
385
        wire  sub_wire2 = data;
386
        wire  sub_wire3 = sub_wire2;
387
        lpm_ff  lpm_ff_component (
388
                                .aclr (aclr),
389
                                .clock (clock),
390
                                .data (sub_wire3),
391
                                .aset (aset),
392
                                .q (sub_wire0)
393
                                // synopsys translate_off
394
                                ,
395
                                .aload (),
396
                                .enable (),
397
                                .sclr (),
398
                                .sload (),
399
                                .sset ()
400
                                // synopsys translate_on
401
                                );
402
        defparam
403
                lpm_ff_component.lpm_fftype = "DFF",
404
                lpm_ff_component.lpm_type = "LPM_FF",
405
                lpm_ff_component.lpm_width = 1;
406
endmodule
407
// ============================================================
408
// CNX file retrieval info
409
// ============================================================
410
// Retrieval info: PRIVATE: ACLR NUMERIC "1"
411
// Retrieval info: PRIVATE: ALOAD NUMERIC "0"
412
// Retrieval info: PRIVATE: ASET NUMERIC "1"
413
// Retrieval info: PRIVATE: ASET_ALL1 NUMERIC "1"
414
// Retrieval info: PRIVATE: CLK_EN NUMERIC "0"
415
// Retrieval info: PRIVATE: DFF NUMERIC "1"
416
// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone IV E"
417
// Retrieval info: PRIVATE: SCLR NUMERIC "0"
418
// Retrieval info: PRIVATE: SLOAD NUMERIC "0"
419
// Retrieval info: PRIVATE: SSET NUMERIC "0"
420
// Retrieval info: PRIVATE: SSET_ALL1 NUMERIC "1"
421
// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
422
// Retrieval info: PRIVATE: UseTFFdataPort NUMERIC "0"
423
// Retrieval info: PRIVATE: nBit NUMERIC "1"
424
// Retrieval info: CONSTANT: LPM_FFTYPE STRING "DFF"
425
// Retrieval info: CONSTANT: LPM_TYPE STRING "LPM_FF"
426
// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC "1"
427
// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT NODEFVAL aclr
428
// Retrieval info: USED_PORT: aset 0 0 0 0 INPUT NODEFVAL aset
429
// Retrieval info: USED_PORT: clock 0 0 0 0 INPUT NODEFVAL clock
430
// Retrieval info: USED_PORT: data 0 0 0 0 INPUT NODEFVAL data
431
// Retrieval info: USED_PORT: q 0 0 0 0 OUTPUT NODEFVAL q
432
// Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0
433
// Retrieval info: CONNECT: q 0 0 0 0 @q 0 0 1 0
434
// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
435
// Retrieval info: CONNECT: @aset 0 0 0 0 aset 0 0 0 0
436
// Retrieval info: CONNECT: @data 0 0 1 0 data 0 0 0 0
437
// Retrieval info: LIBRARY: lpm lpm.lpm_components.all
438
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr.v TRUE
439
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr.inc FALSE
440
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr.cmp FALSE
441
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr.bsf FALSE
442
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr_inst.v FALSE
443
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr_bb.v FALSE
444
// Retrieval info: LIB_FILE: lpm
445
// LATCH
446
// For targtes not supporting LATCH use dff_sr with clk=1 and data=1
447 18 unneback
module vl_latch ( d, le, q, clk);
448 6 unneback
input d, le;
449
output q;
450
input clk;
451
dff_sr i0 (.aclr(), .aset(), .clock(1'b1), .data(1'b1), .q(q));
452
endmodule
453 18 unneback
module vl_shreg ( d, q, clk, rst);
454 17 unneback
parameter depth = 10;
455
input d;
456
output q;
457
input clk, rst;
458
reg [1:depth] dffs;
459
always @ (posedge clk or posedge rst)
460
if (rst)
461
    dffs <= {depth{1'b0}};
462
else
463
    dffs <= {d,dffs[1:depth-1]};
464
assign q = dffs[depth];
465
endmodule
466 18 unneback
module vl_shreg_ce ( d, ce, q, clk, rst);
467 17 unneback
parameter depth = 10;
468
input d, ce;
469
output q;
470
input clk, rst;
471
reg [1:depth] dffs;
472
always @ (posedge clk or posedge rst)
473
if (rst)
474
    dffs <= {depth{1'b0}};
475
else
476
    if (ce)
477
        dffs <= {d,dffs[1:depth-1]};
478
assign q = dffs[depth];
479
endmodule
480 18 unneback
module vl_delay ( d, q, clk, rst);
481 15 unneback
parameter depth = 10;
482
input d;
483
output q;
484
input clk, rst;
485
reg [1:depth] dffs;
486
always @ (posedge clk or posedge rst)
487
if (rst)
488
    dffs <= {depth{1'b0}};
489
else
490
    dffs <= {d,dffs[1:depth-1]};
491
assign q = dffs[depth];
492
endmodule
493 18 unneback
module vl_delay_emptyflag ( d, q, emptyflag, clk, rst);
494 17 unneback
parameter depth = 10;
495
input d;
496
output q, emptyflag;
497
input clk, rst;
498
reg [1:depth] dffs;
499
always @ (posedge clk or posedge rst)
500
if (rst)
501
    dffs <= {depth{1'b0}};
502
else
503
    dffs <= {d,dffs[1:depth-1]};
504
assign q = dffs[depth];
505
assign emptyflag = !(|dffs);
506
endmodule
507 6 unneback
//////////////////////////////////////////////////////////////////////
508
////                                                              ////
509 18 unneback
////  Logic functions                                             ////
510
////                                                              ////
511
////  Description                                                 ////
512
////  Logic functions such as multiplexers                        ////
513
////                                                              ////
514
////                                                              ////
515
////  To Do:                                                      ////
516
////   -                                                          ////
517
////                                                              ////
518
////  Author(s):                                                  ////
519
////      - Michael Unneback, unneback@opencores.org              ////
520
////        ORSoC AB                                              ////
521
////                                                              ////
522
//////////////////////////////////////////////////////////////////////
523
////                                                              ////
524
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
525
////                                                              ////
526
//// This source file may be used and distributed without         ////
527
//// restriction provided that this copyright statement is not    ////
528
//// removed from the file and that any derivative work contains  ////
529
//// the original copyright notice and the associated disclaimer. ////
530
////                                                              ////
531
//// This source file is free software; you can redistribute it   ////
532
//// and/or modify it under the terms of the GNU Lesser General   ////
533
//// Public License as published by the Free Software Foundation; ////
534
//// either version 2.1 of the License, or (at your option) any   ////
535
//// later version.                                               ////
536
////                                                              ////
537
//// This source is distributed in the hope that it will be       ////
538
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
539
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
540
//// PURPOSE.  See the GNU Lesser General Public License for more ////
541
//// details.                                                     ////
542
////                                                              ////
543
//// You should have received a copy of the GNU Lesser General    ////
544
//// Public License along with this source; if not, download it   ////
545
//// from http://www.opencores.org/lgpl.shtml                     ////
546
////                                                              ////
547
//////////////////////////////////////////////////////////////////////
548 34 unneback
module vl_mux2_andor ( a1, a0, sel, dout);
549
parameter width = 32;
550
parameter nr_of_ports = 2;
551
input [width-1:0] a1, a0;
552
input [nr_of_ports-1:0] sel;
553
output [width-1:0] dout;
554
wire [width-1:0] tmp [nr_of_ports-1:0];
555
integer i;
556
// and
557
assign tmp[0] = {width{sel[0]}} & a0;
558
assign tmp[1] = {width{sel[1]}} & a1;
559
// or
560
assign dout = tmp[1] | tmp[0];
561
endmodule
562
module vl_mux3_andor ( a2, a1, a0, sel, dout);
563
parameter width = 32;
564
parameter nr_of_ports = 3;
565
input [width-1:0] a2, a1, a0;
566
input [nr_of_ports-1:0] sel;
567
output [width-1:0] dout;
568
wire [width-1:0] tmp [nr_of_ports-1:0];
569
integer i;
570
// and
571
assign tmp[0] = {width{sel[0]}} & a0;
572
assign tmp[1] = {width{sel[1]}} & a1;
573
assign tmp[2] = {width{sel[2]}} & a2;
574
// or
575
assign dout = tmp[2] | tmp[1] | tmp[0];
576
endmodule
577 18 unneback
module vl_mux4_andor ( a3, a2, a1, a0, sel, dout);
578
parameter width = 32;
579
parameter nr_of_ports = 4;
580
input [width-1:0] a3, a2, a1, a0;
581
input [nr_of_ports-1:0] sel;
582 22 unneback
output [width-1:0] dout;
583 21 unneback
wire [width-1:0] tmp [nr_of_ports-1:0];
584 18 unneback
integer i;
585
// and
586
assign tmp[0] = {width{sel[0]}} & a0;
587
assign tmp[1] = {width{sel[1]}} & a1;
588
assign tmp[2] = {width{sel[2]}} & a2;
589
assign tmp[3] = {width{sel[3]}} & a3;
590
// or
591
assign dout = tmp[3] | tmp[2] | tmp[1] | tmp[0];
592
endmodule
593
module vl_mux5_andor ( a4, a3, a2, a1, a0, sel, dout);
594
parameter width = 32;
595
parameter nr_of_ports = 5;
596
input [width-1:0] a4, a3, a2, a1, a0;
597
input [nr_of_ports-1:0] sel;
598 22 unneback
output [width-1:0] dout;
599 21 unneback
wire [width-1:0] tmp [nr_of_ports-1:0];
600 18 unneback
integer i;
601
// and
602
assign tmp[0] = {width{sel[0]}} & a0;
603
assign tmp[1] = {width{sel[1]}} & a1;
604
assign tmp[2] = {width{sel[2]}} & a2;
605
assign tmp[3] = {width{sel[3]}} & a3;
606
assign tmp[4] = {width{sel[4]}} & a4;
607
// or
608
assign dout = tmp[4] | tmp[3] | tmp[2] | tmp[1] | tmp[0];
609
endmodule
610
module vl_mux6_andor ( a5, a4, a3, a2, a1, a0, sel, dout);
611
parameter width = 32;
612
parameter nr_of_ports = 6;
613
input [width-1:0] a5, a4, a3, a2, a1, a0;
614
input [nr_of_ports-1:0] sel;
615 22 unneback
output [width-1:0] dout;
616 21 unneback
wire [width-1:0] tmp [nr_of_ports-1:0];
617 18 unneback
integer i;
618
// and
619
assign tmp[0] = {width{sel[0]}} & a0;
620
assign tmp[1] = {width{sel[1]}} & a1;
621
assign tmp[2] = {width{sel[2]}} & a2;
622
assign tmp[3] = {width{sel[3]}} & a3;
623
assign tmp[4] = {width{sel[4]}} & a4;
624
assign tmp[5] = {width{sel[5]}} & a5;
625
// or
626
assign dout = tmp[5] | tmp[4] | tmp[3] | tmp[2] | tmp[1] | tmp[0];
627
endmodule
628
//////////////////////////////////////////////////////////////////////
629
////                                                              ////
630 6 unneback
////  Versatile counter                                           ////
631
////                                                              ////
632
////  Description                                                 ////
633
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
634
////  counter                                                     ////
635
////                                                              ////
636
////  To Do:                                                      ////
637
////   - add LFSR with more taps                                  ////
638
////                                                              ////
639
////  Author(s):                                                  ////
640
////      - Michael Unneback, unneback@opencores.org              ////
641
////        ORSoC AB                                              ////
642
////                                                              ////
643
//////////////////////////////////////////////////////////////////////
644
////                                                              ////
645
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
646
////                                                              ////
647
//// This source file may be used and distributed without         ////
648
//// restriction provided that this copyright statement is not    ////
649
//// removed from the file and that any derivative work contains  ////
650
//// the original copyright notice and the associated disclaimer. ////
651
////                                                              ////
652
//// This source file is free software; you can redistribute it   ////
653
//// and/or modify it under the terms of the GNU Lesser General   ////
654
//// Public License as published by the Free Software Foundation; ////
655
//// either version 2.1 of the License, or (at your option) any   ////
656
//// later version.                                               ////
657
////                                                              ////
658
//// This source is distributed in the hope that it will be       ////
659
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
660
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
661
//// PURPOSE.  See the GNU Lesser General Public License for more ////
662
//// details.                                                     ////
663
////                                                              ////
664
//// You should have received a copy of the GNU Lesser General    ////
665
//// Public License along with this source; if not, download it   ////
666
//// from http://www.opencores.org/lgpl.shtml                     ////
667
////                                                              ////
668
//////////////////////////////////////////////////////////////////////
669
// binary counter
670 22 unneback
module vl_cnt_bin ( q, rst, clk);
671
   parameter length = 4;
672
   output [length:1] q;
673
   input rst;
674
   input clk;
675
   parameter clear_value = 0;
676
   parameter set_value = 1;
677
   parameter wrap_value = 0;
678
   parameter level1_value = 15;
679
   reg  [length:1] qi;
680
   wire [length:1] q_next;
681
   assign q_next = qi + {{length-1{1'b0}},1'b1};
682
   always @ (posedge clk or posedge rst)
683
     if (rst)
684
       qi <= {length{1'b0}};
685
     else
686
       qi <= q_next;
687
   assign q = qi;
688
endmodule
689
//////////////////////////////////////////////////////////////////////
690
////                                                              ////
691
////  Versatile counter                                           ////
692
////                                                              ////
693
////  Description                                                 ////
694
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
695
////  counter                                                     ////
696
////                                                              ////
697
////  To Do:                                                      ////
698
////   - add LFSR with more taps                                  ////
699
////                                                              ////
700
////  Author(s):                                                  ////
701
////      - Michael Unneback, unneback@opencores.org              ////
702
////        ORSoC AB                                              ////
703
////                                                              ////
704
//////////////////////////////////////////////////////////////////////
705
////                                                              ////
706
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
707
////                                                              ////
708
//// This source file may be used and distributed without         ////
709
//// restriction provided that this copyright statement is not    ////
710
//// removed from the file and that any derivative work contains  ////
711
//// the original copyright notice and the associated disclaimer. ////
712
////                                                              ////
713
//// This source file is free software; you can redistribute it   ////
714
//// and/or modify it under the terms of the GNU Lesser General   ////
715
//// Public License as published by the Free Software Foundation; ////
716
//// either version 2.1 of the License, or (at your option) any   ////
717
//// later version.                                               ////
718
////                                                              ////
719
//// This source is distributed in the hope that it will be       ////
720
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
721
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
722
//// PURPOSE.  See the GNU Lesser General Public License for more ////
723
//// details.                                                     ////
724
////                                                              ////
725
//// You should have received a copy of the GNU Lesser General    ////
726
//// Public License along with this source; if not, download it   ////
727
//// from http://www.opencores.org/lgpl.shtml                     ////
728
////                                                              ////
729
//////////////////////////////////////////////////////////////////////
730
// binary counter
731
module vl_cnt_bin_clear ( clear, q, rst, clk);
732
   parameter length = 4;
733
   input clear;
734
   output [length:1] q;
735
   input rst;
736
   input clk;
737
   parameter clear_value = 0;
738
   parameter set_value = 1;
739
   parameter wrap_value = 0;
740
   parameter level1_value = 15;
741
   reg  [length:1] qi;
742
   wire [length:1] q_next;
743
   assign q_next =  clear ? {length{1'b0}} :qi + {{length-1{1'b0}},1'b1};
744
   always @ (posedge clk or posedge rst)
745
     if (rst)
746
       qi <= {length{1'b0}};
747
     else
748
       qi <= q_next;
749
   assign q = qi;
750
endmodule
751
//////////////////////////////////////////////////////////////////////
752
////                                                              ////
753
////  Versatile counter                                           ////
754
////                                                              ////
755
////  Description                                                 ////
756
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
757
////  counter                                                     ////
758
////                                                              ////
759
////  To Do:                                                      ////
760
////   - add LFSR with more taps                                  ////
761
////                                                              ////
762
////  Author(s):                                                  ////
763
////      - Michael Unneback, unneback@opencores.org              ////
764
////        ORSoC AB                                              ////
765
////                                                              ////
766
//////////////////////////////////////////////////////////////////////
767
////                                                              ////
768
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
769
////                                                              ////
770
//// This source file may be used and distributed without         ////
771
//// restriction provided that this copyright statement is not    ////
772
//// removed from the file and that any derivative work contains  ////
773
//// the original copyright notice and the associated disclaimer. ////
774
////                                                              ////
775
//// This source file is free software; you can redistribute it   ////
776
//// and/or modify it under the terms of the GNU Lesser General   ////
777
//// Public License as published by the Free Software Foundation; ////
778
//// either version 2.1 of the License, or (at your option) any   ////
779
//// later version.                                               ////
780
////                                                              ////
781
//// This source is distributed in the hope that it will be       ////
782
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
783
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
784
//// PURPOSE.  See the GNU Lesser General Public License for more ////
785
//// details.                                                     ////
786
////                                                              ////
787
//// You should have received a copy of the GNU Lesser General    ////
788
//// Public License along with this source; if not, download it   ////
789
//// from http://www.opencores.org/lgpl.shtml                     ////
790
////                                                              ////
791
//////////////////////////////////////////////////////////////////////
792
// binary counter
793 18 unneback
module vl_cnt_bin_ce ( cke, q, rst, clk);
794 6 unneback
   parameter length = 4;
795
   input cke;
796
   output [length:1] q;
797
   input rst;
798
   input clk;
799
   parameter clear_value = 0;
800
   parameter set_value = 1;
801
   parameter wrap_value = 0;
802
   parameter level1_value = 15;
803
   reg  [length:1] qi;
804
   wire [length:1] q_next;
805
   assign q_next = qi + {{length-1{1'b0}},1'b1};
806
   always @ (posedge clk or posedge rst)
807
     if (rst)
808
       qi <= {length{1'b0}};
809
     else
810
     if (cke)
811
       qi <= q_next;
812
   assign q = qi;
813
endmodule
814
//////////////////////////////////////////////////////////////////////
815
////                                                              ////
816
////  Versatile counter                                           ////
817
////                                                              ////
818
////  Description                                                 ////
819
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
820
////  counter                                                     ////
821
////                                                              ////
822
////  To Do:                                                      ////
823
////   - add LFSR with more taps                                  ////
824
////                                                              ////
825
////  Author(s):                                                  ////
826
////      - Michael Unneback, unneback@opencores.org              ////
827
////        ORSoC AB                                              ////
828
////                                                              ////
829
//////////////////////////////////////////////////////////////////////
830
////                                                              ////
831
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
832
////                                                              ////
833
//// This source file may be used and distributed without         ////
834
//// restriction provided that this copyright statement is not    ////
835
//// removed from the file and that any derivative work contains  ////
836
//// the original copyright notice and the associated disclaimer. ////
837
////                                                              ////
838
//// This source file is free software; you can redistribute it   ////
839
//// and/or modify it under the terms of the GNU Lesser General   ////
840
//// Public License as published by the Free Software Foundation; ////
841
//// either version 2.1 of the License, or (at your option) any   ////
842
//// later version.                                               ////
843
////                                                              ////
844
//// This source is distributed in the hope that it will be       ////
845
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
846
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
847
//// PURPOSE.  See the GNU Lesser General Public License for more ////
848
//// details.                                                     ////
849
////                                                              ////
850
//// You should have received a copy of the GNU Lesser General    ////
851
//// Public License along with this source; if not, download it   ////
852
//// from http://www.opencores.org/lgpl.shtml                     ////
853
////                                                              ////
854
//////////////////////////////////////////////////////////////////////
855
// binary counter
856 18 unneback
module vl_cnt_bin_ce_clear ( clear, cke, q, rst, clk);
857 6 unneback
   parameter length = 4;
858
   input clear;
859
   input cke;
860
   output [length:1] q;
861
   input rst;
862
   input clk;
863
   parameter clear_value = 0;
864
   parameter set_value = 1;
865
   parameter wrap_value = 0;
866
   parameter level1_value = 15;
867
   reg  [length:1] qi;
868
   wire [length:1] q_next;
869
   assign q_next =  clear ? {length{1'b0}} :qi + {{length-1{1'b0}},1'b1};
870
   always @ (posedge clk or posedge rst)
871
     if (rst)
872
       qi <= {length{1'b0}};
873
     else
874
     if (cke)
875
       qi <= q_next;
876
   assign q = qi;
877
endmodule
878
//////////////////////////////////////////////////////////////////////
879
////                                                              ////
880
////  Versatile counter                                           ////
881
////                                                              ////
882
////  Description                                                 ////
883
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
884
////  counter                                                     ////
885
////                                                              ////
886
////  To Do:                                                      ////
887
////   - add LFSR with more taps                                  ////
888
////                                                              ////
889
////  Author(s):                                                  ////
890
////      - Michael Unneback, unneback@opencores.org              ////
891
////        ORSoC AB                                              ////
892
////                                                              ////
893
//////////////////////////////////////////////////////////////////////
894
////                                                              ////
895
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
896
////                                                              ////
897
//// This source file may be used and distributed without         ////
898
//// restriction provided that this copyright statement is not    ////
899
//// removed from the file and that any derivative work contains  ////
900
//// the original copyright notice and the associated disclaimer. ////
901
////                                                              ////
902
//// This source file is free software; you can redistribute it   ////
903
//// and/or modify it under the terms of the GNU Lesser General   ////
904
//// Public License as published by the Free Software Foundation; ////
905
//// either version 2.1 of the License, or (at your option) any   ////
906
//// later version.                                               ////
907
////                                                              ////
908
//// This source is distributed in the hope that it will be       ////
909
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
910
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
911
//// PURPOSE.  See the GNU Lesser General Public License for more ////
912
//// details.                                                     ////
913
////                                                              ////
914
//// You should have received a copy of the GNU Lesser General    ////
915
//// Public License along with this source; if not, download it   ////
916
//// from http://www.opencores.org/lgpl.shtml                     ////
917
////                                                              ////
918
//////////////////////////////////////////////////////////////////////
919
// binary counter
920 29 unneback
module vl_cnt_bin_ce_clear_l1_l2 ( clear, cke, q, level1, level2, rst, clk);
921
   parameter length = 4;
922
   input clear;
923
   input cke;
924
   output [length:1] q;
925
   output reg level1;
926
   output reg level2;
927
   input rst;
928
   input clk;
929
   parameter clear_value = 0;
930
   parameter set_value = 1;
931 30 unneback
   parameter wrap_value = 15;
932
   parameter level1_value = 8;
933
   parameter level2_value = 15;
934 29 unneback
   wire rew;
935 30 unneback
   assign rew = 1'b0;
936 29 unneback
   reg  [length:1] qi;
937
   wire [length:1] q_next;
938
   assign q_next =  clear ? {length{1'b0}} :qi + {{length-1{1'b0}},1'b1};
939
   always @ (posedge clk or posedge rst)
940
     if (rst)
941
       qi <= {length{1'b0}};
942
     else
943
     if (cke)
944
       qi <= q_next;
945
   assign q = qi;
946
    always @ (posedge clk or posedge rst)
947
    if (rst)
948
        level1 <= 1'b0;
949
    else
950
    if (cke)
951
    if (clear)
952
        level1 <= 1'b0;
953
    else if (q_next == level1_value)
954
        level1 <= 1'b1;
955
    else if (qi == level1_value & rew)
956
        level1 <= 1'b0;
957
    always @ (posedge clk or posedge rst)
958
    if (rst)
959
        level2 <= 1'b0;
960
    else
961
    if (cke)
962
    if (clear)
963
        level2 <= 1'b0;
964
    else if (q_next == level2_value)
965
        level2 <= 1'b1;
966
    else if (qi == level2_value & rew)
967
        level2 <= 1'b0;
968
endmodule
969
//////////////////////////////////////////////////////////////////////
970
////                                                              ////
971
////  Versatile counter                                           ////
972
////                                                              ////
973
////  Description                                                 ////
974
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
975
////  counter                                                     ////
976
////                                                              ////
977
////  To Do:                                                      ////
978
////   - add LFSR with more taps                                  ////
979
////                                                              ////
980
////  Author(s):                                                  ////
981
////      - Michael Unneback, unneback@opencores.org              ////
982
////        ORSoC AB                                              ////
983
////                                                              ////
984
//////////////////////////////////////////////////////////////////////
985
////                                                              ////
986
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
987
////                                                              ////
988
//// This source file may be used and distributed without         ////
989
//// restriction provided that this copyright statement is not    ////
990
//// removed from the file and that any derivative work contains  ////
991
//// the original copyright notice and the associated disclaimer. ////
992
////                                                              ////
993
//// This source file is free software; you can redistribute it   ////
994
//// and/or modify it under the terms of the GNU Lesser General   ////
995
//// Public License as published by the Free Software Foundation; ////
996
//// either version 2.1 of the License, or (at your option) any   ////
997
//// later version.                                               ////
998
////                                                              ////
999
//// This source is distributed in the hope that it will be       ////
1000
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1001
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1002
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1003
//// details.                                                     ////
1004
////                                                              ////
1005
//// You should have received a copy of the GNU Lesser General    ////
1006
//// Public License along with this source; if not, download it   ////
1007
//// from http://www.opencores.org/lgpl.shtml                     ////
1008
////                                                              ////
1009
//////////////////////////////////////////////////////////////////////
1010
// binary counter
1011 18 unneback
module vl_cnt_bin_ce_clear_set_rew ( clear, set, cke, rew, q, rst, clk);
1012 6 unneback
   parameter length = 4;
1013
   input clear;
1014
   input set;
1015
   input cke;
1016
   input rew;
1017
   output [length:1] q;
1018
   input rst;
1019
   input clk;
1020
   parameter clear_value = 0;
1021
   parameter set_value = 1;
1022
   parameter wrap_value = 0;
1023
   parameter level1_value = 15;
1024
   reg  [length:1] qi;
1025
   wire  [length:1] q_next, q_next_fw, q_next_rew;
1026
   assign q_next_fw  =  clear ? {length{1'b0}} : set ? set_value :qi + {{length-1{1'b0}},1'b1};
1027
   assign q_next_rew =  clear ? clear_value : set ? set_value :qi - {{length-1{1'b0}},1'b1};
1028
   assign q_next = rew ? q_next_rew : q_next_fw;
1029
   always @ (posedge clk or posedge rst)
1030
     if (rst)
1031
       qi <= {length{1'b0}};
1032
     else
1033
     if (cke)
1034
       qi <= q_next;
1035
   assign q = qi;
1036
endmodule
1037
//////////////////////////////////////////////////////////////////////
1038
////                                                              ////
1039
////  Versatile counter                                           ////
1040
////                                                              ////
1041
////  Description                                                 ////
1042
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1043
////  counter                                                     ////
1044
////                                                              ////
1045
////  To Do:                                                      ////
1046
////   - add LFSR with more taps                                  ////
1047
////                                                              ////
1048
////  Author(s):                                                  ////
1049
////      - Michael Unneback, unneback@opencores.org              ////
1050
////        ORSoC AB                                              ////
1051
////                                                              ////
1052
//////////////////////////////////////////////////////////////////////
1053
////                                                              ////
1054
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1055
////                                                              ////
1056
//// This source file may be used and distributed without         ////
1057
//// restriction provided that this copyright statement is not    ////
1058
//// removed from the file and that any derivative work contains  ////
1059
//// the original copyright notice and the associated disclaimer. ////
1060
////                                                              ////
1061
//// This source file is free software; you can redistribute it   ////
1062
//// and/or modify it under the terms of the GNU Lesser General   ////
1063
//// Public License as published by the Free Software Foundation; ////
1064
//// either version 2.1 of the License, or (at your option) any   ////
1065
//// later version.                                               ////
1066
////                                                              ////
1067
//// This source is distributed in the hope that it will be       ////
1068
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1069
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1070
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1071
//// details.                                                     ////
1072
////                                                              ////
1073
//// You should have received a copy of the GNU Lesser General    ////
1074
//// Public License along with this source; if not, download it   ////
1075
//// from http://www.opencores.org/lgpl.shtml                     ////
1076
////                                                              ////
1077
//////////////////////////////////////////////////////////////////////
1078
// binary counter
1079 18 unneback
module vl_cnt_bin_ce_rew_l1 ( cke, rew, level1, rst, clk);
1080 6 unneback
   parameter length = 4;
1081
   input cke;
1082
   input rew;
1083
   output reg level1;
1084
   input rst;
1085
   input clk;
1086
   parameter clear_value = 0;
1087
   parameter set_value = 1;
1088
   parameter wrap_value = 1;
1089
   parameter level1_value = 15;
1090 29 unneback
   wire clear;
1091 30 unneback
   assign clear = 1'b0;
1092 6 unneback
   reg  [length:1] qi;
1093
   wire  [length:1] q_next, q_next_fw, q_next_rew;
1094
   assign q_next_fw  = qi + {{length-1{1'b0}},1'b1};
1095
   assign q_next_rew = qi - {{length-1{1'b0}},1'b1};
1096
   assign q_next = rew ? q_next_rew : q_next_fw;
1097
   always @ (posedge clk or posedge rst)
1098
     if (rst)
1099
       qi <= {length{1'b0}};
1100
     else
1101
     if (cke)
1102
       qi <= q_next;
1103
    always @ (posedge clk or posedge rst)
1104
    if (rst)
1105
        level1 <= 1'b0;
1106
    else
1107
    if (cke)
1108 29 unneback
    if (clear)
1109
        level1 <= 1'b0;
1110
    else if (q_next == level1_value)
1111 6 unneback
        level1 <= 1'b1;
1112
    else if (qi == level1_value & rew)
1113
        level1 <= 1'b0;
1114
endmodule
1115
//////////////////////////////////////////////////////////////////////
1116
////                                                              ////
1117
////  Versatile counter                                           ////
1118
////                                                              ////
1119
////  Description                                                 ////
1120
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1121
////  counter                                                     ////
1122
////                                                              ////
1123
////  To Do:                                                      ////
1124
////   - add LFSR with more taps                                  ////
1125
////                                                              ////
1126
////  Author(s):                                                  ////
1127
////      - Michael Unneback, unneback@opencores.org              ////
1128
////        ORSoC AB                                              ////
1129
////                                                              ////
1130
//////////////////////////////////////////////////////////////////////
1131
////                                                              ////
1132
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1133
////                                                              ////
1134
//// This source file may be used and distributed without         ////
1135
//// restriction provided that this copyright statement is not    ////
1136
//// removed from the file and that any derivative work contains  ////
1137
//// the original copyright notice and the associated disclaimer. ////
1138
////                                                              ////
1139
//// This source file is free software; you can redistribute it   ////
1140
//// and/or modify it under the terms of the GNU Lesser General   ////
1141
//// Public License as published by the Free Software Foundation; ////
1142
//// either version 2.1 of the License, or (at your option) any   ////
1143
//// later version.                                               ////
1144
////                                                              ////
1145
//// This source is distributed in the hope that it will be       ////
1146
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1147
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1148
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1149
//// details.                                                     ////
1150
////                                                              ////
1151
//// You should have received a copy of the GNU Lesser General    ////
1152
//// Public License along with this source; if not, download it   ////
1153
//// from http://www.opencores.org/lgpl.shtml                     ////
1154
////                                                              ////
1155
//////////////////////////////////////////////////////////////////////
1156 25 unneback
// binary counter
1157
module vl_cnt_bin_ce_rew_zq_l1 ( cke, rew, zq, level1, rst, clk);
1158
   parameter length = 4;
1159
   input cke;
1160
   input rew;
1161
   output reg zq;
1162
   output reg level1;
1163
   input rst;
1164
   input clk;
1165
   parameter clear_value = 0;
1166
   parameter set_value = 1;
1167
   parameter wrap_value = 1;
1168
   parameter level1_value = 15;
1169 29 unneback
   wire clear;
1170 30 unneback
   assign clear = 1'b0;
1171 25 unneback
   reg  [length:1] qi;
1172
   wire  [length:1] q_next, q_next_fw, q_next_rew;
1173
   assign q_next_fw  = qi + {{length-1{1'b0}},1'b1};
1174
   assign q_next_rew = qi - {{length-1{1'b0}},1'b1};
1175
   assign q_next = rew ? q_next_rew : q_next_fw;
1176
   always @ (posedge clk or posedge rst)
1177
     if (rst)
1178
       qi <= {length{1'b0}};
1179
     else
1180
     if (cke)
1181
       qi <= q_next;
1182
   always @ (posedge clk or posedge rst)
1183
     if (rst)
1184
       zq <= 1'b1;
1185
     else
1186
     if (cke)
1187
       zq <= q_next == {length{1'b0}};
1188
    always @ (posedge clk or posedge rst)
1189
    if (rst)
1190
        level1 <= 1'b0;
1191
    else
1192
    if (cke)
1193 29 unneback
    if (clear)
1194
        level1 <= 1'b0;
1195
    else if (q_next == level1_value)
1196 25 unneback
        level1 <= 1'b1;
1197
    else if (qi == level1_value & rew)
1198
        level1 <= 1'b0;
1199
endmodule
1200
//////////////////////////////////////////////////////////////////////
1201
////                                                              ////
1202
////  Versatile counter                                           ////
1203
////                                                              ////
1204
////  Description                                                 ////
1205
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1206
////  counter                                                     ////
1207
////                                                              ////
1208
////  To Do:                                                      ////
1209
////   - add LFSR with more taps                                  ////
1210
////                                                              ////
1211
////  Author(s):                                                  ////
1212
////      - Michael Unneback, unneback@opencores.org              ////
1213
////        ORSoC AB                                              ////
1214
////                                                              ////
1215
//////////////////////////////////////////////////////////////////////
1216
////                                                              ////
1217
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1218
////                                                              ////
1219
//// This source file may be used and distributed without         ////
1220
//// restriction provided that this copyright statement is not    ////
1221
//// removed from the file and that any derivative work contains  ////
1222
//// the original copyright notice and the associated disclaimer. ////
1223
////                                                              ////
1224
//// This source file is free software; you can redistribute it   ////
1225
//// and/or modify it under the terms of the GNU Lesser General   ////
1226
//// Public License as published by the Free Software Foundation; ////
1227
//// either version 2.1 of the License, or (at your option) any   ////
1228
//// later version.                                               ////
1229
////                                                              ////
1230
//// This source is distributed in the hope that it will be       ////
1231
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1232
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1233
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1234
//// details.                                                     ////
1235
////                                                              ////
1236
//// You should have received a copy of the GNU Lesser General    ////
1237
//// Public License along with this source; if not, download it   ////
1238
//// from http://www.opencores.org/lgpl.shtml                     ////
1239
////                                                              ////
1240
//////////////////////////////////////////////////////////////////////
1241
// binary counter
1242
module vl_cnt_bin_ce_rew_q_zq_l1 ( cke, rew, q, zq, level1, rst, clk);
1243
   parameter length = 4;
1244
   input cke;
1245
   input rew;
1246
   output [length:1] q;
1247
   output reg zq;
1248
   output reg level1;
1249
   input rst;
1250
   input clk;
1251
   parameter clear_value = 0;
1252
   parameter set_value = 1;
1253
   parameter wrap_value = 1;
1254
   parameter level1_value = 15;
1255 29 unneback
   wire clear;
1256 30 unneback
   assign clear = 1'b0;
1257 25 unneback
   reg  [length:1] qi;
1258
   wire  [length:1] q_next, q_next_fw, q_next_rew;
1259
   assign q_next_fw  = qi + {{length-1{1'b0}},1'b1};
1260
   assign q_next_rew = qi - {{length-1{1'b0}},1'b1};
1261
   assign q_next = rew ? q_next_rew : q_next_fw;
1262
   always @ (posedge clk or posedge rst)
1263
     if (rst)
1264
       qi <= {length{1'b0}};
1265
     else
1266
     if (cke)
1267
       qi <= q_next;
1268
   assign q = qi;
1269
   always @ (posedge clk or posedge rst)
1270
     if (rst)
1271
       zq <= 1'b1;
1272
     else
1273
     if (cke)
1274
       zq <= q_next == {length{1'b0}};
1275
    always @ (posedge clk or posedge rst)
1276
    if (rst)
1277
        level1 <= 1'b0;
1278
    else
1279
    if (cke)
1280 29 unneback
    if (clear)
1281
        level1 <= 1'b0;
1282
    else if (q_next == level1_value)
1283 25 unneback
        level1 <= 1'b1;
1284
    else if (qi == level1_value & rew)
1285
        level1 <= 1'b0;
1286
endmodule
1287
//////////////////////////////////////////////////////////////////////
1288
////                                                              ////
1289
////  Versatile counter                                           ////
1290
////                                                              ////
1291
////  Description                                                 ////
1292
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1293
////  counter                                                     ////
1294
////                                                              ////
1295
////  To Do:                                                      ////
1296
////   - add LFSR with more taps                                  ////
1297
////                                                              ////
1298
////  Author(s):                                                  ////
1299
////      - Michael Unneback, unneback@opencores.org              ////
1300
////        ORSoC AB                                              ////
1301
////                                                              ////
1302
//////////////////////////////////////////////////////////////////////
1303
////                                                              ////
1304
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1305
////                                                              ////
1306
//// This source file may be used and distributed without         ////
1307
//// restriction provided that this copyright statement is not    ////
1308
//// removed from the file and that any derivative work contains  ////
1309
//// the original copyright notice and the associated disclaimer. ////
1310
////                                                              ////
1311
//// This source file is free software; you can redistribute it   ////
1312
//// and/or modify it under the terms of the GNU Lesser General   ////
1313
//// Public License as published by the Free Software Foundation; ////
1314
//// either version 2.1 of the License, or (at your option) any   ////
1315
//// later version.                                               ////
1316
////                                                              ////
1317
//// This source is distributed in the hope that it will be       ////
1318
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1319
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1320
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1321
//// details.                                                     ////
1322
////                                                              ////
1323
//// You should have received a copy of the GNU Lesser General    ////
1324
//// Public License along with this source; if not, download it   ////
1325
//// from http://www.opencores.org/lgpl.shtml                     ////
1326
////                                                              ////
1327
//////////////////////////////////////////////////////////////////////
1328 6 unneback
// LFSR counter
1329 18 unneback
module vl_cnt_lfsr_zq ( zq, rst, clk);
1330 6 unneback
   parameter length = 4;
1331
   output reg zq;
1332
   input rst;
1333
   input clk;
1334
   parameter clear_value = 0;
1335
   parameter set_value = 1;
1336
   parameter wrap_value = 8;
1337
   parameter level1_value = 15;
1338
   reg  [length:1] qi;
1339
   reg lfsr_fb;
1340
   wire [length:1] q_next;
1341
   reg [32:1] polynom;
1342
   integer i;
1343
   always @ (qi)
1344
   begin
1345
        case (length)
1346
         2: polynom = 32'b11;                               // 0x3
1347
         3: polynom = 32'b110;                              // 0x6
1348
         4: polynom = 32'b1100;                             // 0xC
1349
         5: polynom = 32'b10100;                            // 0x14
1350
         6: polynom = 32'b110000;                           // 0x30
1351
         7: polynom = 32'b1100000;                          // 0x60
1352
         8: polynom = 32'b10111000;                         // 0xb8
1353
         9: polynom = 32'b100010000;                        // 0x110
1354
        10: polynom = 32'b1001000000;                       // 0x240
1355
        11: polynom = 32'b10100000000;                      // 0x500
1356
        12: polynom = 32'b100000101001;                     // 0x829
1357
        13: polynom = 32'b1000000001100;                    // 0x100C
1358
        14: polynom = 32'b10000000010101;                   // 0x2015
1359
        15: polynom = 32'b110000000000000;                  // 0x6000
1360
        16: polynom = 32'b1101000000001000;                 // 0xD008
1361
        17: polynom = 32'b10010000000000000;                // 0x12000
1362
        18: polynom = 32'b100000010000000000;               // 0x20400
1363
        19: polynom = 32'b1000000000000100011;              // 0x40023
1364
        20: polynom = 32'b10000010000000000000;             // 0x82000
1365
        21: polynom = 32'b101000000000000000000;            // 0x140000
1366
        22: polynom = 32'b1100000000000000000000;           // 0x300000
1367
        23: polynom = 32'b10000100000000000000000;          // 0x420000
1368
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
1369
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
1370
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
1371
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
1372
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
1373
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
1374
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
1375
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
1376
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
1377
        default: polynom = 32'b0;
1378
        endcase
1379
        lfsr_fb = qi[length];
1380
        for (i=length-1; i>=1; i=i-1) begin
1381
            if (polynom[i])
1382
                lfsr_fb = lfsr_fb  ~^ qi[i];
1383
        end
1384
    end
1385
   assign q_next = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
1386
   always @ (posedge clk or posedge rst)
1387
     if (rst)
1388
       qi <= {length{1'b0}};
1389
     else
1390
       qi <= q_next;
1391
   always @ (posedge clk or posedge rst)
1392
     if (rst)
1393
       zq <= 1'b1;
1394
     else
1395
       zq <= q_next == {length{1'b0}};
1396
endmodule
1397
//////////////////////////////////////////////////////////////////////
1398
////                                                              ////
1399
////  Versatile counter                                           ////
1400
////                                                              ////
1401
////  Description                                                 ////
1402
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1403
////  counter                                                     ////
1404
////                                                              ////
1405
////  To Do:                                                      ////
1406
////   - add LFSR with more taps                                  ////
1407
////                                                              ////
1408
////  Author(s):                                                  ////
1409
////      - Michael Unneback, unneback@opencores.org              ////
1410
////        ORSoC AB                                              ////
1411
////                                                              ////
1412
//////////////////////////////////////////////////////////////////////
1413
////                                                              ////
1414
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1415
////                                                              ////
1416
//// This source file may be used and distributed without         ////
1417
//// restriction provided that this copyright statement is not    ////
1418
//// removed from the file and that any derivative work contains  ////
1419
//// the original copyright notice and the associated disclaimer. ////
1420
////                                                              ////
1421
//// This source file is free software; you can redistribute it   ////
1422
//// and/or modify it under the terms of the GNU Lesser General   ////
1423
//// Public License as published by the Free Software Foundation; ////
1424
//// either version 2.1 of the License, or (at your option) any   ////
1425
//// later version.                                               ////
1426
////                                                              ////
1427
//// This source is distributed in the hope that it will be       ////
1428
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1429
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1430
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1431
//// details.                                                     ////
1432
////                                                              ////
1433
//// You should have received a copy of the GNU Lesser General    ////
1434
//// Public License along with this source; if not, download it   ////
1435
//// from http://www.opencores.org/lgpl.shtml                     ////
1436
////                                                              ////
1437
//////////////////////////////////////////////////////////////////////
1438
// LFSR counter
1439 18 unneback
module vl_cnt_lfsr_ce_zq ( cke, zq, rst, clk);
1440 6 unneback
   parameter length = 4;
1441
   input cke;
1442
   output reg zq;
1443
   input rst;
1444
   input clk;
1445
   parameter clear_value = 0;
1446
   parameter set_value = 1;
1447
   parameter wrap_value = 8;
1448
   parameter level1_value = 15;
1449
   reg  [length:1] qi;
1450
   reg lfsr_fb;
1451
   wire [length:1] q_next;
1452
   reg [32:1] polynom;
1453
   integer i;
1454
   always @ (qi)
1455
   begin
1456
        case (length)
1457
         2: polynom = 32'b11;                               // 0x3
1458
         3: polynom = 32'b110;                              // 0x6
1459
         4: polynom = 32'b1100;                             // 0xC
1460
         5: polynom = 32'b10100;                            // 0x14
1461
         6: polynom = 32'b110000;                           // 0x30
1462
         7: polynom = 32'b1100000;                          // 0x60
1463
         8: polynom = 32'b10111000;                         // 0xb8
1464
         9: polynom = 32'b100010000;                        // 0x110
1465
        10: polynom = 32'b1001000000;                       // 0x240
1466
        11: polynom = 32'b10100000000;                      // 0x500
1467
        12: polynom = 32'b100000101001;                     // 0x829
1468
        13: polynom = 32'b1000000001100;                    // 0x100C
1469
        14: polynom = 32'b10000000010101;                   // 0x2015
1470
        15: polynom = 32'b110000000000000;                  // 0x6000
1471
        16: polynom = 32'b1101000000001000;                 // 0xD008
1472
        17: polynom = 32'b10010000000000000;                // 0x12000
1473
        18: polynom = 32'b100000010000000000;               // 0x20400
1474
        19: polynom = 32'b1000000000000100011;              // 0x40023
1475
        20: polynom = 32'b10000010000000000000;             // 0x82000
1476
        21: polynom = 32'b101000000000000000000;            // 0x140000
1477
        22: polynom = 32'b1100000000000000000000;           // 0x300000
1478
        23: polynom = 32'b10000100000000000000000;          // 0x420000
1479
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
1480
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
1481
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
1482
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
1483
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
1484
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
1485
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
1486
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
1487
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
1488
        default: polynom = 32'b0;
1489
        endcase
1490
        lfsr_fb = qi[length];
1491
        for (i=length-1; i>=1; i=i-1) begin
1492
            if (polynom[i])
1493
                lfsr_fb = lfsr_fb  ~^ qi[i];
1494
        end
1495
    end
1496
   assign q_next = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
1497
   always @ (posedge clk or posedge rst)
1498
     if (rst)
1499
       qi <= {length{1'b0}};
1500
     else
1501
     if (cke)
1502
       qi <= q_next;
1503
   always @ (posedge clk or posedge rst)
1504
     if (rst)
1505
       zq <= 1'b1;
1506
     else
1507
     if (cke)
1508
       zq <= q_next == {length{1'b0}};
1509
endmodule
1510
//////////////////////////////////////////////////////////////////////
1511
////                                                              ////
1512
////  Versatile counter                                           ////
1513
////                                                              ////
1514
////  Description                                                 ////
1515
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1516
////  counter                                                     ////
1517
////                                                              ////
1518
////  To Do:                                                      ////
1519
////   - add LFSR with more taps                                  ////
1520
////                                                              ////
1521
////  Author(s):                                                  ////
1522
////      - Michael Unneback, unneback@opencores.org              ////
1523
////        ORSoC AB                                              ////
1524
////                                                              ////
1525
//////////////////////////////////////////////////////////////////////
1526
////                                                              ////
1527
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1528
////                                                              ////
1529
//// This source file may be used and distributed without         ////
1530
//// restriction provided that this copyright statement is not    ////
1531
//// removed from the file and that any derivative work contains  ////
1532
//// the original copyright notice and the associated disclaimer. ////
1533
////                                                              ////
1534
//// This source file is free software; you can redistribute it   ////
1535
//// and/or modify it under the terms of the GNU Lesser General   ////
1536
//// Public License as published by the Free Software Foundation; ////
1537
//// either version 2.1 of the License, or (at your option) any   ////
1538
//// later version.                                               ////
1539
////                                                              ////
1540
//// This source is distributed in the hope that it will be       ////
1541
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1542
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1543
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1544
//// details.                                                     ////
1545
////                                                              ////
1546
//// You should have received a copy of the GNU Lesser General    ////
1547
//// Public License along with this source; if not, download it   ////
1548
//// from http://www.opencores.org/lgpl.shtml                     ////
1549
////                                                              ////
1550
//////////////////////////////////////////////////////////////////////
1551
// LFSR counter
1552 27 unneback
module vl_cnt_lfsr_ce_q ( cke, q, rst, clk);
1553
   parameter length = 4;
1554
   input cke;
1555
   output [length:1] q;
1556
   input rst;
1557
   input clk;
1558
   parameter clear_value = 0;
1559
   parameter set_value = 1;
1560
   parameter wrap_value = 8;
1561
   parameter level1_value = 15;
1562
   reg  [length:1] qi;
1563
   reg lfsr_fb;
1564
   wire [length:1] q_next;
1565
   reg [32:1] polynom;
1566
   integer i;
1567
   always @ (qi)
1568
   begin
1569
        case (length)
1570
         2: polynom = 32'b11;                               // 0x3
1571
         3: polynom = 32'b110;                              // 0x6
1572
         4: polynom = 32'b1100;                             // 0xC
1573
         5: polynom = 32'b10100;                            // 0x14
1574
         6: polynom = 32'b110000;                           // 0x30
1575
         7: polynom = 32'b1100000;                          // 0x60
1576
         8: polynom = 32'b10111000;                         // 0xb8
1577
         9: polynom = 32'b100010000;                        // 0x110
1578
        10: polynom = 32'b1001000000;                       // 0x240
1579
        11: polynom = 32'b10100000000;                      // 0x500
1580
        12: polynom = 32'b100000101001;                     // 0x829
1581
        13: polynom = 32'b1000000001100;                    // 0x100C
1582
        14: polynom = 32'b10000000010101;                   // 0x2015
1583
        15: polynom = 32'b110000000000000;                  // 0x6000
1584
        16: polynom = 32'b1101000000001000;                 // 0xD008
1585
        17: polynom = 32'b10010000000000000;                // 0x12000
1586
        18: polynom = 32'b100000010000000000;               // 0x20400
1587
        19: polynom = 32'b1000000000000100011;              // 0x40023
1588
        20: polynom = 32'b10000010000000000000;             // 0x82000
1589
        21: polynom = 32'b101000000000000000000;            // 0x140000
1590
        22: polynom = 32'b1100000000000000000000;           // 0x300000
1591
        23: polynom = 32'b10000100000000000000000;          // 0x420000
1592
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
1593
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
1594
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
1595
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
1596
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
1597
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
1598
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
1599
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
1600
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
1601
        default: polynom = 32'b0;
1602
        endcase
1603
        lfsr_fb = qi[length];
1604
        for (i=length-1; i>=1; i=i-1) begin
1605
            if (polynom[i])
1606
                lfsr_fb = lfsr_fb  ~^ qi[i];
1607
        end
1608
    end
1609
   assign q_next = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
1610
   always @ (posedge clk or posedge rst)
1611
     if (rst)
1612
       qi <= {length{1'b0}};
1613
     else
1614
     if (cke)
1615
       qi <= q_next;
1616
   assign q = qi;
1617
endmodule
1618
//////////////////////////////////////////////////////////////////////
1619
////                                                              ////
1620
////  Versatile counter                                           ////
1621
////                                                              ////
1622
////  Description                                                 ////
1623
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1624
////  counter                                                     ////
1625
////                                                              ////
1626
////  To Do:                                                      ////
1627
////   - add LFSR with more taps                                  ////
1628
////                                                              ////
1629
////  Author(s):                                                  ////
1630
////      - Michael Unneback, unneback@opencores.org              ////
1631
////        ORSoC AB                                              ////
1632
////                                                              ////
1633
//////////////////////////////////////////////////////////////////////
1634
////                                                              ////
1635
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1636
////                                                              ////
1637
//// This source file may be used and distributed without         ////
1638
//// restriction provided that this copyright statement is not    ////
1639
//// removed from the file and that any derivative work contains  ////
1640
//// the original copyright notice and the associated disclaimer. ////
1641
////                                                              ////
1642
//// This source file is free software; you can redistribute it   ////
1643
//// and/or modify it under the terms of the GNU Lesser General   ////
1644
//// Public License as published by the Free Software Foundation; ////
1645
//// either version 2.1 of the License, or (at your option) any   ////
1646
//// later version.                                               ////
1647
////                                                              ////
1648
//// This source is distributed in the hope that it will be       ////
1649
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1650
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1651
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1652
//// details.                                                     ////
1653
////                                                              ////
1654
//// You should have received a copy of the GNU Lesser General    ////
1655
//// Public License along with this source; if not, download it   ////
1656
//// from http://www.opencores.org/lgpl.shtml                     ////
1657
////                                                              ////
1658
//////////////////////////////////////////////////////////////////////
1659
// LFSR counter
1660
module vl_cnt_lfsr_ce_clear_q ( clear, cke, q, rst, clk);
1661
   parameter length = 4;
1662
   input clear;
1663
   input cke;
1664
   output [length:1] q;
1665
   input rst;
1666
   input clk;
1667
   parameter clear_value = 0;
1668
   parameter set_value = 1;
1669
   parameter wrap_value = 8;
1670
   parameter level1_value = 15;
1671
   reg  [length:1] qi;
1672
   reg lfsr_fb;
1673
   wire [length:1] q_next;
1674
   reg [32:1] polynom;
1675
   integer i;
1676
   always @ (qi)
1677
   begin
1678
        case (length)
1679
         2: polynom = 32'b11;                               // 0x3
1680
         3: polynom = 32'b110;                              // 0x6
1681
         4: polynom = 32'b1100;                             // 0xC
1682
         5: polynom = 32'b10100;                            // 0x14
1683
         6: polynom = 32'b110000;                           // 0x30
1684
         7: polynom = 32'b1100000;                          // 0x60
1685
         8: polynom = 32'b10111000;                         // 0xb8
1686
         9: polynom = 32'b100010000;                        // 0x110
1687
        10: polynom = 32'b1001000000;                       // 0x240
1688
        11: polynom = 32'b10100000000;                      // 0x500
1689
        12: polynom = 32'b100000101001;                     // 0x829
1690
        13: polynom = 32'b1000000001100;                    // 0x100C
1691
        14: polynom = 32'b10000000010101;                   // 0x2015
1692
        15: polynom = 32'b110000000000000;                  // 0x6000
1693
        16: polynom = 32'b1101000000001000;                 // 0xD008
1694
        17: polynom = 32'b10010000000000000;                // 0x12000
1695
        18: polynom = 32'b100000010000000000;               // 0x20400
1696
        19: polynom = 32'b1000000000000100011;              // 0x40023
1697
        20: polynom = 32'b10000010000000000000;             // 0x82000
1698
        21: polynom = 32'b101000000000000000000;            // 0x140000
1699
        22: polynom = 32'b1100000000000000000000;           // 0x300000
1700
        23: polynom = 32'b10000100000000000000000;          // 0x420000
1701
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
1702
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
1703
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
1704
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
1705
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
1706
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
1707
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
1708
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
1709
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
1710
        default: polynom = 32'b0;
1711
        endcase
1712
        lfsr_fb = qi[length];
1713
        for (i=length-1; i>=1; i=i-1) begin
1714
            if (polynom[i])
1715
                lfsr_fb = lfsr_fb  ~^ qi[i];
1716
        end
1717
    end
1718
   assign q_next =  clear ? {length{1'b0}} :(qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
1719
   always @ (posedge clk or posedge rst)
1720
     if (rst)
1721
       qi <= {length{1'b0}};
1722
     else
1723
     if (cke)
1724
       qi <= q_next;
1725
   assign q = qi;
1726
endmodule
1727
//////////////////////////////////////////////////////////////////////
1728
////                                                              ////
1729
////  Versatile counter                                           ////
1730
////                                                              ////
1731
////  Description                                                 ////
1732
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1733
////  counter                                                     ////
1734
////                                                              ////
1735
////  To Do:                                                      ////
1736
////   - add LFSR with more taps                                  ////
1737
////                                                              ////
1738
////  Author(s):                                                  ////
1739
////      - Michael Unneback, unneback@opencores.org              ////
1740
////        ORSoC AB                                              ////
1741
////                                                              ////
1742
//////////////////////////////////////////////////////////////////////
1743
////                                                              ////
1744
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1745
////                                                              ////
1746
//// This source file may be used and distributed without         ////
1747
//// restriction provided that this copyright statement is not    ////
1748
//// removed from the file and that any derivative work contains  ////
1749
//// the original copyright notice and the associated disclaimer. ////
1750
////                                                              ////
1751
//// This source file is free software; you can redistribute it   ////
1752
//// and/or modify it under the terms of the GNU Lesser General   ////
1753
//// Public License as published by the Free Software Foundation; ////
1754
//// either version 2.1 of the License, or (at your option) any   ////
1755
//// later version.                                               ////
1756
////                                                              ////
1757
//// This source is distributed in the hope that it will be       ////
1758
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1759
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1760
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1761
//// details.                                                     ////
1762
////                                                              ////
1763
//// You should have received a copy of the GNU Lesser General    ////
1764
//// Public License along with this source; if not, download it   ////
1765
//// from http://www.opencores.org/lgpl.shtml                     ////
1766
////                                                              ////
1767
//////////////////////////////////////////////////////////////////////
1768
// LFSR counter
1769 22 unneback
module vl_cnt_lfsr_ce_q_zq ( cke, q, zq, rst, clk);
1770
   parameter length = 4;
1771
   input cke;
1772
   output [length:1] q;
1773
   output reg zq;
1774
   input rst;
1775
   input clk;
1776
   parameter clear_value = 0;
1777
   parameter set_value = 1;
1778
   parameter wrap_value = 8;
1779
   parameter level1_value = 15;
1780
   reg  [length:1] qi;
1781
   reg lfsr_fb;
1782
   wire [length:1] q_next;
1783
   reg [32:1] polynom;
1784
   integer i;
1785
   always @ (qi)
1786
   begin
1787
        case (length)
1788
         2: polynom = 32'b11;                               // 0x3
1789
         3: polynom = 32'b110;                              // 0x6
1790
         4: polynom = 32'b1100;                             // 0xC
1791
         5: polynom = 32'b10100;                            // 0x14
1792
         6: polynom = 32'b110000;                           // 0x30
1793
         7: polynom = 32'b1100000;                          // 0x60
1794
         8: polynom = 32'b10111000;                         // 0xb8
1795
         9: polynom = 32'b100010000;                        // 0x110
1796
        10: polynom = 32'b1001000000;                       // 0x240
1797
        11: polynom = 32'b10100000000;                      // 0x500
1798
        12: polynom = 32'b100000101001;                     // 0x829
1799
        13: polynom = 32'b1000000001100;                    // 0x100C
1800
        14: polynom = 32'b10000000010101;                   // 0x2015
1801
        15: polynom = 32'b110000000000000;                  // 0x6000
1802
        16: polynom = 32'b1101000000001000;                 // 0xD008
1803
        17: polynom = 32'b10010000000000000;                // 0x12000
1804
        18: polynom = 32'b100000010000000000;               // 0x20400
1805
        19: polynom = 32'b1000000000000100011;              // 0x40023
1806
        20: polynom = 32'b10000010000000000000;             // 0x82000
1807
        21: polynom = 32'b101000000000000000000;            // 0x140000
1808
        22: polynom = 32'b1100000000000000000000;           // 0x300000
1809
        23: polynom = 32'b10000100000000000000000;          // 0x420000
1810
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
1811
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
1812
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
1813
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
1814
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
1815
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
1816
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
1817
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
1818
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
1819
        default: polynom = 32'b0;
1820
        endcase
1821
        lfsr_fb = qi[length];
1822
        for (i=length-1; i>=1; i=i-1) begin
1823
            if (polynom[i])
1824
                lfsr_fb = lfsr_fb  ~^ qi[i];
1825
        end
1826
    end
1827
   assign q_next = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
1828
   always @ (posedge clk or posedge rst)
1829
     if (rst)
1830
       qi <= {length{1'b0}};
1831
     else
1832
     if (cke)
1833
       qi <= q_next;
1834
   assign q = qi;
1835
   always @ (posedge clk or posedge rst)
1836
     if (rst)
1837
       zq <= 1'b1;
1838
     else
1839
     if (cke)
1840
       zq <= q_next == {length{1'b0}};
1841
endmodule
1842
//////////////////////////////////////////////////////////////////////
1843
////                                                              ////
1844
////  Versatile counter                                           ////
1845
////                                                              ////
1846
////  Description                                                 ////
1847
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1848
////  counter                                                     ////
1849
////                                                              ////
1850
////  To Do:                                                      ////
1851
////   - add LFSR with more taps                                  ////
1852
////                                                              ////
1853
////  Author(s):                                                  ////
1854
////      - Michael Unneback, unneback@opencores.org              ////
1855
////        ORSoC AB                                              ////
1856
////                                                              ////
1857
//////////////////////////////////////////////////////////////////////
1858
////                                                              ////
1859
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1860
////                                                              ////
1861
//// This source file may be used and distributed without         ////
1862
//// restriction provided that this copyright statement is not    ////
1863
//// removed from the file and that any derivative work contains  ////
1864
//// the original copyright notice and the associated disclaimer. ////
1865
////                                                              ////
1866
//// This source file is free software; you can redistribute it   ////
1867
//// and/or modify it under the terms of the GNU Lesser General   ////
1868
//// Public License as published by the Free Software Foundation; ////
1869
//// either version 2.1 of the License, or (at your option) any   ////
1870
//// later version.                                               ////
1871
////                                                              ////
1872
//// This source is distributed in the hope that it will be       ////
1873
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1874
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1875
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1876
//// details.                                                     ////
1877
////                                                              ////
1878
//// You should have received a copy of the GNU Lesser General    ////
1879
//// Public License along with this source; if not, download it   ////
1880
//// from http://www.opencores.org/lgpl.shtml                     ////
1881
////                                                              ////
1882
//////////////////////////////////////////////////////////////////////
1883
// LFSR counter
1884 18 unneback
module vl_cnt_lfsr_ce_rew_l1 ( cke, rew, level1, rst, clk);
1885 6 unneback
   parameter length = 4;
1886
   input cke;
1887
   input rew;
1888
   output reg level1;
1889
   input rst;
1890
   input clk;
1891
   parameter clear_value = 0;
1892
   parameter set_value = 1;
1893
   parameter wrap_value = 8;
1894
   parameter level1_value = 15;
1895 29 unneback
   wire clear;
1896 30 unneback
   assign clear = 1'b0;
1897 6 unneback
   reg  [length:1] qi;
1898
   reg lfsr_fb, lfsr_fb_rew;
1899
   wire  [length:1] q_next, q_next_fw, q_next_rew;
1900
   reg [32:1] polynom_rew;
1901
   integer j;
1902
   reg [32:1] polynom;
1903
   integer i;
1904
   always @ (qi)
1905
   begin
1906
        case (length)
1907
         2: polynom = 32'b11;                               // 0x3
1908
         3: polynom = 32'b110;                              // 0x6
1909
         4: polynom = 32'b1100;                             // 0xC
1910
         5: polynom = 32'b10100;                            // 0x14
1911
         6: polynom = 32'b110000;                           // 0x30
1912
         7: polynom = 32'b1100000;                          // 0x60
1913
         8: polynom = 32'b10111000;                         // 0xb8
1914
         9: polynom = 32'b100010000;                        // 0x110
1915
        10: polynom = 32'b1001000000;                       // 0x240
1916
        11: polynom = 32'b10100000000;                      // 0x500
1917
        12: polynom = 32'b100000101001;                     // 0x829
1918
        13: polynom = 32'b1000000001100;                    // 0x100C
1919
        14: polynom = 32'b10000000010101;                   // 0x2015
1920
        15: polynom = 32'b110000000000000;                  // 0x6000
1921
        16: polynom = 32'b1101000000001000;                 // 0xD008
1922
        17: polynom = 32'b10010000000000000;                // 0x12000
1923
        18: polynom = 32'b100000010000000000;               // 0x20400
1924
        19: polynom = 32'b1000000000000100011;              // 0x40023
1925
        20: polynom = 32'b10000010000000000000;             // 0x82000
1926
        21: polynom = 32'b101000000000000000000;            // 0x140000
1927
        22: polynom = 32'b1100000000000000000000;           // 0x300000
1928
        23: polynom = 32'b10000100000000000000000;          // 0x420000
1929
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
1930
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
1931
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
1932
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
1933
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
1934
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
1935
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
1936
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
1937
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
1938
        default: polynom = 32'b0;
1939
        endcase
1940
        lfsr_fb = qi[length];
1941
        for (i=length-1; i>=1; i=i-1) begin
1942
            if (polynom[i])
1943
                lfsr_fb = lfsr_fb  ~^ qi[i];
1944
        end
1945
    end
1946
   assign q_next_fw  = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
1947
   always @ (qi)
1948
   begin
1949
        case (length)
1950
         2: polynom_rew = 32'b11;
1951
         3: polynom_rew = 32'b110;
1952
         4: polynom_rew = 32'b1100;
1953
         5: polynom_rew = 32'b10100;
1954
         6: polynom_rew = 32'b110000;
1955
         7: polynom_rew = 32'b1100000;
1956
         8: polynom_rew = 32'b10111000;
1957
         9: polynom_rew = 32'b100010000;
1958
        10: polynom_rew = 32'b1001000000;
1959
        11: polynom_rew = 32'b10100000000;
1960
        12: polynom_rew = 32'b100000101001;
1961
        13: polynom_rew = 32'b1000000001100;
1962
        14: polynom_rew = 32'b10000000010101;
1963
        15: polynom_rew = 32'b110000000000000;
1964
        16: polynom_rew = 32'b1101000000001000;
1965
        17: polynom_rew = 32'b10010000000000000;
1966
        18: polynom_rew = 32'b100000010000000000;
1967
        19: polynom_rew = 32'b1000000000000100011;
1968
        20: polynom_rew = 32'b10000010000000000000;
1969
        21: polynom_rew = 32'b101000000000000000000;
1970
        22: polynom_rew = 32'b1100000000000000000000;
1971
        23: polynom_rew = 32'b10000100000000000000000;
1972
        24: polynom_rew = 32'b111000010000000000000000;
1973
        25: polynom_rew = 32'b1001000000000000000000000;
1974
        26: polynom_rew = 32'b10000000000000000000100011;
1975
        27: polynom_rew = 32'b100000000000000000000010011;
1976
        28: polynom_rew = 32'b1100100000000000000000000000;
1977
        29: polynom_rew = 32'b10100000000000000000000000000;
1978
        30: polynom_rew = 32'b100000000000000000000000101001;
1979
        31: polynom_rew = 32'b1001000000000000000000000000000;
1980
        32: polynom_rew = 32'b10000000001000000000000000000011;
1981
        default: polynom_rew = 32'b0;
1982
        endcase
1983
        // rotate left
1984
        polynom_rew[length:1] = { polynom_rew[length-2:1],polynom_rew[length] };
1985
        lfsr_fb_rew = qi[length];
1986
        for (i=length-1; i>=1; i=i-1) begin
1987
            if (polynom_rew[i])
1988
                lfsr_fb_rew = lfsr_fb_rew  ~^ qi[i];
1989
        end
1990
    end
1991
   assign q_next_rew = (qi == wrap_value) ? {length{1'b0}} :{lfsr_fb_rew,qi[length:2]};
1992
   assign q_next = rew ? q_next_rew : q_next_fw;
1993
   always @ (posedge clk or posedge rst)
1994
     if (rst)
1995
       qi <= {length{1'b0}};
1996
     else
1997
     if (cke)
1998
       qi <= q_next;
1999
    always @ (posedge clk or posedge rst)
2000
    if (rst)
2001
        level1 <= 1'b0;
2002
    else
2003
    if (cke)
2004 29 unneback
    if (clear)
2005
        level1 <= 1'b0;
2006
    else if (q_next == level1_value)
2007 6 unneback
        level1 <= 1'b1;
2008
    else if (qi == level1_value & rew)
2009
        level1 <= 1'b0;
2010
endmodule
2011
//////////////////////////////////////////////////////////////////////
2012
////                                                              ////
2013
////  Versatile counter                                           ////
2014
////                                                              ////
2015
////  Description                                                 ////
2016
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2017
////  counter                                                     ////
2018
////                                                              ////
2019
////  To Do:                                                      ////
2020
////   - add LFSR with more taps                                  ////
2021
////                                                              ////
2022
////  Author(s):                                                  ////
2023
////      - Michael Unneback, unneback@opencores.org              ////
2024
////        ORSoC AB                                              ////
2025
////                                                              ////
2026
//////////////////////////////////////////////////////////////////////
2027
////                                                              ////
2028
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2029
////                                                              ////
2030
//// This source file may be used and distributed without         ////
2031
//// restriction provided that this copyright statement is not    ////
2032
//// removed from the file and that any derivative work contains  ////
2033
//// the original copyright notice and the associated disclaimer. ////
2034
////                                                              ////
2035
//// This source file is free software; you can redistribute it   ////
2036
//// and/or modify it under the terms of the GNU Lesser General   ////
2037
//// Public License as published by the Free Software Foundation; ////
2038
//// either version 2.1 of the License, or (at your option) any   ////
2039
//// later version.                                               ////
2040
////                                                              ////
2041
//// This source is distributed in the hope that it will be       ////
2042
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2043
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2044
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2045
//// details.                                                     ////
2046
////                                                              ////
2047
//// You should have received a copy of the GNU Lesser General    ////
2048
//// Public License along with this source; if not, download it   ////
2049
//// from http://www.opencores.org/lgpl.shtml                     ////
2050
////                                                              ////
2051
//////////////////////////////////////////////////////////////////////
2052
// GRAY counter
2053 18 unneback
module vl_cnt_gray ( q, rst, clk);
2054 6 unneback
   parameter length = 4;
2055
   output reg [length:1] q;
2056
   input rst;
2057
   input clk;
2058
   parameter clear_value = 0;
2059
   parameter set_value = 1;
2060
   parameter wrap_value = 8;
2061
   parameter level1_value = 15;
2062
   reg  [length:1] qi;
2063
   wire [length:1] q_next;
2064
   assign q_next = qi + {{length-1{1'b0}},1'b1};
2065
   always @ (posedge clk or posedge rst)
2066
     if (rst)
2067
       qi <= {length{1'b0}};
2068
     else
2069
       qi <= q_next;
2070
   always @ (posedge clk or posedge rst)
2071
     if (rst)
2072
       q <= {length{1'b0}};
2073
     else
2074
         q <= (q_next>>1) ^ q_next;
2075
endmodule
2076
//////////////////////////////////////////////////////////////////////
2077
////                                                              ////
2078
////  Versatile counter                                           ////
2079
////                                                              ////
2080
////  Description                                                 ////
2081
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2082
////  counter                                                     ////
2083
////                                                              ////
2084
////  To Do:                                                      ////
2085
////   - add LFSR with more taps                                  ////
2086
////                                                              ////
2087
////  Author(s):                                                  ////
2088
////      - Michael Unneback, unneback@opencores.org              ////
2089
////        ORSoC AB                                              ////
2090
////                                                              ////
2091
//////////////////////////////////////////////////////////////////////
2092
////                                                              ////
2093
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2094
////                                                              ////
2095
//// This source file may be used and distributed without         ////
2096
//// restriction provided that this copyright statement is not    ////
2097
//// removed from the file and that any derivative work contains  ////
2098
//// the original copyright notice and the associated disclaimer. ////
2099
////                                                              ////
2100
//// This source file is free software; you can redistribute it   ////
2101
//// and/or modify it under the terms of the GNU Lesser General   ////
2102
//// Public License as published by the Free Software Foundation; ////
2103
//// either version 2.1 of the License, or (at your option) any   ////
2104
//// later version.                                               ////
2105
////                                                              ////
2106
//// This source is distributed in the hope that it will be       ////
2107
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2108
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2109
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2110
//// details.                                                     ////
2111
////                                                              ////
2112
//// You should have received a copy of the GNU Lesser General    ////
2113
//// Public License along with this source; if not, download it   ////
2114
//// from http://www.opencores.org/lgpl.shtml                     ////
2115
////                                                              ////
2116
//////////////////////////////////////////////////////////////////////
2117
// GRAY counter
2118 18 unneback
module vl_cnt_gray_ce ( cke, q, rst, clk);
2119 6 unneback
   parameter length = 4;
2120
   input cke;
2121
   output reg [length:1] q;
2122
   input rst;
2123
   input clk;
2124
   parameter clear_value = 0;
2125
   parameter set_value = 1;
2126
   parameter wrap_value = 8;
2127
   parameter level1_value = 15;
2128
   reg  [length:1] qi;
2129
   wire [length:1] q_next;
2130
   assign q_next = qi + {{length-1{1'b0}},1'b1};
2131
   always @ (posedge clk or posedge rst)
2132
     if (rst)
2133
       qi <= {length{1'b0}};
2134
     else
2135
     if (cke)
2136
       qi <= q_next;
2137
   always @ (posedge clk or posedge rst)
2138
     if (rst)
2139
       q <= {length{1'b0}};
2140
     else
2141
       if (cke)
2142
         q <= (q_next>>1) ^ q_next;
2143
endmodule
2144
//////////////////////////////////////////////////////////////////////
2145
////                                                              ////
2146
////  Versatile counter                                           ////
2147
////                                                              ////
2148
////  Description                                                 ////
2149
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2150
////  counter                                                     ////
2151
////                                                              ////
2152
////  To Do:                                                      ////
2153
////   - add LFSR with more taps                                  ////
2154
////                                                              ////
2155
////  Author(s):                                                  ////
2156
////      - Michael Unneback, unneback@opencores.org              ////
2157
////        ORSoC AB                                              ////
2158
////                                                              ////
2159
//////////////////////////////////////////////////////////////////////
2160
////                                                              ////
2161
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2162
////                                                              ////
2163
//// This source file may be used and distributed without         ////
2164
//// restriction provided that this copyright statement is not    ////
2165
//// removed from the file and that any derivative work contains  ////
2166
//// the original copyright notice and the associated disclaimer. ////
2167
////                                                              ////
2168
//// This source file is free software; you can redistribute it   ////
2169
//// and/or modify it under the terms of the GNU Lesser General   ////
2170
//// Public License as published by the Free Software Foundation; ////
2171
//// either version 2.1 of the License, or (at your option) any   ////
2172
//// later version.                                               ////
2173
////                                                              ////
2174
//// This source is distributed in the hope that it will be       ////
2175
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2176
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2177
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2178
//// details.                                                     ////
2179
////                                                              ////
2180
//// You should have received a copy of the GNU Lesser General    ////
2181
//// Public License along with this source; if not, download it   ////
2182
//// from http://www.opencores.org/lgpl.shtml                     ////
2183
////                                                              ////
2184
//////////////////////////////////////////////////////////////////////
2185
// GRAY counter
2186 18 unneback
module vl_cnt_gray_ce_bin ( cke, q, q_bin, rst, clk);
2187 6 unneback
   parameter length = 4;
2188
   input cke;
2189
   output reg [length:1] q;
2190
   output [length:1] q_bin;
2191
   input rst;
2192
   input clk;
2193
   parameter clear_value = 0;
2194
   parameter set_value = 1;
2195
   parameter wrap_value = 8;
2196
   parameter level1_value = 15;
2197
   reg  [length:1] qi;
2198
   wire [length:1] q_next;
2199
   assign q_next = qi + {{length-1{1'b0}},1'b1};
2200
   always @ (posedge clk or posedge rst)
2201
     if (rst)
2202
       qi <= {length{1'b0}};
2203
     else
2204
     if (cke)
2205
       qi <= q_next;
2206
   always @ (posedge clk or posedge rst)
2207
     if (rst)
2208
       q <= {length{1'b0}};
2209
     else
2210
       if (cke)
2211
         q <= (q_next>>1) ^ q_next;
2212
   assign q_bin = qi;
2213
endmodule
2214
//////////////////////////////////////////////////////////////////////
2215
////                                                              ////
2216
////  Versatile library, counters                                 ////
2217
////                                                              ////
2218
////  Description                                                 ////
2219
////  counters                                                    ////
2220
////                                                              ////
2221
////                                                              ////
2222
////  To Do:                                                      ////
2223
////   - add more counters                                        ////
2224
////                                                              ////
2225
////  Author(s):                                                  ////
2226
////      - Michael Unneback, unneback@opencores.org              ////
2227
////        ORSoC AB                                              ////
2228
////                                                              ////
2229
//////////////////////////////////////////////////////////////////////
2230
////                                                              ////
2231
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
2232
////                                                              ////
2233
//// This source file may be used and distributed without         ////
2234
//// restriction provided that this copyright statement is not    ////
2235
//// removed from the file and that any derivative work contains  ////
2236
//// the original copyright notice and the associated disclaimer. ////
2237
////                                                              ////
2238
//// This source file is free software; you can redistribute it   ////
2239
//// and/or modify it under the terms of the GNU Lesser General   ////
2240
//// Public License as published by the Free Software Foundation; ////
2241
//// either version 2.1 of the License, or (at your option) any   ////
2242
//// later version.                                               ////
2243
////                                                              ////
2244
//// This source is distributed in the hope that it will be       ////
2245
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2246
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2247
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2248
//// details.                                                     ////
2249
////                                                              ////
2250
//// You should have received a copy of the GNU Lesser General    ////
2251
//// Public License along with this source; if not, download it   ////
2252
//// from http://www.opencores.org/lgpl.shtml                     ////
2253
////                                                              ////
2254
//////////////////////////////////////////////////////////////////////
2255 18 unneback
module vl_cnt_shreg_wrap ( q, rst, clk);
2256 6 unneback
   parameter length = 4;
2257
   output reg [0:length-1] q;
2258
   input rst;
2259
   input clk;
2260
    always @ (posedge clk or posedge rst)
2261
    if (rst)
2262
        q <= {1'b1,{length-1{1'b0}}};
2263
    else
2264
        q <= {q[length-1],q[0:length-2]};
2265
endmodule
2266 18 unneback
module vl_cnt_shreg_ce_wrap ( cke, q, rst, clk);
2267 6 unneback
   parameter length = 4;
2268
   input cke;
2269
   output reg [0:length-1] q;
2270
   input rst;
2271
   input clk;
2272
    always @ (posedge clk or posedge rst)
2273
    if (rst)
2274
        q <= {1'b1,{length-1{1'b0}}};
2275
    else
2276
        if (cke)
2277
            q <= {q[length-1],q[0:length-2]};
2278
endmodule
2279 18 unneback
module vl_cnt_shreg_ce_clear ( cke, clear, q, rst, clk);
2280 6 unneback
   parameter length = 4;
2281
   input cke, clear;
2282
   output reg [0:length-1] q;
2283
   input rst;
2284
   input clk;
2285
    always @ (posedge clk or posedge rst)
2286
    if (rst)
2287
        q <= {1'b1,{length-1{1'b0}}};
2288
    else
2289
        if (cke)
2290
            if (clear)
2291
                q <= {1'b1,{length-1{1'b0}}};
2292
            else
2293
                q <= q >> 1;
2294
endmodule
2295 18 unneback
module vl_cnt_shreg_ce_clear_wrap ( cke, clear, q, rst, clk);
2296 6 unneback
   parameter length = 4;
2297
   input cke, clear;
2298
   output reg [0:length-1] q;
2299
   input rst;
2300
   input clk;
2301
    always @ (posedge clk or posedge rst)
2302
    if (rst)
2303
        q <= {1'b1,{length-1{1'b0}}};
2304
    else
2305
        if (cke)
2306
            if (clear)
2307
                q <= {1'b1,{length-1{1'b0}}};
2308
            else
2309
            q <= {q[length-1],q[0:length-2]};
2310
endmodule
2311
//////////////////////////////////////////////////////////////////////
2312
////                                                              ////
2313
////  Versatile library, memories                                 ////
2314
////                                                              ////
2315
////  Description                                                 ////
2316
////  memories                                                    ////
2317
////                                                              ////
2318
////                                                              ////
2319
////  To Do:                                                      ////
2320
////   - add more memory types                                    ////
2321
////                                                              ////
2322
////  Author(s):                                                  ////
2323
////      - Michael Unneback, unneback@opencores.org              ////
2324
////        ORSoC AB                                              ////
2325
////                                                              ////
2326
//////////////////////////////////////////////////////////////////////
2327
////                                                              ////
2328
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
2329
////                                                              ////
2330
//// This source file may be used and distributed without         ////
2331
//// restriction provided that this copyright statement is not    ////
2332
//// removed from the file and that any derivative work contains  ////
2333
//// the original copyright notice and the associated disclaimer. ////
2334
////                                                              ////
2335
//// This source file is free software; you can redistribute it   ////
2336
//// and/or modify it under the terms of the GNU Lesser General   ////
2337
//// Public License as published by the Free Software Foundation; ////
2338
//// either version 2.1 of the License, or (at your option) any   ////
2339
//// later version.                                               ////
2340
////                                                              ////
2341
//// This source is distributed in the hope that it will be       ////
2342
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2343
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2344
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2345
//// details.                                                     ////
2346
////                                                              ////
2347
//// You should have received a copy of the GNU Lesser General    ////
2348
//// Public License along with this source; if not, download it   ////
2349
//// from http://www.opencores.org/lgpl.shtml                     ////
2350
////                                                              ////
2351
//////////////////////////////////////////////////////////////////////
2352
/// ROM
2353 7 unneback
module vl_rom_init ( adr, q, clk);
2354
   parameter data_width = 32;
2355
   parameter addr_width = 8;
2356
   input [(addr_width-1):0]       adr;
2357
   output reg [(data_width-1):0] q;
2358
   input                         clk;
2359
   reg [data_width-1:0] rom [(1<<addr_width)-1:0];
2360
   parameter memory_file = "vl_rom.vmem";
2361
   initial
2362
     begin
2363
        $readmemh(memory_file, rom);
2364
     end
2365
   always @ (posedge clk)
2366
     q <= rom[adr];
2367
endmodule
2368 14 unneback
/*
2369 7 unneback
module vl_rom ( adr, q, clk);
2370 6 unneback
parameter data_width = 32;
2371
parameter addr_width = 4;
2372
parameter [0:1>>addr_width-1] data [data_width-1:0] = {
2373
    {32'h18000000},
2374
    {32'hA8200000},
2375
    {32'hA8200000},
2376
    {32'hA8200000},
2377
    {32'h44003000},
2378
    {32'h15000000},
2379
    {32'h15000000},
2380
    {32'h15000000},
2381
    {32'h15000000},
2382
    {32'h15000000},
2383
    {32'h15000000},
2384
    {32'h15000000},
2385
    {32'h15000000},
2386
    {32'h15000000},
2387
    {32'h15000000},
2388
    {32'h15000000}};
2389 7 unneback
input [addr_width-1:0] adr;
2390 6 unneback
output reg [data_width-1:0] q;
2391
input clk;
2392
always @ (posedge clk)
2393 7 unneback
    q <= data[adr];
2394 6 unneback
endmodule
2395 14 unneback
*/
2396 6 unneback
// Single port RAM
2397
module vl_ram ( d, adr, we, q, clk);
2398
   parameter data_width = 32;
2399
   parameter addr_width = 8;
2400
   input [(data_width-1):0]      d;
2401
   input [(addr_width-1):0]       adr;
2402
   input                         we;
2403 7 unneback
   output reg [(data_width-1):0] q;
2404 6 unneback
   input                         clk;
2405
   reg [data_width-1:0] ram [(1<<addr_width)-1:0];
2406 7 unneback
   parameter init = 0;
2407
   parameter memory_file = "vl_ram.vmem";
2408
   generate if (init) begin : init_mem
2409
   initial
2410
     begin
2411
        $readmemh(memory_file, ram);
2412
     end
2413
   end
2414
   endgenerate
2415 6 unneback
   always @ (posedge clk)
2416
   begin
2417
   if (we)
2418
     ram[adr] <= d;
2419
   q <= ram[adr];
2420
   end
2421
endmodule
2422 7 unneback
module vl_ram_be ( d, adr, be, we, q, clk);
2423
   parameter data_width = 32;
2424
   parameter addr_width = 8;
2425
   input [(data_width-1):0]      d;
2426
   input [(addr_width-1):0]       adr;
2427
   input [(addr_width/4)-1:0]    be;
2428
   input                         we;
2429
   output reg [(data_width-1):0] q;
2430
   input                         clk;
2431
   reg [data_width-1:0] ram [(1<<addr_width)-1:0];
2432
   parameter init = 0;
2433
   parameter memory_file = "vl_ram.vmem";
2434
   generate if (init) begin : init_mem
2435
   initial
2436
     begin
2437
        $readmemh(memory_file, ram);
2438
     end
2439
   end
2440
   endgenerate
2441
   genvar i;
2442
   generate for (i=0;i<addr_width/4;i=i+1) begin : be_ram
2443
      always @ (posedge clk)
2444
      if (we & be[i])
2445
        ram[adr][(i+1)*8-1:i*8] <= d[(i+1)*8-1:i*8];
2446
   end
2447
   endgenerate
2448
   always @ (posedge clk)
2449
      q <= ram[adr];
2450
endmodule
2451 6 unneback
// Dual port RAM
2452
// ACTEL FPGA should not use logic to handle rw collision
2453 7 unneback
module vl_dpram_1r1w ( d_a, adr_a, we_a, clk_a, q_b, adr_b, clk_b );
2454 6 unneback
   parameter data_width = 32;
2455
   parameter addr_width = 8;
2456
   input [(data_width-1):0]      d_a;
2457
   input [(addr_width-1):0]       adr_a;
2458
   input [(addr_width-1):0]       adr_b;
2459
   input                         we_a;
2460
   output [(data_width-1):0]      q_b;
2461
   input                         clk_a, clk_b;
2462
   reg [(addr_width-1):0]         adr_b_reg;
2463
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] ;
2464 7 unneback
   parameter init = 0;
2465
   parameter memory_file = "vl_ram.vmem";
2466
   generate if (init) begin : init_mem
2467
   initial
2468
     begin
2469
        $readmemh(memory_file, ram);
2470
     end
2471
   end
2472
   endgenerate
2473 6 unneback
   always @ (posedge clk_a)
2474
   if (we_a)
2475
     ram[adr_a] <= d_a;
2476
   always @ (posedge clk_b)
2477
   adr_b_reg <= adr_b;
2478
   assign q_b = ram[adr_b_reg];
2479
endmodule
2480 7 unneback
module vl_dpram_2r1w ( d_a, q_a, adr_a, we_a, clk_a, q_b, adr_b, clk_b );
2481 6 unneback
   parameter data_width = 32;
2482
   parameter addr_width = 8;
2483
   input [(data_width-1):0]      d_a;
2484
   input [(addr_width-1):0]       adr_a;
2485
   input [(addr_width-1):0]       adr_b;
2486
   input                         we_a;
2487
   output [(data_width-1):0]      q_b;
2488
   output reg [(data_width-1):0] q_a;
2489
   input                         clk_a, clk_b;
2490
   reg [(data_width-1):0]         q_b;
2491
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] ;
2492 7 unneback
   parameter init = 0;
2493
   parameter memory_file = "vl_ram.vmem";
2494
   generate if (init) begin : init_mem
2495
   initial
2496
     begin
2497
        $readmemh(memory_file, ram);
2498
     end
2499
   end
2500
   endgenerate
2501 6 unneback
   always @ (posedge clk_a)
2502
     begin
2503
        q_a <= ram[adr_a];
2504
        if (we_a)
2505
             ram[adr_a] <= d_a;
2506
     end
2507
   always @ (posedge clk_b)
2508
          q_b <= ram[adr_b];
2509
endmodule
2510 7 unneback
module vl_dpram_2r2w ( d_a, q_a, adr_a, we_a, clk_a, d_b, q_b, adr_b, we_b, clk_b );
2511 6 unneback
   parameter data_width = 32;
2512
   parameter addr_width = 8;
2513
   input [(data_width-1):0]      d_a;
2514
   input [(addr_width-1):0]       adr_a;
2515
   input [(addr_width-1):0]       adr_b;
2516
   input                         we_a;
2517
   output [(data_width-1):0]      q_b;
2518
   input [(data_width-1):0]       d_b;
2519
   output reg [(data_width-1):0] q_a;
2520
   input                         we_b;
2521
   input                         clk_a, clk_b;
2522
   reg [(data_width-1):0]         q_b;
2523
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] ;
2524 7 unneback
   parameter init = 0;
2525
   parameter memory_file = "vl_ram.vmem";
2526
   generate if (init) begin : init_mem
2527
   initial
2528
     begin
2529
        $readmemh(memory_file, ram);
2530
     end
2531
   end
2532
   endgenerate
2533 6 unneback
   always @ (posedge clk_a)
2534
     begin
2535
        q_a <= ram[adr_a];
2536
        if (we_a)
2537
             ram[adr_a] <= d_a;
2538
     end
2539
   always @ (posedge clk_b)
2540
     begin
2541
        q_b <= ram[adr_b];
2542
        if (we_b)
2543
          ram[adr_b] <= d_b;
2544
     end
2545
endmodule
2546
// Content addresable memory, CAM
2547
// FIFO
2548 25 unneback
module vl_fifo_1r1w_fill_level_sync (
2549
    d, wr, fifo_full,
2550
    q, rd, fifo_empty,
2551
    fill_level,
2552
    clk, rst
2553
    );
2554
parameter data_width = 18;
2555
parameter addr_width = 4;
2556
// write side
2557
input  [data_width-1:0] d;
2558
input                   wr;
2559
output                  fifo_full;
2560
// read side
2561
output [data_width-1:0] q;
2562
input                   rd;
2563
output                  fifo_empty;
2564
// common
2565
output [addr_width:0]   fill_level;
2566
input rst, clk;
2567
wire [addr_width:1] wadr, radr;
2568
vl_cnt_bin_ce
2569
    # ( .length(addr_width))
2570
    fifo_wr_adr( .cke(wr), .q(wadr), .rst(rst), .clk(clk));
2571
vl_cnt_bin_ce
2572
    # (.length(addr_width))
2573
    fifo_rd_adr( .cke(rd), .q(radr), .rst(rst), .clk(clk));
2574
vl_dpram_1r1w
2575
    # (.data_width(data_width), .addr_width(addr_width))
2576
    dpram ( .d_a(d), .adr_a(wadr), .we_a(wr), .clk_a(clk), .q_b(q), .adr_b(radr), .clk_b(clk));
2577 31 unneback
vl_cnt_bin_ce_rew_q_zq_l1
2578 27 unneback
    # (.length(addr_width+1), .level1_value(1<<addr_width))
2579 25 unneback
    fill_level_cnt( .cke(rd ^ wr), .rew(rd), .q(fill_level), .zq(fifo_empty), .level1(fifo_full), .rst(rst), .clk(clk));
2580
endmodule
2581 27 unneback
// Intended use is two small FIFOs (RX and TX typically) in one FPGA RAM resource
2582
// RAM is supposed to be larger than the two FIFOs
2583
// LFSR counters used adr pointers
2584
module vl_fifo_2r2w_sync_simplex (
2585
    // a side
2586
    a_d, a_wr, a_fifo_full,
2587
    a_q, a_rd, a_fifo_empty,
2588
    a_fill_level,
2589
    // b side
2590
    b_d, b_wr, b_fifo_full,
2591
    b_q, b_rd, b_fifo_empty,
2592
    b_fill_level,
2593
    // common
2594
    clk, rst
2595
    );
2596
parameter data_width = 8;
2597
parameter addr_width = 5;
2598
parameter fifo_full_level = (1<<addr_width)-1;
2599
// a side
2600
input  [data_width-1:0] a_d;
2601
input                   a_wr;
2602
output                  a_fifo_full;
2603
output [data_width-1:0] a_q;
2604
input                   a_rd;
2605
output                  a_fifo_empty;
2606
output [addr_width-1:0] a_fill_level;
2607
// b side
2608
input  [data_width-1:0] b_d;
2609
input                   b_wr;
2610
output                  b_fifo_full;
2611
output [data_width-1:0] b_q;
2612
input                   b_rd;
2613
output                  b_fifo_empty;
2614
output [addr_width-1:0] b_fill_level;
2615
input                   clk;
2616
input                   rst;
2617
// adr_gen
2618
wire [addr_width:1] a_wadr, a_radr;
2619
wire [addr_width:1] b_wadr, b_radr;
2620
// dpram
2621
wire [addr_width:0] a_dpram_adr, b_dpram_adr;
2622
vl_cnt_lfsr_ce
2623
    # ( .length(addr_width))
2624
    fifo_a_wr_adr( .cke(a_wr), .q(a_wadr), .rst(rst), .clk(clk));
2625
vl_cnt_lfsr_ce
2626
    # (.length(addr_width))
2627
    fifo_a_rd_adr( .cke(a_rd), .q(a_radr), .rst(rst), .clk(clk));
2628
vl_cnt_lfsr_ce
2629
    # ( .length(addr_width))
2630
    fifo_b_wr_adr( .cke(b_wr), .q(b_wadr), .rst(rst), .clk(clk));
2631
vl_cnt_lfsr_ce
2632
    # (.length(addr_width))
2633
    fifo_b_rd_adr( .cke(b_rd), .q(b_radr), .rst(rst), .clk(clk));
2634
// mux read or write adr to DPRAM
2635
assign a_dpram_adr = (a_wr) ? {1'b0,a_wadr} : {1'b1,a_radr};
2636
assign b_dpram_adr = (b_wr) ? {1'b1,b_wadr} : {1'b0,b_radr};
2637
vl_dpram_2r2w
2638
    # (.data_width(data_width), .addr_width(addr_width+1))
2639
    dpram ( .d_a(a_d), .q_a(a_q), .adr_a(a_dpram_adr), .we_a(a_wr), .clk_a(a_clk),
2640
            .d_b(b_d), .q_b(b_q), .adr_b(b_dpram_adr), .we_b(b_wr), .clk_b(b_clk));
2641
vl_cnt_bin_ce_rew_zq_l1
2642 28 unneback
    # (.length(addr_width), .level1_value(fifo_full_level))
2643 27 unneback
    a_fill_level_cnt( .cke(a_rd ^ a_wr), .rew(a_rd), .q(a_fill_level), .zq(a_fifo_empty), .level1(a_fifo_full), .rst(rst), .clk(clk));
2644
vl_cnt_bin_ce_rew_zq_l1
2645 28 unneback
    # (.length(addr_width), .level1_value(fifo_full_level))
2646 27 unneback
    b_fill_level_cnt( .cke(b_rd ^ b_wr), .rew(b_rd), .q(b_fill_level), .zq(b_fifo_empty), .level1(b_fifo_full), .rst(rst), .clk(clk));
2647
endmodule
2648 6 unneback
module vl_fifo_cmp_async ( wptr, rptr, fifo_empty, fifo_full, wclk, rclk, rst );
2649 11 unneback
   parameter addr_width = 4;
2650
   parameter N = addr_width-1;
2651 6 unneback
   parameter Q1 = 2'b00;
2652
   parameter Q2 = 2'b01;
2653
   parameter Q3 = 2'b11;
2654
   parameter Q4 = 2'b10;
2655
   parameter going_empty = 1'b0;
2656
   parameter going_full  = 1'b1;
2657
   input [N:0]  wptr, rptr;
2658 14 unneback
   output       fifo_empty;
2659 6 unneback
   output       fifo_full;
2660
   input        wclk, rclk, rst;
2661
   wire direction;
2662
   reg  direction_set, direction_clr;
2663
   wire async_empty, async_full;
2664
   wire fifo_full2;
2665 14 unneback
   wire fifo_empty2;
2666 6 unneback
   // direction_set
2667
   always @ (wptr[N:N-1] or rptr[N:N-1])
2668
     case ({wptr[N:N-1],rptr[N:N-1]})
2669
       {Q1,Q2} : direction_set <= 1'b1;
2670
       {Q2,Q3} : direction_set <= 1'b1;
2671
       {Q3,Q4} : direction_set <= 1'b1;
2672
       {Q4,Q1} : direction_set <= 1'b1;
2673
       default : direction_set <= 1'b0;
2674
     endcase
2675
   // direction_clear
2676
   always @ (wptr[N:N-1] or rptr[N:N-1] or rst)
2677
     if (rst)
2678
       direction_clr <= 1'b1;
2679
     else
2680
       case ({wptr[N:N-1],rptr[N:N-1]})
2681
         {Q2,Q1} : direction_clr <= 1'b1;
2682
         {Q3,Q2} : direction_clr <= 1'b1;
2683
         {Q4,Q3} : direction_clr <= 1'b1;
2684
         {Q1,Q4} : direction_clr <= 1'b1;
2685
         default : direction_clr <= 1'b0;
2686
       endcase
2687 18 unneback
    vl_dff_sr dff_sr_dir( .aclr(direction_clr), .aset(direction_set), .clock(1'b1), .data(1'b1), .q(direction));
2688 6 unneback
   assign async_empty = (wptr == rptr) && (direction==going_empty);
2689
   assign async_full  = (wptr == rptr) && (direction==going_full);
2690 18 unneback
    vl_dff_sr dff_sr_empty0( .aclr(rst), .aset(async_full), .clock(wclk), .data(async_full), .q(fifo_full2));
2691
    vl_dff_sr dff_sr_empty1( .aclr(rst), .aset(async_full), .clock(wclk), .data(fifo_full2), .q(fifo_full));
2692 6 unneback
/*
2693
   always @ (posedge wclk or posedge rst or posedge async_full)
2694
     if (rst)
2695
       {fifo_full, fifo_full2} <= 2'b00;
2696
     else if (async_full)
2697
       {fifo_full, fifo_full2} <= 2'b11;
2698
     else
2699
       {fifo_full, fifo_full2} <= {fifo_full2, async_full};
2700
*/
2701 14 unneback
/*   always @ (posedge rclk or posedge async_empty)
2702 6 unneback
     if (async_empty)
2703
       {fifo_empty, fifo_empty2} <= 2'b11;
2704
     else
2705 14 unneback
       {fifo_empty,fifo_empty2} <= {fifo_empty2,async_empty}; */
2706 18 unneback
    vl_dff # ( .reset_value(1'b1)) dff0 ( .d(async_empty), .q(fifo_empty2), .clk(rclk), .rst(async_empty));
2707
    vl_dff # ( .reset_value(1'b1)) dff1 ( .d(fifo_empty2), .q(fifo_empty),  .clk(rclk), .rst(async_empty));
2708 27 unneback
endmodule // async_compb
2709 6 unneback
module vl_fifo_1r1w_async (
2710
    d, wr, fifo_full, wr_clk, wr_rst,
2711
    q, rd, fifo_empty, rd_clk, rd_rst
2712
    );
2713
parameter data_width = 18;
2714
parameter addr_width = 4;
2715
// write side
2716
input  [data_width-1:0] d;
2717
input                   wr;
2718
output                  fifo_full;
2719
input                   wr_clk;
2720
input                   wr_rst;
2721
// read side
2722
output [data_width-1:0] q;
2723
input                   rd;
2724
output                  fifo_empty;
2725
input                   rd_clk;
2726
input                   rd_rst;
2727
wire [addr_width:1] wadr, wadr_bin, radr, radr_bin;
2728 18 unneback
vl_cnt_gray_ce_bin
2729 6 unneback
    # ( .length(addr_width))
2730
    fifo_wr_adr( .cke(wr), .q(wadr), .q_bin(wadr_bin), .rst(wr_rst), .clk(wr_clk));
2731 18 unneback
vl_cnt_gray_ce_bin
2732 6 unneback
    # (.length(addr_width))
2733 23 unneback
    fifo_rd_adr( .cke(rd), .q(radr), .q_bin(radr_bin), .rst(rd_rst), .clk(rd_clk));
2734 7 unneback
vl_dpram_1r1w
2735 6 unneback
    # (.data_width(data_width), .addr_width(addr_width))
2736
    dpram ( .d_a(d), .adr_a(wadr_bin), .we_a(wr), .clk_a(wr_clk), .q_b(q), .adr_b(radr_bin), .clk_b(rd_clk));
2737
vl_fifo_cmp_async
2738
    # (.addr_width(addr_width))
2739
    cmp ( .wptr(wadr), .rptr(radr), .fifo_empty(fifo_empty), .fifo_full(fifo_full), .wclk(wr_clk), .rclk(rd_clk), .rst(wr_rst) );
2740
endmodule
2741 8 unneback
module vl_fifo_2r2w_async (
2742 6 unneback
    // a side
2743
    a_d, a_wr, a_fifo_full,
2744
    a_q, a_rd, a_fifo_empty,
2745
    a_clk, a_rst,
2746
    // b side
2747
    b_d, b_wr, b_fifo_full,
2748
    b_q, b_rd, b_fifo_empty,
2749
    b_clk, b_rst
2750
    );
2751
parameter data_width = 18;
2752
parameter addr_width = 4;
2753
// a side
2754
input  [data_width-1:0] a_d;
2755
input                   a_wr;
2756
output                  a_fifo_full;
2757
output [data_width-1:0] a_q;
2758
input                   a_rd;
2759
output                  a_fifo_empty;
2760
input                   a_clk;
2761
input                   a_rst;
2762
// b side
2763
input  [data_width-1:0] b_d;
2764
input                   b_wr;
2765
output                  b_fifo_full;
2766
output [data_width-1:0] b_q;
2767
input                   b_rd;
2768
output                  b_fifo_empty;
2769
input                   b_clk;
2770
input                   b_rst;
2771
vl_fifo_1r1w_async # (.data_width(data_width), .addr_width(addr_width))
2772
vl_fifo_1r1w_async_a (
2773
    .d(a_d), .wr(a_wr), .fifo_full(a_fifo_full), .wr_clk(a_clk), .wr_rst(a_rst),
2774
    .q(b_q), .rd(b_rd), .fifo_empty(b_fifo_empty), .rd_clk(b_clk), .rd_rst(b_rst)
2775
    );
2776
vl_fifo_1r1w_async # (.data_width(data_width), .addr_width(addr_width))
2777
vl_fifo_1r1w_async_b (
2778
    .d(b_d), .wr(b_wr), .fifo_full(b_fifo_full), .wr_clk(b_clk), .wr_rst(b_rst),
2779
    .q(a_q), .rd(a_rd), .fifo_empty(a_fifo_empty), .rd_clk(a_clk), .rd_rst(a_rst)
2780
    );
2781
endmodule
2782 8 unneback
module vl_fifo_2r2w_async_simplex (
2783 6 unneback
    // a side
2784
    a_d, a_wr, a_fifo_full,
2785
    a_q, a_rd, a_fifo_empty,
2786
    a_clk, a_rst,
2787
    // b side
2788
    b_d, b_wr, b_fifo_full,
2789
    b_q, b_rd, b_fifo_empty,
2790
    b_clk, b_rst
2791
    );
2792
parameter data_width = 18;
2793
parameter addr_width = 4;
2794
// a side
2795
input  [data_width-1:0] a_d;
2796
input                   a_wr;
2797
output                  a_fifo_full;
2798
output [data_width-1:0] a_q;
2799
input                   a_rd;
2800
output                  a_fifo_empty;
2801
input                   a_clk;
2802
input                   a_rst;
2803
// b side
2804
input  [data_width-1:0] b_d;
2805
input                   b_wr;
2806
output                  b_fifo_full;
2807
output [data_width-1:0] b_q;
2808
input                   b_rd;
2809
output                  b_fifo_empty;
2810
input                   b_clk;
2811
input                   b_rst;
2812
// adr_gen
2813
wire [addr_width:1] a_wadr, a_wadr_bin, a_radr, a_radr_bin;
2814
wire [addr_width:1] b_wadr, b_wadr_bin, b_radr, b_radr_bin;
2815
// dpram
2816
wire [addr_width:0] a_dpram_adr, b_dpram_adr;
2817 18 unneback
vl_cnt_gray_ce_bin
2818 6 unneback
    # ( .length(addr_width))
2819
    fifo_a_wr_adr( .cke(a_wr), .q(a_wadr), .q_bin(a_wadr_bin), .rst(a_rst), .clk(a_clk));
2820 18 unneback
vl_cnt_gray_ce_bin
2821 6 unneback
    # (.length(addr_width))
2822
    fifo_a_rd_adr( .cke(a_rd), .q(a_radr), .q_bin(a_radr_bin), .rst(a_rst), .clk(a_clk));
2823 18 unneback
vl_cnt_gray_ce_bin
2824 6 unneback
    # ( .length(addr_width))
2825
    fifo_b_wr_adr( .cke(b_wr), .q(b_wadr), .q_bin(b_wadr_bin), .rst(b_rst), .clk(b_clk));
2826 18 unneback
vl_cnt_gray_ce_bin
2827 6 unneback
    # (.length(addr_width))
2828
    fifo_b_rd_adr( .cke(b_rd), .q(b_radr), .q_bin(b_radr_bin), .rst(b_rst), .clk(b_clk));
2829
// mux read or write adr to DPRAM
2830
assign a_dpram_adr = (a_wr) ? {1'b0,a_wadr_bin} : {1'b1,a_radr_bin};
2831
assign b_dpram_adr = (b_wr) ? {1'b1,b_wadr_bin} : {1'b0,b_radr_bin};
2832 11 unneback
vl_dpram_2r2w
2833 6 unneback
    # (.data_width(data_width), .addr_width(addr_width+1))
2834
    dpram ( .d_a(a_d), .q_a(a_q), .adr_a(a_dpram_adr), .we_a(a_wr), .clk_a(a_clk),
2835
            .d_b(b_d), .q_b(b_q), .adr_b(b_dpram_adr), .we_b(b_wr), .clk_b(b_clk));
2836 11 unneback
vl_fifo_cmp_async
2837 6 unneback
    # (.addr_width(addr_width))
2838
    cmp1 ( .wptr(a_wadr), .rptr(b_radr), .fifo_empty(b_fifo_empty), .fifo_full(a_fifo_full), .wclk(a_clk), .rclk(b_clk), .rst(a_rst) );
2839 11 unneback
vl_fifo_cmp_async
2840 6 unneback
    # (.addr_width(addr_width))
2841
    cmp2 ( .wptr(b_wadr), .rptr(a_radr), .fifo_empty(a_fifo_empty), .fifo_full(b_fifo_full), .wclk(b_clk), .rclk(a_clk), .rst(b_rst) );
2842
endmodule
2843 12 unneback
//////////////////////////////////////////////////////////////////////
2844
////                                                              ////
2845
////  Versatile library, wishbone stuff                           ////
2846
////                                                              ////
2847
////  Description                                                 ////
2848
////  Wishbone compliant modules                                  ////
2849
////                                                              ////
2850
////                                                              ////
2851
////  To Do:                                                      ////
2852
////   -                                                          ////
2853
////                                                              ////
2854
////  Author(s):                                                  ////
2855
////      - Michael Unneback, unneback@opencores.org              ////
2856
////        ORSoC AB                                              ////
2857
////                                                              ////
2858
//////////////////////////////////////////////////////////////////////
2859
////                                                              ////
2860
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
2861
////                                                              ////
2862
//// This source file may be used and distributed without         ////
2863
//// restriction provided that this copyright statement is not    ////
2864
//// removed from the file and that any derivative work contains  ////
2865
//// the original copyright notice and the associated disclaimer. ////
2866
////                                                              ////
2867
//// This source file is free software; you can redistribute it   ////
2868
//// and/or modify it under the terms of the GNU Lesser General   ////
2869
//// Public License as published by the Free Software Foundation; ////
2870
//// either version 2.1 of the License, or (at your option) any   ////
2871
//// later version.                                               ////
2872
////                                                              ////
2873
//// This source is distributed in the hope that it will be       ////
2874
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2875
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2876
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2877
//// details.                                                     ////
2878
////                                                              ////
2879
//// You should have received a copy of the GNU Lesser General    ////
2880
//// Public License along with this source; if not, download it   ////
2881
//// from http://www.opencores.org/lgpl.shtml                     ////
2882
////                                                              ////
2883
//////////////////////////////////////////////////////////////////////
2884
// async wb3 - wb3 bridge
2885
`timescale 1ns/1ns
2886 18 unneback
module vl_wb3wb3_bridge (
2887 12 unneback
        // wishbone slave side
2888
        wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_bte_i, wbs_cti_i, wbs_we_i, wbs_cyc_i, wbs_stb_i, wbs_dat_o, wbs_ack_o, wbs_clk, wbs_rst,
2889
        // wishbone master side
2890
        wbm_dat_o, wbm_adr_o, wbm_sel_o, wbm_bte_o, wbm_cti_o, wbm_we_o, wbm_cyc_o, wbm_stb_o, wbm_dat_i, wbm_ack_i, wbm_clk, wbm_rst);
2891
input [31:0] wbs_dat_i;
2892
input [31:2] wbs_adr_i;
2893
input [3:0]  wbs_sel_i;
2894
input [1:0]  wbs_bte_i;
2895
input [2:0]  wbs_cti_i;
2896
input wbs_we_i, wbs_cyc_i, wbs_stb_i;
2897
output [31:0] wbs_dat_o;
2898 14 unneback
output wbs_ack_o;
2899 12 unneback
input wbs_clk, wbs_rst;
2900
output [31:0] wbm_dat_o;
2901
output reg [31:2] wbm_adr_o;
2902
output [3:0]  wbm_sel_o;
2903
output reg [1:0]  wbm_bte_o;
2904
output reg [2:0]  wbm_cti_o;
2905 14 unneback
output reg wbm_we_o;
2906
output wbm_cyc_o;
2907 12 unneback
output wbm_stb_o;
2908
input [31:0]  wbm_dat_i;
2909
input wbm_ack_i;
2910
input wbm_clk, wbm_rst;
2911
parameter addr_width = 4;
2912
// bte
2913
parameter linear       = 2'b00;
2914
parameter wrap4        = 2'b01;
2915
parameter wrap8        = 2'b10;
2916
parameter wrap16       = 2'b11;
2917
// cti
2918
parameter classic      = 3'b000;
2919
parameter incburst     = 3'b010;
2920
parameter endofburst   = 3'b111;
2921
parameter wbs_adr  = 1'b0;
2922
parameter wbs_data = 1'b1;
2923 33 unneback
parameter wbm_adr0      = 2'b00;
2924
parameter wbm_adr1      = 2'b01;
2925
parameter wbm_data      = 2'b10;
2926
parameter wbm_data_wait = 2'b11;
2927 12 unneback
reg [1:0] wbs_bte_reg;
2928
reg wbs;
2929
wire wbs_eoc_alert, wbm_eoc_alert;
2930
reg wbs_eoc, wbm_eoc;
2931
reg [1:0] wbm;
2932 14 unneback
wire [1:16] wbs_count, wbm_count;
2933 12 unneback
wire [35:0] a_d, a_q, b_d, b_q;
2934
wire a_wr, a_rd, a_fifo_full, a_fifo_empty, b_wr, b_rd, b_fifo_full, b_fifo_empty;
2935
reg a_rd_reg;
2936
wire b_rd_adr, b_rd_data;
2937 14 unneback
wire b_rd_data_reg;
2938
wire [35:0] temp;
2939 12 unneback
assign wbs_eoc_alert = (wbs_bte_reg==wrap4 & wbs_count[3]) | (wbs_bte_reg==wrap8 & wbs_count[7]) | (wbs_bte_reg==wrap16 & wbs_count[15]);
2940
always @ (posedge wbs_clk or posedge wbs_rst)
2941
if (wbs_rst)
2942
        wbs_eoc <= 1'b0;
2943
else
2944
        if (wbs==wbs_adr & wbs_stb_i & !a_fifo_full)
2945
                wbs_eoc <= wbs_bte_i==linear;
2946
        else if (wbs_eoc_alert & (a_rd | a_wr))
2947
                wbs_eoc <= 1'b1;
2948 18 unneback
vl_cnt_shreg_ce_clear # ( .length(16))
2949 12 unneback
    cnt0 (
2950
        .cke(wbs_ack_o),
2951
        .clear(wbs_eoc),
2952
        .q(wbs_count),
2953
        .rst(wbs_rst),
2954
        .clk(wbs_clk));
2955
always @ (posedge wbs_clk or posedge wbs_rst)
2956
if (wbs_rst)
2957
        wbs <= wbs_adr;
2958
else
2959
        if ((wbs==wbs_adr) & wbs_cyc_i & wbs_stb_i & !a_fifo_full)
2960
                wbs <= wbs_data;
2961
        else if (wbs_eoc & wbs_ack_o)
2962
                wbs <= wbs_adr;
2963
// wbs FIFO
2964
assign a_d = (wbs==wbs_adr) ? {wbs_adr_i[31:2],wbs_we_i,wbs_bte_i,wbs_cti_i} : {wbs_dat_i,wbs_sel_i};
2965
assign a_wr = (wbs==wbs_adr)  ? wbs_cyc_i & wbs_stb_i & !a_fifo_full :
2966
              (wbs==wbs_data) ? wbs_we_i  & wbs_stb_i & !a_fifo_full :
2967
              1'b0;
2968
assign a_rd = !a_fifo_empty;
2969
always @ (posedge wbs_clk or posedge wbs_rst)
2970
if (wbs_rst)
2971
        a_rd_reg <= 1'b0;
2972
else
2973
        a_rd_reg <= a_rd;
2974
assign wbs_ack_o = a_rd_reg | (a_wr & wbs==wbs_data);
2975
assign wbs_dat_o = a_q[35:4];
2976
always @ (posedge wbs_clk or posedge wbs_rst)
2977
if (wbs_rst)
2978 13 unneback
        wbs_bte_reg <= 2'b00;
2979 12 unneback
else
2980 13 unneback
        wbs_bte_reg <= wbs_bte_i;
2981 12 unneback
// wbm FIFO
2982
assign wbm_eoc_alert = (wbm_bte_o==wrap4 & wbm_count[3]) | (wbm_bte_o==wrap8 & wbm_count[7]) | (wbm_bte_o==wrap16 & wbm_count[15]);
2983
always @ (posedge wbm_clk or posedge wbm_rst)
2984
if (wbm_rst)
2985
        wbm_eoc <= 1'b0;
2986
else
2987
        if (wbm==wbm_adr0 & !b_fifo_empty)
2988
                wbm_eoc <= b_q[4:3] == linear;
2989
        else if (wbm_eoc_alert & wbm_ack_i)
2990
                wbm_eoc <= 1'b1;
2991
always @ (posedge wbm_clk or posedge wbm_rst)
2992
if (wbm_rst)
2993
        wbm <= wbm_adr0;
2994
else
2995 33 unneback
/*
2996 12 unneback
    if ((wbm==wbm_adr0 & !b_fifo_empty) |
2997
        (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) |
2998
        (wbm==wbm_adr1 & !wbm_we_o) |
2999
        (wbm==wbm_data & wbm_ack_i & wbm_eoc))
3000
        wbm <= {wbm[0],!(wbm[1] ^ wbm[0])};  // count sequence 00,01,10
3001 33 unneback
*/
3002
    case (wbm)
3003
    wbm_adr0:
3004
        if (!b_fifo_empty)
3005
            wbm <= wbm_adr1;
3006
    wbm_adr1:
3007
        if (!wbm_we_o | (!b_fifo_empty & wbm_we_o))
3008
            wbm <= wbm_data;
3009
    wbm_data:
3010
        if (wbm_ack_i & wbm_eoc)
3011
            wbm <= wbm_adr0;
3012
        else if (b_fifo_empty & wbm_we_o & wbm_ack_i)
3013
            wbm <= wbm_data_wait;
3014
    wbm_data_wait:
3015
        if (!b_fifo_empty)
3016
            wbm <= wbm_data;
3017
    endcase
3018 12 unneback
assign b_d = {wbm_dat_i,4'b1111};
3019
assign b_wr = !wbm_we_o & wbm_ack_i;
3020
assign b_rd_adr  = (wbm==wbm_adr0 & !b_fifo_empty);
3021
assign b_rd_data = (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) ? 1'b1 : // b_q[`WE]
3022
                   (wbm==wbm_data & !b_fifo_empty & wbm_we_o & wbm_ack_i & !wbm_eoc) ? 1'b1 :
3023 33 unneback
                   (wbm==wbm_data_wait & !b_fifo_empty) ? 1'b1 :
3024 12 unneback
                   1'b0;
3025
assign b_rd = b_rd_adr | b_rd_data;
3026 18 unneback
vl_dff dff1 ( .d(b_rd_data), .q(b_rd_data_reg), .clk(wbm_clk), .rst(wbm_rst));
3027
vl_dff_ce # ( .width(36)) dff2 ( .d(b_q), .ce(b_rd_data_reg), .q(temp), .clk(wbm_clk), .rst(wbm_rst));
3028 12 unneback
assign {wbm_dat_o,wbm_sel_o} = (b_rd_data_reg) ? b_q : temp;
3029 18 unneback
vl_cnt_shreg_ce_clear # ( .length(16))
3030 12 unneback
    cnt1 (
3031
        .cke(wbm_ack_i),
3032
        .clear(wbm_eoc),
3033
        .q(wbm_count),
3034
        .rst(wbm_rst),
3035
        .clk(wbm_clk));
3036 33 unneback
assign wbm_cyc_o = (wbm==wbm_data | wbm==wbm_data_wait);
3037
assign wbm_stb_o = (wbm==wbm_data);
3038 12 unneback
always @ (posedge wbm_clk or posedge wbm_rst)
3039
if (wbm_rst)
3040
        {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= {30'h0,1'b0,linear,classic};
3041
else begin
3042
        if (wbm==wbm_adr0 & !b_fifo_empty)
3043
                {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= b_q;
3044
        else if (wbm_eoc_alert & wbm_ack_i)
3045
                wbm_cti_o <= endofburst;
3046
end
3047
//async_fifo_dw_simplex_top
3048
vl_fifo_2r2w_async_simplex
3049
# ( .data_width(36), .addr_width(addr_width))
3050
fifo (
3051
    // a side
3052
    .a_d(a_d),
3053
    .a_wr(a_wr),
3054
    .a_fifo_full(a_fifo_full),
3055
    .a_q(a_q),
3056
    .a_rd(a_rd),
3057
    .a_fifo_empty(a_fifo_empty),
3058
    .a_clk(wbs_clk),
3059
    .a_rst(wbs_rst),
3060
    // b side
3061
    .b_d(b_d),
3062
    .b_wr(b_wr),
3063
    .b_fifo_full(b_fifo_full),
3064
    .b_q(b_q),
3065
    .b_rd(b_rd),
3066
    .b_fifo_empty(b_fifo_empty),
3067
    .b_clk(wbm_clk),
3068
    .b_rst(wbm_rst)
3069
    );
3070
endmodule
3071 17 unneback
// WB ROM
3072 18 unneback
module vl_wb_boot_rom (
3073 17 unneback
    wb_adr_i, wb_stb_i, wb_cyc_i,
3074 18 unneback
    wb_dat_o, wb_ack_o, hit_o, wb_clk, wb_rst);
3075
    parameter adr_hi = 31;
3076
    parameter adr_lo = 28;
3077
    parameter adr_sel = 4'hf;
3078
    parameter addr_width = 5;
3079 33 unneback
/*
3080
`ifndef BOOT_ROM
3081
`define BOOT_ROM "boot_rom.v"
3082
`endif
3083
*/
3084 18 unneback
    input [adr_hi:2]    wb_adr_i;
3085
    input               wb_stb_i;
3086
    input               wb_cyc_i;
3087
    output [31:0]        wb_dat_o;
3088
    output              wb_ack_o;
3089
    output              hit_o;
3090
    input               wb_clk;
3091
    input               wb_rst;
3092
    wire hit;
3093
    reg [31:0] wb_dat;
3094
    reg wb_ack;
3095
assign hit = wb_adr_i[adr_hi:adr_lo] == adr_sel;
3096 17 unneback
always @ (posedge wb_clk or posedge wb_rst)
3097
    if (wb_rst)
3098 18 unneback
        wb_dat <= 32'h15000000;
3099 17 unneback
    else
3100 18 unneback
         case (wb_adr_i[addr_width-1:2])
3101 33 unneback
`ifdef BOOT_ROM
3102
`include `BOOT_ROM
3103
`endif
3104 17 unneback
           /*
3105
            // Zero r0 and jump to 0x00000100
3106 18 unneback
 
3107
            1 : wb_dat <= 32'hA8200000;
3108
            2 : wb_dat <= 32'hA8C00100;
3109
            3 : wb_dat <= 32'h44003000;
3110
            4 : wb_dat <= 32'h15000000;
3111 17 unneback
            */
3112
           default:
3113 18 unneback
             wb_dat <= 32'h00000000;
3114 17 unneback
         endcase // case (wb_adr_i)
3115
always @ (posedge wb_clk or posedge wb_rst)
3116
    if (wb_rst)
3117 18 unneback
        wb_ack <= 1'b0;
3118 17 unneback
    else
3119 18 unneback
        wb_ack <= wb_stb_i & wb_cyc_i & hit & !wb_ack;
3120
assign hit_o = hit;
3121
assign wb_dat_o = wb_dat & {32{wb_ack}};
3122
assign wb_ack_o = wb_ack;
3123 17 unneback
endmodule
3124 32 unneback
module vl_wb_dpram (
3125
        // wishbone slave side a
3126
        wbsa_dat_i, wbsa_adr_i, wbsa_we_i, wbsa_cyc_i, wbsa_stb_i, wbsa_dat_o, wbsa_ack_o,
3127
        wbsa_clk, wbsa_rst,
3128
        // wishbone slave side a
3129
        wbsb_dat_i, wbsb_adr_i, wbsb_we_i, wbsb_cyc_i, wbsb_stb_i, wbsb_dat_o, wbsb_ack_o,
3130
        wbsb_clk, wbsb_rst);
3131
parameter data_width = 32;
3132
parameter addr_width = 8;
3133
parameter dat_o_mask_a = 1;
3134
parameter dat_o_mask_b = 1;
3135
input [31:0] wbsa_dat_i;
3136
input [addr_width-1:2] wbsa_adr_i;
3137
input wbsa_we_i, wbsa_cyc_i, wbsa_stb_i;
3138
output [31:0] wbsa_dat_o;
3139
output wbsa_ack_o;
3140
input wbsa_clk, wbsa_rst;
3141
input [31:0] wbsb_dat_i;
3142
input [addr_width-1:2] wbsb_adr_i;
3143
input wbsb_we_i, wbsb_cyc_i, wbsb_stb_i;
3144
output [31:0] wbsb_dat_o;
3145
output wbsb_ack_o;
3146
input wbsb_clk, wbsb_rst;
3147
wire wbsa_dat_tmp, wbsb_dat_tmp;
3148
vl_dpram_2r2w # (
3149 33 unneback
    .data_width(data_width), .addr_width(addr_width) )
3150 32 unneback
dpram0(
3151
    .d_a(wbsa_dat_i),
3152
    .q_a(wbsa_dat_tmp),
3153
    .adr_a(wbsa_adr_i),
3154
    .we_a(wbsa_we_i),
3155
    .clk_a(wbsa_clk),
3156
    .d_b(wbsb_dat_i),
3157
    .q_b(wbsb_dat_tmp),
3158
    .adr_b(wbsb_adr_i),
3159
    .we_b(wbsb_we_i),
3160
    .clk_b(wbsb_clk) );
3161 33 unneback
generate if (dat_o_mask_a==1)
3162 32 unneback
    assign wbsa_dat_o = wbsa_dat_tmp & {data_width{wbsa_ack_o}};
3163
endgenerate
3164 33 unneback
generate if (dat_o_mask_a==0)
3165 32 unneback
    assign wbsa_dat_o = wbsa_dat_tmp;
3166
endgenerate
3167 33 unneback
generate if (dat_o_mask_b==1)
3168 32 unneback
    assign wbsb_dat_o = wbsb_dat_tmp & {data_width{wbsb_ack_o}};
3169
endgenerate
3170 33 unneback
generate if (dat_o_mask_b==0)
3171 32 unneback
    assign wbsb_dat_o = wbsb_dat_tmp;
3172
endgenerate
3173
vl_spr ack_a( .sp(wbsa_cyc_i & wbsa_stb_i & !wbsa_ack_o), .r(1'b1), .q(wbsa_ack_o), .clk(wbsa_clk), .rst(wbsa_rst));
3174
vl_spr ack_b( .sp(wbsb_cyc_i & wbsb_stb_i & !wbsb_ack_o), .r(1'b1), .q(wbsb_ack_o), .clk(wbsb_clk), .rst(wbsb_rst));
3175
endmodule
3176 18 unneback
//////////////////////////////////////////////////////////////////////
3177
////                                                              ////
3178
////  Arithmetic functions                                        ////
3179
////                                                              ////
3180
////  Description                                                 ////
3181
////  Arithmetic functions for ALU and DSP                        ////
3182
////                                                              ////
3183
////                                                              ////
3184
////  To Do:                                                      ////
3185
////   -                                                          ////
3186
////                                                              ////
3187
////  Author(s):                                                  ////
3188
////      - Michael Unneback, unneback@opencores.org              ////
3189
////        ORSoC AB                                              ////
3190
////                                                              ////
3191
//////////////////////////////////////////////////////////////////////
3192
////                                                              ////
3193
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
3194
////                                                              ////
3195
//// This source file may be used and distributed without         ////
3196
//// restriction provided that this copyright statement is not    ////
3197
//// removed from the file and that any derivative work contains  ////
3198
//// the original copyright notice and the associated disclaimer. ////
3199
////                                                              ////
3200
//// This source file is free software; you can redistribute it   ////
3201
//// and/or modify it under the terms of the GNU Lesser General   ////
3202
//// Public License as published by the Free Software Foundation; ////
3203
//// either version 2.1 of the License, or (at your option) any   ////
3204
//// later version.                                               ////
3205
////                                                              ////
3206
//// This source is distributed in the hope that it will be       ////
3207
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
3208
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
3209
//// PURPOSE.  See the GNU Lesser General Public License for more ////
3210
//// details.                                                     ////
3211
////                                                              ////
3212
//// You should have received a copy of the GNU Lesser General    ////
3213
//// Public License along with this source; if not, download it   ////
3214
//// from http://www.opencores.org/lgpl.shtml                     ////
3215
////                                                              ////
3216
//////////////////////////////////////////////////////////////////////
3217
// signed multiplication
3218
module vl_mults (a,b,p);
3219
parameter operand_a_width = 18;
3220
parameter operand_b_width = 18;
3221
parameter result_hi = 35;
3222
parameter result_lo = 0;
3223
input [operand_a_width-1:0] a;
3224
input [operand_b_width-1:0] b;
3225
output [result_hi:result_lo] p;
3226
wire signed [operand_a_width-1:0] ai;
3227
wire signed [operand_b_width-1:0] bi;
3228
wire signed [operand_a_width+operand_b_width-1:0] result;
3229
    assign ai = a;
3230
    assign bi = b;
3231
    assign result = ai * bi;
3232
    assign p = result[result_hi:result_lo];
3233
endmodule
3234
module vl_mults18x18 (a,b,p);
3235
input [17:0] a,b;
3236
output [35:0] p;
3237
vl_mult
3238
    # (.operand_a_width(18), .operand_b_width(18))
3239
    mult0 (.a(a), .b(b), .p(p));
3240
endmodule
3241
// unsigned multiplication
3242
module vl_mult (a,b,p);
3243
parameter operand_a_width = 18;
3244
parameter operand_b_width = 18;
3245
parameter result_hi = 35;
3246
parameter result_lo = 0;
3247
input [operand_a_width-1:0] a;
3248
input [operand_b_width-1:0] b;
3249
output [result_hi:result_hi] p;
3250
wire [operand_a_width+operand_b_width-1:0] result;
3251
    assign result = a * b;
3252
    assign p = result[result_hi:result_lo];
3253
endmodule
3254
// shift unit
3255
// supporting the following shift functions
3256
//   SLL
3257
//   SRL
3258
//   SRA
3259
module vl_shift_unit_32( din, s, dout, opcode);
3260
input [31:0] din; // data in operand
3261
input [4:0] s; // shift operand
3262
input [1:0] opcode;
3263
output [31:0] dout;
3264
parameter opcode_sll = 2'b00;
3265
//parameter opcode_srl = 2'b01;
3266
parameter opcode_sra = 2'b10;
3267
//parameter opcode_ror = 2'b11;
3268
wire sll, sra;
3269
assign sll = opcode == opcode_sll;
3270
assign sra = opcode == opcode_sra;
3271
wire [15:1] s1;
3272
wire [3:0] sign;
3273
wire [7:0] tmp [0:3];
3274
// first stage is multiplier based
3275
// shift operand as fractional 8.7
3276
assign s1[15] = sll & s[2:0]==3'd7;
3277
assign s1[14] = sll & s[2:0]==3'd6;
3278
assign s1[13] = sll & s[2:0]==3'd5;
3279
assign s1[12] = sll & s[2:0]==3'd4;
3280
assign s1[11] = sll & s[2:0]==3'd3;
3281
assign s1[10] = sll & s[2:0]==3'd2;
3282
assign s1[ 9] = sll & s[2:0]==3'd1;
3283
assign s1[ 8] = s[2:0]==3'd0;
3284
assign s1[ 7] = !sll & s[2:0]==3'd1;
3285
assign s1[ 6] = !sll & s[2:0]==3'd2;
3286
assign s1[ 5] = !sll & s[2:0]==3'd3;
3287
assign s1[ 4] = !sll & s[2:0]==3'd4;
3288
assign s1[ 3] = !sll & s[2:0]==3'd5;
3289
assign s1[ 2] = !sll & s[2:0]==3'd6;
3290
assign s1[ 1] = !sll & s[2:0]==3'd7;
3291
assign sign[3] = din[31] & sra;
3292
assign sign[2] = sign[3] & (&din[31:24]);
3293
assign sign[1] = sign[2] & (&din[23:16]);
3294
assign sign[0] = sign[1] & (&din[15:8]);
3295
vl_mults # ( .operand_a_width(25), .operand_b_width(16), .result_hi(14), .result_lo(7)) mult_byte3 ( .a({sign[3], {8{sign[3]}},din[31:24], din[23:16]}), .b({1'b0,s1}), .p(tmp[3]));
3296
vl_mults # ( .operand_a_width(25), .operand_b_width(16), .result_hi(14), .result_lo(7)) mult_byte2 ( .a({sign[2], din[31:24]  ,din[23:16],  din[15:8]}), .b({1'b0,s1}), .p(tmp[2]));
3297
vl_mults # ( .operand_a_width(25), .operand_b_width(16), .result_hi(14), .result_lo(7)) mult_byte1 ( .a({sign[1], din[23:16]  ,din[15:8],   din[7:0]}), .b({1'b0,s1}), .p(tmp[1]));
3298
vl_mults # ( .operand_a_width(25), .operand_b_width(16), .result_hi(14), .result_lo(7)) mult_byte0 ( .a({sign[0], din[15:8]   ,din[7:0],    8'h00}),      .b({1'b0,s1}), .p(tmp[0]));
3299
// second stage is multiplexer based
3300
// shift on byte level
3301
// mux byte 3
3302
assign dout[31:24] = (s[4:3]==2'b00) ? tmp[3] :
3303
                     (sll & s[4:3]==2'b01) ? tmp[2] :
3304
                     (sll & s[4:3]==2'b10) ? tmp[1] :
3305
                     (sll & s[4:3]==2'b11) ? tmp[0] :
3306
                     {8{sign[3]}};
3307
// mux byte 2
3308
assign dout[23:16] = (s[4:3]==2'b00) ? tmp[2] :
3309
                     (sll & s[4:3]==2'b01) ? tmp[1] :
3310
                     (sll & s[4:3]==2'b10) ? tmp[0] :
3311
                     (sll & s[4:3]==2'b11) ? {8{1'b0}} :
3312
                     (s[4:3]==2'b01) ? tmp[3] :
3313
                     {8{sign[3]}};
3314
// mux byte 1
3315
assign dout[15:8]  = (s[4:3]==2'b00) ? tmp[1] :
3316
                     (sll & s[4:3]==2'b01) ? tmp[0] :
3317
                     (sll & s[4:3]==2'b10) ? {8{1'b0}} :
3318
                     (sll & s[4:3]==2'b11) ? {8{1'b0}} :
3319
                     (s[4:3]==2'b01) ? tmp[2] :
3320
                     (s[4:3]==2'b10) ? tmp[3] :
3321
                     {8{sign[3]}};
3322
// mux byte 0
3323
assign dout[7:0]   = (s[4:3]==2'b00) ? tmp[0] :
3324
                     (sll) ?  {8{1'b0}}:
3325
                     (s[4:3]==2'b01) ? tmp[1] :
3326
                     (s[4:3]==2'b10) ? tmp[2] :
3327
                     tmp[3];
3328
endmodule
3329
// logic unit
3330
// supporting the following logic functions
3331
//    a and b
3332
//    a or  b
3333
//    a xor b
3334
//    not b
3335
module vl_logic_unit( a, b, result, opcode);
3336
parameter width = 32;
3337
parameter opcode_and = 2'b00;
3338
parameter opcode_or  = 2'b01;
3339
parameter opcode_xor = 2'b10;
3340
input [width-1:0] a,b;
3341
output [width-1:0] result;
3342
input [1:0] opcode;
3343
assign result = (opcode==opcode_and) ? a & b :
3344
                (opcode==opcode_or)  ? a | b :
3345
                (opcode==opcode_xor) ? a ^ b :
3346
                b;
3347
endmodule
3348
module vl_arith_unit ( a, b, c_in, add_sub, sign, result, c_out, z, ovfl);
3349
parameter width = 32;
3350
parameter opcode_add = 1'b0;
3351
parameter opcode_sub = 1'b1;
3352
input [width-1:0] a,b;
3353
input c_in, add_sub, sign;
3354
output [width-1:0] result;
3355
output c_out, z, ovfl;
3356
assign {c_out,result} = {(a[width-1] & sign),a} + ({a[width-1] & sign,b} ^ {(width+1){(add_sub==opcode_sub)}}) + {{(width-1){1'b0}},(c_in | (add_sub==opcode_sub))};
3357
assign z = (result=={width{1'b0}});
3358
assign ovfl = ( a[width-1] &  b[width-1] & ~result[width-1]) |
3359
               (~a[width-1] & ~b[width-1] &  result[width-1]);
3360
endmodule

powered by: WebSVN 2.1.0

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