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

Subversion Repositories apbi2c

[/] [apbi2c/] [trunk/] [rtl/] [fifo.v] - Diff between revs 18 and 24

Only display areas with differences | Details | Blame | View Log

Rev 18 Rev 24
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
////
////
////
////
////    FIFO BLOCK to I2C Core
////    FIFO BLOCK to I2C Core
////
////
////
////
////
////
//// This file is part of the APB to I2C project
//// This file is part of the APB to I2C project
////
////
//// http://www.opencores.org/cores/apbi2c/
//// http://www.opencores.org/cores/apbi2c/
////
////
////
////
////
////
//// Description
//// Description
////
////
//// Implementation of APB IP core according to
//// Implementation of APB IP core according to
////
////
//// apbi2c_spec IP core specification document.
//// apbi2c_spec IP core specification document.
////
////
////
////
////
////
//// To Do: This block inst functional yet when you try only write half registers and it didnt go correctly FULL and EMPTY
//// To Do: This block inst functional yet when you try only write half registers and it didnt go correctly FULL and EMPTY
////
////
////
////
////
////
////
////
////
////
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
//// Author(s): - Felipe Fernandes Da Costa, fefe2560@gmail.com
////              Ronal Dario Celaya ,rcelaya.dario@gmail.com
 
////
////
///////////////////////////////////////////////////////////////// 
///////////////////////////////////////////////////////////////// 
////
////
////
////
//// Copyright (C) 2009 Authors and OPENCORES.ORG
//// Copyright (C) 2009 Authors and OPENCORES.ORG
////
////
////
////
////
////
//// This source file may be used and distributed without
//// This source file may be used and distributed without
////
////
//// restriction provided that this copyright statement is not
//// restriction provided that this copyright statement is not
////
////
//// removed from the file and that any derivative work contains
//// removed from the file and that any derivative work contains
//// the original copyright notice and the associated disclaimer.
//// the original copyright notice and the associated disclaimer.
////
////
////
////
//// This source file is free software; you can redistribute it
//// This source file is free software; you can redistribute it
////
////
//// and/or modify it under the terms of the GNU Lesser General
//// and/or modify it under the terms of the GNU Lesser General
////
////
//// Public License as published by the Free Software Foundation;
//// Public License as published by the Free Software Foundation;
//// either version 2.1 of the License, or (at your option) any
//// either version 2.1 of the License, or (at your option) any
////
////
//// later version.
//// later version.
////
////
////
////
////
////
//// This source is distributed in the hope that it will be
//// This source is distributed in the hope that it will be
////
////
//// useful, but WITHOUT ANY WARRANTY; without even the implied
//// useful, but WITHOUT ANY WARRANTY; without even the implied
////
////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
////
////
//// PURPOSE. See the GNU Lesser General Public License for more
//// PURPOSE. See the GNU Lesser General Public License for more
//// details.
//// details.
////
////
////
////
////
////
//// You should have received a copy of the GNU Lesser General
//// You should have received a copy of the GNU Lesser General
////
////
//// Public License along with this source; if not, download it
//// Public License along with this source; if not, download it
////
////
//// from http://www.opencores.org/lgpl.shtml
//// from http://www.opencores.org/lgpl.shtml
////
////
////
////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
`timescale 1ns/1ps
`timescale 1ns/1ps
module fifo
module fifo
#(
#(
        parameter integer DWIDTH = 32,
        parameter integer DWIDTH = 32,
        parameter integer AWIDTH = 4
        parameter integer AWIDTH = 4
)
)
 
 
(
(
        input clock, reset, wr_en, rd_en,
        input clock, reset, wr_en, rd_en,
        input [DWIDTH-1:0] data_in,
        input [DWIDTH-1:0] data_in,
        output f_full, f_empty,
        output f_full, f_empty,
        output [DWIDTH-1:0] data_out
        output [DWIDTH-1:0] data_out
);
);
 
 
 
 
//      reg [DWIDTH-1:0] mem [0:2**AWIDTH-1];
        reg [DWIDTH-1:0] mem [0:2**AWIDTH-1];
        parameter integer DEPTH = 1 << AWIDTH;
        //parameter integer DEPTH = 1 << AWIDTH;
        wire [DWIDTH-1:0] data_ram_out;
        //wire [DWIDTH-1:0] data_ram_out;
        wire wr_en_ram;
        //wire wr_en_ram; 
        wire rd_en_ram;
        //wire rd_en_ram;       
 
 
        reg [AWIDTH-1:0] wr_ptr;
        reg [AWIDTH-1:0] wr_ptr;
        reg [AWIDTH-1:0] rd_ptr;
        reg [AWIDTH-1:0] rd_ptr;
        reg [AWIDTH:0] counter;
        reg [AWIDTH-1:0] counter;
 
 
 
 
 
        wire [AWIDTH-1:0] wr;
 
        wire [AWIDTH-1:0] rd;
 
        wire [AWIDTH-1:0] w_counter;
