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

Subversion Repositories boundaries

[/] [boundaries/] [tags/] [TAG000/] [rtl/] [verilog/] [oc_fifo_basic.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 esquehill
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// oc_fifo_basic.v                                              ////
4
////                                                              ////
5
//// This file is part of the boundaries opencores effort.        ////
6
//// <http://www.opencores.org/cores/boundaries/>                 ////
7
////                                                              ////
8
//// Module Description:                                          ////
9
////                                                              ////
10
//// One Clock FIFO                                               ////
11
////                                                              ////
12
//// 2 Parameters: Address Width, Data Width                      ////
13
////   Data storage is internally inferred.                       ////
14
////   Protected against read-while-empty and write-while-full.   ////
15
////   When empty, force data output to zero.                     ////
16
////                                                              ////
17
////   The minimum address width (AW) is 2.                       ////
18
////                                                              ////
19
//// To Do:                                                       ////
20
////   Verify in silicon.                                         ////
21
////                                                              ////
22
//// Author(s):                                                   ////
23
//// - Shannon Hill                                               ////
24
////                                                              ////
25
//////////////////////////////////////////////////////////////////////
26
////                                                              ////
27
//// Copyright (C) 2004 Shannon Hill and OPENCORES.ORG            ////
28
////                                                              ////
29
//// This source file may be used and distributed without         ////
30
//// restriction provided that this copyright statement is not    ////
31
//// removed from the file and that any derivative work contains  ////
32
//// the original copyright notice and the associated disclaimer. ////
33
////                                                              ////
34
//// This source file is free software; you can redistribute it   ////
35
//// and/or modify it under the terms of the GNU Lesser General   ////
36
//// Public License as published by the Free Software Foundation; ////
37
//// either version 2.1 of the License, or (at your option) any   ////
38
//// later version.                                               ////
39
////                                                              ////
40
//// This source is distributed in the hope that it will be       ////
41
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
42
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
43
//// PURPOSE. See the GNU Lesser General Public License for more  ////
44
//// details.                                                     ////
45
////                                                              ////
46
//// You should have received a copy of the GNU Lesser General    ////
47
//// Public License along with this source; if not, download it   ////
48
//// from <http://www.opencores.org/lgpl.shtml>                   ////
49
////                                                              ////
50
//////////////////////////////////////////////////////////////////////
51
//
52
// $Id: oc_fifo_basic.v,v 1.1 2004-07-07 12:41:17 esquehill Exp $
53
//
54
// CVS Revision History
55
//
56
// $Log: not supported by cvs2svn $
57
//
58
//
59
module oc_fifo_basic( /*AUTOARG*/
60
// Outputs
61
have, take_do, need,
62
// Inputs
63
rst_i, clk_i, take, give, give_di
64
);
65
 
66
parameter AW=3;    // default address width
67
parameter DW=8;    // default data width
68
 
69
input            rst_i;
70
input            clk_i;
71
 
72
output           have;
73
input            take;
74
output [DW-1:0]  take_do;
75
 
76
output           need;
77
input            give;
78
input  [DW-1:0]  give_di;
79
 
80
reg  [AW  :0]    rp;
81
reg  [AW  :0]    wp;
82
wire [AW  :0]    rp_add1 = rp + 1'b1;
83
wire [AW  :0]    wp_add1 = wp + 1'b1;
84
 
85
reg              full;
86
reg              emty;
87
 
88
wire             have = ~emty;
89
wire             need = ~full;
90
 
91
reg  [DW-1:0]    mem [0:(1<<AW)-1];
92
 
93
wire [DW-1:0]    take_do = {DW{have}} & mem[ rp[AW-1:0] ]; // take data
94
 
95
always @( posedge clk_i )
96
        if( give & ~full ) mem[ wp[AW-1:0] ] <= give_di;   // give data
97
 
98
always @( posedge clk_i or posedge rst_i )
99
if( rst_i )
100
begin
101
      wp    <= {AW+1{1'b0}};
102
      rp    <= {AW+1{1'b0}};
103
      emty  <= 1'b1;
104
      full  <= 1'b0;
105
end
106
else
107
begin
108
     if( give & ~full ) wp <= wp_add1; // increment write pointer
109
     if( take & ~emty ) rp <= rp_add1; // increment read  pointer
110
 
111
     casex( { give,take, full,emty } )
112
 
113
     // write an entry; no longer empty; might go full
114
 
115
     4'b10_0X: begin  // is give, no take, no full
116
               full  <= ( wp_add1[AW-1:0] == rp[AW-1:0] ) & ( wp_add1[AW] != rp[AW] );
117
               emty  <= 1'b0;
118
               end
119
 
120
     // read  an entry; no longer full ; might go empty
121
 
122
     4'b01_X0: begin  // is take, no give, no emty
123
               full  <= 1'b0;
124
               emty  <= ( rp_add1 == wp );
125
               end
126
 
127
     // take & give while full ; take wins, give loses; no longer full...
128
 
129
     4'b11_10: full  <= 1'b0; // is take, is give, is full, no emty
130
 
131
     // take & give while empty; give wins, take loses; no longer empty...
132
 
133
     4'b11_01: emty  <= 1'b0; // is take, is give, no full, is emty
134
 
135
     default: ;
136
 
137
     endcase
138
 
139
end
140
endmodule

powered by: WebSVN 2.1.0

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