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 5

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

powered by: WebSVN 2.1.0

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