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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [ethmac/] [eth_miim.v] - Blame information for rev 426

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_miim.v                                                  ////
4
////                                                              ////
5
////  This file is part of the Ethernet IP core project           ////
6 409 julius
////  http://www.opencores.org/project,ethmac                   ////
7 6 julius
////                                                              ////
8
////  Author(s):                                                  ////
9
////      - Igor Mohor (igorM@opencores.org)                      ////
10
////                                                              ////
11
////  All additional information is avaliable in the Readme.txt   ////
12
////  file.                                                       ////
13
////                                                              ////
14
//////////////////////////////////////////////////////////////////////
15
////                                                              ////
16
//// Copyright (C) 2001 Authors                                   ////
17
////                                                              ////
18
//// This source file may be used and distributed without         ////
19
//// restriction provided that this copyright statement is not    ////
20
//// removed from the file and that any derivative work contains  ////
21
//// the original copyright notice and the associated disclaimer. ////
22
////                                                              ////
23
//// This source file is free software; you can redistribute it   ////
24
//// and/or modify it under the terms of the GNU Lesser General   ////
25
//// Public License as published by the Free Software Foundation; ////
26
//// either version 2.1 of the License, or (at your option) any   ////
27
//// later version.                                               ////
28
////                                                              ////
29
//// This source is distributed in the hope that it will be       ////
30
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
31
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
32
//// PURPOSE.  See the GNU Lesser General Public License for more ////
33
//// details.                                                     ////
34
////                                                              ////
35
//// You should have received a copy of the GNU Lesser General    ////
36
//// Public License along with this source; if not, download it   ////
37
//// from http://www.opencores.org/lgpl.shtml                     ////
38
////                                                              ////
39
//////////////////////////////////////////////////////////////////////
40
//
41
// CVS Revision History
42
//
43 403 julius
// $Log: not supported by cvs2svn $
44 6 julius
// Revision 1.6  2005/02/21 12:48:07  igorm
45
// Warning fixes.
46
//
47
// Revision 1.5  2003/05/16 10:08:27  mohor
48
// Busy was set 2 cycles too late. Reported by Dennis Scott.
49
//
50
// Revision 1.4  2002/08/14 18:32:10  mohor
51
// - Busy signal was not set on time when scan status operation was performed
52
// and clock was divided with more than 2.
53
// - Nvalid remains valid two more clocks (was previously cleared too soon).
54
//
55
// Revision 1.3  2002/01/23 10:28:16  mohor
56
// Link in the header changed.
57
//
58
// Revision 1.2  2001/10/19 08:43:51  mohor
59
// eth_timescale.v changed to timescale.v This is done because of the
60
// simulation of the few cores in a one joined project.
61
//
62
// Revision 1.1  2001/08/06 14:44:29  mohor
63
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
64
// Include files fixed to contain no path.
65
// File names and module names changed ta have a eth_ prologue in the name.
66
// File eth_timescale.v is used to define timescale
67
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
68
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
69
// and Mdo_OE. The bidirectional signal must be created on the top level. This
70
// is done due to the ASIC tools.
71
//
72
// Revision 1.2  2001/08/02 09:25:31  mohor
73
// Unconnected signals are now connected.
74
//
75
// Revision 1.1  2001/07/30 21:23:42  mohor
76
// Directory structure changed. Files checked and joind together.
77
//
78
// Revision 1.3  2001/06/01 22:28:56  mohor
79
// This files (MIIM) are fully working. They were thoroughly tested. The testbench is not updated.
80
//
81
//
82
 
