1//
2// Copyright 2011 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
18
19module fifo_2clock_cascade
20  #(parameter WIDTH=32, SIZE=9)
21   (input wclk, input [WIDTH-1:0] datain, input src_rdy_i, output dst_rdy_o,
22    output [15:0] space, output [15:0] short_space,
23    input rclk, output [WIDTH-1:0] dataout, output src_rdy_o, input dst_rdy_i,
24    output [15:0] occupied, output [15:0] short_occupied,
25    input arst);
26
27   wire [WIDTH-1:0] data_int1, data_int2;
28   wire 	    src_rdy_int1, src_rdy_int2, dst_rdy_int1, dst_rdy_int2;
29   wire [SIZE-1:0]  level_wclk, level_rclk;
30   wire [4:0] 	    s1_space, s1_occupied, s2_space, s2_occupied;
31   wire [15:0] 	    l_space, l_occupied;
32
33   fifo_short #(.WIDTH(WIDTH)) shortfifo
34     (.clk(wclk), .reset(arst), .clear(0),
35      .datain(datain), .src_rdy_i(src_rdy_i), .dst_rdy_o(dst_rdy_o),
36      .dataout(data_int1), .src_rdy_o(src_rdy_int1), .dst_rdy_i(dst_rdy_int1),
37      .space(s1_space), .occupied(s1_occupied) );
38
39   fifo_2clock #(.WIDTH(WIDTH),.SIZE(SIZE)) fifo_2clock
40     (.wclk(wclk), .datain(data_int1), .src_rdy_i(src_rdy_int1), .dst_rdy_o(dst_rdy_int1), .space(l_space),
41      .rclk(rclk), .dataout(data_int2), .src_rdy_o(src_rdy_int2), .dst_rdy_i(dst_rdy_int2), .occupied(l_occupied),
42      .arst(arst) );
43
44   fifo_short #(.WIDTH(WIDTH)) shortfifo2
45     (.clk(rclk), .reset(arst), .clear(0),
46      .datain(data_int2), .src_rdy_i(src_rdy_int2), .dst_rdy_o(dst_rdy_int2),
47      .dataout(dataout), .src_rdy_o(src_rdy_o), .dst_rdy_i(dst_rdy_i),
48      .space(s2_space), .occupied(s2_occupied));
49
50   // Be conservative -- Only advertise space from input side of fifo, occupied from output side
51   assign 	    space 	    = {11'b0,s1_space} + l_space;
52   assign 	    occupied 	    = {11'b0,s2_occupied} + l_occupied;
53
54   // For the fifo_extram, we only want to know the immediately adjacent space
55   assign 	    short_space     = {11'b0,s1_space};
56   assign 	    short_occupied  = {11'b0,s2_occupied};
57
58endmodule // fifo_2clock_cascade
59