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 2

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

Line No. Rev Author Line
1 2 eyalhoc
 
2
OUTFILE prgen_fifo.v
3
 
4
module prgen_fifo(PORTS);
5
 
6
   parameter                  WIDTH      = 8;
7
   parameter                  DEPTH_FULL = 8;
8
 
9
   parameter                  SINGLE     = DEPTH_FULL == 1;
10
   parameter                  DEPTH      = SINGLE ? 1 : DEPTH_FULL -1;
11
   parameter                  DEPTH_BITS =
12
                              (DEPTH <= 2)   ? 1 :
13
                              (DEPTH <= 4)   ? 2 :
14
                              (DEPTH <= 8)   ? 3 :
15
                              (DEPTH <= 16)  ? 4 :
16
                              (DEPTH <= 32)  ? 5 :
17
                              (DEPTH <= 64)  ? 6 :
18
                              (DEPTH <= 128) ? 7 :
19
                              (DEPTH <= 256) ? 8 : 0; //0 is ilegal
20
 
21
   parameter                  LAST_LINE  = DEPTH-1;
22
 
23
 
24
 
25
   input                      clk;
26
   input                      reset;
27
 
28
   input                      push;
29
   input                      pop;
30
   input [WIDTH-1:0]           din;
31
   output [WIDTH-1:0]          dout;
32
   //output                   next;
33
   output                     empty;
34
   output                     full;
35
 
36
 
37
   wire                       reg_push;
38
   wire                       reg_pop;
39
   wire                       fifo_push;
40
   wire                       fifo_pop;
41
 
42
   reg [DEPTH-1:0]             fullness_in;
43
   reg [DEPTH-1:0]             fullness_out;
44
   reg [DEPTH-1:0]             fullness;
45
   reg [WIDTH-1:0]             fifo [DEPTH-1:0];
46
   wire                       fifo_empty;
47
   wire                       next;
48
   reg [WIDTH-1:0]             dout;
49
   reg                        dout_empty;
50
   reg [DEPTH_BITS-1:0]       ptr_in;
51
   reg [DEPTH_BITS-1:0]       ptr_out;
52
 
53
 
54
 
55
 
56
   assign                     reg_push  = push & fifo_empty & (dout_empty | pop);
57
   assign                     reg_pop   = pop & fifo_empty;
58
   assign                     fifo_push = !SINGLE & push & (~reg_push);
59
   assign                     fifo_pop  = !SINGLE & pop & (~reg_pop);
60
 
61
 
62
   always @(posedge clk or posedge reset)
63
     if (reset)
64
       begin
65
          dout       <= #FFD {WIDTH{1'b0}};
66
          dout_empty <= #FFD 1'b1;
67
       end
68
     else if (reg_push)
69
       begin
70
          dout       <= #FFD din;
71
          dout_empty <= #FFD 1'b0;
72
       end
73
     else if (reg_pop)
74
       begin
75
          dout       <= #FFD {WIDTH{1'b0}};
76
          dout_empty <= #FFD 1'b1;
77
       end
78
     else if (fifo_pop)
79
       begin
80
          dout       <= #FFD fifo[ptr_out];
81
          dout_empty <= #FFD 1'b0;
82
       end
83
 
84
   always @(posedge clk or posedge reset)
85
     if (reset)
86
       ptr_in <= #FFD {DEPTH_BITS{1'b0}};
87
     else if (fifo_push)
88
       ptr_in <= #FFD ptr_in == LAST_LINE ? 0 : ptr_in + 1'b1;
89
 
90
   always @(posedge clk or posedge reset)
91
     if (reset)
92
       ptr_out <= #FFD {DEPTH_BITS{1'b0}};
93
     else if (fifo_pop)
94
       ptr_out <= #FFD ptr_out == LAST_LINE ? 0 : ptr_out + 1'b1;
95
 
96
   always @(posedge clk)
97
     if (fifo_push)
98
       fifo[ptr_in] <= #FFD din;
99
 
100
 
101
   always @(/*AUTOSENSE*/fifo_push or ptr_in)
102
     begin
103
        fullness_in = {DEPTH{1'b0}};
104
        fullness_in[ptr_in] = fifo_push;
105
     end
106
 
107
   always @(/*AUTOSENSE*/fifo_pop or ptr_out)
108
     begin
109
        fullness_out = {DEPTH{1'b0}};
110
        fullness_out[ptr_out] = fifo_pop;
111
     end
112
 
113
   always @(posedge clk or posedge reset)
114
     if (reset)
115
       fullness <= #FFD {DEPTH{1'b0}};
116
     else if (fifo_push | fifo_pop)
117
       fullness <= #FFD (fullness & (~fullness_out)) | fullness_in;
118
 
119
 
120
   assign next       = |fullness;
121
   assign fifo_empty = ~next;
122
   assign empty      = fifo_empty & dout_empty;
123
   assign full       = SINGLE ? !dout_empty : &fullness;
124
 
125
endmodule
126
 
127
 

powered by: WebSVN 2.1.0

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