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

Subversion Repositories usbhostslave

[/] [usbhostslave/] [tags/] [rel_00_07_alpha/] [RTL/] [buffers/] [fifoRTL.v] - Blame information for rev 15

Go to most recent revision | 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
`timescale 1ns / 1ps
48
 
49
module fifoRTL(clk, rst, dataIn, dataOut, fifoWEn, fifoREn, fifoFull, fifoEmpty, forceEmpty, numElementsInFifo);
50
//FIFO_DEPTH = ADDR_WIDTH^2. Min = 2, Max = 66536
51
  parameter FIFO_WIDTH = 8;
52 5 sfielding
  parameter FIFO_DEPTH = 64;
53 2 sfielding
  parameter ADDR_WIDTH = 6;
54
 
55
input clk;
56
input rst;
57
input [FIFO_WIDTH-1:0] dataIn;
58
output [FIFO_WIDTH-1:0] dataOut;
59
input fifoWEn;
60
input fifoREn;
61
output fifoFull;
62
output fifoEmpty;
63
input forceEmpty;
64
output [15:0]numElementsInFifo; //note that this implies a max fifo depth of 65536
65
 
66
wire clk;
67
wire rst;
68
wire [FIFO_WIDTH-1:0] dataIn;
69
reg [FIFO_WIDTH-1:0] dataOut;
70
wire fifoWEn;
71
wire fifoREn;
72
reg fifoFull;
73
reg fifoEmpty;
74
wire forceEmpty;
75
reg  [15:0]numElementsInFifo;
76
 
77
 
78
// local registers
79
reg  [ADDR_WIDTH-1:0]bufferInIndex;
80
reg  [ADDR_WIDTH-1:0]bufferOutIndex;
81
reg  [ADDR_WIDTH:0]bufferCnt;
82
reg  fifoREnDelayed;
83
wire [FIFO_WIDTH-1:0] dataFromMem;
84
 
85
always @(posedge clk)
86
begin
87
  if (rst == 1'b1 || forceEmpty == 1'b1)
88
  begin
89
    bufferCnt <= 0;
90
    fifoFull <= 1'b0;
91
    fifoEmpty <= 1'b1;
92 5 sfielding
    bufferInIndex <= 0;
93
    bufferOutIndex <= 0;
94 2 sfielding
    fifoREnDelayed <= 1'b0;
95 5 sfielding
  end
96 2 sfielding
    else
97
    begin
98
      if (fifoREn == 1'b1 && fifoREnDelayed == 1'b0) begin
99
        dataOut <= dataFromMem;
100
      end
101
      fifoREnDelayed <= fifoREn;
102
      if (fifoWEn == 1'b1 && fifoREn == 1'b0) begin
103
        bufferCnt <= bufferCnt + 1;
104
        bufferInIndex <= bufferInIndex + 1;
105
      end
106
      else if (fifoWEn == 1'b0 && fifoREn == 1'b1 && fifoREnDelayed == 1'b0) begin
107
        bufferCnt <= bufferCnt - 1;
108
        bufferOutIndex <= bufferOutIndex + 1;
109
      end
110
      else if (fifoWEn == 1'b1 && fifoREn == 1'b1 && fifoREnDelayed == 1'b0) begin
111
        bufferOutIndex <= bufferOutIndex + 1;
112
        bufferInIndex <= bufferInIndex + 1;
113
      end
114
      if (bufferCnt[ADDR_WIDTH] == 1'b1)
115
        fifoFull <= 1'b1;
116
      else
117
        fifoFull <= 1'b0;
118
      if (|bufferCnt == 1'b0)
119
        fifoEmpty <= 1'b1;
120
      else
121
        fifoEmpty <= 1'b0;
122
    end
123
end
124
 
125
//pad bufferCnt with leading zeroes
126
always @(bufferCnt) begin
127
  numElementsInFifo <= { {16-ADDR_WIDTH+1{1'b0}}, bufferCnt };
128
end
129
 
130
fifoMem #(FIFO_WIDTH, FIFO_DEPTH, ADDR_WIDTH)  u_fifoMem (
131 5 sfielding
  .addrIn(bufferInIndex),
132
  .addrOut(bufferOutIndex),
133
  .clk(clk),
134
  .dataIn(dataIn),
135
  .writeEn(fifoWEn),
136
  .readEn(fifoREn),
137
  .dataOut(dataFromMem));
138 2 sfielding
 
139
endmodule

powered by: WebSVN 2.1.0

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