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

Subversion Repositories usb_device_core

[/] [usb_device_core/] [trunk/] [src_v/] [usbf_fifo.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 ultra_embe
//-----------------------------------------------------------------
2
//                       USB Device Core
3
//                           V1.0
4
//                     Ultra-Embedded.com
5
//                     Copyright 2014-2019
6
//
7
//                 Email: admin@ultra-embedded.com
8
//
9
//                         License: GPL
10
// If you would like a version with a more permissive license for
11
// use in closed source commercial applications please contact me
12
// for details.
13
//-----------------------------------------------------------------
14
//
15
// This file is open source HDL; you can redistribute it and/or 
16
// modify it under the terms of the GNU General Public License as 
17
// published by the Free Software Foundation; either version 2 of 
18
// the License, or (at your option) any later version.
19
//
20
// This file is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied warranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
// GNU General Public License for more details.
24
//
25
// You should have received a copy of the GNU General Public 
26
// License along with this file; if not, write to the Free Software
27
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28
// USA
29
//-----------------------------------------------------------------
30
 
31
//-----------------------------------------------------------------
32
//                          Generated File
33
//-----------------------------------------------------------------
34
 
35
module usbf_fifo
36
(
37
    // Inputs
38
     input           clk_i
39
    ,input           rst_i
40
    ,input  [  7:0]  data_i
41
    ,input           push_i
42
    ,input           pop_i
43
    ,input           flush_i
44
 
45
    // Outputs
46
    ,output          full_o
47
    ,output          empty_o
48
    ,output [  7:0]  data_o
49
);
50
 
51
 
52
 
53
parameter WIDTH   = 8;
54
parameter DEPTH   = 4;
55
parameter ADDR_W  = 2;
56
 
57
//-----------------------------------------------------------------
58
// Local Params
59
//-----------------------------------------------------------------
60
localparam COUNT_W = ADDR_W + 1;
61
 
62
//-----------------------------------------------------------------
63
// Registers
64
//-----------------------------------------------------------------
65
reg [WIDTH-1:0]         ram [DEPTH-1:0];
66
reg [ADDR_W-1:0]        rd_ptr;
67
reg [ADDR_W-1:0]        wr_ptr;
68
reg [COUNT_W-1:0]       count;
69
 
70
//-----------------------------------------------------------------
71
// Sequential
72
//-----------------------------------------------------------------
73
always @ (posedge clk_i or posedge rst_i)
74
if (rst_i)
75
begin
76
    count   <= {(COUNT_W) {1'b0}};
77
    rd_ptr  <= {(ADDR_W) {1'b0}};
78
    wr_ptr  <= {(ADDR_W) {1'b0}};
79
end
80
else
81
begin
82
 
83
    if (flush_i)
84
    begin
85
        count   <= {(COUNT_W) {1'b0}};
86
        rd_ptr  <= {(ADDR_W) {1'b0}};
87
        wr_ptr  <= {(ADDR_W) {1'b0}};
88
    end
89
 
90
    // Push
91
    if (push_i & ~full_o)
92
    begin
93
        ram[wr_ptr] <= data_i;
94
        wr_ptr      <= wr_ptr + 1;
95
    end
96
 
97
    // Pop
98
    if (pop_i & ~empty_o)
99
    begin
100
        rd_ptr      <= rd_ptr + 1;
101
    end
102
 
103
    // Count up
104
    if ((push_i & ~full_o) & ~(pop_i & ~empty_o))
105
    begin
106
        count <= count + 1;
107
    end
108
    // Count down
109
    else if (~(push_i & ~full_o) & (pop_i & ~empty_o))
110
    begin
111
        count <= count - 1;
112
    end
113
end
114
 
115
//-------------------------------------------------------------------
116
// Combinatorial
117
//-------------------------------------------------------------------
118
/* verilator lint_off WIDTH */
119
assign full_o    = (count == DEPTH);
120
assign empty_o   = (count == 0);
121
/* verilator lint_on WIDTH */
122
 
123
assign data_o    = ram[rd_ptr];
124
 
125
 
126
endmodule

powered by: WebSVN 2.1.0

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