1 //////////////////////////////////////////////////////////////////////
\r
3 //// RMON_ctrl.v ////
\r
5 //// This file is part of the Ethernet IP core project ////
\r
6 //// http://www.opencores.org/projects.cgi/web/ethernet_tri_mode/////
\r
9 //// - Jon Gao (gaojon@yahoo.com) ////
\r
12 //////////////////////////////////////////////////////////////////////
\r
14 //// Copyright (C) 2001 Authors ////
\r
16 //// This source file may be used and distributed without ////
\r
17 //// restriction provided that this copyright statement is not ////
\r
18 //// removed from the file and that any derivative work contains ////
\r
19 //// the original copyright notice and the associated disclaimer. ////
\r
21 //// This source file is free software; you can redistribute it ////
\r
22 //// and/or modify it under the terms of the GNU Lesser General ////
\r
23 //// Public License as published by the Free Software Foundation; ////
\r
24 //// either version 2.1 of the License, or (at your option) any ////
\r
25 //// later version. ////
\r
27 //// This source is distributed in the hope that it will be ////
\r
28 //// useful, but WITHOUT ANY WARRANTY; without even the implied ////
\r
29 //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
\r
30 //// PURPOSE. See the GNU Lesser General Public License for more ////
\r
33 //// You should have received a copy of the GNU Lesser General ////
\r
34 //// Public License along with this source; if not, download it ////
\r
35 //// from http://www.opencores.org/lgpl.shtml ////
\r
37 //////////////////////////////////////////////////////////////////////
\r
39 // CVS Revision History
\r
41 // $Log: RMON_ctrl.v,v $
\r
42 // Revision 1.4 2006/06/25 04:58:57 maverickist
\r
45 // Revision 1.3 2006/01/19 14:07:55 maverickist
\r
46 // verification is complete.
\r
48 // Revision 1.2 2005/12/16 06:44:19 Administrator
\r
49 // replaced tab with space.
\r
50 // passed 9.6k length frame test.
\r
52 // Revision 1.1.1.1 2005/12/13 01:51:45 Administrator
\r
83 input [4:0] Reg_addr_0 ;
\r
84 input [15:0] Reg_data_0 ;
\r
87 input [4:0] Reg_addr_1 ;
\r
88 input [15:0] Reg_data_1 ;
\r
92 output [5:0] Addra ;
\r
93 output [31:0] Dina ;
\r
94 input [31:0] Douta ;
\r
97 input [5:0] CPU_rd_addr ;
\r
98 input CPU_rd_apply ;
\r
99 output CPU_rd_grant ;
\r
100 output [31:0] CPU_rd_dout ;
\r
105 //******************************************************************************
\r
106 //internal signals
\r
107 //******************************************************************************
\r
109 parameter StateCPU =4'd00;
\r
110 parameter StateMAC0 =4'd01;
\r
111 parameter StateMAC1 =4'd02;
\r
114 reg [3:0] CurrentState /* synthesys syn_keep=1 */;
\r
115 reg [3:0] NextState;
\r
116 reg [3:0] CurrentState_reg;
\r
118 reg [4:0] StepCounter;
\r
126 reg [31:0] CPU_rd_dout ;
\r
127 reg CPU_rd_apply_reg ;
\r
128 //******************************************************************************
\r
130 //******************************************************************************
\r
132 always @(posedge Clk or posedge Reset)
\r
134 CurrentState <=StateMAC0;
\r
136 CurrentState <=NextState;
\r
138 always @(posedge Clk or posedge Reset)
\r
140 CurrentState_reg <=StateMAC0;
\r
141 else if(CurrentState!=StateCPU)
\r
142 CurrentState_reg <=CurrentState;
\r
144 always @(CurrentState or CPU_rd_apply_reg or Reg_apply_0 or CurrentState_reg
\r
150 if(!Reg_apply_0&&CPU_rd_apply_reg)
\r
151 NextState =StateCPU;
\r
152 else if(!Reg_apply_0)
\r
153 NextState =StateMAC1;
\r
155 NextState =CurrentState;
\r
157 if(!Reg_apply_1&&CPU_rd_apply_reg)
\r
158 NextState =StateCPU;
\r
159 else if(!Reg_apply_1)
\r
160 NextState =StateMAC0;
\r
162 NextState =CurrentState;
\r
164 if (StepCounter==3)
\r
165 case (CurrentState_reg)
\r
166 StateMAC0 :NextState =StateMAC0 ;
\r
167 StateMAC1 :NextState =StateMAC1 ;
\r
168 default :NextState =StateMAC0;
\r
171 NextState =CurrentState;
\r
174 NextState =StateMAC0;
\r
179 always @(posedge Clk or posedge Reset)
\r
182 else if(NextState!=CurrentState)
\r
184 else if (StepCounter!=4'hf)
\r
185 StepCounter <=StepCounter + 1;
\r
187 //******************************************************************************
\r
189 //******************************************************************************
\r
190 always @(StepCounter)
\r
191 if( StepCounter==1||StepCounter==4||
\r
192 StepCounter==7||StepCounter==10)
\r
197 always @(StepCounter or CurrentState)
\r
198 if( StepCounter==2||StepCounter==5||
\r
199 StepCounter==8||StepCounter==11)
\r
204 always @(StepCounter or CurrentState)
\r
205 if( StepCounter==3||StepCounter==6||
\r
206 StepCounter==9||StepCounter==12)
\r
212 //******************************************************************************
\r
213 //gen output signals
\r
214 //******************************************************************************
\r
218 StateMAC0 : Addra={1'd0 ,Reg_addr_0 };
\r
219 StateMAC1 : Addra={1'd1 ,Reg_addr_1 };
\r
220 StateCPU: Addra=CPU_rd_addr;
\r
225 always @(posedge Clk or posedge Reset)
\r
230 StateMAC0 : Dina<=Douta+Reg_data_0 ;
\r
231 StateMAC1 : Dina<=Douta+Reg_data_1 ;
\r
238 always @(CurrentState or Pipeline)
\r
239 if(CurrentState==StateMAC0)
\r
240 Reg_next_0 =Pipeline;
\r
244 always @(CurrentState or Pipeline)
\r
245 if(CurrentState==StateMAC1)
\r
246 Reg_next_1 =Pipeline;
\r
252 reg CPU_rd_apply_dl1;
\r
253 reg CPU_rd_apply_dl2;
\r
255 always @ (posedge Clk or posedge Reset)
\r
258 CPU_rd_apply_dl1 <=0;
\r
259 CPU_rd_apply_dl2 <=0;
\r
263 CPU_rd_apply_dl1 <=CPU_rd_apply;
\r
264 CPU_rd_apply_dl2 <=CPU_rd_apply_dl1;
\r
267 always @ (posedge Clk or posedge Reset)
\r
269 CPU_rd_apply_reg <=0;
\r
270 else if (CPU_rd_apply_dl1&!CPU_rd_apply_dl2)
\r
271 CPU_rd_apply_reg <=1;
\r
272 else if (CurrentState==StateCPU&&Write)
\r
273 CPU_rd_apply_reg <=0;
\r
275 assign CPU_rd_grant = CPU_rd_apply & CPU_rd_apply_dl1 & CPU_rd_apply_dl2 & !CPU_rd_apply_reg;
\r
277 always @ (posedge Clk or posedge Reset)
\r
280 else if (Pipeline&&CurrentState==StateCPU)
\r
281 CPU_rd_dout <=Douta;
\r