1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-30 02:32:53 +08:00

Making FIFO/memories easier to use

-WIDTH/DEPTH parameters
-Removing references to "clean" in ifdefs
This commit is contained in:
Andreas Olofsson 2015-05-07 23:50:34 -04:00
parent dc8cb83268
commit b2b7f96e86
5 changed files with 131 additions and 124 deletions

View File

@ -31,9 +31,11 @@ module emailbox (/*AUTOARG*/
parameter AW = 32; //data width of fifo parameter AW = 32; //data width of fifo
parameter PW = 104; //packet size parameter PW = 104; //packet size
parameter RFAW = 6; //address bus width parameter RFAW = 6; //address bus width
parameter GROUP = 4'h0; //address map group
parameter ID = 12'h000; //link id parameter ID = 12'h000; //link id
parameter WIDTH = 104;
parameter DEPTH = 16;
/*****************************/ /*****************************/
/*RESET */ /*RESET */
/*****************************/ /*****************************/
@ -73,7 +75,7 @@ module emailbox (/*AUTOARG*/
/*****************************/ /*****************************/
wire mailbox_read; wire mailbox_read;
wire mi_rd; wire mi_rd;
wire [2*DW-1:0] mailbox_fifo_data; wire [WIDTH-1:0] mailbox_fifo_data;
wire mailbox_empty; wire mailbox_empty;
wire mailbox_pop; wire mailbox_pop;
wire [31:0] emesh_addr; wire [31:0] emesh_addr;
@ -106,7 +108,8 @@ module emailbox (/*AUTOARG*/
if(mi_rd) if(mi_rd)
case(mi_addr[RFAW+1:2]) case(mi_addr[RFAW+1:2])
`E_MAILBOXLO: mi_dout[63:0] <= mailbox_fifo_data[63:0]; `E_MAILBOXLO: mi_dout[63:0] <= mailbox_fifo_data[63:0];
`E_MAILBOXHI: mi_dout[63:0] <= {mailbox_fifo_data[2*DW-1:DW],mailbox_fifo_data[2*DW-1:DW]}; `E_MAILBOXHI: mi_dout[63:0] <= {mailbox_fifo_data[2*DW-1:DW],
mailbox_fifo_data[2*DW-1:DW]};
default: mi_dout[63:0] <= 64'd0; default: mi_dout[63:0] <= 64'd0;
endcase // case (mi_addr[RFAW-1:2]) endcase // case (mi_addr[RFAW-1:2])
else else
@ -120,8 +123,12 @@ module emailbox (/*AUTOARG*/
//BUG! This fifo is currently hard coded to 32 entries //BUG! This fifo is currently hard coded to 32 entries
//Should be parametrized to up to 4096 entries //Should be parametrized to up to 4096 entries
fifo_async #(.DW(64), .AW(5)) fifo(// Outputs
.dout (mailbox_fifo_data[2*DW-1:0]), defparam fifo.WIDTH = WIDTH;
defparam fifo.DEPTH = DEPTH;
fifo_async fifo(// Outputs
.dout (mailbox_fifo_data[WIDTH-1:0]),
.empty (mailbox_empty), .empty (mailbox_empty),
.full (mailbox_full), .full (mailbox_full),
.prog_full (), .prog_full (),
@ -130,10 +137,11 @@ module emailbox (/*AUTOARG*/
.rd_en (mailbox_pop), .rd_en (mailbox_pop),
.rd_clk (rd_clk), .rd_clk (rd_clk),
//Write Port //Write Port
.din (emesh_din[63:0]), .din ({40'b0,emesh_din[63:0]}),
.wr_en (emesh_write), .wr_en (emesh_write),
.wr_clk (wr_clk), .wr_clk (wr_clk),
.reset (reset) .wr_rst (reset),
.rd_rst (reset)
); );
endmodule // emailbox endmodule // emailbox

View File

@ -4,17 +4,17 @@ module fifo_async
// Outputs // Outputs
full, prog_full, dout, empty, valid, full, prog_full, dout, empty, valid,
// Inputs // Inputs
reset, wr_clk, rd_clk, wr_en, din, rd_en wr_rst, rd_rst, wr_clk, rd_clk, wr_en, din, rd_en
); );
parameter DW = 104; parameter WIDTH = 104; //FIFO width
parameter AW = 2; parameter DEPTH = 16; //FIFO depth
//########## //##########
//# RESET/CLOCK //# RESET/CLOCK
//########## //##########
input reset; //asynchronous reset input wr_rst; //write reset
input rd_rst; //read reset
input wr_clk; //write clock input wr_clk; //write clock
input rd_clk; //read clock input rd_clk; //read clock
@ -22,7 +22,7 @@ module fifo_async
//# FIFO WRITE //# FIFO WRITE
//########## //##########
input wr_en; input wr_en;
input [DW-1:0] din; input [WIDTH-1:0] din;
output full; output full;
output prog_full; output prog_full;
@ -30,42 +30,41 @@ module fifo_async
//# FIFO READ //# FIFO READ
//########### //###########
input rd_en; input rd_en;
output [DW-1:0] dout; output [WIDTH-1:0] dout;
output empty; output empty;
output valid; output valid;
reg valid;
`ifdef TARGET_CLEAN `ifdef TARGET_CLEAN
parameter AW = $clog2(DEPTH); //FIFO address width (for model)
//Wires //Wires
wire [DW/8-1:0] wr_vec; wire [WIDTH/8-1:0] wr_vec;
wire [AW:0] wr_rd_gray_pointer; wire [AW:0] wr_rd_gray_pointer;
wire [AW:0] rd_wr_gray_pointer; wire [AW:0] rd_wr_gray_pointer;
wire [AW:0] wr_gray_pointer; wire [AW:0] wr_gray_pointer;
wire [AW:0] rd_gray_pointer; wire [AW:0] rd_gray_pointer;
wire [AW-1:0] rd_addr; wire [AW-1:0] rd_addr;
wire [AW-1:0] wr_addr; wire [AW-1:0] wr_addr;
reg valid;
assign wr_vec[WIDTH/8-1:0] = {(WIDTH/8){wr_en}};
assign wr_vec[DW/8-1:0] = {(DW/8){wr_en}};
//Valid data at output //Valid data at output
always @ (posedge rd_clk or posedge reset) always @ (posedge rd_clk or posedge rd_rst)
if(reset) if(rd_rst)
valid <=1'b0; valid <=1'b0;
else else
valid <= rd_en; valid <= rd_en;
memory_dp #(.DW(DW),.AW(AW)) memory_dp ( memory_dp #(.FW(WIDTH),.AW(AW)) memory_dp (
// Outputs // Outputs
.rd_data (dout[DW-1:0]), .rd_data (dout[WIDTH-1:0]),
// Inputs // Inputs
.wr_clk (wr_clk), .wr_clk (wr_clk),
.wr_en (wr_vec[DW/8-1:0]), .wr_en (wr_vec[WIDTH/8-1:0]),
.wr_addr (wr_addr[AW-1:0]), .wr_addr (wr_addr[AW-1:0]),
.wr_data (din[DW-1:0]), .wr_data (din[WIDTH-1:0]),
.rd_clk (rd_clk), .rd_clk (rd_clk),
.rd_en (rd_en), .rd_en (rd_en),
.rd_addr (rd_addr[AW-1:0])); .rd_addr (rd_addr[AW-1:0]));
@ -77,7 +76,7 @@ module fifo_async
.rd_addr (rd_addr[AW-1:0]), .rd_addr (rd_addr[AW-1:0]),
.rd_gray_pointer(rd_gray_pointer[AW:0]), .rd_gray_pointer(rd_gray_pointer[AW:0]),
// Inputs // Inputs
.reset (reset), .reset (rd_rst),
.rd_clk (rd_clk), .rd_clk (rd_clk),
.rd_wr_gray_pointer(rd_wr_gray_pointer[AW:0]), .rd_wr_gray_pointer(rd_wr_gray_pointer[AW:0]),
.rd_read (rd_en)); .rd_read (rd_en));
@ -90,7 +89,7 @@ module fifo_async
.wr_addr (wr_addr[AW-1:0]), .wr_addr (wr_addr[AW-1:0]),
.wr_gray_pointer (wr_gray_pointer[AW:0]), .wr_gray_pointer (wr_gray_pointer[AW:0]),
// Inputs // Inputs
.reset (reset), .reset (wr_rst),
.wr_clk (wr_clk), .wr_clk (wr_clk),
.wr_rd_gray_pointer(wr_rd_gray_pointer[AW:0]), .wr_rd_gray_pointer(wr_rd_gray_pointer[AW:0]),
.wr_write (wr_en)); .wr_write (wr_en));
@ -98,22 +97,36 @@ module fifo_async
synchronizer #(.DW(AW+1)) rd2wr_sync (.out (wr_rd_gray_pointer[AW:0]), synchronizer #(.DW(AW+1)) rd2wr_sync (.out (wr_rd_gray_pointer[AW:0]),
.in (rd_gray_pointer[AW:0]), .in (rd_gray_pointer[AW:0]),
.reset (reset), .reset (wr_rst),
.clk (wr_clk)); .clk (wr_clk));
synchronizer #(.DW(AW+1)) wr2rd_sync (.out (rd_wr_gray_pointer[AW:0]), synchronizer #(.DW(AW+1)) wr2rd_sync (.out (rd_wr_gray_pointer[AW:0]),
.in (wr_gray_pointer[AW:0]), .in (wr_gray_pointer[AW:0]),
.reset (reset), .reset (rd_rst),
.clk (rd_clk)); .clk (rd_clk));
`elsif TARGET_XILINX `elsif TARGET_XILINX
generate
if((WIDTH==104) & (DEPTH==16))
fifo_async_104x16 fifo_async_104x16 (
.wr_clk(wr_clk),
.wr_rst(wr_rst),
.rd_clk(rd_clk),
.rd_rst(rd_rst),
.din(din[WIDTH-1:0]),
.wr_en(wr_en),
.rd_en(rd_en),
.dout(dout[WIDTH-1:0]),
.full(full),
.empty(empty),
.valid(valid)
);
endgenerate
//insert generate FIFO
`endif // `ifdef TARGET_CLEAN `endif // !`elsif TARGET_XILINX
endmodule // fifo_async endmodule // fifo_async
// Local Variables: // Local Variables:

