OpenCores
URL https://opencores.org/ocsvn/sgmii/sgmii/trunk

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [build/] [OpenCore_MAC/] [RMON_ctrl.v] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 jefflieu
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  RMON_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: not supported by cvs2svn $
42
// Revision 1.3  2006/01/19 14:07:55  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
module RMON_CTRL (
53
Clk             ,
54
Reset           ,
55
//RMON_CTRL        
56
Reg_apply_0     ,
57
Reg_addr_0      ,
58
Reg_data_0      ,
59
Reg_next_0      ,
60
Reg_apply_1     ,
61
Reg_addr_1      ,
62
Reg_data_1      ,
63
Reg_next_1      ,
64
//dual-port ram
65
Addra               ,
66
Dina                ,
67
Douta               ,
68
Wea                 ,
69
//CPU                  
70
CPU_rd_addr     ,
71
CPU_rd_apply        ,
72
CPU_rd_grant        ,
73
CPU_rd_dout
74
 
75
);
76
input           Clk             ;
77
input           Reset           ;
78
                //RMON_CTRL
79
input           Reg_apply_0     ;
80
input   [4:0]   Reg_addr_0      ;
81
input   [15:0]  Reg_data_0      ;
82
output          Reg_next_0      ;
83
input           Reg_apply_1     ;
84
input   [4:0]   Reg_addr_1      ;
85
input   [15:0]  Reg_data_1      ;
86
output          Reg_next_1      ;
87
                //dual-port ram 
88
                //port-a for Rmon  
89
output  [5:0]   Addra               ;
90
output  [31:0]  Dina                ;
91
input   [31:0]  Douta               ;
92
output          Wea                 ;
93
                //CPU
94
input   [5:0]   CPU_rd_addr         ;
95
input           CPU_rd_apply        ;
96
output          CPU_rd_grant        ;
97
output  [31:0]  CPU_rd_dout         ;
98
 
99
 
100
 
101
 
102
//******************************************************************************
103
//internal signals                                                              
104
//******************************************************************************
105
 
106
parameter       StateCPU        =4'd00;
107
parameter       StateMAC0       =4'd01;
108
parameter       StateMAC1       =4'd02;
109
 
110
 
111
reg [3:0]       CurrentState /* synthesys syn_keep=1 */;
112
reg [3:0]       NextState;
113
reg [3:0]       CurrentState_reg;
114
 
115
reg [4:0]       StepCounter;
116
reg [31:0]      DoutaReg;
117
reg [5:0]       Addra               ;
118
reg [31:0]      Dina;
119
reg             Reg_next_0      ;
120
reg             Reg_next_1      ;
121
reg             Write;
122
reg             Read;
123
reg             Pipeline;
124
reg [31:0]      CPU_rd_dout         ;
125
reg             CPU_rd_apply_reg    ;
126
//******************************************************************************
127
//State Machine                                                            
128
//******************************************************************************
129
 
130
always @(posedge Clk or posedge Reset)
131
    if (Reset)
132
        CurrentState    <=StateMAC0;
133
    else
134
        CurrentState    <=NextState;
135
 
136
always @(posedge Clk or posedge Reset)
137
    if (Reset)
138
        CurrentState_reg    <=StateMAC0;
139
    else if(CurrentState!=StateCPU)
140
        CurrentState_reg    <=CurrentState;
141
 
142
always @(CurrentState or CPU_rd_apply_reg or Reg_apply_0 or CurrentState_reg
143
                                       or Reg_apply_1
144
                                       or StepCounter
145
                                       )
146
    case(CurrentState)
147
        StateMAC0:
148
            if(!Reg_apply_0&&CPU_rd_apply_reg)
149
                NextState   =StateCPU;
150
            else if(!Reg_apply_0)
151
                NextState   =StateMAC1;
152
            else
153
                NextState   =CurrentState;
154
        StateMAC1:
155
            if(!Reg_apply_1&&CPU_rd_apply_reg)
156
                NextState   =StateCPU;
157
            else if(!Reg_apply_1)
158
                NextState   =StateMAC0;
159
            else
160
                NextState   =CurrentState;
161
        StateCPU:
162
            if (StepCounter==3)
163
                case (CurrentState_reg)
164
                    StateMAC0   :NextState  =StateMAC0 ;
