Merged r9433:9527 from features/gr-usrp2 into trunk. Adds usrp2 and gr-usrp2 top...
[debian/gnuradio] / usrp2 / fpga / opencores / ethernet_tri_mode / rtl / verilog / MAC_tx / flow_ctrl.v
1 //////////////////////////////////////////////////////////////////////
2 ////                                                              ////
3 ////  flow_ctrl.v                                                 ////
4 ////                                                              ////
5 ////  This file is part of the Ethernet IP core project           ////
6 ////  http://www.opencores.org/projects.cgi/web/ethernet_tri_mode/////
7 ////                                                              ////
8 ////  Author(s):                                                  ////
9 ////      - Jon Gao (gaojon@yahoo.com)                            ////
10 ////                                                              ////
11 ////                                                              ////
12 //////////////////////////////////////////////////////////////////////
13 ////                                                              ////
14 //// Copyright (C) 2001 Authors                                   ////
15 ////                                                              ////
16 //// This source file may be used and distributed without         ////
17 //// restriction provided that this copyright statement is not    ////
18 //// removed from the file and that any derivative work contains  ////
19 //// the original copyright notice and the associated disclaimer. ////
20 ////                                                              ////
21 //// This source file is free software; you can redistribute it   ////
22 //// and/or modify it under the terms of the GNU Lesser General   ////
23 //// Public License as published by the Free Software Foundation; ////
24 //// either version 2.1 of the License, or (at your option) any   ////
25 //// later version.                                               ////
26 ////                                                              ////
27 //// This source is distributed in the hope that it will be       ////
28 //// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
29 //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
30 //// PURPOSE.  See the GNU Lesser General Public License for more ////
31 //// details.                                                     ////
32 ////                                                              ////
33 //// You should have received a copy of the GNU Lesser General    ////
34 //// Public License along with this source; if not, download it   ////
35 //// from http://www.opencores.org/lgpl.shtml                     ////
36 ////                                                              ////
37 //////////////////////////////////////////////////////////////////////
38 //                                                                    
39 // CVS Revision History                                               
40 //                                                                    
41 // $Log: flow_ctrl.v,v $
42 // Revision 1.3  2006/01/19 14:07:54  maverickist
43 // verification is complete.
44 //
45 // Revision 1.2  2005/12/16 06:44:19  Administrator
46 // replaced tab with space.
47 // passed 9.6k length frame test.
48 //
49 // Revision 1.1.1.1  2005/12/13 01:51:45  Administrator
50 // no message
51 //                                           
52
53 module flow_ctrl 
54 (
55 Reset               ,
56 Clk                 ,
57 //host processor    ,
58 tx_pause_en         ,
59 xoff_cpu            ,
60 xon_cpu             ,
61 //MAC_rx_flow       ,
62 pause_quanta        ,
63 pause_quanta_val    ,
64 //MAC_tx_ctrl       ,
65 pause_apply         ,
66 pause_quanta_sub    ,
67 xoff_gen            ,
68 xoff_gen_complete   ,
69 xon_gen             ,
70 xon_gen_complete    
71
72 );
73
74 input           Reset               ;
75 input           Clk                 ;
76                 //host processor    ;
77 input           tx_pause_en         ;
78 input           xoff_cpu            ;
79 input           xon_cpu             ;
80                 //MAC_rx_flow       ;
81 input   [15:0]  pause_quanta        ;
82 input           pause_quanta_val    ;
83                 //MAC_tx_ctrl       ;
84 output          pause_apply         ;
85 input           pause_quanta_sub    ;
86 output          xoff_gen            ;
87 input           xoff_gen_complete   ;
88 output          xon_gen             ;
89 input           xon_gen_complete    ;
90   
91 //******************************************************************************
92 //internal signals                                                              
93 //******************************************************************************  
94 reg             xoff_cpu_dl1            ;
95 reg             xoff_cpu_dl2            ;
96 reg             xon_cpu_dl1             ;   
97 reg             xon_cpu_dl2             ;
98 reg [15:0]      pause_quanta_dl1        ;
99 reg             pause_quanta_val_dl1    ;
100 reg             pause_quanta_val_dl2    ;       
101 reg             pause_apply             ;
102 reg             xoff_gen                ;
103 reg             xon_gen                 ;
104 reg [15:0]      pause_quanta_counter    ;
105 reg             tx_pause_en_dl1         ;
106 reg             tx_pause_en_dl2         ;
107 //******************************************************************************  
108 //boundery signal processing                                                               
109 //******************************************************************************
110 always @ (posedge Clk or posedge Reset)
111     if (Reset)
112         begin
113         xoff_cpu_dl1        <=0;
114         xoff_cpu_dl2        <=0;
115         end
116     else
117         begin
118         xoff_cpu_dl1        <=xoff_cpu;
119         xoff_cpu_dl2        <=xoff_cpu_dl1;
120         end
121
122 always @ (posedge Clk or posedge Reset)
123     if (Reset)
124         begin
125         xon_cpu_dl1     <=0;
126         xon_cpu_dl2     <=0;
127         end
128     else
129         begin
130         xon_cpu_dl1     <=xon_cpu;
131         xon_cpu_dl2     <=xon_cpu_dl1;
132         end     
133         
134 always @ (posedge Clk or posedge Reset)
135     if (Reset)
136         begin
137         pause_quanta_dl1        <=0;
138         end
139     else
140         begin
141         pause_quanta_dl1        <=pause_quanta;
142         end  
143        
144 always @ (posedge Clk or posedge Reset)
145     if (Reset)
146         begin
147         pause_quanta_val_dl1    <=0;
148         pause_quanta_val_dl2    <=0;
149         end
150     else
151         begin
152         pause_quanta_val_dl1    <=pause_quanta_val;
153         pause_quanta_val_dl2    <=pause_quanta_val_dl1;
154         end                      
155         
156 always @ (posedge Clk or posedge Reset)
157     if (Reset)
158         begin           
159         tx_pause_en_dl1     <=0;
160         tx_pause_en_dl2     <=0; 
161         end
162     else
163         begin           
164         tx_pause_en_dl1     <=tx_pause_en;
165         tx_pause_en_dl2     <=tx_pause_en_dl1; 
166         end     
167
168 //******************************************************************************        
169 //gen output signals                                                            
170 //******************************************************************************
171 always @ (posedge Clk or posedge Reset)
172     if (Reset)
173         xoff_gen        <=0;
174     else if (xoff_gen_complete)
175         xoff_gen        <=0;
176     else if (xoff_cpu_dl1&&!xoff_cpu_dl2)
177         xoff_gen        <=1;
178
179 always @ (posedge Clk or posedge Reset)
180     if (Reset)
181         xon_gen     <=0;
182     else if (xon_gen_complete)
183         xon_gen     <=0;
184     else if (xon_cpu_dl1&&!xon_cpu_dl2)
185         xon_gen     <=1;                     
186
187 always @ (posedge Clk or posedge Reset)
188     if (Reset)
189         pause_quanta_counter    <=0;
190     else if(pause_quanta_val_dl1&&!pause_quanta_val_dl2)
191         pause_quanta_counter    <=pause_quanta_dl1; 
192     else if(pause_quanta_sub&&pause_quanta_counter!=0)
193         pause_quanta_counter    <=pause_quanta_counter-1;
194         
195 always @ (posedge Clk or posedge Reset)
196     if (Reset)
197         pause_apply     <=0;
198     else if(pause_quanta_counter==0)
199         pause_apply     <=0;
200     else if (tx_pause_en_dl2)
201         pause_apply     <=1;
202         
203 endmodule