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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [tags/] [rel_00_01_alpha/] [RTL/] [buffers/] [fifoRTL.v] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sfielding
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// fifoRTL.v                                                    ////
4
////                                                              ////
5
//// This file is part of the usbhostslave opencores effort.
6
//// <http://www.opencores.org/cores//>                           ////
7
////                                                              ////
8
//// Module Description:                                          ////
9
////  parameterized fifo. fifo depth is restricted to 2^ADDR_WIDTH
10
////  No protection against over runs and under runs.
11
////  User must check full and empty flags before accessing fifo
12
//// 
13
////                                                              ////
14
//// To Do:                                                       ////
15
//// 
16
////                                                              ////
17
//// Author(s):                                                   ////
18
//// - Steve Fielding, sfielding@base2designs.com                 ////
19
////                                                              ////
20
//////////////////////////////////////////////////////////////////////
21
////                                                              ////
22
//// Copyright (C) 2004 Steve Fielding and OPENCORES.ORG          ////
23
////                                                              ////
24
//// This source file may be used and distributed without         ////
25
//// restriction provided that this copyright statement is not    ////
26
//// removed from the file and that any derivative work contains  ////
27
//// the original copyright notice and the associated disclaimer. ////
28
////                                                              ////
29
//// This source file is free software; you can redistribute it   ////
30
//// and/or modify it under the terms of the GNU Lesser General   ////
31
//// Public License as published by the Free Software Foundation; ////
32
//// either version 2.1 of the License, or (at your option) any   ////
33
//// later version.                                               ////
34
////                                                              ////
35
//// This source is distributed in the hope that it will be       ////
36
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
37
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
38
//// PURPOSE. See the GNU Lesser General Public License for more  ////
39
//// details.                                                     ////
40
////                                                              ////
41
//// You should have received a copy of the GNU Lesser General    ////
42
//// Public License along with this source; if not, download it   ////
43
//// from <http://www.opencores.org/lgpl.shtml>                   ////
44
////                                                              ////
45
//////////////////////////////////////////////////////////////////////
46
//
47
// $Id: fifoRTL.v,v 1.1.1.1 2004-10-11 04:00:51 sfielding Exp $
48
//
49
// CVS Revision History
50
//
51
// $Log: not supported by cvs2svn $
52
//
53
 
54
`timescale 1ns / 1ps
55
 
56
module fifoRTL(clk, rst, dataIn, dataOut, fifoWEn, fifoREn, fifoFull, fifoEmpty, forceEmpty, numElementsInFifo);
57
//FIFO_DEPTH = ADDR_WIDTH^2. Min = 2, Max = 66536
58
  parameter FIFO_WIDTH = 8;
59
        parameter FIFO_DEPTH = 64;
60
  parameter ADDR_WIDTH = 6;
61
 
62
input clk;
63
input rst;
64
input [FIFO_WIDTH-1:0] dataIn;
65
output [FIFO_WIDTH-1:0] dataOut;
66
input fifoWEn;
67
input fifoREn;
68
output fifoFull;
69
output fifoEmpty;
70
input forceEmpty;
71
output [15:0]numElementsInFifo; //note that this implies a max fifo depth of 65536
72
 
73
wire clk;
74
wire rst;
75
wire [FIFO_WIDTH-1:0] dataIn;
76
reg [FIFO_WIDTH-1:0] dataOut;
77
wire fifoWEn;
78
wire fifoREn;
79
reg fifoFull;
80
reg fifoEmpty;
81
wire forceEmpty;
82
reg  [15:0]numElementsInFifo;
83
 
84
 
85
// local registers
86
reg  [ADDR_WIDTH-1:0]bufferInIndex;
87
reg  [ADDR_WIDTH-1:0]bufferOutIndex;
88
reg  [ADDR_WIDTH:0]bufferCnt;
89
reg  fifoREnDelayed;
90
wire [FIFO_WIDTH-1:0] dataFromMem;
91
 
92
always @(posedge clk)
93
begin
94
  if (rst == 1'b1 || forceEmpty == 1'b1)
95
  begin
96
    bufferCnt <= 0;
97
    fifoFull <= 1'b0;
98
    fifoEmpty <= 1'b1;
99
                bufferInIndex <= 0;
100
                bufferOutIndex <= 0;
101
    fifoREnDelayed <= 1'b0;
102
        end
103
    else
104
    begin
105
      if (fifoREn == 1'b1 && fifoREnDelayed == 1'b0) begin
106
        dataOut <= dataFromMem;
107
      end
108
      fifoREnDelayed <= fifoREn;
109
      if (fifoWEn == 1'b1 && fifoREn == 1'b0) begin
110
        bufferCnt <= bufferCnt + 1;
111
        bufferInIndex <= bufferInIndex + 1;
112
      end
113
      else if (fifoWEn == 1'b0 && fifoREn == 1'b1 && fifoREnDelayed == 1'b0) begin
114
        bufferCnt <= bufferCnt - 1;
115
        bufferOutIndex <= bufferOutIndex + 1;
116
      end
117
      else if (fifoWEn == 1'b1 && fifoREn == 1'b1 && fifoREnDelayed == 1'b0) begin
118
        bufferOutIndex <= bufferOutIndex + 1;
119
        bufferInIndex <= bufferInIndex + 1;
120
      end
121
      if (bufferCnt[ADDR_WIDTH] == 1'b1)
122
        fifoFull <= 1'b1;
123
      else
124
        fifoFull <= 1'b0;
125
      if (|bufferCnt == 1'b0)
126
        fifoEmpty <= 1'b1;
127
      else
128
        fifoEmpty <= 1'b0;
129
    end
130
end
131
 
132
//pad bufferCnt with leading zeroes
133
always @(bufferCnt) begin
134
  numElementsInFifo <= { {16-ADDR_WIDTH+1{1'b0}}, bufferCnt };
135
end
136
 
137
fifoMem #(FIFO_WIDTH, FIFO_DEPTH, ADDR_WIDTH)  u_fifoMem (
138
        .addrIn(bufferInIndex),
139
        .addrOut(bufferOutIndex),
140
        .clk(clk),
141
        .dataIn(dataIn),
142
        .writeEn(fifoWEn),
143
        .readEn(fifoREn),
144
        .dataOut(dataFromMem));
145
 
146
endmodule

powered by: WebSVN 2.1.0

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