//=======================================================================
|
//=======================================================================
|
// Project Monophony
|
// Project Monophony
|
// Wire-Frame 3D Graphics Accelerator IP Core
|
// Wire-Frame 3D Graphics Accelerator IP Core
|
//
|
//
|
// File:
|
// File:
|
// fm_afifo.v
|
// fm_afifo.v
|
//
|
//
|
// Abstract:
|
// Abstract:
|
// Asynchronus FIFO
|
// Asynchronus FIFO
|
//
|
//
|
// Author:
|
// Author:
|
// Kenji Ishimaru (info.wf3d@gmail.com)
|
// Kenji Ishimaru (info.info.wf3d@gmail.com)
|
//
|
//
|
//======================================================================
|
//======================================================================
|
//
|
//
|
// Copyright (c) 2015, Kenji Ishimaru
|
// Copyright (c) 2015, Kenji Ishimaru
|
// All rights reserved.
|
// All rights reserved.
|
//
|
//
|
// Redistribution and use in source and binary forms, with or without
|
// Redistribution and use in source and binary forms, with or without
|
// modification, are permitted provided that the following conditions are met:
|
// modification, are permitted provided that the following conditions are met:
|
//
|
//
|
// -Redistributions of source code must retain the above copyright notice,
|
// -Redistributions of source code must retain the above copyright notice,
|
// this list of conditions and the following disclaimer.
|
// this list of conditions and the following disclaimer.
|
// -Redistributions in binary form must reproduce the above copyright notice,
|
// -Redistributions in binary form must reproduce the above copyright notice,
|
// this list of conditions and the following disclaimer in the documentation
|
// this list of conditions and the following disclaimer in the documentation
|
// and/or other materials provided with the distribution.
|
// and/or other materials provided with the distribution.
|
//
|
//
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
//
|
//
|
// Revision History
|
// Revision History
|
|
|
module fm_afifo (
|
module fm_afifo (
|
clk_core,
|
clk_core,
|
clk_vi,
|
clk_vi,
|
rst_x,
|
rst_x,
|
i_color_mode,
|
i_color_mode,
|
i_wstrobe,
|
i_wstrobe,
|
i_dt,
|
i_dt,
|
o_full,
|
o_full,
|
i_renable,
|
i_renable,
|
o_dt,
|
o_dt,
|
o_empty,
|
o_empty,
|
o_dnum
|
o_dnum
|
);
|
);
|
|
|
// set default parameters
|
// set default parameters
|
parameter P_RANGE = 7;
|
parameter P_RANGE = 7;
|
parameter P_DEPTH = 1 << P_RANGE; // 128
|
parameter P_DEPTH = 1 << P_RANGE; // 128
|
`ifdef PP_BUSWIDTH_64
|
`ifdef PP_BUSWIDTH_64
|
localparam P_IB_DATA_WIDTH = 'd64;
|
localparam P_IB_DATA_WIDTH = 'd64;
|
`else
|
`else
|
localparam P_IB_DATA_WIDTH = 'd32;
|
localparam P_IB_DATA_WIDTH = 'd32;
|
`endif
|
`endif
|
////////////////////////////
|
////////////////////////////
|
// I/O definition
|
// I/O definition
|
////////////////////////////
|
////////////////////////////
|
input clk_core; // system clock
|
input clk_core; // system clock
|
input clk_vi;
|
input clk_vi;
|
input rst_x; // system reset
|
input rst_x; // system reset
|
input [1:0] i_color_mode;
|
input [1:0] i_color_mode;
|
input i_wstrobe; // write strobe
|
input i_wstrobe; // write strobe
|
input [P_IB_DATA_WIDTH-1:0]
|
input [P_IB_DATA_WIDTH-1:0]
|
i_dt; // write data
|
i_dt; // write data
|
output o_full; // write data full
|
output o_full; // write data full
|
input i_renable; // read enable
|
input i_renable; // read enable
|
output [15:0] o_dt; // read data
|
output [15:0] o_dt; // read data
|
output o_empty; // read data empty
|
output o_empty; // read data empty
|
output [P_RANGE:0] o_dnum; // written data number
|
output [P_RANGE:0] o_dnum; // written data number
|
|
|
/////////////////////////
|
/////////////////////////
|
// Register definition
|
// Register definition
|
/////////////////////////
|
/////////////////////////
|
reg [P_RANGE-1:0] r_write_counter;
|
reg [P_RANGE-1:0] r_write_counter;
|
reg [P_RANGE-1:0] r_read_counter;
|
reg [P_RANGE-1:0] r_read_counter;
|
// data registers
|
// data registers
|
`ifdef PP_BUSWIDTH_64
|
`ifdef PP_BUSWIDTH_64
|
reg [3:0] r_select_hw;
|
reg [3:0] r_select_hw;
|
`else
|
`else
|
reg [2:0] r_select_hw;
|
reg [2:0] r_select_hw;
|
`endif
|
`endif
|
/////////////////////////
|
/////////////////////////
|
// wire definition
|
// wire definition
|
/////////////////////////
|
/////////////////////////
|
wire o_full;
|
wire o_full;
|
wire o_empty;
|
wire o_empty;
|
wire [15:0] o_dt;
|
wire [15:0] o_dt;
|
wire w_we;
|
wire w_we;
|
wire w_re;
|
wire w_re;
|
wire [P_IB_DATA_WIDTH-1:0]
|
wire [P_IB_DATA_WIDTH-1:0]
|
w_dt;
|
w_dt;
|
wire [P_RANGE-1:0] w_read_counter_inc;
|
wire [P_RANGE-1:0] w_read_counter_inc;
|
wire [P_RANGE-1:0] w_read_counter;
|
wire [P_RANGE-1:0] w_read_counter;
|
wire [15:0] w_dt16;
|
wire [15:0] w_dt16;
|
wire [7:0] w_dt8;
|
wire [7:0] w_dt8;
|
wire [3:0] w_dt4;
|
wire [3:0] w_dt4;
|
// /////////////////////////
|
// /////////////////////////
|
// assign statement
|
// assign statement
|
/////////////////////////
|
/////////////////////////
|
`ifdef PP_BUSWIDTH_64
|
`ifdef PP_BUSWIDTH_64
|
assign w_dt16 = (r_select_hw[1:0] == 'd3) ? w_dt[63:48] :
|
assign w_dt16 = (r_select_hw[1:0] == 'd3) ? w_dt[63:48] :
|
(r_select_hw[1:0] == 'd2) ? w_dt[47:32] :
|
(r_select_hw[1:0] == 'd2) ? w_dt[47:32] :
|
(r_select_hw[1:0] == 'd1) ? w_dt[31:16] :
|
(r_select_hw[1:0] == 'd1) ? w_dt[31:16] :
|
w_dt[15:0];
|
w_dt[15:0];
|
|
|
assign w_dt8 = (r_select_hw[2:0] == 'd7) ? w_dt[63:56] :
|
assign w_dt8 = (r_select_hw[2:0] == 'd7) ? w_dt[63:56] :
|
(r_select_hw[2:0] == 'd6) ? w_dt[55:48] :
|
(r_select_hw[2:0] == 'd6) ? w_dt[55:48] :
|
(r_select_hw[2:0] == 'd5) ? w_dt[47:40] :
|
(r_select_hw[2:0] == 'd5) ? w_dt[47:40] :
|
(r_select_hw[2:0] == 'd4) ? w_dt[39:32] :
|
(r_select_hw[2:0] == 'd4) ? w_dt[39:32] :
|
(r_select_hw[2:0] == 'd3) ? w_dt[31:24] :
|
(r_select_hw[2:0] == 'd3) ? w_dt[31:24] :
|
(r_select_hw[2:0] == 'd2) ? w_dt[23:16] :
|
(r_select_hw[2:0] == 'd2) ? w_dt[23:16] :
|
(r_select_hw[2:0] == 'd1) ? w_dt[15:8] :
|
(r_select_hw[2:0] == 'd1) ? w_dt[15:8] :
|
w_dt[7:0];
|
w_dt[7:0];
|
|
|
assign w_dt4 = (r_select_hw[3:0] == 'd15) ? w_dt[63:60] :
|
assign w_dt4 = (r_select_hw[3:0] == 'd15) ? w_dt[63:60] :
|
(r_select_hw[3:0] == 'd14) ? w_dt[59:56] :
|
(r_select_hw[3:0] == 'd14) ? w_dt[59:56] :
|
(r_select_hw[3:0] == 'd13) ? w_dt[55:52] :
|
(r_select_hw[3:0] == 'd13) ? w_dt[55:52] :
|
(r_select_hw[3:0] == 'd12) ? w_dt[51:48] :
|
(r_select_hw[3:0] == 'd12) ? w_dt[51:48] :
|
(r_select_hw[3:0] == 'd11) ? w_dt[47:44] :
|
(r_select_hw[3:0] == 'd11) ? w_dt[47:44] :
|
(r_select_hw[3:0] == 'd10) ? w_dt[43:40] :
|
(r_select_hw[3:0] == 'd10) ? w_dt[43:40] :
|
(r_select_hw[3:0] == 'd9) ? w_dt[39:36] :
|
(r_select_hw[3:0] == 'd9) ? w_dt[39:36] :
|
(r_select_hw[3:0] == 'd8) ? w_dt[35:32] :
|
(r_select_hw[3:0] == 'd8) ? w_dt[35:32] :
|
(r_select_hw[3:0] == 'd7) ? w_dt[31:28] :
|
(r_select_hw[3:0] == 'd7) ? w_dt[31:28] :
|
(r_select_hw[3:0] == 'd6) ? w_dt[27:24] :
|
(r_select_hw[3:0] == 'd6) ? w_dt[27:24] :
|
(r_select_hw[3:0] == 'd5) ? w_dt[23:20] :
|
(r_select_hw[3:0] == 'd5) ? w_dt[23:20] :
|
(r_select_hw[3:0] == 'd4) ? w_dt[19:16] :
|
(r_select_hw[3:0] == 'd4) ? w_dt[19:16] :
|
(r_select_hw[3:0] == 'd3) ? w_dt[15:12] :
|
(r_select_hw[3:0] == 'd3) ? w_dt[15:12] :
|
(r_select_hw[3:0] == 'd2) ? w_dt[11:8] :
|
(r_select_hw[3:0] == 'd2) ? w_dt[11:8] :
|
(r_select_hw[3:0] == 'd1) ? w_dt[7:4] :
|
(r_select_hw[3:0] == 'd1) ? w_dt[7:4] :
|
w_dt[3:0];
|
w_dt[3:0];
|
|
|
assign w_re = i_renable & ((i_color_mode == 'd3) ? (r_select_hw[3:0] == 'd15) :
|
assign w_re = i_renable & ((i_color_mode == 'd3) ? (r_select_hw[3:0] == 'd15) :
|
(i_color_mode == 'd2) ? (r_select_hw[2:0] == 'd7) :
|
(i_color_mode == 'd2) ? (r_select_hw[2:0] == 'd7) :
|
(r_select_hw[1:0] == 'd3)
|
(r_select_hw[1:0] == 'd3)
|
);
|
);
|
`else
|
`else
|
assign w_dt16 = (r_select_hw[0]) ? w_dt[31:16] : w_dt[15:0];
|
assign w_dt16 = (r_select_hw[0]) ? w_dt[31:16] : w_dt[15:0];
|
assign w_dt8 = (r_select_hw[1:0] == 'd3) ? w_dt[31:24] :
|
assign w_dt8 = (r_select_hw[1:0] == 'd3) ? w_dt[31:24] :
|
(r_select_hw[1:0] == 'd2) ? w_dt[23:16] :
|
(r_select_hw[1:0] == 'd2) ? w_dt[23:16] :
|
(r_select_hw[1:0] == 'd1) ? w_dt[15:8] :
|
(r_select_hw[1:0] == 'd1) ? w_dt[15:8] :
|
w_dt[7:0];
|
w_dt[7:0];
|
|
|
assign w_dt4 = (r_select_hw[2:0] == 'd7) ? w_dt[31:28] :
|
assign w_dt4 = (r_select_hw[2:0] == 'd7) ? w_dt[31:28] :
|
(r_select_hw[2:0] == 'd6) ? w_dt[27:24] :
|
(r_select_hw[2:0] == 'd6) ? w_dt[27:24] :
|
(r_select_hw[2:0] == 'd5) ? w_dt[23:20] :
|
(r_select_hw[2:0] == 'd5) ? w_dt[23:20] :
|
(r_select_hw[2:0] == 'd4) ? w_dt[19:16] :
|
(r_select_hw[2:0] == 'd4) ? w_dt[19:16] :
|
(r_select_hw[2:0] == 'd3) ? w_dt[15:12] :
|
(r_select_hw[2:0] == 'd3) ? w_dt[15:12] :
|
(r_select_hw[2:0] == 'd2) ? w_dt[11:8] :
|
(r_select_hw[2:0] == 'd2) ? w_dt[11:8] :
|
(r_select_hw[2:0] == 'd1) ? w_dt[7:4] :
|
(r_select_hw[2:0] == 'd1) ? w_dt[7:4] :
|
w_dt[3:0];
|
w_dt[3:0];
|
|
|
assign w_re = i_renable & ((i_color_mode == 'd3) ? (r_select_hw == 'd7) :
|
assign w_re = i_renable & ((i_color_mode == 'd3) ? (r_select_hw == 'd7) :
|
(i_color_mode == 'd2) ? (r_select_hw[1:0] == 'd3) :
|
(i_color_mode == 'd2) ? (r_select_hw[1:0] == 'd3) :
|
(r_select_hw[0] == 'd1)
|
(r_select_hw[0] == 'd1)
|
);
|
);
|
`endif
|
`endif
|
assign o_dt = (i_color_mode == 'd3) ? {12'd0,w_dt4} :
|
assign o_dt = (i_color_mode == 'd3) ? {12'd0,w_dt4} :
|
(i_color_mode == 'd2) ? {8'd0,w_dt8} :
|
(i_color_mode == 'd2) ? {8'd0,w_dt8} :
|
w_dt16 ;
|
w_dt16 ;
|
assign o_dnum = 0;
|
assign o_dnum = 0;
|
assign o_full = 1'b0;
|
assign o_full = 1'b0;
|
assign o_empty = 1'b0;
|
assign o_empty = 1'b0;
|
assign w_we = i_wstrobe;
|
assign w_we = i_wstrobe;
|
assign w_read_counter_inc = r_read_counter + 1'b1;
|
assign w_read_counter_inc = r_read_counter + 1'b1;
|
assign w_read_counter = (w_re) ? w_read_counter_inc : r_read_counter;
|
assign w_read_counter = (w_re) ? w_read_counter_inc : r_read_counter;
|
|
|
////////////////////////
|
////////////////////////
|
// always
|
// always
|
///////////////////////
|
///////////////////////
|
// write side (clk_core)
|
// write side (clk_core)
|
always @(posedge clk_core or negedge rst_x) begin
|
always @(posedge clk_core or negedge rst_x) begin
|
if (~rst_x) begin
|
if (~rst_x) begin
|
r_write_counter <= 'd0;
|
r_write_counter <= 'd0;
|
end else begin
|
end else begin
|
if (w_we) begin
|
if (w_we) begin
|
r_write_counter <= r_write_counter + 1'b1;
|
r_write_counter <= r_write_counter + 1'b1;
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
// read side (clk_vi)
|
// read side (clk_vi)
|
always @(posedge clk_vi or negedge rst_x) begin
|
always @(posedge clk_vi or negedge rst_x) begin
|
if (~rst_x) begin
|
if (~rst_x) begin
|
r_read_counter <= 'd0;
|
r_read_counter <= 'd0;
|
end else begin
|
end else begin
|
if (w_re) begin
|
if (w_re) begin
|
r_read_counter <= w_read_counter_inc;
|
r_read_counter <= w_read_counter_inc;
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
// select half word
|
// select half word
|
always @(posedge clk_vi or negedge rst_x) begin
|
always @(posedge clk_vi or negedge rst_x) begin
|
if (~rst_x) begin
|
if (~rst_x) begin
|
r_select_hw <= 'd0;
|
r_select_hw <= 'd0;
|
end else begin
|
end else begin
|
if (i_renable) r_select_hw <= r_select_hw + 1'b1;
|
if (i_renable) r_select_hw <= r_select_hw + 1'b1;
|
end
|
end
|
end
|
end
|
|
|
///////////////////
|
///////////////////
|
// module instance
|
// module instance
|
///////////////////
|
///////////////////
|
`ifdef PP_BUSWIDTH_64
|
`ifdef PP_BUSWIDTH_64
|
fm_cmn_ram #(.P_RAM_TYPE("TYPE_A"),.P_WIDTH(64),.P_RANGE( P_RANGE)) ram_00 (
|
fm_cmn_ram #(.P_RAM_TYPE("TYPE_A"),.P_WIDTH(64),.P_RANGE( P_RANGE)) ram_00 (
|
`else
|
`else
|
fm_cmn_ram #(.P_RAM_TYPE("TYPE_A"),.P_WIDTH(32),.P_RANGE( P_RANGE)) ram_00 (
|
fm_cmn_ram #(.P_RAM_TYPE("TYPE_A"),.P_WIDTH(32),.P_RANGE( P_RANGE)) ram_00 (
|
`endif
|
`endif
|
.clka(clk_core),
|
.clka(clk_core),
|
.clkb(clk_vi),
|
.clkb(clk_vi),
|
.wea(w_we),
|
.wea(w_we),
|
.addra(r_write_counter),
|
.addra(r_write_counter),
|
.addrb(w_read_counter),
|
.addrb(w_read_counter),
|
.dia(i_dt),
|
.dia(i_dt),
|
.doa(),
|
.doa(),
|
.dob(w_dt)
|
.dob(w_dt)
|
);
|
);
|
|
|
endmodule
|
endmodule
|
|
|
|
|
|
|