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

Subversion Repositories wiegand_ctl

[/] [wiegand_ctl/] [trunk/] [rtl/] [verilog/] [fifos.v] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 jeaander
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  fifos.v                                                     ////
4
////                                                              ////
5
////                                                              ////
6
////  This file is part of the Wiegand Protocol Controller        ////
7
////  http://www.opencores.org/projects/wiegand/                  ////
8
////                                                              ////
9
////                                                              ////
10
////  Author(s):                                                  ////
11
////       Jeff Anderson                                          ////
12
////       jeaander@opencores.org                                 ////
13
////                                                              ////
14
////                                                              ////
15
////  All additional information is available in the README.txt   ////
16
////  file.                                                       ////
17
////                                                              ////
18
//////////////////////////////////////////////////////////////////////
19
////                                                              ////
20
//// Copyright (C) 2013 Authors                                   ////
21
////                                                              ////
22
//// This source file may be used and distributed without         ////
23
//// restriction provided that this copyright statement is not    ////
24
//// removed from the file and that any derivative work contains  ////
25
//// the original copyright notice and the associated disclaimer. ////
26
////                                                              ////
27
//// This source file is free software; you can redistribute it   ////
28
//// and/or modify it under the terms of the GNU Lesser General   ////
29
//// Public License as published by the Free Software Foundation; ////
30
//// either version 2.1 of the License, or (at your option) any   ////
31
//// later version.                                               ////
32
////                                                              ////
33
//// This source is distributed in the hope that it will be       ////
34
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
35
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
36
//// PURPOSE.  See the GNU Lesser General Public License for more ////
37
//// details.                                                     ////
38
////                                                              ////
39
//// You should have received a copy of the GNU Lesser General    ////
40
//// Public License along with this source; if not, download it   ////
41
//// from http://www.opencores.org/lgpl.shtml                     ////
42
////                                                              ////
43
////                                                              ////
44
//////////////////////////////////////////////////////////////////////
45
//
46
//  Revisions at end of file
47
//
48
 
49
// synopsys translate_off
50
`include "timescale.v"
51
// synopsys translate_on
52
`include "wiegand_defines.v"
53
 
54
//pulling in data bus width from WIEGAND_defines file
55
`ifdef WIEGAND_WIDTH64
56
  `define WIEGAND_FIFODATAWIDTH 64
57
`elsif WIEGAND_WIDTH32
58
  `define WIEGAND_FIFODATAWIDTH 32
59
`elsif WIEGAND_WIDTH16
60
  `define WIEGAND_FIFODATAWIDTH 16
61
`else
62
  `define WIEGAND_FIFODATAWIDTH 8
63
`endif
64
 
65
//define depth of FIFO; pulling in depth from WIEGAND_defines
66
//`define WIEGAND_FIFODEPTH 16
67
 
68
//uncomment a single implementation of FIFO; pulling in implementation from WIEGAND_defines
69
//`define WIEGAND_CUSTOMFIFO
70
 
71
module fifo_wieg
72
(
73
  clk_rd,
74
  clk_wr,
75
  d_i,
76
  d_o,
77
  rst,
78
  wr_en,
79
  rd_en,
80
  full,
81
  empty
82
);
83
  input clk_rd;
84
  input clk_wr;
85
  input [`WIEGAND_FIFODATAWIDTH-1:0] d_i;
86
  output [`WIEGAND_FIFODATAWIDTH-1:0] d_o;
87
  input rst;
88
  input wr_en;
89
  input rd_en;
90
  output full;
91
  output empty;
92
 
93
`ifdef WIEGAND_CUSTOMFIFO
94
  `ifdef WIEGAND_WIDTH64
95
    wire [7:0] full_int;
96
    wire [7:0] empty_int;
97
    assign full = |full_int;
98
    assign empty = |empty_int;
99
    custom_fifo_dp custom_fifo_dp1(clk_rd,clk_wr,d_i[63:56],d_o[63:56],rst,wr_en,rd_en,full_int[0],empty_int[0]);
100
    custom_fifo_dp custom_fifo_dp2(clk_rd,clk_wr,d_i[55:48],d_o[55:48],rst,wr_en,rd_en,full_int[1],empty_int[1]);
101
    custom_fifo_dp custom_fifo_dp3(clk_rd,clk_wr,d_i[47:40],d_o[47:40],rst,wr_en,rd_en,full_int[2],empty_int[2]);
102
    custom_fifo_dp custom_fifo_dp4(clk_rd,clk_wr,d_i[39:32],d_o[39:32],rst,wr_en,rd_en,full_int[3],empty_int[3]);
103
    custom_fifo_dp custom_fifo_dp5(clk_rd,clk_wr,d_i[31:24],d_o[31:24],rst,wr_en,rd_en,full_int[4],empty_int[4]);
104
    custom_fifo_dp custom_fifo_dp6(clk_rd,clk_wr,d_i[23:16],d_o[23:16],rst,wr_en,rd_en,full_int[5],empty_int[5]);
105
    custom_fifo_dp custom_fifo_dp7(clk_rd,clk_wr,d_i[15:8],d_o[15:8],rst,wr_en,rd_en,full_int[6],empty_int[6]);
106
    custom_fifo_dp custom_fifo_dp8(clk_rd,clk_wr,d_i[7:0],d_o[7:0],rst,wr_en,rd_en,full_int[7],empty_int[7]);