View File

@ -11,9 +11,8 @@ module fifo_cdc (/*AUTOARG*/
clk_in, clk_out, reset, access_in, packet_in, wait_in clk_in, clk_out, reset, access_in, packet_in, wait_in
); );
parameter FD = 16; //minimum depth parameter WIDTH = 104;
parameter AW = $clog2(FD); parameter DEPTH = 16;
parameter DW = 104;
/********************************/ /********************************/
/*Clocks/reset */ /*Clocks/reset */
@ -26,14 +25,14 @@ module fifo_cdc (/*AUTOARG*/
/*Input Packet*/ /*Input Packet*/
/********************************/ /********************************/
input access_in; input access_in;
input [DW-1:0] packet_in; input [WIDTH-1:0] packet_in;
output wait_out; output wait_out;
/********************************/ /********************************/
/*Register RD/WR Packet to ERX*/ /*Register RD/WR Packet to ERX*/
/********************************/ /********************************/
output access_out; output access_out;
output [DW-1:0] packet_out; output [WIDTH-1:0] packet_out;
input wait_in; input wait_in;
//Local wires //Local wires
@ -43,7 +42,6 @@ module fifo_cdc (/*AUTOARG*/
wire full; wire full;
reg access_out; reg access_out;
assign wr_en = access_in & ~full; assign wr_en = access_in & ~full;
assign rd_en = ~empty & ~wait_in; assign rd_en = ~empty & ~wait_in;
assign wait_out = full; assign wait_out = full;
@ -56,19 +54,23 @@ module fifo_cdc (/*AUTOARG*/
access_out <=rd_en; access_out <=rd_en;
//Read response fifo (from master) //Read response fifo (from master)
fifo_async #(.DW(DW), .AW(5)) fifo(
defparam fifo.WIDTH=104;
defparam fifo.DEPTH=16;
fifo_async fifo(
.prog_full (), .prog_full (),
.full (full), .full (full),
// Outputs // Outputs
.dout (packet_out[DW-1:0]), .dout (packet_out[WIDTH-1:0]),
.empty (empty), .empty (empty),
.valid (), .valid (),
// Inputs // Inputs
.reset (reset), .wr_rst (reset),
.rd_rst (reset),
.wr_clk (clk_in), .wr_clk (clk_in),
.rd_clk (clk_out), .rd_clk (clk_out),
.wr_en (wr_en), .wr_en (wr_en),
.din (packet_in[DW-1:0]), .din (packet_in[WIDTH-1:0]),
.rd_en (rd_en) .rd_en (rd_en)
); );

View File

@ -34,8 +34,6 @@ module memory_dp(/*AUTOARG*/
//SIMPLE MEMORY MODEL //SIMPLE MEMORY MODEL
////////////////////// //////////////////////
`ifdef TARGET_CLEAN
reg [DW-1:0] ram [MD-1:0]; reg [DW-1:0] ram [MD-1:0];
reg [DW-1:0] rd_data; reg [DW-1:0] rd_data;
@ -55,12 +53,6 @@ module memory_dp(/*AUTOARG*/
end end
end end
endgenerate endgenerate
`elsif TARGET_XILINX
//instantiate XILINX BRAM (based on parameter size)
`elsif TARGET_ALTERA
`endif
endmodule // memory_dp endmodule // memory_dp

View File

@ -26,8 +26,6 @@ module memory_sp(/*AUTOARG*/
input [DW-1:0] din; //data input input [DW-1:0] din; //data input
output [DW-1:0] dout;//data output output [DW-1:0] dout;//data output
`ifdef TARGET_CLEAN
reg [DW-1:0] ram [MD-1:0]; reg [DW-1:0] ram [MD-1:0];
reg [DW-1:0] rd_data; reg [DW-1:0] rd_data;
reg [DW-1:0] dout; reg [DW-1:0] dout;
@ -48,12 +46,6 @@ module memory_sp(/*AUTOARG*/
end end
end end
endgenerate endgenerate
`elsif TARGET_XILINX
//instantiate XILINX BRAM (based on parameter size)
`elsif TARGET_ALTERA
//instantiate ALTERA BRAM (based on paremeter size)
`endif
endmodule // memory_dp endmodule // memory_dp