Fix warnings, mostly from implicitly defined wires or unspecified widths
[debian/gnuradio] / usrp2 / fpga / simple_gemac / flow_ctrl_rx.v
1 \r
2 // RX side of flow control -- when we are running out of RX space, send a PAUSE\r
3 \r
4 module flow_ctrl_rx\r
5   (input pause_request_en, input [15:0] pause_time, input [15:0] pause_thresh,\r
6    input rx_clk, input rx_reset, input [15:0] rx_fifo_space,\r
7    input tx_clk, input tx_reset, output reg pause_req, output reg [15:0] pause_time_req\r
8    );\r
9    \r
10    // ******************************************************************************        \r
11    // Force our TX to send a PAUSE frame because our RX is nearly full\r
12    // ******************************************************************************\r
13 \r
14    // RX Clock Domain\r
15    reg xon, xoff;\r
16    reg [21:0] countdown;\r
17 \r
18    wire [15:0] pause_low_thresh = pause_thresh;\r
19    wire [15:0] pause_hi_thresh = 16'hFFFF;\r
20    wire [21:0] pq_reduced = {pause_time,6'd0} - 1700;\r
21    \r
22    always @(posedge rx_clk)\r
23      if(rx_reset)\r
24        xoff <= 0;\r
25      else\r
26        xoff <= (pause_request_en & (countdown==0) & (rx_fifo_space < pause_low_thresh));\r
27    \r
28    always @(posedge rx_clk)\r
29      if(rx_reset)\r
30        xon  <= 0;\r
31      else\r
32        xon  <= ((countdown!=0) & (rx_fifo_space > pause_hi_thresh));\r
33    \r
34    always @(posedge rx_clk)\r
35      if(rx_reset)\r
36        countdown <= 0;\r
37      else if(xoff)\r
38        countdown <= pq_reduced;\r
39      else if(xon)\r
40        countdown <= 0;\r
41      else if(countdown != 0)\r
42        countdown <= countdown - 1;\r
43 \r
44    // Cross clock domains\r
45    wire        xon_tx, xoff_tx;\r
46    oneshot_2clk send_xon (.clk_in(rx_clk), .in(xon), .clk_out(tx_clk), .out(xon_tx));\r
47    oneshot_2clk send_xoff (.clk_in(rx_clk), .in(xoff), .clk_out(tx_clk), .out(xoff_tx));\r
48    \r
49    always @(posedge tx_clk)\r
50      if(xoff_tx)\r
51        pause_time_req <= pause_time;\r
52      else if(xon_tx)\r
53        pause_time_req <= 0;\r
54 \r
55    always @(posedge tx_clk)\r
56      if(tx_reset)\r
57        pause_req      <= 0;\r
58      else \r
59        pause_req      <= xon_tx | xoff_tx;\r
60    \r
61 endmodule // flow_ctrl_rx\r