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 64

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

Line No. Rev Author Line
1 40 unneback
`ifndef BASE
2
`define BASE vl_
3
`endif
4
 
5 60 unneback
// default SYN_KEEP definition
6
`define SYN_KEEP /*synthesis syn_keep = 1*/
7
 
8 44 unneback
`ifdef ACTEL
9 60 unneback
`undef SYN_KEEP
10 44 unneback
`define SYN_KEEP /*synthesis syn_keep = 1*/
11
`endif
12
 
13 40 unneback
`ifdef ALL
14
 
15
`define GBUF
16
`define SYNC_RST
17
`define PLL
18
 
19
`define MULTS
20
`define MULTS18X18
21
`define MULT
22
`define SHIFT_UNIT_32
23
`define LOGIC_UNIT
24
 
25
`define CNT_SHREG_WRAP
26
`define CNT_SHREG_CE_WRAP
27
`define CNT_SHREG_CE_CLEAR
28
`define CNT_SHREG_CE_CLEAR_WRAP
29
 
30
`define MUX_ANDOR
31
`define MUX2_ANDOR
32
`define MUX3_ANDOR
33
`define MUX4_ANDOR
34
`define MUX5_ANDOR
35
`define MUX6_ANDOR
36 43 unneback
`define PARITY
37 40 unneback
 
38
`define ROM_INIT
39
`define RAM
40
`define RAM_BE
41
`define DPRAM_1R1W
42
`define DPRAM_2R1W
43
`define DPRAM_2R2W
44
`define FIFO_1R1W_FILL_LEVEL_SYNC
45
`define FIFO_2R2W_SYNC_SIMPLEX
46
`define FIFO_CMP_ASYNC
47
`define FIFO_1R1W_ASYNC
48
`define FIFO_2R2W_ASYNC
49
`define FIFO_2R2W_ASYNC_SIMPLEX
50 48 unneback
`define REG_FILE
51 40 unneback
 
52
`define DFF
53
`define DFF_ARRAY
54
`define DFF_CE
55
`define DFF_CE_CLEAR
56
`define DF_CE_SET
57
`define SPR
58
`define SRP
59
`define DFF_SR
60
`define LATCH
61
`define SHREG
62
`define SHREG_CE
63
`define DELAY
64
`define DELAY_EMPTYFLAG
65
 
66
`define WB3WB3_BRIDGE
67
`define WB3_ARBITER_TYPE1
68 59 unneback
`define WB_B3_RAM_BE
69 49 unneback
`define WB_B4_RAM_BE
70 48 unneback
`define WB_B4_ROM
71 40 unneback
`define WB_BOOT_ROM
72
`define WB_DPRAM
73
 
74 44 unneback
`define IO_DFF_OE
75
`define O_DFF
76
 
77 40 unneback
`endif
78
 
79
`ifdef PLL
80
`ifndef SYNC_RST
81
`define SYNC_RST
82
`endif
83
`endif
84
 
85
`ifdef SYNC_RST
86
`ifndef GBUF
87
`define GBUF
88
`endif
89
`endif
90
 
91
`ifdef WB_DPRAM
92
`ifndef DPRAM_2R2W
93
`define DPRAM_2R2W
94
`endif
95
`ifndef SPR
96
`define SPR
97
`endif
98
`endif
99
 
100 62 unneback
`ifdef WB_B3_RAM_BE
101
`ifndef WB3_ARBITER_TYPE1
102
`define WB3_ARBITER_TYPE1
103
`endif
104
`ifndef RAM_BE
105
`define RAM_BE
106
`endif
107
`endif
108
 
109 40 unneback
`ifdef WB3_ARBITER_TYPE1
110 42 unneback
`ifndef SPR
111
`define SPR
112
`endif
113 40 unneback
`ifndef MUX_ANDOR
114
`define MUX_ANDOR
115
`endif
116
`endif
117
 
118
`ifdef WB3WB3_BRIDGE
119
`ifndef CNT_SHREG_CE_CLEAR
120
`define CNT_SHREG_CE_CLEAR
121
`endif
122
`ifndef DFF
123
`define DFF
124
`endif
125
`ifndef DFF_CE
126
`define DFF_CE
127
`endif
128
`ifndef CNT_SHREG_CE_CLEAR
129
`define CNT_SHREG_CE_CLEAR
130
`endif
131
`ifndef FIFO_2R2W_ASYNC_SIMPLEX
132
`define FIFO_2R2W_ASYNC_SIMPLEX
133
`endif
134
`endif
135
 
136
`ifdef MULTS18X18
137
`ifndef MULTS
138
`define MULTS
139
`endif
140
`endif
141
 
142
`ifdef SHIFT_UNIT_32
143
`ifndef MULTS
144
`define MULTS
145
`endif
146
`endif
147
 
148
`ifdef MUX2_ANDOR
149
`ifndef MUX_ANDOR
150
`define MUX_ANDOR
151
`endif
152
`endif
153
 
154
`ifdef MUX3_ANDOR
155
`ifndef MUX_ANDOR
156
`define MUX_ANDOR
157
`endif
158
`endif
159
 
160
`ifdef MUX4_ANDOR
161
`ifndef MUX_ANDOR
162
`define MUX_ANDOR
163
`endif
164
`endif
165
 
166
`ifdef MUX5_ANDOR
167
`ifndef MUX_ANDOR
168
`define MUX_ANDOR
169
`endif
170
`endif
171
 
172
`ifdef MUX6_ANDOR
173
`ifndef MUX_ANDOR
174
`define MUX_ANDOR
175
`endif
176
`endif
177
 
178
`ifdef FIFO_1R1W_FILL_LEVEL_SYNC
179
`ifndef CNT_BIN_CE
180
`define CNT_BIN_CE
181
`endif
182
`ifndef DPRAM_1R1W
183
`define DPRAM_1R1W
184
`endif
185
`ifndef CNT_BIN_CE_REW_Q_ZQ_L1
186
`define CNT_BIN_CE_REW_Q_ZQ_L1
187
`endif
188
`endif
189
 
190
`ifdef FIFO_1R1W_FILL_LEVEL_SYNC
191
`ifndef CNT_LFSR_CE
192
`define CNT_LFSR_CE
193
`endif
194
`ifndef DPRAM_2R2W
195
`define DPRAM_2R2W
196
`endif
197
`ifndef CNT_BIN_CE_REW_ZQ_L1
198
`define CNT_BIN_CE_REW_ZQ_L1
199
`endif
200
`endif
201
 
202
`ifdef FIFO_2R2W_ASYNC_SIMPLEX
203
`ifndef CNT_GRAY_CE_BIN
204
`define CNT_GRAY_CE_BIN
205
`endif
206
`ifndef DPRAM_2R2W
207
`define DPRAM_2R2W
208
`endif
209
`ifndef FIFO_CMP_ASYNC
210
`define FIFO_CMP_ASYNC
211
`endif
212
`endif
213
 
214
`ifdef FIFO_2R2W_ASYNC
215
`ifndef FIFO_1R1W_ASYNC
216
`define FIFO_1R1W_ASYNC
217
`endif
218
`endif
219
 
220
`ifdef FIFO_1R1W_ASYNC
221
`ifndef CNT_GRAY_CE_BIN
222
`define CNT_GRAY_CE_BIN
223
`endif
224
`ifndef DPRAM_1R1W
225
`define DPRAM_1R1W
226
`endif
227
`ifndef FIFO_CMP_ASYNC
228
`define FIFO_CMP_ASYNC
229
`endif
230
`endif
231
 
232
`ifdef FIFO_CMP_ASYNC
233
`ifndef DFF_SR
234
`define DFF_SR
235
`endif
236
`ifndef DFF
237
`define DFF
238
`endif
239
`endif
240 48 unneback
 
241
`ifdef REG_FILE
242
`ifndef DPRAM_1R1W
243
`define DPRAM_1R1W
244
`endif
245
`endif
246 62 unneback
//////////////////////////////////////////////////////////////////////
247 6 unneback
////                                                              ////
248
////  Versatile library, clock and reset                          ////
249
////                                                              ////
250
////  Description                                                 ////
251
////  Logic related to clock and reset                            ////
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 48 unneback
`ifdef ACTEL
289
`ifdef GBUF
290
`timescale 1 ns/100 ps
291 6 unneback
// Global buffer
292
// usage:
293
// use to enable global buffers for high fan out signals such as clock and reset
294
// Version: 8.4 8.4.0.33
295
module gbuf(GL,CLK);
296
output GL;
297
input  CLK;
298
 
299
    wire GND;
300
 
301
    GND GND_1_net(.Y(GND));
302
    CLKDLY Inst1(.CLK(CLK), .GL(GL), .DLYGL0(GND), .DLYGL1(GND),
303
        .DLYGL2(GND), .DLYGL3(GND), .DLYGL4(GND)) /* synthesis black_box */;
304
 
305
endmodule
306
`timescale 1 ns/1 ns
307 40 unneback
`define MODULE gbuf
308
module `BASE`MODULE ( i, o);
309
`undef MODULE
310 6 unneback
input i;
311
output o;
312
`ifdef SIM_GBUF
313
assign o=i;
314
`else
315
gbuf gbuf_i0 ( .CLK(i), .GL(o));
316
`endif
317
endmodule
318 40 unneback
`endif
319 33 unneback
 
320 6 unneback
`else
321 33 unneback
 
322 40 unneback
`ifdef ALTERA
323
`ifdef GBUF
324 21 unneback
//altera
325 40 unneback
`define MODULE gbuf
326
module `BASE`MODULE ( i, o);
327
`undef MODULE
328 33 unneback
input i;
329
output o;
330
assign o = i;
331
endmodule
332 40 unneback
`endif
333 33 unneback
 
334 6 unneback
`else
335
 
336 40 unneback
`ifdef GBUF
337 6 unneback
`timescale 1 ns/100 ps
338 40 unneback
`define MODULE
339
module `BASE`MODULE ( i, o);
340
`undef MODULE
341 6 unneback
input i;
342
output o;
343
assign o = i;
344
endmodule
345 40 unneback
`endif
346 6 unneback
`endif // ALTERA
347
`endif //ACTEL
348
 
349 40 unneback
`ifdef SYNC_RST
350 6 unneback
// sync reset
351 17 unneback
// input active lo async reset, normally from external reset generator and/or switch
352 6 unneback
// output active high global reset sync with two DFFs 
353
`timescale 1 ns/100 ps
354 40 unneback
`define MODULE sync_rst
355
module `BASE`MODULE ( rst_n_i, rst_o, clk);
356
`undef MODULE
357 6 unneback
input rst_n_i, clk;
358
output rst_o;
359 18 unneback
reg [1:0] tmp;
360 6 unneback
always @ (posedge clk or negedge rst_n_i)
361
if (!rst_n_i)
362 17 unneback
        tmp <= 2'b11;
363 6 unneback
else
364 33 unneback
        tmp <= {1'b0,tmp[1]};
365 40 unneback
`define MODULE gbuf
366
`BASE`MODULE buf_i0( .i(tmp[0]), .o(rst_o));
367
`undef MODULE
368 6 unneback
endmodule
369 40 unneback
`endif
370 6 unneback
 
371 40 unneback
`ifdef PLL
372 6 unneback
// vl_pll
373
`ifdef ACTEL
374 32 unneback
///////////////////////////////////////////////////////////////////////////////
375 17 unneback
`timescale 1 ps/1 ps
376 40 unneback
`define MODULE pll
377
module `BASE`MODULE ( clk_i, rst_n_i, lock, clk_o, rst_o);
378
`undef MODULE
379 6 unneback
parameter index = 0;
380
parameter number_of_clk = 1;
381 17 unneback
parameter period_time_0 = 20000;
382
parameter period_time_1 = 20000;
383
parameter period_time_2 = 20000;
384
parameter lock_delay = 2000000;
385 6 unneback
input clk_i, rst_n_i;
386
output lock;
387
output reg [0:number_of_clk-1] clk_o;
388
output [0:number_of_clk-1] rst_o;
389
 
390
`ifdef SIM_PLL
391
 
392
always
393
     #((period_time_0)/2) clk_o[0] <=  (!rst_n_i) ? 0 : ~clk_o[0];
394
 
395
generate if (number_of_clk > 1)
396
always
397
     #((period_time_1)/2) clk_o[1] <=  (!rst_n_i) ? 0 : ~clk_o[1];
398
endgenerate
399
 
400
generate if (number_of_clk > 2)
401
always
402
     #((period_time_2)/2) clk_o[2] <=  (!rst_n_i) ? 0 : ~clk_o[2];
403
endgenerate
404
 
405
genvar i;
406
generate for (i=0;i<number_of_clk;i=i+1) begin: clock
407
     vl_sync_rst rst_i0 ( .rst_n_i(rst_n_i | lock), .rst_o(rst_o[i]), .clk(clk_o[i]));
408
end
409
endgenerate
410
 
411
assign #lock_delay lock = rst_n_i;
412
 
413
endmodule
414
`else
415
generate if (number_of_clk==1 & index==0) begin
416
        pll0 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]));
417
end
418
endgenerate // index==0
419
generate if (number_of_clk==1 & index==1) begin
420
        pll1 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]));
421
end
422
endgenerate // index==1
423
generate if (number_of_clk==1 & index==2) begin
424
        pll2 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]));
425
end
426
endgenerate // index==2
427
generate if (number_of_clk==1 & index==3) begin
428
        pll3 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]));
429
end
430
endgenerate // index==0
431
 
432
generate if (number_of_clk==2 & index==0) begin
433
        pll0 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]), .GLB(clk_o[1]));
434
end
435
endgenerate // index==0
436
generate if (number_of_clk==2 & index==1) begin
437
        pll1 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]), .GLB(clk_o[1]));
438
end
439
endgenerate // index==1
440
generate if (number_of_clk==2 & index==2) begin
441
        pll2 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]), .GLB(clk_o[1]));
442
end
443
endgenerate // index==2
444
generate if (number_of_clk==2 & index==3) begin
445
        pll3 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]), .GLB(clk_o[1]));
446
end
447
endgenerate // index==0
448
 
449
generate if (number_of_clk==3 & index==0) begin
450
        pll0 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]), .GLB(clk_o[1]), .GLC(clk_o[2]));
451
end
452
endgenerate // index==0
453
generate if (number_of_clk==3 & index==1) begin
454
        pll1 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]), .GLB(clk_o[1]), .GLC(clk_o[2]));
455
end
456
endgenerate // index==1
457
generate if (number_of_clk==3 & index==2) begin
458
        pll2 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]), .GLB(clk_o[1]), .GLC(clk_o[2]));
459
end
460
endgenerate // index==2
461
generate if (number_of_clk==3 & index==3) begin
462
        pll3 pll_i0 (.POWERDOWN(1'b1), .CLKA(clk_i), .LOCK(lock), .GLA(clk_o[0]), .GLB(clk_o[1]), .GLC(clk_o[2]));
463
end
464
endgenerate // index==0
465
 
466
genvar i;
467
generate for (i=0;i<number_of_clk;i=i+1) begin: clock
468 40 unneback
`define MODULE sync_rst
469
        `BASE`MODULE rst_i0 ( .rst_n_i(rst_n_i | lock), .rst_o(rst_o), .clk(clk_o[i]));
470
`undef MODULE
471 6 unneback
end
472
endgenerate
473
endmodule
474
`endif
475 32 unneback
///////////////////////////////////////////////////////////////////////////////
476 6 unneback
 
477
`else
478
 
479 32 unneback
///////////////////////////////////////////////////////////////////////////////
480 6 unneback
`ifdef ALTERA
481
 
482 32 unneback
`timescale 1 ps/1 ps
483 40 unneback
`define MODULE pll
484
module `BASE`MODULE ( clk_i, rst_n_i, lock, clk_o, rst_o);
485
`undef MODULE
486 32 unneback
parameter index = 0;
487
parameter number_of_clk = 1;
488
parameter period_time_0 = 20000;
489
parameter period_time_1 = 20000;
490
parameter period_time_2 = 20000;
491
parameter period_time_3 = 20000;
492
parameter period_time_4 = 20000;
493
parameter lock_delay = 2000000;
494
input clk_i, rst_n_i;
495
output lock;
496
output reg [0:number_of_clk-1] clk_o;
497
output [0:number_of_clk-1] rst_o;
498
 
499
`ifdef SIM_PLL
500
 
501
always
502
     #((period_time_0)/2) clk_o[0] <=  (!rst_n_i) ? 0 : ~clk_o[0];
503
 
504
generate if (number_of_clk > 1)
505
always
506
     #((period_time_1)/2) clk_o[1] <=  (!rst_n_i) ? 0 : ~clk_o[1];
507
endgenerate
508
 
509
generate if (number_of_clk > 2)
510
always
511
     #((period_time_2)/2) clk_o[2] <=  (!rst_n_i) ? 0 : ~clk_o[2];
512
endgenerate
513
 
514 33 unneback
generate if (number_of_clk > 3)
515 32 unneback
always
516
     #((period_time_3)/2) clk_o[3] <=  (!rst_n_i) ? 0 : ~clk_o[3];
517
endgenerate
518
 
519 33 unneback
generate if (number_of_clk > 4)
520 32 unneback
always
521
     #((period_time_4)/2) clk_o[4] <=  (!rst_n_i) ? 0 : ~clk_o[4];
522
endgenerate
523
 
524
genvar i;
525
generate for (i=0;i<number_of_clk;i=i+1) begin: clock
526
     vl_sync_rst rst_i0 ( .rst_n_i(rst_n_i | lock), .rst_o(rst_o[i]), .clk(clk_o[i]));
527
end
528
endgenerate
529
 
530 33 unneback
//assign #lock_delay lock = rst_n_i;
531
assign lock = rst_n_i;
532 32 unneback
 
533
endmodule
534 6 unneback
`else
535
 
536 33 unneback
`ifdef VL_PLL0
537
`ifdef VL_PLL0_CLK1
538
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]));
539
`endif
540
`ifdef VL_PLL0_CLK2
541
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]));
542
`endif
543
`ifdef VL_PLL0_CLK3
544
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]));
545
`endif
546
`ifdef VL_PLL0_CLK4
547
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]));
548
`endif
549
`ifdef VL_PLL0_CLK5
550
    pll0 pll0_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]), .c4(clk_o[4]));
551
`endif
552
`endif
553 32 unneback
 
554 33 unneback
`ifdef VL_PLL1
555
`ifdef VL_PLL1_CLK1
556
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]));
557
`endif
558
`ifdef VL_PLL1_CLK2
559
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]));
560
`endif
561
`ifdef VL_PLL1_CLK3
562
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]));
563
`endif
564
`ifdef VL_PLL1_CLK4
565
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]));
566
`endif
567
`ifdef VL_PLL1_CLK5
568
    pll1 pll1_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]), .c4(clk_o[4]));
569
`endif
570
`endif
571 32 unneback
 
572 33 unneback
`ifdef VL_PLL2
573
`ifdef VL_PLL2_CLK1
574
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]));
575
`endif
576
`ifdef VL_PLL2_CLK2
577
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]));
578
`endif
579
`ifdef VL_PLL2_CLK3
580
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]));
581
`endif
582
`ifdef VL_PLL2_CLK4
583
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]));
584
`endif
585
`ifdef VL_PLL2_CLK5
586
    pll2 pll2_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]), .c4(clk_o[4]));
587
`endif
588
`endif
589 32 unneback
 
590 33 unneback
`ifdef VL_PLL3
591
`ifdef VL_PLL3_CLK1
592
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]));
593
`endif
594
`ifdef VL_PLL3_CLK2
595
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]));
596
`endif
597
`ifdef VL_PLL3_CLK3
598
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]));
599
`endif
600
`ifdef VL_PLL3_CLK4
601
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]));
602
`endif
603
`ifdef VL_PLL3_CLK5
604
    pll3 pll3_i0 (.areset(rst_n_i), .inclk0(clk_i), .locked(lock), .c0(clk_o[0]), .c1(clk_o[1]), .c2(clk_o[2]), .c3(clk_o[3]), .c4(clk_o[4]));
605
`endif
606
`endif
607 32 unneback
 
608
genvar i;
609
generate for (i=0;i<number_of_clk;i=i+1) begin: clock
610 40 unneback
`define MODULE sync_rst
611
        `BASE`MODULE rst_i0 ( .rst_n_i(rst_n_i | lock), .rst_o(rst_o[i]), .clk(clk_o[i]));
612
`undef MODULE
613 32 unneback
end
614
endgenerate
615
endmodule
616
`endif
617
///////////////////////////////////////////////////////////////////////////////
618
 
619
`else
620
 
621 6 unneback
// generic PLL
622 17 unneback
`timescale 1 ps/1 ps
623 40 unneback
`define MODULE pll
624
module `BASE`MODULE ( clk_i, rst_n_i, lock, clk_o, rst_o);
625
`undef MODULE
626 6 unneback
parameter index = 0;
627
parameter number_of_clk = 1;
628 17 unneback
parameter period_time_0 = 20000;
629
parameter period_time_1 = 20000;
630
parameter period_time_2 = 20000;
631 6 unneback
parameter lock_delay = 2000;
632
input clk_i, rst_n_i;
633
output lock;
634
output reg [0:number_of_clk-1] clk_o;
635
output [0:number_of_clk-1] rst_o;
636
 
637
always
638
     #((period_time_0)/2) clk_o[0] <=  (!rst_n_i) ? 0 : ~clk_o[0];
639
 
640
generate if (number_of_clk > 1)
641
always
642
     #((period_time_1)/2) clk_o[1] <=  (!rst_n_i) ? 0 : ~clk_o[1];
643
endgenerate
644
 
645
generate if (number_of_clk > 2)
646
always
647
     #((period_time_2)/2) clk_o[2] <=  (!rst_n_i) ? 0 : ~clk_o[2];
648
endgenerate
649
 
650
genvar i;
651
generate for (i=0;i<number_of_clk;i=i+1) begin: clock
652 40 unneback
`define MODULE sync_rst
653
     `BASE`MODULE rst_i0 ( .rst_n_i(rst_n_i | lock), .rst_o(rst_o[i]), .clk(clk_o[i]));
654
`undef MODULE
655 6 unneback
end
656
endgenerate
657
 
658
assign #lock_delay lock = rst_n_i;
659
 
660
endmodule
661
 
662
`endif //altera
663 17 unneback
`endif //actel
664 40 unneback
`undef MODULE
665
`endif//////////////////////////////////////////////////////////////////////
666 6 unneback
////                                                              ////
667
////  Versatile library, registers                                ////
668
////                                                              ////
669
////  Description                                                 ////
670
////  Different type of registers                                 ////
671
////                                                              ////
672
////                                                              ////
673
////  To Do:                                                      ////
674
////   - add more different registers                             ////
675
////                                                              ////
676
////  Author(s):                                                  ////
677
////      - Michael Unneback, unneback@opencores.org              ////
678
////        ORSoC AB                                              ////
679
////                                                              ////
680
//////////////////////////////////////////////////////////////////////
681
////                                                              ////
682
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
683
////                                                              ////
684
//// This source file may be used and distributed without         ////
685
//// restriction provided that this copyright statement is not    ////
686
//// removed from the file and that any derivative work contains  ////
687
//// the original copyright notice and the associated disclaimer. ////
688
////                                                              ////
689
//// This source file is free software; you can redistribute it   ////
690
//// and/or modify it under the terms of the GNU Lesser General   ////
691
//// Public License as published by the Free Software Foundation; ////
692
//// either version 2.1 of the License, or (at your option) any   ////
693
//// later version.                                               ////
694
////                                                              ////
695
//// This source is distributed in the hope that it will be       ////
696
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
697
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
698
//// PURPOSE.  See the GNU Lesser General Public License for more ////
699
//// details.                                                     ////
700
////                                                              ////
701
//// You should have received a copy of the GNU Lesser General    ////
702
//// Public License along with this source; if not, download it   ////
703
//// from http://www.opencores.org/lgpl.shtml                     ////
704
////                                                              ////
705
//////////////////////////////////////////////////////////////////////
706
 
707 40 unneback
`ifdef DFF
708
`define MODULE dff
709
module `BASE`MODULE ( d, q, clk, rst);
710
`undef MODULE
711 6 unneback
        parameter width = 1;
712
        parameter reset_value = 0;
713
 
714
        input [width-1:0] d;
715
        input clk, rst;
716
        output reg [width-1:0] q;
717
 
718
        always @ (posedge clk or posedge rst)
719
        if (rst)
720
                q <= reset_value;
721
        else
722
                q <= d;
723
 
724
endmodule
725 40 unneback
`endif
726 6 unneback
 
727 40 unneback
`ifdef DFF_ARRAY
728
`define MODULE dff_array
729
module `BASE`MODULE ( d, q, clk, rst);
730
`undef MODULE
731 6 unneback
 
732
        parameter width = 1;
733
        parameter depth = 2;
734
        parameter reset_value = 1'b0;
735
 
736
        input [width-1:0] d;
737
        input clk, rst;
738
        output [width-1:0] q;
739
        reg  [0:depth-1] q_tmp [width-1:0];
740
        integer i;
741
        always @ (posedge clk or posedge rst)
742
        if (rst) begin
743
            for (i=0;i<depth;i=i+1)
744
                q_tmp[i] <= {width{reset_value}};
745
        end else begin
746
            q_tmp[0] <= d;
747
            for (i=1;i<depth;i=i+1)
748
                q_tmp[i] <= q_tmp[i-1];
749
        end
750
 
751
    assign q = q_tmp[depth-1];
752
 
753
endmodule
754 40 unneback
`endif
755 6 unneback
 
756 40 unneback
`ifdef DFF_CE
757
`define MODULE dff_ce
758
module `BASE`MODULE ( d, ce, q, clk, rst);
759
`undef MODULE
760 6 unneback
 
761
        parameter width = 1;
762
        parameter reset_value = 0;
763
 
764
        input [width-1:0] d;
765
        input ce, clk, rst;
766
        output reg [width-1:0] q;
767
 
768
        always @ (posedge clk or posedge rst)
769
        if (rst)
770
                q <= reset_value;
771
        else
772
                if (ce)
773
                        q <= d;
774
 
775
endmodule
776 40 unneback
`endif
777 6 unneback
 
778 40 unneback
`ifdef DFF_CE_CLEAR
779
`define MODULE dff_ce_clear
780
module `BASE`MODULE ( d, ce, clear, q, clk, rst);
781
`undef MODULE
782 8 unneback
 
783
        parameter width = 1;
784
        parameter reset_value = 0;
785
 
786
        input [width-1:0] d;
787 10 unneback
        input ce, clear, clk, rst;
788 8 unneback
        output reg [width-1:0] q;
789
 
790
        always @ (posedge clk or posedge rst)
791
        if (rst)
792
            q <= reset_value;
793
        else
794
            if (ce)
795
                if (clear)
