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

Subversion Repositories ethernet_tri_mode

[/] [ethernet_tri_mode/] [trunk/] [rtl/] [verilog/] [eth_miim.v] - Blame information for rev 5

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

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

powered by: WebSVN 2.1.0

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