165
                    StateMAC1   :NextState  =StateMAC1 ;
166
                    default     :NextState  =StateMAC0;
167
                endcase
168
            else
169
                NextState   =CurrentState;
170
 
171
        default:
172
                NextState   =StateMAC0;
173
    endcase
174
 
175
 
176
 
177
always @(posedge Clk or posedge Reset)
178
    if (Reset)
179
        StepCounter     <=0;
180
    else if(NextState!=CurrentState)
181
        StepCounter     <=0;
182
    else if (StepCounter!=4'hf)
183
        StepCounter     <=StepCounter + 1;
184
 
185
//******************************************************************************
186
//temp signals                                                            
187
//******************************************************************************
188
always @(StepCounter)
189
    if( StepCounter==1||StepCounter==4||
190
        StepCounter==7||StepCounter==10)
191
        Read    =1;
192
    else
193
        Read    =0;
194
 
195
always @(StepCounter or CurrentState)
196
    if( StepCounter==2||StepCounter==5||
197
        StepCounter==8||StepCounter==11)
198
        Pipeline    =1;
199
    else
200
        Pipeline    =0;
201
 
202
always @(StepCounter or CurrentState)
203
    if( StepCounter==3||StepCounter==6||
204
        StepCounter==9||StepCounter==12)
205
        Write   =1;
206
    else
207
        Write   =0;
208
 
209
always @(posedge Clk or posedge Reset)
210
    if (Reset)
211
        DoutaReg        <=0;
212
    else if (Read)
213
        DoutaReg        <=Douta;
214
 
215
 
216
//******************************************************************************
217
//gen output signals                                                        
218
//******************************************************************************    
219
//Addra 
220
always @(*)
221
    case(CurrentState)
222
        StateMAC0 :     Addra={1'd0 ,Reg_addr_0 };
223
        StateMAC1 :     Addra={1'd1 ,Reg_addr_1 };
224
        StateCPU:       Addra=CPU_rd_addr;
225
        default:        Addra=0;
226
        endcase
227
 
228
//Dina
229
always @(posedge Clk or posedge Reset)
230
    if (Reset)
231
        Dina    <=0;
232
    else
233
        case(CurrentState)
234
            StateMAC0 :     Dina<=Douta+Reg_data_0 ;
235
            StateMAC1 :     Dina<=Douta+Reg_data_1 ;
236
            StateCPU:       Dina<=0;
237
            default:        Dina<=0;
238
        endcase
239
 
240
assign  Wea     =Write;
241
//Reg_next
242
always @(CurrentState or Pipeline)
243
    if(CurrentState==StateMAC0)
244
        Reg_next_0  =Pipeline;
245
    else
246
        Reg_next_0  =0;
247
 
248
always @(CurrentState or Pipeline)
249
    if(CurrentState==StateMAC1)
250
        Reg_next_1  =Pipeline;
251
    else
252
        Reg_next_1  =0;
253
 
254
 
255
//CPU_rd_grant   
256
reg     CPU_rd_apply_dl1;
257
reg     CPU_rd_apply_dl2;
258
//rising edge
259
always @ (posedge Clk or posedge Reset)
260
    if (Reset)
261
        begin
262
        CPU_rd_apply_dl1        <=0;
263
        CPU_rd_apply_dl2        <=0;
264
        end
265
    else
266
        begin
267
        CPU_rd_apply_dl1        <=CPU_rd_apply;
268
        CPU_rd_apply_dl2        <=CPU_rd_apply_dl1;
269
        end
270
 
271
always @ (posedge Clk or posedge Reset)
272
    if (Reset)
273
        CPU_rd_apply_reg    <=0;
274
    else if (CPU_rd_apply_dl1&!CPU_rd_apply_dl2)
275
        CPU_rd_apply_reg    <=1;
276
    else if (CurrentState==StateCPU&&Write)
277
        CPU_rd_apply_reg    <=0;
278
 
279
assign CPU_rd_grant =!CPU_rd_apply_reg;
280
 
281
always @ (posedge Clk or posedge Reset)
282
    if (Reset)
283
        CPU_rd_dout     <=0;
284
    else if (Pipeline&&CurrentState==StateCPU)
285
        CPU_rd_dout     <=Douta;
286
 
287
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.