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

Subversion Repositories ethmac

[/] [ethmac/] [tags/] [rel_14/] [rtl/] [verilog/] [eth_miim.v] - Blame information for rev 37

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

powered by: WebSVN 2.1.0

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