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

Subversion Repositories apbi2c

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

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
////              Ronal Dario Celaya
30
////
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
        reg last_was_write;
102
 
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
                        wr_ptr <= wr_ptr + 1'b1;
113
                end
114
        end
115 13 redbear
 
116 16 celaya.dar
//Read pointer
117
        always@(posedge clock)
118
        begin
119 2 redbear
                if (reset)
120
                begin
121 16 celaya.dar
                        rd_ptr <= {(AWIDTH){1'b0}};
122
                end
123
                else if (rd_en && !f_empty)
124
                begin
125
                        rd_ptr <= rd_ptr + 1'b1;
126
                end
127
        end
128 13 redbear
 
129 16 celaya.dar
//Counter
130
        always@(posedge clock)
131
        begin
132
                if (reset)
133
                begin
134
                        counter <= {(AWIDTH+1){1'b0}};
135 2 redbear
                end
136
                else
137
                begin
138 16 celaya.dar
                        if (rd_en && !f_empty && !wr_en)
139 2 redbear
                        begin
140 16 celaya.dar
                                counter <= counter - 1'b1;
141 2 redbear
                        end
142 16 celaya.dar
                        else if (wr_en && !f_full && !rd_en)
143 2 redbear
                        begin
144 16 celaya.dar
                                counter <= counter + 1'b1;
145
                        end
146 2 redbear
                end
147 13 redbear
        end
148 2 redbear
 
149 16 celaya.dar
        assign f_full = (counter == DEPTH -1) ; //(!last_was_write | last_position != {AWIDTH{1'b0}} )? 1'b1:1'b0;
150
        assign f_empty = (counter == {AWIDTH{1'b0}}); //(last_was_write)? 1'b1:1'b0;
151
        assign wr_en_ram = wr_en;
152
        assign rd_en_ram = rd_en;
153
        assign data_out = data_ram_out;
154 13 redbear
 
155 16 celaya.dar
dp_ram #(DWIDTH, AWIDTH)
156
RAM_1   (
157
                .clock(clock),
158
                .reset(reset),
159
                .wr_en(wr_en_ram),
160
                .rd_en(rd_en_ram),
161
                .data_in(data_in),
162
                .wr_addr(wr_ptr),
163
                .data_out(data_ram_out),
164
                .rd_addr(rd_ptr)
165
        );
166 2 redbear
 
167
endmodule

powered by: WebSVN 2.1.0

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