summaryrefslogtreecommitdiff
path: root/rtl/dma_axi32/prgen_fifo.v
blob: 39a8364184c2c30a00c01544ca5eae9dc1081885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// verilator lint_off WIDTHEXPAND
// verilator lint_off WIDTHTRUNC
/////////////////////////////////////////////////////////////////////
////                                                             ////
////  Author: Eyal Hochberg                                      ////
////          eyal@provartec.com                                 ////
////                                                             ////
////  Downloaded from: http://www.opencores.org                  ////
/////////////////////////////////////////////////////////////////////
////                                                             ////
//// Copyright (C) 2010 Provartec LTD                            ////
//// www.provartec.com                                           ////
//// info@provartec.com                                          ////
////                                                             ////
//// This source file may be used and distributed without        ////
//// restriction provided that this copyright statement is not   ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer.////
////                                                             ////
//// This source file is free software; you can redistribute it  ////
//// and/or modify it under the terms of the GNU Lesser General  ////
//// Public License as published by the Free Software Foundation.////
////                                                             ////
//// This source is distributed in the hope that it will be      ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
//// PURPOSE.  See the GNU Lesser General Public License for more////
//// details. http://www.gnu.org/licenses/lgpl.html              ////
////                                                             ////
/////////////////////////////////////////////////////////////////////
//---------------------------------------------------------
//-- File generated by RobustVerilog parser
//-- Version: 1.0
//-- Invoked Fri Mar 25 23:34:51 2011
//--
//-- Source file: prgen_fifo.v
//---------------------------------------------------------



module prgen_fifo(clk,reset,push,pop,din,dout,empty,full);

   parameter                  WIDTH      = 8;
   parameter                  DEPTH_FULL = 8;

   parameter               SINGLE     = DEPTH_FULL == 1;
   parameter               DEPTH      = SINGLE ? 1 : DEPTH_FULL -1;
   parameter               DEPTH_BITS = 
                  (DEPTH <= 2)   ? 1 :
                  (DEPTH <= 4)   ? 2 :
                  (DEPTH <= 8)   ? 3 :
                  (DEPTH <= 16)  ? 4 :
                  (DEPTH <= 32)  ? 5 :
                  (DEPTH <= 64)  ? 6 :
                  (DEPTH <= 128) ? 7 : 
                  (DEPTH <= 256) ? 8 : 0; //0 is ilegal

   parameter               LAST_LINE  = DEPTH-1;
   
   

   input                      clk;
   input                      reset;

   input               push;
   input               pop;
   input [WIDTH-1:0]           din;
   output [WIDTH-1:0]           dout;
   //output               next;
   output               empty;
   output               full;
   

   wire               reg_push;
   wire               reg_pop;
   wire               fifo_push;
   wire               fifo_pop;
   
   reg [DEPTH-1:0]           fullness_in;
   reg [DEPTH-1:0]           fullness_out;
   reg [DEPTH-1:0]           fullness;
   reg [WIDTH-1:0]           fifo [DEPTH-1:0];
   wire               fifo_empty;
   wire               next;
   reg [WIDTH-1:0]           dout;
   reg                   dout_empty;
   reg [DEPTH_BITS-1:0]       ptr_in;
   reg [DEPTH_BITS-1:0]       ptr_out;
   
   


   assign               reg_push  = push & fifo_empty & (dout_empty | pop);
   assign               reg_pop   = pop & fifo_empty;
   assign               fifo_push = !SINGLE & push & (~reg_push);
   assign               fifo_pop  = !SINGLE & pop & (~reg_pop);
   
   
   always @(posedge clk or posedge reset)
     if (reset)
       begin
      dout       <= {WIDTH{1'b0}};
      dout_empty <= 1'b1;
       end
     else if (reg_push)
       begin
      dout       <= din;
      dout_empty <= 1'b0;
       end
     else if (reg_pop)
       begin
      dout       <= {WIDTH{1'b0}};
      dout_empty <= 1'b1;
       end
     else if (fifo_pop)
       begin
      dout       <= fifo[ptr_out];
      dout_empty <= 1'b0;
       end
   
   always @(posedge clk or posedge reset)
     if (reset)
       ptr_in <= {DEPTH_BITS{1'b0}};
     else if (fifo_push)
       ptr_in <= ptr_in == LAST_LINE ? 0 : ptr_in + 1'b1;

   always @(posedge clk or posedge reset)
     if (reset)
       ptr_out <= {DEPTH_BITS{1'b0}};
     else if (fifo_pop)
       ptr_out <= ptr_out == LAST_LINE ? 0 : ptr_out + 1'b1;

   always @(posedge clk)
     if (fifo_push)
       fifo[ptr_in] <= din;

   
   always @(/*AUTOSENSE*/fifo_push or ptr_in)
     begin
    fullness_in = {DEPTH{1'b0}};
    fullness_in[ptr_in] = fifo_push;
     end
   
   always @(/*AUTOSENSE*/fifo_pop or ptr_out)
     begin
    fullness_out = {DEPTH{1'b0}};
    fullness_out[ptr_out] = fifo_pop;
     end
   
   always @(posedge clk or posedge reset)
     if (reset)
       fullness <= {DEPTH{1'b0}};
     else if (fifo_push | fifo_pop)
       fullness <= (fullness & (~fullness_out)) | fullness_in;


   assign next       = |fullness;
   assign fifo_empty = ~next;
   assign empty      = fifo_empty & dout_empty;
   assign full       = SINGLE ? !dout_empty : &fullness;

   
   
   
endmodule




// verilator lint_on WIDTHEXPAND
// verilator lint_on WIDTHTRUNC