83
`include "timescale.v"
84
 
85
 
86
module eth_miim
87
(
88
  Clk,
89
  Reset,
90
  Divider,
91
  NoPre,
92
  CtrlData,
93
  Rgad,
94
  Fiad,
95
  WCtrlData,
96
  RStat,
97
  ScanStat,
98
  Mdi,
99
  Mdo,
100
  MdoEn,
101
  Mdc,
102
  Busy,
103
  Prsd,
104
  LinkFail,
105
  Nvalid,
106
  WCtrlDataStart,
107
  RStatStart,
108
  UpdateMIIRX_DATAReg
109
);
110
 
111
 
112
 
113
input         Clk;                // Host Clock
114
input         Reset;              // General Reset
115
input   [7:0] Divider;            // Divider for the host clock
116
input  [15:0] CtrlData;           // Control Data (to be written to the PHY reg.)
117
input   [4:0] Rgad;               // Register Address (within the PHY)
118
input   [4:0] Fiad;               // PHY Address
119
input         NoPre;              // No Preamble (no 32-bit preamble)
120
input         WCtrlData;          // Write Control Data operation
121
input         RStat;              // Read Status operation
122
input         ScanStat;           // Scan Status operation
123
input         Mdi;                // MII Management Data In
124
 
125
output        Mdc;                // MII Management Data Clock
126
output        Mdo;                // MII Management Data Output
127
output        MdoEn;              // MII Management Data Output Enable
128
output        Busy;               // Busy Signal
129
output        LinkFail;           // Link Integrity Signal
130
output        Nvalid;             // Invalid Status (qualifier for the valid scan result)
131
 
132
output [15:0] Prsd;               // Read Status Data (data read from the PHY)
133
 
134
output        WCtrlDataStart;     // This signals resets the WCTRLDATA bit in the MIIM Command register
135
output        RStatStart;         // This signal resets the RSTAT BIT in the MIIM Command register
136
output        UpdateMIIRX_DATAReg;// Updates MII RX_DATA register with read data
137
 
138
parameter Tp = 1;
139
 
140
 
141
reg           Nvalid;
142
reg           EndBusy_d;          // Pre-end Busy signal
143
reg           EndBusy;            // End Busy signal (stops the operation in progress)
144
 
145
reg           WCtrlData_q1;       // Write Control Data operation delayed 1 Clk cycle
146
reg           WCtrlData_q2;       // Write Control Data operation delayed 2 Clk cycles
147
reg           WCtrlData_q3;       // Write Control Data operation delayed 3 Clk cycles
148
reg           WCtrlDataStart;     // Start Write Control Data Command (positive edge detected)
149
reg           WCtrlDataStart_q;
150
reg           WCtrlDataStart_q1;  // Start Write Control Data Command delayed 1 Mdc cycle
151
reg           WCtrlDataStart_q2;  // Start Write Control Data Command delayed 2 Mdc cycles
152
 
153
reg           RStat_q1;           // Read Status operation delayed 1 Clk cycle
154
reg           RStat_q2;           // Read Status operation delayed 2 Clk cycles
155
reg           RStat_q3;           // Read Status operation delayed 3 Clk cycles
156
reg           RStatStart;         // Start Read Status Command (positive edge detected)
157
reg           RStatStart_q1;      // Start Read Status Command delayed 1 Mdc cycle
158
reg           RStatStart_q2;      // Start Read Status Command delayed 2 Mdc cycles
159
 
160
reg           ScanStat_q1;        // Scan Status operation delayed 1 cycle
161
reg           ScanStat_q2;        // Scan Status operation delayed 2 cycles
162
reg           SyncStatMdcEn;      // Scan Status operation delayed at least cycles and synchronized to MdcEn
163
 
164
wire          WriteDataOp;        // Write Data Operation (positive edge detected)
165
wire          ReadStatusOp;       // Read Status Operation (positive edge detected)
166
wire          ScanStatusOp;       // Scan Status Operation (positive edge detected)
167
wire          StartOp;            // Start Operation (start of any of the preceding operations)
168
wire          EndOp;              // End of Operation
169
 
170
reg           InProgress;         // Operation in progress
171
reg           InProgress_q1;      // Operation in progress delayed 1 Mdc cycle
172
reg           InProgress_q2;      // Operation in progress delayed 2 Mdc cycles
173
reg           InProgress_q3;      // Operation in progress delayed 3 Mdc cycles
174
 
175
reg           WriteOp;            // Write Operation Latch (When asserted, write operation is in progress)
176
reg     [6:0] BitCounter;         // Bit Counter
177
 
178
 
179
wire    [3:0] ByteSelect;         // Byte Select defines which byte (preamble, data, operation, etc.) is loaded and shifted through the shift register.
180
wire          MdcEn;              // MII Management Data Clock Enable signal is asserted for one Clk period before Mdc rises.
181
wire          ShiftedBit;         // This bit is output of the shift register and is connected to the Mdo signal
182
wire          MdcEn_n;
183
 
184
wire          LatchByte1_d2;
185
wire          LatchByte0_d2;
186
reg           LatchByte1_d;
187
reg           LatchByte0_d;
188
reg     [1:0] LatchByte;          // Latch Byte selects which part of Read Status Data is updated from the shift register
189
 
190
reg           UpdateMIIRX_DATAReg;// Updates MII RX_DATA register with read data
191
 
192
 
193
 
194
 
195
 
196
// Generation of the EndBusy signal. It is used for ending the MII Management operation.
197
always @ (posedge Clk or posedge Reset)
198
begin
199
  if(Reset)
200
    begin
201 403 julius
      EndBusy_d <=  1'b0;
202
      EndBusy <=  1'b0;
203 6 julius
    end
204
  else
205
    begin
206 403 julius
      EndBusy_d <=  ~InProgress_q2 & InProgress_q3;
207
      EndBusy   <=  EndBusy_d;
208 6 julius
    end
209
end
210
 
211
 
212
// Update MII RX_DATA register
213
always @ (posedge Clk or posedge Reset)
214
begin
215
  if(Reset)
216 403 julius
    UpdateMIIRX_DATAReg <=  0;
217 6 julius
  else
218
  if(EndBusy & ~WCtrlDataStart_q)
219 403 julius
    UpdateMIIRX_DATAReg <=  1;
220 6 julius
  else
221 403 julius
    UpdateMIIRX_DATAReg <=  0;
222 6 julius
end
223
 
224
 
225
 
226
// Generation of the delayed signals used for positive edge triggering.
227
always @ (posedge Clk or posedge Reset)
228
begin
229
  if(Reset)
230
    begin
231 403 julius
      WCtrlData_q1 <=  1'b0;
232
      WCtrlData_q2 <=  1'b0;
233
      WCtrlData_q3 <=  1'b0;
234 6 julius
 
235 403 julius
      RStat_q1 <=  1'b0;
236
      RStat_q2 <=  1'b0;
237
      RStat_q3 <=  1'b0;
238 6 julius
 
239 403 julius
      ScanStat_q1  <=  1'b0;
240
      ScanStat_q2  <=  1'b0;
241
      SyncStatMdcEn <=  1'b0;
242 6 julius
    end
243
  else
244
    begin
245 403 julius
      WCtrlData_q1 <=  WCtrlData;
246
      WCtrlData_q2 <=  WCtrlData_q1;
247
      WCtrlData_q3 <=  WCtrlData_q2;
248 6 julius
 
249 403 julius
      RStat_q1 <=  RStat;
250
      RStat_q2 <=  RStat_q1;
251
      RStat_q3 <=  RStat_q2;
252 6 julius
 
253 403 julius
      ScanStat_q1  <=  ScanStat;
254
      ScanStat_q2  <=  ScanStat_q1;
255 6 julius
      if(MdcEn)
256 403 julius
        SyncStatMdcEn  <=  ScanStat_q2;
257 6 julius
    end
258
end
259
 
260
 
261
// Generation of the Start Commands (Write Control Data or Read Status)
262
always @ (posedge Clk or posedge Reset)
263
begin
264
  if(Reset)
265
    begin
266 403 julius
      WCtrlDataStart <=  1'b0;
267
      WCtrlDataStart_q <=  1'b0;
268
      RStatStart <=  1'b0;
269 6 julius
    end
270
  else
271
    begin
272
      if(EndBusy)
273
        begin
274 403 julius
          WCtrlDataStart <=  1'b0;
275
          RStatStart <=  1'b0;
276 6 julius
        end
277
      else
278
        begin
279
          if(WCtrlData_q2 & ~WCtrlData_q3)
280 403 julius
            WCtrlDataStart <=  1'b1;
281 6 julius
          if(RStat_q2 & ~RStat_q3)
282 403 julius
            RStatStart <=  1'b1;
283
          WCtrlDataStart_q <=  WCtrlDataStart;
284 6 julius
        end
285
    end
286
end
287
 
288
 
289
// Generation of the Nvalid signal (indicates when the status is invalid)
290
always @ (posedge Clk or posedge Reset)
291
begin
292
  if(Reset)
293 403 julius
    Nvalid <=  1'b0;
294 6 julius
  else
295
    begin
296
      if(~InProgress_q2 & InProgress_q3)
297
        begin
298 403 julius
          Nvalid <=  1'b0;
299 6 julius
        end
300
      else
301
        begin
302
          if(ScanStat_q2  & ~SyncStatMdcEn)
303 403 julius
            Nvalid <=  1'b1;
304 6 julius
        end
305
    end
306
end
307
 
308
// Signals used for the generation of the Operation signals (positive edge)
309
always @ (posedge Clk or posedge Reset)
310
begin
311
  if(Reset)
312
    begin
313 403 julius
      WCtrlDataStart_q1 <=  1'b0;
314
      WCtrlDataStart_q2 <=  1'b0;
315 6 julius
 
316 403 julius
      RStatStart_q1 <=  1'b0;
317
      RStatStart_q2 <=  1'b0;
318 6 julius
 
319 403 julius
      InProgress_q1 <=  1'b0;
320
      InProgress_q2 <=  1'b0;
321
      InProgress_q3 <=  1'b0;
322 6 julius
 
323 403 julius
          LatchByte0_d <=  1'b0;
324
          LatchByte1_d <=  1'b0;
325 6 julius
 
326 403 julius
          LatchByte <=  2'b00;
327 6 julius
    end
328
  else
329
    begin
330
      if(MdcEn)
331
        begin
332 403 julius
          WCtrlDataStart_q1 <=  WCtrlDataStart;
333
          WCtrlDataStart_q2 <=  WCtrlDataStart_q1;
334 6 julius
 
335 403 julius
          RStatStart_q1 <=  RStatStart;
336
          RStatStart_q2 <=  RStatStart_q1;
337 6 julius
 
338 403 julius
          LatchByte[0] <=  LatchByte0_d;
339
          LatchByte[1] <=  LatchByte1_d;
340 6 julius
 
341 403 julius
          LatchByte0_d <=  LatchByte0_d2;
342
          LatchByte1_d <=  LatchByte1_d2;
343 6 julius
 
344 403 julius
          InProgress_q1 <=  InProgress;
345
          InProgress_q2 <=  InProgress_q1;
346
          InProgress_q3 <=  InProgress_q2;
347 6 julius
        end
348
    end
349
end
350
 
351
 
352
// Generation of the Operation signals
353
assign WriteDataOp  = WCtrlDataStart_q1 & ~WCtrlDataStart_q2;
354
assign ReadStatusOp = RStatStart_q1     & ~RStatStart_q2;
355
assign ScanStatusOp = SyncStatMdcEn     & ~InProgress & ~InProgress_q1 & ~InProgress_q2;
356
assign StartOp      = WriteDataOp | ReadStatusOp | ScanStatusOp;
357
 
358
// Busy
359
assign Busy = WCtrlData | WCtrlDataStart | RStat | RStatStart | SyncStatMdcEn | EndBusy | InProgress | InProgress_q3 | Nvalid;
360
 
361
 
362
// Generation of the InProgress signal (indicates when an operation is in progress)
363
// Generation of the WriteOp signal (indicates when a write is in progress)
364
always @ (posedge Clk or posedge Reset)
365
begin
366
  if(Reset)
367
    begin
368 403 julius
      InProgress <=  1'b0;
369
      WriteOp <=  1'b0;
370 6 julius
    end
371
  else
372
    begin
373
      if(MdcEn)
374
        begin
375
          if(StartOp)
376
            begin
377
              if(~InProgress)
378 403 julius
                WriteOp <=  WriteDataOp;
379
              InProgress <=  1'b1;
380 6 julius
            end
381
          else
382
            begin
383
              if(EndOp)
384
                begin
385 403 julius
                  InProgress <=  1'b0;
386
                  WriteOp <=  1'b0;
387 6 julius
                end
388
            end
389
        end
390
    end
391
end
392
 
393
 
394
 
395
// Bit Counter counts from 0 to 63 (from 32 to 63 when NoPre is asserted)
396
always @ (posedge Clk or posedge Reset)
397
begin
398
  if(Reset)
399 403 julius
    BitCounter[6:0] <=  7'h0;
400 6 julius
  else
401
    begin
402
      if(MdcEn)
403
        begin
404
          if(InProgress)
405
            begin
406
              if(NoPre & ( BitCounter == 7'h0 ))
407 403 julius
                BitCounter[6:0] <=  7'h21;
408 6 julius
              else
409 403 julius
                BitCounter[6:0] <=  BitCounter[6:0] + 1'b1;
410 6 julius
            end
411
          else
412 403 julius
            BitCounter[6:0] <=  7'h0;
413 6 julius
        end
414
    end
415
end
416
 
417
 
418
// Operation ends when the Bit Counter reaches 63
419
assign EndOp = BitCounter==63;
420
 
421
assign ByteSelect[0] = InProgress & ((NoPre & (BitCounter == 7'h0)) | (~NoPre & (BitCounter == 7'h20)));
422
assign ByteSelect[1] = InProgress & (BitCounter == 7'h28);
423
assign ByteSelect[2] = InProgress & WriteOp & (BitCounter == 7'h30);
424
assign ByteSelect[3] = InProgress & WriteOp & (BitCounter == 7'h38);
425
 
426
 
427
// Latch Byte selects which part of Read Status Data is updated from the shift register
428
assign LatchByte1_d2 = InProgress & ~WriteOp & BitCounter == 7'h37;
429
assign LatchByte0_d2 = InProgress & ~WriteOp & BitCounter == 7'h3F;
430
 
431
 
432
// Connecting the Clock Generator Module
433
eth_clockgen clkgen(.Clk(Clk), .Reset(Reset), .Divider(Divider[7:0]), .MdcEn(MdcEn), .MdcEn_n(MdcEn_n), .Mdc(Mdc)
434
                   );
435
 
436
// Connecting the Shift Register Module
437
eth_shiftreg shftrg(.Clk(Clk), .Reset(Reset), .MdcEn_n(MdcEn_n), .Mdi(Mdi), .Fiad(Fiad), .Rgad(Rgad),
438
                    .CtrlData(CtrlData), .WriteOp(WriteOp), .ByteSelect(ByteSelect), .LatchByte(LatchByte),
439
                    .ShiftedBit(ShiftedBit), .Prsd(Prsd), .LinkFail(LinkFail)
440
                   );
441
 
442
// Connecting the Output Control Module
443
eth_outputcontrol outctrl(.Clk(Clk), .Reset(Reset), .MdcEn_n(MdcEn_n), .InProgress(InProgress),
444
                          .ShiftedBit(ShiftedBit), .BitCounter(BitCounter), .WriteOp(WriteOp), .NoPre(NoPre),
445
                          .Mdo(Mdo), .MdoEn(MdoEn)
446
                         );
447
 
448
endmodule

powered by: WebSVN 2.1.0

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