107
  `elsif WIEGAND_WIDTH32
108
    wire [3:0] full_int;
109
    wire [3:0] empty_int;
110
    assign full = |full_int;
111
    assign empty = |empty_int;
112
    custom_fifo_dp custom_fifo_dp5(clk_rd,clk_wr,d_i[31:24],d_o[31:24],rst,wr_en,rd_en,full_int[0],empty_int[0]);
113
    custom_fifo_dp custom_fifo_dp6(clk_rd,clk_wr,d_i[23:16],d_o[23:16],rst,wr_en,rd_en,full_int[1],empty_int[1]);
114
    custom_fifo_dp custom_fifo_dp7(clk_rd,clk_wr,d_i[15:8],d_o[15:8],rst,wr_en,rd_en,full_int[2],empty_int[2]);
115
    custom_fifo_dp custom_fifo_dp8(clk_rd,clk_wr,d_i[7:0],d_o[7:0],rst,wr_en,rd_en,full_int[3],empty_int[3]);
116
  `elsif WIEGAND_WIDTH16
117
    wire [1:0] full_int;
118
    wire [1:0] empty_int;
119
    assign full = |full_int;
120
    assign empty = |empty_int;
121
    custom_fifo_dp custom_fifo_dp7(clk_rd,clk_wr,d_i[15:8],d_o[15:8],rst,wr_en,rd_en,full_int[0],empty_int[0]);
122
    custom_fifo_dp custom_fifo_dp8(clk_rd,clk_wr,d_i[7:0],d_o[7:0],rst,wr_en,rd_en,full_int[1],empty_int[1]);
123
  `else
124
    custom_fifo_dp custom_fifo_dp8(clk_rd,clk_wr,d_i[7:0],d_o[7:0],rst,wr_en,rd_en,full,empty);
125
  `endif
126
`endif
127
 
128
endmodule
129
 
130
module custom_fifo_dp (
131
  clk_rd,
132
  clk_wr,
133
  d_i,
134
  d_o,
135
  rst,
136
  wr_en,
137
  rd_en,
138
  full,
139
  empty
140
);
141
  input clk_rd;
142
  input clk_wr;
143
  input [7:0] d_i;
144
  output [7:0] d_o;
145
  input rst;
146
  input wr_en;
147
  input rd_en;
148
  output full;
149
  output empty;
150
 
151
  reg [`WIEGAND_FIFODEPTH-1:0] addr_rd;
152
  reg [`WIEGAND_FIFODEPTH-1:0] addr_wr;
153
  reg [7:0] fifo_out;
154
  wire [7:0] mem_byte_out;
155
  wire [`WIEGAND_FIFODEPTH-1:0] full_int;
156
 
157
  //bytewide memory array in FIFO.  user sets depth.
158
  genvar c;
159
  generate
160
    for (c = 0; c < `WIEGAND_FIFODEPTH; c = c + 1) begin: mem
161
      mem_byte mem_byte(rst,clk_wr,d_i,mem_byte_out,addr_wr[c],addr_rd[c]);
162
    end
163
  endgenerate
164
 
165
  //read logic needed here to handle clock domain change
166
  assign d_o = fifo_out;
167
  always @(posedge clk_rd or posedge rst) begin
168
    if (rst)  fifo_out <= 8'h0;
169
    else      fifo_out <= mem_byte_out;
170
  end
171
 
172
  //addressing logic is simply a circular shift register that gets reset to 1
173
  always @(posedge clk_wr or posedge rst) begin
174
    if (rst)  addr_wr <= `WIEGAND_FIFODEPTH'h1;
175
    else if (wr_en&(~full)) begin
176
      addr_wr[`WIEGAND_FIFODEPTH-1:1] <= addr_wr[`WIEGAND_FIFODEPTH-2:0];
177
      addr_wr[0] <= addr_wr[`WIEGAND_FIFODEPTH-1];
178
    end
179
  end
180
 
181
  always @(posedge clk_rd or posedge rst) begin
182
    if (rst)  addr_rd <= `WIEGAND_FIFODEPTH'h1;
183
    else if (rd_en&(~empty)) begin
184
      addr_rd[`WIEGAND_FIFODEPTH-1:1] <= addr_rd[`WIEGAND_FIFODEPTH-2:0];
185
      addr_rd[0] <= addr_rd[`WIEGAND_FIFODEPTH-1];
186
    end
187
  end
188
 
189
  //use address logic for flags
190
  assign empty = (addr_wr == addr_rd);              //when read addr catches write addr, we're empty
191
 
192
  assign full = empty?1'b0:|full_int;              //if fifo isn't empty, then OR all full flag outputs
193
 
194
  assign full_int[0] = (addr_wr[`WIEGAND_FIFODEPTH-1] & addr_rd[0]);  //when we've written to entire mem, we're full
195
  genvar d;
196
  generate
197
    for (d = 1; d < `WIEGAND_FIFODEPTH; d = d + 1) begin: flag
198
      assign full_int[d] = (addr_wr[d-1] & addr_rd[d]);   //when we've written to entire mem, we're full
199
    end
200
  endgenerate
201
 
202
endmodule
203
 
204
module mem_byte(
205
  rst,
206
  clk,
207
  din,
208
  dout,
209
  wen,
210
  ren
211
);
212
 
213
  input rst;
214
  input clk;
215
  input[7:0] din;
216
  output [7:0] dout;
217
  input wen;
218
  input ren;
219
 
220
  reg[7:0] byte_reg;
221
 
222
  //just a byte-wide register with input and output enables
223
  assign dout = ren?byte_reg:8'bz;
224
 
225
  always @(posedge clk or posedge rst) begin
226
    if (rst)        byte_reg <= 8'h0;
227
    else if (wen)   byte_reg <= din;
228
  end
229
 
230
endmodule
231
 
232
//////////////////////////////////////////////////////////////////////
233
//
234
// CVS Revision History
235
//
236
// $Log: $
237
//

powered by: WebSVN 2.1.0

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