//Write pointer
//Write pointer
        always@(posedge clock)
        always@(posedge clock)
        begin
        begin
                if (reset)
                if (reset)
                begin
                begin
                        wr_ptr <= {(AWIDTH){1'b0}};
                        wr_ptr <= {(AWIDTH){1'b0}};
                end
                end
                else if (wr_en && !f_full)
                else if (wr_en && !f_full)
                begin
                begin
                        wr_ptr <= wr_ptr + 1'b1;
                        mem[wr_ptr]<=data_in;
 
                        wr_ptr <= wr;
                end
                end
        end
        end
 
 
//Read pointer
//Read pointer
        always@(posedge clock)
        always@(posedge clock)
        begin
        begin
                if (reset)
                if (reset)
                begin
                begin
                        rd_ptr <= {(AWIDTH){1'b0}};
                        rd_ptr <= {(AWIDTH){1'b0}};
                end
                end
                else if (rd_en && !f_empty)
                else if (rd_en && !f_empty)
                begin
                begin
                        rd_ptr <= rd_ptr + 1'b1;
                        rd_ptr <= rd;
                end
                end
        end
        end
 
 
//Counter
//Counter
        always@(posedge clock)
        always@(posedge clock)
        begin
        begin
                if (reset)
                if (reset)
                begin
                begin
                        counter <= {(AWIDTH+1){1'b0}};
                        counter <= {(AWIDTH){1'b0}};
                end
                end
                else
                else
                begin
                begin
                        if (rd_en && !f_empty && !wr_en)
                        if (rd_en && !f_empty && !wr_en)
                        begin
                        begin
                                counter <= counter - 1'b1;
                                counter <= w_counter;
                        end
                        end
                        else if (wr_en && !f_full && !rd_en)
                        else if (wr_en && !f_full && !rd_en)
                        begin
                        begin
                                counter <= counter + 1'b1;
                                counter <= w_counter;
                        end
                        end
                end
                end
        end
        end
 
 
        assign f_full = (counter == DEPTH- 1) ;
        assign f_full = (counter == 4'd15)?1'b1:1'b0;//DEPTH- 1) ; 
        assign f_empty = (counter == {AWIDTH{1'b0}});
        assign f_empty = (counter == 4'd0)?1'b1:1'b0;//{AWIDTH{1'b0}});
        assign wr_en_ram = wr_en;
        assign wr = (wr_en && !f_full)?wr_ptr + 4'd1:wr_ptr + 4'd0;
        assign rd_en_ram = rd_en;
        assign rd = (rd_en && !f_empty)?rd_ptr+ 4'd1:rd_ptr+ 4'd0;
        assign data_out = data_ram_out;
        assign w_counter = (rd_en && !f_empty && !wr_en)? counter - 4'd1:
 
                           (wr_en && !f_full && !rd_en)? counter + 4'd1:
dp_ram #(DWIDTH, AWIDTH)
                            w_counter + 4'd0;
RAM_1   (
        //assign wr_en_ram = wr_en;
                .clock(clock),
        //assign rd_en_ram = rd_en;
                .reset(reset),
        assign data_out = mem[rd_ptr];//data_ram_out;
                .wr_en(wr_en_ram),
/*
                .rd_en(rd_en_ram),
dp_ram #(DWIDTH, AWIDTH)
                .data_in(data_in),
RAM_1   (
                .wr_addr(wr_ptr),
                .clock(clock),
                .data_out(data_ram_out),
                .reset(reset),
                .rd_addr(rd_ptr)
                .wr_en(wr_en_ram),
        );
                .rd_en(rd_en_ram),
 
                .data_in(data_in),
 
                .wr_addr(wr_ptr),
 
                .data_out(data_ram_out),
 
                .rd_addr(rd_ptr)
 
        );
 
*/
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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