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

Subversion Repositories synchronous_reset_fifo

[/] [synchronous_reset_fifo/] [trunk/] [rtl/] [fifo.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 madhu54321
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "fifo.v"                                          ////
4
////                                                              ////
5
////  This file is part of the "synchronous_reset_fifo" project   ////
6
//// http://opencores.com/project,synchronous_reset_fifo          ////
7
////                                                              ////
8
////  Author:                                                     ////
9
////     - Madhumangal Javanthieswaran (madhu54321@opencores.org) ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
/************************************************************************
39
 Design Name : synchronous_reset_fifo
40
 Module Name : fifo.v
41
 Description :
42
 Date        : 19/12/2011
43
 Author      : Madhumangal Javanthieswaran
44
 Email       : j.madhumangal@gmail.com
45
 Company     :
46
 Version     : 1.0
47
 Revision    : 0.0
48
************************************************************************/
49
//Fifo size definitions
50
 
51
//Fifo Module
52
module fifo(clock,write_enb,read_enb,data_in,data_out,empty,full,resetn);
53
 
54
parameter WIDTH = 8;
55
parameter DEPTH = 16;
56
parameter POINTER_SIZE = 5;
57
 
58
//Inputs
59
input clock;
60
input resetn;
61
input write_enb;
62
input read_enb;
63
input [WIDTH-1:0] data_in;
64
 
65
//Outputs
66
output [WIDTH-1:0] data_out;
67
output empty;
68
output full;
69
 
70
//Wires and Internal Registers
71
wire empty;
72
wire full;
73
reg [WIDTH-1:0] memory [0:DEPTH-1];
74
reg [POINTER_SIZE-1:0] write_ptr;
75
reg [POINTER_SIZE-1:0] read_ptr;
76
reg [WIDTH-1:0] data_out;
77
 
78
 
79
//Asynchronous Logic
80
//FIFO full and empty logic
81
 
82
assign empty = ((write_ptr - read_ptr)== 5'b00000) ? 1'b1 : 1'b0;
83
assign full  = ((write_ptr - read_ptr) == 5'b10000) ? 1'b1 : 1'b0;
84
 
85
//Synchronous Logic
86
//FIFO write and read logic 
87
always@(posedge clock)
88
begin
89
        if (resetn == 1'b0)
90
   begin
91
   write_ptr <= 5'b00000;
92
   read_ptr  <= 5'b00000;
93
   data_out <= 8'b00000000;
94
   end
95
 
96
  else
97
//Simultaneous Read and Write
98
   begin
99
   if ((write_enb == 1'b1) &&  (full == 1'b0))
100
    begin
101
    memory[write_ptr] <= data_in;
102
    write_ptr <= write_ptr + 1;
103
    end
104
   end
105
   begin
106
   if ((read_enb == 1'b1) &&  (empty == 1'b0))
107
    begin
108
    data_out <= memory[read_ptr];
109
    read_ptr <= read_ptr + 1;
110
    end
111
   end
112
end
113
endmodule

powered by: WebSVN 2.1.0

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