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

Subversion Repositories apbi2c

[/] [apbi2c/] [trunk/] [rtl/] [fifo.v] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    FIFO BLOCK to I2C Core
5
////
6
////
7
////
8
//// This file is part of the APB to I2C project
9
////
10
//// http://www.opencores.org/cores/apbi2c/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// apbi2c_spec IP core specification document.
19
////
20
////
21
////
22
//// To Do: This block inst functional yet when you try only write half registers and it didnt go correctly FULL and EMPTY
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
29 18 redbear
////              Ronal Dario Celaya ,rcelaya.dario@gmail.com
30 2 redbear
////
31
///////////////////////////////////////////////////////////////// 
32
////
33
////
34
//// Copyright (C) 2009 Authors and OPENCORES.ORG
35
////
36
////
37
////
38
//// This source file may be used and distributed without
39
////
40
//// restriction provided that this copyright statement is not
41
////
42
//// removed from the file and that any derivative work contains
43
//// the original copyright notice and the associated disclaimer.
44
////
45
////
46
//// This source file is free software; you can redistribute it
47
////
48
//// and/or modify it under the terms of the GNU Lesser General
49
////
50
//// Public License as published by the Free Software Foundation;
51
//// either version 2.1 of the License, or (at your option) any
52
////
53
//// later version.
54
////
55
////
56
////
57
//// This source is distributed in the hope that it will be
58
////
59
//// useful, but WITHOUT ANY WARRANTY; without even the implied
60
////
61
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
62
////
63
//// PURPOSE. See the GNU Lesser General Public License for more
64
//// details.
65
////
66
////
67
////
68
//// You should have received a copy of the GNU Lesser General
69
////
70
//// Public License along with this source; if not, download it
71
////
72
//// from http://www.opencores.org/lgpl.shtml
73
////
74
////
75
///////////////////////////////////////////////////////////////////
76 16 celaya.dar
`timescale 1ns/1ps
77 2 redbear
module fifo
78
#(
79
        parameter integer DWIDTH = 32,
80
        parameter integer AWIDTH = 4
81
)
82
 
83
(
84
        input clock, reset, wr_en, rd_en,
85
        input [DWIDTH-1:0] data_in,
86
        output f_full, f_empty,
87
        output [DWIDTH-1:0] data_out
88
);
89
 
90
 
91 16 celaya.dar
//      reg [DWIDTH-1:0] mem [0:2**AWIDTH-1];
92
        parameter integer DEPTH = 1 << AWIDTH;
93
        wire [DWIDTH-1:0] data_ram_out;
94
        wire wr_en_ram;
95
        wire rd_en_ram;
96 2 redbear
 
97
        reg [AWIDTH-1:0] wr_ptr;
98
        reg [AWIDTH-1:0] rd_ptr;
99 16 celaya.dar
        reg [AWIDTH:0] counter;
100 2 redbear
 
101
 
102 16 celaya.dar
//Write pointer
103 13 redbear
        always@(posedge clock)
104
        begin
105 16 celaya.dar
                if (reset)
106
                begin
107
                        wr_ptr <= {(AWIDTH){1'b0}};
108
                end
109
                else if (wr_en && !f_full)
110
                begin
111
                        wr_ptr <= wr_ptr + 1'b1;
112
                end
113
        end
114 13 redbear
 
115 16 celaya.dar
//Read pointer
116
        always@(posedge clock)
117
        begin
118 2 redbear
                if (reset)
119
                begin
120 16 celaya.dar
                        rd_ptr <= {(AWIDTH){1'b0}};
121
                end
122
                else if (rd_en && !f_empty)
123
                begin
124
                        rd_ptr <= rd_ptr + 1'b1;
125
                end
126
        end
127 13 redbear
 
128 16 celaya.dar
//Counter
129
        always@(posedge clock)
130
        begin
131
                if (reset)
132
                begin
133
                        counter <= {(AWIDTH+1){1'b0}};
134 2 redbear
                end
135
                else
136
                begin
137 16 celaya.dar
                        if (rd_en && !f_empty && !wr_en)
138 2 redbear
                        begin
139 16 celaya.dar
                                counter <= counter - 1'b1;
140 2 redbear
                        end
141 16 celaya.dar
                        else if (wr_en && !f_full && !rd_en)
142 2 redbear
                        begin
143 16 celaya.dar
                                counter <= counter + 1'b1;
144
                        end
145 2 redbear
                end
146 13 redbear
        end
147 2 redbear
 
148 18 redbear
        assign f_full = (counter == DEPTH- 1) ;
149
        assign f_empty = (counter == {AWIDTH{1'b0}});
150 16 celaya.dar
        assign wr_en_ram = wr_en;
151
        assign rd_en_ram = rd_en;
152
        assign data_out = data_ram_out;
153 13 redbear
 
154 16 celaya.dar
dp_ram #(DWIDTH, AWIDTH)
155
RAM_1   (
156
                .clock(clock),
157
                .reset(reset),
158
                .wr_en(wr_en_ram),
159
                .rd_en(rd_en_ram),
160
                .data_in(data_in),
161
                .wr_addr(wr_ptr),
162
                .data_out(data_ram_out),
163
                .rd_addr(rd_ptr)
164
        );
165 2 redbear
 
166
endmodule

powered by: WebSVN 2.1.0

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