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

Subversion Repositories robust_axi2apb

[/] [robust_axi2apb/] [trunk/] [src/] [gen/] [prgen_fifo.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 4 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
ITER DX 1 15
33
module prgen_fifo(PORTS);
34
 
35
   parameter                  WIDTH      = 8;
36
   parameter                  DEPTH_FULL = 8;
37
 
38
   parameter                  SINGLE     = DEPTH_FULL == 1;
39
   parameter                  DEPTH      = SINGLE ? 1 : DEPTH_FULL -1;
40
   parameter                  DEPTH_BITS =
41
                              (DEPTH <= EXPR(2^DX)) ? DX :
42
                              0; //0 is ilegal
43
 
44
   parameter                  LAST_LINE  = DEPTH-1;
45
 
46
 
47
 
48
   input                      clk;
49
   input                      reset;
50
 
51
   input                      push;
52
   input                      pop;
53
   input [WIDTH-1:0]           din;
54
   output [WIDTH-1:0]          dout;
55
   output                     empty;
56
   output                     full;
57
 
58
 
59
   wire                       reg_push;
60
   wire                       reg_pop;
61
   wire                       fifo_push;
62
   wire                       fifo_pop;
63
 
64
   reg [DEPTH-1:0]             fullness_in;
65
   reg [DEPTH-1:0]             fullness_out;
66
   reg [DEPTH-1:0]             fullness;
67
   reg [WIDTH-1:0]             fifo [DEPTH-1:0];
68
   wire                       fifo_empty;
69
   wire                       next;
70
   reg [WIDTH-1:0]             dout;
71
   reg                        dout_empty;
72
   reg [DEPTH_BITS-1:0]       ptr_in;
73
   reg [DEPTH_BITS-1:0]       ptr_out;
74
 
75
 
76
 
77
 
78
   assign                     reg_push  = push & fifo_empty & (dout_empty | pop);
79
   assign                     reg_pop   = pop & fifo_empty;
80
   assign                     fifo_push = !SINGLE & push & (~reg_push);
81
   assign                     fifo_pop  = !SINGLE & pop & (~reg_pop);
82
 
83
 
84
   always @(posedge clk or posedge reset)
85
     if (reset)
86
       begin
87
          dout       <= #FFD {WIDTH{1'b0}};
88
          dout_empty <= #FFD 1'b1;
89
       end
90
     else if (reg_push)
91
       begin
92
          dout       <= #FFD din;
93
          dout_empty <= #FFD 1'b0;
94
       end
95
     else if (reg_pop)
96
       begin
97
          dout       <= #FFD {WIDTH{1'b0}};
98
          dout_empty <= #FFD 1'b1;
99
       end
100
     else if (fifo_pop)
101
       begin
102
          dout       <= #FFD fifo[ptr_out];
103
          dout_empty <= #FFD 1'b0;
104
       end
105
 
106
   always @(posedge clk or posedge reset)
107
     if (reset)
108
       ptr_in <= #FFD {DEPTH_BITS{1'b0}};
109
     else if (fifo_push)
110
       ptr_in <= #FFD ptr_in == LAST_LINE ? 0 : ptr_in + 1'b1;
111
 
112
   always @(posedge clk or posedge reset)
113
     if (reset)
114
       ptr_out <= #FFD {DEPTH_BITS{1'b0}};
115
     else if (fifo_pop)
116
       ptr_out <= #FFD ptr_out == LAST_LINE ? 0 : ptr_out + 1'b1;
117
 
118
   always @(posedge clk)
119
     if (fifo_push)
120
       fifo[ptr_in] <= #FFD din;
121
 
122
 
123
   always @(*)
124
     begin
125
        fullness_in = {DEPTH{1'b0}};
126
        fullness_in[ptr_in] = fifo_push;
127
     end
128
 
129
   always @(*)
130
     begin
131
        fullness_out = {DEPTH{1'b0}};
132
        fullness_out[ptr_out] = fifo_pop;
133
     end
134
 
135
   always @(posedge clk or posedge reset)
136
     if (reset)
137
       fullness <= #FFD {DEPTH{1'b0}};
138
     else if (fifo_push | fifo_pop)
139
       fullness <= #FFD (fullness & (~fullness_out)) | fullness_in;
140
 
141
 
142
   assign next       = |fullness;
143
   assign fifo_empty = ~next;
144
   assign empty      = fifo_empty & dout_empty;
145
   assign full       = SINGLE ? !dout_empty : &fullness;
146
 
147
endmodule
148
 
149
 

powered by: WebSVN 2.1.0

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