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

Subversion Repositories cryptosorter

[/] [cryptosorter/] [trunk/] [lib/] [bsv/] [BRAMFIFO/] [BRAMFIFOF.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 kfleming
//----------------------------------------------------------------------//
2
// The MIT License 
3
// 
4
// Copyright (c) 2008 Kermin Fleming, kfleming@mit.edu 
5
// 
6
// Permission is hereby granted, free of charge, to any person 
7
// obtaining a copy of this software and associated documentation 
8
// files (the "Software"), to deal in the Software without 
9
// restriction, including without limitation the rights to use,
10
// copy, modify, merge, publish, distribute, sublicense, and/or sell
11
// copies of the Software, and to permit persons to whom the
12
// Software is furnished to do so, subject to the following conditions:
13
// 
14
// The above copyright notice and this permission notice shall be
15
// included in all copies or substantial portions of the Software.
16
// 
17
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
// OTHER DEALINGS IN THE SOFTWARE.
25
//----------------------------------------------------------------------//
26
 
27
 
28
/***
29
 *
30
 * This module implements a parametric verilog sized fifo.  This particular
31
 * sized fifo will synthesize on to Xilinx block rams.  The fifo is parametric
32
 * in terms of both data width and the number of data stored in the fifo.
33
 * the interface is gaurded.  The fifo is not loopy.
34
 * The methods supported by the FIFO are clear, dequeue, enqueue, notFull,
35
 * and notEmpty
36
 *
37
 ***/
38
 
39
 
40
module BRAMFIFOF(CLK, RST_N,
41
            D_IN, CLR, DEQ,
42
            ENQ, D_OUT, FULL_N, EMPTY_N);
43
 
44
   // synopsys template   
45
   parameter                   log_data_count = 0;
46
   parameter                   data_count = 1;
47
   parameter                   data_width = 1;
48
 
49
   input                       CLK;
50
   input                       RST_N;
51
 
52
   input [data_width - 1 : 0]  D_IN;
53
   input                       CLR;
54
   input                       DEQ;
55
   input                       ENQ;
56
 
57
   output [data_width - 1 : 0] D_OUT;
58
   output                      FULL_N;
59
   output                      EMPTY_N;
60
 
61
 
62
 
63
   reg [data_width - 1 : 0]    arr[0:data_count]; /*synthesis syn_ramstyle = "block_ram"*/
64
 
65
   reg                          skid_flag;
66
   reg [log_data_count + 2 : 0] fifo_data_count;
67
   reg [log_data_count + 2 : 0] read_ptr;
68
   reg [log_data_count + 2 : 0] read_ptr_current;
69
   reg [log_data_count + 2 : 0] write_ptr;
70
   reg [data_width - 1 : 0]    skid_buffer; // this is a fast output buffer
71
   reg [data_width - 1 : 0]    RAM_OUT;
72
 
73
 
74
   assign D_OUT = (skid_flag)?skid_buffer:RAM_OUT;
75
 
76
   assign FULL_N = !(fifo_data_count == data_count);
77
   assign EMPTY_N = !(fifo_data_count == 0);
78
 
79
   integer x;
80
 
81
   always@(*)
82
     begin
83
       if(DEQ)
84
         begin
85
           read_ptr_current = (read_ptr  == data_count)?0:(read_ptr + 1);
86
         end
87
       else
88
         begin
89
           read_ptr_current = read_ptr;
90
         end
91
     end
92
 
93
 
94
 
95
   always@(posedge CLK)
96
     begin
97
       if (!RST_N)
98
         begin  //Make simulation behavior consistent with Xilinx synthesis
99
           // synopsys translate_off
100
           for (x = 0; x < data_count + 1; x = x + 1)
101
           begin
102
             arr[x] <= 0;
103
           end
104
           // synopsys translate_on
105
           fifo_data_count <= 0;
106
           skid_buffer <= 0;
107
           skid_flag <= 0;
108
           read_ptr <= 0;
109
           write_ptr <= 0;
110
           //$display("Params: data_count: %d, log_data_count: %d, data_width: %d", data_count, log_data_count, data_width);
111
         end
112
       else
113
         begin
114
           // assign output buffer
115
           skid_buffer <= D_IN;
116
 
117
           if(CLR)
118
             begin
119
               skid_flag <= 0;
120
             end
121
           else if(ENQ && ((fifo_data_count == 0) || ((fifo_data_count == 1) && DEQ)))
122
             begin
123
               //$display("Enque to output buffer");
124
               skid_flag <= 1;
125
             end
126
           else
127
             begin
128
               skid_flag <= 0;
129
             end
130
 
131
           // write_ptr
132
            if(CLR)
133
              begin
134
                write_ptr <= 0;
135
              end
136
            else if(ENQ)
137
              begin
138
                //$display("Enque to BRAM[%d]: %d", write_ptr,D_IN);
139
                write_ptr <= (write_ptr  == data_count)?0:(write_ptr + 1);
140
              end
141
            else
142
              begin
143
                write_ptr <= write_ptr;
144
              end
145
 
146
           //read_ptr
147
            if(CLR)
148
              begin
149
                read_ptr <= 0;
150
              end
151
            else if(DEQ)
152
              begin
153
                //$display("Advancing read ptr");
154
                read_ptr <= (read_ptr  == data_count)?0:(read_ptr + 1);
155
              end
156
            else
157
              begin
158
                read_ptr <= read_ptr;
159
              end
160
 
161
           // assign fifo data_count
162
           if(CLR)
163
             begin
164
               fifo_data_count <= 0;
165
             end
166
           else if(ENQ && DEQ)
167
             begin
168
               fifo_data_count <= fifo_data_count;
169
             end
170
           else if(ENQ)
171
             begin
172
               fifo_data_count <= fifo_data_count + 1;
173
             end
174
           else if(DEQ)
175
             begin
176
               fifo_data_count <= fifo_data_count - 1;
177
             end
178
           else
179
             begin
180
               fifo_data_count <= fifo_data_count;
181
             end
182
           if(ENQ)
183
             begin
184
               arr[write_ptr] <= D_IN;
185
             end
186
           RAM_OUT <= arr[read_ptr_current];
187
 
188
         end
189
     end // always@ (posedge CLK)
190
 
191
endmodule

powered by: WebSVN 2.1.0

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