mirror of
https://github.com/aolofsson/oh.git
synced 2025-01-30 02:32:53 +08:00
Adding platform agnostic dual ported memory and async fifo
This commit is contained in:
parent
3ddb6679ff
commit
4fd4c8e989
@ -1,71 +1,113 @@
|
||||
/*
|
||||
Copyright (C) 2015 Adapteva, Inc.
|
||||
Contributed by Andreas Olofsson <andreas@adapteva.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program (see the file COPYING). If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
########################################################################
|
||||
Generic asynchronous FIFO
|
||||
|
||||
Caution: There is no protection against overflow or underflow,
|
||||
driving logic should avoid wen on full or ren on empty.
|
||||
########################################################################
|
||||
*/
|
||||
|
||||
module fifo_async(/*AUTOARG*/
|
||||
module fifo_async
|
||||
(/*AUTOARG*/
|
||||
// Outputs
|
||||
wr_full, wr_progfull, rd_data, rd_empty,
|
||||
rd_data, rd_fifo_empty, wr_fifo_full,
|
||||
// Inputs
|
||||
reset, wr_clk, wr_en, wr_data, rd_clk, rd_en
|
||||
reset, wr_clk, rd_clk, wr_write, wr_data, rd_read
|
||||
);
|
||||
|
||||
parameter AW = 5; //fifo address width
|
||||
parameter DW = 16; //fifo data width
|
||||
|
||||
//Reset
|
||||
input reset;
|
||||
parameter DW = 104;
|
||||
parameter AW = 2;
|
||||
|
||||
//Write side interface
|
||||
input wr_clk; //write side clock
|
||||
input wr_en; //write enable
|
||||
input [DW-1:0] wr_data; //write data
|
||||
output wr_full; //fifo full
|
||||
output wr_progfull; //programmable full level
|
||||
//##########
|
||||
//# INPUTS
|
||||
//##########
|
||||
input reset;
|
||||
input wr_clk; //write clock
|
||||
input rd_clk; //read clock
|
||||
|
||||
//Read side interface
|
||||
input rd_clk; //read side clock
|
||||
input rd_en; //read enable
|
||||
output [DW-1:0] rd_data; //read data
|
||||
output rd_empty; //fifo empty
|
||||
input wr_write;
|
||||
input [DW-1:0] wr_data;
|
||||
input rd_read;
|
||||
|
||||
//###########
|
||||
//# OUTPUTS
|
||||
//###########
|
||||
output [DW-1:0] rd_data;
|
||||
output rd_fifo_empty;
|
||||
output wr_fifo_full;
|
||||
|
||||
//Wires
|
||||
wire [DW/8-1:0] wr_en;
|
||||
wire [AW:0] wr_rd_gray_pointer;
|
||||
wire [AW:0] rd_wr_gray_pointer;
|
||||
wire [AW:0] wr_gray_pointer;
|
||||
wire [AW:0] rd_gray_pointer;
|
||||
wire [AW-1:0] rd_addr;
|
||||
wire [AW-1:0] wr_addr;
|
||||
|
||||
|
||||
assign wr_en[DW/8-1:0] = {(DW/8){wr_write}};
|
||||
|
||||
memory_dp #(.DW(DW),.AW(AW)) memory_dp (
|
||||
// Outputs
|
||||
.rd_data (rd_data[DW-1:0]),
|
||||
// Inputs
|
||||
.wr_clk (wr_clk),
|
||||
.wr_en (wr_en[DW/8-1:0]),
|
||||
.wr_addr (wr_addr[AW-1:0]),
|
||||
.wr_data (wr_data[DW-1:0]),
|
||||
.rd_clk (rd_clk),
|
||||
.rd_en (1'b1),
|
||||
.rd_addr (rd_addr[AW-1:0]));
|
||||
|
||||
//Read State Machine
|
||||
fifo_empty_block #(.AW(AW)) fifo_empty_block(
|
||||
// Outputs
|
||||
.rd_fifo_empty (rd_fifo_empty),
|
||||
.rd_addr (rd_addr[AW-1:0]),
|
||||
.rd_gray_pointer(rd_gray_pointer[AW:0]),
|
||||
// Inputs
|
||||
.reset (reset),
|
||||
.rd_clk (rd_clk),
|
||||
.rd_wr_gray_pointer(rd_wr_gray_pointer[AW:0]),
|
||||
.rd_read (rd_read));
|
||||
|
||||
//Write State Machine
|
||||
fifo_full_block #(.AW(AW)) fifo_full_block(
|
||||
// Outputs
|
||||
.wr_fifo_full (wr_fifo_full),
|
||||
.wr_addr (wr_addr[AW-1:0]),
|
||||
.wr_gray_pointer (wr_gray_pointer[AW:0]),
|
||||
// Inputs
|
||||
.reset (reset),
|
||||
.wr_clk (wr_clk),
|
||||
.wr_rd_gray_pointer(wr_rd_gray_pointer[AW:0]),
|
||||
.wr_write (wr_write));
|
||||
|
||||
|
||||
//Dummy for now...
|
||||
assign rd_data = 103'b0;
|
||||
assign rd_empty = 1'b0;
|
||||
assign wr_full = 1'b0;
|
||||
assign wr_progfull = 1'b0;
|
||||
synchronizer #(.DW(AW+1)) rd2wr_sync (.out (wr_rd_gray_pointer[AW:0]),
|
||||
.in (rd_gray_pointer[AW:0]),
|
||||
.clk (wr_clk));
|
||||
|
||||
|
||||
//TODO:instatiate the right fifo
|
||||
//distributed RAM
|
||||
//32 x 103
|
||||
//async reset signal, assert high, full asserted on 16
|
||||
|
||||
synchronizer #(.DW(AW+1)) wr2rd_sync (.out (rd_wr_gray_pointer[AW:0]),
|
||||
.in (wr_gray_pointer[AW:0]),
|
||||
.clk (rd_clk));
|
||||
|
||||
|
||||
|
||||
endmodule // fifo_async
|
||||
// Local Variables:
|
||||
// verilog-library-directories:("." "../../common/hdl")
|
||||
// End:
|
||||
|
||||
/*
|
||||
Copyright (C) 2013 Adapteva, Inc.
|
||||
Contributed by Andreas Olofsson, Roman Trogan <support@adapteva.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program (see the file COPYING). If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
@ -68,11 +68,8 @@ module fifo_async_emesh (/*AUTOARG*/
|
||||
assign emesh_data_out[31:0] = fifo_dout[71:40];
|
||||
assign emesh_srcaddr_out[31:0] = fifo_dout[103:72];
|
||||
|
||||
|
||||
//TODO: paraemtrize fifo properly
|
||||
|
||||
fifo_async_104x32 fifo_async_104x32 (//outputs
|
||||
.dout (fifo_dout[103:0]),
|
||||
`ifdef TARGET_XILINX
|
||||
fifo_async_104x32 fifo_async_104x32 (.dout (fifo_dout[103:0]),
|
||||
.full (fifo_full),
|
||||
.empty (fifo_empty),
|
||||
.prog_full (fifo_progfull),
|
||||
@ -84,8 +81,25 @@ module fifo_async_emesh (/*AUTOARG*/
|
||||
.wr_en (emesh_access_in),
|
||||
.rd_en (fifo_read)
|
||||
);
|
||||
|
||||
`elsif TARGET_CLEAN
|
||||
fifo_async #(.DW(104), .AW(5)) fifo_async (
|
||||
.rd_data (fifo_dout[103:0]),
|
||||
.wr_fifo_full (fifo_progfull),
|
||||
.rd_fifo_empty (fifo_empty),
|
||||
//inputs
|
||||
.reset (reset),
|
||||
.wr_clk (wr_clk),
|
||||
.rd_clk (rd_clk),
|
||||
.wr_data (fifo_din[103:0]),
|
||||
.wr_write (emesh_access_in),
|
||||
.rd_read (fifo_read)
|
||||
);
|
||||
`elsif TARGET_ALTERA
|
||||
//SOMETHING
|
||||
`endif
|
||||
|
||||
|
||||
|
||||
endmodule // fifo_sync
|
||||
// Local Variables:
|
||||
// verilog-library-directories:("." "../../stubs/hdl")
|
||||
|
@ -1,25 +1,11 @@
|
||||
/*
|
||||
Copyright (C) 2014 Adapteva, Inc.
|
||||
Contributed by Andreas Olofsson <andreas@adapteva.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.This program is distributed in the hope
|
||||
that it will be useful,but WITHOUT ANY WARRANTY; without even the implied
|
||||
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details. You should have received a copy
|
||||
of the GNU General Public License along with this program (see the file
|
||||
COPYING). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*###########################################################################
|
||||
# Function: Dual port memory wrapper (one read/ one write port)
|
||||
#
|
||||
# To run without hardware platform dependancy, `define:
|
||||
# "TARGET_CLEAN"
|
||||
############################################################################
|
||||
*/
|
||||
|
||||
`define USE_MEM_MODEL
|
||||
module memory_dp(/*AUTOARG*/
|
||||
// Outputs
|
||||
rd_data,
|
||||
@ -47,7 +33,9 @@ module memory_dp(/*AUTOARG*/
|
||||
//////////////////////
|
||||
//SIMPLE MEMORY MODEL
|
||||
//////////////////////
|
||||
`ifdef USE_MEM_MODEL
|
||||
|
||||
`ifdef TARGET_CLEAN
|
||||
|
||||
reg [DW-1:0] ram [MD-1:0];
|
||||
reg [DW-1:0] rd_data;
|
||||
|
||||
@ -69,8 +57,7 @@ module memory_dp(/*AUTOARG*/
|
||||
endgenerate
|
||||
`elsif TARGET_XILINX
|
||||
//instantiate XILINX BRAM (based on parameter size)
|
||||
|
||||
|
||||
|
||||
`elsif TARGET_ALTERA
|
||||
|
||||
`endif
|
||||
@ -78,6 +65,20 @@ module memory_dp(/*AUTOARG*/
|
||||
endmodule // memory_dp
|
||||
|
||||
|
||||
/*
|
||||
Copyright (C) 2014 Adapteva, Inc.
|
||||
Contributed by Andreas Olofsson <andreas@adapteva.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.This program is distributed in the hope
|
||||
that it will be useful,but WITHOUT ANY WARRANTY; without even the implied
|
||||
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details. You should have received a copy
|
||||
of the GNU General Public License along with this program (see the file
|
||||
COPYING). If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user