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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_17/] [rtl/] [verilog/] [eth_miim.v] - Blame information for rev 338

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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