1//
2// Copyright 2012 Ettus Research LLC
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program.  If not, see <http://www.gnu.org/licenses/>.
16//
17
18module gpmc16_to_fifo36
19#(
20    parameter FIFO_SIZE = 9,
21
22    //not ready until minimum xfers of space available
23    parameter MIN_SPACE16 = 128
24)
25(
26    //input interface
27    input gpif_clk, input gpif_rst,
28    input [15:0] in_data,
29    input valid,
30    output reg ready,
31
32    //output fifo interface
33    input fifo_clk, input fifo_rst,
34    output [35:0] out_data,
35    output out_src_rdy,
36    input out_dst_rdy
37);
38
39    wire [35:0] data_int;
40    wire src_rdy_int, dst_rdy_int;
41    wire [18:0] refr_data;
42    wire refr_src_rdy, refr_dst_rdy;
43
44    wire [15:0] fifo_space;
45
46    always @(posedge gpif_clk)
47        ready <= (fifo_space >= MIN_SPACE16/2);
48
49   packet_reframer packet_reframer
50     (.clk(gpif_clk), .reset(gpif_rst), .clear(1'b0),
51      .data_i(in_data), .src_rdy_i(valid), .dst_rdy_o(),
52      .data_o(refr_data), .src_rdy_o(refr_src_rdy), .dst_rdy_i(refr_dst_rdy));
53
54   fifo19_to_fifo36 #(.LE(1)) f19_to_f36
55     (.clk(gpif_clk), .reset(gpif_rst), .clear(1'b0),
56      .f19_datain(refr_data), .f19_src_rdy_i(refr_src_rdy), .f19_dst_rdy_o(refr_dst_rdy),
57      .f36_dataout(data_int), .f36_src_rdy_o(src_rdy_int), .f36_dst_rdy_i(dst_rdy_int));
58
59   fifo_2clock_cascade #(.WIDTH(36), .SIZE(FIFO_SIZE)) fifo_2clk
60     (.wclk(gpif_clk), .datain(data_int), .src_rdy_i(src_rdy_int), .dst_rdy_o(dst_rdy_int), .space(fifo_space),
61      .rclk(fifo_clk), .dataout(out_data), .src_rdy_o(out_src_rdy), .dst_rdy_i(out_dst_rdy), .occupied(),
62      .arst(fifo_rst | gpif_rst));
63
64endmodule //fifo_to_gpmc16
65