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 19 20module serdes_fc_rx 21 #(parameter LWMARK = 64, 22 parameter HWMARK = 320) 23 (input clk, input rst, 24 input [15:0] fifo_space, 25 output reg send_xon, 26 output reg send_xoff, 27 input sent); 28 29 reg [15:0] countdown; 30 reg send_xon_int, send_xoff_int; 31 32 always @(posedge clk) 33 if(rst) 34 begin 35 send_xon_int <= 0; 36 send_xoff_int <= 0; 37 countdown <= 0; 38 end 39 else 40 begin 41 send_xon_int <= 0; 42 send_xoff_int <= 0; 43 if(countdown == 0) 44 if(fifo_space < LWMARK) 45 begin 46 send_xoff_int <= 1; 47 countdown <= 240; 48 end 49 else 50 ; 51 else 52 if(fifo_space > HWMARK) 53 begin 54 send_xon_int <= 1; 55 countdown <= 0; 56 end 57 else 58 countdown <= countdown - 1; 59 end // else: !if(rst) 60 61 // If we are between the high and low water marks, we let the countdown expire 62 63 always @(posedge clk) 64 if(rst) 65 send_xon <= 0; 66 else if(send_xon_int) 67 send_xon <= 1; 68 else if(sent) 69 send_xon <= 0; 70 71 always @(posedge clk) 72 if(rst) 73 send_xoff <= 0; 74 else if(send_xoff_int) 75 send_xoff <= 1; 76 else if(sent) 77 send_xoff <= 0; 78 79endmodule // serdes_fc_rx 80