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

Subversion Repositories versatile_library

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

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

powered by: WebSVN 2.1.0

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