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

Subversion Repositories apbi2c

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

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
////
30
///////////////////////////////////////////////////////////////// 
31
////
32
////
33
//// Copyright (C) 2009 Authors and OPENCORES.ORG
34
////
35
////
36
////
37
//// This source file may be used and distributed without
38
////
39
//// restriction provided that this copyright statement is not
40
////
41
//// removed from the file and that any derivative work contains
42
//// the original copyright notice and the associated disclaimer.
43
////
44
////
45
//// This source file is free software; you can redistribute it
46
////
47
//// and/or modify it under the terms of the GNU Lesser General
48
////
49
//// Public License as published by the Free Software Foundation;
50
//// either version 2.1 of the License, or (at your option) any
51
////
52
//// later version.
53
////
54
////
55
////
56
//// This source is distributed in the hope that it will be
57
////
58
//// useful, but WITHOUT ANY WARRANTY; without even the implied
59
////
60
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
61
////
62
//// PURPOSE. See the GNU Lesser General Public License for more
63
//// details.
64
////
65
////
66
////
67
//// You should have received a copy of the GNU Lesser General
68
////
69
//// Public License along with this source; if not, download it
70
////
71
//// from http://www.opencores.org/lgpl.shtml
72
////
73
////
74
///////////////////////////////////////////////////////////////////
75 16 celaya.dar
`timescale 1ns/1ps
76 2 redbear
module fifo
77
#(
78
        parameter integer DWIDTH = 32,
79
        parameter integer AWIDTH = 4
80
)
81
 
82
(
83
        input clock, reset, wr_en, rd_en,
84
        input [DWIDTH-1:0] data_in,
85
        output f_full, f_empty,
86
        output [DWIDTH-1:0] data_out
87
);
88
 
89
 
90 24 redbear
        reg [DWIDTH-1:0] mem [0:2**AWIDTH-1];
91
        //parameter integer DEPTH = 1 << AWIDTH;
92
        //wire [DWIDTH-1:0] data_ram_out;
93
        //wire wr_en_ram; 
94
        //wire rd_en_ram;       
95 2 redbear
 
96
        reg [AWIDTH-1:0] wr_ptr;
97
        reg [AWIDTH-1:0] rd_ptr;
98 24 redbear
        reg [AWIDTH-1:0] counter;
99 2 redbear
 
100 24 redbear
        wire [AWIDTH-1:0] wr;
101
        wire [AWIDTH-1:0] rd;
102
        wire [AWIDTH-1:0] w_counter;
103 16 celaya.dar
//Write pointer
104 13 redbear
        always@(posedge clock)
105
        begin
106 16 celaya.dar
                if (reset)
107
                begin
108
                        wr_ptr <= {(AWIDTH){1'b0}};
109
                end
110
                else if (wr_en && !f_full)
111
                begin
112 24 redbear
                        mem[wr_ptr]<=data_in;
113
                        wr_ptr <= wr;
114 16 celaya.dar
                end
115
        end
116 13 redbear
 
117 16 celaya.dar
//Read pointer
118
        always@(posedge clock)
119
        begin
120 2 redbear
                if (reset)
121
                begin
122 16 celaya.dar
                        rd_ptr <= {(AWIDTH){1'b0}};
123
                end
124
                else if (rd_en && !f_empty)
125
                begin
126 24 redbear
                        rd_ptr <= rd;
127 16 celaya.dar
                end
128
        end
129 13 redbear
 
130 16 celaya.dar
//Counter
131
        always@(posedge clock)
132
        begin
133
                if (reset)
134
                begin
135 24 redbear
                        counter <= {(AWIDTH){1'b0}};
136 2 redbear
                end
137
                else
138
                begin
139 16 celaya.dar
                        if (rd_en && !f_empty && !wr_en)
140 2 redbear
                        begin
141 24 redbear
                                counter <= w_counter;
142 2 redbear
                        end
143 16 celaya.dar
                        else if (wr_en && !f_full && !rd_en)
144 2 redbear
                        begin
145 24 redbear
                                counter <= w_counter;
146 16 celaya.dar
                        end
147 2 redbear
                end
148 13 redbear
        end
149 2 redbear
 
150 24 redbear
        assign f_full = (counter == 4'd15)?1'b1:1'b0;//DEPTH- 1) ; 
151
        assign f_empty = (counter == 4'd0)?1'b1:1'b0;//{AWIDTH{1'b0}});
152
        assign wr = (wr_en && !f_full)?wr_ptr + 4'd1:wr_ptr + 4'd0;
153
        assign rd = (rd_en && !f_empty)?rd_ptr+ 4'd1:rd_ptr+ 4'd0;
154
        assign w_counter = (rd_en && !f_empty && !wr_en)? counter - 4'd1:
155
                           (wr_en && !f_full && !rd_en)? counter + 4'd1:
156
                            w_counter + 4'd0;
157
        //assign wr_en_ram = wr_en;
158
        //assign rd_en_ram = rd_en;
159
        assign data_out = mem[rd_ptr];//data_ram_out;
160
/*
161 16 celaya.dar
dp_ram #(DWIDTH, AWIDTH)
162
RAM_1   (
163
                .clock(clock),
164
                .reset(reset),
165
                .wr_en(wr_en_ram),
166
                .rd_en(rd_en_ram),
167
                .data_in(data_in),
168
                .wr_addr(wr_ptr),
169
                .data_out(data_ram_out),
170
                .rd_addr(rd_ptr)
171
        );
172 24 redbear
*/
173 2 redbear
endmodule

powered by: WebSVN 2.1.0

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