796
                    q <= {width{1'b0}};
797
                else
798
                    q <= d;
799
 
800
endmodule
801 40 unneback
`endif
802 8 unneback
 
803 40 unneback
`ifdef DF_CE_SET
804
`define MODULE dff_ce_set
805
module `BASE`MODULE ( d, ce, set, q, clk, rst);
806
`undef MODULE
807 24 unneback
 
808
        parameter width = 1;
809
        parameter reset_value = 0;
810
 
811
        input [width-1:0] d;
812
        input ce, set, clk, rst;
813
        output reg [width-1:0] q;
814
 
815
        always @ (posedge clk or posedge rst)
816
        if (rst)
817
            q <= reset_value;
818
        else
819
            if (ce)
820
                if (set)
821
                    q <= {width{1'b1}};
822
                else
823
                    q <= d;
824
 
825
endmodule
826 40 unneback
`endif
827 24 unneback
 
828 40 unneback
`ifdef SPR
829
`define MODULE spr
830
module `BASE`MODULE ( sp, r, q, clk, rst);
831
`undef MODULE
832
 
833 64 unneback
        //parameter width = 1;
834
        parameter reset_value = 1'b0;
835 29 unneback
 
836
        input sp, r;
837
        output reg q;
838
        input clk, rst;
839
 
840
        always @ (posedge clk or posedge rst)
841
        if (rst)
842
            q <= reset_value;
843
        else
844
            if (sp)
845
                q <= 1'b1;
846
            else if (r)
847
                q <= 1'b0;
848
 
849
endmodule
850 40 unneback
`endif
851 29 unneback
 
852 40 unneback
`ifdef SRP
853
`define MODULE srp
854
module `BASE`MODULE ( s, rp, q, clk, rst);
855
`undef MODULE
856
 
857 29 unneback
        parameter width = 1;
858
        parameter reset_value = 0;
859
 
860
        input s, rp;
861
        output reg q;
862
        input clk, rst;
863
 
864
        always @ (posedge clk or posedge rst)
865
        if (rst)
866
            q <= reset_value;
867
        else
868
            if (rp)
869
                q <= 1'b0;
870
            else if (s)
871
                q <= 1'b1;
872
 
873
endmodule
874 40 unneback
`endif
875 29 unneback
 
876 40 unneback
`ifdef ALTERA
877 29 unneback
 
878 40 unneback
`ifdef DFF_SR
879 6 unneback
// megafunction wizard: %LPM_FF%
880
// GENERATION: STANDARD
881
// VERSION: WM1.0
882
// MODULE: lpm_ff 
883
 
884
// ============================================================
885
// File Name: dff_sr.v
886
// Megafunction Name(s):
887
//                      lpm_ff
888
//
889
// Simulation Library Files(s):
890
//                      lpm
891
// ============================================================
892
// ************************************************************
893
// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
894
//
895
// 9.1 Build 304 01/25/2010 SP 1 SJ Full Version
896
// ************************************************************
897
 
898
 
899
//Copyright (C) 1991-2010 Altera Corporation
900
//Your use of Altera Corporation's design tools, logic functions 
901
//and other software and tools, and its AMPP partner logic 
902
//functions, and any output files from any of the foregoing 
903
//(including device programming or simulation files), and any 
904
//associated documentation or information are expressly subject 
905
//to the terms and conditions of the Altera Program License 
906
//Subscription Agreement, Altera MegaCore Function License 
907
//Agreement, or other applicable license agreement, including, 
908
//without limitation, that your use is for the sole purpose of 
909
//programming logic devices manufactured by Altera and sold by 
910
//Altera or its authorized distributors.  Please refer to the 
911
//applicable agreement for further details.
912
 
913
 
914
// synopsys translate_off
915
`timescale 1 ps / 1 ps
916
// synopsys translate_on
917 40 unneback
`define MODULE dff_sr
918
module `BASE`MODULE (
919
`undef MODULE
920
 
921 6 unneback
        aclr,
922
        aset,
923
        clock,
924
        data,
925
        q);
926
 
927
        input     aclr;
928
        input     aset;
929
        input     clock;
930
        input     data;
931
        output    q;
932
 
933
        wire [0:0] sub_wire0;
934
        wire [0:0] sub_wire1 = sub_wire0[0:0];
935
        wire  q = sub_wire1;
936
        wire  sub_wire2 = data;
937
        wire  sub_wire3 = sub_wire2;
938
 
939
        lpm_ff  lpm_ff_component (
940
                                .aclr (aclr),
941
                                .clock (clock),
942
                                .data (sub_wire3),
943
                                .aset (aset),
944
                                .q (sub_wire0)
945
                                // synopsys translate_off
946
                                ,
947
                                .aload (),
948
                                .enable (),
949
                                .sclr (),
950
                                .sload (),
951
                                .sset ()
952
                                // synopsys translate_on
953
                                );
954
        defparam
955
                lpm_ff_component.lpm_fftype = "DFF",
956
                lpm_ff_component.lpm_type = "LPM_FF",
957
                lpm_ff_component.lpm_width = 1;
958
 
959
 
960
endmodule
961
 
962
// ============================================================
963
// CNX file retrieval info
964
// ============================================================
965
// Retrieval info: PRIVATE: ACLR NUMERIC "1"
966
// Retrieval info: PRIVATE: ALOAD NUMERIC "0"
967
// Retrieval info: PRIVATE: ASET NUMERIC "1"
968
// Retrieval info: PRIVATE: ASET_ALL1 NUMERIC "1"
969
// Retrieval info: PRIVATE: CLK_EN NUMERIC "0"
970
// Retrieval info: PRIVATE: DFF NUMERIC "1"
971
// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone IV E"
972
// Retrieval info: PRIVATE: SCLR NUMERIC "0"
973
// Retrieval info: PRIVATE: SLOAD NUMERIC "0"
974
// Retrieval info: PRIVATE: SSET NUMERIC "0"
975
// Retrieval info: PRIVATE: SSET_ALL1 NUMERIC "1"
976
// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
977
// Retrieval info: PRIVATE: UseTFFdataPort NUMERIC "0"
978
// Retrieval info: PRIVATE: nBit NUMERIC "1"
979
// Retrieval info: CONSTANT: LPM_FFTYPE STRING "DFF"
980
// Retrieval info: CONSTANT: LPM_TYPE STRING "LPM_FF"
981
// Retrieval info: CONSTANT: LPM_WIDTH NUMERIC "1"
982
// Retrieval info: USED_PORT: aclr 0 0 0 0 INPUT NODEFVAL aclr
983
// Retrieval info: USED_PORT: aset 0 0 0 0 INPUT NODEFVAL aset
984
// Retrieval info: USED_PORT: clock 0 0 0 0 INPUT NODEFVAL clock
985
// Retrieval info: USED_PORT: data 0 0 0 0 INPUT NODEFVAL data
986
// Retrieval info: USED_PORT: q 0 0 0 0 OUTPUT NODEFVAL q
987
// Retrieval info: CONNECT: @clock 0 0 0 0 clock 0 0 0 0
988
// Retrieval info: CONNECT: q 0 0 0 0 @q 0 0 1 0
989
// Retrieval info: CONNECT: @aclr 0 0 0 0 aclr 0 0 0 0
990
// Retrieval info: CONNECT: @aset 0 0 0 0 aset 0 0 0 0
991
// Retrieval info: CONNECT: @data 0 0 1 0 data 0 0 0 0
992
// Retrieval info: LIBRARY: lpm lpm.lpm_components.all
993
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr.v TRUE
994
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr.inc FALSE
995
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr.cmp FALSE
996
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr.bsf FALSE
997
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr_inst.v FALSE
998
// Retrieval info: GEN_FILE: TYPE_NORMAL dff_sr_bb.v FALSE
999
// Retrieval info: LIB_FILE: lpm
1000 40 unneback
`endif
1001 6 unneback
 
1002
`else
1003
 
1004 40 unneback
`ifdef DFF_SR
1005
`define MODULE dff_sr
1006
module `BASE`MODULE ( aclr, aset, clock, data, q);
1007
`undef MODULE
1008 6 unneback
 
1009
    input         aclr;
1010
    input         aset;
1011
    input         clock;
1012
    input         data;
1013
    output reg    q;
1014
 
1015
   always @ (posedge clock or posedge aclr or posedge aset)
1016
     if (aclr)
1017
       q <= 1'b0;
1018
     else if (aset)
1019
       q <= 1'b1;
1020
     else
1021
       q <= data;
1022
 
1023
endmodule
1024 40 unneback
`endif
1025 6 unneback
 
1026
`endif
1027
 
1028
// LATCH
1029
// For targtes not supporting LATCH use dff_sr with clk=1 and data=1
1030
`ifdef ALTERA
1031 40 unneback
 
1032
`ifdef LATCH
1033
`define MODULE latch
1034
module `BASE`MODULE ( d, le, q, clk);
1035
`undef MODULE
1036 6 unneback
input d, le;
1037
output q;
1038
input clk;
1039
dff_sr i0 (.aclr(), .aset(), .clock(1'b1), .data(1'b1), .q(q));
1040
endmodule
1041 40 unneback
`endif
1042
 
1043 6 unneback
`else
1044 40 unneback
 
1045
`ifdef LATCH
1046
`define MODULE latch
1047
module `BASE`MODULE ( d, le, q, clk);
1048
`undef MODULE
1049 6 unneback
input d, le;
1050 48 unneback
input clk;
1051
always @ (le or d)
1052 60 unneback
if (le)
1053 48 unneback
    d <= q;
1054 6 unneback
endmodule
1055 15 unneback
`endif
1056
 
1057 40 unneback
`endif
1058
 
1059
`ifdef SHREG
1060
`define MODULE shreg
1061
module `BASE`MODULE ( d, q, clk, rst);
1062
`undef MODULE
1063
 
1064 17 unneback
parameter depth = 10;
1065
input d;
1066
output q;
1067
input clk, rst;
1068
 
1069
reg [1:depth] dffs;
1070
 
1071
always @ (posedge clk or posedge rst)
1072
if (rst)
1073
    dffs <= {depth{1'b0}};
1074
else
1075
    dffs <= {d,dffs[1:depth-1]};
1076
assign q = dffs[depth];
1077
endmodule
1078 40 unneback
`endif
1079 17 unneback
 
1080 40 unneback
`ifdef SHREG_CE
1081
`define MODULE shreg_ce
1082
module `BASE`MODULE ( d, ce, q, clk, rst);
1083
`undef MODULE
1084 17 unneback
parameter depth = 10;
1085
input d, ce;
1086
output q;
1087
input clk, rst;
1088
 
1089
reg [1:depth] dffs;
1090
 
1091
always @ (posedge clk or posedge rst)
1092
if (rst)
1093
    dffs <= {depth{1'b0}};
1094
else
1095
    if (ce)
1096
        dffs <= {d,dffs[1:depth-1]};
1097
assign q = dffs[depth];
1098
endmodule
1099 40 unneback
`endif
1100 17 unneback
 
1101 40 unneback
`ifdef DELAY
1102
`define MODULE delay
1103
module `BASE`MODULE ( d, q, clk, rst);
1104
`undef MODULE
1105 15 unneback
parameter depth = 10;
1106
input d;
1107
output q;
1108
input clk, rst;
1109
 
1110
reg [1:depth] dffs;
1111
 
1112
always @ (posedge clk or posedge rst)
1113
if (rst)
1114
    dffs <= {depth{1'b0}};
1115
else
1116
    dffs <= {d,dffs[1:depth-1]};
1117
assign q = dffs[depth];
1118 17 unneback
endmodule
1119 40 unneback
`endif
1120 17 unneback
 
1121 40 unneback
`ifdef DELAY_EMPTYFLAG
1122
`define MODULE delay_emptyflag
1123 41 unneback
module `BASE`MODULE ( d, q, emptyflag, clk, rst);
1124 40 unneback
`undef MODULE
1125 17 unneback
parameter depth = 10;
1126
input d;
1127
output q, emptyflag;
1128
input clk, rst;
1129
 
1130
reg [1:depth] dffs;
1131
 
1132
always @ (posedge clk or posedge rst)
1133
if (rst)
1134
    dffs <= {depth{1'b0}};
1135
else
1136
    dffs <= {d,dffs[1:depth-1]};
1137
assign q = dffs[depth];
1138
assign emptyflag = !(|dffs);
1139
endmodule
1140 40 unneback
`endif
1141 17 unneback
//////////////////////////////////////////////////////////////////////
1142 6 unneback
////                                                              ////
1143 18 unneback
////  Logic functions                                             ////
1144
////                                                              ////
1145
////  Description                                                 ////
1146
////  Logic functions such as multiplexers                        ////
1147
////                                                              ////
1148
////                                                              ////
1149
////  To Do:                                                      ////
1150
////   -                                                          ////
1151
////                                                              ////
1152
////  Author(s):                                                  ////
1153
////      - Michael Unneback, unneback@opencores.org              ////
1154
////        ORSoC AB                                              ////
1155
////                                                              ////
1156
//////////////////////////////////////////////////////////////////////
1157
////                                                              ////
1158
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
1159
////                                                              ////
1160
//// This source file may be used and distributed without         ////
1161
//// restriction provided that this copyright statement is not    ////
1162
//// removed from the file and that any derivative work contains  ////
1163
//// the original copyright notice and the associated disclaimer. ////
1164
////                                                              ////
1165
//// This source file is free software; you can redistribute it   ////
1166
//// and/or modify it under the terms of the GNU Lesser General   ////
1167
//// Public License as published by the Free Software Foundation; ////
1168
//// either version 2.1 of the License, or (at your option) any   ////
1169
//// later version.                                               ////
1170
////                                                              ////
1171
//// This source is distributed in the hope that it will be       ////
1172
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1173
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1174
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1175
//// details.                                                     ////
1176
////                                                              ////
1177
//// You should have received a copy of the GNU Lesser General    ////
1178
//// Public License along with this source; if not, download it   ////
1179
//// from http://www.opencores.org/lgpl.shtml                     ////
1180
////                                                              ////
1181
//////////////////////////////////////////////////////////////////////
1182 40 unneback
`ifdef MUX_ANDOR
1183
`define MODULE mux_andor
1184
module `BASE`MODULE ( a, sel, dout);
1185
`undef MODULE
1186 36 unneback
 
1187
parameter width = 32;
1188
parameter nr_of_ports = 4;
1189
 
1190
input [nr_of_ports*width-1:0] a;
1191
input [nr_of_ports-1:0] sel;
1192
output reg [width-1:0] dout;
1193
 
1194 38 unneback
integer i,j;
1195
 
1196 36 unneback
always @ (a, sel)
1197
begin
1198
    dout = a[width-1:0] & {width{sel[0]}};
1199 42 unneback
    for (i=1;i<nr_of_ports;i=i+1)
1200
        for (j=0;j<width;j=j+1)
1201
            dout[j] = (a[i*width + j] & sel[i]) | dout[j];
1202 36 unneback
end
1203
 
1204
endmodule
1205 40 unneback
`endif
1206 36 unneback
 
1207 40 unneback
`ifdef MUX2_ANDOR
1208
`define MODULE mux2_andor
1209
module `BASE`MODULE ( a1, a0, sel, dout);
1210
`undef MODULE
1211 18 unneback
 
1212 34 unneback
parameter width = 32;
1213 35 unneback
localparam nr_of_ports = 2;
1214 34 unneback
input [width-1:0] a1, a0;
1215
input [nr_of_ports-1:0] sel;
1216
output [width-1:0] dout;
1217
 
1218 40 unneback
`define MODULE mux_andor
1219
`BASE`MODULE
1220 38 unneback
    # ( .width(width), .nr_of_ports(nr_of_ports))
1221 36 unneback
    mux0( .a({a1,a0}), .sel(sel), .dout(dout));
1222 40 unneback
`undef MODULE
1223
 
1224 34 unneback
endmodule
1225 40 unneback
`endif
1226 34 unneback
 
1227 40 unneback
`ifdef MUX3_ANDOR
1228
`define MODULE mux3_andor
1229
module `BASE`MODULE ( a2, a1, a0, sel, dout);
1230
`undef MODULE
1231 34 unneback
 
1232
parameter width = 32;
1233 35 unneback
localparam nr_of_ports = 3;
1234 34 unneback
input [width-1:0] a2, a1, a0;
1235
input [nr_of_ports-1:0] sel;
1236
output [width-1:0] dout;
1237
 
1238 40 unneback
`define MODULE mux_andor
1239
`BASE`MODULE
1240 38 unneback
    # ( .width(width), .nr_of_ports(nr_of_ports))
1241 36 unneback
    mux0( .a({a2,a1,a0}), .sel(sel), .dout(dout));
1242 40 unneback
`undef MODULE
1243 34 unneback
endmodule
1244 40 unneback
`endif
1245 34 unneback
 
1246 40 unneback
`ifdef MUX4_ANDOR
1247
`define MODULE mux4_andor
1248
module `BASE`MODULE ( a3, a2, a1, a0, sel, dout);
1249
`undef MODULE
1250 18 unneback
 
1251
parameter width = 32;
1252 35 unneback
localparam nr_of_ports = 4;
1253 18 unneback
input [width-1:0] a3, a2, a1, a0;
1254
input [nr_of_ports-1:0] sel;
1255 22 unneback
output [width-1:0] dout;
1256 18 unneback
 
1257 40 unneback
`define MODULE mux_andor
1258
`BASE`MODULE
1259 38 unneback
    # ( .width(width), .nr_of_ports(nr_of_ports))
1260 36 unneback
    mux0( .a({a3,a2,a1,a0}), .sel(sel), .dout(dout));
1261 40 unneback
`undef MODULE
1262 18 unneback
 
1263
endmodule
1264 40 unneback
`endif
1265 18 unneback
 
1266 40 unneback
`ifdef MUX5_ANDOR
1267
`define MODULE mux5_andor
1268
module `BASE`MODULE ( a4, a3, a2, a1, a0, sel, dout);
1269
`undef MODULE
1270 18 unneback
 
1271
parameter width = 32;
1272 35 unneback
localparam nr_of_ports = 5;
1273 18 unneback
input [width-1:0] a4, a3, a2, a1, a0;
1274
input [nr_of_ports-1:0] sel;
1275 22 unneback
output [width-1:0] dout;
1276 18 unneback
 
1277 40 unneback
`define MODULE mux_andor
1278
`BASE`MODULE
1279 38 unneback
    # ( .width(width), .nr_of_ports(nr_of_ports))
1280 36 unneback
    mux0( .a({a4,a3,a2,a1,a0}), .sel(sel), .dout(dout));
1281 40 unneback
`undef MODULE
1282 18 unneback
 
1283
endmodule
1284 40 unneback
`endif
1285 18 unneback
 
1286 40 unneback
`ifdef MUX6_ANDOR
1287
`define MODULE mux6_andor
1288
module `BASE`MODULE ( a5, a4, a3, a2, a1, a0, sel, dout);
1289
`undef MODULE
1290 18 unneback
 
1291
parameter width = 32;
1292 35 unneback
localparam nr_of_ports = 6;
1293 18 unneback
input [width-1:0] a5, a4, a3, a2, a1, a0;
1294
input [nr_of_ports-1:0] sel;
1295 22 unneback
output [width-1:0] dout;
1296 18 unneback
 
1297 40 unneback
`define MODULE mux_andor
1298
`BASE`MODULE
1299 38 unneback
    # ( .width(width), .nr_of_ports(nr_of_ports))
1300 36 unneback
    mux0( .a({a5,a4,a3,a2,a1,a0}), .sel(sel), .dout(dout));
1301 40 unneback
`undef MODULE
1302 18 unneback
 
1303
endmodule
1304 40 unneback
`endif
1305 43 unneback
 
1306
`ifdef PARITY
1307
 
1308
`define MODULE parity_generate
1309
module `BASE`MODULE (data, parity);
1310
`undef MODULE
1311
parameter word_size = 32;
1312
parameter chunk_size = 8;
1313
parameter parity_type = 1'b0; // 0 - even, 1 - odd parity
1314
input [word_size-1:0] data;
1315
output reg [word_size/chunk_size-1:0] parity;
1316
integer i,j;
1317
always @ (data)
1318
for (i=0;i<word_size/chunk_size;i=i+1) begin
1319
    parity[i] = parity_type;
1320
    for (j=0;j<chunk_size;j=j+1) begin
1321 46 unneback
        parity[i] = data[i*chunk_size+j] ^ parity[i];
1322 43 unneback
    end
1323
end
1324
endmodule
1325
 
1326
`define MODULE parity_check
1327
module `BASE`MODULE( data, parity, parity_error);
1328
`undef MODULE
1329
parameter word_size = 32;
1330
parameter chunk_size = 8;
1331
parameter parity_type = 1'b0; // 0 - even, 1 - odd parity
1332
input [word_size-1:0] data;
1333
input [word_size/chunk_size-1:0] parity;
1334
output parity_error;
1335 44 unneback
reg [word_size/chunk_size-1:0] error_flag;
1336 43 unneback
integer i,j;
1337
always @ (data or parity)
1338
for (i=0;i<word_size/chunk_size;i=i+1) begin
1339
    error_flag[i] = parity[i] ^ parity_type;
1340
    for (j=0;j<chunk_size;j=j+1) begin
1341 46 unneback
        error_flag[i] = data[i*chunk_size+j] ^ error_flag[i];
1342 43 unneback
    end
1343
end
1344
assign parity_error = |error_flag;
1345
endmodule
1346
 
1347 44 unneback
`endif//////////////////////////////////////////////////////////////////////
1348
////                                                              ////
1349
////  IO functions                                                ////
1350
////                                                              ////
1351
////  Description                                                 ////
1352
////  IO functions such as IOB flip-flops                         ////
1353
////                                                              ////
1354
////                                                              ////
1355
////  To Do:                                                      ////
1356
////   -                                                          ////
1357
////                                                              ////
1358
////  Author(s):                                                  ////
1359
////      - Michael Unneback, unneback@opencores.org              ////
1360
////        ORSoC AB                                              ////
1361
////                                                              ////
1362 18 unneback
//////////////////////////////////////////////////////////////////////
1363
////                                                              ////
1364 44 unneback
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
1365
////                                                              ////
1366
//// This source file may be used and distributed without         ////
1367
//// restriction provided that this copyright statement is not    ////
1368
//// removed from the file and that any derivative work contains  ////
1369
//// the original copyright notice and the associated disclaimer. ////
1370
////                                                              ////
1371
//// This source file is free software; you can redistribute it   ////
1372
//// and/or modify it under the terms of the GNU Lesser General   ////
1373
//// Public License as published by the Free Software Foundation; ////
1374
//// either version 2.1 of the License, or (at your option) any   ////
1375
//// later version.                                               ////
1376
////                                                              ////
1377
//// This source is distributed in the hope that it will be       ////
1378
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1379
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1380
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1381
//// details.                                                     ////
1382
////                                                              ////
1383
//// You should have received a copy of the GNU Lesser General    ////
1384
//// Public License along with this source; if not, download it   ////
1385
//// from http://www.opencores.org/lgpl.shtml                     ////
1386
////                                                              ////
1387
//////////////////////////////////////////////////////////////////////
1388 45 unneback
`timescale 1ns/1ns
1389 44 unneback
`ifdef O_DFF
1390
`define MODULE o_dff
1391
module `BASE`MODULE (d_i, o_pad, clk, rst);
1392
`undef MODULE
1393
parameter width = 1;
1394 45 unneback
parameter reset_value = {width{1'b0}};
1395
input  [width-1:0]  d_i;
1396 44 unneback
output [width-1:0] o_pad;
1397
input clk, rst;
1398
wire [width-1:0] d_i_int `SYN_KEEP;
1399 45 unneback
reg  [width-1:0] o_pad_int;
1400 44 unneback
assign d_i_int = d_i;
1401
genvar i;
1402 45 unneback
generate
1403 44 unneback
for (i=0;i<width;i=i+1) begin
1404
    always @ (posedge clk or posedge rst)
1405
    if (rst)
1406 45 unneback
        o_pad_int[i] <= reset_value[i];
1407 44 unneback
    else
1408 45 unneback
        o_pad_int[i] <= d_i_int[i];
1409
    assign #1 o_pad[i] = o_pad_int[i];
1410 44 unneback
end
1411
endgenerate
1412
endmodule
1413
`endif
1414
 
1415 45 unneback
`timescale 1ns/1ns
1416 44 unneback
`ifdef IO_DFF_OE
1417
`define MODULE io_dff_oe
1418
module `BASE`MODULE ( d_i, d_o, oe, io_pad, clk, rst);
1419
`undef MODULE
1420
parameter width = 1;
1421
input  [width-1:0] d_o;
1422
output reg [width-1:0] d_i;
1423
input oe;
1424
inout [width-1:0] io_pad;
1425
input clk, rst;
1426
wire [width-1:0] oe_d `SYN_KEEP;
1427
reg [width-1:0] oe_q;
1428
reg [width-1:0] d_o_q;
1429
assign oe_d = {width{oe}};
1430
genvar i;
1431
generate
1432
for (i=0;i<width;i=i+1) begin
1433
    always @ (posedge clk or posedge rst)
1434
    if (rst)
1435
        oe_q[i] <= 1'b0;
1436
    else
1437
        oe_q[i] <= oe_d[i];
1438
    always @ (posedge clk or posedge rst)
1439
    if (rst)
1440
        d_o_q[i] <= 1'b0;
1441
    else
1442
        d_o_q[i] <= d_o[i];
1443
    always @ (posedge clk or posedge rst)
1444
    if (rst)
1445
        d_i[i] <= 1'b0;
1446
    else
1447
        d_i[i] <= io_pad[i];
1448 45 unneback
    assign #1 io_pad[i] = (oe_q[i]) ? d_o_q[i] : 1'bz;
1449 44 unneback
end
1450
endgenerate
1451
endmodule
1452
`endif
1453
`ifdef CNT_BIN
1454
//////////////////////////////////////////////////////////////////////
1455
////                                                              ////
1456 6 unneback
////  Versatile counter                                           ////
1457
////                                                              ////
1458
////  Description                                                 ////
1459
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1460
////  counter                                                     ////
1461
////                                                              ////
1462
////  To Do:                                                      ////
1463
////   - add LFSR with more taps                                  ////
1464
////                                                              ////
1465
////  Author(s):                                                  ////
1466
////      - Michael Unneback, unneback@opencores.org              ////
1467
////        ORSoC AB                                              ////
1468
////                                                              ////
1469
//////////////////////////////////////////////////////////////////////
1470
////                                                              ////
1471
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1472
////                                                              ////
1473
//// This source file may be used and distributed without         ////
1474
//// restriction provided that this copyright statement is not    ////
1475
//// removed from the file and that any derivative work contains  ////
1476
//// the original copyright notice and the associated disclaimer. ////
1477
////                                                              ////
1478
//// This source file is free software; you can redistribute it   ////
1479
//// and/or modify it under the terms of the GNU Lesser General   ////
1480
//// Public License as published by the Free Software Foundation; ////
1481
//// either version 2.1 of the License, or (at your option) any   ////
1482
//// later version.                                               ////
1483
////                                                              ////
1484
//// This source is distributed in the hope that it will be       ////
1485
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1486
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1487
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1488
//// details.                                                     ////
1489
////                                                              ////
1490
//// You should have received a copy of the GNU Lesser General    ////
1491
//// Public License along with this source; if not, download it   ////
1492
//// from http://www.opencores.org/lgpl.shtml                     ////
1493
////                                                              ////
1494
//////////////////////////////////////////////////////////////////////
1495
 
1496
// binary counter
1497 22 unneback
 
1498 40 unneback
`define MODULE cnt_bin
1499
module `BASE`MODULE (
1500
`undef MODULE
1501
 q, rst, clk);
1502
 
1503 22 unneback
   parameter length = 4;
1504
   output [length:1] q;
1505
   input rst;
1506
   input clk;
1507
 
1508
   parameter clear_value = 0;
1509
   parameter set_value = 1;
1510
   parameter wrap_value = 0;
1511
   parameter level1_value = 15;
1512
 
1513
   reg  [length:1] qi;
1514
   wire [length:1] q_next;
1515
   assign q_next = qi + {{length-1{1'b0}},1'b1};
1516
 
1517
   always @ (posedge clk or posedge rst)
1518
     if (rst)
1519
       qi <= {length{1'b0}};
1520
     else
1521
       qi <= q_next;
1522
 
1523
   assign q = qi;
1524
 
1525
endmodule
1526 40 unneback
`endif
1527
`ifdef CNT_BIN_CLEAR
1528 22 unneback
//////////////////////////////////////////////////////////////////////
1529
////                                                              ////
1530
////  Versatile counter                                           ////
1531
////                                                              ////
1532
////  Description                                                 ////
1533
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1534
////  counter                                                     ////
1535
////                                                              ////
1536
////  To Do:                                                      ////
1537
////   - add LFSR with more taps                                  ////
1538
////                                                              ////
1539
////  Author(s):                                                  ////
1540
////      - Michael Unneback, unneback@opencores.org              ////
1541
////        ORSoC AB                                              ////
1542
////                                                              ////
1543
//////////////////////////////////////////////////////////////////////
1544
////                                                              ////
1545
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1546
////                                                              ////
1547
//// This source file may be used and distributed without         ////
1548
//// restriction provided that this copyright statement is not    ////
1549
//// removed from the file and that any derivative work contains  ////
1550
//// the original copyright notice and the associated disclaimer. ////
1551
////                                                              ////
1552
//// This source file is free software; you can redistribute it   ////
1553
//// and/or modify it under the terms of the GNU Lesser General   ////
1554
//// Public License as published by the Free Software Foundation; ////
1555
//// either version 2.1 of the License, or (at your option) any   ////
1556
//// later version.                                               ////
1557
////                                                              ////
1558
//// This source is distributed in the hope that it will be       ////
1559
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1560
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1561
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1562
//// details.                                                     ////
1563
////                                                              ////
1564
//// You should have received a copy of the GNU Lesser General    ////
1565
//// Public License along with this source; if not, download it   ////
1566
//// from http://www.opencores.org/lgpl.shtml                     ////
1567
////                                                              ////
1568
//////////////////////////////////////////////////////////////////////
1569
 
1570
// binary counter
1571
 
1572 40 unneback
`define MODULE cnt_bin_clear
1573
module `BASE`MODULE (
1574
`undef MODULE
1575
 clear, q, rst, clk);
1576
 
1577 22 unneback
   parameter length = 4;
1578
   input clear;
1579
   output [length:1] q;
1580
   input rst;
1581
   input clk;
1582
 
1583
   parameter clear_value = 0;
1584
   parameter set_value = 1;
1585
   parameter wrap_value = 0;
1586
   parameter level1_value = 15;
1587
 
1588
   reg  [length:1] qi;
1589
   wire [length:1] q_next;
1590
   assign q_next =  clear ? {length{1'b0}} :qi + {{length-1{1'b0}},1'b1};
1591
 
1592
   always @ (posedge clk or posedge rst)
1593
     if (rst)
1594
       qi <= {length{1'b0}};
1595
     else
1596
       qi <= q_next;
1597
 
1598
   assign q = qi;
1599
 
1600
endmodule
1601 40 unneback
`endif
1602
`ifdef CNT_BIN_CE
1603 22 unneback
//////////////////////////////////////////////////////////////////////
1604
////                                                              ////
1605
////  Versatile counter                                           ////
1606
////                                                              ////
1607
////  Description                                                 ////
1608
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1609
////  counter                                                     ////
1610
////                                                              ////
1611
////  To Do:                                                      ////
1612
////   - add LFSR with more taps                                  ////
1613
////                                                              ////
1614
////  Author(s):                                                  ////
1615
////      - Michael Unneback, unneback@opencores.org              ////
1616
////        ORSoC AB                                              ////
1617
////                                                              ////
1618
//////////////////////////////////////////////////////////////////////
1619
////                                                              ////
1620
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1621
////                                                              ////
1622
//// This source file may be used and distributed without         ////
1623
//// restriction provided that this copyright statement is not    ////
1624
//// removed from the file and that any derivative work contains  ////
1625
//// the original copyright notice and the associated disclaimer. ////
1626
////                                                              ////
1627
//// This source file is free software; you can redistribute it   ////
1628
//// and/or modify it under the terms of the GNU Lesser General   ////
1629
//// Public License as published by the Free Software Foundation; ////
1630
//// either version 2.1 of the License, or (at your option) any   ////
1631
//// later version.                                               ////
1632
////                                                              ////
1633
//// This source is distributed in the hope that it will be       ////
1634
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1635
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1636
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1637
//// details.                                                     ////
1638
////                                                              ////
1639
//// You should have received a copy of the GNU Lesser General    ////
1640
//// Public License along with this source; if not, download it   ////
1641
//// from http://www.opencores.org/lgpl.shtml                     ////
1642
////                                                              ////
1643
//////////////////////////////////////////////////////////////////////
1644
 
1645
// binary counter
1646 6 unneback
 
1647 40 unneback
`define MODULE cnt_bin_ce
1648
module `BASE`MODULE (
1649
`undef MODULE
1650
 cke, q, rst, clk);
1651
 
1652 6 unneback
   parameter length = 4;
1653
   input cke;
1654
   output [length:1] q;
1655
   input rst;
1656
   input clk;
1657
 
1658
   parameter clear_value = 0;
1659
   parameter set_value = 1;
1660
   parameter wrap_value = 0;
1661
   parameter level1_value = 15;
1662
 
1663
   reg  [length:1] qi;
1664
   wire [length:1] q_next;
1665
   assign q_next = qi + {{length-1{1'b0}},1'b1};
1666
 
1667
   always @ (posedge clk or posedge rst)
1668
     if (rst)
1669
       qi <= {length{1'b0}};
1670
     else
1671
     if (cke)
1672
       qi <= q_next;
1673
 
1674
   assign q = qi;
1675
 
1676
endmodule
1677 40 unneback
`endif
1678
`ifdef CNT_BIN_CE_CLEAR
1679 6 unneback
//////////////////////////////////////////////////////////////////////
1680
////                                                              ////
1681
////  Versatile counter                                           ////
1682
////                                                              ////
1683
////  Description                                                 ////
1684
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1685
////  counter                                                     ////
1686
////                                                              ////
1687
////  To Do:                                                      ////
1688
////   - add LFSR with more taps                                  ////
1689
////                                                              ////
1690
////  Author(s):                                                  ////
1691
////      - Michael Unneback, unneback@opencores.org              ////
1692
////        ORSoC AB                                              ////
1693
////                                                              ////
1694
//////////////////////////////////////////////////////////////////////
1695
////                                                              ////
1696
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1697
////                                                              ////
1698
//// This source file may be used and distributed without         ////
1699
//// restriction provided that this copyright statement is not    ////
1700
//// removed from the file and that any derivative work contains  ////
1701
//// the original copyright notice and the associated disclaimer. ////
1702
////                                                              ////
1703
//// This source file is free software; you can redistribute it   ////
1704
//// and/or modify it under the terms of the GNU Lesser General   ////
1705
//// Public License as published by the Free Software Foundation; ////
1706
//// either version 2.1 of the License, or (at your option) any   ////
1707
//// later version.                                               ////
1708
////                                                              ////
1709
//// This source is distributed in the hope that it will be       ////
1710
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1711
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1712
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1713
//// details.                                                     ////
1714
////                                                              ////
1715
//// You should have received a copy of the GNU Lesser General    ////
1716
//// Public License along with this source; if not, download it   ////
1717
//// from http://www.opencores.org/lgpl.shtml                     ////
1718
////                                                              ////
1719
//////////////////////////////////////////////////////////////////////
1720
 
1721
// binary counter
1722
 
1723 40 unneback
`define MODULE cnt_bin_ce_clear
1724
module `BASE`MODULE (
1725
`undef MODULE
1726
 clear, cke, q, rst, clk);
1727
 
1728 6 unneback
   parameter length = 4;
1729
   input clear;
1730
   input cke;
1731
   output [length:1] q;
1732
   input rst;
1733
   input clk;
1734
 
1735
   parameter clear_value = 0;
1736
   parameter set_value = 1;
1737
   parameter wrap_value = 0;
1738
   parameter level1_value = 15;
1739
 
1740
   reg  [length:1] qi;
1741
   wire [length:1] q_next;
1742
   assign q_next =  clear ? {length{1'b0}} :qi + {{length-1{1'b0}},1'b1};
1743
 
1744
   always @ (posedge clk or posedge rst)
1745
     if (rst)
1746
       qi <= {length{1'b0}};
1747
     else
1748
     if (cke)
1749
       qi <= q_next;
1750
 
1751
   assign q = qi;
1752
 
1753
endmodule
1754 40 unneback
`endif
1755
`ifdef CNT_BIN_CE_CLEAR_L1_L2
1756 6 unneback
//////////////////////////////////////////////////////////////////////
1757
////                                                              ////
1758
////  Versatile counter                                           ////
1759
////                                                              ////
1760
////  Description                                                 ////
1761
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1762
////  counter                                                     ////
1763
////                                                              ////
1764
////  To Do:                                                      ////
1765
////   - add LFSR with more taps                                  ////
1766
////                                                              ////
1767
////  Author(s):                                                  ////
1768
////      - Michael Unneback, unneback@opencores.org              ////
1769
////        ORSoC AB                                              ////
1770
////                                                              ////
1771
//////////////////////////////////////////////////////////////////////
1772
////                                                              ////
1773
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1774
////                                                              ////
1775
//// This source file may be used and distributed without         ////
1776
//// restriction provided that this copyright statement is not    ////
1777
//// removed from the file and that any derivative work contains  ////
1778
//// the original copyright notice and the associated disclaimer. ////
1779
////                                                              ////
1780
//// This source file is free software; you can redistribute it   ////
1781
//// and/or modify it under the terms of the GNU Lesser General   ////
1782
//// Public License as published by the Free Software Foundation; ////
1783
//// either version 2.1 of the License, or (at your option) any   ////
1784
//// later version.                                               ////
1785
////                                                              ////
1786
//// This source is distributed in the hope that it will be       ////
1787
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1788
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1789
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1790
//// details.                                                     ////
1791
////                                                              ////
1792
//// You should have received a copy of the GNU Lesser General    ////
1793
//// Public License along with this source; if not, download it   ////
1794
//// from http://www.opencores.org/lgpl.shtml                     ////
1795
////                                                              ////
1796
//////////////////////////////////////////////////////////////////////
1797
 
1798
// binary counter
1799 29 unneback
 
1800 40 unneback
`define MODULE cnt_bin_ce_clear_l1_l2
1801
module `BASE`MODULE (
1802
`undef MODULE
1803
 clear, cke, q, level1, level2, rst, clk);
1804
 
1805 29 unneback
   parameter length = 4;
1806
   input clear;
1807
   input cke;
1808
   output [length:1] q;
1809
   output reg level1;
1810
   output reg level2;
1811
   input rst;
1812
   input clk;
1813
 
1814
   parameter clear_value = 0;
1815
   parameter set_value = 1;
1816 30 unneback
   parameter wrap_value = 15;
1817
   parameter level1_value = 8;
1818
   parameter level2_value = 15;
1819 29 unneback
 
1820
   wire rew;
1821 30 unneback
   assign rew = 1'b0;
1822 29 unneback
   reg  [length:1] qi;
1823
   wire [length:1] q_next;
1824
   assign q_next =  clear ? {length{1'b0}} :qi + {{length-1{1'b0}},1'b1};
1825
 
1826
   always @ (posedge clk or posedge rst)
1827
     if (rst)
1828
       qi <= {length{1'b0}};
1829
     else
1830
     if (cke)
1831
       qi <= q_next;
1832
 
1833
   assign q = qi;
1834
 
1835
 
1836
    always @ (posedge clk or posedge rst)
1837
    if (rst)
1838
        level1 <= 1'b0;
1839
    else
1840
    if (cke)
1841
    if (clear)
1842
        level1 <= 1'b0;
1843
    else if (q_next == level1_value)
1844
        level1 <= 1'b1;
1845
    else if (qi == level1_value & rew)
1846
        level1 <= 1'b0;
1847
 
1848
    always @ (posedge clk or posedge rst)
1849
    if (rst)
1850
        level2 <= 1'b0;
1851
    else
1852
    if (cke)
1853
    if (clear)
1854
        level2 <= 1'b0;
1855
    else if (q_next == level2_value)
1856
        level2 <= 1'b1;
1857
    else if (qi == level2_value & rew)
1858
        level2 <= 1'b0;
1859
endmodule
1860 40 unneback
`endif
1861
`ifdef CNT_BIN_CE_CLEAR_SET_REW
1862 29 unneback
//////////////////////////////////////////////////////////////////////
1863
////                                                              ////
1864
////  Versatile counter                                           ////
1865
////                                                              ////
1866
////  Description                                                 ////
1867
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1868
////  counter                                                     ////
1869
////                                                              ////
1870
////  To Do:                                                      ////
1871
////   - add LFSR with more taps                                  ////
1872
////                                                              ////
1873
////  Author(s):                                                  ////
1874
////      - Michael Unneback, unneback@opencores.org              ////
1875
////        ORSoC AB                                              ////
1876
////                                                              ////
1877
//////////////////////////////////////////////////////////////////////
1878
////                                                              ////
1879
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1880
////                                                              ////
1881
//// This source file may be used and distributed without         ////
1882
//// restriction provided that this copyright statement is not    ////
1883
//// removed from the file and that any derivative work contains  ////
1884
//// the original copyright notice and the associated disclaimer. ////
1885
////                                                              ////
1886
//// This source file is free software; you can redistribute it   ////
1887
//// and/or modify it under the terms of the GNU Lesser General   ////
1888
//// Public License as published by the Free Software Foundation; ////
1889
//// either version 2.1 of the License, or (at your option) any   ////
1890
//// later version.                                               ////
1891
////                                                              ////
1892
//// This source is distributed in the hope that it will be       ////
1893
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1894
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1895
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1896
//// details.                                                     ////
1897
////                                                              ////
1898
//// You should have received a copy of the GNU Lesser General    ////
1899
//// Public License along with this source; if not, download it   ////
1900
//// from http://www.opencores.org/lgpl.shtml                     ////
1901
////                                                              ////
1902
//////////////////////////////////////////////////////////////////////
1903
 
1904
// binary counter
1905 6 unneback
 
1906 40 unneback
`define MODULE cnt_bin_ce_clear_set_rew
1907
module `BASE`MODULE (
1908
`undef MODULE
1909
 clear, set, cke, rew, q, rst, clk);
1910
 
1911 6 unneback
   parameter length = 4;
1912
   input clear;
1913
   input set;
1914
   input cke;
1915
   input rew;
1916
   output [length:1] q;
1917
   input rst;
1918
   input clk;
1919
 
1920
   parameter clear_value = 0;
1921
   parameter set_value = 1;
1922
   parameter wrap_value = 0;
1923
   parameter level1_value = 15;
1924
 
1925
   reg  [length:1] qi;
1926
   wire  [length:1] q_next, q_next_fw, q_next_rew;
1927
   assign q_next_fw  =  clear ? {length{1'b0}} : set ? set_value :qi + {{length-1{1'b0}},1'b1};
1928
   assign q_next_rew =  clear ? clear_value : set ? set_value :qi - {{length-1{1'b0}},1'b1};
1929
   assign q_next = rew ? q_next_rew : q_next_fw;
1930
 
1931
   always @ (posedge clk or posedge rst)
1932
     if (rst)
1933
       qi <= {length{1'b0}};
1934
     else
1935
     if (cke)
1936
       qi <= q_next;
1937
 
1938
   assign q = qi;
1939
 
1940
endmodule
1941 40 unneback
`endif
1942
`ifdef CNT_BIN_CE_REW_L1
1943 6 unneback
//////////////////////////////////////////////////////////////////////
1944
////                                                              ////
1945
////  Versatile counter                                           ////
1946
////                                                              ////
1947
////  Description                                                 ////
1948
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
1949
////  counter                                                     ////
1950
////                                                              ////
1951
////  To Do:                                                      ////
1952
////   - add LFSR with more taps                                  ////
1953
////                                                              ////
1954
////  Author(s):                                                  ////
1955
////      - Michael Unneback, unneback@opencores.org              ////
1956
////        ORSoC AB                                              ////
1957
////                                                              ////
1958
//////////////////////////////////////////////////////////////////////
1959
////                                                              ////
1960
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
1961
////                                                              ////
1962
//// This source file may be used and distributed without         ////
1963
//// restriction provided that this copyright statement is not    ////
1964
//// removed from the file and that any derivative work contains  ////
1965
//// the original copyright notice and the associated disclaimer. ////
1966
////                                                              ////
1967
//// This source file is free software; you can redistribute it   ////
1968
//// and/or modify it under the terms of the GNU Lesser General   ////
1969
//// Public License as published by the Free Software Foundation; ////
1970
//// either version 2.1 of the License, or (at your option) any   ////
1971
//// later version.                                               ////
1972
////                                                              ////
1973
//// This source is distributed in the hope that it will be       ////
1974
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1975
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1976
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1977
//// details.                                                     ////
1978
////                                                              ////
1979
//// You should have received a copy of the GNU Lesser General    ////
1980
//// Public License along with this source; if not, download it   ////
1981
//// from http://www.opencores.org/lgpl.shtml                     ////
1982
////                                                              ////
1983
//////////////////////////////////////////////////////////////////////
1984
 
1985
// binary counter
1986
 
1987 40 unneback
`define MODULE cnt_bin_ce_rew_l1
1988
module `BASE`MODULE (
1989
`undef MODULE
1990
 cke, rew, level1, rst, clk);
1991
 
1992 6 unneback
   parameter length = 4;
1993
   input cke;
1994
   input rew;
1995
   output reg level1;
1996
   input rst;
1997
   input clk;
1998
 
1999
   parameter clear_value = 0;
2000
   parameter set_value = 1;
2001
   parameter wrap_value = 1;
2002
   parameter level1_value = 15;
2003
 
2004 29 unneback
   wire clear;
2005 30 unneback
   assign clear = 1'b0;
2006 6 unneback
   reg  [length:1] qi;
2007
   wire  [length:1] q_next, q_next_fw, q_next_rew;
2008
   assign q_next_fw  = qi + {{length-1{1'b0}},1'b1};
2009
   assign q_next_rew = qi - {{length-1{1'b0}},1'b1};
2010
   assign q_next = rew ? q_next_rew : q_next_fw;
2011
 
2012
   always @ (posedge clk or posedge rst)
2013
     if (rst)
2014
       qi <= {length{1'b0}};
2015
     else
2016
     if (cke)
2017
       qi <= q_next;
2018
 
2019
 
2020
 
2021
    always @ (posedge clk or posedge rst)
2022
    if (rst)
2023
        level1 <= 1'b0;
2024
    else
2025
    if (cke)
2026 29 unneback
    if (clear)
2027
        level1 <= 1'b0;
2028
    else if (q_next == level1_value)
2029 6 unneback
        level1 <= 1'b1;
2030
    else if (qi == level1_value & rew)
2031
        level1 <= 1'b0;
2032
endmodule
2033 40 unneback
`endif
2034
`ifdef CNT_BIN_CE_REW_ZQ_L1
2035 6 unneback
//////////////////////////////////////////////////////////////////////
2036
////                                                              ////
2037
////  Versatile counter                                           ////
2038
////                                                              ////
2039
////  Description                                                 ////
2040
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2041
////  counter                                                     ////
2042
////                                                              ////
2043
////  To Do:                                                      ////
2044
////   - add LFSR with more taps                                  ////
2045
////                                                              ////
2046
////  Author(s):                                                  ////
2047
////      - Michael Unneback, unneback@opencores.org              ////
2048
////        ORSoC AB                                              ////
2049
////                                                              ////
2050
//////////////////////////////////////////////////////////////////////
2051
////                                                              ////
2052
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2053
////                                                              ////
2054
//// This source file may be used and distributed without         ////
2055
//// restriction provided that this copyright statement is not    ////
2056
//// removed from the file and that any derivative work contains  ////
2057
//// the original copyright notice and the associated disclaimer. ////
2058
////                                                              ////
2059
//// This source file is free software; you can redistribute it   ////
2060
//// and/or modify it under the terms of the GNU Lesser General   ////
2061
//// Public License as published by the Free Software Foundation; ////
2062
//// either version 2.1 of the License, or (at your option) any   ////
2063
//// later version.                                               ////
2064
////                                                              ////
2065
//// This source is distributed in the hope that it will be       ////
2066
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2067
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2068
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2069
//// details.                                                     ////
2070
////                                                              ////
2071
//// You should have received a copy of the GNU Lesser General    ////
2072
//// Public License along with this source; if not, download it   ////
2073
//// from http://www.opencores.org/lgpl.shtml                     ////
2074
////                                                              ////
2075
//////////////////////////////////////////////////////////////////////
2076
 
2077 25 unneback
// binary counter
2078
 
2079 40 unneback
`define MODULE cnt_bin_ce_rew_zq_l1
2080
module `BASE`MODULE (
2081
`undef MODULE
2082
 cke, rew, zq, level1, rst, clk);
2083
 
2084 25 unneback
   parameter length = 4;
2085
   input cke;
2086
   input rew;
2087
   output reg zq;
2088
   output reg level1;
2089
   input rst;
2090
   input clk;
2091
 
2092
   parameter clear_value = 0;
2093
   parameter set_value = 1;
2094
   parameter wrap_value = 1;
2095
   parameter level1_value = 15;
2096
 
2097 29 unneback
   wire clear;
2098 30 unneback
   assign clear = 1'b0;
2099 25 unneback
   reg  [length:1] qi;
2100
   wire  [length:1] q_next, q_next_fw, q_next_rew;
2101
   assign q_next_fw  = qi + {{length-1{1'b0}},1'b1};
2102
   assign q_next_rew = qi - {{length-1{1'b0}},1'b1};
2103
   assign q_next = rew ? q_next_rew : q_next_fw;
2104
 
2105
   always @ (posedge clk or posedge rst)
2106
     if (rst)
2107
       qi <= {length{1'b0}};
2108
     else
2109
     if (cke)
2110
       qi <= q_next;
2111
 
2112
 
2113
 
2114
   always @ (posedge clk or posedge rst)
2115
     if (rst)
2116
       zq <= 1'b1;
2117
     else
2118
     if (cke)
2119
       zq <= q_next == {length{1'b0}};
2120
 
2121
    always @ (posedge clk or posedge rst)
2122
    if (rst)
2123
        level1 <= 1'b0;
2124
    else
2125
    if (cke)
2126 29 unneback
    if (clear)
2127
        level1 <= 1'b0;
2128
    else if (q_next == level1_value)
2129 25 unneback
        level1 <= 1'b1;
2130
    else if (qi == level1_value & rew)
2131
        level1 <= 1'b0;
2132
endmodule
2133 40 unneback
`endif
2134
`ifdef CNT_BIN_CE_REW_Q_ZQ_L1
2135 25 unneback
//////////////////////////////////////////////////////////////////////
2136
////                                                              ////
2137
////  Versatile counter                                           ////
2138
////                                                              ////
2139
////  Description                                                 ////
2140
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2141
////  counter                                                     ////
2142
////                                                              ////
2143
////  To Do:                                                      ////
2144
////   - add LFSR with more taps                                  ////
2145
////                                                              ////
2146
////  Author(s):                                                  ////
2147
////      - Michael Unneback, unneback@opencores.org              ////
2148
////        ORSoC AB                                              ////
2149
////                                                              ////
2150
//////////////////////////////////////////////////////////////////////
2151
////                                                              ////
2152
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2153
////                                                              ////
2154
//// This source file may be used and distributed without         ////
2155
//// restriction provided that this copyright statement is not    ////
2156
//// removed from the file and that any derivative work contains  ////
2157
//// the original copyright notice and the associated disclaimer. ////
2158
////                                                              ////
2159
//// This source file is free software; you can redistribute it   ////
2160
//// and/or modify it under the terms of the GNU Lesser General   ////
2161
//// Public License as published by the Free Software Foundation; ////
2162
//// either version 2.1 of the License, or (at your option) any   ////
2163
//// later version.                                               ////
2164
////                                                              ////
2165
//// This source is distributed in the hope that it will be       ////
2166
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2167
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2168
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2169
//// details.                                                     ////
2170
////                                                              ////
2171
//// You should have received a copy of the GNU Lesser General    ////
2172
//// Public License along with this source; if not, download it   ////
2173
//// from http://www.opencores.org/lgpl.shtml                     ////
2174
////                                                              ////
2175
//////////////////////////////////////////////////////////////////////
2176
 
2177
// binary counter
2178
 
2179 40 unneback
`define MODULE cnt_bin_ce_rew_q_zq_l1
2180
module `BASE`MODULE (
2181
`undef MODULE
2182
 cke, rew, q, zq, level1, rst, clk);
2183
 
2184 25 unneback
   parameter length = 4;
2185
   input cke;
2186
   input rew;
2187
   output [length:1] q;
2188
   output reg zq;
2189
   output reg level1;
2190
   input rst;
2191
   input clk;
2192
 
2193
   parameter clear_value = 0;
2194
   parameter set_value = 1;
2195
   parameter wrap_value = 1;
2196
   parameter level1_value = 15;
2197
 
2198 29 unneback
   wire clear;
2199 30 unneback
   assign clear = 1'b0;
2200 25 unneback
   reg  [length:1] qi;
2201
   wire  [length:1] q_next, q_next_fw, q_next_rew;
2202
   assign q_next_fw  = qi + {{length-1{1'b0}},1'b1};
2203
   assign q_next_rew = qi - {{length-1{1'b0}},1'b1};
2204
   assign q_next = rew ? q_next_rew : q_next_fw;
2205
 
2206
   always @ (posedge clk or posedge rst)
2207
     if (rst)
2208
       qi <= {length{1'b0}};
2209
     else
2210
     if (cke)
2211
       qi <= q_next;
2212
 
2213
   assign q = qi;
2214
 
2215
 
2216
   always @ (posedge clk or posedge rst)
2217
     if (rst)
2218
       zq <= 1'b1;
2219
     else
2220
     if (cke)
2221
       zq <= q_next == {length{1'b0}};
2222
 
2223
    always @ (posedge clk or posedge rst)
2224
    if (rst)
2225
        level1 <= 1'b0;
2226
    else
2227
    if (cke)
2228 29 unneback
    if (clear)
2229
        level1 <= 1'b0;
2230
    else if (q_next == level1_value)
2231 25 unneback
        level1 <= 1'b1;
2232
    else if (qi == level1_value & rew)
2233
        level1 <= 1'b0;
2234
endmodule
2235 40 unneback
`endif
2236
`ifdef CNT_LFSR_ZQ
2237 25 unneback
//////////////////////////////////////////////////////////////////////
2238
////                                                              ////
2239
////  Versatile counter                                           ////
2240
////                                                              ////
2241
////  Description                                                 ////
2242
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2243
////  counter                                                     ////
2244
////                                                              ////
2245
////  To Do:                                                      ////
2246
////   - add LFSR with more taps                                  ////
2247
////                                                              ////
2248
////  Author(s):                                                  ////
2249
////      - Michael Unneback, unneback@opencores.org              ////
2250
////        ORSoC AB                                              ////
2251
////                                                              ////
2252
//////////////////////////////////////////////////////////////////////
2253
////                                                              ////
2254
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2255
////                                                              ////
2256
//// This source file may be used and distributed without         ////
2257
//// restriction provided that this copyright statement is not    ////
2258
//// removed from the file and that any derivative work contains  ////
2259
//// the original copyright notice and the associated disclaimer. ////
2260
////                                                              ////
2261
//// This source file is free software; you can redistribute it   ////
2262
//// and/or modify it under the terms of the GNU Lesser General   ////
2263
//// Public License as published by the Free Software Foundation; ////
2264
//// either version 2.1 of the License, or (at your option) any   ////
2265
//// later version.                                               ////
2266
////                                                              ////
2267
//// This source is distributed in the hope that it will be       ////
2268
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2269
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2270
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2271
//// details.                                                     ////
2272
////                                                              ////
2273
//// You should have received a copy of the GNU Lesser General    ////
2274
//// Public License along with this source; if not, download it   ////
2275
//// from http://www.opencores.org/lgpl.shtml                     ////
2276
////                                                              ////
2277
//////////////////////////////////////////////////////////////////////
2278
 
2279 6 unneback
// LFSR counter
2280
 
2281 40 unneback
`define MODULE cnt_lfsr_zq
2282
module `BASE`MODULE (
2283
`undef MODULE
2284
 zq, rst, clk);
2285
 
2286 6 unneback
   parameter length = 4;
2287
   output reg zq;
2288
   input rst;
2289
   input clk;
2290
 
2291
   parameter clear_value = 0;
2292
   parameter set_value = 1;
2293
   parameter wrap_value = 8;
2294
   parameter level1_value = 15;
2295
 
2296
   reg  [length:1] qi;
2297
   reg lfsr_fb;
2298
   wire [length:1] q_next;
2299
   reg [32:1] polynom;
2300
   integer i;
2301
 
2302
   always @ (qi)
2303
   begin
2304
        case (length)
2305
         2: polynom = 32'b11;                               // 0x3
2306
         3: polynom = 32'b110;                              // 0x6
2307
         4: polynom = 32'b1100;                             // 0xC
2308
         5: polynom = 32'b10100;                            // 0x14
2309
         6: polynom = 32'b110000;                           // 0x30
2310
         7: polynom = 32'b1100000;                          // 0x60
2311
         8: polynom = 32'b10111000;                         // 0xb8
2312
         9: polynom = 32'b100010000;                        // 0x110
2313
        10: polynom = 32'b1001000000;                       // 0x240
2314
        11: polynom = 32'b10100000000;                      // 0x500
2315
        12: polynom = 32'b100000101001;                     // 0x829
2316
        13: polynom = 32'b1000000001100;                    // 0x100C
2317
        14: polynom = 32'b10000000010101;                   // 0x2015
2318
        15: polynom = 32'b110000000000000;                  // 0x6000
2319
        16: polynom = 32'b1101000000001000;                 // 0xD008
2320
        17: polynom = 32'b10010000000000000;                // 0x12000
2321
        18: polynom = 32'b100000010000000000;               // 0x20400
2322
        19: polynom = 32'b1000000000000100011;              // 0x40023
2323 37 unneback
        20: polynom = 32'b10010000000000000000;             // 0x90000
2324 6 unneback
        21: polynom = 32'b101000000000000000000;            // 0x140000
2325
        22: polynom = 32'b1100000000000000000000;           // 0x300000
2326
        23: polynom = 32'b10000100000000000000000;          // 0x420000
2327
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
2328
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
2329
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
2330
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
2331
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
2332
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
2333
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
2334
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
2335
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
2336
        default: polynom = 32'b0;
2337
        endcase
2338
        lfsr_fb = qi[length];
2339
        for (i=length-1; i>=1; i=i-1) begin
2340
            if (polynom[i])
2341
                lfsr_fb = lfsr_fb  ~^ qi[i];
2342
        end
2343
    end
2344
   assign q_next = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
2345
 
2346
   always @ (posedge clk or posedge rst)
2347
     if (rst)
2348
       qi <= {length{1'b0}};
2349
     else
2350
       qi <= q_next;
2351
 
2352
 
2353
 
2354
   always @ (posedge clk or posedge rst)
2355
     if (rst)
2356
       zq <= 1'b1;
2357
     else
2358
       zq <= q_next == {length{1'b0}};
2359
endmodule
2360 40 unneback
`endif
2361
`ifdef CNT_LFSR_CE_ZQ
2362 6 unneback
//////////////////////////////////////////////////////////////////////
2363
////                                                              ////
2364
////  Versatile counter                                           ////
2365
////                                                              ////
2366
////  Description                                                 ////
2367
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2368
////  counter                                                     ////
2369
////                                                              ////
2370
////  To Do:                                                      ////
2371
////   - add LFSR with more taps                                  ////
2372
////                                                              ////
2373
////  Author(s):                                                  ////
2374
////      - Michael Unneback, unneback@opencores.org              ////
2375
////        ORSoC AB                                              ////
2376
////                                                              ////
2377
//////////////////////////////////////////////////////////////////////
2378
////                                                              ////
2379
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2380
////                                                              ////
2381
//// This source file may be used and distributed without         ////
2382
//// restriction provided that this copyright statement is not    ////
2383
//// removed from the file and that any derivative work contains  ////
2384
//// the original copyright notice and the associated disclaimer. ////
2385
////                                                              ////
2386
//// This source file is free software; you can redistribute it   ////
2387
//// and/or modify it under the terms of the GNU Lesser General   ////
2388
//// Public License as published by the Free Software Foundation; ////
2389
//// either version 2.1 of the License, or (at your option) any   ////
2390
//// later version.                                               ////
2391
////                                                              ////
2392
//// This source is distributed in the hope that it will be       ////
2393
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2394
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2395
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2396
//// details.                                                     ////
2397
////                                                              ////
2398
//// You should have received a copy of the GNU Lesser General    ////
2399
//// Public License along with this source; if not, download it   ////
2400
//// from http://www.opencores.org/lgpl.shtml                     ////
2401
////                                                              ////
2402
//////////////////////////////////////////////////////////////////////
2403
 
2404
// LFSR counter
2405
 
2406 40 unneback
`define MODULE cnt_lfsr_ce_zq
2407
module `BASE`MODULE (
2408
`undef MODULE
2409
 cke, zq, rst, clk);
2410
 
2411 6 unneback
   parameter length = 4;
2412
   input cke;
2413
   output reg zq;
2414
   input rst;
2415
   input clk;
2416
 
2417
   parameter clear_value = 0;
2418
   parameter set_value = 1;
2419
   parameter wrap_value = 8;
2420
   parameter level1_value = 15;
2421
 
2422
   reg  [length:1] qi;
2423
   reg lfsr_fb;
2424
   wire [length:1] q_next;
2425
   reg [32:1] polynom;
2426
   integer i;
2427
 
2428
   always @ (qi)
2429
   begin
2430
        case (length)
2431
         2: polynom = 32'b11;                               // 0x3
2432
         3: polynom = 32'b110;                              // 0x6
2433
         4: polynom = 32'b1100;                             // 0xC
2434
         5: polynom = 32'b10100;                            // 0x14
2435
         6: polynom = 32'b110000;                           // 0x30
2436
         7: polynom = 32'b1100000;                          // 0x60
2437
         8: polynom = 32'b10111000;                         // 0xb8
2438
         9: polynom = 32'b100010000;                        // 0x110
2439
        10: polynom = 32'b1001000000;                       // 0x240
2440
        11: polynom = 32'b10100000000;                      // 0x500
2441
        12: polynom = 32'b100000101001;                     // 0x829
2442
        13: polynom = 32'b1000000001100;                    // 0x100C
2443
        14: polynom = 32'b10000000010101;                   // 0x2015
2444
        15: polynom = 32'b110000000000000;                  // 0x6000
2445
        16: polynom = 32'b1101000000001000;                 // 0xD008
2446
        17: polynom = 32'b10010000000000000;                // 0x12000
2447
        18: polynom = 32'b100000010000000000;               // 0x20400
2448
        19: polynom = 32'b1000000000000100011;              // 0x40023
2449 37 unneback
        20: polynom = 32'b10010000000000000000;             // 0x90000
2450 6 unneback
        21: polynom = 32'b101000000000000000000;            // 0x140000
2451
        22: polynom = 32'b1100000000000000000000;           // 0x300000
2452
        23: polynom = 32'b10000100000000000000000;          // 0x420000
2453
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
2454
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
2455
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
2456
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
2457
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
2458
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
2459
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
2460
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
2461
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
2462
        default: polynom = 32'b0;
2463
        endcase
2464
        lfsr_fb = qi[length];
2465
        for (i=length-1; i>=1; i=i-1) begin
2466
            if (polynom[i])
2467
                lfsr_fb = lfsr_fb  ~^ qi[i];
2468
        end
2469
    end
2470
   assign q_next = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
2471
 
2472
   always @ (posedge clk or posedge rst)
2473
     if (rst)
2474
       qi <= {length{1'b0}};
2475
     else
2476
     if (cke)
2477
       qi <= q_next;
2478
 
2479
 
2480
 
2481
   always @ (posedge clk or posedge rst)
2482
     if (rst)
2483
       zq <= 1'b1;
2484
     else
2485
     if (cke)
2486
       zq <= q_next == {length{1'b0}};
2487
endmodule
2488 40 unneback
`endif
2489
`ifdef CNT_LFSR_CE_Q
2490 6 unneback
//////////////////////////////////////////////////////////////////////
2491
////                                                              ////
2492
////  Versatile counter                                           ////
2493
////                                                              ////
2494
////  Description                                                 ////
2495
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2496
////  counter                                                     ////
2497
////                                                              ////
2498
////  To Do:                                                      ////
2499
////   - add LFSR with more taps                                  ////
2500
////                                                              ////
2501
////  Author(s):                                                  ////
2502
////      - Michael Unneback, unneback@opencores.org              ////
2503
////        ORSoC AB                                              ////
2504
////                                                              ////
2505
//////////////////////////////////////////////////////////////////////
2506
////                                                              ////
2507
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2508
////                                                              ////
2509
//// This source file may be used and distributed without         ////
2510
//// restriction provided that this copyright statement is not    ////
2511
//// removed from the file and that any derivative work contains  ////
2512
//// the original copyright notice and the associated disclaimer. ////
2513
////                                                              ////
2514
//// This source file is free software; you can redistribute it   ////
2515
//// and/or modify it under the terms of the GNU Lesser General   ////
2516
//// Public License as published by the Free Software Foundation; ////
2517
//// either version 2.1 of the License, or (at your option) any   ////
2518
//// later version.                                               ////
2519
////                                                              ////
2520
//// This source is distributed in the hope that it will be       ////
2521
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2522
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2523
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2524
//// details.                                                     ////
2525
////                                                              ////
2526
//// You should have received a copy of the GNU Lesser General    ////
2527
//// Public License along with this source; if not, download it   ////
2528
//// from http://www.opencores.org/lgpl.shtml                     ////
2529
////                                                              ////
2530
//////////////////////////////////////////////////////////////////////
2531 22 unneback
 
2532
// LFSR counter
2533 27 unneback
 
2534 40 unneback
`define MODULE cnt_lfsr_ce_q
2535
module `BASE`MODULE (
2536
`undef MODULE
2537
 cke, q, rst, clk);
2538
 
2539 27 unneback
   parameter length = 4;
2540
   input cke;
2541
   output [length:1] q;
2542
   input rst;
2543
   input clk;
2544
 
2545
   parameter clear_value = 0;
2546
   parameter set_value = 1;
2547
   parameter wrap_value = 8;
2548
   parameter level1_value = 15;
2549
 
2550
   reg  [length:1] qi;
2551
   reg lfsr_fb;
2552
   wire [length:1] q_next;
2553
   reg [32:1] polynom;
2554
   integer i;
2555
 
2556
   always @ (qi)
2557
   begin
2558
        case (length)
2559
         2: polynom = 32'b11;                               // 0x3
2560
         3: polynom = 32'b110;                              // 0x6
2561
         4: polynom = 32'b1100;                             // 0xC
2562
         5: polynom = 32'b10100;                            // 0x14
2563
         6: polynom = 32'b110000;                           // 0x30
2564
         7: polynom = 32'b1100000;                          // 0x60
2565
         8: polynom = 32'b10111000;                         // 0xb8
2566
         9: polynom = 32'b100010000;                        // 0x110
2567
        10: polynom = 32'b1001000000;                       // 0x240
2568
        11: polynom = 32'b10100000000;                      // 0x500
2569
        12: polynom = 32'b100000101001;                     // 0x829
2570
        13: polynom = 32'b1000000001100;                    // 0x100C
2571
        14: polynom = 32'b10000000010101;                   // 0x2015
2572
        15: polynom = 32'b110000000000000;                  // 0x6000
2573
        16: polynom = 32'b1101000000001000;                 // 0xD008
2574
        17: polynom = 32'b10010000000000000;                // 0x12000
2575
        18: polynom = 32'b100000010000000000;               // 0x20400
2576
        19: polynom = 32'b1000000000000100011;              // 0x40023
2577 37 unneback
        20: polynom = 32'b10010000000000000000;             // 0x90000
2578 27 unneback
        21: polynom = 32'b101000000000000000000;            // 0x140000
2579
        22: polynom = 32'b1100000000000000000000;           // 0x300000
2580
        23: polynom = 32'b10000100000000000000000;          // 0x420000
2581
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
2582
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
2583
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
2584
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
2585
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
2586
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
2587
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
2588
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
2589
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
2590
        default: polynom = 32'b0;
2591
        endcase
2592
        lfsr_fb = qi[length];
2593
        for (i=length-1; i>=1; i=i-1) begin
2594
            if (polynom[i])
2595
                lfsr_fb = lfsr_fb  ~^ qi[i];
2596
        end
2597
    end
2598
   assign q_next = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
2599
 
2600
   always @ (posedge clk or posedge rst)
2601
     if (rst)
2602
       qi <= {length{1'b0}};
2603
     else
2604
     if (cke)
2605
       qi <= q_next;
2606
 
2607
   assign q = qi;
2608
 
2609
endmodule
2610 40 unneback
`endif
2611
`ifdef CNT_LFSR_CE_CLEAR_Q
2612 27 unneback
//////////////////////////////////////////////////////////////////////
2613
////                                                              ////
2614
////  Versatile counter                                           ////
2615
////                                                              ////
2616
////  Description                                                 ////
2617
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2618
////  counter                                                     ////
2619
////                                                              ////
2620
////  To Do:                                                      ////
2621
////   - add LFSR with more taps                                  ////
2622
////                                                              ////
2623
////  Author(s):                                                  ////
2624
////      - Michael Unneback, unneback@opencores.org              ////
2625
////        ORSoC AB                                              ////
2626
////                                                              ////
2627
//////////////////////////////////////////////////////////////////////
2628
////                                                              ////
2629
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2630
////                                                              ////
2631
//// This source file may be used and distributed without         ////
2632
//// restriction provided that this copyright statement is not    ////
2633
//// removed from the file and that any derivative work contains  ////
2634
//// the original copyright notice and the associated disclaimer. ////
2635
////                                                              ////
2636
//// This source file is free software; you can redistribute it   ////
2637
//// and/or modify it under the terms of the GNU Lesser General   ////
2638
//// Public License as published by the Free Software Foundation; ////
2639
//// either version 2.1 of the License, or (at your option) any   ////
2640
//// later version.                                               ////
2641
////                                                              ////
2642
//// This source is distributed in the hope that it will be       ////
2643
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2644
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2645
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2646
//// details.                                                     ////
2647
////                                                              ////
2648
//// You should have received a copy of the GNU Lesser General    ////
2649
//// Public License along with this source; if not, download it   ////
2650
//// from http://www.opencores.org/lgpl.shtml                     ////
2651
////                                                              ////
2652
//////////////////////////////////////////////////////////////////////
2653
 
2654
// LFSR counter
2655
 
2656 40 unneback
`define MODULE cnt_lfsr_ce_clear_q
2657
module `BASE`MODULE (
2658
`undef MODULE
2659
 clear, cke, q, rst, clk);
2660
 
2661 27 unneback
   parameter length = 4;
2662
   input clear;
2663
   input cke;
2664
   output [length:1] q;
2665
   input rst;
2666
   input clk;
2667
 
2668
   parameter clear_value = 0;
2669
   parameter set_value = 1;
2670
   parameter wrap_value = 8;
2671
   parameter level1_value = 15;
2672
 
2673
   reg  [length:1] qi;
2674
   reg lfsr_fb;
2675
   wire [length:1] q_next;
2676
   reg [32:1] polynom;
2677
   integer i;
2678
 
2679
   always @ (qi)
2680
   begin
2681
        case (length)
2682
         2: polynom = 32'b11;                               // 0x3
2683
         3: polynom = 32'b110;                              // 0x6
2684
         4: polynom = 32'b1100;                             // 0xC
2685
         5: polynom = 32'b10100;                            // 0x14
2686
         6: polynom = 32'b110000;                           // 0x30
2687
         7: polynom = 32'b1100000;                          // 0x60
2688
         8: polynom = 32'b10111000;                         // 0xb8
2689
         9: polynom = 32'b100010000;                        // 0x110
2690
        10: polynom = 32'b1001000000;                       // 0x240
2691
        11: polynom = 32'b10100000000;                      // 0x500
2692
        12: polynom = 32'b100000101001;                     // 0x829
2693
        13: polynom = 32'b1000000001100;                    // 0x100C
2694
        14: polynom = 32'b10000000010101;                   // 0x2015
2695
        15: polynom = 32'b110000000000000;                  // 0x6000
2696
        16: polynom = 32'b1101000000001000;                 // 0xD008
2697
        17: polynom = 32'b10010000000000000;                // 0x12000
2698
        18: polynom = 32'b100000010000000000;               // 0x20400
2699
        19: polynom = 32'b1000000000000100011;              // 0x40023
2700 37 unneback
        20: polynom = 32'b10010000000000000000;             // 0x90000
2701 27 unneback
        21: polynom = 32'b101000000000000000000;            // 0x140000
2702
        22: polynom = 32'b1100000000000000000000;           // 0x300000
2703
        23: polynom = 32'b10000100000000000000000;          // 0x420000
2704
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
2705
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
2706
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
2707
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
2708
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
2709
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
2710
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
2711
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
2712
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
2713
        default: polynom = 32'b0;
2714
        endcase
2715
        lfsr_fb = qi[length];
2716
        for (i=length-1; i>=1; i=i-1) begin
2717
            if (polynom[i])
2718
                lfsr_fb = lfsr_fb  ~^ qi[i];
2719
        end
2720
    end
2721
   assign q_next =  clear ? {length{1'b0}} :(qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
2722
 
2723
   always @ (posedge clk or posedge rst)
2724
     if (rst)
2725
       qi <= {length{1'b0}};
2726
     else
2727
     if (cke)
2728
       qi <= q_next;
2729
 
2730
   assign q = qi;
2731
 
2732
endmodule
2733 40 unneback
`endif
2734
`ifdef CNT_LFSR_CE_Q_ZQ
2735 27 unneback
//////////////////////////////////////////////////////////////////////
2736
////                                                              ////
2737
////  Versatile counter                                           ////
2738
////                                                              ////
2739
////  Description                                                 ////
2740
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2741
////  counter                                                     ////
2742
////                                                              ////
2743
////  To Do:                                                      ////
2744
////   - add LFSR with more taps                                  ////
2745
////                                                              ////
2746
////  Author(s):                                                  ////
2747
////      - Michael Unneback, unneback@opencores.org              ////
2748
////        ORSoC AB                                              ////
2749
////                                                              ////
2750
//////////////////////////////////////////////////////////////////////
2751
////                                                              ////
2752
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2753
////                                                              ////
2754
//// This source file may be used and distributed without         ////
2755
//// restriction provided that this copyright statement is not    ////
2756
//// removed from the file and that any derivative work contains  ////
2757
//// the original copyright notice and the associated disclaimer. ////
2758
////                                                              ////
2759
//// This source file is free software; you can redistribute it   ////
2760
//// and/or modify it under the terms of the GNU Lesser General   ////
2761
//// Public License as published by the Free Software Foundation; ////
2762
//// either version 2.1 of the License, or (at your option) any   ////
2763
//// later version.                                               ////
2764
////                                                              ////
2765
//// This source is distributed in the hope that it will be       ////
2766
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2767
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2768
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2769
//// details.                                                     ////
2770
////                                                              ////
2771
//// You should have received a copy of the GNU Lesser General    ////
2772
//// Public License along with this source; if not, download it   ////
2773
//// from http://www.opencores.org/lgpl.shtml                     ////
2774
////                                                              ////
2775
//////////////////////////////////////////////////////////////////////
2776
 
2777
// LFSR counter
2778 22 unneback
 
2779 40 unneback
`define MODULE cnt_lfsr_ce_q_zq
2780
module `BASE`MODULE (
2781
`undef MODULE
2782
 cke, q, zq, rst, clk);
2783
 
2784 22 unneback
   parameter length = 4;
2785
   input cke;
2786
   output [length:1] q;
2787
   output reg zq;
2788
   input rst;
2789
   input clk;
2790
 
2791
   parameter clear_value = 0;
2792
   parameter set_value = 1;
2793
   parameter wrap_value = 8;
2794
   parameter level1_value = 15;
2795
 
2796
   reg  [length:1] qi;
2797
   reg lfsr_fb;
2798
   wire [length:1] q_next;
2799
   reg [32:1] polynom;
2800
   integer i;
2801
 
2802
   always @ (qi)
2803
   begin
2804
        case (length)
2805
         2: polynom = 32'b11;                               // 0x3
2806
         3: polynom = 32'b110;                              // 0x6
2807
         4: polynom = 32'b1100;                             // 0xC
2808
         5: polynom = 32'b10100;                            // 0x14
2809
         6: polynom = 32'b110000;                           // 0x30
2810
         7: polynom = 32'b1100000;                          // 0x60
2811
         8: polynom = 32'b10111000;                         // 0xb8
2812
         9: polynom = 32'b100010000;                        // 0x110
2813
        10: polynom = 32'b1001000000;                       // 0x240
2814
        11: polynom = 32'b10100000000;                      // 0x500
2815
        12: polynom = 32'b100000101001;                     // 0x829
2816
        13: polynom = 32'b1000000001100;                    // 0x100C
2817
        14: polynom = 32'b10000000010101;                   // 0x2015
2818
        15: polynom = 32'b110000000000000;                  // 0x6000
2819
        16: polynom = 32'b1101000000001000;                 // 0xD008
2820
        17: polynom = 32'b10010000000000000;                // 0x12000
2821
        18: polynom = 32'b100000010000000000;               // 0x20400
2822
        19: polynom = 32'b1000000000000100011;              // 0x40023
2823 37 unneback
        20: polynom = 32'b10010000000000000000;             // 0x90000
2824 22 unneback
        21: polynom = 32'b101000000000000000000;            // 0x140000
2825
        22: polynom = 32'b1100000000000000000000;           // 0x300000
2826
        23: polynom = 32'b10000100000000000000000;          // 0x420000
2827
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
2828
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
2829
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
2830
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
2831
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
2832
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
2833
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
2834
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
2835
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
2836
        default: polynom = 32'b0;
2837
        endcase
2838
        lfsr_fb = qi[length];
2839
        for (i=length-1; i>=1; i=i-1) begin
2840
            if (polynom[i])
2841
                lfsr_fb = lfsr_fb  ~^ qi[i];
2842
        end
2843
    end
2844
   assign q_next = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
2845
 
2846
   always @ (posedge clk or posedge rst)
2847
     if (rst)
2848
       qi <= {length{1'b0}};
2849
     else
2850
     if (cke)
2851
       qi <= q_next;
2852
 
2853
   assign q = qi;
2854
 
2855
 
2856
   always @ (posedge clk or posedge rst)
2857
     if (rst)
2858
       zq <= 1'b1;
2859
     else
2860
     if (cke)
2861
       zq <= q_next == {length{1'b0}};
2862
endmodule
2863 40 unneback
`endif
2864
`ifdef CNT_LFSR_CE_REW_L1
2865 22 unneback
//////////////////////////////////////////////////////////////////////
2866
////                                                              ////
2867
////  Versatile counter                                           ////
2868
////                                                              ////
2869
////  Description                                                 ////
2870
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
2871
////  counter                                                     ////
2872
////                                                              ////
2873
////  To Do:                                                      ////
2874
////   - add LFSR with more taps                                  ////
2875
////                                                              ////
2876
////  Author(s):                                                  ////
2877
////      - Michael Unneback, unneback@opencores.org              ////
2878
////        ORSoC AB                                              ////
2879
////                                                              ////
2880
//////////////////////////////////////////////////////////////////////
2881
////                                                              ////
2882
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
2883
////                                                              ////
2884
//// This source file may be used and distributed without         ////
2885
//// restriction provided that this copyright statement is not    ////
2886
//// removed from the file and that any derivative work contains  ////
2887
//// the original copyright notice and the associated disclaimer. ////
2888
////                                                              ////
2889
//// This source file is free software; you can redistribute it   ////
2890
//// and/or modify it under the terms of the GNU Lesser General   ////
2891
//// Public License as published by the Free Software Foundation; ////
2892
//// either version 2.1 of the License, or (at your option) any   ////
2893
//// later version.                                               ////
2894
////                                                              ////
2895
//// This source is distributed in the hope that it will be       ////
2896
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2897
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2898
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2899
//// details.                                                     ////
2900
////                                                              ////
2901
//// You should have received a copy of the GNU Lesser General    ////
2902
//// Public License along with this source; if not, download it   ////
2903
//// from http://www.opencores.org/lgpl.shtml                     ////
2904
////                                                              ////
2905
//////////////////////////////////////////////////////////////////////
2906 6 unneback
 
2907
// LFSR counter
2908
 
2909 40 unneback
`define MODULE cnt_lfsr_ce_rew_l1
2910
module `BASE`MODULE (
2911
`undef MODULE
2912
 cke, rew, level1, rst, clk);
2913
 
2914 6 unneback
   parameter length = 4;
2915
   input cke;
2916
   input rew;
2917
   output reg level1;
2918
   input rst;
2919
   input clk;
2920
 
2921
   parameter clear_value = 0;
2922
   parameter set_value = 1;
2923
   parameter wrap_value = 8;
2924
   parameter level1_value = 15;
2925
 
2926 29 unneback
   wire clear;
2927 30 unneback
   assign clear = 1'b0;
2928 6 unneback
   reg  [length:1] qi;
2929
   reg lfsr_fb, lfsr_fb_rew;
2930
   wire  [length:1] q_next, q_next_fw, q_next_rew;
2931
   reg [32:1] polynom_rew;
2932
   integer j;
2933
   reg [32:1] polynom;
2934
   integer i;
2935
 
2936
   always @ (qi)
2937
   begin
2938
        case (length)
2939
         2: polynom = 32'b11;                               // 0x3
2940
         3: polynom = 32'b110;                              // 0x6
2941
         4: polynom = 32'b1100;                             // 0xC
2942
         5: polynom = 32'b10100;                            // 0x14
2943
         6: polynom = 32'b110000;                           // 0x30
2944
         7: polynom = 32'b1100000;                          // 0x60
2945
         8: polynom = 32'b10111000;                         // 0xb8
2946
         9: polynom = 32'b100010000;                        // 0x110
2947
        10: polynom = 32'b1001000000;                       // 0x240
2948
        11: polynom = 32'b10100000000;                      // 0x500
2949
        12: polynom = 32'b100000101001;                     // 0x829
2950
        13: polynom = 32'b1000000001100;                    // 0x100C
2951
        14: polynom = 32'b10000000010101;                   // 0x2015
2952
        15: polynom = 32'b110000000000000;                  // 0x6000
2953
        16: polynom = 32'b1101000000001000;                 // 0xD008
2954
        17: polynom = 32'b10010000000000000;                // 0x12000
2955
        18: polynom = 32'b100000010000000000;               // 0x20400
2956
        19: polynom = 32'b1000000000000100011;              // 0x40023
2957 37 unneback
        20: polynom = 32'b10010000000000000000;             // 0x90000
2958 6 unneback
        21: polynom = 32'b101000000000000000000;            // 0x140000
2959
        22: polynom = 32'b1100000000000000000000;           // 0x300000
2960
        23: polynom = 32'b10000100000000000000000;          // 0x420000
2961
        24: polynom = 32'b111000010000000000000000;         // 0xE10000
2962
        25: polynom = 32'b1001000000000000000000000;        // 0x1200000
2963
        26: polynom = 32'b10000000000000000000100011;       // 0x2000023
2964
        27: polynom = 32'b100000000000000000000010011;      // 0x4000013
2965
        28: polynom = 32'b1100100000000000000000000000;     // 0xC800000
2966
        29: polynom = 32'b10100000000000000000000000000;    // 0x14000000
2967
        30: polynom = 32'b100000000000000000000000101001;   // 0x20000029
2968
        31: polynom = 32'b1001000000000000000000000000000;  // 0x48000000
2969
        32: polynom = 32'b10000000001000000000000000000011; // 0x80200003
2970
        default: polynom = 32'b0;
2971
        endcase
2972
        lfsr_fb = qi[length];
2973
        for (i=length-1; i>=1; i=i-1) begin
2974
            if (polynom[i])
2975
                lfsr_fb = lfsr_fb  ~^ qi[i];
2976
        end
2977
    end
2978
   assign q_next_fw  = (qi == wrap_value) ? {length{1'b0}} :{qi[length-1:1],lfsr_fb};
2979
   always @ (qi)
2980
   begin
2981
        case (length)
2982
         2: polynom_rew = 32'b11;
2983
         3: polynom_rew = 32'b110;
2984
         4: polynom_rew = 32'b1100;
2985
         5: polynom_rew = 32'b10100;
2986
         6: polynom_rew = 32'b110000;
2987
         7: polynom_rew = 32'b1100000;
2988
         8: polynom_rew = 32'b10111000;
2989
         9: polynom_rew = 32'b100010000;
2990
        10: polynom_rew = 32'b1001000000;
2991
        11: polynom_rew = 32'b10100000000;
2992
        12: polynom_rew = 32'b100000101001;
2993
        13: polynom_rew = 32'b1000000001100;
2994
        14: polynom_rew = 32'b10000000010101;
2995
        15: polynom_rew = 32'b110000000000000;
2996
        16: polynom_rew = 32'b1101000000001000;
2997
        17: polynom_rew = 32'b10010000000000000;
2998
        18: polynom_rew = 32'b100000010000000000;
2999
        19: polynom_rew = 32'b1000000000000100011;
3000
        20: polynom_rew = 32'b10000010000000000000;
3001
        21: polynom_rew = 32'b101000000000000000000;
3002
        22: polynom_rew = 32'b1100000000000000000000;
3003
        23: polynom_rew = 32'b10000100000000000000000;
3004
        24: polynom_rew = 32'b111000010000000000000000;
3005
        25: polynom_rew = 32'b1001000000000000000000000;
3006
        26: polynom_rew = 32'b10000000000000000000100011;
3007
        27: polynom_rew = 32'b100000000000000000000010011;
3008
        28: polynom_rew = 32'b1100100000000000000000000000;
3009
        29: polynom_rew = 32'b10100000000000000000000000000;
3010
        30: polynom_rew = 32'b100000000000000000000000101001;
3011
        31: polynom_rew = 32'b1001000000000000000000000000000;
3012
        32: polynom_rew = 32'b10000000001000000000000000000011;
3013
        default: polynom_rew = 32'b0;
3014
        endcase
3015
        // rotate left
3016
        polynom_rew[length:1] = { polynom_rew[length-2:1],polynom_rew[length] };
3017
        lfsr_fb_rew = qi[length];
3018
        for (i=length-1; i>=1; i=i-1) begin
3019
            if (polynom_rew[i])
3020
                lfsr_fb_rew = lfsr_fb_rew  ~^ qi[i];
3021
        end
3022
    end
3023
   assign q_next_rew = (qi == wrap_value) ? {length{1'b0}} :{lfsr_fb_rew,qi[length:2]};
3024
   assign q_next = rew ? q_next_rew : q_next_fw;
3025
 
3026
   always @ (posedge clk or posedge rst)
3027
     if (rst)
3028
       qi <= {length{1'b0}};
3029
     else
3030
     if (cke)
3031
       qi <= q_next;
3032
 
3033
 
3034
 
3035
    always @ (posedge clk or posedge rst)
3036
    if (rst)
3037
        level1 <= 1'b0;
3038
    else
3039
    if (cke)
3040 29 unneback
    if (clear)
3041
        level1 <= 1'b0;
3042
    else if (q_next == level1_value)
3043 6 unneback
        level1 <= 1'b1;
3044
    else if (qi == level1_value & rew)
3045
        level1 <= 1'b0;
3046
endmodule
3047 40 unneback
`endif
3048
`ifdef CNT_GRAY
3049 6 unneback
//////////////////////////////////////////////////////////////////////
3050
////                                                              ////
3051
////  Versatile counter                                           ////
3052
////                                                              ////
3053
////  Description                                                 ////
3054
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
3055
////  counter                                                     ////
3056
////                                                              ////
3057
////  To Do:                                                      ////
3058
////   - add LFSR with more taps                                  ////
3059
////                                                              ////
3060
////  Author(s):                                                  ////
3061
////      - Michael Unneback, unneback@opencores.org              ////
3062
////        ORSoC AB                                              ////
3063
////                                                              ////
3064
//////////////////////////////////////////////////////////////////////
3065
////                                                              ////
3066
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
3067
////                                                              ////
3068
//// This source file may be used and distributed without         ////
3069
//// restriction provided that this copyright statement is not    ////
3070
//// removed from the file and that any derivative work contains  ////
3071
//// the original copyright notice and the associated disclaimer. ////
3072
////                                                              ////
3073
//// This source file is free software; you can redistribute it   ////
3074
//// and/or modify it under the terms of the GNU Lesser General   ////
3075
//// Public License as published by the Free Software Foundation; ////
3076
//// either version 2.1 of the License, or (at your option) any   ////
3077
//// later version.                                               ////
3078
////                                                              ////
3079
//// This source is distributed in the hope that it will be       ////
3080
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
3081
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
3082
//// PURPOSE.  See the GNU Lesser General Public License for more ////
3083
//// details.                                                     ////
3084
////                                                              ////
3085
//// You should have received a copy of the GNU Lesser General    ////
3086
//// Public License along with this source; if not, download it   ////
3087
//// from http://www.opencores.org/lgpl.shtml                     ////
3088
////                                                              ////
3089
//////////////////////////////////////////////////////////////////////
3090
 
3091
// GRAY counter
3092
 
3093 40 unneback
`define MODULE cnt_gray
3094
module `BASE`MODULE (
3095
`undef MODULE
3096
 q, rst, clk);
3097
 
3098 6 unneback
   parameter length = 4;
3099
   output reg [length:1] q;
3100
   input rst;
3101
   input clk;
3102
 
3103
   parameter clear_value = 0;
3104
   parameter set_value = 1;
3105
   parameter wrap_value = 8;
3106
   parameter level1_value = 15;
3107
 
3108
   reg  [length:1] qi;
3109
   wire [length:1] q_next;
3110
   assign q_next = qi + {{length-1{1'b0}},1'b1};
3111
 
3112
   always @ (posedge clk or posedge rst)
3113
     if (rst)
3114
       qi <= {length{1'b0}};
3115
     else
3116
       qi <= q_next;
3117
 
3118
   always @ (posedge clk or posedge rst)
3119
     if (rst)
3120
       q <= {length{1'b0}};
3121
     else
3122
         q <= (q_next>>1) ^ q_next;
3123
 
3124
endmodule
3125 40 unneback
`endif
3126
`ifdef CNT_GRAY_CE
3127 6 unneback
//////////////////////////////////////////////////////////////////////
3128
////                                                              ////
3129
////  Versatile counter                                           ////
3130
////                                                              ////
3131
////  Description                                                 ////
3132
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
3133
////  counter                                                     ////
3134
////                                                              ////
3135
////  To Do:                                                      ////
3136
////   - add LFSR with more taps                                  ////
3137
////                                                              ////
3138
////  Author(s):                                                  ////
3139
////      - Michael Unneback, unneback@opencores.org              ////
3140
////        ORSoC AB                                              ////
3141
////                                                              ////
3142
//////////////////////////////////////////////////////////////////////
3143
////                                                              ////
3144
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
3145
////                                                              ////
3146
//// This source file may be used and distributed without         ////
3147
//// restriction provided that this copyright statement is not    ////
3148
//// removed from the file and that any derivative work contains  ////
3149
//// the original copyright notice and the associated disclaimer. ////
3150
////                                                              ////
3151
//// This source file is free software; you can redistribute it   ////
3152
//// and/or modify it under the terms of the GNU Lesser General   ////
3153
//// Public License as published by the Free Software Foundation; ////
3154
//// either version 2.1 of the License, or (at your option) any   ////
3155
//// later version.                                               ////
3156
////                                                              ////
3157
//// This source is distributed in the hope that it will be       ////
3158
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
3159
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
3160
//// PURPOSE.  See the GNU Lesser General Public License for more ////
3161
//// details.                                                     ////
3162
////                                                              ////
3163
//// You should have received a copy of the GNU Lesser General    ////
3164
//// Public License along with this source; if not, download it   ////
3165
//// from http://www.opencores.org/lgpl.shtml                     ////
3166
////                                                              ////
3167
//////////////////////////////////////////////////////////////////////
3168
 
3169
// GRAY counter
3170
 
3171 40 unneback
`define MODULE cnt_gray_ce
3172
module `BASE`MODULE (
3173
`undef MODULE
3174
 cke, q, rst, clk);
3175
 
3176 6 unneback
   parameter length = 4;
3177
   input cke;
3178
   output reg [length:1] q;
3179
   input rst;
3180
   input clk;
3181
 
3182
   parameter clear_value = 0;
3183
   parameter set_value = 1;
3184
   parameter wrap_value = 8;
3185
   parameter level1_value = 15;
3186
 
3187
   reg  [length:1] qi;
3188
   wire [length:1] q_next;
3189
   assign q_next = qi + {{length-1{1'b0}},1'b1};
3190
 
3191
   always @ (posedge clk or posedge rst)
3192
     if (rst)
3193
       qi <= {length{1'b0}};
3194
     else
3195
     if (cke)
3196
       qi <= q_next;
3197
 
3198
   always @ (posedge clk or posedge rst)
3199
     if (rst)
3200
       q <= {length{1'b0}};
3201
     else
3202
       if (cke)
3203
         q <= (q_next>>1) ^ q_next;
3204
 
3205
endmodule
3206 40 unneback
`endif
3207
`ifdef CNT_GRAY_CE_BIN
3208 6 unneback
//////////////////////////////////////////////////////////////////////
3209
////                                                              ////
3210
////  Versatile counter                                           ////
3211
////                                                              ////
3212
////  Description                                                 ////
3213
////  Versatile counter, a reconfigurable binary, gray or LFSR    ////
3214
////  counter                                                     ////
3215
////                                                              ////
3216
////  To Do:                                                      ////
3217
////   - add LFSR with more taps                                  ////
3218
////                                                              ////
3219
////  Author(s):                                                  ////
3220
////      - Michael Unneback, unneback@opencores.org              ////
3221
////        ORSoC AB                                              ////
3222
////                                                              ////
3223
//////////////////////////////////////////////////////////////////////
3224
////                                                              ////
3225
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
3226
////                                                              ////
3227
//// This source file may be used and distributed without         ////
3228
//// restriction provided that this copyright statement is not    ////
3229
//// removed from the file and that any derivative work contains  ////
3230
//// the original copyright notice and the associated disclaimer. ////
3231
////                                                              ////
3232
//// This source file is free software; you can redistribute it   ////
3233
//// and/or modify it under the terms of the GNU Lesser General   ////
3234
//// Public License as published by the Free Software Foundation; ////
3235
//// either version 2.1 of the License, or (at your option) any   ////
3236
//// later version.                                               ////
3237
////                                                              ////
3238
//// This source is distributed in the hope that it will be       ////
3239
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
3240
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
3241
//// PURPOSE.  See the GNU Lesser General Public License for more ////
3242
//// details.                                                     ////
3243
////                                                              ////
3244
//// You should have received a copy of the GNU Lesser General    ////
3245
//// Public License along with this source; if not, download it   ////
3246
//// from http://www.opencores.org/lgpl.shtml                     ////
3247
////                                                              ////
3248
//////////////////////////////////////////////////////////////////////
3249
 
3250
// GRAY counter
3251
 
3252 40 unneback
`define MODULE cnt_gray_ce_bin
3253
module `BASE`MODULE (
3254
`undef MODULE
3255
 cke, q, q_bin, rst, clk);
3256
 
3257 6 unneback
   parameter length = 4;
3258
   input cke;
3259
   output reg [length:1] q;
3260
   output [length:1] q_bin;
3261
   input rst;
3262
   input clk;
3263
 
3264
   parameter clear_value = 0;
3265
   parameter set_value = 1;
3266
   parameter wrap_value = 8;
3267
   parameter level1_value = 15;
3268
 
3269
   reg  [length:1] qi;
3270
   wire [length:1] q_next;
3271
   assign q_next = qi + {{length-1{1'b0}},1'b1};
3272
 
3273
   always @ (posedge clk or posedge rst)
3274
     if (rst)
3275
       qi <= {length{1'b0}};
3276
     else
3277
     if (cke)
3278
       qi <= q_next;
3279
 
3280
   always @ (posedge clk or posedge rst)
3281
     if (rst)
3282
       q <= {length{1'b0}};
3283
     else
3284
       if (cke)
3285
         q <= (q_next>>1) ^ q_next;
3286
 
3287
   assign q_bin = qi;
3288
 
3289
endmodule
3290 40 unneback
`endif
3291 6 unneback
//////////////////////////////////////////////////////////////////////
3292
////                                                              ////
3293
////  Versatile library, counters                                 ////
3294
////                                                              ////
3295
////  Description                                                 ////
3296
////  counters                                                    ////
3297
////                                                              ////
3298
////                                                              ////
3299
////  To Do:                                                      ////
3300
////   - add more counters                                        ////
3301
////                                                              ////
3302
////  Author(s):                                                  ////
3303
////      - Michael Unneback, unneback@opencores.org              ////
3304
////        ORSoC AB                                              ////
3305
////                                                              ////
3306
//////////////////////////////////////////////////////////////////////
3307
////                                                              ////
3308
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
3309
////                                                              ////
3310
//// This source file may be used and distributed without         ////
3311
//// restriction provided that this copyright statement is not    ////
3312
//// removed from the file and that any derivative work contains  ////
3313
//// the original copyright notice and the associated disclaimer. ////
3314
////                                                              ////
3315
//// This source file is free software; you can redistribute it   ////
3316
//// and/or modify it under the terms of the GNU Lesser General   ////
3317
//// Public License as published by the Free Software Foundation; ////
3318
//// either version 2.1 of the License, or (at your option) any   ////
3319
//// later version.                                               ////
3320
////                                                              ////
3321
//// This source is distributed in the hope that it will be       ////
3322
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
3323
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
3324
//// PURPOSE.  See the GNU Lesser General Public License for more ////
3325
//// details.                                                     ////
3326
////                                                              ////
3327
//// You should have received a copy of the GNU Lesser General    ////
3328
//// Public License along with this source; if not, download it   ////
3329
//// from http://www.opencores.org/lgpl.shtml                     ////
3330
////                                                              ////
3331
//////////////////////////////////////////////////////////////////////
3332
 
3333 40 unneback
`ifdef CNT_SHREG_WRAP
3334
`define MODULE cnt_shreg_wrap
3335
module `BASE`MODULE ( q, rst, clk);
3336
`undef MODULE
3337 6 unneback
 
3338
   parameter length = 4;
3339
   output reg [0:length-1] q;
3340
   input rst;
3341
   input clk;
3342
 
3343
    always @ (posedge clk or posedge rst)
3344
    if (rst)
3345
        q <= {1'b1,{length-1{1'b0}}};
3346
    else
3347
        q <= {q[length-1],q[0:length-2]};
3348
 
3349
endmodule
3350 40 unneback
`endif
3351 6 unneback
 
3352 40 unneback
`ifdef CNT_SHREG_CE_WRAP
3353
`define MODULE cnt_shreg_ce_wrap
3354
module `BASE`MODULE ( cke, q, rst, clk);
3355
`undef MODULE
3356 6 unneback
 
3357
   parameter length = 4;
3358
   input cke;
3359
   output reg [0:length-1] q;
3360
   input rst;
3361
   input clk;
3362
 
3363
    always @ (posedge clk or posedge rst)
3364
    if (rst)
3365
        q <= {1'b1,{length-1{1'b0}}};
3366
    else
3367
        if (cke)
3368
            q <= {q[length-1],q[0:length-2]};
3369
 
3370
endmodule
3371 40 unneback
`endif
3372 6 unneback
 
3373 40 unneback
`ifdef CNT_SHREG_CE_CLEAR
3374
`define MODULE cnt_shreg_ce_clear
3375
module `BASE`MODULE ( cke, clear, q, rst, clk);
3376
`undef MODULE
3377 6 unneback
 
3378
   parameter length = 4;
3379
   input cke, clear;
3380
   output reg [0:length-1] q;
3381
   input rst;
3382
   input clk;
3383
 
3384
    always @ (posedge clk or posedge rst)
3385
    if (rst)
3386
        q <= {1'b1,{length-1{1'b0}}};
3387
    else
3388
        if (cke)
3389
            if (clear)
3390
                q <= {1'b1,{length-1{1'b0}}};
3391
            else
3392
                q <= q >> 1;
3393
 
3394
endmodule
3395 40 unneback
`endif
3396 6 unneback
 
3397 40 unneback
`ifdef CNT_SHREG_CE_CLEAR_WRAP
3398
`define MODULE cnt_shreg_ce_clear_wrap
3399
module `BASE`MODULE ( cke, clear, q, rst, clk);
3400
`undef MODULE
3401 6 unneback
 
3402
   parameter length = 4;
3403
   input cke, clear;
3404
   output reg [0:length-1] q;
3405
   input rst;
3406
   input clk;
3407
 
3408
    always @ (posedge clk or posedge rst)
3409
    if (rst)
3410
        q <= {1'b1,{length-1{1'b0}}};
3411
    else
3412
        if (cke)
3413
            if (clear)
3414
                q <= {1'b1,{length-1{1'b0}}};
3415
            else
3416
            q <= {q[length-1],q[0:length-2]};
3417
 
3418
endmodule
3419 40 unneback
`endif
3420 6 unneback
//////////////////////////////////////////////////////////////////////
3421
////                                                              ////
3422
////  Versatile library, memories                                 ////
3423
////                                                              ////
3424
////  Description                                                 ////
3425
////  memories                                                    ////
3426
////                                                              ////
3427
////                                                              ////
3428
////  To Do:                                                      ////
3429
////   - add more memory types                                    ////
3430
////                                                              ////
3431
////  Author(s):                                                  ////
3432
////      - Michael Unneback, unneback@opencores.org              ////
3433
////        ORSoC AB                                              ////
3434
////                                                              ////
3435
//////////////////////////////////////////////////////////////////////
3436
////                                                              ////
3437
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
3438
////                                                              ////
3439
//// This source file may be used and distributed without         ////
3440
//// restriction provided that this copyright statement is not    ////
3441
//// removed from the file and that any derivative work contains  ////
3442
//// the original copyright notice and the associated disclaimer. ////
3443
////                                                              ////
3444
//// This source file is free software; you can redistribute it   ////
3445
//// and/or modify it under the terms of the GNU Lesser General   ////
3446
//// Public License as published by the Free Software Foundation; ////
3447
//// either version 2.1 of the License, or (at your option) any   ////
3448
//// later version.                                               ////
3449
////                                                              ////
3450
//// This source is distributed in the hope that it will be       ////
3451
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
3452
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
3453
//// PURPOSE.  See the GNU Lesser General Public License for more ////
3454
//// details.                                                     ////
3455
////                                                              ////
3456
//// You should have received a copy of the GNU Lesser General    ////
3457
//// Public License along with this source; if not, download it   ////
3458
//// from http://www.opencores.org/lgpl.shtml                     ////
3459
////                                                              ////
3460
//////////////////////////////////////////////////////////////////////
3461
 
3462 40 unneback
`ifdef ROM_INIT
3463 6 unneback
/// ROM
3464 40 unneback
`define MODULE rom_init
3465
module `BASE`MODULE ( adr, q, clk);
3466
`undef MODULE
3467 6 unneback
 
3468 7 unneback
   parameter data_width = 32;
3469
   parameter addr_width = 8;
3470
   input [(addr_width-1):0]       adr;
3471
   output reg [(data_width-1):0] q;
3472
   input                         clk;
3473
   reg [data_width-1:0] rom [(1<<addr_width)-1:0];
3474
   parameter memory_file = "vl_rom.vmem";
3475
   initial
3476
     begin
3477
        $readmemh(memory_file, rom);
3478
     end
3479
 
3480
   always @ (posedge clk)
3481
     q <= rom[adr];
3482 6 unneback
 
3483 7 unneback
endmodule
3484 40 unneback
`endif
3485 7 unneback
 
3486 40 unneback
`ifdef RAM
3487
`define MODULE ram
3488 6 unneback
// Single port RAM
3489 40 unneback
module `BASE`MODULE ( d, adr, we, q, clk);
3490
`undef MODULE
3491 6 unneback
 
3492
   parameter data_width = 32;
3493
   parameter addr_width = 8;
3494
   input [(data_width-1):0]      d;
3495
   input [(addr_width-1):0]       adr;
3496
   input                         we;
3497 7 unneback
   output reg [(data_width-1):0] q;
3498 6 unneback
   input                         clk;
3499
   reg [data_width-1:0] ram [(1<<addr_width)-1:0];
3500 7 unneback
   parameter init = 0;
3501
   parameter memory_file = "vl_ram.vmem";
3502
   generate if (init) begin : init_mem
3503
   initial
3504
     begin
3505
        $readmemh(memory_file, ram);
3506
     end
3507
   end
3508
   endgenerate
3509
 
3510 6 unneback
   always @ (posedge clk)
3511
   begin
3512
   if (we)
3513
     ram[adr] <= d;
3514
   q <= ram[adr];
3515
   end
3516
 
3517
endmodule
3518 40 unneback
`endif
3519 6 unneback
 
3520 40 unneback
`ifdef RAM_BE
3521
`define MODULE ram_be
3522
module `BASE`MODULE ( d, adr, be, we, q, clk);
3523
`undef MODULE
3524
 
3525 7 unneback
   parameter data_width = 32;
3526
   parameter addr_width = 8;
3527
   input [(data_width-1):0]      d;
3528
   input [(addr_width-1):0]       adr;
3529
   input [(addr_width/4)-1:0]    be;
3530
   input                         we;
3531
   output reg [(data_width-1):0] q;
3532
   input                         clk;
3533
 
3534
   reg [data_width-1:0] ram [(1<<addr_width)-1:0];
3535
 
3536 60 unneback
   parameter memory_init = 0;
3537 7 unneback
   parameter memory_file = "vl_ram.vmem";
3538 60 unneback
   generate if (memory_init) begin : init_mem
3539 7 unneback
   initial
3540
     begin
3541
        $readmemh(memory_file, ram);
3542
     end
3543
   end
3544
   endgenerate
3545
 
3546 60 unneback
`ifdef SYSTEMVERILOG
3547
// use a multi-dimensional packed array
3548
//to model individual bytes within the word
3549
 
3550
logic [dat_width/8-1:0][7:0] ram[0:1<<(adr_width-2)-1];// # words = 1 << address width
3551
always_ff@(posedge clk)
3552
begin
3553
    if(we) begin // note: we should have a for statement to support any bus width
3554
        if(be[3]) ram[adr[adr_size-2:0]][3] <= d[31:24];
3555
        if(be[2]) ram[adr[adr_size-2:0]][2] <= d[23:16];
3556
        if(be[1]) ram[adr[adr_size-2:0]][1] <= d[15:8];
3557
        if(be[0]) ram[adr[adr_size-2:0]][0] <= d[7:0];
3558
    end
3559
    q <= ram[raddr];
3560
end
3561
 
3562
`else
3563
 
3564 7 unneback
   genvar i;
3565
   generate for (i=0;i<addr_width/4;i=i+1) begin : be_ram
3566
      always @ (posedge clk)
3567
      if (we & be[i])
3568
        ram[adr][(i+1)*8-1:i*8] <= d[(i+1)*8-1:i*8];
3569
   end
3570
   endgenerate
3571
 
3572
   always @ (posedge clk)
3573
      q <= ram[adr];
3574
 
3575 60 unneback
`endif
3576
 
3577 7 unneback
endmodule
3578 40 unneback
`endif
3579 7 unneback
 
3580 6 unneback
`ifdef ACTEL
3581 48 unneback
        // ACTEL FPGA should not use logic to handle rw collision
3582 6 unneback
        `define SYN /*synthesis syn_ramstyle = "no_rw_check"*/
3583
`else
3584
        `define SYN
3585
`endif
3586
 
3587 40 unneback
`ifdef DPRAM_1R1W
3588
`define MODULE dpram_1r1w
3589
module `BASE`MODULE ( d_a, adr_a, we_a, clk_a, q_b, adr_b, clk_b );
3590
`undef MODULE
3591 6 unneback
   parameter data_width = 32;
3592
   parameter addr_width = 8;
3593
   input [(data_width-1):0]      d_a;
3594
   input [(addr_width-1):0]       adr_a;
3595
   input [(addr_width-1):0]       adr_b;
3596
   input                         we_a;
3597
   output [(data_width-1):0]      q_b;
3598
   input                         clk_a, clk_b;
3599
   reg [(addr_width-1):0]         adr_b_reg;
3600
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] `SYN;
3601 7 unneback
 
3602
   parameter init = 0;
3603
   parameter memory_file = "vl_ram.vmem";
3604
   generate if (init) begin : init_mem
3605
   initial
3606
     begin
3607
        $readmemh(memory_file, ram);
3608
     end
3609
   end
3610
   endgenerate
3611
 
3612 6 unneback
   always @ (posedge clk_a)
3613
   if (we_a)
3614
     ram[adr_a] <= d_a;
3615
   always @ (posedge clk_b)
3616
   adr_b_reg <= adr_b;
3617
   assign q_b = ram[adr_b_reg];
3618 40 unneback
 
3619 6 unneback
endmodule
3620 40 unneback
`endif
3621 6 unneback
 
3622 40 unneback
`ifdef DPRAM_2R1W
3623
`define MODULE dpram_2r1w
3624
module `BASE`MODULE ( d_a, q_a, adr_a, we_a, clk_a, q_b, adr_b, clk_b );
3625
`undef MODULE
3626
 
3627 6 unneback
   parameter data_width = 32;
3628
   parameter addr_width = 8;
3629
   input [(data_width-1):0]      d_a;
3630
   input [(addr_width-1):0]       adr_a;
3631
   input [(addr_width-1):0]       adr_b;
3632
   input                         we_a;
3633
   output [(data_width-1):0]      q_b;
3634
   output reg [(data_width-1):0] q_a;
3635
   input                         clk_a, clk_b;
3636
   reg [(data_width-1):0]         q_b;
3637
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] `SYN;
3638 7 unneback
 
3639
   parameter init = 0;
3640
   parameter memory_file = "vl_ram.vmem";
3641
   generate if (init) begin : init_mem
3642
   initial
3643
     begin
3644
        $readmemh(memory_file, ram);
3645
     end
3646
   end
3647
   endgenerate
3648
 
3649 6 unneback
   always @ (posedge clk_a)
3650
     begin
3651
        q_a <= ram[adr_a];
3652
        if (we_a)
3653
             ram[adr_a] <= d_a;
3654
     end
3655
   always @ (posedge clk_b)
3656
          q_b <= ram[adr_b];
3657
endmodule
3658 40 unneback
`endif
3659 6 unneback
 
3660 40 unneback
`ifdef DPRAM_2R2W
3661
`define MODULE dpram_2r2w
3662
module `BASE`MODULE ( d_a, q_a, adr_a, we_a, clk_a, d_b, q_b, adr_b, we_b, clk_b );
3663
`undef MODULE
3664
 
3665 6 unneback
   parameter data_width = 32;
3666
   parameter addr_width = 8;
3667
   input [(data_width-1):0]      d_a;
3668
   input [(addr_width-1):0]       adr_a;
3669
   input [(addr_width-1):0]       adr_b;
3670
   input                         we_a;
3671
   output [(data_width-1):0]      q_b;
3672
   input [(data_width-1):0]       d_b;
3673
   output reg [(data_width-1):0] q_a;
3674
   input                         we_b;
3675
   input                         clk_a, clk_b;
3676
   reg [(data_width-1):0]         q_b;
3677
   reg [data_width-1:0] ram [(1<<addr_width)-1:0] `SYN;
3678 7 unneback
 
3679
   parameter init = 0;
3680
   parameter memory_file = "vl_ram.vmem";
3681
   generate if (init) begin : init_mem
3682
   initial
3683
     begin
3684
        $readmemh(memory_file, ram);
3685
     end
3686
   end
3687
   endgenerate
3688
 
3689 6 unneback
   always @ (posedge clk_a)
3690
     begin
3691
        q_a <= ram[adr_a];
3692
        if (we_a)
3693
             ram[adr_a] <= d_a;
3694
     end
3695
   always @ (posedge clk_b)
3696
     begin
3697
        q_b <= ram[adr_b];
3698
        if (we_b)
3699
          ram[adr_b] <= d_b;
3700
     end
3701
endmodule
3702 40 unneback
`endif
3703 6 unneback
 
3704
// Content addresable memory, CAM
3705
 
3706 40 unneback
`ifdef FIFO_1R1W_FILL_LEVEL_SYNC
3707 6 unneback
// FIFO
3708 40 unneback
`define MODULE fifo_1r1w_fill_level_sync
3709
module `BASE`MODULE (
3710
`undef MODULE
3711 25 unneback
    d, wr, fifo_full,
3712
    q, rd, fifo_empty,
3713
    fill_level,
3714
    clk, rst
3715
    );
3716
 
3717
parameter data_width = 18;
3718
parameter addr_width = 4;
3719 6 unneback
 
3720 25 unneback
// write side
3721
input  [data_width-1:0] d;
3722
input                   wr;
3723
output                  fifo_full;
3724
// read side
3725
output [data_width-1:0] q;
3726
input                   rd;
3727
output                  fifo_empty;
3728
// common
3729
output [addr_width:0]   fill_level;
3730
input rst, clk;
3731
 
3732
wire [addr_width:1] wadr, radr;
3733
 
3734 40 unneback
`define MODULE cnt_bin_ce
3735
`BASE`MODULE
3736 25 unneback
    # ( .length(addr_width))
3737
    fifo_wr_adr( .cke(wr), .q(wadr), .rst(rst), .clk(clk));
3738 40 unneback
`BASE`MODULE
3739 25 unneback
    # (.length(addr_width))
3740
    fifo_rd_adr( .cke(rd), .q(radr), .rst(rst), .clk(clk));
3741 40 unneback
`undef MODULE
3742 25 unneback
 
3743 40 unneback
`define MODULE dpram_1r1w
3744
`BASE`MODULE
3745 25 unneback
    # (.data_width(data_width), .addr_width(addr_width))
3746
    dpram ( .d_a(d), .adr_a(wadr), .we_a(wr), .clk_a(clk), .q_b(q), .adr_b(radr), .clk_b(clk));
3747 40 unneback
`undef MODULE
3748 25 unneback
 
3749 40 unneback
`define MODULE cnt_bin_ce_rew_q_zq_l1
3750
`BASE`MODULE
3751 27 unneback
    # (.length(addr_width+1), .level1_value(1<<addr_width))
3752 25 unneback
    fill_level_cnt( .cke(rd ^ wr), .rew(rd), .q(fill_level), .zq(fifo_empty), .level1(fifo_full), .rst(rst), .clk(clk));
3753 40 unneback
`undef MODULE
3754 25 unneback
endmodule
3755 40 unneback
`endif
3756 25 unneback
 
3757 40 unneback
`ifdef FIFO_2R2W_SYNC_SIMPLEX
3758 27 unneback
// Intended use is two small FIFOs (RX and TX typically) in one FPGA RAM resource
3759
// RAM is supposed to be larger than the two FIFOs
3760
// LFSR counters used adr pointers
3761 40 unneback
`define MODULE fifo_2r2w_sync_simplex
3762
module `BASE`MODULE (
3763
`undef MODULE
3764 27 unneback
    // a side
3765
    a_d, a_wr, a_fifo_full,
3766
    a_q, a_rd, a_fifo_empty,
3767
    a_fill_level,
3768
    // b side
3769
    b_d, b_wr, b_fifo_full,
3770
    b_q, b_rd, b_fifo_empty,
3771
    b_fill_level,
3772
    // common
3773
    clk, rst
3774
    );
3775
parameter data_width = 8;
3776
parameter addr_width = 5;
3777
parameter fifo_full_level = (1<<addr_width)-1;
3778
 
3779
// a side
3780
input  [data_width-1:0] a_d;
3781
input                   a_wr;
3782
output                  a_fifo_full;
3783
output [data_width-1:0] a_q;
3784
input                   a_rd;
3785
output                  a_fifo_empty;
3786
output [addr_width-1:0] a_fill_level;
3787
 
3788
// b side
3789
input  [data_width-1:0] b_d;
3790
input                   b_wr;
3791
output                  b_fifo_full;
3792
output [data_width-1:0] b_q;
3793
input                   b_rd;
3794
output                  b_fifo_empty;
3795
output [addr_width-1:0] b_fill_level;
3796
 
3797
input                   clk;
3798
input                   rst;
3799
 
3800
// adr_gen
3801
wire [addr_width:1] a_wadr, a_radr;
3802
wire [addr_width:1] b_wadr, b_radr;
3803
// dpram
3804
wire [addr_width:0] a_dpram_adr, b_dpram_adr;
3805
 
3806 40 unneback
`define MODULE cnt_lfsr_ce
3807
`BASE`MODULE
3808 27 unneback
    # ( .length(addr_width))
3809
    fifo_a_wr_adr( .cke(a_wr), .q(a_wadr), .rst(rst), .clk(clk));
3810
 
3811 40 unneback
`BASE`MODULE
3812 27 unneback
    # (.length(addr_width))
3813
    fifo_a_rd_adr( .cke(a_rd), .q(a_radr), .rst(rst), .clk(clk));
3814
 
3815 40 unneback
`BASE`MODULE
3816 27 unneback
    # ( .length(addr_width))
3817
    fifo_b_wr_adr( .cke(b_wr), .q(b_wadr), .rst(rst), .clk(clk));
3818
 
3819 40 unneback
`BASE`MODULE
3820 27 unneback
    # (.length(addr_width))
3821
    fifo_b_rd_adr( .cke(b_rd), .q(b_radr), .rst(rst), .clk(clk));
3822 40 unneback
`undef MODULE
3823 27 unneback
 
3824
// mux read or write adr to DPRAM
3825
assign a_dpram_adr = (a_wr) ? {1'b0,a_wadr} : {1'b1,a_radr};
3826
assign b_dpram_adr = (b_wr) ? {1'b1,b_wadr} : {1'b0,b_radr};
3827
 
3828 40 unneback
`define MODULE dpram_2r2w
3829
`BASE`MODULE
3830 27 unneback
    # (.data_width(data_width), .addr_width(addr_width+1))
3831
    dpram ( .d_a(a_d), .q_a(a_q), .adr_a(a_dpram_adr), .we_a(a_wr), .clk_a(a_clk),
3832
            .d_b(b_d), .q_b(b_q), .adr_b(b_dpram_adr), .we_b(b_wr), .clk_b(b_clk));
3833 40 unneback
`undef MODULE
3834
 
3835
`define MODULE cnt_bin_ce_rew_zq_l1
3836
`BASE`MODULE
3837 28 unneback
    # (.length(addr_width), .level1_value(fifo_full_level))
3838 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));
3839
 
3840 40 unneback
`BASE`MODULE
3841 28 unneback
    # (.length(addr_width), .level1_value(fifo_full_level))
3842 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));
3843 40 unneback
`undef MODULE
3844 27 unneback
 
3845
endmodule
3846 40 unneback
`endif
3847 27 unneback
 
3848 40 unneback
`ifdef FIFO_CMP_ASYNC
3849
`define MODULE fifo_cmp_async
3850
module `BASE`MODULE ( wptr, rptr, fifo_empty, fifo_full, wclk, rclk, rst );
3851
`undef MODULE
3852 6 unneback
 
3853 11 unneback
   parameter addr_width = 4;
3854
   parameter N = addr_width-1;
3855 6 unneback
 
3856
   parameter Q1 = 2'b00;
3857
   parameter Q2 = 2'b01;
3858
   parameter Q3 = 2'b11;
3859
   parameter Q4 = 2'b10;
3860
 
3861
   parameter going_empty = 1'b0;
3862
   parameter going_full  = 1'b1;
3863
 
3864
   input [N:0]  wptr, rptr;
3865 14 unneback
   output       fifo_empty;
3866 6 unneback
   output       fifo_full;
3867
   input        wclk, rclk, rst;
3868
 
3869
`ifndef GENERATE_DIRECTION_AS_LATCH
3870
   wire direction;
3871
`endif
3872
`ifdef GENERATE_DIRECTION_AS_LATCH
3873
   reg direction;
3874
`endif
3875
   reg  direction_set, direction_clr;
3876
 
3877
   wire async_empty, async_full;
3878
   wire fifo_full2;
3879 14 unneback
   wire fifo_empty2;
3880 6 unneback
 
3881
   // direction_set
3882
   always @ (wptr[N:N-1] or rptr[N:N-1])
3883
     case ({wptr[N:N-1],rptr[N:N-1]})
3884
       {Q1,Q2} : direction_set <= 1'b1;
3885
       {Q2,Q3} : direction_set <= 1'b1;
3886
       {Q3,Q4} : direction_set <= 1'b1;
3887
       {Q4,Q1} : direction_set <= 1'b1;
3888
       default : direction_set <= 1'b0;
3889
     endcase
3890
 
3891
   // direction_clear
3892
   always @ (wptr[N:N-1] or rptr[N:N-1] or rst)
3893
     if (rst)
3894
       direction_clr <= 1'b1;
3895
     else
3896
       case ({wptr[N:N-1],rptr[N:N-1]})
3897
         {Q2,Q1} : direction_clr <= 1'b1;
3898
         {Q3,Q2} : direction_clr <= 1'b1;
3899
         {Q4,Q3} : direction_clr <= 1'b1;
3900
         {Q1,Q4} : direction_clr <= 1'b1;
3901
         default : direction_clr <= 1'b0;
3902
       endcase
3903
 
3904 40 unneback
`define MODULE dff_sr
3905 6 unneback
`ifndef GENERATE_DIRECTION_AS_LATCH
3906 40 unneback
    `BASE`MODULE dff_sr_dir( .aclr(direction_clr), .aset(direction_set), .clock(1'b1), .data(1'b1), .q(direction));
3907 6 unneback
`endif
3908
 
3909
`ifdef GENERATE_DIRECTION_AS_LATCH
3910
   always @ (posedge direction_set or posedge direction_clr)
3911
     if (direction_clr)
3912
       direction <= going_empty;
3913
     else
3914
       direction <= going_full;
3915
`endif
3916
 
3917
   assign async_empty = (wptr == rptr) && (direction==going_empty);
3918
   assign async_full  = (wptr == rptr) && (direction==going_full);
3919
 
3920 40 unneback
    `BASE`MODULE dff_sr_empty0( .aclr(rst), .aset(async_full), .clock(wclk), .data(async_full), .q(fifo_full2));
3921
    `BASE`MODULE dff_sr_empty1( .aclr(rst), .aset(async_full), .clock(wclk), .data(fifo_full2), .q(fifo_full));
3922
`undef MODULE
3923 6 unneback
 
3924
/*
3925
   always @ (posedge wclk or posedge rst or posedge async_full)
3926
     if (rst)
3927
       {fifo_full, fifo_full2} <= 2'b00;
3928
     else if (async_full)
3929
       {fifo_full, fifo_full2} <= 2'b11;
3930
     else
3931
       {fifo_full, fifo_full2} <= {fifo_full2, async_full};
3932
*/
3933 14 unneback
/*   always @ (posedge rclk or posedge async_empty)
3934 6 unneback
     if (async_empty)
3935
       {fifo_empty, fifo_empty2} <= 2'b11;
3936
     else
3937 14 unneback
       {fifo_empty,fifo_empty2} <= {fifo_empty2,async_empty}; */
3938 40 unneback
`define MODULE dff
3939
    `BASE`MODULE # ( .reset_value(1'b1)) dff0 ( .d(async_empty), .q(fifo_empty2), .clk(rclk), .rst(async_empty));
3940
    `BASE`MODULE # ( .reset_value(1'b1)) dff1 ( .d(fifo_empty2), .q(fifo_empty),  .clk(rclk), .rst(async_empty));
3941
`undef MODULE
3942 27 unneback
endmodule // async_compb
3943 40 unneback
`endif
3944 6 unneback
 
3945 40 unneback
`ifdef FIFO_1R1W_ASYNC
3946
`define MODULE fifo_1r1w_async
3947
module `BASE`MODULE (
3948
`undef MODULE
3949 6 unneback
    d, wr, fifo_full, wr_clk, wr_rst,
3950
    q, rd, fifo_empty, rd_clk, rd_rst
3951
    );
3952
 
3953
parameter data_width = 18;
3954
parameter addr_width = 4;
3955
 
3956
// write side
3957
input  [data_width-1:0] d;
3958
input                   wr;
3959
output                  fifo_full;
3960
input                   wr_clk;
3961
input                   wr_rst;
3962
// read side
3963
output [data_width-1:0] q;
3964
input                   rd;
3965
output                  fifo_empty;
3966
input                   rd_clk;
3967
input                   rd_rst;
3968
 
3969
wire [addr_width:1] wadr, wadr_bin, radr, radr_bin;
3970 23 unneback
 
3971 40 unneback
`define MODULE cnt_gray_ce_bin
3972
`BASE`MODULE
3973 6 unneback
    # ( .length(addr_width))
3974
    fifo_wr_adr( .cke(wr), .q(wadr), .q_bin(wadr_bin), .rst(wr_rst), .clk(wr_clk));
3975
 
3976 40 unneback
`BASE`MODULE
3977 6 unneback
    # (.length(addr_width))
3978 23 unneback
    fifo_rd_adr( .cke(rd), .q(radr), .q_bin(radr_bin), .rst(rd_rst), .clk(rd_clk));
3979 40 unneback
`undef MODULE
3980 6 unneback
 
3981 40 unneback
`define MODULE dpram_1r1w
3982
`BASE`MODULE
3983 6 unneback
    # (.data_width(data_width), .addr_width(addr_width))
3984
    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));
3985 40 unneback
`undef MODULE
3986 6 unneback
 
3987 40 unneback
`define MODULE fifo_cmp_async
3988
`BASE`MODULE
3989 6 unneback
    # (.addr_width(addr_width))
3990
    cmp ( .wptr(wadr), .rptr(radr), .fifo_empty(fifo_empty), .fifo_full(fifo_full), .wclk(wr_clk), .rclk(rd_clk), .rst(wr_rst) );
3991 40 unneback
`undef MODULE
3992 6 unneback
 
3993
endmodule
3994 40 unneback
`endif
3995 6 unneback
 
3996 40 unneback
`ifdef FIFO_2R2W_ASYNC
3997
`define MODULE fifo_2r2w_async
3998
module `BASE`MODULE (
3999
`undef MODULE
4000 6 unneback
    // a side
4001
    a_d, a_wr, a_fifo_full,
4002
    a_q, a_rd, a_fifo_empty,
4003
    a_clk, a_rst,
4004
    // b side
4005
    b_d, b_wr, b_fifo_full,
4006
    b_q, b_rd, b_fifo_empty,
4007
    b_clk, b_rst
4008
    );
4009
 
4010
parameter data_width = 18;
4011
parameter addr_width = 4;
4012
 
4013
// a side
4014
input  [data_width-1:0] a_d;
4015
input                   a_wr;
4016
output                  a_fifo_full;
4017
output [data_width-1:0] a_q;
4018
input                   a_rd;
4019
output                  a_fifo_empty;
4020
input                   a_clk;
4021
input                   a_rst;
4022
 
4023
// b side
4024
input  [data_width-1:0] b_d;
4025
input                   b_wr;
4026
output                  b_fifo_full;
4027
output [data_width-1:0] b_q;
4028
input                   b_rd;
4029
output                  b_fifo_empty;
4030
input                   b_clk;
4031
input                   b_rst;
4032
 
4033 40 unneback
`define MODULE fifo_1r1w_async
4034
`BASE`MODULE # (.data_width(data_width), .addr_width(addr_width))
4035 6 unneback
vl_fifo_1r1w_async_a (
4036
    .d(a_d), .wr(a_wr), .fifo_full(a_fifo_full), .wr_clk(a_clk), .wr_rst(a_rst),
4037
    .q(b_q), .rd(b_rd), .fifo_empty(b_fifo_empty), .rd_clk(b_clk), .rd_rst(b_rst)
4038
    );
4039
 
4040 40 unneback
`BASE`MODULE # (.data_width(data_width), .addr_width(addr_width))
4041 6 unneback
vl_fifo_1r1w_async_b (
4042
    .d(b_d), .wr(b_wr), .fifo_full(b_fifo_full), .wr_clk(b_clk), .wr_rst(b_rst),
4043
    .q(a_q), .rd(a_rd), .fifo_empty(a_fifo_empty), .rd_clk(a_clk), .rd_rst(a_rst)
4044
    );
4045 40 unneback
`undef MODULE
4046
 
4047 6 unneback
endmodule
4048 40 unneback
`endif
4049 6 unneback
 
4050 40 unneback
`ifdef FIFO_2R2W_ASYNC_SIMPLEX
4051
`define MODULE fifo_2r2w_async_simplex
4052
module `BASE`MODULE (
4053
`undef MODULE
4054 6 unneback
    // a side
4055
    a_d, a_wr, a_fifo_full,
4056
    a_q, a_rd, a_fifo_empty,
4057
    a_clk, a_rst,
4058
    // b side
4059
    b_d, b_wr, b_fifo_full,
4060
    b_q, b_rd, b_fifo_empty,
4061
    b_clk, b_rst
4062
    );
4063
 
4064
parameter data_width = 18;
4065
parameter addr_width = 4;
4066
 
4067
// a side
4068
input  [data_width-1:0] a_d;
4069
input                   a_wr;
4070
output                  a_fifo_full;
4071
output [data_width-1:0] a_q;
4072
input                   a_rd;
4073
output                  a_fifo_empty;
4074
input                   a_clk;
4075
input                   a_rst;
4076
 
4077
// b side
4078
input  [data_width-1:0] b_d;
4079
input                   b_wr;
4080
output                  b_fifo_full;
4081
output [data_width-1:0] b_q;
4082
input                   b_rd;
4083
output                  b_fifo_empty;
4084
input                   b_clk;
4085
input                   b_rst;
4086
 
4087
// adr_gen
4088
wire [addr_width:1] a_wadr, a_wadr_bin, a_radr, a_radr_bin;
4089
wire [addr_width:1] b_wadr, b_wadr_bin, b_radr, b_radr_bin;
4090
// dpram
4091
wire [addr_width:0] a_dpram_adr, b_dpram_adr;
4092
 
4093 40 unneback
`define MODULE cnt_gray_ce_bin
4094
`BASE`MODULE
4095 6 unneback
    # ( .length(addr_width))
4096
    fifo_a_wr_adr( .cke(a_wr), .q(a_wadr), .q_bin(a_wadr_bin), .rst(a_rst), .clk(a_clk));
4097
 
4098 40 unneback
`BASE`MODULE
4099 6 unneback
    # (.length(addr_width))
4100
    fifo_a_rd_adr( .cke(a_rd), .q(a_radr), .q_bin(a_radr_bin), .rst(a_rst), .clk(a_clk));
4101
 
4102 40 unneback
`BASE`MODULE
4103 6 unneback
    # ( .length(addr_width))
4104
    fifo_b_wr_adr( .cke(b_wr), .q(b_wadr), .q_bin(b_wadr_bin), .rst(b_rst), .clk(b_clk));
4105
 
4106 40 unneback
`BASE`MODULE
4107 6 unneback
    # (.length(addr_width))
4108
    fifo_b_rd_adr( .cke(b_rd), .q(b_radr), .q_bin(b_radr_bin), .rst(b_rst), .clk(b_clk));
4109 40 unneback
`undef MODULE
4110 6 unneback
 
4111
// mux read or write adr to DPRAM
4112
assign a_dpram_adr = (a_wr) ? {1'b0,a_wadr_bin} : {1'b1,a_radr_bin};
4113
assign b_dpram_adr = (b_wr) ? {1'b1,b_wadr_bin} : {1'b0,b_radr_bin};
4114
 
4115 40 unneback
`define MODULE dpram_2r2w
4116
`BASE`MODULE
4117 6 unneback
    # (.data_width(data_width), .addr_width(addr_width+1))
4118
    dpram ( .d_a(a_d), .q_a(a_q), .adr_a(a_dpram_adr), .we_a(a_wr), .clk_a(a_clk),
4119
            .d_b(b_d), .q_b(b_q), .adr_b(b_dpram_adr), .we_b(b_wr), .clk_b(b_clk));
4120 40 unneback
`undef MODULE
4121 6 unneback
 
4122 40 unneback
`define MODULE fifo_cmp_async
4123
`BASE`MODULE
4124 6 unneback
    # (.addr_width(addr_width))
4125
    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) );
4126
 
4127 40 unneback
`BASE`MODULE
4128 6 unneback
    # (.addr_width(addr_width))
4129
    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) );
4130 40 unneback
`undef MODULE
4131 6 unneback
 
4132
endmodule
4133 40 unneback
`endif
4134 48 unneback
 
4135
`ifdef REG_FILE
4136
`define MODULE reg_file
4137
module `BASE`MODULE (
4138
`undef MODULE
4139
    a1, a2, a3, wd3, we3, rd1, rd2, clk
4140
);
4141
parameter data_width = 32;
4142
parameter addr_width = 5;
4143
input [addr_width-1:0] a1, a2, a3;
4144
input [data_width-1:0] wd3;
4145
input we3;
4146
output [data_width-1:0] rd1, rd2;
4147
input clk;
4148
 
4149
`ifdef ACTEL
4150
reg [data_width-1:0] wd3_reg;
4151
reg [addr_width-1:0] a1_reg, a2_reg, a3_reg;
4152
reg we3_reg;
4153
reg [data_width-1:0] ram1 [(1<<addr_width)-1:0] `SYN;
4154
reg [data_width-1:0] ram2 [(1<<addr_width)-1:0] `SYN;
4155
always @ (posedge clk or posedge rst)
4156
if (rst)
4157
    {wd3_reg, a3_reg, we3_reg} <= {(data_width+addr_width+1){1'b0}};
4158
else
4159
    {wd3_reg, a3_reg, we3_reg} <= {wd3,a3,wd3};
4160
 
4161
    always @ (negedge clk)
4162
    if (we3_reg)
4163
        ram1[a3_reg] <= wd3;
4164
    always @ (posedge clk)
4165
        a1_reg <= a1;
4166
    assign rd1 = ram1[a1_reg];
4167
 
4168
    always @ (negedge clk)
4169
    if (we3_reg)
4170
        ram2[a3_reg] <= wd3;
4171
    always @ (posedge clk)
4172
        a2_reg <= a2;
4173
    assign rd2 = ram2[a2_reg];
4174
 
4175
`else
4176
 
4177
`define MODULE dpram_1r1w
4178
`BASE`MODULE
4179
    # ( .data_width(data_width), .addr_width(addr_width))
4180
    ram1 (
4181
        .d_a(wd3),
4182
        .adr_a(a3),
4183
        .we_a(we3),
4184
        .clk_a(clk),
4185
        .q_b(rd1),
4186
        .adr_b(a1),
4187
        .clk_b(clk) );
4188
 
4189
`BASE`MODULE
4190
    # ( .data_width(data_width), .addr_width(addr_width))
4191
    ram2 (
4192
        .d_a(wd3),
4193
        .adr_a(a3),
4194
        .we_a(we3),
4195
        .clk_a(clk),
4196
        .q_b(rd2),
4197
        .adr_b(a2),
4198
        .clk_b(clk) );
4199
`undef MODULE
4200
 
4201
`endif
4202
 
4203
endmodule
4204
`endif
4205 12 unneback
//////////////////////////////////////////////////////////////////////
4206
////                                                              ////
4207
////  Versatile library, wishbone stuff                           ////
4208
////                                                              ////
4209
////  Description                                                 ////
4210
////  Wishbone compliant modules                                  ////
4211
////                                                              ////
4212
////                                                              ////
4213
////  To Do:                                                      ////
4214
////   -                                                          ////
4215
////                                                              ////
4216
////  Author(s):                                                  ////
4217
////      - Michael Unneback, unneback@opencores.org              ////
4218
////        ORSoC AB                                              ////
4219
////                                                              ////
4220
//////////////////////////////////////////////////////////////////////
4221
////                                                              ////
4222
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
4223
////                                                              ////
4224
//// This source file may be used and distributed without         ////
4225
//// restriction provided that this copyright statement is not    ////
4226
//// removed from the file and that any derivative work contains  ////
4227
//// the original copyright notice and the associated disclaimer. ////
4228
////                                                              ////
4229
//// This source file is free software; you can redistribute it   ////
4230
//// and/or modify it under the terms of the GNU Lesser General   ////
4231
//// Public License as published by the Free Software Foundation; ////
4232
//// either version 2.1 of the License, or (at your option) any   ////
4233
//// later version.                                               ////
4234
////                                                              ////
4235
//// This source is distributed in the hope that it will be       ////
4236
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
4237
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
4238
//// PURPOSE.  See the GNU Lesser General Public License for more ////
4239
//// details.                                                     ////
4240
////                                                              ////
4241
//// You should have received a copy of the GNU Lesser General    ////
4242
//// Public License along with this source; if not, download it   ////
4243
//// from http://www.opencores.org/lgpl.shtml                     ////
4244
////                                                              ////
4245
//////////////////////////////////////////////////////////////////////
4246
 
4247 40 unneback
`ifdef WB3WB3_BRIDGE
4248 12 unneback
// async wb3 - wb3 bridge
4249
`timescale 1ns/1ns
4250 40 unneback
`define MODULE wb3wb3_bridge
4251
module `BASE`MODULE (
4252
`undef MODULE
4253 12 unneback
        // wishbone slave side
4254
        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,
4255
        // wishbone master side
4256
        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);
4257
 
4258
input [31:0] wbs_dat_i;
4259
input [31:2] wbs_adr_i;
4260
input [3:0]  wbs_sel_i;
4261
input [1:0]  wbs_bte_i;
4262
input [2:0]  wbs_cti_i;
4263
input wbs_we_i, wbs_cyc_i, wbs_stb_i;
4264
output [31:0] wbs_dat_o;
4265 14 unneback
output wbs_ack_o;
4266 12 unneback
input wbs_clk, wbs_rst;
4267
 
4268
output [31:0] wbm_dat_o;
4269
output reg [31:2] wbm_adr_o;
4270
output [3:0]  wbm_sel_o;
4271
output reg [1:0]  wbm_bte_o;
4272
output reg [2:0]  wbm_cti_o;
4273 14 unneback
output reg wbm_we_o;
4274
output wbm_cyc_o;
4275 12 unneback
output wbm_stb_o;
4276
input [31:0]  wbm_dat_i;
4277
input wbm_ack_i;
4278
input wbm_clk, wbm_rst;
4279
 
4280
parameter addr_width = 4;
4281
 
4282
// bte
4283
parameter linear       = 2'b00;
4284
parameter wrap4        = 2'b01;
4285
parameter wrap8        = 2'b10;
4286
parameter wrap16       = 2'b11;
4287
// cti
4288
parameter classic      = 3'b000;
4289
parameter incburst     = 3'b010;
4290
parameter endofburst   = 3'b111;
4291
 
4292
parameter wbs_adr  = 1'b0;
4293
parameter wbs_data = 1'b1;
4294
 
4295 33 unneback
parameter wbm_adr0      = 2'b00;
4296
parameter wbm_adr1      = 2'b01;
4297
parameter wbm_data      = 2'b10;
4298
parameter wbm_data_wait = 2'b11;
4299 12 unneback
 
4300
reg [1:0] wbs_bte_reg;
4301
reg wbs;
4302
wire wbs_eoc_alert, wbm_eoc_alert;
4303
reg wbs_eoc, wbm_eoc;
4304
reg [1:0] wbm;
4305
 
4306 14 unneback
wire [1:16] wbs_count, wbm_count;
4307 12 unneback
 
4308
wire [35:0] a_d, a_q, b_d, b_q;
4309
wire a_wr, a_rd, a_fifo_full, a_fifo_empty, b_wr, b_rd, b_fifo_full, b_fifo_empty;
4310
reg a_rd_reg;
4311
wire b_rd_adr, b_rd_data;
4312 14 unneback
wire b_rd_data_reg;
4313
wire [35:0] temp;
4314 12 unneback
 
4315
`define WE 5
4316
`define BTE 4:3
4317
`define CTI 2:0
4318
 
4319
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]);
4320
always @ (posedge wbs_clk or posedge wbs_rst)
4321
if (wbs_rst)
4322
        wbs_eoc <= 1'b0;
4323
else
4324
        if (wbs==wbs_adr & wbs_stb_i & !a_fifo_full)
4325
                wbs_eoc <= wbs_bte_i==linear;
4326
        else if (wbs_eoc_alert & (a_rd | a_wr))
4327
                wbs_eoc <= 1'b1;
4328
 
4329 40 unneback
`define MODULE cnt_shreg_ce_clear
4330
`BASE`MODULE # ( .length(16))
4331
`undef MODULE
4332 12 unneback
    cnt0 (
4333
        .cke(wbs_ack_o),
4334
        .clear(wbs_eoc),
4335
        .q(wbs_count),
4336
        .rst(wbs_rst),
4337
        .clk(wbs_clk));
4338
 
4339
always @ (posedge wbs_clk or posedge wbs_rst)
4340
if (wbs_rst)
4341
        wbs <= wbs_adr;
4342
else
4343
        if ((wbs==wbs_adr) & wbs_cyc_i & wbs_stb_i & !a_fifo_full)
4344
                wbs <= wbs_data;
4345
        else if (wbs_eoc & wbs_ack_o)
4346
                wbs <= wbs_adr;
4347
 
4348
// wbs FIFO
4349
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};
4350
assign a_wr = (wbs==wbs_adr)  ? wbs_cyc_i & wbs_stb_i & !a_fifo_full :
4351
              (wbs==wbs_data) ? wbs_we_i  & wbs_stb_i & !a_fifo_full :
4352
              1'b0;
4353
assign a_rd = !a_fifo_empty;
4354
always @ (posedge wbs_clk or posedge wbs_rst)
4355
if (wbs_rst)
4356
        a_rd_reg <= 1'b0;
4357
else
4358
        a_rd_reg <= a_rd;
4359
assign wbs_ack_o = a_rd_reg | (a_wr & wbs==wbs_data);
4360
 
4361
assign wbs_dat_o = a_q[35:4];
4362
 
4363
always @ (posedge wbs_clk or posedge wbs_rst)
4364
if (wbs_rst)
4365 13 unneback
        wbs_bte_reg <= 2'b00;
4366 12 unneback
else
4367 13 unneback
        wbs_bte_reg <= wbs_bte_i;
4368 12 unneback
 
4369
// wbm FIFO
4370
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]);
4371
always @ (posedge wbm_clk or posedge wbm_rst)
4372
if (wbm_rst)
4373
        wbm_eoc <= 1'b0;
4374
else
4375
        if (wbm==wbm_adr0 & !b_fifo_empty)
4376
                wbm_eoc <= b_q[`BTE] == linear;
4377
        else if (wbm_eoc_alert & wbm_ack_i)
4378
                wbm_eoc <= 1'b1;
4379
 
4380
always @ (posedge wbm_clk or posedge wbm_rst)
4381
if (wbm_rst)
4382
        wbm <= wbm_adr0;
4383
else
4384 33 unneback
/*
4385 12 unneback
    if ((wbm==wbm_adr0 & !b_fifo_empty) |
4386
        (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) |
4387
        (wbm==wbm_adr1 & !wbm_we_o) |
4388
        (wbm==wbm_data & wbm_ack_i & wbm_eoc))
4389
        wbm <= {wbm[0],!(wbm[1] ^ wbm[0])};  // count sequence 00,01,10
4390 33 unneback
*/
4391
    case (wbm)
4392
    wbm_adr0:
4393
        if (!b_fifo_empty)
4394
            wbm <= wbm_adr1;
4395
    wbm_adr1:
4396
        if (!wbm_we_o | (!b_fifo_empty & wbm_we_o))
4397
            wbm <= wbm_data;
4398
    wbm_data:
4399
        if (wbm_ack_i & wbm_eoc)
4400
            wbm <= wbm_adr0;
4401
        else if (b_fifo_empty & wbm_we_o & wbm_ack_i)
4402
            wbm <= wbm_data_wait;
4403
    wbm_data_wait:
4404
        if (!b_fifo_empty)
4405
            wbm <= wbm_data;
4406
    endcase
4407 12 unneback
 
4408
assign b_d = {wbm_dat_i,4'b1111};
4409
assign b_wr = !wbm_we_o & wbm_ack_i;
4410
assign b_rd_adr  = (wbm==wbm_adr0 & !b_fifo_empty);
4411
assign b_rd_data = (wbm==wbm_adr1 & !b_fifo_empty & wbm_we_o) ? 1'b1 : // b_q[`WE]
4412
                   (wbm==wbm_data & !b_fifo_empty & wbm_we_o & wbm_ack_i & !wbm_eoc) ? 1'b1 :
4413 33 unneback
                   (wbm==wbm_data_wait & !b_fifo_empty) ? 1'b1 :
4414 12 unneback
                   1'b0;
4415
assign b_rd = b_rd_adr | b_rd_data;
4416
 
4417 40 unneback
`define MODULE dff
4418
`BASE`MODULE dff1 ( .d(b_rd_data), .q(b_rd_data_reg), .clk(wbm_clk), .rst(wbm_rst));
4419
`undef MODULE
4420
`define MODULE dff_ce
4421
`BASE`MODULE # ( .width(36)) dff2 ( .d(b_q), .ce(b_rd_data_reg), .q(temp), .clk(wbm_clk), .rst(wbm_rst));
4422
`undef MODULE
4423 12 unneback
 
4424
assign {wbm_dat_o,wbm_sel_o} = (b_rd_data_reg) ? b_q : temp;
4425
 
4426 40 unneback
`define MODULE cnt_shreg_ce_clear
4427 42 unneback
`BASE`MODULE # ( .length(16))
4428 40 unneback
`undef MODULE
4429 12 unneback
    cnt1 (
4430
        .cke(wbm_ack_i),
4431
        .clear(wbm_eoc),
4432
        .q(wbm_count),
4433
        .rst(wbm_rst),
4434
        .clk(wbm_clk));
4435
 
4436 33 unneback
assign wbm_cyc_o = (wbm==wbm_data | wbm==wbm_data_wait);
4437
assign wbm_stb_o = (wbm==wbm_data);
4438 12 unneback
 
4439
always @ (posedge wbm_clk or posedge wbm_rst)
4440
if (wbm_rst)
4441
        {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= {30'h0,1'b0,linear,classic};
4442
else begin
4443
        if (wbm==wbm_adr0 & !b_fifo_empty)
4444
                {wbm_adr_o,wbm_we_o,wbm_bte_o,wbm_cti_o} <= b_q;
4445
        else if (wbm_eoc_alert & wbm_ack_i)
4446
                wbm_cti_o <= endofburst;
4447
end
4448
 
4449
//async_fifo_dw_simplex_top
4450 40 unneback
`define MODULE fifo_2r2w_async_simplex
4451
`BASE`MODULE
4452
`undef MODULE
4453 12 unneback
# ( .data_width(36), .addr_width(addr_width))
4454
fifo (
4455
    // a side
4456
    .a_d(a_d),
4457
    .a_wr(a_wr),
4458
    .a_fifo_full(a_fifo_full),
4459
    .a_q(a_q),
4460
    .a_rd(a_rd),
4461
    .a_fifo_empty(a_fifo_empty),
4462
    .a_clk(wbs_clk),
4463
    .a_rst(wbs_rst),
4464
    // b side
4465
    .b_d(b_d),
4466
    .b_wr(b_wr),
4467
    .b_fifo_full(b_fifo_full),
4468
    .b_q(b_q),
4469
    .b_rd(b_rd),
4470
    .b_fifo_empty(b_fifo_empty),
4471
    .b_clk(wbm_clk),
4472
    .b_rst(wbm_rst)
4473
    );
4474
 
4475
endmodule
4476 40 unneback
`undef WE
4477
`undef BTE
4478
`undef CTI
4479
`endif
4480 17 unneback
 
4481 40 unneback
`ifdef WB3_ARBITER_TYPE1
4482
`define MODULE wb3_arbiter_type1
4483 42 unneback
module `BASE`MODULE (
4484 40 unneback
`undef MODULE
4485 39 unneback
    wbm_dat_o, wbm_adr_o, wbm_sel_o, wbm_cti_o, wbm_bte_o, wbm_we_o, wbm_stb_o, wbm_cyc_o,
4486
    wbm_dat_i, wbm_ack_i, wbm_err_i, wbm_rty_i,
4487
    wbs_dat_i, wbs_adr_i, wbs_sel_i, wbs_cti_i, wbs_bte_i, wbs_we_i, wbs_stb_i, wbs_cyc_i,
4488
    wbs_dat_o, wbs_ack_o, wbs_err_o, wbs_rty_o,
4489
    wb_clk, wb_rst
4490
);
4491
 
4492
parameter nr_of_ports = 3;
4493
parameter adr_size = 26;
4494
parameter adr_lo   = 2;
4495
parameter dat_size = 32;
4496
parameter sel_size = dat_size/8;
4497
 
4498
localparam aw = (adr_size - adr_lo) * nr_of_ports;
4499
localparam dw = dat_size * nr_of_ports;
4500
localparam sw = sel_size * nr_of_ports;
4501
localparam cw = 3 * nr_of_ports;
4502
localparam bw = 2 * nr_of_ports;
4503
 
4504
input  [dw-1:0] wbm_dat_o;
4505
input  [aw-1:0] wbm_adr_o;
4506
input  [sw-1:0] wbm_sel_o;
4507
input  [cw-1:0] wbm_cti_o;
4508
input  [bw-1:0] wbm_bte_o;
4509
input  [nr_of_ports-1:0] wbm_we_o, wbm_stb_o, wbm_cyc_o;
4510
output [dw-1:0] wbm_dat_i;
4511
output [nr_of_ports-1:0] wbm_ack_i, wbm_err_i, wbm_rty_i;
4512
 
4513
output [dat_size-1:0] wbs_dat_i;
4514
output [adr_size-1:adr_lo] wbs_adr_i;
4515
output [sel_size-1:0] wbs_sel_i;
4516
output [2:0] wbs_cti_i;
4517
output [1:0] wbs_bte_i;
4518
output wbs_we_i, wbs_stb_i, wbs_cyc_i;
4519
input  [dat_size-1:0] wbs_dat_o;
4520
input  wbs_ack_o, wbs_err_o, wbs_rty_o;
4521
 
4522
input wb_clk, wb_rst;
4523
 
4524 44 unneback
reg  [nr_of_ports-1:0] select;
4525 39 unneback
wire [nr_of_ports-1:0] state;
4526
wire [nr_of_ports-1:0] eoc; // end-of-cycle
4527
wire [nr_of_ports-1:0] sel;
4528
wire idle;
4529
 
4530
genvar i;
4531
 
4532
assign idle = !(|state);
4533
 
4534
generate
4535
if (nr_of_ports == 2) begin
4536
 
4537
    wire [2:0] wbm1_cti_o, wbm0_cti_o;
4538
 
4539
    assign {wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
4540
 
4541 44 unneback
    //assign select = (idle) ? {wbm_cyc_o[1],!wbm_cyc_o[1] & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
4542
 
4543
    always @ (idle or wbm_cyc_o)
4544
    if (idle)
4545
        casex (wbm_cyc_o)
4546
        2'b1x : select = 2'b10;
4547
        2'b01 : select = 2'b01;
4548
        default : select = {nr_of_ports{1'b0}};
4549
        endcase
4550
    else
4551
        select = {nr_of_ports{1'b0}};
4552
 
4553 39 unneback
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
4554
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
4555
 
4556
end
4557
endgenerate
4558
 
4559
generate
4560
if (nr_of_ports == 3) begin
4561
 
4562
    wire [2:0] wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
4563
 
4564
    assign {wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
4565
 
4566 44 unneback
    always @ (idle or wbm_cyc_o)
4567
    if (idle)
4568
        casex (wbm_cyc_o)
4569
        3'b1xx : select = 3'b100;
4570
        3'b01x : select = 3'b010;
4571
        3'b001 : select = 3'b001;
4572
        default : select = {nr_of_ports{1'b0}};
4573
        endcase
4574
    else
4575
        select = {nr_of_ports{1'b0}};
4576
 
4577
//    assign select = (idle) ? {wbm_cyc_o[2],!wbm_cyc_o[2] & wbm_cyc_o[1],wbm_cyc_o[2:1]==2'b00 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
4578 39 unneback
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
4579
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
4580
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
4581
 
4582
end
4583
endgenerate
4584
 
4585
generate
4586 44 unneback
if (nr_of_ports == 4) begin
4587
 
4588
    wire [2:0] wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
4589
 
4590
    assign {wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
4591
 
4592
    //assign select = (idle) ? {wbm_cyc_o[3],!wbm_cyc_o[3] & wbm_cyc_o[2],wbm_cyc_o[3:2]==2'b00 & wbm_cyc_o[1],wbm_cyc_o[3:1]==3'b000 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
4593
 
4594
    always @ (idle or wbm_cyc_o)
4595
    if (idle)
4596
        casex (wbm_cyc_o)
4597
        4'b1xxx : select = 4'b1000;
4598
        4'b01xx : select = 4'b0100;
4599
        4'b001x : select = 4'b0010;
4600
        4'b0001 : select = 4'b0001;
4601
        default : select = {nr_of_ports{1'b0}};
4602
        endcase
4603
    else
4604
        select = {nr_of_ports{1'b0}};
4605
 
4606
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
4607
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
4608
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
4609
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
4610
 
4611
end
4612
endgenerate
4613
 
4614
generate
4615
if (nr_of_ports == 5) begin
4616
 
4617
    wire [2:0] wbm4_cti_o, wbm3_cti_o, wbm2_cti_o, wbm1_cti_o, wbm0_cti_o;
4618
 
4619
    assign {wbm4_cti_o, wbm3_cti_o, wbm2_cti_o,wbm1_cti_o,wbm0_cti_o} = wbm_cti_o;
4620
 
4621
    //assign select = (idle) ? {wbm_cyc_o[3],!wbm_cyc_o[3] & wbm_cyc_o[2],wbm_cyc_o[3:2]==2'b00 & wbm_cyc_o[1],wbm_cyc_o[3:1]==3'b000 & wbm_cyc_o[0]} : {nr_of_ports{1'b0}};
4622
 
4623
    always @ (idle or wbm_cyc_o)
4624
    if (idle)
4625
        casex (wbm_cyc_o)
4626
        5'b1xxxx : select = 5'b10000;
4627
        5'b01xxx : select = 5'b01000;
4628
        5'b001xx : select = 5'b00100;
4629
        5'b0001x : select = 5'b00010;
4630
        5'b00001 : select = 5'b00001;
4631
        default : select = {nr_of_ports{1'b0}};
4632
        endcase
4633
    else
4634
        select = {nr_of_ports{1'b0}};
4635
 
4636
    assign eoc[4] = (wbm_ack_i[4] & (wbm4_cti_o == 3'b000 | wbm4_cti_o == 3'b111)) | !wbm_cyc_o[4];
4637
    assign eoc[3] = (wbm_ack_i[3] & (wbm3_cti_o == 3'b000 | wbm3_cti_o == 3'b111)) | !wbm_cyc_o[3];
4638
    assign eoc[2] = (wbm_ack_i[2] & (wbm2_cti_o == 3'b000 | wbm2_cti_o == 3'b111)) | !wbm_cyc_o[2];
4639
    assign eoc[1] = (wbm_ack_i[1] & (wbm1_cti_o == 3'b000 | wbm1_cti_o == 3'b111)) | !wbm_cyc_o[1];
4640
    assign eoc[0] = (wbm_ack_i[0] & (wbm0_cti_o == 3'b000 | wbm0_cti_o == 3'b111)) | !wbm_cyc_o[0];
4641
 
4642
end
4643
endgenerate
4644
 
4645
generate
4646 63 unneback
for (i=0;i<nr_of_ports;i=i+1) begin : spr0
4647 42 unneback
`define MODULE spr
4648
    `BASE`MODULE sr0( .sp(select[i]), .r(eoc[i]), .q(state[i]), .clk(wb_clk), .rst(wb_rst));
4649
`undef MODULE
4650 39 unneback
end
4651
endgenerate
4652
 
4653
    assign sel = select | state;
4654
 
4655 40 unneback
`define MODULE mux_andor
4656
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(32)) mux0 ( .a(wbm_dat_o), .sel(sel), .dout(wbs_dat_i));
4657
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(adr_size-adr_lo)) mux1 ( .a(wbm_adr_o), .sel(sel), .dout(wbs_adr_i));
4658
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(sel_size)) mux2 ( .a(wbm_sel_o), .sel(sel), .dout(wbs_sel_i));
4659
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(3)) mux3 ( .a(wbm_cti_o), .sel(sel), .dout(wbs_cti_i));
4660
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(2)) mux4 ( .a(wbm_bte_o), .sel(sel), .dout(wbs_bte_i));
4661
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(1)) mux5 ( .a(wbm_we_o), .sel(sel), .dout(wbs_we_i));
4662
    `BASE`MODULE # ( .nr_of_ports(nr_of_ports), .width(1)) mux6 ( .a(wbm_stb_o), .sel(sel), .dout(wbs_stb_i));
4663
`undef MODULE
4664 39 unneback
    assign wbs_cyc_i = |sel;
4665
 
4666
    assign wbm_dat_i = {nr_of_ports{wbs_dat_o}};
4667
    assign wbm_ack_i = {nr_of_ports{wbs_ack_o}} & sel;
4668
    assign wbm_err_i = {nr_of_ports{wbs_err_o}} & sel;
4669
    assign wbm_rty_i = {nr_of_ports{wbs_rty_o}} & sel;
4670
 
4671
endmodule
4672 40 unneback
`endif
4673 39 unneback
 
4674 60 unneback
`ifdef WB_B3_RAM_BE
4675 49 unneback
// WB RAM with byte enable
4676 59 unneback
`define MODULE wb_b3_ram_be
4677
module `BASE`MODULE (
4678
`undef MODULE
4679 61 unneback
    wb_dat_i, wb_adr_i, wb_cti_i, wb_bte_i, wb_sel_i, wb_we_i, wb_stb_i, wb_cyc_i,
4680 59 unneback
    wb_dat_o, wb_ack_o, wb_clk, wb_rst);
4681
 
4682 60 unneback
parameter nr_of_ports = 3;
4683
parameter wb_arbiter_type = 1;
4684
parameter adr_size = 26;
4685
parameter adr_lo   = 2;
4686
parameter dat_size = 32;
4687
parameter memory_init = 1;
4688
parameter memory_file = "vl_ram.vmem";
4689 59 unneback
 
4690 60 unneback
localparam aw = (adr_size - adr_lo) * nr_of_ports;
4691
localparam dw = dat_size * nr_of_ports;
4692
localparam sw = dat_size/8 * nr_of_ports;
4693
localparam cw = 3 * nr_of_ports;
4694
localparam bw = 2 * nr_of_ports;
4695
 
4696
input [dw-1:0] wb_dat_i;
4697
input [aw-1:0] wb_adr_i;
4698
input [cw-1:0] wb_cti_i;
4699 61 unneback
input [bw-1:0] wb_bte_i;
4700 60 unneback
input [sw-1:0] wb_sel_i;
4701
input [nr_of_ports-1:0] wb_we_i, wb_stb_i, wb_cyc_i;
4702
output [dw-1:0] wb_dat_o;
4703 59 unneback
output wb_ack_o;
4704
input wb_clk, wb_rst;
4705
 
4706 60 unneback
wire [sw-1:0] cke;
4707 59 unneback
 
4708 60 unneback
// local wb slave
4709
wire [dat_size-1:0] wbs_dat_i;
4710
wire [adr_size-1:0] wbs_adr_i;
4711
wire [2:0] wbs_cti_i;
4712 61 unneback
wire [1:0] wbs_bte_i;
4713 60 unneback
wire [(dat_size/8)-1:0] wbs_sel_i;
4714
wire  wbs_we_i, wbs_stb_i, wbs_cyc_i;
4715
wire [dat_size-1:0] wbs_dat_o;
4716
reg wbs_ack_o;
4717
 
4718 59 unneback
generate
4719 60 unneback
if (nr_of_ports == 1) begin
4720
    assign wbs_dat_i = wb_dat_i;
4721
    assign wbs_adr_i = wb_adr_i;
4722
    assign wbs_cti_i = wb_cti_i;
4723
    assign wbs_sel_i = wb_sel_i;
4724
    assign wbs_we_i  = wb_we_i;
4725
    assign wbs_stb_i = wb_stb_i;
4726
    assign wbs_cyc_i = wb_cyc_i;
4727
    assign wb_dat_o  = wbs_dat_o;
4728
    assign wb_ack_o  = wbs_ack_o;
4729 59 unneback
end
4730
endgenerate
4731
 
4732 60 unneback
generate
4733
if (nr_of_ports > 1 & wb_arbiter_type == 1) begin
4734
`define MODULE wb3_arbiter_type1
4735
`BASE`MODULE wb_arbiter0(
4736
`undef MODULE
4737
    .wbm_dat_o(wb_dat_i),
4738
    .wbm_adr_o(wb_adr_i),
4739
    .wbm_sel_o(wb_sel_i),
4740
    .wbm_cti_o(wb_cti_i),
4741
    .wbm_bte_o(wb_bte_i),
4742
    .wbm_we_o(wb_we_i),
4743
    .wbm_stb_o(wb_stb_i),
4744
    .wbm_cyc_o(wb_cyc_i),
4745
    .wbm_dat_i(wb_dat_o),
4746
    .wbm_ack_i(wb_ack_o),
4747
    .wbm_err_i(),
4748
    .wbm_rty_i(),
4749
    .wbs_dat_i(wbs_dat_i),
4750
    .wbs_adr_i(wbs_adr_i),
4751
    .wbs_sel_i(wbs_sel_i),
4752
    .wbs_cti_i(wbs_cti_i),
4753
    .wbs_bte_i(wbs_bte_i),
4754
    .wbs_we_i(wbs_we_i),
4755
    .wbs_stb_i(wbs_stb_i),
4756
    .wbs_cyc_i(wbs_cyc_i),
4757
    .wbs_dat_o(wbs_dat_o),
4758
    .wbs_ack_o(wbs_ack_o),
4759
    .wbs_err_o(1'b0),
4760
    .wbs_rty_o(1'b0),
4761
    .wb_clk(wb_clk),
4762
    .wb_rst(wb_rst)
4763
);
4764
end
4765
endgenerate
4766
 
4767
`define MODULE ram_be
4768
`BASE`MODULE # (
4769
    .data_width(dat_size),
4770
    .addr_width(adr_size),
4771
    .memory_init(1),
4772
    .memory_file("memory_file"))
4773
ram0(
4774
`undef MODULE
4775
    .d(wbs_dat_i),
4776
    .adr(wbs_adr_i[adr_size-1:2]),
4777
    .be(wbs_sel_i),
4778
    .we(wbs_we_i),
4779
    .q(wbs_dat_o),
4780
    .clk(wb_clk)
4781
);
4782
 
4783 59 unneback
always @ (posedge wb_clk or posedge wb_rst)
4784
if (wb_rst)
4785 60 unneback
    wbs_ack_o <= 1'b0;
4786 59 unneback
else
4787 60 unneback
    if (wbs_cti_i==3'b000 | wbs_cti_i==3'b111)
4788
        wbs_ack_o <= wbs_stb_i & wbs_cyc_i & !wbs_ack_o;
4789 59 unneback
    else
4790 60 unneback
        wbs_ack_o <= wbs_stb_i & wbs_cyc_i;
4791
 
4792 59 unneback
endmodule
4793
`endif
4794
 
4795
`ifdef WB_B4_RAM_BE
4796
// WB RAM with byte enable
4797 49 unneback
`define MODULE wb_b4_ram_be
4798
module `BASE`MODULE (
4799
`undef MODULE
4800
    wb_dat_i, wb_adr_i, wb_sel_i, wb_we_i, wb_stb_i, wb_cyc_i,
4801 52 unneback
    wb_dat_o, wb_stall_o, wb_ack_o, wb_clk, wb_rst);
4802 49 unneback
 
4803
    parameter dat_width = 32;
4804
    parameter adr_width = 8;
4805
 
4806
input [dat_width-1:0] wb_dat_i;
4807
input [adr_width-1:0] wb_adr_i;
4808
input [dat_width/8-1:0] wb_sel_i;
4809
input wb_we_i, wb_stb_i, wb_cyc_i;
4810
output [dat_width-1:0] wb_dat_o;
4811 51 unneback
reg [dat_width-1:0] wb_dat_o;
4812 52 unneback
output wb_stall_o;
4813 49 unneback
output wb_ack_o;
4814
reg wb_ack_o;
4815
input wb_clk, wb_rst;
4816
 
4817 56 unneback
wire [dat_width/8-1:0] cke;
4818
 
4819 49 unneback
generate
4820
if (dat_width==32) begin
4821 51 unneback
reg [7:0] ram3 [1<<(adr_width-2)-1:0];
4822
reg [7:0] ram2 [1<<(adr_width-2)-1:0];
4823
reg [7:0] ram1 [1<<(adr_width-2)-1:0];
4824
reg [7:0] ram0 [1<<(adr_width-2)-1:0];
4825 56 unneback
assign cke = wb_sel_i & {(dat_width/8){wb_we_i}};
4826 49 unneback
    always @ (posedge wb_clk)
4827
    begin
4828 56 unneback
        if (cke[3]) ram3[wb_adr_i[adr_width-1:2]] <= wb_dat_i[31:24];
4829
        if (cke[2]) ram2[wb_adr_i[adr_width-1:2]] <= wb_dat_i[23:16];
4830
        if (cke[1]) ram1[wb_adr_i[adr_width-1:2]] <= wb_dat_i[15:8];
4831
        if (cke[0]) ram0[wb_adr_i[adr_width-1:2]] <= wb_dat_i[7:0];
4832 49 unneback
    end
4833 59 unneback
    always @ (posedge wb_clk or posedge wb_rst)
4834
    begin
4835
        if (wb_rst)
4836
            wb_dat_o <= 32'h0;
4837
        else
4838
            wb_dat_o <= {ram3[wb_adr_i[adr_width-1:2]],ram2[wb_adr_i[adr_width-1:2]],ram1[wb_adr_i[adr_width-1:2]],ram0[wb_adr_i[adr_width-1:2]]};
4839
    end
4840 49 unneback
end
4841
endgenerate
4842
 
4843 52 unneback
always @ (posedge wb_clk or posedge wb_rst)
4844 55 unneback
if (wb_rst)
4845 52 unneback
    wb_ack_o <= 1'b0;
4846
else
4847 54 unneback
    wb_ack_o <= wb_stb_i & wb_cyc_i;
4848 52 unneback
 
4849
assign wb_stall_o = 1'b0;
4850
 
4851 49 unneback
endmodule
4852
`endif
4853
 
4854 48 unneback
`ifdef WB_B4_ROM
4855
// WB ROM
4856
`define MODULE wb_b4_rom
4857
module `BASE`MODULE (
4858
`undef MODULE
4859
    wb_adr_i, wb_stb_i, wb_cyc_i,
4860
    wb_dat_o, stall_o, wb_ack_o, wb_clk, wb_rst);
4861
 
4862
    parameter dat_width = 32;
4863
    parameter dat_default = 32'h15000000;
4864
    parameter adr_width = 32;
4865
 
4866
/*
4867
`ifndef ROM
4868
`define ROM "rom.v"
4869
`endif
4870
*/
4871
    input [adr_width-1:2]   wb_adr_i;
4872
    input                   wb_stb_i;
4873
    input                   wb_cyc_i;
4874
    output [dat_width-1:0]  wb_dat_o;
4875
    reg [dat_width-1:0]     wb_dat_o;
4876
    output                  wb_ack_o;
4877
    reg                     wb_ack_o;
4878
    output                  stall_o;
4879
    input                   wb_clk;
4880
    input                   wb_rst;
4881
 
4882
always @ (posedge wb_clk or posedge wb_rst)
4883
    if (wb_rst)
4884
        wb_dat_o <= {dat_width{1'b0}};
4885
    else
4886
         case (wb_adr_i[adr_width-1:2])
4887
`ifdef ROM
4888
`include `ROM
4889
`endif
4890
           default:
4891
             wb_dat_o <= dat_default;
4892
 
4893
         endcase // case (wb_adr_i)
4894
 
4895
 
4896
always @ (posedge wb_clk or posedge wb_rst)
4897
    if (wb_rst)
4898
        wb_ack_o <= 1'b0;
4899
    else
4900
        wb_ack_o <= wb_stb_i & wb_cyc_i;
4901
 
4902
assign stall_o = 1'b0;
4903
 
4904
endmodule
4905
`endif
4906
 
4907
 
4908 40 unneback
`ifdef WB_BOOT_ROM
4909 17 unneback
// WB ROM
4910 40 unneback
`define MODULE wb_boot_rom
4911
module `BASE`MODULE (
4912
`undef MODULE
4913 17 unneback
    wb_adr_i, wb_stb_i, wb_cyc_i,
4914 18 unneback
    wb_dat_o, wb_ack_o, hit_o, wb_clk, wb_rst);
4915 17 unneback
 
4916 18 unneback
    parameter adr_hi = 31;
4917
    parameter adr_lo = 28;
4918
    parameter adr_sel = 4'hf;
4919
    parameter addr_width = 5;
4920 33 unneback
/*
4921 17 unneback
`ifndef BOOT_ROM
4922
`define BOOT_ROM "boot_rom.v"
4923
`endif
4924 33 unneback
*/
4925 18 unneback
    input [adr_hi:2]    wb_adr_i;
4926
    input               wb_stb_i;
4927
    input               wb_cyc_i;
4928
    output [31:0]        wb_dat_o;
4929
    output              wb_ack_o;
4930
    output              hit_o;
4931
    input               wb_clk;
4932
    input               wb_rst;
4933
 
4934
    wire hit;
4935
    reg [31:0] wb_dat;
4936
    reg wb_ack;
4937
 
4938
assign hit = wb_adr_i[adr_hi:adr_lo] == adr_sel;
4939 17 unneback
 
4940
always @ (posedge wb_clk or posedge wb_rst)
4941
    if (wb_rst)
4942 18 unneback
        wb_dat <= 32'h15000000;
4943 17 unneback
    else
4944 18 unneback
         case (wb_adr_i[addr_width-1:2])
4945 33 unneback
`ifdef BOOT_ROM
4946 17 unneback
`include `BOOT_ROM
4947 33 unneback
`endif
4948 17 unneback
           /*
4949
            // Zero r0 and jump to 0x00000100
4950 18 unneback
 
4951
            1 : wb_dat <= 32'hA8200000;
4952
            2 : wb_dat <= 32'hA8C00100;
4953
            3 : wb_dat <= 32'h44003000;
4954
            4 : wb_dat <= 32'h15000000;
4955 17 unneback
            */
4956
           default:
4957 18 unneback
             wb_dat <= 32'h00000000;
4958 17 unneback
 
4959
         endcase // case (wb_adr_i)
4960
 
4961
 
4962
always @ (posedge wb_clk or posedge wb_rst)
4963
    if (wb_rst)
4964 18 unneback
        wb_ack <= 1'b0;
4965 17 unneback
    else
4966 18 unneback
        wb_ack <= wb_stb_i & wb_cyc_i & hit & !wb_ack;
4967 17 unneback
 
4968 18 unneback
assign hit_o = hit;
4969
assign wb_dat_o = wb_dat & {32{wb_ack}};
4970
assign wb_ack_o = wb_ack;
4971
 
4972 17 unneback
endmodule
4973 40 unneback
`endif
4974 32 unneback
 
4975 40 unneback
`ifdef WB_DPRAM
4976
`define MODULE wb_dpram
4977
module `BASE`MODULE (
4978
`undef MODULE
4979 32 unneback
        // wishbone slave side a
4980
        wbsa_dat_i, wbsa_adr_i, wbsa_we_i, wbsa_cyc_i, wbsa_stb_i, wbsa_dat_o, wbsa_ack_o,
4981
        wbsa_clk, wbsa_rst,
4982
        // wishbone slave side a
4983
        wbsb_dat_i, wbsb_adr_i, wbsb_we_i, wbsb_cyc_i, wbsb_stb_i, wbsb_dat_o, wbsb_ack_o,
4984
        wbsb_clk, wbsb_rst);
4985
 
4986
parameter data_width = 32;
4987
parameter addr_width = 8;
4988
 
4989
parameter dat_o_mask_a = 1;
4990
parameter dat_o_mask_b = 1;
4991
 
4992
input [31:0] wbsa_dat_i;
4993
input [addr_width-1:2] wbsa_adr_i;
4994
input wbsa_we_i, wbsa_cyc_i, wbsa_stb_i;
4995
output [31:0] wbsa_dat_o;
4996
output wbsa_ack_o;
4997
input wbsa_clk, wbsa_rst;
4998
 
4999
input [31:0] wbsb_dat_i;
5000
input [addr_width-1:2] wbsb_adr_i;
5001
input wbsb_we_i, wbsb_cyc_i, wbsb_stb_i;
5002
output [31:0] wbsb_dat_o;
5003
output wbsb_ack_o;
5004
input wbsb_clk, wbsb_rst;
5005
 
5006
wire wbsa_dat_tmp, wbsb_dat_tmp;
5007
 
5008 40 unneback
`define MODULE dpram_2r2w
5009
`BASE`MODULE # (
5010
`undef MODULE
5011 33 unneback
    .data_width(data_width), .addr_width(addr_width) )
5012 32 unneback
dpram0(
5013
    .d_a(wbsa_dat_i),
5014
    .q_a(wbsa_dat_tmp),
5015
    .adr_a(wbsa_adr_i),
5016
    .we_a(wbsa_we_i),
5017
    .clk_a(wbsa_clk),
5018
    .d_b(wbsb_dat_i),
5019
    .q_b(wbsb_dat_tmp),
5020
    .adr_b(wbsb_adr_i),
5021
    .we_b(wbsb_we_i),
5022
    .clk_b(wbsb_clk) );
5023
 
5024 33 unneback
generate if (dat_o_mask_a==1)
5025 32 unneback
    assign wbsa_dat_o = wbsa_dat_tmp & {data_width{wbsa_ack_o}};
5026
endgenerate
5027 33 unneback
generate if (dat_o_mask_a==0)
5028 32 unneback
    assign wbsa_dat_o = wbsa_dat_tmp;
5029
endgenerate
5030
 
5031 33 unneback
generate if (dat_o_mask_b==1)
5032 32 unneback
    assign wbsb_dat_o = wbsb_dat_tmp & {data_width{wbsb_ack_o}};
5033
endgenerate
5034 33 unneback
generate if (dat_o_mask_b==0)
5035 32 unneback
    assign wbsb_dat_o = wbsb_dat_tmp;
5036
endgenerate
5037
 
5038 40 unneback
`define MODULE spr
5039
`BASE`MODULE ack_a( .sp(wbsa_cyc_i & wbsa_stb_i & !wbsa_ack_o), .r(1'b1), .q(wbsa_ack_o), .clk(wbsa_clk), .rst(wbsa_rst));
5040
`BASE`MODULE ack_b( .sp(wbsb_cyc_i & wbsb_stb_i & !wbsb_ack_o), .r(1'b1), .q(wbsb_ack_o), .clk(wbsb_clk), .rst(wbsb_rst));
5041
`undef MODULE
5042 32 unneback
 
5043
endmodule
5044 40 unneback
`endif
5045 18 unneback
//////////////////////////////////////////////////////////////////////
5046
////                                                              ////
5047
////  Arithmetic functions                                        ////
5048
////                                                              ////
5049
////  Description                                                 ////
5050
////  Arithmetic functions for ALU and DSP                        ////
5051
////                                                              ////
5052
////                                                              ////
5053
////  To Do:                                                      ////
5054
////   -                                                          ////
5055
////                                                              ////
5056
////  Author(s):                                                  ////
5057
////      - Michael Unneback, unneback@opencores.org              ////
5058
////        ORSoC AB                                              ////
5059
////                                                              ////
5060
//////////////////////////////////////////////////////////////////////
5061
////                                                              ////
5062
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
5063
////                                                              ////
5064
//// This source file may be used and distributed without         ////
5065
//// restriction provided that this copyright statement is not    ////
5066
//// removed from the file and that any derivative work contains  ////
5067
//// the original copyright notice and the associated disclaimer. ////
5068
////                                                              ////
5069
//// This source file is free software; you can redistribute it   ////
5070
//// and/or modify it under the terms of the GNU Lesser General   ////
5071
//// Public License as published by the Free Software Foundation; ////
5072
//// either version 2.1 of the License, or (at your option) any   ////
5073
//// later version.                                               ////
5074
////                                                              ////
5075
//// This source is distributed in the hope that it will be       ////
5076
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
5077
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
5078
//// PURPOSE.  See the GNU Lesser General Public License for more ////
5079
//// details.                                                     ////
5080
////                                                              ////
5081
//// You should have received a copy of the GNU Lesser General    ////
5082
//// Public License along with this source; if not, download it   ////
5083
//// from http://www.opencores.org/lgpl.shtml                     ////
5084
////                                                              ////
5085
//////////////////////////////////////////////////////////////////////
5086
 
5087 40 unneback
`ifdef MULTS
5088 18 unneback
// signed multiplication
5089 40 unneback
`define MODULE mults
5090
module `BASE`MODULE (a,b,p);
5091
`undef MODULE
5092 18 unneback
parameter operand_a_width = 18;
5093
parameter operand_b_width = 18;
5094
parameter result_hi = 35;
5095
parameter result_lo = 0;
5096
input [operand_a_width-1:0] a;
5097
input [operand_b_width-1:0] b;
5098
output [result_hi:result_lo] p;
5099
wire signed [operand_a_width-1:0] ai;
5100
wire signed [operand_b_width-1:0] bi;
5101
wire signed [operand_a_width+operand_b_width-1:0] result;
5102
 
5103
    assign ai = a;
5104
    assign bi = b;
5105
    assign result = ai * bi;
5106
    assign p = result[result_hi:result_lo];
5107
 
5108
endmodule
5109 40 unneback
`endif
5110
`ifdef MULTS18X18
5111
`define MODULE mults18x18
5112
module `BASE`MODULE (a,b,p);
5113
`undef MODULE
5114 18 unneback
input [17:0] a,b;
5115
output [35:0] p;
5116
vl_mult
5117
    # (.operand_a_width(18), .operand_b_width(18))
5118
    mult0 (.a(a), .b(b), .p(p));
5119
endmodule
5120 40 unneback
`endif
5121 18 unneback
 
5122 40 unneback
`ifdef MULT
5123
`define MODULE mult
5124 18 unneback
// unsigned multiplication
5125 40 unneback
module `BASE`MODULE (a,b,p);
5126
`undef MODULE
5127 18 unneback
parameter operand_a_width = 18;
5128
parameter operand_b_width = 18;
5129
parameter result_hi = 35;
5130
parameter result_lo = 0;
5131
input [operand_a_width-1:0] a;
5132
input [operand_b_width-1:0] b;
5133
output [result_hi:result_hi] p;
5134
 
5135
wire [operand_a_width+operand_b_width-1:0] result;
5136
 
5137
    assign result = a * b;
5138
    assign p = result[result_hi:result_lo];
5139
 
5140
endmodule
5141 40 unneback
`endif
5142 18 unneback
 
5143 40 unneback
`ifdef SHIFT_UNIT_32
5144
`define MODULE shift_unit_32
5145 18 unneback
// shift unit
5146
// supporting the following shift functions
5147
//   SLL
5148
//   SRL
5149
//   SRA
5150
`define SHIFT_UNIT_MULT # ( .operand_a_width(25), .operand_b_width(16), .result_hi(14), .result_lo(7))
5151 40 unneback
module `BASE`MODULE( din, s, dout, opcode);
5152
`undef MODULE
5153 18 unneback
input [31:0] din; // data in operand
5154
input [4:0] s; // shift operand
5155
input [1:0] opcode;
5156
output [31:0] dout;
5157
 
5158
parameter opcode_sll = 2'b00;
5159
//parameter opcode_srl = 2'b01;
5160
parameter opcode_sra = 2'b10;
5161
//parameter opcode_ror = 2'b11;
5162
 
5163
wire sll, sra;
5164
assign sll = opcode == opcode_sll;
5165
assign sra = opcode == opcode_sra;
5166
 
5167
wire [15:1] s1;
5168
wire [3:0] sign;
5169
wire [7:0] tmp [0:3];
5170
 
5171
// first stage is multiplier based
5172
// shift operand as fractional 8.7
5173
assign s1[15] = sll & s[2:0]==3'd7;
5174
assign s1[14] = sll & s[2:0]==3'd6;
5175
assign s1[13] = sll & s[2:0]==3'd5;
5176
assign s1[12] = sll & s[2:0]==3'd4;
5177
assign s1[11] = sll & s[2:0]==3'd3;
5178
assign s1[10] = sll & s[2:0]==3'd2;
5179
assign s1[ 9] = sll & s[2:0]==3'd1;
5180
assign s1[ 8] = s[2:0]==3'd0;
5181
assign s1[ 7] = !sll & s[2:0]==3'd1;
5182
assign s1[ 6] = !sll & s[2:0]==3'd2;
5183
assign s1[ 5] = !sll & s[2:0]==3'd3;
5184
assign s1[ 4] = !sll & s[2:0]==3'd4;
5185
assign s1[ 3] = !sll & s[2:0]==3'd5;
5186
assign s1[ 2] = !sll & s[2:0]==3'd6;
5187
assign s1[ 1] = !sll & s[2:0]==3'd7;
5188
 
5189
assign sign[3] = din[31] & sra;
5190
assign sign[2] = sign[3] & (&din[31:24]);
5191
assign sign[1] = sign[2] & (&din[23:16]);
5192
assign sign[0] = sign[1] & (&din[15:8]);
5193 40 unneback
`define MODULE mults
5194
`BASE`MODULE `SHIFT_UNIT_MULT mult_byte3 ( .a({sign[3], {8{sign[3]}},din[31:24], din[23:16]}), .b({1'b0,s1}), .p(tmp[3]));
5195
`BASE`MODULE `SHIFT_UNIT_MULT mult_byte2 ( .a({sign[2], din[31:24]  ,din[23:16],  din[15:8]}), .b({1'b0,s1}), .p(tmp[2]));
5196
`BASE`MODULE `SHIFT_UNIT_MULT mult_byte1 ( .a({sign[1], din[23:16]  ,din[15:8],   din[7:0]}), .b({1'b0,s1}), .p(tmp[1]));
5197
`BASE`MODULE `SHIFT_UNIT_MULT mult_byte0 ( .a({sign[0], din[15:8]   ,din[7:0],    8'h00}),      .b({1'b0,s1}), .p(tmp[0]));
5198
`undef MODULE
5199 18 unneback
// second stage is multiplexer based
5200
// shift on byte level
5201
 
5202
// mux byte 3
5203
assign dout[31:24] = (s[4:3]==2'b00) ? tmp[3] :
5204
                     (sll & s[4:3]==2'b01) ? tmp[2] :
5205
                     (sll & s[4:3]==2'b10) ? tmp[1] :
5206
                     (sll & s[4:3]==2'b11) ? tmp[0] :
5207
                     {8{sign[3]}};
5208
 
5209
// mux byte 2
5210
assign dout[23:16] = (s[4:3]==2'b00) ? tmp[2] :
5211
                     (sll & s[4:3]==2'b01) ? tmp[1] :
5212
                     (sll & s[4:3]==2'b10) ? tmp[0] :
5213
                     (sll & s[4:3]==2'b11) ? {8{1'b0}} :
5214
                     (s[4:3]==2'b01) ? tmp[3] :
5215
                     {8{sign[3]}};
5216
 
5217
// mux byte 1
5218
assign dout[15:8]  = (s[4:3]==2'b00) ? tmp[1] :
5219
                     (sll & s[4:3]==2'b01) ? tmp[0] :
5220
                     (sll & s[4:3]==2'b10) ? {8{1'b0}} :
5221
                     (sll & s[4:3]==2'b11) ? {8{1'b0}} :
5222
                     (s[4:3]==2'b01) ? tmp[2] :
5223
                     (s[4:3]==2'b10) ? tmp[3] :
5224
                     {8{sign[3]}};
5225
 
5226
// mux byte 0
5227
assign dout[7:0]   = (s[4:3]==2'b00) ? tmp[0] :
5228
                     (sll) ?  {8{1'b0}}:
5229
                     (s[4:3]==2'b01) ? tmp[1] :
5230
                     (s[4:3]==2'b10) ? tmp[2] :
5231
                     tmp[3];
5232
 
5233
endmodule
5234 40 unneback
`endif
5235 18 unneback
 
5236 40 unneback
`ifdef LOGIC_UNIT
5237 18 unneback
// logic unit
5238
// supporting the following logic functions
5239
//    a and b
5240
//    a or  b
5241
//    a xor b
5242
//    not b
5243 40 unneback
`define MODULE logic_unit
5244
module `BASE`MODULE( a, b, result, opcode);
5245
`undef MODULE
5246 18 unneback
parameter width = 32;
5247
parameter opcode_and = 2'b00;
5248
parameter opcode_or  = 2'b01;
5249
parameter opcode_xor = 2'b10;
5250
input [width-1:0] a,b;
5251
output [width-1:0] result;
5252
input [1:0] opcode;
5253
 
5254
assign result = (opcode==opcode_and) ? a & b :
5255
                (opcode==opcode_or)  ? a | b :
5256
                (opcode==opcode_xor) ? a ^ b :
5257
                b;
5258
 
5259
endmodule
5260 48 unneback
`endif
5261 18 unneback
 
5262 48 unneback
`ifdef ARITH_UNIT
5263
`define MODULE arith_unit
5264
module `BASE`MODULE ( a, b, c_in, add_sub, sign, result, c_out, z, ovfl);
5265
`undef MODULE
5266 18 unneback
parameter width = 32;
5267
parameter opcode_add = 1'b0;
5268
parameter opcode_sub = 1'b1;
5269
input [width-1:0] a,b;
5270
input c_in, add_sub, sign;
5271
output [width-1:0] result;
5272
output c_out, z, ovfl;
5273
 
5274
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))};
5275
assign z = (result=={width{1'b0}});
5276
assign ovfl = ( a[width-1] &  b[width-1] & ~result[width-1]) |
5277
               (~a[width-1] & ~b[width-1] &  result[width-1]);
5278
endmodule
5279 40 unneback
`endif
5280 48 unneback
 
5281
`ifdef COUNT_UNIT
5282
`define MODULE count_unit
5283
module `BASE`MODULE (din, dout, opcode);
5284
`undef MODULE
5285
parameter width = 32;
5286
input [width-1:0] din;
5287
output [width-1:0] dout;
5288
input opcode;
5289
 
5290
integer i;
5291 58 unneback
wire [width/32+4:0] ff1, fl1;
5292 48 unneback
 
5293 57 unneback
/*
5294 48 unneback
always @(din) begin
5295
    ff1 = 0; i = 0;
5296
    while (din[i] == 0 && i < width) begin // complex condition
5297
        ff1 = ff1 + 1;
5298
        i = i + 1;
5299
    end
5300
end
5301
 
5302
always @(din) begin
5303
    fl1 = width; i = width-1;
5304
    while (din[i] == 0 && i >= width) begin // complex condition
5305
        fl1 = fl1 - 1;
5306
        i = i - 1;
5307
    end
5308
end
5309 57 unneback
*/
5310 48 unneback
 
5311
generate
5312
if (width==32) begin
5313 57 unneback
 
5314
    assign ff1 = din[0] ? 6'd1 :
5315
                 din[1] ? 6'd2 :
5316
                 din[2] ? 6'd3 :
5317
                 din[3] ? 6'd4 :
5318
                 din[4] ? 6'd5 :
5319
                 din[5] ? 6'd6 :
5320
                 din[6] ? 6'd7 :
5321
                 din[7] ? 6'd8 :
5322
                 din[8] ? 6'd9 :
5323
                 din[9] ? 6'd10 :
5324
                 din[10] ? 6'd11 :
5325
                 din[11] ? 6'd12 :
5326
                 din[12] ? 6'd13 :
5327
                 din[13] ? 6'd14 :
5328
                 din[14] ? 6'd15 :
5329
                 din[15] ? 6'd16 :
5330
                 din[16] ? 6'd17 :
5331
                 din[17] ? 6'd18 :
5332
                 din[18] ? 6'd19 :
5333
                 din[19] ? 6'd20 :
5334
                 din[20] ? 6'd21 :
5335
                 din[21] ? 6'd22 :
5336
                 din[22] ? 6'd23 :
5337
                 din[23] ? 6'd24 :
5338
                 din[24] ? 6'd25 :
5339
                 din[25] ? 6'd26 :
5340
                 din[26] ? 6'd27 :
5341
                 din[27] ? 6'd28 :
5342
                 din[28] ? 6'd29 :
5343
                 din[29] ? 6'd30 :
5344
                 din[30] ? 6'd31 :
5345
                 din[31] ? 6'd32 :
5346
                 6'd0;
5347
 
5348
    assign fl1 = din[31] ? 6'd32 :
5349
                 din[30] ? 6'd31 :
5350
                 din[29] ? 6'd30 :
5351
                 din[28] ? 6'd29 :
5352
                 din[27] ? 6'd28 :
5353
                 din[26] ? 6'd27 :
5354
                 din[25] ? 6'd26 :
5355
                 din[24] ? 6'd25 :
5356
                 din[23] ? 6'd24 :
5357
                 din[22] ? 6'd23 :
5358
                 din[21] ? 6'd22 :
5359
                 din[20] ? 6'd21 :
5360
                 din[19] ? 6'd20 :
5361
                 din[18] ? 6'd19 :
5362
                 din[17] ? 6'd18 :
5363
                 din[16] ? 6'd17 :
5364
                 din[15] ? 6'd16 :
5365
                 din[14] ? 6'd15 :
5366
                 din[13] ? 6'd14 :
5367
                 din[12] ? 6'd13 :
5368
                 din[11] ? 6'd12 :
5369
                 din[10] ? 6'd11 :
5370
                 din[9] ? 6'd10 :
5371
                 din[8] ? 6'd9 :
5372
                 din[7] ? 6'd8 :
5373
                 din[6] ? 6'd7 :
5374
                 din[5] ? 6'd6 :
5375
                 din[4] ? 6'd5 :
5376
                 din[3] ? 6'd4 :
5377
                 din[2] ? 6'd3 :
5378
                 din[1] ? 6'd2 :
5379
                 din[0] ? 6'd1 :
5380
                 6'd0;
5381
 
5382
    assign dout = (!opcode) ? {{26{1'b0}}, ff1} : {{26{1'b0}}, fl1};
5383 48 unneback
end
5384
endgenerate
5385 57 unneback
 
5386 48 unneback
generate
5387
if (width==64) begin
5388 57 unneback
    assign ff1 = 7'd0;
5389
    assign fl1 = 7'd0;
5390
    assign dout = (!opcode) ? {{57{1'b0}}, ff1} : {{57{1'b0}}, fl1};
5391 48 unneback
end
5392
endgenerate
5393
 
5394
endmodule
5395
`endif
5396
 
5397
`ifdef EXT_UNIT
5398
`define MODULE ext_unit
5399
module `BASE`MODULE ( a, b, F, result, opcode);
5400
`undef MODULE
5401
parameter width = 32;
5402
input [width-1:0] a, b;
5403
input F;
5404
output reg [width-1:0] result;
5405
input [2:0] opcode;
5406
 
5407
generate
5408
if (width==32) begin
5409
always @ (a or b or F or opcode)
5410
begin
5411
    case (opcode)
5412
    3'b000: result = {{24{1'b0}},a[7:0]};
5413
    3'b001: result = {{24{a[7]}},a[7:0]};
5414
    3'b010: result = {{16{1'b0}},a[7:0]};
5415
    3'b011: result = {{16{a[15]}},a[15:0]};
5416
    3'b110: result = (F) ? a : b;
5417
    default: result = {b[15:0],16'h0000};
5418
    endcase
5419
end
5420
end
5421
endgenerate
5422
 
5423
generate
5424
if (width==64) begin
5425
always @ (a or b or F or opcode)
5426
begin
5427
    case (opcode)
5428
    3'b000: result = {{56{1'b0}},a[7:0]};
5429
    3'b001: result = {{56{a[7]}},a[7:0]};
5430
    3'b010: result = {{48{1'b0}},a[7:0]};
5431
    3'b011: result = {{48{a[15]}},a[15:0]};
5432 57 unneback
    3'b110: result = (F) ? a : b;
5433 48 unneback
    default: result = {32'h00000000,b[15:0],16'h0000};
5434
    endcase
5435
end
5436
end
5437
endgenerate
5438
endmodule
5439
`endif

powered by: WebSVN 2.1.0

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