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