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

Subversion Repositories robust_axi_fabric

[/] [robust_axi_fabric/] [trunk/] [src/] [gen/] [prgen_fifo.v] - Blame information for rev 12

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

Line No. Rev Author Line
1 7 eyalhoc
<##//////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  Author: Eyal Hochberg                                      ////
4
////          eyal@provartec.com                                 ////
5
////                                                             ////
6
////  Downloaded from: http://www.opencores.org                  ////
7
/////////////////////////////////////////////////////////////////////
8
////                                                             ////
9
//// Copyright (C) 2010 Provartec LTD                            ////
10
//// www.provartec.com                                           ////
11
//// info@provartec.com                                          ////
12
////                                                             ////
13
//// This source file may be used and distributed without        ////
14
//// restriction provided that this copyright statement is not   ////
15
//// removed from the file and that any derivative work contains ////
16
//// the original copyright notice and the associated disclaimer.////
17
////                                                             ////
18
//// This source file is free software; you can redistribute it  ////
19
//// and/or modify it under the terms of the GNU Lesser General  ////
20
//// Public License as published by the Free Software Foundation.////
21
////                                                             ////
22
//// This source is distributed in the hope that it will be      ////
23
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
24
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
25
//// PURPOSE.  See the GNU Lesser General Public License for more////
26
//// details. http://www.gnu.org/licenses/lgpl.html              ////
27
////                                                             ////
28
//////////////////////////////////////////////////////////////////##>
29 2 eyalhoc
 
30
OUTFILE prgen_fifo.v
31
 
32
module prgen_fifo(PORTS);
33
 
34
   parameter                  WIDTH      = 8;
35
   parameter                  DEPTH_FULL = 8;
36
 
37
   parameter                  SINGLE     = DEPTH_FULL == 1;
38
   parameter                  DEPTH      = SINGLE ? 1 : DEPTH_FULL -1;
39
   parameter                  DEPTH_BITS =
40
                              (DEPTH <= 2)   ? 1 :
41
                              (DEPTH <= 4)   ? 2 :
42
                              (DEPTH <= 8)   ? 3 :
43
                              (DEPTH <= 16)  ? 4 :
44
                              (DEPTH <= 32)  ? 5 :
45
                              (DEPTH <= 64)  ? 6 :
46
                              (DEPTH <= 128) ? 7 :
47
                              (DEPTH <= 256) ? 8 : 0; //0 is ilegal
48
 
49
   parameter                  LAST_LINE  = DEPTH-1;
50
 
51
 
52
 
53
   input                      clk;
54
   input                      reset;
55
 
56
   input                      push;
57
   input                      pop;
58
   input [WIDTH-1:0]           din;
59
   output [WIDTH-1:0]          dout;
60
   //output                   next;
61
   output                     empty;
62
   output                     full;
63
 
64
 
65
   wire                       reg_push;
66
   wire                       reg_pop;
67
   wire                       fifo_push;
68
   wire                       fifo_pop;
69
 
70
   reg [DEPTH-1:0]             fullness_in;
71
   reg [DEPTH-1:0]             fullness_out;
72
   reg [DEPTH-1:0]             fullness;
73
   reg [WIDTH-1:0]             fifo [DEPTH-1:0];
74
   wire                       fifo_empty;
75
   wire                       next;
76
   reg [WIDTH-1:0]             dout;
77
   reg                        dout_empty;
78
   reg [DEPTH_BITS-1:0]       ptr_in;
79
   reg [DEPTH_BITS-1:0]       ptr_out;
80
 
81
 
82
 
83
 
84
   assign                     reg_push  = push & fifo_empty & (dout_empty | pop);
85
   assign                     reg_pop   = pop & fifo_empty;
86
   assign                     fifo_push = !SINGLE & push & (~reg_push);
87
   assign                     fifo_pop  = !SINGLE & pop & (~reg_pop);
88
 
89
 
90
   always @(posedge clk or posedge reset)
91
     if (reset)
92
       begin
93
          dout       <= #FFD {WIDTH{1'b0}};
94
          dout_empty <= #FFD 1'b1;
95
       end
96
     else if (reg_push)
97
       begin
98
          dout       <= #FFD din;
99
          dout_empty <= #FFD 1'b0;
100
       end
101
     else if (reg_pop)
102
       begin
103
          dout       <= #FFD {WIDTH{1'b0}};
104
          dout_empty <= #FFD 1'b1;
105
       end
106
     else if (fifo_pop)
107
       begin
108
          dout       <= #FFD fifo[ptr_out];
109
          dout_empty <= #FFD 1'b0;
110
       end
111
 
112
   always @(posedge clk or posedge reset)
113
     if (reset)
114
       ptr_in <= #FFD {DEPTH_BITS{1'b0}};
115
     else if (fifo_push)
116
       ptr_in <= #FFD ptr_in == LAST_LINE ? 0 : ptr_in + 1'b1;
117
 
118
   always @(posedge clk or posedge reset)
119
     if (reset)
120
       ptr_out <= #FFD {DEPTH_BITS{1'b0}};
121
     else if (fifo_pop)
122
       ptr_out <= #FFD ptr_out == LAST_LINE ? 0 : ptr_out + 1'b1;
123
 
124
   always @(posedge clk)
125
     if (fifo_push)
126
       fifo[ptr_in] <= #FFD din;
127
 
128
 
129
   always @(/*AUTOSENSE*/fifo_push or ptr_in)
130
     begin
131
        fullness_in = {DEPTH{1'b0}};
132
        fullness_in[ptr_in] = fifo_push;
133
     end
134
 
135
   always @(/*AUTOSENSE*/fifo_pop or ptr_out)
136
     begin
137
        fullness_out = {DEPTH{1'b0}};
138
        fullness_out[ptr_out] = fifo_pop;
139
     end
140
 
141
   always @(posedge clk or posedge reset)
142
     if (reset)
143
       fullness <= #FFD {DEPTH{1'b0}};
144
     else if (fifo_push | fifo_pop)
145
       fullness <= #FFD (fullness & (~fullness_out)) | fullness_in;
146
 
147
 
148
   assign next       = |fullness;
149
   assign fifo_empty = ~next;
150
   assign empty      = fifo_empty & dout_empty;
151
   assign full       = SINGLE ? !dout_empty : &fullness;
152
 
153
endmodule
154
 
155
 

powered by: WebSVN 2.1.0

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