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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [rtl/] [verilog/] [components/] [ethernet/] [eth_top_ip.v] - Blame information for rev 19

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

Line No. Rev Author Line
1 18 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  eth_clockgen.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: eth_clockgen.v,v $
44
// Revision 1.4  2005/02/21 12:48:05  igorm
45
// Warning fixes.
46
//
47
// Revision 1.3  2002/01/23 10:28:16  mohor
48
// Link in the header changed.
49
//
50
// Revision 1.2  2001/10/19 08:43:51  mohor
51
// eth_timescale.v changed to timescale.v This is done because of the
52
// simulation of the few cores in a one joined project.
53
//
54
// Revision 1.1  2001/08/06 14:44:29  mohor
55
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
56
// Include files fixed to contain no path.
57
// File names and module names changed ta have a eth_ prologue in the name.
58
// File eth_timescale.v is used to define timescale
59
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
60
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
61
// and Mdo_OE. The bidirectional signal must be created on the top level. This
62
// is done due to the ASIC tools.
63
//
64
// Revision 1.1  2001/07/30 21:23:42  mohor
65
// Directory structure changed. Files checked and joind together.
66
//
67
// Revision 1.3  2001/06/01 22:28:55  mohor
68
// This files (MIIM) are fully working. They were thoroughly tested. The testbench is not updated.
69
//
70
//
71
 
72
`include "timescale.v"
73
 
74
module eth_clockgen(Clk, Reset, Divider, MdcEn, MdcEn_n, Mdc);
75
 
76
parameter Tp=1;
77
 
78
input       Clk;              // Input clock (Host clock)
79
input       Reset;            // Reset signal
80
input [7:0] Divider;          // Divider (input clock will be divided by the Divider[7:0])
81
 
82
output      Mdc;              // Output clock
83
output      MdcEn;            // Enable signal is asserted for one Clk period before Mdc rises.
84
output      MdcEn_n;          // Enable signal is asserted for one Clk period before Mdc falls.
85
 
86
reg         Mdc;
87
reg   [7:0] Counter;
88
 
89
wire        CountEq0;
90
wire  [7:0] CounterPreset;
91
wire  [7:0] TempDivider;
92
 
93
 
94
assign TempDivider[7:0]   = (Divider[7:0]<2)? 8'h02 : Divider[7:0]; // If smaller than 2
95
assign CounterPreset[7:0] = (TempDivider[7:0]>>1) - 1'b1;           // We are counting half of period
96
 
97
 
98
// Counter counts half period
99
always @ (posedge Clk or posedge Reset)
100
begin
101
  if(Reset)
102
    Counter[7:0] <= #Tp 8'h1;
103
  else
104
    begin
105
      if(CountEq0)
106
        begin
107
          Counter[7:0] <= #Tp CounterPreset[7:0];
108
        end
109
      else
110
        Counter[7:0] <= #Tp Counter - 8'h1;
111
    end
112
end
113
 
114
 
115
// Mdc is asserted every other half period
116
always @ (posedge Clk or posedge Reset)
117
begin
118
  if(Reset)
119
    Mdc <= #Tp 1'b0;
120
  else
121
    begin
122
      if(CountEq0)
123
        Mdc <= #Tp ~Mdc;
124
    end
125
end
126
 
127
 
128
assign CountEq0 = Counter == 8'h0;
129
assign MdcEn = CountEq0 & ~Mdc;
130
assign MdcEn_n = CountEq0 & Mdc;
131
 
132
endmodule
133
 
134
 
135
//////////////////////////////////////////////////////////////////////
136
////                                                              ////
137
////  eth_crc.v                                                   ////
138
////                                                              ////
139
////  This file is part of the Ethernet IP core project           ////
140
////  http://www.opencores.org/projects/ethmac/                   ////
141
////                                                              ////
142
////  Author(s):                                                  ////
143
////      - Igor Mohor (igorM@opencores.org)                      ////
144
////      - Novan Hartadi (novan@vlsi.itb.ac.id)                  ////
145
////      - Mahmud Galela (mgalela@vlsi.itb.ac.id)                ////
146
////                                                              ////
147
////  All additional information is avaliable in the Readme.txt   ////
148
////  file.                                                       ////
149
////                                                              ////
150
//////////////////////////////////////////////////////////////////////
151
////                                                              ////
152
//// Copyright (C) 2001 Authors                                   ////
153
////                                                              ////
154
//// This source file may be used and distributed without         ////
155
//// restriction provided that this copyright statement is not    ////
156
//// removed from the file and that any derivative work contains  ////
157
//// the original copyright notice and the associated disclaimer. ////
158
////                                                              ////
159
//// This source file is free software; you can redistribute it   ////
160
//// and/or modify it under the terms of the GNU Lesser General   ////
161
//// Public License as published by the Free Software Foundation; ////
162
//// either version 2.1 of the License, or (at your option) any   ////
163
//// later version.                                               ////
164
////                                                              ////
165
//// This source is distributed in the hope that it will be       ////
166
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
167
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
168
//// PURPOSE.  See the GNU Lesser General Public License for more ////
169
//// details.                                                     ////
170
////                                                              ////
171
//// You should have received a copy of the GNU Lesser General    ////
172
//// Public License along with this source; if not, download it   ////
173
//// from http://www.opencores.org/lgpl.shtml                     ////
174
////                                                              ////
175
//////////////////////////////////////////////////////////////////////
176
//
177
// CVS Revision History
178
//
179
// $Log: eth_crc.v,v $
180
// Revision 1.3  2002/01/23 10:28:16  mohor
181
// Link in the header changed.
182
//
183
// Revision 1.2  2001/10/19 08:43:51  mohor
184
// eth_timescale.v changed to timescale.v This is done because of the
185
// simulation of the few cores in a one joined project.
186
//
187
// Revision 1.1  2001/08/06 14:44:29  mohor
188
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
189
// Include files fixed to contain no path.
190
// File names and module names changed ta have a eth_ prologue in the name.
191
// File eth_timescale.v is used to define timescale
192
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
193
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
194
// and Mdo_OE. The bidirectional signal must be created on the top level. This
195
// is done due to the ASIC tools.
196
//
197
// Revision 1.1  2001/07/30 21:23:42  mohor
198
// Directory structure changed. Files checked and joind together.
199
//
200
// Revision 1.3  2001/06/19 18:16:40  mohor
201
// TxClk changed to MTxClk (as discribed in the documentation).
202
// Crc changed so only one file can be used instead of two.
203
//
204
// Revision 1.2  2001/06/19 10:38:07  mohor
205
// Minor changes in header.
206
//
207
// Revision 1.1  2001/06/19 10:27:57  mohor
208
// TxEthMAC initial release.
209
//
210
//
211
//
212
 
213
 
214
`include "timescale.v"
215
 
216
module eth_crc (Clk, Reset, Data, Enable, Initialize, Crc, CrcError);
217
 
218
 
219
parameter Tp = 1;
220
 
221
input Clk;
222
input Reset;
223
input [3:0] Data;
224
input Enable;
225
input Initialize;
226
 
227
output [31:0] Crc;
228
output CrcError;
229
 
230
reg  [31:0] Crc;
231
 
232
wire [31:0] CrcNext;
233
 
234
 
235
assign CrcNext[0] = Enable & (Data[0] ^ Crc[28]);
236
assign CrcNext[1] = Enable & (Data[1] ^ Data[0] ^ Crc[28] ^ Crc[29]);
237
assign CrcNext[2] = Enable & (Data[2] ^ Data[1] ^ Data[0] ^ Crc[28] ^ Crc[29] ^ Crc[30]);
238
assign CrcNext[3] = Enable & (Data[3] ^ Data[2] ^ Data[1] ^ Crc[29] ^ Crc[30] ^ Crc[31]);
239
assign CrcNext[4] = (Enable & (Data[3] ^ Data[2] ^ Data[0] ^ Crc[28] ^ Crc[30] ^ Crc[31])) ^ Crc[0];
240
assign CrcNext[5] = (Enable & (Data[3] ^ Data[1] ^ Data[0] ^ Crc[28] ^ Crc[29] ^ Crc[31])) ^ Crc[1];
241
assign CrcNext[6] = (Enable & (Data[2] ^ Data[1] ^ Crc[29] ^ Crc[30])) ^ Crc[ 2];
242
assign CrcNext[7] = (Enable & (Data[3] ^ Data[2] ^ Data[0] ^ Crc[28] ^ Crc[30] ^ Crc[31])) ^ Crc[3];
243
assign CrcNext[8] = (Enable & (Data[3] ^ Data[1] ^ Data[0] ^ Crc[28] ^ Crc[29] ^ Crc[31])) ^ Crc[4];
244
assign CrcNext[9] = (Enable & (Data[2] ^ Data[1] ^ Crc[29] ^ Crc[30])) ^ Crc[5];
245
assign CrcNext[10] = (Enable & (Data[3] ^ Data[2] ^ Data[0] ^ Crc[28] ^ Crc[30] ^ Crc[31])) ^ Crc[6];
246
assign CrcNext[11] = (Enable & (Data[3] ^ Data[1] ^ Data[0] ^ Crc[28] ^ Crc[29] ^ Crc[31])) ^ Crc[7];
247
assign CrcNext[12] = (Enable & (Data[2] ^ Data[1] ^ Data[0] ^ Crc[28] ^ Crc[29] ^ Crc[30])) ^ Crc[8];
248
assign CrcNext[13] = (Enable & (Data[3] ^ Data[2] ^ Data[1] ^ Crc[29] ^ Crc[30] ^ Crc[31])) ^ Crc[9];
249
assign CrcNext[14] = (Enable & (Data[3] ^ Data[2] ^ Crc[30] ^ Crc[31])) ^ Crc[10];
250
assign CrcNext[15] = (Enable & (Data[3] ^ Crc[31])) ^ Crc[11];
251
assign CrcNext[16] = (Enable & (Data[0] ^ Crc[28])) ^ Crc[12];
252
assign CrcNext[17] = (Enable & (Data[1] ^ Crc[29])) ^ Crc[13];
253
assign CrcNext[18] = (Enable & (Data[2] ^ Crc[30])) ^ Crc[14];
254
assign CrcNext[19] = (Enable & (Data[3] ^ Crc[31])) ^ Crc[15];
255
assign CrcNext[20] = Crc[16];
256
assign CrcNext[21] = Crc[17];
257
assign CrcNext[22] = (Enable & (Data[0] ^ Crc[28])) ^ Crc[18];
258
assign CrcNext[23] = (Enable & (Data[1] ^ Data[0] ^ Crc[29] ^ Crc[28])) ^ Crc[19];
259
assign CrcNext[24] = (Enable & (Data[2] ^ Data[1] ^ Crc[30] ^ Crc[29])) ^ Crc[20];
260
assign CrcNext[25] = (Enable & (Data[3] ^ Data[2] ^ Crc[31] ^ Crc[30])) ^ Crc[21];
261
assign CrcNext[26] = (Enable & (Data[3] ^ Data[0] ^ Crc[31] ^ Crc[28])) ^ Crc[22];
262
assign CrcNext[27] = (Enable & (Data[1] ^ Crc[29])) ^ Crc[23];
263
assign CrcNext[28] = (Enable & (Data[2] ^ Crc[30])) ^ Crc[24];
264
assign CrcNext[29] = (Enable & (Data[3] ^ Crc[31])) ^ Crc[25];
265
assign CrcNext[30] = Crc[26];
266
assign CrcNext[31] = Crc[27];
267
 
268
 
269
always @ (posedge Clk or posedge Reset)
270
begin
271
  if (Reset)
272
    Crc <= #1 32'hffffffff;
273
  else
274
  if(Initialize)
275
    Crc <= #Tp 32'hffffffff;
276
  else
277
    Crc <= #Tp CrcNext;
278
end
279
 
280
assign CrcError = Crc[31:0] != 32'hc704dd7b;  // CRC not equal to magic number
281
 
282
endmodule
283
//////////////////////////////////////////////////////////////////////
284
////                                                              ////
285
////  eth_fifo.v                                                  ////
286
////                                                              ////
287
////  This file is part of the Ethernet IP core project           ////
288
////  http://www.opencores.org/projects/ethmac/                   ////
289
////                                                              ////
290
////  Author(s):                                                  ////
291
////      - Igor Mohor (igorM@opencores.org)                      ////
292
////                                                              ////
293
////  All additional information is avaliable in the Readme.txt   ////
294
////  file.                                                       ////
295
////                                                              ////
296
//////////////////////////////////////////////////////////////////////
297
////                                                              ////
298
//// Copyright (C) 2001 Authors                                   ////
299
////                                                              ////
300
//// This source file may be used and distributed without         ////
301
//// restriction provided that this copyright statement is not    ////
302
//// removed from the file and that any derivative work contains  ////
303
//// the original copyright notice and the associated disclaimer. ////
304
////                                                              ////
305
//// This source file is free software; you can redistribute it   ////
306
//// and/or modify it under the terms of the GNU Lesser General   ////
307
//// Public License as published by the Free Software Foundation; ////
308
//// either version 2.1 of the License, or (at your option) any   ////
309
//// later version.                                               ////
310
////                                                              ////
311
//// This source is distributed in the hope that it will be       ////
312
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
313
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
314
//// PURPOSE.  See the GNU Lesser General Public License for more ////
315
//// details.                                                     ////
316
////                                                              ////
317
//// You should have received a copy of the GNU Lesser General    ////
318
//// Public License along with this source; if not, download it   ////
319
//// from http://www.opencores.org/lgpl.shtml                     ////
320
////                                                              ////
321
//////////////////////////////////////////////////////////////////////
322
//
323
// CVS Revision History
324
//
325
// $Log: eth_fifo.v,v $
326
// Revision 1.4  2005/02/21 12:48:07  igorm
327
// Warning fixes.
328
//
329
// Revision 1.3  2002/04/22 13:45:52  mohor
330
// Generic ram or Xilinx ram can be used in fifo (selectable by setting
331
// ETH_FIFO_XILINX in eth_defines.v).
332
//
333
// Revision 1.2  2002/03/25 13:33:04  mohor
334
// When clear and read/write are active at the same time, cnt and pointers are
335
// set to 1.
336
//
337
// Revision 1.1  2002/02/05 16:44:39  mohor
338
// Both rx and tx part are finished. Tested with wb_clk_i between 10 and 200
339
// MHz. Statuses, overrun, control frame transmission and reception still  need
340
// to be fixed.
341
//
342
//
343
 
344
`include "eth_defines.v"
345
`include "timescale.v"
346
 
347
module eth_fifo (data_in, data_out, clk, reset, write, read, clear, almost_full, full, almost_empty, empty, cnt);
348
 
349
parameter DATA_WIDTH    = 32;
350
parameter DEPTH         = 8;
351
parameter CNT_WIDTH     = 4;
352
 
353
parameter Tp            = 1;
354
 
355
input                     clk;
356
input                     reset;
357
input                     write;
358
input                     read;
359
input                     clear;
360
input   [DATA_WIDTH-1:0]  data_in;
361
 
362
output  [DATA_WIDTH-1:0]  data_out;
363
output                    almost_full;
364
output                    full;
365
output                    almost_empty;
366
output                    empty;
367
output  [CNT_WIDTH-1:0]   cnt;
368
 
369
`ifdef ETH_FIFO_XILINX
370
`else
371
  `ifdef ETH_ALTERA_ALTSYNCRAM
372
  `else
373
    reg     [DATA_WIDTH-1:0]  fifo  [0:DEPTH-1];
374
//    reg     [DATA_WIDTH-1:0]  data_out;
375
  `endif
376
`endif
377
 
378
reg     [CNT_WIDTH-1:0]   cnt;
379
reg     [CNT_WIDTH-2:0]   read_pointer;
380
reg     [CNT_WIDTH-2:0]   write_pointer;
381
 
382
 
383
always @ (posedge clk or posedge reset)
384
begin
385
  if(reset)
386
    cnt <=#Tp 0;
387
  else
388
  if(clear)
389
    cnt <=#Tp { {(CNT_WIDTH-1){1'b0}}, read^write};
390
  else
391
  if(read ^ write)
392
    if(read)
393
      cnt <=#Tp cnt - 1'b1;
394
    else
395
      cnt <=#Tp cnt + 1'b1;
396
end
397
 
398
always @ (posedge clk or posedge reset)
399
begin
400
  if(reset)
401
    read_pointer <=#Tp 0;
402
  else
403
  if(clear)
404
    read_pointer <=#Tp { {(CNT_WIDTH-2){1'b0}}, read};
405
  else
406
  if(read & ~empty)
407
    read_pointer <=#Tp read_pointer + 1'b1;
408
end
409
 
410
always @ (posedge clk or posedge reset)
411
begin
412
  if(reset)
413
    write_pointer <=#Tp 0;
414
  else
415
  if(clear)
416
    write_pointer <=#Tp { {(CNT_WIDTH-2){1'b0}}, write};
417
  else
418
  if(write & ~full)
419
    write_pointer <=#Tp write_pointer + 1'b1;
420
end
421
 
422
assign empty = ~(|cnt);
423
assign almost_empty = cnt == 1;
424
assign full  = cnt == DEPTH;
425
assign almost_full  = &cnt[CNT_WIDTH-2:0];
426
 
427
 
428
 
429
`ifdef ETH_FIFO_XILINX
430
  xilinx_dist_ram_16x32 fifo
431
  ( .data_out(data_out),
432
    .we(write & ~full),
433
    .data_in(data_in),
434
    .read_address( clear ? {CNT_WIDTH-1{1'b0}} : read_pointer),
435
    .write_address(clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
436
    .wclk(clk)
437
  );
438
`else   // !ETH_FIFO_XILINX
439
`ifdef ETH_ALTERA_ALTSYNCRAM
440
  altera_dpram_16x32    altera_dpram_16x32_inst
441
  (
442
        .data             (data_in),
443
        .wren             (write & ~full),
444
        .wraddress        (clear ? {CNT_WIDTH-1{1'b0}} : write_pointer),
445
        .rdaddress        (clear ? {CNT_WIDTH-1{1'b0}} : read_pointer ),
446
        .clock            (clk),
447
        .q                (data_out)
448
  );  //exemplar attribute altera_dpram_16x32_inst NOOPT TRUE
449
`else   // !ETH_ALTERA_ALTSYNCRAM
450
 
451
   wire [CNT_WIDTH-2:0] waddr, raddr;
452
   reg [CNT_WIDTH-2:0]   raddr_reg;
453
   wire       we;
454
 
455
   assign waddr = clear ? {CNT_WIDTH-1{1'b0}} : write_pointer;
456
   assign raddr = clear ? {CNT_WIDTH-1{1'b0}} : read_pointer;
457
 
458
   assign we = (write & clear) | (write & ~full);
459
 
460
   always @ (posedge clk)
461
     if (we)
462
       fifo[waddr] <= #Tp data_in;
463
 
464
   always @ (posedge clk)
465
     raddr_reg <= raddr;
466
 
467
   assign #Tp data_out = fifo[raddr_reg];
468
 
469
 
470
   /*
471
  always @ (posedge clk)
472
  begin
473
    if(write & clear)
474
      fifo[0] <=#Tp data_in;
475
    else
476
   if(write & ~full)
477
      fifo[write_pointer] <=#Tp data_in;
478
  end
479
 
480
 
481
  always @ (posedge clk)
482
  begin
483
    if(clear)
484
      data_out <=#Tp fifo[0];
485
    else
486
      data_out <=#Tp fifo[read_pointer];
487
  end
488
    */
489
`endif  // !ETH_ALTERA_ALTSYNCRAM
490
`endif  // !ETH_FIFO_XILINX
491
 
492
 
493
endmodule
494
//////////////////////////////////////////////////////////////////////
495
////                                                              ////
496
////  eth_maccontrol.v                                            ////
497
////                                                              ////
498
////  This file is part of the Ethernet IP core project           ////
499
////  http://www.opencores.org/projects/ethmac/                   ////
500
////                                                              ////
501
////  Author(s):                                                  ////
502
////      - Igor Mohor (igorM@opencores.org)                      ////
503
////                                                              ////
504
////  All additional information is avaliable in the Readme.txt   ////
505
////  file.                                                       ////
506
////                                                              ////
507
//////////////////////////////////////////////////////////////////////
508
////                                                              ////
509
//// Copyright (C) 2001 Authors                                   ////
510
////                                                              ////
511
//// This source file may be used and distributed without         ////
512
//// restriction provided that this copyright statement is not    ////
513
//// removed from the file and that any derivative work contains  ////
514
//// the original copyright notice and the associated disclaimer. ////
515
////                                                              ////
516
//// This source file is free software; you can redistribute it   ////
517
//// and/or modify it under the terms of the GNU Lesser General   ////
518
//// Public License as published by the Free Software Foundation; ////
519
//// either version 2.1 of the License, or (at your option) any   ////
520
//// later version.                                               ////
521
////                                                              ////
522
//// This source is distributed in the hope that it will be       ////
523
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
524
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
525
//// PURPOSE.  See the GNU Lesser General Public License for more ////
526
//// details.                                                     ////
527
////                                                              ////
528
//// You should have received a copy of the GNU Lesser General    ////
529
//// Public License along with this source; if not, download it   ////
530
//// from http://www.opencores.org/lgpl.shtml                     ////
531
////                                                              ////
532
//////////////////////////////////////////////////////////////////////
533
//
534
// CVS Revision History
535
//
536
// $Log: eth_maccontrol.v,v $
537
// Revision 1.7  2003/01/22 13:49:26  tadejm
538
// When control packets were received, they were ignored in some cases.
539
//
540
// Revision 1.6  2002/11/22 01:57:06  mohor
541
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
542
// synchronized.
543
//
544
// Revision 1.5  2002/11/21 00:14:39  mohor
545
// TxDone and TxAbort changed so they're not propagated to the wishbone
546
// module when control frame is transmitted.
547
//
548
// Revision 1.4  2002/11/19 17:37:32  mohor
549
// When control frame (PAUSE) was sent, status was written in the
550
// eth_wishbone module and both TXB and TXC interrupts were set. Fixed.
551
// Only TXC interrupt is set.
552
//
553
// Revision 1.3  2002/01/23 10:28:16  mohor
554
// Link in the header changed.
555
//
556
// Revision 1.2  2001/10/19 08:43:51  mohor
557
// eth_timescale.v changed to timescale.v This is done because of the
558
// simulation of the few cores in a one joined project.
559
//
560
// Revision 1.1  2001/08/06 14:44:29  mohor
561
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
562
// Include files fixed to contain no path.
563
// File names and module names changed ta have a eth_ prologue in the name.
564
// File eth_timescale.v is used to define timescale
565
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
566
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
567
// and Mdo_OE. The bidirectional signal must be created on the top level. This
568
// is done due to the ASIC tools.
569
//
570
// Revision 1.1  2001/07/30 21:23:42  mohor
571
// Directory structure changed. Files checked and joind together.
572
//
573
// Revision 1.1  2001/07/03 12:51:54  mohor
574
// Initial release of the MAC Control module.
575
//
576
//
577
//
578
//
579
 
580
 
581
`include "timescale.v"
582
 
583
 
584
module eth_maccontrol (MTxClk, MRxClk, TxReset, RxReset, TPauseRq, TxDataIn, TxStartFrmIn, TxUsedDataIn,
585
                       TxEndFrmIn, TxDoneIn, TxAbortIn, RxData, RxValid, RxStartFrm, RxEndFrm, ReceiveEnd,
586
                       ReceivedPacketGood, ReceivedLengthOK, TxFlow, RxFlow, DlyCrcEn, TxPauseTV,
587
                       MAC, PadIn, PadOut, CrcEnIn, CrcEnOut, TxDataOut, TxStartFrmOut, TxEndFrmOut,
588
                       TxDoneOut, TxAbortOut, TxUsedDataOut, WillSendControlFrame, TxCtrlEndFrm,
589
                       ReceivedPauseFrm, ControlFrmAddressOK, SetPauseTimer, r_PassAll, RxStatusWriteLatched_sync2
590
                      );
591
 
592
 
593
parameter   Tp = 1;
594
 
595
 
596
input         MTxClk;                   // Transmit clock (from PHY)
597
input         MRxClk;                   // Receive clock (from PHY)
598
input         TxReset;                  // Transmit reset
599
input         RxReset;                  // Receive reset
600
input         TPauseRq;                 // Transmit control frame (from host)
601
input   [7:0] TxDataIn;                 // Transmit packet data byte (from host)
602
input         TxStartFrmIn;             // Transmit packet start frame input (from host)
603
input         TxUsedDataIn;             // Transmit packet used data (from TxEthMAC)
604
input         TxEndFrmIn;               // Transmit packet end frame input (from host)
605
input         TxDoneIn;                 // Transmit packet done (from TxEthMAC)
606
input         TxAbortIn;                // Transmit packet abort (input from TxEthMAC)
607
input         PadIn;                    // Padding (input from registers)
608
input         CrcEnIn;                  // Crc append (input from registers)
609
input   [7:0] RxData;                   // Receive Packet Data (from RxEthMAC)
610
input         RxValid;                  // Received a valid packet
611
input         RxStartFrm;               // Receive packet start frame (input from RxEthMAC)
612
input         RxEndFrm;                 // Receive packet end frame (input from RxEthMAC)
613
input         ReceiveEnd;               // End of receiving of the current packet (input from RxEthMAC)
614
input         ReceivedPacketGood;       // Received packet is good
615
input         ReceivedLengthOK;         // Length of the received packet is OK
616
input         TxFlow;                   // Tx flow control (from registers)
617
input         RxFlow;                   // Rx flow control (from registers)
618
input         DlyCrcEn;                 // Delayed CRC enabled (from registers)
619
input  [15:0] TxPauseTV;                // Transmit Pause Timer Value (from registers)
620
input  [47:0] MAC;                      // MAC address (from registers)
621
input         RxStatusWriteLatched_sync2;
622
input         r_PassAll;
623
 
624
output  [7:0] TxDataOut;                // Transmit Packet Data (to TxEthMAC)
625
output        TxStartFrmOut;            // Transmit packet start frame (output to TxEthMAC)
626
output        TxEndFrmOut;              // Transmit packet end frame (output to TxEthMAC)
627
output        TxDoneOut;                // Transmit packet done (to host)
628
output        TxAbortOut;               // Transmit packet aborted (to host)
629
output        TxUsedDataOut;            // Transmit packet used data (to host)
630
output        PadOut;                   // Padding (output to TxEthMAC)
631
output        CrcEnOut;                 // Crc append (output to TxEthMAC)
632
output        WillSendControlFrame;
633
output        TxCtrlEndFrm;
634
output        ReceivedPauseFrm;
635
output        ControlFrmAddressOK;
636
output        SetPauseTimer;
637
 
638
reg           TxUsedDataOutDetected;
639
reg           TxAbortInLatched;
640
reg           TxDoneInLatched;
641
reg           MuxedDone;
642
reg           MuxedAbort;
643
 
644
wire          Pause;
645
wire          TxCtrlStartFrm;
646
wire    [7:0] ControlData;
647
wire          CtrlMux;
648
wire          SendingCtrlFrm;           // Sending Control Frame (enables padding and CRC)
649
wire          BlockTxDone;
650
 
651
 
652
// Signal TxUsedDataOut was detected (a transfer is already in progress)
653
always @ (posedge MTxClk or posedge TxReset)
654
begin
655
  if(TxReset)
656
    TxUsedDataOutDetected <= #Tp 1'b0;
657
  else
658
  if(TxDoneIn | TxAbortIn)
659
    TxUsedDataOutDetected <= #Tp 1'b0;
660
  else
661
  if(TxUsedDataOut)
662
    TxUsedDataOutDetected <= #Tp 1'b1;
663
end
664
 
665
 
666
// Latching variables
667
always @ (posedge MTxClk or posedge TxReset)
668
begin
669
  if(TxReset)
670
    begin
671
      TxAbortInLatched <= #Tp 1'b0;
672
      TxDoneInLatched  <= #Tp 1'b0;
673
    end
674
  else
675
    begin
676
      TxAbortInLatched <= #Tp TxAbortIn;
677
      TxDoneInLatched  <= #Tp TxDoneIn;
678
    end
679
end
680
 
681
 
682
 
683
// Generating muxed abort signal
684
always @ (posedge MTxClk or posedge TxReset)
685
begin
686
  if(TxReset)
687
    MuxedAbort <= #Tp 1'b0;
688
  else
689
  if(TxStartFrmIn)
690
    MuxedAbort <= #Tp 1'b0;
691
  else
692
  if(TxAbortIn & ~TxAbortInLatched & TxUsedDataOutDetected)
693
    MuxedAbort <= #Tp 1'b1;
694
end
695
 
696
 
697
// Generating muxed done signal
698
always @ (posedge MTxClk or posedge TxReset)
699
begin
700
  if(TxReset)
701
    MuxedDone <= #Tp 1'b0;
702
  else
703
  if(TxStartFrmIn)
704
    MuxedDone <= #Tp 1'b0;
705
  else
706
  if(TxDoneIn & (~TxDoneInLatched) & TxUsedDataOutDetected)
707
    MuxedDone <= #Tp 1'b1;
708
end
709
 
710
 
711
// TxDoneOut
712
assign TxDoneOut  = CtrlMux? ((~TxStartFrmIn) & (~BlockTxDone) & MuxedDone) :
713
                             ((~TxStartFrmIn) & (~BlockTxDone) & TxDoneIn);
714
 
715
// TxAbortOut
716
assign TxAbortOut  = CtrlMux? ((~TxStartFrmIn) & (~BlockTxDone) & MuxedAbort) :
717
                              ((~TxStartFrmIn) & (~BlockTxDone) & TxAbortIn);
718
 
719
// TxUsedDataOut
720
assign TxUsedDataOut  = ~CtrlMux & TxUsedDataIn;
721
 
722
// TxStartFrmOut
723
assign TxStartFrmOut = CtrlMux? TxCtrlStartFrm : (TxStartFrmIn & ~Pause);
724
 
725
 
726
// TxEndFrmOut
727
assign TxEndFrmOut = CtrlMux? TxCtrlEndFrm : TxEndFrmIn;
728
 
729
 
730
// TxDataOut[7:0]
731
assign TxDataOut[7:0] = CtrlMux? ControlData[7:0] : TxDataIn[7:0];
732
 
733
 
734
// PadOut
735
assign PadOut = PadIn | SendingCtrlFrm;
736
 
737
 
738
// CrcEnOut
739
assign CrcEnOut = CrcEnIn | SendingCtrlFrm;
740
 
741
 
742
 
743
// Connecting receivecontrol module
744
eth_receivecontrol receivecontrol1
745
(
746
 .MTxClk(MTxClk), .MRxClk(MRxClk), .TxReset(TxReset), .RxReset(RxReset), .RxData(RxData),
747
 .RxValid(RxValid), .RxStartFrm(RxStartFrm), .RxEndFrm(RxEndFrm), .RxFlow(RxFlow),
748
 .ReceiveEnd(ReceiveEnd), .MAC(MAC), .DlyCrcEn(DlyCrcEn), .TxDoneIn(TxDoneIn),
749
 .TxAbortIn(TxAbortIn), .TxStartFrmOut(TxStartFrmOut), .ReceivedLengthOK(ReceivedLengthOK),
750
 .ReceivedPacketGood(ReceivedPacketGood), .TxUsedDataOutDetected(TxUsedDataOutDetected),
751
 .Pause(Pause), .ReceivedPauseFrm(ReceivedPauseFrm), .AddressOK(ControlFrmAddressOK),
752
 .r_PassAll(r_PassAll), .RxStatusWriteLatched_sync2(RxStatusWriteLatched_sync2), .SetPauseTimer(SetPauseTimer)
753
);
754
 
755
 
756
eth_transmitcontrol transmitcontrol1
757
(
758
 .MTxClk(MTxClk), .TxReset(TxReset), .TxUsedDataIn(TxUsedDataIn), .TxUsedDataOut(TxUsedDataOut),
759
 .TxDoneIn(TxDoneIn), .TxAbortIn(TxAbortIn), .TxStartFrmIn(TxStartFrmIn), .TPauseRq(TPauseRq),
760
 .TxUsedDataOutDetected(TxUsedDataOutDetected), .TxFlow(TxFlow), .DlyCrcEn(DlyCrcEn), .TxPauseTV(TxPauseTV),
761
 .MAC(MAC), .TxCtrlStartFrm(TxCtrlStartFrm), .TxCtrlEndFrm(TxCtrlEndFrm), .SendingCtrlFrm(SendingCtrlFrm),
762
 .CtrlMux(CtrlMux), .ControlData(ControlData), .WillSendControlFrame(WillSendControlFrame), .BlockTxDone(BlockTxDone)
763
);
764
 
765
 
766
 
767
endmodule
768
//////////////////////////////////////////////////////////////////////
769
////                                                              ////
770
////  eth_macstatus.v                                             ////
771
////                                                              ////
772
////  This file is part of the Ethernet IP core project           ////
773
////  http://www.opencores.org/projects/ethmac/                   ////
774
////                                                              ////
775
////  Author(s):                                                  ////
776
////      - Igor Mohor (igorM@opencores.org)                      ////
777
////                                                              ////
778
////  All additional information is available in the Readme.txt   ////
779
////  file.                                                       ////
780
////                                                              ////
781
//////////////////////////////////////////////////////////////////////
782
////                                                              ////
783
//// Copyright (C) 2001, 2002 Authors                             ////
784
////                                                              ////
785
//// This source file may be used and distributed without         ////
786
//// restriction provided that this copyright statement is not    ////
787
//// removed from the file and that any derivative work contains  ////
788
//// the original copyright notice and the associated disclaimer. ////
789
////                                                              ////
790
//// This source file is free software; you can redistribute it   ////
791
//// and/or modify it under the terms of the GNU Lesser General   ////
792
//// Public License as published by the Free Software Foundation; ////
793
//// either version 2.1 of the License, or (at your option) any   ////
794
//// later version.                                               ////
795
////                                                              ////
796
//// This source is distributed in the hope that it will be       ////
797
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
798
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
799
//// PURPOSE.  See the GNU Lesser General Public License for more ////
800
//// details.                                                     ////
801
////                                                              ////
802
//// You should have received a copy of the GNU Lesser General    ////
803
//// Public License along with this source; if not, download it   ////
804
//// from http://www.opencores.org/lgpl.shtml                     ////
805
////                                                              ////
806
//////////////////////////////////////////////////////////////////////
807
//
808
// CVS Revision History
809
//
810
// $Log: eth_macstatus.v,v $
811
// Revision 1.17  2005/03/21 20:07:18  igorm
812
// Some small fixes + some troubles fixed.
813
//
814
// Revision 1.16  2005/02/21 10:42:11  igorm
815
// Defer indication fixed.
816
//
817
// Revision 1.15  2003/01/30 13:28:19  tadejm
818
// Defer indication changed.
819
//
820
// Revision 1.14  2002/11/22 01:57:06  mohor
821
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
822
// synchronized.
823
//
824
// Revision 1.13  2002/11/13 22:30:58  tadejm
825
// Late collision is reported only when not in the full duplex.
826
// Sample is taken (for status) as soon as MRxDV is not valid (regardless
827
// of the received byte cnt).
828
//
829
// Revision 1.12  2002/09/12 14:50:16  mohor
830
// CarrierSenseLost bug fixed when operating in full duplex mode.
831
//
832
// Revision 1.11  2002/09/04 18:38:03  mohor
833
// CarrierSenseLost status is not set when working in loopback mode.
834
//
835
// Revision 1.10  2002/07/25 18:17:46  mohor
836
// InvalidSymbol generation changed.
837
//
838
// Revision 1.9  2002/04/22 13:51:44  mohor
839
// Short frame and ReceivedLengthOK were not detected correctly.
840
//
841
// Revision 1.8  2002/02/18 10:40:17  mohor
842
// Small fixes.
843
//
844
// Revision 1.7  2002/02/15 17:07:39  mohor
845
// Status was not written correctly when frames were discarted because of
846
// address mismatch.
847
//
848
// Revision 1.6  2002/02/11 09:18:21  mohor
849
// Tx status is written back to the BD.
850
//
851
// Revision 1.5  2002/02/08 16:21:54  mohor
852
// Rx status is written back to the BD.
853
//
854
// Revision 1.4  2002/01/23 10:28:16  mohor
855
// Link in the header changed.
856
//
857
// Revision 1.3  2001/10/19 08:43:51  mohor
858
// eth_timescale.v changed to timescale.v This is done because of the
859
// simulation of the few cores in a one joined project.
860
//
861
// Revision 1.2  2001/09/11 14:17:00  mohor
862
// Few little NCSIM warnings fixed.
863
//
864
// Revision 1.1  2001/08/06 14:44:29  mohor
865
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
866
// Include files fixed to contain no path.
867
// File names and module names changed ta have a eth_ prologue in the name.
868
// File eth_timescale.v is used to define timescale
869
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
870
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
871
// and Mdo_OE. The bidirectional signal must be created on the top level. This
872
// is done due to the ASIC tools.
873
//
874
// Revision 1.1  2001/07/30 21:23:42  mohor
875
// Directory structure changed. Files checked and joind together.
876
//
877
//
878
//
879
//
880
//
881
 
882
`include "timescale.v"
883
 
884
 
885
module eth_macstatus(
886
                      MRxClk, Reset, ReceivedLengthOK, ReceiveEnd, ReceivedPacketGood, RxCrcError,
887
                      MRxErr, MRxDV, RxStateSFD, RxStateData, RxStatePreamble, RxStateIdle, Transmitting,
888
                      RxByteCnt, RxByteCntEq0, RxByteCntGreat2, RxByteCntMaxFrame,
889
                      InvalidSymbol, MRxD, LatchedCrcError, Collision, CollValid, RxLateCollision,
890
                      r_RecSmall, r_MinFL, r_MaxFL, ShortFrame, DribbleNibble, ReceivedPacketTooBig, r_HugEn,
891
                      LoadRxStatus, StartTxDone, StartTxAbort, RetryCnt, RetryCntLatched, MTxClk, MaxCollisionOccured,
892
                      RetryLimit, LateCollision, LateCollLatched, DeferIndication, DeferLatched, RstDeferLatched, TxStartFrm,
893
                      StatePreamble, StateData, CarrierSense, CarrierSenseLost, TxUsedData, LatchedMRxErr, Loopback,
894
                      r_FullD
895
                    );
896
 
897
 
898
 
899
parameter Tp = 1;
900
 
901
 
902
input         MRxClk;
903
input         Reset;
904
input         RxCrcError;
905
input         MRxErr;
906
input         MRxDV;
907
 
908
input         RxStateSFD;
909
input   [1:0] RxStateData;
910
input         RxStatePreamble;
911
input         RxStateIdle;
912
input         Transmitting;
913
input  [15:0] RxByteCnt;
914
input         RxByteCntEq0;
915
input         RxByteCntGreat2;
916
input         RxByteCntMaxFrame;
917
input   [3:0] MRxD;
918
input         Collision;
919
input   [5:0] CollValid;
920
input         r_RecSmall;
921
input  [15:0] r_MinFL;
922
input  [15:0] r_MaxFL;
923
input         r_HugEn;
924
input         StartTxDone;
925
input         StartTxAbort;
926
input   [3:0] RetryCnt;
927
input         MTxClk;
928
input         MaxCollisionOccured;
929
input         LateCollision;
930
input         DeferIndication;
931
input         TxStartFrm;
932
input         StatePreamble;
933
input   [1:0] StateData;
934
input         CarrierSense;
935
input         TxUsedData;
936
input         Loopback;
937
input         r_FullD;
938
 
939
 
940
output        ReceivedLengthOK;
941
output        ReceiveEnd;
942
output        ReceivedPacketGood;
943
output        InvalidSymbol;
944
output        LatchedCrcError;
945
output        RxLateCollision;
946
output        ShortFrame;
947
output        DribbleNibble;
948
output        ReceivedPacketTooBig;
949
output        LoadRxStatus;
950
output  [3:0] RetryCntLatched;
951
output        RetryLimit;
952
output        LateCollLatched;
953
output        DeferLatched;
954
input         RstDeferLatched;
955
output        CarrierSenseLost;
956
output        LatchedMRxErr;
957
 
958
 
959
reg           ReceiveEnd;
960
 
961
reg           LatchedCrcError;
962
reg           LatchedMRxErr;
963
reg           LoadRxStatus;
964
reg           InvalidSymbol;
965
reg     [3:0] RetryCntLatched;
966
reg           RetryLimit;
967
reg           LateCollLatched;
968
reg           DeferLatched;
969
reg           CarrierSenseLost;
970
 
971
wire          TakeSample;
972
wire          SetInvalidSymbol; // Invalid symbol was received during reception in 100Mbps 
973
 
974
// Crc error
975
always @ (posedge MRxClk or posedge Reset)
976
begin
977
  if(Reset)
978
    LatchedCrcError <=#Tp 1'b0;
979
  else
980
  if(RxStateSFD)
981
    LatchedCrcError <=#Tp 1'b0;
982
  else
983
  if(RxStateData[0])
984
    LatchedCrcError <=#Tp RxCrcError & ~RxByteCntEq0;
985
end
986
 
987
 
988
// LatchedMRxErr
989
always @ (posedge MRxClk or posedge Reset)
990
begin
991
  if(Reset)
992
    LatchedMRxErr <=#Tp 1'b0;
993
  else
994
  if(MRxErr & MRxDV & (RxStatePreamble | RxStateSFD | (|RxStateData) | RxStateIdle & ~Transmitting))
995
    LatchedMRxErr <=#Tp 1'b1;
996
  else
997
    LatchedMRxErr <=#Tp 1'b0;
998
end
999
 
1000
 
1001
// ReceivedPacketGood
1002
assign ReceivedPacketGood = ~LatchedCrcError;
1003
 
1004
 
1005
// ReceivedLengthOK
1006
assign ReceivedLengthOK = RxByteCnt[15:0] >= r_MinFL[15:0] & RxByteCnt[15:0] <= r_MaxFL[15:0];
1007
 
1008
 
1009
 
1010
 
1011
 
1012
// Time to take a sample
1013
//assign TakeSample = |RxStateData     & ~MRxDV & RxByteCntGreat2  |
1014
assign TakeSample = (|RxStateData)   & (~MRxDV)                    |
1015
                      RxStateData[0] &   MRxDV & RxByteCntMaxFrame;
1016
 
1017
 
1018
// LoadRxStatus
1019
always @ (posedge MRxClk or posedge Reset)
1020
begin
1021
  if(Reset)
1022
    LoadRxStatus <=#Tp 1'b0;
1023
  else
1024
    LoadRxStatus <=#Tp TakeSample;
1025
end
1026
 
1027
 
1028
 
1029
// ReceiveEnd
1030
always @ (posedge MRxClk or posedge Reset)
1031
begin
1032
  if(Reset)
1033
    ReceiveEnd  <=#Tp 1'b0;
1034
  else
1035
    ReceiveEnd  <=#Tp LoadRxStatus;
1036
end
1037
 
1038
 
1039
// Invalid Symbol received during 100Mbps mode
1040
assign SetInvalidSymbol = MRxDV & MRxErr & MRxD[3:0] == 4'he;
1041
 
1042
 
1043
// InvalidSymbol
1044
always @ (posedge MRxClk or posedge Reset)
1045
begin
1046
  if(Reset)
1047
    InvalidSymbol <=#Tp 1'b0;
1048
  else
1049
  if(LoadRxStatus & ~SetInvalidSymbol)
1050
    InvalidSymbol <=#Tp 1'b0;
1051
  else
1052
  if(SetInvalidSymbol)
1053
    InvalidSymbol <=#Tp 1'b1;
1054
end
1055
 
1056
 
1057
// Late Collision
1058
 
1059
reg RxLateCollision;
1060
reg RxColWindow;
1061
// Collision Window
1062
always @ (posedge MRxClk or posedge Reset)
1063
begin
1064
  if(Reset)
1065
    RxLateCollision <=#Tp 1'b0;
1066
  else
1067
  if(LoadRxStatus)
1068
    RxLateCollision <=#Tp 1'b0;
1069
  else
1070
  if(Collision & (~r_FullD) & (~RxColWindow | r_RecSmall))
1071
    RxLateCollision <=#Tp 1'b1;
1072
end
1073
 
1074
// Collision Window
1075
always @ (posedge MRxClk or posedge Reset)
1076
begin
1077
  if(Reset)
1078
    RxColWindow <=#Tp 1'b1;
1079
  else
1080
  if(~Collision & RxByteCnt[5:0] == CollValid[5:0] & RxStateData[1])
1081
    RxColWindow <=#Tp 1'b0;
1082
  else
1083
  if(RxStateIdle)
1084
    RxColWindow <=#Tp 1'b1;
1085
end
1086
 
1087
 
1088
// ShortFrame
1089
reg ShortFrame;
1090
always @ (posedge MRxClk or posedge Reset)
1091
begin
1092
  if(Reset)
1093
    ShortFrame <=#Tp 1'b0;
1094
  else
1095
  if(LoadRxStatus)
1096
    ShortFrame <=#Tp 1'b0;
1097
  else
1098
  if(TakeSample)
1099
    ShortFrame <=#Tp RxByteCnt[15:0] < r_MinFL[15:0];
1100
end
1101
 
1102
 
1103
// DribbleNibble
1104
reg DribbleNibble;
1105
always @ (posedge MRxClk or posedge Reset)
1106
begin
1107
  if(Reset)
1108
    DribbleNibble <=#Tp 1'b0;
1109
  else
1110
  if(RxStateSFD)
1111
    DribbleNibble <=#Tp 1'b0;
1112
  else
1113
  if(~MRxDV & RxStateData[1])
1114
    DribbleNibble <=#Tp 1'b1;
1115
end
1116
 
1117
 
1118
reg ReceivedPacketTooBig;
1119
always @ (posedge MRxClk or posedge Reset)
1120
begin
1121
  if(Reset)
1122
    ReceivedPacketTooBig <=#Tp 1'b0;
1123
  else
1124
  if(LoadRxStatus)
1125
    ReceivedPacketTooBig <=#Tp 1'b0;
1126
  else
1127
  if(TakeSample)
1128
    ReceivedPacketTooBig <=#Tp ~r_HugEn & RxByteCnt[15:0] > r_MaxFL[15:0];
1129
end
1130
 
1131
 
1132
 
1133
// Latched Retry counter for tx status
1134
always @ (posedge MTxClk or posedge Reset)
1135
begin
1136
  if(Reset)
1137
    RetryCntLatched <=#Tp 4'h0;
1138
  else
1139
  if(StartTxDone | StartTxAbort)
1140
    RetryCntLatched <=#Tp RetryCnt;
1141
end
1142
 
1143
 
1144
// Latched Retransmission limit
1145
always @ (posedge MTxClk or posedge Reset)
1146
begin
1147
  if(Reset)
1148
    RetryLimit <=#Tp 1'h0;
1149
  else
1150
  if(StartTxDone | StartTxAbort)
1151
    RetryLimit <=#Tp MaxCollisionOccured;
1152
end
1153
 
1154
 
1155
// Latched Late Collision
1156
always @ (posedge MTxClk or posedge Reset)
1157
begin
1158
  if(Reset)
1159
    LateCollLatched <=#Tp 1'b0;
1160
  else
1161
  if(StartTxDone | StartTxAbort)
1162
    LateCollLatched <=#Tp LateCollision;
1163
end
1164
 
1165
 
1166
 
1167
// Latched Defer state
1168
always @ (posedge MTxClk or posedge Reset)
1169
begin
1170
  if(Reset)
1171
    DeferLatched <=#Tp 1'b0;
1172
  else
1173
  if(DeferIndication)
1174
    DeferLatched <=#Tp 1'b1;
1175
  else
1176
  if(RstDeferLatched)
1177
    DeferLatched <=#Tp 1'b0;
1178
end
1179
 
1180
 
1181
// CarrierSenseLost
1182
always @ (posedge MTxClk or posedge Reset)
1183
begin
1184
  if(Reset)
1185
    CarrierSenseLost <=#Tp 1'b0;
1186
  else
1187
  if((StatePreamble | (|StateData)) & ~CarrierSense & ~Loopback & ~Collision & ~r_FullD)
1188
    CarrierSenseLost <=#Tp 1'b1;
1189
  else
1190
  if(TxStartFrm)
1191
    CarrierSenseLost <=#Tp 1'b0;
1192
end
1193
 
1194
 
1195
endmodule
1196
//////////////////////////////////////////////////////////////////////
1197
////                                                              ////
1198
////  eth_miim.v                                                  ////
1199
////                                                              ////
1200
////  This file is part of the Ethernet IP core project           ////
1201
////  http://www.opencores.org/projects/ethmac/                   ////
1202
////                                                              ////
1203
////  Author(s):                                                  ////
1204
////      - Igor Mohor (igorM@opencores.org)                      ////
1205
////                                                              ////
1206
////  All additional information is avaliable in the Readme.txt   ////
1207
////  file.                                                       ////
1208
////                                                              ////
1209
//////////////////////////////////////////////////////////////////////
1210
////                                                              ////
1211
//// Copyright (C) 2001 Authors                                   ////
1212
////                                                              ////
1213
//// This source file may be used and distributed without         ////
1214
//// restriction provided that this copyright statement is not    ////
1215
//// removed from the file and that any derivative work contains  ////
1216
//// the original copyright notice and the associated disclaimer. ////
1217
////                                                              ////
1218
//// This source file is free software; you can redistribute it   ////
1219
//// and/or modify it under the terms of the GNU Lesser General   ////
1220
//// Public License as published by the Free Software Foundation; ////
1221
//// either version 2.1 of the License, or (at your option) any   ////
1222
//// later version.                                               ////
1223
////                                                              ////
1224
//// This source is distributed in the hope that it will be       ////
1225
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1226
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1227
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1228
//// details.                                                     ////
1229
////                                                              ////
1230
//// You should have received a copy of the GNU Lesser General    ////
1231
//// Public License along with this source; if not, download it   ////
1232
//// from http://www.opencores.org/lgpl.shtml                     ////
1233
////                                                              ////
1234
//////////////////////////////////////////////////////////////////////
1235
//
1236
// CVS Revision History
1237
//
1238
// $Log: eth_miim.v,v $
1239
// Revision 1.7  2005/03/21 20:07:18  igorm
1240
// Some small fixes + some troubles fixed.
1241
//
1242
// Revision 1.6  2005/02/21 12:48:07  igorm
1243
// Warning fixes.
1244
//
1245
// Revision 1.5  2003/05/16 10:08:27  mohor
1246
// Busy was set 2 cycles too late. Reported by Dennis Scott.
1247
//
1248
// Revision 1.4  2002/08/14 18:32:10  mohor
1249
// - Busy signal was not set on time when scan status operation was performed
1250
// and clock was divided with more than 2.
1251
// - Nvalid remains valid two more clocks (was previously cleared too soon).
1252
//
1253
// Revision 1.3  2002/01/23 10:28:16  mohor
1254
// Link in the header changed.
1255
//
1256
// Revision 1.2  2001/10/19 08:43:51  mohor
1257
// eth_timescale.v changed to timescale.v This is done because of the
1258
// simulation of the few cores in a one joined project.
1259
//
1260
// Revision 1.1  2001/08/06 14:44:29  mohor
1261
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
1262
// Include files fixed to contain no path.
1263
// File names and module names changed ta have a eth_ prologue in the name.
1264
// File eth_timescale.v is used to define timescale
1265
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
1266
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
1267
// and Mdo_OE. The bidirectional signal must be created on the top level. This
1268
// is done due to the ASIC tools.
1269
//
1270
// Revision 1.2  2001/08/02 09:25:31  mohor
1271
// Unconnected signals are now connected.
1272
//
1273
// Revision 1.1  2001/07/30 21:23:42  mohor
1274
// Directory structure changed. Files checked and joind together.
1275
//
1276
// Revision 1.3  2001/06/01 22:28:56  mohor
1277
// This files (MIIM) are fully working. They were thoroughly tested. The testbench is not updated.
1278
//
1279
//
1280
 
1281
`include "timescale.v"
1282
 
1283
 
1284
module eth_miim
1285
(
1286
  Clk,
1287
  Reset,
1288
  Divider,
1289
  NoPre,
1290
  CtrlData,
1291
  Rgad,
1292
  Fiad,
1293
  WCtrlData,
1294
  RStat,
1295
  ScanStat,
1296
  Mdi,
1297
  Mdo,
1298
  MdoEn,
1299
  Mdc,
1300
  Busy,
1301
  Prsd,
1302
  LinkFail,
1303
  Nvalid,
1304
  WCtrlDataStart,
1305
  RStatStart,
1306
  UpdateMIIRX_DATAReg
1307
);
1308
 
1309
 
1310
 
1311
input         Clk;                // Host Clock
1312
input         Reset;              // General Reset
1313
input   [7:0] Divider;            // Divider for the host clock
1314
input  [15:0] CtrlData;           // Control Data (to be written to the PHY reg.)
1315
input   [4:0] Rgad;               // Register Address (within the PHY)
1316
input   [4:0] Fiad;               // PHY Address
1317
input         NoPre;              // No Preamble (no 32-bit preamble)
1318
input         WCtrlData;          // Write Control Data operation
1319
input         RStat;              // Read Status operation
1320
input         ScanStat;           // Scan Status operation
1321
input         Mdi;                // MII Management Data In
1322
 
1323
output        Mdc;                // MII Management Data Clock
1324
output        Mdo;                // MII Management Data Output
1325
output        MdoEn;              // MII Management Data Output Enable
1326
output        Busy;               // Busy Signal
1327
output        LinkFail;           // Link Integrity Signal
1328
output        Nvalid;             // Invalid Status (qualifier for the valid scan result)
1329
 
1330
output [15:0] Prsd;               // Read Status Data (data read from the PHY)
1331
 
1332
output        WCtrlDataStart;     // This signals resets the WCTRLDATA bit in the MIIM Command register
1333
output        RStatStart;         // This signal resets the RSTAT BIT in the MIIM Command register
1334
output        UpdateMIIRX_DATAReg;// Updates MII RX_DATA register with read data
1335
 
1336
parameter Tp = 1;
1337
 
1338
 
1339
reg           Nvalid;
1340
reg           EndBusy_d;          // Pre-end Busy signal
1341
reg           EndBusy;            // End Busy signal (stops the operation in progress)
1342
 
1343
reg           WCtrlData_q1;       // Write Control Data operation delayed 1 Clk cycle
1344
reg           WCtrlData_q2;       // Write Control Data operation delayed 2 Clk cycles
1345
reg           WCtrlData_q3;       // Write Control Data operation delayed 3 Clk cycles
1346
reg           WCtrlDataStart;     // Start Write Control Data Command (positive edge detected)
1347
reg           WCtrlDataStart_q;
1348
reg           WCtrlDataStart_q1;  // Start Write Control Data Command delayed 1 Mdc cycle
1349
reg           WCtrlDataStart_q2;  // Start Write Control Data Command delayed 2 Mdc cycles
1350
 
1351
reg           RStat_q1;           // Read Status operation delayed 1 Clk cycle
1352
reg           RStat_q2;           // Read Status operation delayed 2 Clk cycles
1353
reg           RStat_q3;           // Read Status operation delayed 3 Clk cycles
1354
reg           RStatStart;         // Start Read Status Command (positive edge detected)
1355
reg           RStatStart_q1;      // Start Read Status Command delayed 1 Mdc cycle
1356
reg           RStatStart_q2;      // Start Read Status Command delayed 2 Mdc cycles
1357
 
1358
reg           ScanStat_q1;        // Scan Status operation delayed 1 cycle
1359
reg           ScanStat_q2;        // Scan Status operation delayed 2 cycles
1360
reg           SyncStatMdcEn;      // Scan Status operation delayed at least cycles and synchronized to MdcEn
1361
 
1362
wire          WriteDataOp;        // Write Data Operation (positive edge detected)
1363
wire          ReadStatusOp;       // Read Status Operation (positive edge detected)
1364
wire          ScanStatusOp;       // Scan Status Operation (positive edge detected)
1365
wire          StartOp;            // Start Operation (start of any of the preceding operations)
1366
wire          EndOp;              // End of Operation
1367
 
1368
reg           InProgress;         // Operation in progress
1369
reg           InProgress_q1;      // Operation in progress delayed 1 Mdc cycle
1370
reg           InProgress_q2;      // Operation in progress delayed 2 Mdc cycles
1371
reg           InProgress_q3;      // Operation in progress delayed 3 Mdc cycles
1372
 
1373
reg           WriteOp;            // Write Operation Latch (When asserted, write operation is in progress)
1374
reg     [6:0] BitCounter;         // Bit Counter
1375
 
1376
 
1377
wire    [3:0] ByteSelect;         // Byte Select defines which byte (preamble, data, operation, etc.) is loaded and shifted through the shift register.
1378
wire          MdcEn;              // MII Management Data Clock Enable signal is asserted for one Clk period before Mdc rises.
1379
wire          ShiftedBit;         // This bit is output of the shift register and is connected to the Mdo signal
1380
wire          MdcEn_n;
1381
 
1382
wire          LatchByte1_d2;
1383
wire          LatchByte0_d2;
1384
reg           LatchByte1_d;
1385
reg           LatchByte0_d;
1386
reg     [1:0] LatchByte;          // Latch Byte selects which part of Read Status Data is updated from the shift register
1387
 
1388
reg           UpdateMIIRX_DATAReg;// Updates MII RX_DATA register with read data
1389
 
1390
 
1391
 
1392
 
1393
 
1394
// Generation of the EndBusy signal. It is used for ending the MII Management operation.
1395
always @ (posedge Clk or posedge Reset)
1396
begin
1397
  if(Reset)
1398
    begin
1399
      EndBusy_d <= #Tp 1'b0;
1400
      EndBusy <= #Tp 1'b0;
1401
    end
1402
  else
1403
    begin
1404
      EndBusy_d <= #Tp ~InProgress_q2 & InProgress_q3;
1405
      EndBusy   <= #Tp EndBusy_d;
1406
    end
1407
end
1408
 
1409
 
1410
// Update MII RX_DATA register
1411
always @ (posedge Clk or posedge Reset)
1412
begin
1413
  if(Reset)
1414
    UpdateMIIRX_DATAReg <= #Tp 0;
1415
  else
1416
  if(EndBusy & ~WCtrlDataStart_q)
1417
    UpdateMIIRX_DATAReg <= #Tp 1;
1418
  else
1419
    UpdateMIIRX_DATAReg <= #Tp 0;
1420
end
1421
 
1422
 
1423
 
1424
// Generation of the delayed signals used for positive edge triggering.
1425
always @ (posedge Clk or posedge Reset)
1426
begin
1427
  if(Reset)
1428
    begin
1429
      WCtrlData_q1 <= #Tp 1'b0;
1430
      WCtrlData_q2 <= #Tp 1'b0;
1431
      WCtrlData_q3 <= #Tp 1'b0;
1432
 
1433
      RStat_q1 <= #Tp 1'b0;
1434
      RStat_q2 <= #Tp 1'b0;
1435
      RStat_q3 <= #Tp 1'b0;
1436
 
1437
      ScanStat_q1  <= #Tp 1'b0;
1438
      ScanStat_q2  <= #Tp 1'b0;
1439
      SyncStatMdcEn <= #Tp 1'b0;
1440
    end
1441
  else
1442
    begin
1443
      WCtrlData_q1 <= #Tp WCtrlData;
1444
      WCtrlData_q2 <= #Tp WCtrlData_q1;
1445
      WCtrlData_q3 <= #Tp WCtrlData_q2;
1446
 
1447
      RStat_q1 <= #Tp RStat;
1448
      RStat_q2 <= #Tp RStat_q1;
1449
      RStat_q3 <= #Tp RStat_q2;
1450
 
1451
      ScanStat_q1  <= #Tp ScanStat;
1452
      ScanStat_q2  <= #Tp ScanStat_q1;
1453
      if(MdcEn)
1454
        SyncStatMdcEn  <= #Tp ScanStat_q2;
1455
    end
1456
end
1457
 
1458
 
1459
// Generation of the Start Commands (Write Control Data or Read Status)
1460
always @ (posedge Clk or posedge Reset)
1461
begin
1462
  if(Reset)
1463
    begin
1464
      WCtrlDataStart <= #Tp 1'b0;
1465
      WCtrlDataStart_q <= #Tp 1'b0;
1466
      RStatStart <= #Tp 1'b0;
1467
    end
1468
  else
1469
    begin
1470
      if(EndBusy)
1471
        begin
1472
          WCtrlDataStart <= #Tp 1'b0;
1473
          RStatStart <= #Tp 1'b0;
1474
        end
1475
      else
1476
        begin
1477
          if(WCtrlData_q2 & ~WCtrlData_q3)
1478
            WCtrlDataStart <= #Tp 1'b1;
1479
          if(RStat_q2 & ~RStat_q3)
1480
            RStatStart <= #Tp 1'b1;
1481
          WCtrlDataStart_q <= #Tp WCtrlDataStart;
1482
        end
1483
    end
1484
end
1485
 
1486
 
1487
// Generation of the Nvalid signal (indicates when the status is invalid)
1488
always @ (posedge Clk or posedge Reset)
1489
begin
1490
  if(Reset)
1491
    Nvalid <= #Tp 1'b0;
1492
  else
1493
    begin
1494
      if(~InProgress_q2 & InProgress_q3)
1495
        begin
1496
          Nvalid <= #Tp 1'b0;
1497
        end
1498
      else
1499
        begin
1500
          if(ScanStat_q2  & ~SyncStatMdcEn)
1501
            Nvalid <= #Tp 1'b1;
1502
        end
1503
    end
1504
end
1505
 
1506
// Signals used for the generation of the Operation signals (positive edge)
1507
always @ (posedge Clk or posedge Reset)
1508
begin
1509
  if(Reset)
1510
    begin
1511
      WCtrlDataStart_q1 <= #Tp 1'b0;
1512
      WCtrlDataStart_q2 <= #Tp 1'b0;
1513
 
1514
      RStatStart_q1 <= #Tp 1'b0;
1515
      RStatStart_q2 <= #Tp 1'b0;
1516
 
1517
      InProgress_q1 <= #Tp 1'b0;
1518
      InProgress_q2 <= #Tp 1'b0;
1519
      InProgress_q3 <= #Tp 1'b0;
1520
 
1521
          LatchByte0_d <= #Tp 1'b0;
1522
          LatchByte1_d <= #Tp 1'b0;
1523
 
1524
          LatchByte <= #Tp 2'b00;
1525
    end
1526
  else
1527
    begin
1528
      if(MdcEn)
1529
        begin
1530
          WCtrlDataStart_q1 <= #Tp WCtrlDataStart;
1531
          WCtrlDataStart_q2 <= #Tp WCtrlDataStart_q1;
1532
 
1533
          RStatStart_q1 <= #Tp RStatStart;
1534
          RStatStart_q2 <= #Tp RStatStart_q1;
1535
 
1536
          LatchByte[0] <= #Tp LatchByte0_d;
1537
          LatchByte[1] <= #Tp LatchByte1_d;
1538
 
1539
          LatchByte0_d <= #Tp LatchByte0_d2;
1540
          LatchByte1_d <= #Tp LatchByte1_d2;
1541
 
1542
          InProgress_q1 <= #Tp InProgress;
1543
          InProgress_q2 <= #Tp InProgress_q1;
1544
          InProgress_q3 <= #Tp InProgress_q2;
1545
        end
1546
    end
1547
end
1548
 
1549
 
1550
// Generation of the Operation signals
1551
assign WriteDataOp  = WCtrlDataStart_q1 & ~WCtrlDataStart_q2;
1552
assign ReadStatusOp = RStatStart_q1     & ~RStatStart_q2;
1553
assign ScanStatusOp = SyncStatMdcEn     & ~InProgress & ~InProgress_q1 & ~InProgress_q2;
1554
assign StartOp      = WriteDataOp | ReadStatusOp | ScanStatusOp;
1555
 
1556
// Busy
1557
assign Busy = WCtrlData | WCtrlDataStart | RStat | RStatStart | SyncStatMdcEn | EndBusy | InProgress | InProgress_q3 | Nvalid;
1558
 
1559
 
1560
// Generation of the InProgress signal (indicates when an operation is in progress)
1561
// Generation of the WriteOp signal (indicates when a write is in progress)
1562
always @ (posedge Clk or posedge Reset)
1563
begin
1564
  if(Reset)
1565
    begin
1566
      InProgress <= #Tp 1'b0;
1567
      WriteOp <= #Tp 1'b0;
1568
    end
1569
  else
1570
    begin
1571
      if(MdcEn)
1572
        begin
1573
          if(StartOp)
1574
            begin
1575
              if(~InProgress)
1576
                WriteOp <= #Tp WriteDataOp;
1577
              InProgress <= #Tp 1'b1;
1578
            end
1579
          else
1580
            begin
1581
              if(EndOp)
1582
                begin
1583
                  InProgress <= #Tp 1'b0;
1584
                  WriteOp <= #Tp 1'b0;
1585
                end
1586
            end
1587
        end
1588
    end
1589
end
1590
 
1591
 
1592
 
1593
// Bit Counter counts from 0 to 63 (from 32 to 63 when NoPre is asserted)
1594
always @ (posedge Clk or posedge Reset)
1595
begin
1596
  if(Reset)
1597
    BitCounter[6:0] <= #Tp 7'h0;
1598
  else
1599
    begin
1600
      if(MdcEn)
1601
        begin
1602
          if(InProgress)
1603
            begin
1604
              if(NoPre & ( BitCounter == 7'h0 ))
1605
                BitCounter[6:0] <= #Tp 7'h21;
1606
              else
1607
                BitCounter[6:0] <= #Tp BitCounter[6:0] + 1'b1;
1608
            end
1609
          else
1610
            BitCounter[6:0] <= #Tp 7'h0;
1611
        end
1612
    end
1613
end
1614
 
1615
 
1616
// Operation ends when the Bit Counter reaches 63
1617
assign EndOp = BitCounter==63;
1618
 
1619
assign ByteSelect[0] = InProgress & ((NoPre & (BitCounter == 7'h0)) | (~NoPre & (BitCounter == 7'h20)));
1620
assign ByteSelect[1] = InProgress & (BitCounter == 7'h28);
1621
assign ByteSelect[2] = InProgress & WriteOp & (BitCounter == 7'h30);
1622
assign ByteSelect[3] = InProgress & WriteOp & (BitCounter == 7'h38);
1623
 
1624
 
1625
// Latch Byte selects which part of Read Status Data is updated from the shift register
1626
assign LatchByte1_d2 = InProgress & ~WriteOp & BitCounter == 7'h37;
1627
assign LatchByte0_d2 = InProgress & ~WriteOp & BitCounter == 7'h3F;
1628
 
1629
 
1630
// Connecting the Clock Generator Module
1631
eth_clockgen clkgen(.Clk(Clk), .Reset(Reset), .Divider(Divider[7:0]), .MdcEn(MdcEn), .MdcEn_n(MdcEn_n), .Mdc(Mdc)
1632
                   );
1633
 
1634
// Connecting the Shift Register Module
1635
eth_shiftreg shftrg(.Clk(Clk), .Reset(Reset), .MdcEn_n(MdcEn_n), .Mdi(Mdi), .Fiad(Fiad), .Rgad(Rgad),
1636
                    .CtrlData(CtrlData), .WriteOp(WriteOp), .ByteSelect(ByteSelect), .LatchByte(LatchByte),
1637
                    .ShiftedBit(ShiftedBit), .Prsd(Prsd), .LinkFail(LinkFail)
1638
                   );
1639
 
1640
// Connecting the Output Control Module
1641
eth_outputcontrol outctrl(.Clk(Clk), .Reset(Reset), .MdcEn_n(MdcEn_n), .InProgress(InProgress),
1642
                          .ShiftedBit(ShiftedBit), .BitCounter(BitCounter), .WriteOp(WriteOp), .NoPre(NoPre),
1643
                          .Mdo(Mdo), .MdoEn(MdoEn)
1644
                         );
1645
 
1646
endmodule
1647
//////////////////////////////////////////////////////////////////////
1648
////                                                              ////
1649
////  eth_outputcontrol.v                                         ////
1650
////                                                              ////
1651
////  This file is part of the Ethernet IP core project           ////
1652
////  http://www.opencores.org/projects/ethmac/                   ////
1653
////                                                              ////
1654
////  Author(s):                                                  ////
1655
////      - Igor Mohor (igorM@opencores.org)                      ////
1656
////                                                              ////
1657
////  All additional information is avaliable in the Readme.txt   ////
1658
////  file.                                                       ////
1659
////                                                              ////
1660
//////////////////////////////////////////////////////////////////////
1661
////                                                              ////
1662
//// Copyright (C) 2001 Authors                                   ////
1663
////                                                              ////
1664
//// This source file may be used and distributed without         ////
1665
//// restriction provided that this copyright statement is not    ////
1666
//// removed from the file and that any derivative work contains  ////
1667
//// the original copyright notice and the associated disclaimer. ////
1668
////                                                              ////
1669
//// This source file is free software; you can redistribute it   ////
1670
//// and/or modify it under the terms of the GNU Lesser General   ////
1671
//// Public License as published by the Free Software Foundation; ////
1672
//// either version 2.1 of the License, or (at your option) any   ////
1673
//// later version.                                               ////
1674
////                                                              ////
1675
//// This source is distributed in the hope that it will be       ////
1676
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1677
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1678
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1679
//// details.                                                     ////
1680
////                                                              ////
1681
//// You should have received a copy of the GNU Lesser General    ////
1682
//// Public License along with this source; if not, download it   ////
1683
//// from http://www.opencores.org/lgpl.shtml                     ////
1684
////                                                              ////
1685
//////////////////////////////////////////////////////////////////////
1686
//
1687
// CVS Revision History
1688
//
1689
// $Log: eth_outputcontrol.v,v $
1690
// Revision 1.4  2002/07/09 20:11:59  mohor
1691
// Comment removed.
1692
//
1693
// Revision 1.3  2002/01/23 10:28:16  mohor
1694
// Link in the header changed.
1695
//
1696
// Revision 1.2  2001/10/19 08:43:51  mohor
1697
// eth_timescale.v changed to timescale.v This is done because of the
1698
// simulation of the few cores in a one joined project.
1699
//
1700
// Revision 1.1  2001/08/06 14:44:29  mohor
1701
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
1702
// Include files fixed to contain no path.
1703
// File names and module names changed ta have a eth_ prologue in the name.
1704
// File eth_timescale.v is used to define timescale
1705
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
1706
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
1707
// and Mdo_OE. The bidirectional signal must be created on the top level. This
1708
// is done due to the ASIC tools.
1709
//
1710
// Revision 1.1  2001/07/30 21:23:42  mohor
1711
// Directory structure changed. Files checked and joind together.
1712
//
1713
// Revision 1.3  2001/06/01 22:28:56  mohor
1714
// This files (MIIM) are fully working. They were thoroughly tested. The testbench is not updated.
1715
//
1716
//
1717
 
1718
`include "timescale.v"
1719
 
1720
module eth_outputcontrol(Clk, Reset, InProgress, ShiftedBit, BitCounter, WriteOp, NoPre, MdcEn_n, Mdo, MdoEn);
1721
 
1722
parameter Tp = 1;
1723
 
1724
input         Clk;                // Host Clock
1725
input         Reset;              // General Reset
1726
input         WriteOp;            // Write Operation Latch (When asserted, write operation is in progress)
1727
input         NoPre;              // No Preamble (no 32-bit preamble)
1728
input         InProgress;         // Operation in progress
1729
input         ShiftedBit;         // This bit is output of the shift register and is connected to the Mdo signal
1730
input   [6:0] BitCounter;         // Bit Counter
1731
input         MdcEn_n;            // MII Management Data Clock Enable signal is asserted for one Clk period before Mdc falls.
1732
 
1733
output        Mdo;                // MII Management Data Output
1734
output        MdoEn;              // MII Management Data Output Enable
1735
 
1736
wire          SerialEn;
1737
 
1738
reg           MdoEn_2d;
1739
reg           MdoEn_d;
1740
reg           MdoEn;
1741
 
1742
reg           Mdo_2d;
1743
reg           Mdo_d;
1744
reg           Mdo;                // MII Management Data Output
1745
 
1746
 
1747
 
1748
// Generation of the Serial Enable signal (enables the serialization of the data)
1749
assign SerialEn =  WriteOp & InProgress & ( BitCounter>31 | ( ( BitCounter == 0 ) & NoPre ) )
1750
                | ~WriteOp & InProgress & (( BitCounter>31 & BitCounter<46 ) | ( ( BitCounter == 0 ) & NoPre ));
1751
 
1752
 
1753
// Generation of the MdoEn signal
1754
always @ (posedge Clk or posedge Reset)
1755
begin
1756
  if(Reset)
1757
    begin
1758
      MdoEn_2d <= #Tp 1'b0;
1759
      MdoEn_d <= #Tp 1'b0;
1760
      MdoEn <= #Tp 1'b0;
1761
    end
1762
  else
1763
    begin
1764
      if(MdcEn_n)
1765
        begin
1766
          MdoEn_2d <= #Tp SerialEn | InProgress & BitCounter<32;
1767
          MdoEn_d <= #Tp MdoEn_2d;
1768
          MdoEn <= #Tp MdoEn_d;
1769
        end
1770
    end
1771
end
1772
 
1773
 
1774
// Generation of the Mdo signal.
1775
always @ (posedge Clk or posedge Reset)
1776
begin
1777
  if(Reset)
1778
    begin
1779
      Mdo_2d <= #Tp 1'b0;
1780
      Mdo_d <= #Tp 1'b0;
1781
      Mdo <= #Tp 1'b0;
1782
    end
1783
  else
1784
    begin
1785
      if(MdcEn_n)
1786
        begin
1787
          Mdo_2d <= #Tp ~SerialEn & BitCounter<32;
1788
          Mdo_d <= #Tp ShiftedBit | Mdo_2d;
1789
          Mdo <= #Tp Mdo_d;
1790
        end
1791
    end
1792
end
1793
 
1794
 
1795
 
1796
endmodule
1797
//////////////////////////////////////////////////////////////////////
1798
////                                                              ////
1799
////  eth_random.v                                                ////
1800
////                                                              ////
1801
////  This file is part of the Ethernet IP core project           ////
1802
////  http://www.opencores.org/projects/ethmac/                   ////
1803
////                                                              ////
1804
////  Author(s):                                                  ////
1805
////      - Igor Mohor (igorM@opencores.org)                      ////
1806
////      - Novan Hartadi (novan@vlsi.itb.ac.id)                  ////
1807
////      - Mahmud Galela (mgalela@vlsi.itb.ac.id)                ////
1808
////                                                              ////
1809
////  All additional information is avaliable in the Readme.txt   ////
1810
////  file.                                                       ////
1811
////                                                              ////
1812
//////////////////////////////////////////////////////////////////////
1813
////                                                              ////
1814
//// Copyright (C) 2001 Authors                                   ////
1815
////                                                              ////
1816
//// This source file may be used and distributed without         ////
1817
//// restriction provided that this copyright statement is not    ////
1818
//// removed from the file and that any derivative work contains  ////
1819
//// the original copyright notice and the associated disclaimer. ////
1820
////                                                              ////
1821
//// This source file is free software; you can redistribute it   ////
1822
//// and/or modify it under the terms of the GNU Lesser General   ////
1823
//// Public License as published by the Free Software Foundation; ////
1824
//// either version 2.1 of the License, or (at your option) any   ////
1825
//// later version.                                               ////
1826
////                                                              ////
1827
//// This source is distributed in the hope that it will be       ////
1828
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1829
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1830
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1831
//// details.                                                     ////
1832
////                                                              ////
1833
//// You should have received a copy of the GNU Lesser General    ////
1834
//// Public License along with this source; if not, download it   ////
1835
//// from http://www.opencores.org/lgpl.shtml                     ////
1836
////                                                              ////
1837
//////////////////////////////////////////////////////////////////////
1838
//
1839
// CVS Revision History
1840
//
1841
// $Log: eth_random.v,v $
1842
// Revision 1.4  2003/06/13 11:26:08  mohor
1843
// Binary operator used instead of unary (xnor).
1844
//
1845
// Revision 1.3  2002/01/23 10:28:16  mohor
1846
// Link in the header changed.
1847
//
1848
// Revision 1.2  2001/10/19 08:43:51  mohor
1849
// eth_timescale.v changed to timescale.v This is done because of the
1850
// simulation of the few cores in a one joined project.
1851
//
1852
// Revision 1.1  2001/08/06 14:44:29  mohor
1853
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
1854
// Include files fixed to contain no path.
1855
// File names and module names changed ta have a eth_ prologue in the name.
1856
// File eth_timescale.v is used to define timescale
1857
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
1858
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
1859
// and Mdo_OE. The bidirectional signal must be created on the top level. This
1860
// is done due to the ASIC tools.
1861
//
1862
// Revision 1.1  2001/07/30 21:23:42  mohor
1863
// Directory structure changed. Files checked and joind together.
1864
//
1865
// Revision 1.3  2001/06/19 18:16:40  mohor
1866
// TxClk changed to MTxClk (as discribed in the documentation).
1867
// Crc changed so only one file can be used instead of two.
1868
//
1869
// Revision 1.2  2001/06/19 10:38:07  mohor
1870
// Minor changes in header.
1871
//
1872
// Revision 1.1  2001/06/19 10:27:57  mohor
1873
// TxEthMAC initial release.
1874
//
1875
//
1876
//
1877
//
1878
 
1879
`include "timescale.v"
1880
 
1881
module eth_random (MTxClk, Reset, StateJam, StateJam_q, RetryCnt, NibCnt, ByteCnt,
1882
                   RandomEq0, RandomEqByteCnt);
1883
 
1884
parameter Tp = 1;
1885
 
1886
input MTxClk;
1887
input Reset;
1888
input StateJam;
1889
input StateJam_q;
1890
input [3:0] RetryCnt;
1891
input [15:0] NibCnt;
1892
input [9:0] ByteCnt;
1893
output RandomEq0;
1894
output RandomEqByteCnt;
1895
 
1896
wire Feedback;
1897
reg [9:0] x;
1898
wire [9:0] Random;
1899
reg  [9:0] RandomLatched;
1900
 
1901
 
1902
always @ (posedge MTxClk or posedge Reset)
1903
begin
1904
  if(Reset)
1905
    x[9:0] <= #Tp 0;
1906
  else
1907
    x[9:0] <= #Tp {x[8:0], Feedback};
1908
end
1909
 
1910
assign Feedback = ~(x[2] ^ x[9]);
1911
 
1912
assign Random [0] = x[0];
1913
assign Random [1] = (RetryCnt > 1) ? x[1] : 1'b0;
1914
assign Random [2] = (RetryCnt > 2) ? x[2] : 1'b0;
1915
assign Random [3] = (RetryCnt > 3) ? x[3] : 1'b0;
1916
assign Random [4] = (RetryCnt > 4) ? x[4] : 1'b0;
1917
assign Random [5] = (RetryCnt > 5) ? x[5] : 1'b0;
1918
assign Random [6] = (RetryCnt > 6) ? x[6] : 1'b0;
1919
assign Random [7] = (RetryCnt > 7) ? x[7] : 1'b0;
1920
assign Random [8] = (RetryCnt > 8) ? x[8] : 1'b0;
1921
assign Random [9] = (RetryCnt > 9) ? x[9] : 1'b0;
1922
 
1923
 
1924
always @ (posedge MTxClk or posedge Reset)
1925
begin
1926
  if(Reset)
1927
    RandomLatched <= #Tp 10'h000;
1928
  else
1929
    begin
1930
      if(StateJam & StateJam_q)
1931
        RandomLatched <= #Tp Random;
1932
    end
1933
end
1934
 
1935
// Random Number == 0      IEEE 802.3 page 68. If 0 we go to defer and not to backoff.
1936
assign RandomEq0 = RandomLatched == 10'h0;
1937
 
1938
assign RandomEqByteCnt = ByteCnt[9:0] == RandomLatched & (&NibCnt[6:0]);
1939
 
1940
endmodule
1941
//////////////////////////////////////////////////////////////////////
1942
////                                                              ////
1943
////  eth_receivecontrol.v                                        ////
1944
////                                                              ////
1945
////  This file is part of the Ethernet IP core project           ////
1946
////  http://www.opencores.org/projects/ethmac/                   ////
1947
////                                                              ////
1948
////  Author(s):                                                  ////
1949
////      - Igor Mohor (igorM@opencores.org)                      ////
1950
////                                                              ////
1951
////  All additional information is avaliable in the Readme.txt   ////
1952
////  file.                                                       ////
1953
////                                                              ////
1954
//////////////////////////////////////////////////////////////////////
1955
////                                                              ////
1956
//// Copyright (C) 2001 Authors                                   ////
1957
////                                                              ////
1958
//// This source file may be used and distributed without         ////
1959
//// restriction provided that this copyright statement is not    ////
1960
//// removed from the file and that any derivative work contains  ////
1961
//// the original copyright notice and the associated disclaimer. ////
1962
////                                                              ////
1963
//// This source file is free software; you can redistribute it   ////
1964
//// and/or modify it under the terms of the GNU Lesser General   ////
1965
//// Public License as published by the Free Software Foundation; ////
1966
//// either version 2.1 of the License, or (at your option) any   ////
1967
//// later version.                                               ////
1968
////                                                              ////
1969
//// This source is distributed in the hope that it will be       ////
1970
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
1971
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
1972
//// PURPOSE.  See the GNU Lesser General Public License for more ////
1973
//// details.                                                     ////
1974
////                                                              ////
1975
//// You should have received a copy of the GNU Lesser General    ////
1976
//// Public License along with this source; if not, download it   ////
1977
//// from http://www.opencores.org/lgpl.shtml                     ////
1978
////                                                              ////
1979
//////////////////////////////////////////////////////////////////////
1980
//
1981
// CVS Revision History
1982
//
1983
// $Log: eth_receivecontrol.v,v $
1984
// Revision 1.5  2003/01/22 13:49:26  tadejm
1985
// When control packets were received, they were ignored in some cases.
1986
//
1987
// Revision 1.4  2002/11/22 01:57:06  mohor
1988
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
1989
// synchronized.
1990
//
1991
// Revision 1.3  2002/01/23 10:28:16  mohor
1992
// Link in the header changed.
1993
//
1994
// Revision 1.2  2001/10/19 08:43:51  mohor
1995
// eth_timescale.v changed to timescale.v This is done because of the
1996
// simulation of the few cores in a one joined project.
1997
//
1998
// Revision 1.1  2001/08/06 14:44:29  mohor
1999
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
2000
// Include files fixed to contain no path.
2001
// File names and module names changed ta have a eth_ prologue in the name.
2002
// File eth_timescale.v is used to define timescale
2003
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
2004
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
2005
// and Mdo_OE. The bidirectional signal must be created on the top level. This
2006
// is done due to the ASIC tools.
2007
//
2008
// Revision 1.1  2001/07/30 21:23:42  mohor
2009
// Directory structure changed. Files checked and joind together.
2010
//
2011
// Revision 1.1  2001/07/03 12:51:54  mohor
2012
// Initial release of the MAC Control module.
2013
//
2014
//
2015
//
2016
//
2017
//
2018
 
2019
 
2020
`include "timescale.v"
2021
 
2022
 
2023
module eth_receivecontrol (MTxClk, MRxClk, TxReset, RxReset, RxData, RxValid, RxStartFrm,
2024
                           RxEndFrm, RxFlow, ReceiveEnd, MAC, DlyCrcEn, TxDoneIn,
2025
                           TxAbortIn, TxStartFrmOut, ReceivedLengthOK, ReceivedPacketGood,
2026
                           TxUsedDataOutDetected, Pause, ReceivedPauseFrm, AddressOK,
2027
                           RxStatusWriteLatched_sync2, r_PassAll, SetPauseTimer
2028
                          );
2029
 
2030
parameter Tp = 1;
2031
 
2032
 
2033
input       MTxClk;
2034
input       MRxClk;
2035
input       TxReset;
2036
input       RxReset;
2037
input [7:0] RxData;
2038
input       RxValid;
2039
input       RxStartFrm;
2040
input       RxEndFrm;
2041
input       RxFlow;
2042
input       ReceiveEnd;
2043
input [47:0]MAC;
2044
input       DlyCrcEn;
2045
input       TxDoneIn;
2046
input       TxAbortIn;
2047
input       TxStartFrmOut;
2048
input       ReceivedLengthOK;
2049
input       ReceivedPacketGood;
2050
input       TxUsedDataOutDetected;
2051
input       RxStatusWriteLatched_sync2;
2052
input       r_PassAll;
2053
 
2054
output      Pause;
2055
output      ReceivedPauseFrm;
2056
output      AddressOK;
2057
output      SetPauseTimer;
2058
 
2059
 
2060
reg         Pause;
2061
reg         AddressOK;                // Multicast or unicast address detected
2062
reg         TypeLengthOK;             // Type/Length field contains 0x8808
2063
reg         DetectionWindow;          // Detection of the PAUSE frame is possible within this window
2064
reg         OpCodeOK;                 // PAUSE opcode detected (0x0001)
2065
reg  [2:0]  DlyCrcCnt;
2066
reg  [4:0]  ByteCnt;
2067
reg [15:0]  AssembledTimerValue;
2068
reg [15:0]  LatchedTimerValue;
2069
reg         ReceivedPauseFrm;
2070
reg         ReceivedPauseFrmWAddr;
2071
reg         PauseTimerEq0_sync1;
2072
reg         PauseTimerEq0_sync2;
2073
reg [15:0]  PauseTimer;
2074
reg         Divider2;
2075
reg  [5:0]  SlotTimer;
2076
 
2077
wire [47:0] ReservedMulticast;        // 0x0180C2000001
2078
wire [15:0] TypeLength;               // 0x8808
2079
wire        ResetByteCnt;             // 
2080
wire        IncrementByteCnt;         // 
2081
wire        ByteCntEq0;               // ByteCnt = 0
2082
wire        ByteCntEq1;               // ByteCnt = 1
2083
wire        ByteCntEq2;               // ByteCnt = 2
2084
wire        ByteCntEq3;               // ByteCnt = 3
2085
wire        ByteCntEq4;               // ByteCnt = 4
2086
wire        ByteCntEq5;               // ByteCnt = 5
2087
wire        ByteCntEq12;              // ByteCnt = 12
2088
wire        ByteCntEq13;              // ByteCnt = 13
2089
wire        ByteCntEq14;              // ByteCnt = 14
2090
wire        ByteCntEq15;              // ByteCnt = 15
2091
wire        ByteCntEq16;              // ByteCnt = 16
2092
wire        ByteCntEq17;              // ByteCnt = 17
2093
wire        ByteCntEq18;              // ByteCnt = 18
2094
wire        DecrementPauseTimer;      // 
2095
wire        PauseTimerEq0;            // 
2096
wire        ResetSlotTimer;           // 
2097
wire        IncrementSlotTimer;       // 
2098
wire        SlotFinished;             // 
2099
 
2100
 
2101
 
2102
// Reserved multicast address and Type/Length for PAUSE control
2103
assign ReservedMulticast = 48'h0180C2000001;
2104
assign TypeLength = 16'h8808;
2105
 
2106
 
2107
// Address Detection (Multicast or unicast)
2108
always @ (posedge MRxClk or posedge RxReset)
2109
begin
2110
  if(RxReset)
2111
    AddressOK <= #Tp 1'b0;
2112
  else
2113
  if(DetectionWindow & ByteCntEq0)
2114
    AddressOK <= #Tp  RxData[7:0] == ReservedMulticast[47:40] | RxData[7:0] == MAC[47:40];
2115
  else
2116
  if(DetectionWindow & ByteCntEq1)
2117
    AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[39:32] | RxData[7:0] == MAC[39:32]) & AddressOK;
2118
  else
2119
  if(DetectionWindow & ByteCntEq2)
2120
    AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[31:24] | RxData[7:0] == MAC[31:24]) & AddressOK;
2121
  else
2122
  if(DetectionWindow & ByteCntEq3)
2123
    AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[23:16] | RxData[7:0] == MAC[23:16]) & AddressOK;
2124
  else
2125
  if(DetectionWindow & ByteCntEq4)
2126
    AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[15:8]  | RxData[7:0] == MAC[15:8])  & AddressOK;
2127
  else
2128
  if(DetectionWindow & ByteCntEq5)
2129
    AddressOK <= #Tp (RxData[7:0] == ReservedMulticast[7:0]   | RxData[7:0] == MAC[7:0])   & AddressOK;
2130
  else
2131
  if(ReceiveEnd)
2132
    AddressOK <= #Tp 1'b0;
2133
end
2134
 
2135
 
2136
 
2137
// TypeLengthOK (Type/Length Control frame detected)
2138
always @ (posedge MRxClk or posedge RxReset )
2139
begin
2140
  if(RxReset)
2141
    TypeLengthOK <= #Tp 1'b0;
2142
  else
2143
  if(DetectionWindow & ByteCntEq12)
2144
    TypeLengthOK <= #Tp ByteCntEq12 & (RxData[7:0] == TypeLength[15:8]);
2145
  else
2146
  if(DetectionWindow & ByteCntEq13)
2147
    TypeLengthOK <= #Tp ByteCntEq13 & (RxData[7:0] == TypeLength[7:0]) & TypeLengthOK;
2148
  else
2149
  if(ReceiveEnd)
2150
    TypeLengthOK <= #Tp 1'b0;
2151
end
2152
 
2153
 
2154
 
2155
// Latch Control Frame Opcode
2156
always @ (posedge MRxClk or posedge RxReset )
2157
begin
2158
  if(RxReset)
2159
    OpCodeOK <= #Tp 1'b0;
2160
  else
2161
  if(ByteCntEq16)
2162
    OpCodeOK <= #Tp 1'b0;
2163
  else
2164
    begin
2165
      if(DetectionWindow & ByteCntEq14)
2166
        OpCodeOK <= #Tp ByteCntEq14 & RxData[7:0] == 8'h00;
2167
 
2168
      if(DetectionWindow & ByteCntEq15)
2169
        OpCodeOK <= #Tp ByteCntEq15 & RxData[7:0] == 8'h01 & OpCodeOK;
2170
    end
2171
end
2172
 
2173
 
2174
// ReceivedPauseFrmWAddr (+Address Check)
2175
always @ (posedge MRxClk or posedge RxReset )
2176
begin
2177
  if(RxReset)
2178
    ReceivedPauseFrmWAddr <= #Tp 1'b0;
2179
  else
2180
  if(ReceiveEnd)
2181
    ReceivedPauseFrmWAddr <= #Tp 1'b0;
2182
  else
2183
  if(ByteCntEq16 & TypeLengthOK & OpCodeOK & AddressOK)
2184
    ReceivedPauseFrmWAddr <= #Tp 1'b1;
2185
end
2186
 
2187
 
2188
 
2189
// Assembling 16-bit timer value from two 8-bit data
2190
always @ (posedge MRxClk or posedge RxReset )
2191
begin
2192
  if(RxReset)
2193
    AssembledTimerValue[15:0] <= #Tp 16'h0;
2194
  else
2195
  if(RxStartFrm)
2196
    AssembledTimerValue[15:0] <= #Tp 16'h0;
2197
  else
2198
    begin
2199
      if(DetectionWindow & ByteCntEq16)
2200
        AssembledTimerValue[15:8] <= #Tp RxData[7:0];
2201
      if(DetectionWindow & ByteCntEq17)
2202
        AssembledTimerValue[7:0] <= #Tp RxData[7:0];
2203
    end
2204
end
2205
 
2206
 
2207
// Detection window (while PAUSE detection is possible)
2208
always @ (posedge MRxClk or posedge RxReset )
2209
begin
2210
  if(RxReset)
2211
    DetectionWindow <= #Tp 1'b1;
2212
  else
2213
  if(ByteCntEq18)
2214
    DetectionWindow <= #Tp 1'b0;
2215
  else
2216
  if(ReceiveEnd)
2217
    DetectionWindow <= #Tp 1'b1;
2218
end
2219
 
2220
 
2221
 
2222
// Latching Timer Value
2223
always @ (posedge MRxClk or posedge RxReset )
2224
begin
2225
  if(RxReset)
2226
    LatchedTimerValue[15:0] <= #Tp 16'h0;
2227
  else
2228
  if(DetectionWindow &  ReceivedPauseFrmWAddr &  ByteCntEq18)
2229
    LatchedTimerValue[15:0] <= #Tp AssembledTimerValue[15:0];
2230
  else
2231
  if(ReceiveEnd)
2232
    LatchedTimerValue[15:0] <= #Tp 16'h0;
2233
end
2234
 
2235
 
2236
 
2237
// Delayed CEC counter
2238
always @ (posedge MRxClk or posedge RxReset)
2239
begin
2240
  if(RxReset)
2241
    DlyCrcCnt <= #Tp 3'h0;
2242
  else
2243
  if(RxValid & RxEndFrm)
2244
    DlyCrcCnt <= #Tp 3'h0;
2245
  else
2246
  if(RxValid & ~RxEndFrm & ~DlyCrcCnt[2])
2247
    DlyCrcCnt <= #Tp DlyCrcCnt + 1'b1;
2248
end
2249
 
2250
 
2251
assign ResetByteCnt = RxEndFrm;
2252
assign IncrementByteCnt = RxValid & DetectionWindow & ~ByteCntEq18 & (~DlyCrcEn | DlyCrcEn & DlyCrcCnt[2]);
2253
 
2254
 
2255
// Byte counter
2256
always @ (posedge MRxClk or posedge RxReset)
2257
begin
2258
  if(RxReset)
2259
    ByteCnt[4:0] <= #Tp 5'h0;
2260
  else
2261
  if(ResetByteCnt)
2262
    ByteCnt[4:0] <= #Tp 5'h0;
2263
  else
2264
  if(IncrementByteCnt)
2265
    ByteCnt[4:0] <= #Tp ByteCnt[4:0] + 1'b1;
2266
end
2267
 
2268
 
2269
assign ByteCntEq0 = RxValid & ByteCnt[4:0] == 5'h0;
2270
assign ByteCntEq1 = RxValid & ByteCnt[4:0] == 5'h1;
2271
assign ByteCntEq2 = RxValid & ByteCnt[4:0] == 5'h2;
2272
assign ByteCntEq3 = RxValid & ByteCnt[4:0] == 5'h3;
2273
assign ByteCntEq4 = RxValid & ByteCnt[4:0] == 5'h4;
2274
assign ByteCntEq5 = RxValid & ByteCnt[4:0] == 5'h5;
2275
assign ByteCntEq12 = RxValid & ByteCnt[4:0] == 5'h0C;
2276
assign ByteCntEq13 = RxValid & ByteCnt[4:0] == 5'h0D;
2277
assign ByteCntEq14 = RxValid & ByteCnt[4:0] == 5'h0E;
2278
assign ByteCntEq15 = RxValid & ByteCnt[4:0] == 5'h0F;
2279
assign ByteCntEq16 = RxValid & ByteCnt[4:0] == 5'h10;
2280
assign ByteCntEq17 = RxValid & ByteCnt[4:0] == 5'h11;
2281
assign ByteCntEq18 = RxValid & ByteCnt[4:0] == 5'h12 & DetectionWindow;
2282
 
2283
 
2284
assign SetPauseTimer = ReceiveEnd & ReceivedPauseFrmWAddr & ReceivedPacketGood & ReceivedLengthOK & RxFlow;
2285
assign DecrementPauseTimer = SlotFinished & |PauseTimer;
2286
 
2287
 
2288
// PauseTimer[15:0]
2289
always @ (posedge MRxClk or posedge RxReset)
2290
begin
2291
  if(RxReset)
2292
    PauseTimer[15:0] <= #Tp 16'h0;
2293
  else
2294
  if(SetPauseTimer)
2295
    PauseTimer[15:0] <= #Tp LatchedTimerValue[15:0];
2296
  else
2297
  if(DecrementPauseTimer)
2298
    PauseTimer[15:0] <= #Tp PauseTimer[15:0] - 1'b1;
2299
end
2300
 
2301
assign PauseTimerEq0 = ~(|PauseTimer[15:0]);
2302
 
2303
 
2304
 
2305
// Synchronization of the pause timer
2306
always @ (posedge MTxClk or posedge TxReset)
2307
begin
2308
  if(TxReset)
2309
    begin
2310
      PauseTimerEq0_sync1 <= #Tp 1'b1;
2311
      PauseTimerEq0_sync2 <= #Tp 1'b1;
2312
    end
2313
  else
2314
    begin
2315
      PauseTimerEq0_sync1 <= #Tp PauseTimerEq0;
2316
      PauseTimerEq0_sync2 <= #Tp PauseTimerEq0_sync1;
2317
    end
2318
end
2319
 
2320
 
2321
// Pause signal generation
2322
always @ (posedge MTxClk or posedge TxReset)
2323
begin
2324
  if(TxReset)
2325
    Pause <= #Tp 1'b0;
2326
  else
2327
  if((TxDoneIn | TxAbortIn | ~TxUsedDataOutDetected) & ~TxStartFrmOut)
2328
    Pause <= #Tp RxFlow & ~PauseTimerEq0_sync2;
2329
end
2330
 
2331
 
2332
// Divider2 is used for incrementing the Slot timer every other clock
2333
always @ (posedge MRxClk or posedge RxReset)
2334
begin
2335
  if(RxReset)
2336
    Divider2 <= #Tp 1'b0;
2337
  else
2338
  if(|PauseTimer[15:0] & RxFlow)
2339
    Divider2 <= #Tp ~Divider2;
2340
  else
2341
    Divider2 <= #Tp 1'b0;
2342
end
2343
 
2344
 
2345
assign ResetSlotTimer = RxReset;
2346
assign IncrementSlotTimer =  Pause & RxFlow & Divider2;
2347
 
2348
 
2349
// SlotTimer
2350
always @ (posedge MRxClk or posedge RxReset)
2351
begin
2352
  if(RxReset)
2353
    SlotTimer[5:0] <= #Tp 6'h0;
2354
  else
2355
  if(ResetSlotTimer)
2356
    SlotTimer[5:0] <= #Tp 6'h0;
2357
  else
2358
  if(IncrementSlotTimer)
2359
    SlotTimer[5:0] <= #Tp SlotTimer[5:0] + 1'b1;
2360
end
2361
 
2362
 
2363
assign SlotFinished = &SlotTimer[5:0] & IncrementSlotTimer;  // Slot is 512 bits (64 bytes)
2364
 
2365
 
2366
 
2367
// Pause Frame received
2368
always @ (posedge MRxClk or posedge RxReset)
2369
begin
2370
  if(RxReset)
2371
    ReceivedPauseFrm <=#Tp 1'b0;
2372
  else
2373
  if(RxStatusWriteLatched_sync2 & r_PassAll | ReceivedPauseFrm & (~r_PassAll))
2374
    ReceivedPauseFrm <=#Tp 1'b0;
2375
  else
2376
  if(ByteCntEq16 & TypeLengthOK & OpCodeOK)
2377
    ReceivedPauseFrm <=#Tp 1'b1;
2378
end
2379
 
2380
 
2381
endmodule
2382
//////////////////////////////////////////////////////////////////////
2383
////                                                              ////
2384
////  eth_register.v                                              ////
2385
////                                                              ////
2386
////  This file is part of the Ethernet IP core project           ////
2387
////  http://www.opencores.org/projects/ethmac/                   ////
2388
////                                                              ////
2389
////  Author(s):                                                  ////
2390
////      - Igor Mohor (igorM@opencores.org)                      ////
2391
////                                                              ////
2392
////  All additional information is avaliable in the Readme.txt   ////
2393
////  file.                                                       ////
2394
////                                                              ////
2395
//////////////////////////////////////////////////////////////////////
2396
////                                                              ////
2397
//// Copyright (C) 2001, 2002 Authors                             ////
2398
////                                                              ////
2399
//// This source file may be used and distributed without         ////
2400
//// restriction provided that this copyright statement is not    ////
2401
//// removed from the file and that any derivative work contains  ////
2402
//// the original copyright notice and the associated disclaimer. ////
2403
////                                                              ////
2404
//// This source file is free software; you can redistribute it   ////
2405
//// and/or modify it under the terms of the GNU Lesser General   ////
2406
//// Public License as published by the Free Software Foundation; ////
2407
//// either version 2.1 of the License, or (at your option) any   ////
2408
//// later version.                                               ////
2409
////                                                              ////
2410
//// This source is distributed in the hope that it will be       ////
2411
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2412
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2413
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2414
//// details.                                                     ////
2415
////                                                              ////
2416
//// You should have received a copy of the GNU Lesser General    ////
2417
//// Public License along with this source; if not, download it   ////
2418
//// from http://www.opencores.org/lgpl.shtml                     ////
2419
////                                                              ////
2420
//////////////////////////////////////////////////////////////////////
2421
//
2422
// CVS Revision History
2423
//
2424
// $Log: eth_register.v,v $
2425
// Revision 1.6  2002/08/16 22:10:12  mohor
2426
// Synchronous reset added.
2427
//
2428
// Revision 1.5  2002/08/16 12:33:27  mohor
2429
// Parameter ResetValue changed to capital letters.
2430
//
2431
// Revision 1.4  2002/02/26 16:18:08  mohor
2432
// Reset values are passed to registers through parameters
2433
//
2434
// Revision 1.3  2002/01/23 10:28:16  mohor
2435
// Link in the header changed.
2436
//
2437
// Revision 1.2  2001/10/19 08:43:51  mohor
2438
// eth_timescale.v changed to timescale.v This is done because of the
2439
// simulation of the few cores in a one joined project.
2440
//
2441
// Revision 1.1  2001/08/06 14:44:29  mohor
2442
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
2443
// Include files fixed to contain no path.
2444
// File names and module names changed ta have a eth_ prologue in the name.
2445
// File eth_timescale.v is used to define timescale
2446
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
2447
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
2448
// and Mdo_OE. The bidirectional signal must be created on the top level. This
2449
// is done due to the ASIC tools.
2450
//
2451
//
2452
//
2453
//
2454
//
2455
//
2456
//
2457
 
2458
`include "timescale.v"
2459
 
2460
 
2461
module eth_register(DataIn, DataOut, Write, Clk, Reset);
2462
 
2463
parameter WIDTH = 8; // default parameter of the register width
2464
parameter RESET_VALUE = 0;
2465
 
2466
input [WIDTH-1:0] DataIn;
2467
 
2468
input Write;
2469
input Clk;
2470
input Reset;
2471
 
2472
output [WIDTH-1:0] DataOut;
2473
reg    [WIDTH-1:0] DataOut;
2474
 
2475
 
2476
 
2477
   always @ (posedge Clk or posedge Reset)
2478
     if(Reset)
2479
       DataOut<=#1 RESET_VALUE;
2480
     else
2481
       if(Write)                         // write
2482
         DataOut<=#1 DataIn;
2483
 
2484
endmodule   // Register
2485
//////////////////////////////////////////////////////////////////////
2486
////                                                              ////
2487
////  eth_registers.v                                             ////
2488
////                                                              ////
2489
////  This file is part of the Ethernet IP core project           ////
2490
////  http://www.opencores.org/projects/ethmac/                   ////
2491
////                                                              ////
2492
////  Author(s):                                                  ////
2493
////      - Igor Mohor (igorM@opencores.org)                      ////
2494
////                                                              ////
2495
////  All additional information is avaliable in the Readme.txt   ////
2496
////  file.                                                       ////
2497
////                                                              ////
2498
//////////////////////////////////////////////////////////////////////
2499
////                                                              ////
2500
//// Copyright (C) 2001, 2002 Authors                             ////
2501
////                                                              ////
2502
//// This source file may be used and distributed without         ////
2503
//// restriction provided that this copyright statement is not    ////
2504
//// removed from the file and that any derivative work contains  ////
2505
//// the original copyright notice and the associated disclaimer. ////
2506
////                                                              ////
2507
//// This source file is free software; you can redistribute it   ////
2508
//// and/or modify it under the terms of the GNU Lesser General   ////
2509
//// Public License as published by the Free Software Foundation; ////
2510
//// either version 2.1 of the License, or (at your option) any   ////
2511
//// later version.                                               ////
2512
////                                                              ////
2513
//// This source is distributed in the hope that it will be       ////
2514
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
2515
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
2516
//// PURPOSE.  See the GNU Lesser General Public License for more ////
2517
//// details.                                                     ////
2518
////                                                              ////
2519
//// You should have received a copy of the GNU Lesser General    ////
2520
//// Public License along with this source; if not, download it   ////
2521
//// from http://www.opencores.org/lgpl.shtml                     ////
2522
////                                                              ////
2523
//////////////////////////////////////////////////////////////////////
2524
//
2525
// CVS Revision History
2526
//
2527
// $Log: eth_registers.v,v $
2528
// Revision 1.29  2005/03/21 20:07:18  igorm
2529
// Some small fixes + some troubles fixed.
2530
//
2531
// Revision 1.28  2004/04/26 15:26:23  igorm
2532
// - Bug connected to the TX_BD_NUM_Wr signal fixed (bug came in with the
2533
//   previous update of the core.
2534
// - TxBDAddress is set to 0 after the TX is enabled in the MODER register.
2535
// - RxBDAddress is set to r_TxBDNum<<1 after the RX is enabled in the MODER
2536
//   register. (thanks to Mathias and Torbjorn)
2537
// - Multicast reception was fixed. Thanks to Ulrich Gries
2538
//
2539
// Revision 1.27  2004/04/26 11:42:17  igorm
2540
// TX_BD_NUM_Wr error fixed. Error was entered with the last check-in.
2541
//
2542
// Revision 1.26  2003/11/12 18:24:59  tadejm
2543
// WISHBONE slave changed and tested from only 32-bit accesss to byte access.
2544
//
2545
// Revision 1.25  2003/04/18 16:26:25  mohor
2546
// RxBDAddress was updated also when value to r_TxBDNum was written with
2547
// greater value than allowed.
2548
//
2549
// Revision 1.24  2002/11/22 01:57:06  mohor
2550
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
2551
// synchronized.
2552
//
2553
// Revision 1.23  2002/11/19 18:13:49  mohor
2554
// r_MiiMRst is not used for resetting the MIIM module. wb_rst used instead.
2555
//
2556
// Revision 1.22  2002/11/14 18:37:20  mohor
2557
// r_Rst signal does not reset any module any more and is removed from the design.
2558
//
2559
// Revision 1.21  2002/09/10 10:35:23  mohor
2560
// Ethernet debug registers removed.
2561
//
2562
// Revision 1.20  2002/09/04 18:40:25  mohor
2563
// ETH_TXCTRL and ETH_RXCTRL registers added. Interrupts related to
2564
// the control frames connected.
2565
//
2566
// Revision 1.19  2002/08/19 16:01:40  mohor
2567
// Only values smaller or equal to 0x80 can be written to TX_BD_NUM register.
2568
// r_TxEn and r_RxEn depend on the limit values of the TX_BD_NUMOut.
2569
//
2570
// Revision 1.18  2002/08/16 22:28:23  mohor
2571
// Syntax error fixed.
2572
//
2573
// Revision 1.17  2002/08/16 22:23:03  mohor
2574
// Syntax error fixed.
2575
//
2576
// Revision 1.16  2002/08/16 22:14:22  mohor
2577
// Synchronous reset added to all registers. Defines used for width. r_MiiMRst
2578
// changed from bit position 10 to 9.
2579
//
2580
// Revision 1.15  2002/08/14 18:26:37  mohor
2581
// LinkFailRegister is reflecting the status of the PHY's link fail status bit.
2582
//
2583
// Revision 1.14  2002/04/22 14:03:44  mohor
2584
// Interrupts are visible in the ETH_INT_SOURCE regardless if they are enabled
2585
// or not.
2586
//
2587
// Revision 1.13  2002/02/26 16:18:09  mohor
2588
// Reset values are passed to registers through parameters
2589
//
2590
// Revision 1.12  2002/02/17 13:23:42  mohor
2591
// Define missmatch fixed.
2592
//
2593
// Revision 1.11  2002/02/16 14:03:44  mohor
2594
// Registered trimmed. Unused registers removed.
2595
//
2596
// Revision 1.10  2002/02/15 11:08:25  mohor
2597
// File format fixed a bit.
2598
//
2599
// Revision 1.9  2002/02/14 20:19:41  billditt
2600
// Modified for Address Checking,
2601
// addition of eth_addrcheck.v
2602
//
2603
// Revision 1.8  2002/02/12 17:01:19  mohor
2604
// HASH0 and HASH1 registers added. 
2605
 
2606
// Revision 1.7  2002/01/23 10:28:16  mohor
2607
// Link in the header changed.
2608
//
2609
// Revision 1.6  2001/12/05 15:00:16  mohor
2610
// RX_BD_NUM changed to TX_BD_NUM (holds number of TX descriptors
2611
// instead of the number of RX descriptors).
2612
//
2613
// Revision 1.5  2001/12/05 10:22:19  mohor
2614
// ETH_RX_BD_ADR register deleted. ETH_RX_BD_NUM is used instead.
2615
//
2616
// Revision 1.4  2001/10/19 08:43:51  mohor
2617
// eth_timescale.v changed to timescale.v This is done because of the
2618
// simulation of the few cores in a one joined project.
2619
//
2620
// Revision 1.3  2001/10/18 12:07:11  mohor
2621
// Status signals changed, Adress decoding changed, interrupt controller
2622
// added.
2623
//
2624
// Revision 1.2  2001/09/24 15:02:56  mohor
2625
// Defines changed (All precede with ETH_). Small changes because some
2626
// tools generate warnings when two operands are together. Synchronization
2627
// between two clocks domains in eth_wishbonedma.v is changed (due to ASIC
2628
// demands).
2629
//
2630
// Revision 1.1  2001/08/06 14:44:29  mohor
2631
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
2632
// Include files fixed to contain no path.
2633
// File names and module names changed ta have a eth_ prologue in the name.
2634
// File eth_timescale.v is used to define timescale
2635
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
2636
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
2637
// and Mdo_OE. The bidirectional signal must be created on the top level. This
2638
// is done due to the ASIC tools.
2639
//
2640
// Revision 1.2  2001/08/02 09:25:31  mohor
2641
// Unconnected signals are now connected.
2642
//
2643
// Revision 1.1  2001/07/30 21:23:42  mohor
2644
// Directory structure changed. Files checked and joind together.
2645
//
2646
//
2647
//
2648
//
2649
//
2650
//
2651
 
2652
`include "eth_defines.v"
2653
`include "timescale.v"
2654
 
2655
 
2656
module eth_registers( DataIn, Address, Rw, Cs, Clk, Reset, DataOut,
2657
                      r_RecSmall, r_Pad, r_HugEn, r_CrcEn, r_DlyCrcEn,
2658
                      r_FullD, r_ExDfrEn, r_NoBckof, r_LoopBck, r_IFG,
2659
                      r_Pro, r_Iam, r_Bro, r_NoPre, r_TxEn, r_RxEn,
2660
                      TxB_IRQ, TxE_IRQ, RxB_IRQ, RxE_IRQ, Busy_IRQ,
2661
                      r_IPGT, r_IPGR1, r_IPGR2, r_MinFL, r_MaxFL, r_MaxRet,
2662
                      r_CollValid, r_TxFlow, r_RxFlow, r_PassAll,
2663
                      r_MiiNoPre, r_ClkDiv, r_WCtrlData, r_RStat, r_ScanStat,
2664
                      r_RGAD, r_FIAD, r_CtrlData, NValid_stat, Busy_stat,
2665
                      LinkFail, r_MAC, WCtrlDataStart, RStatStart,
2666
                      UpdateMIIRX_DATAReg, Prsd, r_TxBDNum, int_o,
2667
                      r_HASH0, r_HASH1, r_TxPauseTV, r_TxPauseRq, RstTxPauseRq, TxCtrlEndFrm,
2668
                      StartTxDone, TxClk, RxClk, SetPauseTimer
2669
                    );
2670
 
2671
parameter Tp = 1;
2672
 
2673
input [31:0] DataIn;
2674
input [7:0] Address;
2675
 
2676
input Rw;
2677
input [3:0] Cs;
2678
input Clk;
2679
input Reset;
2680
 
2681
input WCtrlDataStart;
2682
input RStatStart;
2683
 
2684
input UpdateMIIRX_DATAReg;
2685
input [15:0] Prsd;
2686
 
2687
output [31:0] DataOut;
2688
reg    [31:0] DataOut;
2689
 
2690
output r_RecSmall;
2691
output r_Pad;
2692
output r_HugEn;
2693
output r_CrcEn;
2694
output r_DlyCrcEn;
2695
output r_FullD;
2696
output r_ExDfrEn;
2697
output r_NoBckof;
2698
output r_LoopBck;
2699
output r_IFG;
2700
output r_Pro;
2701
output r_Iam;
2702
output r_Bro;
2703
output r_NoPre;
2704
output r_TxEn;
2705
output r_RxEn;
2706
output [31:0] r_HASH0;
2707
output [31:0] r_HASH1;
2708
 
2709
input TxB_IRQ;
2710
input TxE_IRQ;
2711
input RxB_IRQ;
2712
input RxE_IRQ;
2713
input Busy_IRQ;
2714
 
2715
output [6:0] r_IPGT;
2716
 
2717
output [6:0] r_IPGR1;
2718
 
2719
output [6:0] r_IPGR2;
2720
 
2721
output [15:0] r_MinFL;
2722
output [15:0] r_MaxFL;
2723
 
2724
output [3:0] r_MaxRet;
2725
output [5:0] r_CollValid;
2726
 
2727
output r_TxFlow;
2728
output r_RxFlow;
2729
output r_PassAll;
2730
 
2731
output r_MiiNoPre;
2732
output [7:0] r_ClkDiv;
2733
 
2734
output r_WCtrlData;
2735
output r_RStat;
2736
output r_ScanStat;
2737
 
2738
output [4:0] r_RGAD;
2739
output [4:0] r_FIAD;
2740
 
2741
output [15:0]r_CtrlData;
2742
 
2743
 
2744
input NValid_stat;
2745
input Busy_stat;
2746
input LinkFail;
2747
 
2748
output [47:0]r_MAC;
2749
output [7:0] r_TxBDNum;
2750
output       int_o;
2751
output [15:0]r_TxPauseTV;
2752
output       r_TxPauseRq;
2753
input        RstTxPauseRq;
2754
input        TxCtrlEndFrm;
2755
input        StartTxDone;
2756
input        TxClk;
2757
input        RxClk;
2758
input        SetPauseTimer;
2759
 
2760
reg          irq_txb;
2761
reg          irq_txe;
2762
reg          irq_rxb;
2763
reg          irq_rxe;
2764
reg          irq_busy;
2765
reg          irq_txc;
2766
reg          irq_rxc;
2767
 
2768
reg SetTxCIrq_txclk;
2769
reg SetTxCIrq_sync1, SetTxCIrq_sync2, SetTxCIrq_sync3;
2770
reg SetTxCIrq;
2771
reg ResetTxCIrq_sync1, ResetTxCIrq_sync2;
2772
 
2773
reg SetRxCIrq_rxclk;
2774
reg SetRxCIrq_sync1, SetRxCIrq_sync2, SetRxCIrq_sync3;
2775
reg SetRxCIrq;
2776
reg ResetRxCIrq_sync1;
2777
reg ResetRxCIrq_sync2;
2778
reg ResetRxCIrq_sync3;
2779
 
2780
wire [3:0] Write =   Cs  & {4{Rw}};
2781
wire       Read  = (|Cs) &   ~Rw;
2782
 
2783
wire MODER_Sel      = (Address == `ETH_MODER_ADR       );
2784
wire INT_SOURCE_Sel = (Address == `ETH_INT_SOURCE_ADR  );
2785
wire INT_MASK_Sel   = (Address == `ETH_INT_MASK_ADR    );
2786
wire IPGT_Sel       = (Address == `ETH_IPGT_ADR        );
2787
wire IPGR1_Sel      = (Address == `ETH_IPGR1_ADR       );
2788
wire IPGR2_Sel      = (Address == `ETH_IPGR2_ADR       );
2789
wire PACKETLEN_Sel  = (Address == `ETH_PACKETLEN_ADR   );
2790
wire COLLCONF_Sel   = (Address == `ETH_COLLCONF_ADR    );
2791
 
2792
wire CTRLMODER_Sel  = (Address == `ETH_CTRLMODER_ADR   );
2793
wire MIIMODER_Sel   = (Address == `ETH_MIIMODER_ADR    );
2794
wire MIICOMMAND_Sel = (Address == `ETH_MIICOMMAND_ADR  );
2795
wire MIIADDRESS_Sel = (Address == `ETH_MIIADDRESS_ADR  );
2796
wire MIITX_DATA_Sel = (Address == `ETH_MIITX_DATA_ADR  );
2797
wire MAC_ADDR0_Sel  = (Address == `ETH_MAC_ADDR0_ADR   );
2798
wire MAC_ADDR1_Sel  = (Address == `ETH_MAC_ADDR1_ADR   );
2799
wire HASH0_Sel      = (Address == `ETH_HASH0_ADR       );
2800
wire HASH1_Sel      = (Address == `ETH_HASH1_ADR       );
2801
wire TXCTRL_Sel     = (Address == `ETH_TX_CTRL_ADR     );
2802
wire RXCTRL_Sel     = (Address == `ETH_RX_CTRL_ADR     );
2803
wire TX_BD_NUM_Sel  = (Address == `ETH_TX_BD_NUM_ADR   );
2804
 
2805
 
2806
wire [2:0] MODER_Wr;
2807
wire [0:0] INT_SOURCE_Wr;
2808
wire [0:0] INT_MASK_Wr;
2809
wire [0:0] IPGT_Wr;
2810
wire [0:0] IPGR1_Wr;
2811
wire [0:0] IPGR2_Wr;
2812
wire [3:0] PACKETLEN_Wr;
2813
wire [2:0] COLLCONF_Wr;
2814
wire [0:0] CTRLMODER_Wr;
2815
wire [1:0] MIIMODER_Wr;
2816
wire [0:0] MIICOMMAND_Wr;
2817
wire [1:0] MIIADDRESS_Wr;
2818
wire [1:0] MIITX_DATA_Wr;
2819
wire       MIIRX_DATA_Wr;
2820
wire [3:0] MAC_ADDR0_Wr;
2821
wire [1:0] MAC_ADDR1_Wr;
2822
wire [3:0] HASH0_Wr;
2823
wire [3:0] HASH1_Wr;
2824
wire [2:0] TXCTRL_Wr;
2825
wire [0:0] TX_BD_NUM_Wr;
2826
 
2827
assign MODER_Wr[0]       = Write[0]  & MODER_Sel;
2828
assign MODER_Wr[1]       = Write[1]  & MODER_Sel;
2829
assign MODER_Wr[2]       = Write[2]  & MODER_Sel;
2830
assign INT_SOURCE_Wr[0]  = Write[0]  & INT_SOURCE_Sel;
2831
assign INT_MASK_Wr[0]    = Write[0]  & INT_MASK_Sel;
2832
assign IPGT_Wr[0]        = Write[0]  & IPGT_Sel;
2833
assign IPGR1_Wr[0]       = Write[0]  & IPGR1_Sel;
2834
assign IPGR2_Wr[0]       = Write[0]  & IPGR2_Sel;
2835
assign PACKETLEN_Wr[0]   = Write[0]  & PACKETLEN_Sel;
2836
assign PACKETLEN_Wr[1]   = Write[1]  & PACKETLEN_Sel;
2837
assign PACKETLEN_Wr[2]   = Write[2]  & PACKETLEN_Sel;
2838
assign PACKETLEN_Wr[3]   = Write[3]  & PACKETLEN_Sel;
2839
assign COLLCONF_Wr[0]    = Write[0]  & COLLCONF_Sel;
2840
assign COLLCONF_Wr[1]    = 1'b0;  // Not used
2841
assign COLLCONF_Wr[2]    = Write[2]  & COLLCONF_Sel;
2842
 
2843
assign CTRLMODER_Wr[0]   = Write[0]  & CTRLMODER_Sel;
2844
assign MIIMODER_Wr[0]    = Write[0]  & MIIMODER_Sel;
2845
assign MIIMODER_Wr[1]    = Write[1]  & MIIMODER_Sel;
2846
assign MIICOMMAND_Wr[0]  = Write[0]  & MIICOMMAND_Sel;
2847
assign MIIADDRESS_Wr[0]  = Write[0]  & MIIADDRESS_Sel;
2848
assign MIIADDRESS_Wr[1]  = Write[1]  & MIIADDRESS_Sel;
2849
assign MIITX_DATA_Wr[0]  = Write[0]  & MIITX_DATA_Sel;
2850
assign MIITX_DATA_Wr[1]  = Write[1]  & MIITX_DATA_Sel;
2851
assign MIIRX_DATA_Wr     = UpdateMIIRX_DATAReg;
2852
assign MAC_ADDR0_Wr[0]   = Write[0]  & MAC_ADDR0_Sel;
2853
assign MAC_ADDR0_Wr[1]   = Write[1]  & MAC_ADDR0_Sel;
2854
assign MAC_ADDR0_Wr[2]   = Write[2]  & MAC_ADDR0_Sel;
2855
assign MAC_ADDR0_Wr[3]   = Write[3]  & MAC_ADDR0_Sel;
2856
assign MAC_ADDR1_Wr[0]   = Write[0]  & MAC_ADDR1_Sel;
2857
assign MAC_ADDR1_Wr[1]   = Write[1]  & MAC_ADDR1_Sel;
2858
assign HASH0_Wr[0]       = Write[0]  & HASH0_Sel;
2859
assign HASH0_Wr[1]       = Write[1]  & HASH0_Sel;
2860
assign HASH0_Wr[2]       = Write[2]  & HASH0_Sel;
2861
assign HASH0_Wr[3]       = Write[3]  & HASH0_Sel;
2862
assign HASH1_Wr[0]       = Write[0]  & HASH1_Sel;
2863
assign HASH1_Wr[1]       = Write[1]  & HASH1_Sel;
2864
assign HASH1_Wr[2]       = Write[2]  & HASH1_Sel;
2865
assign HASH1_Wr[3]       = Write[3]  & HASH1_Sel;
2866
assign TXCTRL_Wr[0]      = Write[0]  & TXCTRL_Sel;
2867
assign TXCTRL_Wr[1]      = Write[1]  & TXCTRL_Sel;
2868
assign TXCTRL_Wr[2]      = Write[2]  & TXCTRL_Sel;
2869
assign TX_BD_NUM_Wr[0]   = Write[0]  & TX_BD_NUM_Sel & (DataIn<='h80);
2870
 
2871
 
2872
 
2873
wire [31:0] MODEROut;
2874
wire [31:0] INT_SOURCEOut;
2875
wire [31:0] INT_MASKOut;
2876
wire [31:0] IPGTOut;
2877
wire [31:0] IPGR1Out;
2878
wire [31:0] IPGR2Out;
2879
wire [31:0] PACKETLENOut;
2880
wire [31:0] COLLCONFOut;
2881
wire [31:0] CTRLMODEROut;
2882
wire [31:0] MIIMODEROut;
2883
wire [31:0] MIICOMMANDOut;
2884
wire [31:0] MIIADDRESSOut;
2885
wire [31:0] MIITX_DATAOut;
2886
wire [31:0] MIIRX_DATAOut;
2887
wire [31:0] MIISTATUSOut;
2888
wire [31:0] MAC_ADDR0Out;
2889
wire [31:0] MAC_ADDR1Out;
2890
wire [31:0] TX_BD_NUMOut;
2891
wire [31:0] HASH0Out;
2892
wire [31:0] HASH1Out;
2893
wire [31:0] TXCTRLOut;
2894
 
2895
// MODER Register
2896
eth_register #(`ETH_MODER_WIDTH_0, `ETH_MODER_DEF_0)        MODER_0
2897
  (
2898
   .DataIn    (DataIn[`ETH_MODER_WIDTH_0 - 1:0]),
2899
   .DataOut   (MODEROut[`ETH_MODER_WIDTH_0 - 1:0]),
2900
   .Write     (MODER_Wr[0]),
2901
   .Clk       (Clk),
2902
   .Reset     (Reset)
2903
  );
2904
eth_register #(`ETH_MODER_WIDTH_1, `ETH_MODER_DEF_1)        MODER_1
2905
  (
2906
   .DataIn    (DataIn[`ETH_MODER_WIDTH_1 + 7:8]),
2907
   .DataOut   (MODEROut[`ETH_MODER_WIDTH_1 + 7:8]),
2908
   .Write     (MODER_Wr[1]),
2909
   .Clk       (Clk),
2910
   .Reset     (Reset)
2911
  );
2912
eth_register #(`ETH_MODER_WIDTH_2, `ETH_MODER_DEF_2)        MODER_2
2913
  (
2914
   .DataIn    (DataIn[`ETH_MODER_WIDTH_2 + 15:16]),
2915
   .DataOut   (MODEROut[`ETH_MODER_WIDTH_2 + 15:16]),
2916
   .Write     (MODER_Wr[2]),
2917
   .Clk       (Clk),
2918
   .Reset     (Reset)
2919
  );
2920
assign MODEROut[31:`ETH_MODER_WIDTH_2 + 16] = 0;
2921
 
2922
// INT_MASK Register
2923
eth_register #(`ETH_INT_MASK_WIDTH_0, `ETH_INT_MASK_DEF_0)  INT_MASK_0
2924
  (
2925
   .DataIn    (DataIn[`ETH_INT_MASK_WIDTH_0 - 1:0]),
2926
   .DataOut   (INT_MASKOut[`ETH_INT_MASK_WIDTH_0 - 1:0]),
2927
   .Write     (INT_MASK_Wr[0]),
2928
   .Clk       (Clk),
2929
   .Reset     (Reset)
2930
  );
2931
assign INT_MASKOut[31:`ETH_INT_MASK_WIDTH_0] = 0;
2932
`ifdef ETH_IPGT
2933
   assign IPGTOut[`ETH_IPGT_WIDTH_0 - 1:0] = `ETH_IPGT_DEF_0;
2934
`else
2935
// IPGT Register
2936
eth_register #(`ETH_IPGT_WIDTH_0, `ETH_IPGT_DEF_0)          IPGT_0
2937
  (
2938
   .DataIn    (DataIn[`ETH_IPGT_WIDTH_0 - 1:0]),
2939
   .DataOut   (IPGTOut[`ETH_IPGT_WIDTH_0 - 1:0]),
2940
   .Write     (IPGT_Wr[0]),
2941
   .Clk       (Clk),
2942
   .Reset     (Reset)
2943
  );
2944
`endif
2945
assign IPGTOut[31:`ETH_IPGT_WIDTH_0] = 0;
2946
`ifdef ETH_IPGR1
2947
   assign IPGR1Out[`ETH_IPGR1_WIDTH_0 - 1:0] = `ETH_IPGR1_DEF_0;
2948
`else
2949
// IPGR1 Register
2950
eth_register #(`ETH_IPGR1_WIDTH_0, `ETH_IPGR1_DEF_0)        IPGR1_0
2951
  (
2952
   .DataIn    (DataIn[`ETH_IPGR1_WIDTH_0 - 1:0]),
2953
   .DataOut   (IPGR1Out[`ETH_IPGR1_WIDTH_0 - 1:0]),
2954
   .Write     (IPGR1_Wr[0]),
2955
   .Clk       (Clk),
2956
   .Reset     (Reset)
2957
  );
2958
`endif
2959
assign IPGR1Out[31:`ETH_IPGR1_WIDTH_0] = 0;
2960
 
2961
`ifdef ETH_IPGR2
2962
   assign IPGR2Out[`ETH_IPGR2_WIDTH_0 - 1:0] = `ETH_IPGR2_DEF_0;
2963
`else
2964
// IPGR2 Register
2965
eth_register #(`ETH_IPGR2_WIDTH_0, `ETH_IPGR2_DEF_0)        IPGR2_0
2966
  (
2967
   .DataIn    (DataIn[`ETH_IPGR2_WIDTH_0 - 1:0]),
2968
   .DataOut   (IPGR2Out[`ETH_IPGR2_WIDTH_0 - 1:0]),
2969
   .Write     (IPGR2_Wr[0]),
2970
   .Clk       (Clk),
2971
   .Reset     (Reset)
2972
  );
2973
`endif
2974
assign IPGR2Out[31:`ETH_IPGR2_WIDTH_0] = 0;
2975
 
2976
`ifdef ETH_PACKETLEN
2977
   assign PACKETLENOut = {`ETH_PACKETLEN_DEF_3,`ETH_PACKETLEN_DEF_2,`ETH_PACKETLEN_DEF_1,`ETH_PACKETLEN_DEF_0};
2978
`else
2979
// PACKETLEN Register
2980
eth_register #(`ETH_PACKETLEN_WIDTH_0, `ETH_PACKETLEN_DEF_0) PACKETLEN_0
2981
  (
2982
   .DataIn    (DataIn[`ETH_PACKETLEN_WIDTH_0 - 1:0]),
2983
   .DataOut   (PACKETLENOut[`ETH_PACKETLEN_WIDTH_0 - 1:0]),
2984
   .Write     (PACKETLEN_Wr[0]),
2985
   .Clk       (Clk),
2986
   .Reset     (Reset)
2987
  );
2988
eth_register #(`ETH_PACKETLEN_WIDTH_1, `ETH_PACKETLEN_DEF_1) PACKETLEN_1
2989
  (
2990
   .DataIn    (DataIn[`ETH_PACKETLEN_WIDTH_1 + 7:8]),
2991
   .DataOut   (PACKETLENOut[`ETH_PACKETLEN_WIDTH_1 + 7:8]),
2992
   .Write     (PACKETLEN_Wr[1]),
2993
   .Clk       (Clk),
2994
   .Reset     (Reset)
2995
  );
2996
eth_register #(`ETH_PACKETLEN_WIDTH_2, `ETH_PACKETLEN_DEF_2) PACKETLEN_2
2997
  (
2998
   .DataIn    (DataIn[`ETH_PACKETLEN_WIDTH_2 + 15:16]),
2999
   .DataOut   (PACKETLENOut[`ETH_PACKETLEN_WIDTH_2 + 15:16]),
3000
   .Write     (PACKETLEN_Wr[2]),
3001
   .Clk       (Clk),
3002
   .Reset     (Reset)
3003
  );
3004
eth_register #(`ETH_PACKETLEN_WIDTH_3, `ETH_PACKETLEN_DEF_3) PACKETLEN_3
3005
  (
3006
   .DataIn    (DataIn[`ETH_PACKETLEN_WIDTH_3 + 23:24]),
3007
   .DataOut   (PACKETLENOut[`ETH_PACKETLEN_WIDTH_3 + 23:24]),
3008
   .Write     (PACKETLEN_Wr[3]),
3009
   .Clk       (Clk),
3010
   .Reset     (Reset)
3011
  );
3012
`endif // !`ifdef
3013
 
3014
`ifdef ETH_COLLCONF
3015
   assign COLLCONFOut[`ETH_COLLCONF_WIDTH_0 - 1:0] = `ETH_COLLCONF_DEF_0;
3016
   assign COLLCONFOut[`ETH_COLLCONF_WIDTH_2 + 15:16] = `ETH_COLLCONF_DEF_2;
3017
`else
3018
// COLLCONF Register
3019
eth_register #(`ETH_COLLCONF_WIDTH_0, `ETH_COLLCONF_DEF_0)   COLLCONF_0
3020
  (
3021
   .DataIn    (DataIn[`ETH_COLLCONF_WIDTH_0 - 1:0]),
3022
   .DataOut   (COLLCONFOut[`ETH_COLLCONF_WIDTH_0 - 1:0]),
3023
   .Write     (COLLCONF_Wr[0]),
3024
   .Clk       (Clk),
3025
   .Reset     (Reset)
3026
  );
3027
eth_register #(`ETH_COLLCONF_WIDTH_2, `ETH_COLLCONF_DEF_2)   COLLCONF_2
3028
  (
3029
   .DataIn    (DataIn[`ETH_COLLCONF_WIDTH_2 + 15:16]),
3030
   .DataOut   (COLLCONFOut[`ETH_COLLCONF_WIDTH_2 + 15:16]),
3031
   .Write     (COLLCONF_Wr[2]),
3032
   .Clk       (Clk),
3033
   .Reset     (Reset)
3034
  );
3035
`endif
3036
assign COLLCONFOut[15:`ETH_COLLCONF_WIDTH_0] = 0;
3037
assign COLLCONFOut[31:`ETH_COLLCONF_WIDTH_2 + 16] = 0;
3038
 
3039
// TX_BD_NUM Register
3040
eth_register #(`ETH_TX_BD_NUM_WIDTH_0, `ETH_TX_BD_NUM_DEF_0) TX_BD_NUM_0
3041
  (
3042
   .DataIn    (DataIn[`ETH_TX_BD_NUM_WIDTH_0 - 1:0]),
3043
   .DataOut   (TX_BD_NUMOut[`ETH_TX_BD_NUM_WIDTH_0 - 1:0]),
3044
   .Write     (TX_BD_NUM_Wr[0]),
3045
   .Clk       (Clk),
3046
   .Reset     (Reset)
3047
  );
3048
assign TX_BD_NUMOut[31:`ETH_TX_BD_NUM_WIDTH_0] = 0;
3049
 
3050
// CTRLMODER Register
3051
eth_register #(`ETH_CTRLMODER_WIDTH_0, `ETH_CTRLMODER_DEF_0)  CTRLMODER_0
3052
  (
3053
   .DataIn    (DataIn[`ETH_CTRLMODER_WIDTH_0 - 1:0]),
3054
   .DataOut   (CTRLMODEROut[`ETH_CTRLMODER_WIDTH_0 - 1:0]),
3055
   .Write     (CTRLMODER_Wr[0]),
3056
   .Clk       (Clk),
3057
   .Reset     (Reset)
3058
  );
3059
assign CTRLMODEROut[31:`ETH_CTRLMODER_WIDTH_0] = 0;
3060
 
3061
// MIIMODER Register
3062
eth_register #(`ETH_MIIMODER_WIDTH_0, `ETH_MIIMODER_DEF_0)    MIIMODER_0
3063
  (
3064
   .DataIn    (DataIn[`ETH_MIIMODER_WIDTH_0 - 1:0]),
3065
   .DataOut   (MIIMODEROut[`ETH_MIIMODER_WIDTH_0 - 1:0]),
3066
   .Write     (MIIMODER_Wr[0]),
3067
   .Clk       (Clk),
3068
   .Reset     (Reset)
3069
  );
3070
eth_register #(`ETH_MIIMODER_WIDTH_1, `ETH_MIIMODER_DEF_1)    MIIMODER_1
3071
  (
3072
   .DataIn    (DataIn[`ETH_MIIMODER_WIDTH_1 + 7:8]),
3073
   .DataOut   (MIIMODEROut[`ETH_MIIMODER_WIDTH_1 + 7:8]),
3074
   .Write     (MIIMODER_Wr[1]),
3075
   .Clk       (Clk),
3076
   .Reset     (Reset)
3077
  );
3078
assign MIIMODEROut[31:`ETH_MIIMODER_WIDTH_1 + 8] = 0;
3079
 
3080
// MIICOMMAND Register
3081
eth_register #(1, 0)                                      MIICOMMAND0
3082
  (
3083
   .DataIn    (DataIn[0]),
3084
   .DataOut   (MIICOMMANDOut[0]),
3085
   .Write     (MIICOMMAND_Wr[0]),
3086
   .Clk       (Clk),
3087
   .Reset     (Reset)
3088
  );
3089
eth_register #(1, 0)                                      MIICOMMAND1
3090
  (
3091
   .DataIn    (DataIn[1]),
3092
   .DataOut   (MIICOMMANDOut[1]),
3093
   .Write     (MIICOMMAND_Wr[0]),
3094
   .Clk       (Clk),
3095
   .Reset     (Reset)
3096
  );
3097
eth_register #(1, 0)                                      MIICOMMAND2
3098
  (
3099
   .DataIn    (DataIn[2]),
3100
   .DataOut   (MIICOMMANDOut[2]),
3101
   .Write     (MIICOMMAND_Wr[0]),
3102
   .Clk       (Clk),
3103
   .Reset     (Reset)
3104
  );
3105
assign MIICOMMANDOut[31:`ETH_MIICOMMAND_WIDTH_0] = 29'h0;
3106
 
3107
// MIIADDRESSRegister
3108
eth_register #(`ETH_MIIADDRESS_WIDTH_0, `ETH_MIIADDRESS_DEF_0) MIIADDRESS_0
3109
  (
3110
   .DataIn    (DataIn[`ETH_MIIADDRESS_WIDTH_0 - 1:0]),
3111
   .DataOut   (MIIADDRESSOut[`ETH_MIIADDRESS_WIDTH_0 - 1:0]),
3112
   .Write     (MIIADDRESS_Wr[0]),
3113
   .Clk       (Clk),
3114
   .Reset     (Reset)
3115
  );
3116
eth_register #(`ETH_MIIADDRESS_WIDTH_1, `ETH_MIIADDRESS_DEF_1) MIIADDRESS_1
3117
  (
3118
   .DataIn    (DataIn[`ETH_MIIADDRESS_WIDTH_1 + 7:8]),
3119
   .DataOut   (MIIADDRESSOut[`ETH_MIIADDRESS_WIDTH_1 + 7:8]),
3120
   .Write     (MIIADDRESS_Wr[1]),
3121
   .Clk       (Clk),
3122
   .Reset     (Reset)
3123
  );
3124
assign MIIADDRESSOut[7:`ETH_MIIADDRESS_WIDTH_0] = 0;
3125
assign MIIADDRESSOut[31:`ETH_MIIADDRESS_WIDTH_1 + 8] = 0;
3126
 
3127
// MIITX_DATA Register
3128
eth_register #(`ETH_MIITX_DATA_WIDTH_0, `ETH_MIITX_DATA_DEF_0) MIITX_DATA_0
3129
  (
3130
   .DataIn    (DataIn[`ETH_MIITX_DATA_WIDTH_0 - 1:0]),
3131
   .DataOut   (MIITX_DATAOut[`ETH_MIITX_DATA_WIDTH_0 - 1:0]),
3132
   .Write     (MIITX_DATA_Wr[0]),
3133
   .Clk       (Clk),
3134
   .Reset     (Reset)
3135
  );
3136
eth_register #(`ETH_MIITX_DATA_WIDTH_1, `ETH_MIITX_DATA_DEF_1) MIITX_DATA_1
3137
  (
3138
   .DataIn    (DataIn[`ETH_MIITX_DATA_WIDTH_1 + 7:8]),
3139
   .DataOut   (MIITX_DATAOut[`ETH_MIITX_DATA_WIDTH_1 + 7:8]),
3140
   .Write     (MIITX_DATA_Wr[1]),
3141
   .Clk       (Clk),
3142
   .Reset     (Reset)
3143
  );
3144
assign MIITX_DATAOut[31:`ETH_MIITX_DATA_WIDTH_1 + 8] = 0;
3145
 
3146
// MIIRX_DATA Register
3147
eth_register #(`ETH_MIIRX_DATA_WIDTH, `ETH_MIIRX_DATA_DEF) MIIRX_DATA
3148
  (
3149
   .DataIn    (Prsd[`ETH_MIIRX_DATA_WIDTH-1:0]),
3150
   .DataOut   (MIIRX_DATAOut[`ETH_MIIRX_DATA_WIDTH-1:0]),
3151
   .Write     (MIIRX_DATA_Wr), // not written from WB
3152
   .Clk       (Clk),
3153
   .Reset     (Reset)
3154
  );
3155
assign MIIRX_DATAOut[31:`ETH_MIIRX_DATA_WIDTH] = 0;
3156
 
3157
`ifdef ETH_MAC_ADDR
3158
   assign MAC_ADDR0Out = {`ETH_MAC_ADDR0_DEF_3,`ETH_MAC_ADDR0_DEF_2,`ETH_MAC_ADDR0_DEF_1,`ETH_MAC_ADDR0_DEF_0};
3159
   assign MAC_ADDR1Out = {16'h0,`ETH_MAC_ADDR1_DEF_1,`ETH_MAC_ADDR1_DEF_0};
3160
`else
3161
// MAC_ADDR0 Register
3162
eth_register #(`ETH_MAC_ADDR0_WIDTH_0, `ETH_MAC_ADDR0_DEF_0)  MAC_ADDR0_0
3163
  (
3164
   .DataIn    (DataIn[`ETH_MAC_ADDR0_WIDTH_0 - 1:0]),
3165
   .DataOut   (MAC_ADDR0Out[`ETH_MAC_ADDR0_WIDTH_0 - 1:0]),
3166
   .Write     (MAC_ADDR0_Wr[0]),
3167
   .Clk       (Clk),
3168
   .Reset     (Reset)
3169
  );
3170
eth_register #(`ETH_MAC_ADDR0_WIDTH_1, `ETH_MAC_ADDR0_DEF_1)  MAC_ADDR0_1
3171
  (
3172
   .DataIn    (DataIn[`ETH_MAC_ADDR0_WIDTH_1 + 7:8]),
3173
   .DataOut   (MAC_ADDR0Out[`ETH_MAC_ADDR0_WIDTH_1 + 7:8]),
3174
   .Write     (MAC_ADDR0_Wr[1]),
3175
   .Clk       (Clk),
3176
   .Reset     (Reset)
3177
  );
3178
eth_register #(`ETH_MAC_ADDR0_WIDTH_2, `ETH_MAC_ADDR0_DEF_2)  MAC_ADDR0_2
3179
  (
3180
   .DataIn    (DataIn[`ETH_MAC_ADDR0_WIDTH_2 + 15:16]),
3181
   .DataOut   (MAC_ADDR0Out[`ETH_MAC_ADDR0_WIDTH_2 + 15:16]),
3182
   .Write     (MAC_ADDR0_Wr[2]),
3183
   .Clk       (Clk),
3184
   .Reset     (Reset)
3185
  );
3186
eth_register #(`ETH_MAC_ADDR0_WIDTH_3, `ETH_MAC_ADDR0_DEF_3)  MAC_ADDR0_3
3187
  (
3188
   .DataIn    (DataIn[`ETH_MAC_ADDR0_WIDTH_3 + 23:24]),
3189
   .DataOut   (MAC_ADDR0Out[`ETH_MAC_ADDR0_WIDTH_3 + 23:24]),
3190
   .Write     (MAC_ADDR0_Wr[3]),
3191
   .Clk       (Clk),
3192
   .Reset     (Reset)
3193
  );
3194
 
3195
// MAC_ADDR1 Register
3196
eth_register #(`ETH_MAC_ADDR1_WIDTH_0, `ETH_MAC_ADDR1_DEF_0)  MAC_ADDR1_0
3197
  (
3198
   .DataIn    (DataIn[`ETH_MAC_ADDR1_WIDTH_0 - 1:0]),
3199
   .DataOut   (MAC_ADDR1Out[`ETH_MAC_ADDR1_WIDTH_0 - 1:0]),
3200
   .Write     (MAC_ADDR1_Wr[0]),
3201
   .Clk       (Clk),
3202
   .Reset     (Reset)
3203
  );
3204
eth_register #(`ETH_MAC_ADDR1_WIDTH_1, `ETH_MAC_ADDR1_DEF_1)  MAC_ADDR1_1
3205
  (
3206
   .DataIn    (DataIn[`ETH_MAC_ADDR1_WIDTH_1 + 7:8]),
3207
   .DataOut   (MAC_ADDR1Out[`ETH_MAC_ADDR1_WIDTH_1 + 7:8]),
3208
   .Write     (MAC_ADDR1_Wr[1]),
3209
   .Clk       (Clk),
3210
   .Reset     (Reset)
3211
  );
3212
assign MAC_ADDR1Out[31:`ETH_MAC_ADDR1_WIDTH_1 + 8] = 0;
3213
`endif // !`ifdef ETH_MAC_ADDR
3214
`ifdef ETH_HASH0
3215
   assign HASH0Out = {`ETH_HASH0_DEF_3,`ETH_HASH0_DEF_2,`ETH_HASH0_DEF_1,`ETH_HASH0_DEF_0};
3216
`else
3217
// RXHASH0 Register
3218
eth_register #(`ETH_HASH0_WIDTH_0, `ETH_HASH0_DEF_0)          RXHASH0_0
3219
  (
3220
   .DataIn    (DataIn[`ETH_HASH0_WIDTH_0 - 1:0]),
3221
   .DataOut   (HASH0Out[`ETH_HASH0_WIDTH_0 - 1:0]),
3222
   .Write     (HASH0_Wr[0]),
3223
   .Clk       (Clk),
3224
   .Reset     (Reset)
3225
  );
3226
eth_register #(`ETH_HASH0_WIDTH_1, `ETH_HASH0_DEF_1)          RXHASH0_1
3227
  (
3228
   .DataIn    (DataIn[`ETH_HASH0_WIDTH_1 + 7:8]),
3229
   .DataOut   (HASH0Out[`ETH_HASH0_WIDTH_1 + 7:8]),
3230
   .Write     (HASH0_Wr[1]),
3231
   .Clk       (Clk),
3232
   .Reset     (Reset)
3233
  );
3234
eth_register #(`ETH_HASH0_WIDTH_2, `ETH_HASH0_DEF_2)          RXHASH0_2
3235
  (
3236
   .DataIn    (DataIn[`ETH_HASH0_WIDTH_2 + 15:16]),
3237
   .DataOut   (HASH0Out[`ETH_HASH0_WIDTH_2 + 15:16]),
3238
   .Write     (HASH0_Wr[2]),
3239
   .Clk       (Clk),
3240
   .Reset     (Reset)
3241
  );
3242
eth_register #(`ETH_HASH0_WIDTH_3, `ETH_HASH0_DEF_3)          RXHASH0_3
3243
  (
3244
   .DataIn    (DataIn[`ETH_HASH0_WIDTH_3 + 23:24]),
3245
   .DataOut   (HASH0Out[`ETH_HASH0_WIDTH_3 + 23:24]),
3246
   .Write     (HASH0_Wr[3]),
3247
   .Clk       (Clk),
3248
   .Reset     (Reset)
3249
  );
3250
`endif // !`ifdef ETH_HASH0
3251
`ifdef ETH_HASH1
3252
   assign HASH1Out = {`ETH_HASH1_DEF_3,`ETH_HASH1_DEF_2,`ETH_HASH1_DEF_1,`ETH_HASH1_DEF_0};
3253
`else
3254
// RXHASH1 Register
3255
eth_register #(`ETH_HASH1_WIDTH_0, `ETH_HASH1_DEF_0)          RXHASH1_0
3256
  (
3257
   .DataIn    (DataIn[`ETH_HASH1_WIDTH_0 - 1:0]),
3258
   .DataOut   (HASH1Out[`ETH_HASH1_WIDTH_0 - 1:0]),
3259
   .Write     (HASH1_Wr[0]),
3260
   .Clk       (Clk),
3261
   .Reset     (Reset)
3262
  );
3263
eth_register #(`ETH_HASH1_WIDTH_1, `ETH_HASH1_DEF_1)          RXHASH1_1
3264
  (
3265
   .DataIn    (DataIn[`ETH_HASH1_WIDTH_1 + 7:8]),
3266
   .DataOut   (HASH1Out[`ETH_HASH1_WIDTH_1 + 7:8]),
3267
   .Write     (HASH1_Wr[1]),
3268
   .Clk       (Clk),
3269
   .Reset     (Reset)
3270
  );
3271
eth_register #(`ETH_HASH1_WIDTH_2, `ETH_HASH1_DEF_2)          RXHASH1_2
3272
  (
3273
   .DataIn    (DataIn[`ETH_HASH1_WIDTH_2 + 15:16]),
3274
   .DataOut   (HASH1Out[`ETH_HASH1_WIDTH_2 + 15:16]),
3275
   .Write     (HASH1_Wr[2]),
3276
   .Clk       (Clk),
3277
   .Reset     (Reset)
3278
  );
3279
eth_register #(`ETH_HASH1_WIDTH_3, `ETH_HASH1_DEF_3)          RXHASH1_3
3280
  (
3281
   .DataIn    (DataIn[`ETH_HASH1_WIDTH_3 + 23:24]),
3282
   .DataOut   (HASH1Out[`ETH_HASH1_WIDTH_3 + 23:24]),
3283
   .Write     (HASH1_Wr[3]),
3284
   .Clk       (Clk),
3285
   .Reset     (Reset)
3286
  );
3287
`endif
3288
// TXCTRL Register
3289
eth_register #(`ETH_TX_CTRL_WIDTH_0, `ETH_TX_CTRL_DEF_0)  TXCTRL_0
3290
  (
3291
   .DataIn    (DataIn[`ETH_TX_CTRL_WIDTH_0 - 1:0]),
3292
   .DataOut   (TXCTRLOut[`ETH_TX_CTRL_WIDTH_0 - 1:0]),
3293
   .Write     (TXCTRL_Wr[0]),
3294
   .Clk       (Clk),
3295
   .Reset     (Reset)
3296
  );
3297
eth_register #(`ETH_TX_CTRL_WIDTH_1, `ETH_TX_CTRL_DEF_1)  TXCTRL_1
3298
  (
3299
   .DataIn    (DataIn[`ETH_TX_CTRL_WIDTH_1 + 7:8]),
3300
   .DataOut   (TXCTRLOut[`ETH_TX_CTRL_WIDTH_1 + 7:8]),
3301
   .Write     (TXCTRL_Wr[1]),
3302
   .Clk       (Clk),
3303
   .Reset     (Reset)
3304
  );
3305
eth_register #(`ETH_TX_CTRL_WIDTH_2, `ETH_TX_CTRL_DEF_2)  TXCTRL_2 // Request bit is synchronously reset
3306
  (
3307
   .DataIn    (DataIn[`ETH_TX_CTRL_WIDTH_2 + 15:16]),
3308
   .DataOut   (TXCTRLOut[`ETH_TX_CTRL_WIDTH_2 + 15:16]),
3309
   .Write     (TXCTRL_Wr[2]),
3310
   .Clk       (Clk),
3311
   .Reset     (Reset)
3312
  );
3313
assign TXCTRLOut[31:`ETH_TX_CTRL_WIDTH_2 + 16] = 0;
3314
 
3315
 
3316
 
3317
// Reading data from registers
3318
always @ (Address       or Read           or MODEROut       or INT_SOURCEOut  or
3319
          INT_MASKOut   or IPGTOut        or IPGR1Out       or IPGR2Out       or
3320
          PACKETLENOut  or COLLCONFOut    or CTRLMODEROut   or MIIMODEROut    or
3321
          MIICOMMANDOut or MIIADDRESSOut  or MIITX_DATAOut  or MIIRX_DATAOut  or
3322
          MIISTATUSOut  or MAC_ADDR0Out   or MAC_ADDR1Out   or TX_BD_NUMOut   or
3323
          HASH0Out      or HASH1Out       or TXCTRLOut
3324
         )
3325
begin
3326
  if(Read)  // read
3327
    begin
3328
      case(Address)
3329
        `ETH_MODER_ADR        :  DataOut<=MODEROut;
3330
        `ETH_INT_SOURCE_ADR   :  DataOut<=INT_SOURCEOut;
3331
        `ETH_INT_MASK_ADR     :  DataOut<=INT_MASKOut;
3332
        `ETH_IPGT_ADR         :  DataOut<=IPGTOut;
3333
        `ETH_IPGR1_ADR        :  DataOut<=IPGR1Out;
3334
        `ETH_IPGR2_ADR        :  DataOut<=IPGR2Out;
3335
        `ETH_PACKETLEN_ADR    :  DataOut<=PACKETLENOut;
3336
        `ETH_COLLCONF_ADR     :  DataOut<=COLLCONFOut;
3337
        `ETH_CTRLMODER_ADR    :  DataOut<=CTRLMODEROut;
3338
        `ETH_MIIMODER_ADR     :  DataOut<=MIIMODEROut;
3339
        `ETH_MIICOMMAND_ADR   :  DataOut<=MIICOMMANDOut;
3340
        `ETH_MIIADDRESS_ADR   :  DataOut<=MIIADDRESSOut;
3341
        `ETH_MIITX_DATA_ADR   :  DataOut<=MIITX_DATAOut;
3342
        `ETH_MIIRX_DATA_ADR   :  DataOut<=MIIRX_DATAOut;
3343
        `ETH_MIISTATUS_ADR    :  DataOut<=MIISTATUSOut;
3344
        `ETH_MAC_ADDR0_ADR    :  DataOut<=MAC_ADDR0Out;
3345
        `ETH_MAC_ADDR1_ADR    :  DataOut<=MAC_ADDR1Out;
3346
        `ETH_TX_BD_NUM_ADR    :  DataOut<=TX_BD_NUMOut;
3347
        `ETH_HASH0_ADR        :  DataOut<=HASH0Out;
3348
        `ETH_HASH1_ADR        :  DataOut<=HASH1Out;
3349
        `ETH_TX_CTRL_ADR      :  DataOut<=TXCTRLOut;
3350
 
3351
        default:             DataOut<=32'h0;
3352
      endcase
3353
    end
3354
  else
3355
    DataOut<=32'h0;
3356
end
3357
 
3358
 
3359
assign r_RecSmall         = MODEROut[16];
3360
assign r_Pad              = MODEROut[15];
3361
assign r_HugEn            = MODEROut[14];
3362
assign r_CrcEn            = MODEROut[13];
3363
assign r_DlyCrcEn         = MODEROut[12];
3364
// assign r_Rst           = MODEROut[11];   This signal is not used any more
3365
assign r_FullD            = MODEROut[10];
3366
assign r_ExDfrEn          = MODEROut[9];
3367
assign r_NoBckof          = MODEROut[8];
3368
assign r_LoopBck          = MODEROut[7];
3369
assign r_IFG              = MODEROut[6];
3370
assign r_Pro              = MODEROut[5];
3371
assign r_Iam              = MODEROut[4];
3372
assign r_Bro              = MODEROut[3];
3373
assign r_NoPre            = MODEROut[2];
3374
assign r_TxEn             = MODEROut[1] & (TX_BD_NUMOut>0);     // Transmission is enabled when there is at least one TxBD.
3375
assign r_RxEn             = MODEROut[0] & (TX_BD_NUMOut<'h80);  // Reception is enabled when there is  at least one RxBD.
3376
 
3377
assign r_IPGT[6:0]        = IPGTOut[6:0];
3378
 
3379
assign r_IPGR1[6:0]       = IPGR1Out[6:0];
3380
 
3381
assign r_IPGR2[6:0]       = IPGR2Out[6:0];
3382
 
3383
assign r_MinFL[15:0]      = PACKETLENOut[31:16];
3384
assign r_MaxFL[15:0]      = PACKETLENOut[15:0];
3385
 
3386
assign r_MaxRet[3:0]      = COLLCONFOut[19:16];
3387
assign r_CollValid[5:0]   = COLLCONFOut[5:0];
3388
 
3389
assign r_TxFlow           = CTRLMODEROut[2];
3390
assign r_RxFlow           = CTRLMODEROut[1];
3391
assign r_PassAll          = CTRLMODEROut[0];
3392
 
3393
assign r_MiiNoPre         = MIIMODEROut[8];
3394
assign r_ClkDiv[7:0]      = MIIMODEROut[7:0];
3395
 
3396
assign r_WCtrlData        = MIICOMMANDOut[2];
3397
assign r_RStat            = MIICOMMANDOut[1];
3398
assign r_ScanStat         = MIICOMMANDOut[0];
3399
 
3400
assign r_RGAD[4:0]        = MIIADDRESSOut[12:8];
3401
assign r_FIAD[4:0]        = MIIADDRESSOut[4:0];
3402
 
3403
assign r_CtrlData[15:0]   = MIITX_DATAOut[15:0];
3404
 
3405
assign MIISTATUSOut[31:`ETH_MIISTATUS_WIDTH] = 0;
3406
assign MIISTATUSOut[2]    = NValid_stat         ;
3407
assign MIISTATUSOut[1]    = Busy_stat           ;
3408
assign MIISTATUSOut[0]    = LinkFail            ;
3409
 
3410
assign r_MAC[31:0]        = MAC_ADDR0Out[31:0];
3411
assign r_MAC[47:32]       = MAC_ADDR1Out[15:0];
3412
assign r_HASH1[31:0]      = HASH1Out;
3413
assign r_HASH0[31:0]      = HASH0Out;
3414
 
3415
assign r_TxBDNum[7:0]     = TX_BD_NUMOut[7:0];
3416
 
3417
assign r_TxPauseTV[15:0]  = TXCTRLOut[15:0];
3418
assign r_TxPauseRq        = TXCTRLOut[16];
3419
 
3420
 
3421
// Synchronizing TxC Interrupt
3422
always @ (posedge TxClk or posedge Reset)
3423
begin
3424
  if(Reset)
3425
    SetTxCIrq_txclk <=#Tp 1'b0;
3426
  else
3427
  if(TxCtrlEndFrm & StartTxDone & r_TxFlow)
3428
    SetTxCIrq_txclk <=#Tp 1'b1;
3429
  else
3430
  if(ResetTxCIrq_sync2)
3431
    SetTxCIrq_txclk <=#Tp 1'b0;
3432
end
3433
 
3434
 
3435
always @ (posedge Clk or posedge Reset)
3436
begin
3437
  if(Reset)
3438
    SetTxCIrq_sync1 <=#Tp 1'b0;
3439
  else
3440
    SetTxCIrq_sync1 <=#Tp SetTxCIrq_txclk;
3441
end
3442
 
3443
always @ (posedge Clk or posedge Reset)
3444
begin
3445
  if(Reset)
3446
    SetTxCIrq_sync2 <=#Tp 1'b0;
3447
  else
3448
    SetTxCIrq_sync2 <=#Tp SetTxCIrq_sync1;
3449
end
3450
 
3451
always @ (posedge Clk or posedge Reset)
3452
begin
3453
  if(Reset)
3454
    SetTxCIrq_sync3 <=#Tp 1'b0;
3455
  else
3456
    SetTxCIrq_sync3 <=#Tp SetTxCIrq_sync2;
3457
end
3458
 
3459
always @ (posedge Clk or posedge Reset)
3460
begin
3461
  if(Reset)
3462
    SetTxCIrq <=#Tp 1'b0;
3463
  else
3464
    SetTxCIrq <=#Tp SetTxCIrq_sync2 & ~SetTxCIrq_sync3;
3465
end
3466
 
3467
always @ (posedge TxClk or posedge Reset)
3468
begin
3469
  if(Reset)
3470
    ResetTxCIrq_sync1 <=#Tp 1'b0;
3471
  else
3472
    ResetTxCIrq_sync1 <=#Tp SetTxCIrq_sync2;
3473
end
3474
 
3475
always @ (posedge TxClk or posedge Reset)
3476
begin
3477
  if(Reset)
3478
    ResetTxCIrq_sync2 <=#Tp 1'b0;
3479
  else
3480
    ResetTxCIrq_sync2 <=#Tp SetTxCIrq_sync1;
3481
end
3482
 
3483
 
3484
// Synchronizing RxC Interrupt
3485
always @ (posedge RxClk or posedge Reset)
3486
begin
3487
  if(Reset)
3488
    SetRxCIrq_rxclk <=#Tp 1'b0;
3489
  else
3490
  if(SetPauseTimer & r_RxFlow)
3491
    SetRxCIrq_rxclk <=#Tp 1'b1;
3492
  else
3493
  if(ResetRxCIrq_sync2 & (~ResetRxCIrq_sync3))
3494
    SetRxCIrq_rxclk <=#Tp 1'b0;
3495
end
3496
 
3497
 
3498
always @ (posedge Clk or posedge Reset)
3499
begin
3500
  if(Reset)
3501
    SetRxCIrq_sync1 <=#Tp 1'b0;
3502
  else
3503
    SetRxCIrq_sync1 <=#Tp SetRxCIrq_rxclk;
3504
end
3505
 
3506
always @ (posedge Clk or posedge Reset)
3507
begin
3508
  if(Reset)
3509
    SetRxCIrq_sync2 <=#Tp 1'b0;
3510
  else
3511
    SetRxCIrq_sync2 <=#Tp SetRxCIrq_sync1;
3512
end
3513
 
3514
always @ (posedge Clk or posedge Reset)
3515
begin
3516
  if(Reset)
3517
    SetRxCIrq_sync3 <=#Tp 1'b0;
3518
  else
3519
    SetRxCIrq_sync3 <=#Tp SetRxCIrq_sync2;
3520
end
3521
 
3522
always @ (posedge Clk or posedge Reset)
3523
begin
3524
  if(Reset)
3525
    SetRxCIrq <=#Tp 1'b0;
3526
  else
3527
    SetRxCIrq <=#Tp SetRxCIrq_sync2 & ~SetRxCIrq_sync3;
3528
end
3529
 
3530
always @ (posedge RxClk or posedge Reset)
3531
begin
3532
  if(Reset)
3533
    ResetRxCIrq_sync1 <=#Tp 1'b0;
3534
  else
3535
    ResetRxCIrq_sync1 <=#Tp SetRxCIrq_sync2;
3536
end
3537
 
3538
always @ (posedge RxClk or posedge Reset)
3539
begin
3540
  if(Reset)
3541
    ResetRxCIrq_sync2 <=#Tp 1'b0;
3542
  else
3543
    ResetRxCIrq_sync2 <=#Tp ResetRxCIrq_sync1;
3544
end
3545
 
3546
always @ (posedge RxClk or posedge Reset)
3547
begin
3548
  if(Reset)
3549
    ResetRxCIrq_sync3 <=#Tp 1'b0;
3550
  else
3551
    ResetRxCIrq_sync3 <=#Tp ResetRxCIrq_sync2;
3552
end
3553
 
3554
 
3555
 
3556
// Interrupt generation
3557
always @ (posedge Clk or posedge Reset)
3558
begin
3559
  if(Reset)
3560
    irq_txb <= 1'b0;
3561
  else
3562
  if(TxB_IRQ)
3563
    irq_txb <= #Tp 1'b1;
3564
  else
3565
  if(INT_SOURCE_Wr[0] & DataIn[0])
3566
    irq_txb <= #Tp 1'b0;
3567
end
3568
 
3569
always @ (posedge Clk or posedge Reset)
3570
begin
3571
  if(Reset)
3572
    irq_txe <= 1'b0;
3573
  else
3574
  if(TxE_IRQ)
3575
    irq_txe <= #Tp 1'b1;
3576
  else
3577
  if(INT_SOURCE_Wr[0] & DataIn[1])
3578
    irq_txe <= #Tp 1'b0;
3579
end
3580
 
3581
always @ (posedge Clk or posedge Reset)
3582
begin
3583
  if(Reset)
3584
    irq_rxb <= 1'b0;
3585
  else
3586
  if(RxB_IRQ)
3587
    irq_rxb <= #Tp 1'b1;
3588
  else
3589
  if(INT_SOURCE_Wr[0] & DataIn[2])
3590
    irq_rxb <= #Tp 1'b0;
3591
end
3592
 
3593
always @ (posedge Clk or posedge Reset)
3594
begin
3595
  if(Reset)
3596
    irq_rxe <= 1'b0;
3597
  else
3598
  if(RxE_IRQ)
3599
    irq_rxe <= #Tp 1'b1;
3600
  else
3601
  if(INT_SOURCE_Wr[0] & DataIn[3])
3602
    irq_rxe <= #Tp 1'b0;
3603
end
3604
 
3605
always @ (posedge Clk or posedge Reset)
3606
begin
3607
  if(Reset)
3608
    irq_busy <= 1'b0;
3609
  else
3610
  if(Busy_IRQ)
3611
    irq_busy <= #Tp 1'b1;
3612
  else
3613
  if(INT_SOURCE_Wr[0] & DataIn[4])
3614
    irq_busy <= #Tp 1'b0;
3615
end
3616
 
3617
always @ (posedge Clk or posedge Reset)
3618
begin
3619
  if(Reset)
3620
    irq_txc <= 1'b0;
3621
  else
3622
  if(SetTxCIrq)
3623
    irq_txc <= #Tp 1'b1;
3624
  else
3625
  if(INT_SOURCE_Wr[0] & DataIn[5])
3626
    irq_txc <= #Tp 1'b0;
3627
end
3628
 
3629
always @ (posedge Clk or posedge Reset)
3630
begin
3631
  if(Reset)
3632
    irq_rxc <= 1'b0;
3633
  else
3634
  if(SetRxCIrq)
3635
    irq_rxc <= #Tp 1'b1;
3636
  else
3637
  if(INT_SOURCE_Wr[0] & DataIn[6])
3638
    irq_rxc <= #Tp 1'b0;
3639
end
3640
 
3641
// Generating interrupt signal
3642
assign int_o = irq_txb  & INT_MASKOut[0] |
3643
               irq_txe  & INT_MASKOut[1] |
3644
               irq_rxb  & INT_MASKOut[2] |
3645
               irq_rxe  & INT_MASKOut[3] |
3646
               irq_busy & INT_MASKOut[4] |
3647
               irq_txc  & INT_MASKOut[5] |
3648
               irq_rxc  & INT_MASKOut[6] ;
3649
 
3650
// For reading interrupt status
3651
assign INT_SOURCEOut = {{(32-`ETH_INT_SOURCE_WIDTH_0){1'b0}}, irq_rxc, irq_txc, irq_busy, irq_rxe, irq_rxb, irq_txe, irq_txb};
3652
 
3653
 
3654
 
3655
endmodule
3656
//////////////////////////////////////////////////////////////////////
3657
////                                                              ////
3658
////  eth_rxaddrcheck.v                                           ////
3659
////                                                              ////
3660
////  This file is part of the Ethernet IP core project           ////
3661
////  http://www.opencores.org/cores/ethmac/                      ////
3662
////                                                              ////
3663
////  Author(s):                                                  ////
3664
////      - Bill Dittenhofer (billditt@aol.com)                   ////
3665
////                                                              ////
3666
////  All additional information is avaliable in the Readme.txt   ////
3667
////  file.                                                       ////
3668
////                                                              ////
3669
//////////////////////////////////////////////////////////////////////
3670
////                                                              ////
3671
//// Copyright (C) 2001 Authors                                   ////
3672
////                                                              ////
3673
//// This source file may be used and distributed without         ////
3674
//// restriction provided that this copyright statement is not    ////
3675
//// removed from the file and that any derivative work contains  ////
3676
//// the original copyright notice and the associated disclaimer. ////
3677
////                                                              ////
3678
//// This source file is free software; you can redistribute it   ////
3679
//// and/or modify it under the terms of the GNU Lesser General   ////
3680
//// Public License as published by the Free Software Foundation; ////
3681
//// either version 2.1 of the License, or (at your option) any   ////
3682
//// later version.                                               ////
3683
////                                                              ////
3684
//// This source is distributed in the hope that it will be       ////
3685
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
3686
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
3687
//// PURPOSE.  See the GNU Lesser General Public License for more ////
3688
//// details.                                                     ////
3689
////                                                              ////
3690
//// You should have received a copy of the GNU Lesser General    ////
3691
//// Public License along with this source; if not, download it   ////
3692
//// from http://www.opencores.org/lgpl.shtml                     ////
3693
////                                                              ////
3694
//////////////////////////////////////////////////////////////////////
3695
//
3696
// CVS Revision History
3697
//
3698
// $Log: eth_rxaddrcheck.v,v $
3699
// Revision 1.9  2002/11/22 01:57:06  mohor
3700
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
3701
// synchronized.
3702
//
3703
// Revision 1.8  2002/11/19 17:34:52  mohor
3704
// AddressMiss status is connecting to the Rx BD. AddressMiss is identifying
3705
// that a frame was received because of the promiscous mode.
3706
//
3707
// Revision 1.7  2002/09/04 18:41:06  mohor
3708
// Bug when last byte of destination address was not checked fixed.
3709
//
3710
// Revision 1.6  2002/03/20 15:14:11  mohor
3711
// When in promiscous mode some frames were not received correctly. Fixed.
3712
//
3713
// Revision 1.5  2002/03/02 21:06:32  mohor
3714
// Log info was missing.
3715
//
3716
//
3717
// Revision 1.1  2002/02/08 12:51:54  ditt
3718
// Initial release of the ethernet addresscheck module.
3719
//
3720
//
3721
//
3722
//
3723
//
3724
 
3725
 
3726
`include "timescale.v"
3727
 
3728
 
3729
module eth_rxaddrcheck(MRxClk,  Reset, RxData, Broadcast ,r_Bro ,r_Pro,
3730
                       ByteCntEq2, ByteCntEq3, ByteCntEq4, ByteCntEq5,
3731
                       ByteCntEq6, ByteCntEq7, HASH0, HASH1,
3732
                       CrcHash,    CrcHashGood, StateData, RxEndFrm,
3733
                       Multicast, MAC, RxAbort, AddressMiss, PassAll,
3734
                       ControlFrmAddressOK
3735
                      );
3736
 
3737
parameter Tp = 1;
3738
 
3739
  input        MRxClk;
3740
  input        Reset;
3741
  input [7:0]  RxData;
3742
  input        Broadcast;
3743
  input        r_Bro;
3744
  input        r_Pro;
3745
  input        ByteCntEq2;
3746
  input        ByteCntEq3;
3747
  input        ByteCntEq4;
3748
  input        ByteCntEq5;
3749
  input        ByteCntEq6;
3750
  input        ByteCntEq7;
3751
  input [31:0] HASH0;
3752
  input [31:0] HASH1;
3753
  input [5:0]  CrcHash;
3754
  input        CrcHashGood;
3755
  input        Multicast;
3756
  input [47:0] MAC;
3757
  input [1:0]  StateData;
3758
  input        RxEndFrm;
3759
  input        PassAll;
3760
  input        ControlFrmAddressOK;
3761
 
3762
  output       RxAbort;
3763
  output       AddressMiss;
3764
 
3765
 wire BroadcastOK;
3766
 wire ByteCntEq2;
3767
 wire ByteCntEq3;
3768
 wire ByteCntEq4;
3769
 wire ByteCntEq5;
3770
 wire RxAddressInvalid;
3771
 wire RxCheckEn;
3772
 wire HashBit;
3773
 wire [31:0] IntHash;
3774
 reg [7:0]  ByteHash;
3775
 reg MulticastOK;
3776
 reg UnicastOK;
3777
 reg RxAbort;
3778
 reg AddressMiss;
3779
 
3780
assign RxAddressInvalid = ~(UnicastOK | BroadcastOK | MulticastOK | r_Pro);
3781
 
3782
assign BroadcastOK = Broadcast & ~r_Bro;
3783
 
3784
assign RxCheckEn   = | StateData;
3785
 
3786
 // Address Error Reported at end of address cycle
3787
 // RxAbort clears after one cycle
3788
 
3789
always @ (posedge MRxClk or posedge Reset)
3790
begin
3791
  if(Reset)
3792
    RxAbort <= #Tp 1'b0;
3793
  else if(RxAddressInvalid & ByteCntEq7 & RxCheckEn)
3794
    RxAbort <= #Tp 1'b1;
3795
  else
3796
    RxAbort <= #Tp 1'b0;
3797
end
3798
 
3799
 
3800
// This ff holds the "Address Miss" information that is written to the RX BD status.
3801
always @ (posedge MRxClk or posedge Reset)
3802
begin
3803
  if(Reset)
3804
    AddressMiss <= #Tp 1'b0;
3805
  else if(ByteCntEq7 & RxCheckEn)
3806
    AddressMiss <= #Tp (~(UnicastOK | BroadcastOK | MulticastOK | (PassAll & ControlFrmAddressOK)));
3807
end
3808
 
3809
 
3810
// Hash Address Check, Multicast
3811
always @ (posedge MRxClk or posedge Reset)
3812
begin
3813
  if(Reset)
3814
    MulticastOK <= #Tp 1'b0;
3815
  else if(RxEndFrm | RxAbort)
3816
    MulticastOK <= #Tp 1'b0;
3817
  else if(CrcHashGood & Multicast)
3818
    MulticastOK <= #Tp HashBit;
3819
end
3820
 
3821
 
3822
// Address Detection (unicast)
3823
// start with ByteCntEq2 due to delay of addres from RxData
3824
always @ (posedge MRxClk or posedge Reset)
3825
begin
3826
  if(Reset)
3827
    UnicastOK <= #Tp 1'b0;
3828
  else
3829
  if(RxCheckEn & ByteCntEq2)
3830
    UnicastOK <= #Tp   RxData[7:0] == MAC[47:40];
3831
  else
3832
  if(RxCheckEn & ByteCntEq3)
3833
    UnicastOK <= #Tp ( RxData[7:0] == MAC[39:32]) & UnicastOK;
3834
  else
3835
  if(RxCheckEn & ByteCntEq4)
3836
    UnicastOK <= #Tp ( RxData[7:0] == MAC[31:24]) & UnicastOK;
3837
  else
3838
  if(RxCheckEn & ByteCntEq5)
3839
    UnicastOK <= #Tp ( RxData[7:0] == MAC[23:16]) & UnicastOK;
3840
  else
3841
  if(RxCheckEn & ByteCntEq6)
3842
    UnicastOK <= #Tp ( RxData[7:0] == MAC[15:8])  & UnicastOK;
3843
  else
3844
  if(RxCheckEn & ByteCntEq7)
3845
    UnicastOK <= #Tp ( RxData[7:0] == MAC[7:0])   & UnicastOK;
3846
  else
3847
  if(RxEndFrm | RxAbort)
3848
    UnicastOK <= #Tp 1'b0;
3849
end
3850
 
3851
assign IntHash = (CrcHash[5])? HASH1 : HASH0;
3852
 
3853
always@(CrcHash or IntHash)
3854
begin
3855
  case(CrcHash[4:3])
3856
    2'b00: ByteHash = IntHash[7:0];
3857
    2'b01: ByteHash = IntHash[15:8];
3858
    2'b10: ByteHash = IntHash[23:16];
3859
    2'b11: ByteHash = IntHash[31:24];
3860
  endcase
3861
end
3862
 
3863
assign HashBit = ByteHash[CrcHash[2:0]];
3864
 
3865
 
3866
endmodule
3867
//////////////////////////////////////////////////////////////////////
3868
////                                                              ////
3869
////  eth_rxcounters.v                                            ////
3870
////                                                              ////
3871
////  This file is part of the Ethernet IP core project           ////
3872
////  http://www.opencores.org/projects/ethmac/                   ////
3873
////                                                              ////
3874
////  Author(s):                                                  ////
3875
////      - Igor Mohor (igorM@opencores.org)                      ////
3876
////      - Novan Hartadi (novan@vlsi.itb.ac.id)                  ////
3877
////      - Mahmud Galela (mgalela@vlsi.itb.ac.id)                ////
3878
////                                                              ////
3879
////  All additional information is avaliable in the Readme.txt   ////
3880
////  file.                                                       ////
3881
////                                                              ////
3882
//////////////////////////////////////////////////////////////////////
3883
////                                                              ////
3884
//// Copyright (C) 2001 Authors                                   ////
3885
////                                                              ////
3886
//// This source file may be used and distributed without         ////
3887
//// restriction provided that this copyright statement is not    ////
3888
//// removed from the file and that any derivative work contains  ////
3889
//// the original copyright notice and the associated disclaimer. ////
3890
////                                                              ////
3891
//// This source file is free software; you can redistribute it   ////
3892
//// and/or modify it under the terms of the GNU Lesser General   ////
3893
//// Public License as published by the Free Software Foundation; ////
3894
//// either version 2.1 of the License, or (at your option) any   ////
3895
//// later version.                                               ////
3896
////                                                              ////
3897
//// This source is distributed in the hope that it will be       ////
3898
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
3899
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
3900
//// PURPOSE.  See the GNU Lesser General Public License for more ////
3901
//// details.                                                     ////
3902
////                                                              ////
3903
//// You should have received a copy of the GNU Lesser General    ////
3904
//// Public License along with this source; if not, download it   ////
3905
//// from http://www.opencores.org/lgpl.shtml                     ////
3906
////                                                              ////
3907
//////////////////////////////////////////////////////////////////////
3908
//
3909
// CVS Revision History
3910
//
3911
// $Log: eth_rxcounters.v,v $
3912
// Revision 1.6  2005/02/21 11:00:57  igorm
3913
// Delayed CRC fixed.
3914
//
3915
// Revision 1.5  2002/02/15 11:13:29  mohor
3916
// Format of the file changed a bit.
3917
//
3918
// Revision 1.4  2002/02/14 20:19:41  billditt
3919
// Modified for Address Checking,
3920
// addition of eth_addrcheck.v
3921
//
3922
// Revision 1.3  2002/01/23 10:28:16  mohor
3923
// Link in the header changed.
3924
//
3925
// Revision 1.2  2001/10/19 08:43:51  mohor
3926
// eth_timescale.v changed to timescale.v This is done because of the
3927
// simulation of the few cores in a one joined project.
3928
//
3929
// Revision 1.1  2001/08/06 14:44:29  mohor
3930
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
3931
// Include files fixed to contain no path.
3932
// File names and module names changed ta have a eth_ prologue in the name.
3933
// File eth_timescale.v is used to define timescale
3934
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
3935
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
3936
// and Mdo_OE. The bidirectional signal must be created on the top level. This
3937
// is done due to the ASIC tools.
3938
//
3939
// Revision 1.1  2001/07/30 21:23:42  mohor
3940
// Directory structure changed. Files checked and joind together.
3941
//
3942
// Revision 1.1  2001/06/27 21:26:19  mohor
3943
// Initial release of the RxEthMAC module.
3944
//
3945
//
3946
//
3947
//
3948
//
3949
//
3950
 
3951
 
3952
`include "timescale.v"
3953
 
3954
 
3955
module eth_rxcounters (MRxClk, Reset, MRxDV, StateIdle, StateSFD, StateData, StateDrop, StatePreamble,
3956
                       MRxDEqD, DlyCrcEn, DlyCrcCnt, Transmitting, MaxFL, r_IFG, HugEn, IFGCounterEq24,
3957
                       ByteCntEq0, ByteCntEq1, ByteCntEq2,ByteCntEq3,ByteCntEq4,ByteCntEq5, ByteCntEq6,
3958
                       ByteCntEq7, ByteCntGreat2, ByteCntSmall7, ByteCntMaxFrame, ByteCntOut
3959
                      );
3960
 
3961
parameter Tp = 1;
3962
 
3963
input         MRxClk;
3964
input         Reset;
3965
input         MRxDV;
3966
input         StateSFD;
3967
input [1:0]   StateData;
3968
input         MRxDEqD;
3969
input         StateIdle;
3970
input         StateDrop;
3971
input         DlyCrcEn;
3972
input         StatePreamble;
3973
input         Transmitting;
3974
input         HugEn;
3975
input [15:0]  MaxFL;
3976
input         r_IFG;
3977
 
3978
output        IFGCounterEq24;           // IFG counter reaches 9600 ns (960 ns)
3979
output [3:0]  DlyCrcCnt;                // Delayed CRC counter
3980
output        ByteCntEq0;               // Byte counter = 0
3981
output        ByteCntEq1;               // Byte counter = 1
3982
output        ByteCntEq2;               // Byte counter = 2  
3983
output        ByteCntEq3;               // Byte counter = 3  
3984
output        ByteCntEq4;               // Byte counter = 4  
3985
output        ByteCntEq5;               // Byte counter = 5  
3986
output        ByteCntEq6;               // Byte counter = 6
3987
output        ByteCntEq7;               // Byte counter = 7
3988
output        ByteCntGreat2;            // Byte counter > 2
3989
output        ByteCntSmall7;            // Byte counter < 7
3990
output        ByteCntMaxFrame;          // Byte counter = MaxFL
3991
output [15:0] ByteCntOut;               // Byte counter
3992
 
3993
wire          ResetByteCounter;
3994
wire          IncrementByteCounter;
3995
wire          ResetIFGCounter;
3996
wire          IncrementIFGCounter;
3997
wire          ByteCntMax;
3998
 
3999
reg   [15:0]  ByteCnt;
4000
reg   [3:0]   DlyCrcCnt;
4001
reg   [4:0]   IFGCounter;
4002
 
4003
wire  [15:0]  ByteCntDelayed;
4004
 
4005
 
4006
 
4007
assign ResetByteCounter = MRxDV & (StateSFD & MRxDEqD | StateData[0] & ByteCntMaxFrame);
4008
 
4009
assign IncrementByteCounter = ~ResetByteCounter & MRxDV &
4010
                              (StatePreamble | StateSFD | StateIdle & ~Transmitting |
4011
                               StateData[1] & ~ByteCntMax & ~(DlyCrcEn & |DlyCrcCnt)
4012
                              );
4013
 
4014
 
4015
always @ (posedge MRxClk or posedge Reset)
4016
begin
4017
  if(Reset)
4018
    ByteCnt[15:0] <= #Tp 16'h0;
4019
  else
4020
    begin
4021
      if(ResetByteCounter)
4022
        ByteCnt[15:0] <= #Tp 16'h0;
4023
      else
4024
      if(IncrementByteCounter)
4025
        ByteCnt[15:0] <= #Tp ByteCnt[15:0] + 1'b1;
4026
     end
4027
end
4028
 
4029
assign ByteCntDelayed = ByteCnt + 3'h4;
4030
assign ByteCntOut = DlyCrcEn? ByteCntDelayed : ByteCnt;
4031
 
4032
assign ByteCntEq0       = ByteCnt == 16'h0;
4033
assign ByteCntEq1       = ByteCnt == 16'h1;
4034
assign ByteCntEq2       = ByteCnt == 16'h2;
4035
assign ByteCntEq3       = ByteCnt == 16'h3;
4036
assign ByteCntEq4       = ByteCnt == 16'h4;
4037
assign ByteCntEq5       = ByteCnt == 16'h5;
4038
assign ByteCntEq6       = ByteCnt == 16'h6;
4039
assign ByteCntEq7       = ByteCnt == 16'h7;
4040
assign ByteCntGreat2    = ByteCnt >  16'h2;
4041
assign ByteCntSmall7    = ByteCnt <  16'h7;
4042
assign ByteCntMax       = ByteCnt == 16'hffff;
4043
assign ByteCntMaxFrame  = ByteCnt == MaxFL[15:0] & ~HugEn;
4044
 
4045
 
4046
assign ResetIFGCounter = StateSFD  &  MRxDV & MRxDEqD | StateDrop;
4047
 
4048
assign IncrementIFGCounter = ~ResetIFGCounter & (StateDrop | StateIdle | StatePreamble | StateSFD) & ~IFGCounterEq24;
4049
 
4050
always @ (posedge MRxClk or posedge Reset)
4051
begin
4052
  if(Reset)
4053
    IFGCounter[4:0] <= #Tp 5'h0;
4054
  else
4055
    begin
4056
      if(ResetIFGCounter)
4057
        IFGCounter[4:0] <= #Tp 5'h0;
4058
      else
4059
      if(IncrementIFGCounter)
4060
        IFGCounter[4:0] <= #Tp IFGCounter[4:0] + 1'b1;
4061
    end
4062
end
4063
 
4064
 
4065
 
4066
assign IFGCounterEq24 = (IFGCounter[4:0] == 5'h18) | r_IFG; // 24*400 = 9600 ns or r_IFG is set to 1
4067
 
4068
 
4069
always @ (posedge MRxClk or posedge Reset)
4070
begin
4071
  if(Reset)
4072
    DlyCrcCnt[3:0] <= #Tp 4'h0;
4073
  else
4074
    begin
4075
      if(DlyCrcCnt[3:0] == 4'h9)
4076
        DlyCrcCnt[3:0] <= #Tp 4'h0;
4077
      else
4078
      if(DlyCrcEn & StateSFD)
4079
        DlyCrcCnt[3:0] <= #Tp 4'h1;
4080
      else
4081
      if(DlyCrcEn & (|DlyCrcCnt[3:0]))
4082
        DlyCrcCnt[3:0] <= #Tp DlyCrcCnt[3:0] + 1'b1;
4083
    end
4084
end
4085
 
4086
 
4087
endmodule
4088
//////////////////////////////////////////////////////////////////////
4089
////                                                              ////
4090
////  eth_rxethmac.v                                              ////
4091
////                                                              ////
4092
////  This file is part of the Ethernet IP core project           ////
4093
////  http://www.opencores.org/projects/ethmac/                   ////
4094
////                                                              ////
4095
////  Author(s):                                                  ////
4096
////      - Igor Mohor (igorM@opencores.org)                      ////
4097
////      - Novan Hartadi (novan@vlsi.itb.ac.id)                  ////
4098
////      - Mahmud Galela (mgalela@vlsi.itb.ac.id)                ////
4099
////                                                              ////
4100
////  All additional information is avaliable in the Readme.txt   ////
4101
////  file.                                                       ////
4102
////                                                              ////
4103
//////////////////////////////////////////////////////////////////////
4104
////                                                              ////
4105
//// Copyright (C) 2001 Authors                                   ////
4106
////                                                              ////
4107
//// This source file may be used and distributed without         ////
4108
//// restriction provided that this copyright statement is not    ////
4109
//// removed from the file and that any derivative work contains  ////
4110
//// the original copyright notice and the associated disclaimer. ////
4111
////                                                              ////
4112
//// This source file is free software; you can redistribute it   ////
4113
//// and/or modify it under the terms of the GNU Lesser General   ////
4114
//// Public License as published by the Free Software Foundation; ////
4115
//// either version 2.1 of the License, or (at your option) any   ////
4116
//// later version.                                               ////
4117
////                                                              ////
4118
//// This source is distributed in the hope that it will be       ////
4119
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
4120
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
4121
//// PURPOSE.  See the GNU Lesser General Public License for more ////
4122
//// details.                                                     ////
4123
////                                                              ////
4124
//// You should have received a copy of the GNU Lesser General    ////
4125
//// Public License along with this source; if not, download it   ////
4126
//// from http://www.opencores.org/lgpl.shtml                     ////
4127
////                                                              ////
4128
//////////////////////////////////////////////////////////////////////
4129
//
4130
// CVS Revision History
4131
//
4132
// $Log: eth_rxethmac.v,v $
4133
// Revision 1.13  2005/02/21 12:48:07  igorm
4134
// Warning fixes.
4135
//
4136
// Revision 1.12  2004/04/26 15:26:23  igorm
4137
// - Bug connected to the TX_BD_NUM_Wr signal fixed (bug came in with the
4138
//   previous update of the core.
4139
// - TxBDAddress is set to 0 after the TX is enabled in the MODER register.
4140
// - RxBDAddress is set to r_TxBDNum<<1 after the RX is enabled in the MODER
4141
//   register. (thanks to Mathias and Torbjorn)
4142
// - Multicast reception was fixed. Thanks to Ulrich Gries
4143
//
4144
// Revision 1.11  2004/03/17 09:32:15  igorm
4145
// Multicast detection fixed. Only the LSB of the first byte is checked.
4146
//
4147
// Revision 1.10  2002/11/22 01:57:06  mohor
4148
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
4149
// synchronized.
4150
//
4151
// Revision 1.9  2002/11/19 17:35:35  mohor
4152
// AddressMiss status is connecting to the Rx BD. AddressMiss is identifying
4153
// that a frame was received because of the promiscous mode.
4154
//
4155
// Revision 1.8  2002/02/16 07:15:27  mohor
4156
// Testbench fixed, code simplified, unused signals removed.
4157
//
4158
// Revision 1.7  2002/02/15 13:44:28  mohor
4159
// RxAbort is an output. No need to have is declared as wire.
4160
//
4161
// Revision 1.6  2002/02/15 11:17:48  mohor
4162
// File format changed.
4163
//
4164
// Revision 1.5  2002/02/14 20:48:43  billditt
4165
// Addition  of new module eth_addrcheck.v
4166
//
4167
// Revision 1.4  2002/01/23 10:28:16  mohor
4168
// Link in the header changed.
4169
//
4170
// Revision 1.3  2001/10/19 08:43:51  mohor
4171
// eth_timescale.v changed to timescale.v This is done because of the
4172
// simulation of the few cores in a one joined project.
4173
//
4174
// Revision 1.2  2001/09/11 14:17:00  mohor
4175
// Few little NCSIM warnings fixed.
4176
//
4177
// Revision 1.1  2001/08/06 14:44:29  mohor
4178
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
4179
// Include files fixed to contain no path.
4180
// File names and module names changed ta have a eth_ prologue in the name.
4181
// File eth_timescale.v is used to define timescale
4182
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
4183
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
4184
// and Mdo_OE. The bidirectional signal must be created on the top level. This
4185
// is done due to the ASIC tools.
4186
//
4187
// Revision 1.1  2001/07/30 21:23:42  mohor
4188
// Directory structure changed. Files checked and joind together.
4189
//
4190
// Revision 1.1  2001/06/27 21:26:19  mohor
4191
// Initial release of the RxEthMAC module.
4192
//
4193
//
4194
//
4195
//
4196
//
4197
 
4198
`include "timescale.v"
4199
 
4200
 
4201
module eth_rxethmac (MRxClk, MRxDV, MRxD, Reset, Transmitting, MaxFL, r_IFG, HugEn, DlyCrcEn,
4202
                     RxData, RxValid, RxStartFrm, RxEndFrm, ByteCnt, ByteCntEq0, ByteCntGreat2,
4203
                     ByteCntMaxFrame, CrcError, StateIdle, StatePreamble, StateSFD, StateData,
4204
                     MAC, r_Pro, r_Bro,r_HASH0, r_HASH1, RxAbort, AddressMiss, PassAll, ControlFrmAddressOK
4205
                    );
4206
 
4207
parameter Tp = 1;
4208
 
4209
 
4210
 
4211
input         MRxClk;
4212
input         MRxDV;
4213
input   [3:0] MRxD;
4214
input         Transmitting;
4215
input         HugEn;
4216
input         DlyCrcEn;
4217
input  [15:0] MaxFL;
4218
input         r_IFG;
4219
input         Reset;
4220
input  [47:0] MAC;     //  Station Address  
4221
input         r_Bro;   //  broadcast disable
4222
input         r_Pro;   //  promiscuous enable 
4223
input [31:0]  r_HASH0; //  lower 4 bytes Hash Table
4224
input [31:0]  r_HASH1; //  upper 4 bytes Hash Table
4225
input         PassAll;
4226
input         ControlFrmAddressOK;
4227
 
4228
output  [7:0] RxData;
4229
output        RxValid;
4230
output        RxStartFrm;
4231
output        RxEndFrm;
4232
output [15:0] ByteCnt;
4233
output        ByteCntEq0;
4234
output        ByteCntGreat2;
4235
output        ByteCntMaxFrame;
4236
output        CrcError;
4237
output        StateIdle;
4238
output        StatePreamble;
4239
output        StateSFD;
4240
output  [1:0] StateData;
4241
output        RxAbort;
4242
output        AddressMiss;
4243
 
4244
reg     [7:0] RxData;
4245
reg           RxValid;
4246
reg           RxStartFrm;
4247
reg           RxEndFrm;
4248
reg           Broadcast;
4249
reg           Multicast;
4250
reg     [5:0] CrcHash;
4251
reg           CrcHashGood;
4252
reg           DelayData;
4253
reg     [7:0] LatchedByte;
4254
reg     [7:0] RxData_d;
4255
reg           RxValid_d;
4256
reg           RxStartFrm_d;
4257
reg           RxEndFrm_d;
4258
 
4259
wire          MRxDEqD;
4260
wire          MRxDEq5;
4261
wire          StateDrop;
4262
wire          ByteCntEq1;
4263
wire          ByteCntEq2;
4264
wire          ByteCntEq3;
4265
wire          ByteCntEq4;
4266
wire          ByteCntEq5;
4267
wire          ByteCntEq6;
4268
wire          ByteCntEq7;
4269
wire          ByteCntSmall7;
4270
wire   [31:0] Crc;
4271
wire          Enable_Crc;
4272
wire          Initialize_Crc;
4273
wire    [3:0] Data_Crc;
4274
wire          GenerateRxValid;
4275
wire          GenerateRxStartFrm;
4276
wire          GenerateRxEndFrm;
4277
wire          DribbleRxEndFrm;
4278
wire    [3:0] DlyCrcCnt;
4279
wire          IFGCounterEq24;
4280
 
4281
assign MRxDEqD = MRxD == 4'hd;
4282
assign MRxDEq5 = MRxD == 4'h5;
4283
 
4284
 
4285
// Rx State Machine module
4286
eth_rxstatem rxstatem1 (.MRxClk(MRxClk), .Reset(Reset), .MRxDV(MRxDV), .ByteCntEq0(ByteCntEq0),
4287
                        .ByteCntGreat2(ByteCntGreat2), .Transmitting(Transmitting), .MRxDEq5(MRxDEq5),
4288
                        .MRxDEqD(MRxDEqD), .IFGCounterEq24(IFGCounterEq24), .ByteCntMaxFrame(ByteCntMaxFrame),
4289
                        .StateData(StateData), .StateIdle(StateIdle), .StatePreamble(StatePreamble),
4290
                        .StateSFD(StateSFD), .StateDrop(StateDrop)
4291
                       );
4292
 
4293
 
4294
// Rx Counters module
4295
eth_rxcounters rxcounters1 (.MRxClk(MRxClk), .Reset(Reset), .MRxDV(MRxDV), .StateIdle(StateIdle),
4296
                            .StateSFD(StateSFD), .StateData(StateData), .StateDrop(StateDrop),
4297
                            .StatePreamble(StatePreamble), .MRxDEqD(MRxDEqD), .DlyCrcEn(DlyCrcEn),
4298
                            .DlyCrcCnt(DlyCrcCnt), .Transmitting(Transmitting), .MaxFL(MaxFL), .r_IFG(r_IFG),
4299
                            .HugEn(HugEn), .IFGCounterEq24(IFGCounterEq24), .ByteCntEq0(ByteCntEq0),
4300
                            .ByteCntEq1(ByteCntEq1), .ByteCntEq2(ByteCntEq2), .ByteCntEq3(ByteCntEq3),
4301
                            .ByteCntEq4(ByteCntEq4), .ByteCntEq5(ByteCntEq5), .ByteCntEq6(ByteCntEq6),
4302
                            .ByteCntEq7(ByteCntEq7), .ByteCntGreat2(ByteCntGreat2),
4303
                            .ByteCntSmall7(ByteCntSmall7), .ByteCntMaxFrame(ByteCntMaxFrame),
4304
                            .ByteCntOut(ByteCnt)
4305
                           );
4306
 
4307
// Rx Address Check
4308
 
4309
eth_rxaddrcheck rxaddrcheck1
4310
              (.MRxClk(MRxClk),         .Reset( Reset),             .RxData(RxData),
4311
               .Broadcast (Broadcast),  .r_Bro (r_Bro),             .r_Pro(r_Pro),
4312
               .ByteCntEq6(ByteCntEq6), .ByteCntEq7(ByteCntEq7),    .ByteCntEq2(ByteCntEq2),
4313
               .ByteCntEq3(ByteCntEq3), .ByteCntEq4(ByteCntEq4),    .ByteCntEq5(ByteCntEq5),
4314
               .HASH0(r_HASH0),         .HASH1(r_HASH1),
4315
               .CrcHash(CrcHash),       .CrcHashGood(CrcHashGood),  .StateData(StateData),
4316
               .Multicast(Multicast),   .MAC(MAC),                  .RxAbort(RxAbort),
4317
               .RxEndFrm(RxEndFrm),     .AddressMiss(AddressMiss),  .PassAll(PassAll),
4318
               .ControlFrmAddressOK(ControlFrmAddressOK)
4319
              );
4320
 
4321
 
4322
assign Enable_Crc = MRxDV & (|StateData & ~ByteCntMaxFrame);
4323
assign Initialize_Crc = StateSFD | DlyCrcEn & (|DlyCrcCnt[3:0]) & DlyCrcCnt[3:0] < 4'h9;
4324
 
4325
assign Data_Crc[0] = MRxD[3];
4326
assign Data_Crc[1] = MRxD[2];
4327
assign Data_Crc[2] = MRxD[1];
4328
assign Data_Crc[3] = MRxD[0];
4329
 
4330
 
4331
// Connecting module Crc
4332
eth_crc crcrx (.Clk(MRxClk), .Reset(Reset), .Data(Data_Crc), .Enable(Enable_Crc), .Initialize(Initialize_Crc),
4333
               .Crc(Crc), .CrcError(CrcError)
4334
              );
4335
 
4336
 
4337
 
4338
// Latching CRC for use in the hash table
4339
 
4340
always @ (posedge MRxClk)
4341
begin
4342
  CrcHashGood <= #Tp StateData[0] & ByteCntEq6;
4343
end
4344
 
4345
always @ (posedge MRxClk)
4346
begin
4347
  if(Reset | StateIdle)
4348
    CrcHash[5:0] <= #Tp 6'h0;
4349
  else
4350
  if(StateData[0] & ByteCntEq6)
4351
    CrcHash[5:0] <= #Tp Crc[31:26];
4352
end
4353
 
4354
 
4355
// Output byte stream
4356
always @ (posedge MRxClk or posedge Reset)
4357
begin
4358
  if(Reset)
4359
    begin
4360
      RxData_d[7:0]      <= #Tp 8'h0;
4361
      DelayData          <= #Tp 1'b0;
4362
      LatchedByte[7:0]   <= #Tp 8'h0;
4363
      RxData[7:0]        <= #Tp 8'h0;
4364
    end
4365
  else
4366
    begin
4367
      LatchedByte[7:0]   <= #Tp {MRxD[3:0], LatchedByte[7:4]};  // Latched byte
4368
      DelayData          <= #Tp StateData[0];
4369
 
4370
      if(GenerateRxValid)
4371
        RxData_d[7:0] <= #Tp LatchedByte[7:0] & {8{|StateData}};  // Data goes through only in data state 
4372
      else
4373
      if(~DelayData)
4374
        RxData_d[7:0] <= #Tp 8'h0;                                // Delaying data to be valid for two cycles. Zero when not active.
4375
 
4376
      RxData[7:0] <= #Tp RxData_d[7:0];                           // Output data byte
4377
    end
4378
end
4379
 
4380
 
4381
 
4382
always @ (posedge MRxClk or posedge Reset)
4383
begin
4384
  if(Reset)
4385
    Broadcast <= #Tp 1'b0;
4386
  else
4387
    begin
4388
      if(StateData[0] & ~(&LatchedByte[7:0]) & ByteCntSmall7)
4389
        Broadcast <= #Tp 1'b0;
4390
      else
4391
      if(StateData[0] & (&LatchedByte[7:0]) & ByteCntEq1)
4392
        Broadcast <= #Tp 1'b1;
4393
      else
4394
      if(RxAbort | RxEndFrm)
4395
        Broadcast <= #Tp 1'b0;
4396
    end
4397
end
4398
 
4399
 
4400
always @ (posedge MRxClk or posedge Reset)
4401
begin
4402
  if(Reset)
4403
    Multicast <= #Tp 1'b0;
4404
  else
4405
    begin
4406
      if(StateData[0] & ByteCntEq1 & LatchedByte[0])
4407
        Multicast <= #Tp 1'b1;
4408
      else if(RxAbort | RxEndFrm)
4409
      Multicast <= #Tp 1'b0;
4410
    end
4411
end
4412
 
4413
 
4414
assign GenerateRxValid = StateData[0] & (~ByteCntEq0 | DlyCrcCnt >= 4'h3);
4415
 
4416
always @ (posedge MRxClk or posedge Reset)
4417
begin
4418
  if(Reset)
4419
    begin
4420
      RxValid_d <= #Tp 1'b0;
4421
      RxValid   <= #Tp 1'b0;
4422
    end
4423
  else
4424
    begin
4425
      RxValid_d <= #Tp GenerateRxValid;
4426
      RxValid   <= #Tp RxValid_d;
4427
    end
4428
end
4429
 
4430
 
4431
assign GenerateRxStartFrm = StateData[0] & (ByteCntEq1 & ~DlyCrcEn | DlyCrcCnt == 4'h3 & DlyCrcEn);
4432
 
4433
always @ (posedge MRxClk or posedge Reset)
4434
begin
4435
  if(Reset)
4436
    begin
4437
      RxStartFrm_d <= #Tp 1'b0;
4438
      RxStartFrm   <= #Tp 1'b0;
4439
    end
4440
  else
4441
    begin
4442
      RxStartFrm_d <= #Tp GenerateRxStartFrm;
4443
      RxStartFrm   <= #Tp RxStartFrm_d;
4444
    end
4445
end
4446
 
4447
 
4448
assign GenerateRxEndFrm = StateData[0] & (~MRxDV & ByteCntGreat2 | ByteCntMaxFrame);
4449
assign DribbleRxEndFrm  = StateData[1] &  ~MRxDV & ByteCntGreat2;
4450
 
4451
 
4452
always @ (posedge MRxClk or posedge Reset)
4453
begin
4454
  if(Reset)
4455
    begin
4456
      RxEndFrm_d <= #Tp 1'b0;
4457
      RxEndFrm   <= #Tp 1'b0;
4458
    end
4459
  else
4460
    begin
4461
      RxEndFrm_d <= #Tp GenerateRxEndFrm;
4462
      RxEndFrm   <= #Tp RxEndFrm_d | DribbleRxEndFrm;
4463
    end
4464
end
4465
 
4466
 
4467
endmodule
4468
//////////////////////////////////////////////////////////////////////
4469
////                                                              ////
4470
////  eth_rxstatem.v                                              ////
4471
////                                                              ////
4472
////  This file is part of the Ethernet IP core project           ////
4473
////  http://www.opencores.org/projects/ethmac/                   ////
4474
////                                                              ////
4475
////  Author(s):                                                  ////
4476
////      - Igor Mohor (igorM@opencores.org)                      ////
4477
////      - Novan Hartadi (novan@vlsi.itb.ac.id)                  ////
4478
////      - Mahmud Galela (mgalela@vlsi.itb.ac.id)                ////
4479
////                                                              ////
4480
////  All additional information is avaliable in the Readme.txt   ////
4481
////  file.                                                       ////
4482
////                                                              ////
4483
//////////////////////////////////////////////////////////////////////
4484
////                                                              ////
4485
//// Copyright (C) 2001 Authors                                   ////
4486
////                                                              ////
4487
//// This source file may be used and distributed without         ////
4488
//// restriction provided that this copyright statement is not    ////
4489
//// removed from the file and that any derivative work contains  ////
4490
//// the original copyright notice and the associated disclaimer. ////
4491
////                                                              ////
4492
//// This source file is free software; you can redistribute it   ////
4493
//// and/or modify it under the terms of the GNU Lesser General   ////
4494
//// Public License as published by the Free Software Foundation; ////
4495
//// either version 2.1 of the License, or (at your option) any   ////
4496
//// later version.                                               ////
4497
////                                                              ////
4498
//// This source is distributed in the hope that it will be       ////
4499
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
4500
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
4501
//// PURPOSE.  See the GNU Lesser General Public License for more ////
4502
//// details.                                                     ////
4503
////                                                              ////
4504
//// You should have received a copy of the GNU Lesser General    ////
4505
//// Public License along with this source; if not, download it   ////
4506
//// from http://www.opencores.org/lgpl.shtml                     ////
4507
////                                                              ////
4508
//////////////////////////////////////////////////////////////////////
4509
//
4510
// CVS Revision History
4511
//
4512
// $Log: eth_rxstatem.v,v $
4513
// Revision 1.6  2002/11/13 22:28:26  tadejm
4514
// StartIdle state changed (not important the size of the packet).
4515
// StartData1 activates only while ByteCnt is smaller than the MaxFrame.
4516
//
4517
// Revision 1.5  2002/01/23 10:28:16  mohor
4518
// Link in the header changed.
4519
//
4520
// Revision 1.4  2001/10/19 08:43:51  mohor
4521
// eth_timescale.v changed to timescale.v This is done because of the
4522
// simulation of the few cores in a one joined project.
4523
//
4524
// Revision 1.3  2001/10/18 12:07:11  mohor
4525
// Status signals changed, Adress decoding changed, interrupt controller
4526
// added.
4527
//
4528
// Revision 1.2  2001/09/11 14:17:00  mohor
4529
// Few little NCSIM warnings fixed.
4530
//
4531
// Revision 1.1  2001/08/06 14:44:29  mohor
4532
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
4533
// Include files fixed to contain no path.
4534
// File names and module names changed ta have a eth_ prologue in the name.
4535
// File eth_timescale.v is used to define timescale
4536
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
4537
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
4538
// and Mdo_OE. The bidirectional signal must be created on the top level. This
4539
// is done due to the ASIC tools.
4540
//
4541
// Revision 1.1  2001/07/30 21:23:42  mohor
4542
// Directory structure changed. Files checked and joind together.
4543
//
4544
// Revision 1.2  2001/07/03 12:55:41  mohor
4545
// Minor changes because of the synthesys warnings.
4546
//
4547
//
4548
// Revision 1.1  2001/06/27 21:26:19  mohor
4549
// Initial release of the RxEthMAC module.
4550
//
4551
//
4552
//
4553
//
4554
 
4555
 
4556
`include "timescale.v"
4557
 
4558
 
4559
module eth_rxstatem (MRxClk, Reset, MRxDV, ByteCntEq0, ByteCntGreat2, Transmitting, MRxDEq5, MRxDEqD,
4560
                     IFGCounterEq24, ByteCntMaxFrame, StateData, StateIdle, StatePreamble, StateSFD,
4561
                     StateDrop
4562
                    );
4563
 
4564
parameter Tp = 1;
4565
 
4566
input         MRxClk;
4567
input         Reset;
4568
input         MRxDV;
4569
input         ByteCntEq0;
4570
input         ByteCntGreat2;
4571
input         MRxDEq5;
4572
input         Transmitting;
4573
input         MRxDEqD;
4574
input         IFGCounterEq24;
4575
input         ByteCntMaxFrame;
4576
 
4577
output [1:0]  StateData;
4578
output        StateIdle;
4579
output        StateDrop;
4580
output        StatePreamble;
4581
output        StateSFD;
4582
 
4583
reg           StateData0;
4584
reg           StateData1;
4585
reg           StateIdle;
4586
reg           StateDrop;
4587
reg           StatePreamble;
4588
reg           StateSFD;
4589
 
4590
wire          StartIdle;
4591
wire          StartDrop;
4592
wire          StartData0;
4593
wire          StartData1;
4594
wire          StartPreamble;
4595
wire          StartSFD;
4596
 
4597
 
4598
// Defining the next state
4599
assign StartIdle = ~MRxDV & (StateDrop | StatePreamble | StateSFD | (|StateData));
4600
 
4601
assign StartPreamble = MRxDV & ~MRxDEq5 & (StateIdle & ~Transmitting);
4602
 
4603
assign StartSFD = MRxDV & MRxDEq5 & (StateIdle & ~Transmitting | StatePreamble);
4604
 
4605
assign StartData0 = MRxDV & (StateSFD & MRxDEqD & IFGCounterEq24 | StateData1);
4606
 
4607
assign StartData1 = MRxDV & StateData0 & (~ByteCntMaxFrame);
4608
 
4609
assign StartDrop = MRxDV & (StateIdle & Transmitting | StateSFD & ~IFGCounterEq24 &  MRxDEqD
4610
                         |  StateData0 &  ByteCntMaxFrame
4611
                           );
4612
 
4613
// Rx State Machine
4614
always @ (posedge MRxClk or posedge Reset)
4615
begin
4616
  if(Reset)
4617
    begin
4618
      StateIdle     <= #Tp 1'b0;
4619
      StateDrop     <= #Tp 1'b1;
4620
      StatePreamble <= #Tp 1'b0;
4621
      StateSFD      <= #Tp 1'b0;
4622
      StateData0    <= #Tp 1'b0;
4623
      StateData1    <= #Tp 1'b0;
4624
    end
4625
  else
4626
    begin
4627
      if(StartPreamble | StartSFD | StartDrop)
4628
        StateIdle <= #Tp 1'b0;
4629
      else
4630
      if(StartIdle)
4631
        StateIdle <= #Tp 1'b1;
4632
 
4633
      if(StartIdle)
4634
        StateDrop <= #Tp 1'b0;
4635
      else
4636
      if(StartDrop)
4637
        StateDrop <= #Tp 1'b1;
4638
 
4639
      if(StartSFD | StartIdle | StartDrop)
4640
        StatePreamble <= #Tp 1'b0;
4641
      else
4642
      if(StartPreamble)
4643
        StatePreamble <= #Tp 1'b1;
4644
 
4645
      if(StartPreamble | StartIdle | StartData0 | StartDrop)
4646
        StateSFD <= #Tp 1'b0;
4647
      else
4648
      if(StartSFD)
4649
        StateSFD <= #Tp 1'b1;
4650
 
4651
      if(StartIdle | StartData1 | StartDrop)
4652
        StateData0 <= #Tp 1'b0;
4653
      else
4654
      if(StartData0)
4655
        StateData0 <= #Tp 1'b1;
4656
 
4657
      if(StartIdle | StartData0 | StartDrop)
4658
        StateData1 <= #Tp 1'b0;
4659
      else
4660
      if(StartData1)
4661
        StateData1 <= #Tp 1'b1;
4662
    end
4663
end
4664
 
4665
assign StateData[1:0] = {StateData1, StateData0};
4666
 
4667
endmodule
4668
//////////////////////////////////////////////////////////////////////
4669
////                                                              ////
4670
////  eth_shiftreg.v                                              ////
4671
////                                                              ////
4672
////  This file is part of the Ethernet IP core project           ////
4673
////  http://www.opencores.org/projects/ethmac/                   ////
4674
////                                                              ////
4675
////  Author(s):                                                  ////
4676
////      - Igor Mohor (igorM@opencores.org)                      ////
4677
////                                                              ////
4678
////  All additional information is avaliable in the Readme.txt   ////
4679
////  file.                                                       ////
4680
////                                                              ////
4681
//////////////////////////////////////////////////////////////////////
4682
////                                                              ////
4683
//// Copyright (C) 2001 Authors                                   ////
4684
////                                                              ////
4685
//// This source file may be used and distributed without         ////
4686
//// restriction provided that this copyright statement is not    ////
4687
//// removed from the file and that any derivative work contains  ////
4688
//// the original copyright notice and the associated disclaimer. ////
4689
////                                                              ////
4690
//// This source file is free software; you can redistribute it   ////
4691
//// and/or modify it under the terms of the GNU Lesser General   ////
4692
//// Public License as published by the Free Software Foundation; ////
4693
//// either version 2.1 of the License, or (at your option) any   ////
4694
//// later version.                                               ////
4695
////                                                              ////
4696
//// This source is distributed in the hope that it will be       ////
4697
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
4698
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
4699
//// PURPOSE.  See the GNU Lesser General Public License for more ////
4700
//// details.                                                     ////
4701
////                                                              ////
4702
//// You should have received a copy of the GNU Lesser General    ////
4703
//// Public License along with this source; if not, download it   ////
4704
//// from http://www.opencores.org/lgpl.shtml                     ////
4705
////                                                              ////
4706
//////////////////////////////////////////////////////////////////////
4707
//
4708
// CVS Revision History
4709
//
4710
// $Log: eth_shiftreg.v,v $
4711
// Revision 1.6  2005/03/08 14:45:09  igorm
4712
// Case statement improved for synthesys.
4713
//
4714
// Revision 1.5  2002/08/14 18:16:59  mohor
4715
// LinkFail signal was not latching appropriate bit.
4716
//
4717
// Revision 1.4  2002/03/02 21:06:01  mohor
4718
// LinkFail signal was not latching appropriate bit.
4719
//
4720
// Revision 1.3  2002/01/23 10:28:16  mohor
4721
// Link in the header changed.
4722
//
4723
// Revision 1.2  2001/10/19 08:43:51  mohor
4724
// eth_timescale.v changed to timescale.v This is done because of the
4725
// simulation of the few cores in a one joined project.
4726
//
4727
// Revision 1.1  2001/08/06 14:44:29  mohor
4728
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
4729
// Include files fixed to contain no path.
4730
// File names and module names changed ta have a eth_ prologue in the name.
4731
// File eth_timescale.v is used to define timescale
4732
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
4733
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
4734
// and Mdo_OE. The bidirectional signal must be created on the top level. This
4735
// is done due to the ASIC tools.
4736
//
4737
// Revision 1.1  2001/07/30 21:23:42  mohor
4738
// Directory structure changed. Files checked and joind together.
4739
//
4740
// Revision 1.3  2001/06/01 22:28:56  mohor
4741
// This files (MIIM) are fully working. They were thoroughly tested. The testbench is not updated.
4742
//
4743
//
4744
 
4745
`include "timescale.v"
4746
 
4747
 
4748
module eth_shiftreg(Clk, Reset, MdcEn_n, Mdi, Fiad, Rgad, CtrlData, WriteOp, ByteSelect,
4749
                    LatchByte, ShiftedBit, Prsd, LinkFail);
4750
 
4751
 
4752
parameter Tp=1;
4753
 
4754
input       Clk;              // Input clock (Host clock)
4755
input       Reset;            // Reset signal
4756
input       MdcEn_n;          // Enable signal is asserted for one Clk period before Mdc falls.
4757
input       Mdi;              // MII input data
4758
input [4:0] Fiad;             // PHY address
4759
input [4:0] Rgad;             // Register address (within the selected PHY)
4760
input [15:0]CtrlData;         // Control data (data to be written to the PHY)
4761
input       WriteOp;          // The current operation is a PHY register write operation
4762
input [3:0] ByteSelect;       // Byte select
4763
input [1:0] LatchByte;        // Byte select for latching (read operation)
4764
 
4765
output      ShiftedBit;       // Bit shifted out of the shift register
4766
output[15:0]Prsd;             // Read Status Data (data read from the PHY)
4767
output      LinkFail;         // Link Integrity Signal
4768
 
4769
reg   [7:0] ShiftReg;         // Shift register for shifting the data in and out
4770
reg   [15:0]Prsd;
4771
reg         LinkFail;
4772
 
4773
 
4774
 
4775
 
4776
// ShiftReg[7:0] :: Shift Register Data
4777
always @ (posedge Clk or posedge Reset)
4778
begin
4779
  if(Reset)
4780
    begin
4781
      ShiftReg[7:0] <= #Tp 8'h0;
4782
      Prsd[15:0] <= #Tp 16'h0;
4783
      LinkFail <= #Tp 1'b0;
4784
    end
4785
  else
4786
    begin
4787
      if(MdcEn_n)
4788
        begin
4789
          if(|ByteSelect)
4790
            begin
4791
              case (ByteSelect[3:0])  // synopsys parallel_case full_case
4792
                4'h1 :    ShiftReg[7:0] <= #Tp {2'b01, ~WriteOp, WriteOp, Fiad[4:1]};
4793
                4'h2 :    ShiftReg[7:0] <= #Tp {Fiad[0], Rgad[4:0], 2'b10};
4794
                4'h4 :    ShiftReg[7:0] <= #Tp CtrlData[15:8];
4795
                4'h8 :    ShiftReg[7:0] <= #Tp CtrlData[7:0];
4796
              endcase
4797
            end
4798
          else
4799
            begin
4800
              ShiftReg[7:0] <= #Tp {ShiftReg[6:0], Mdi};
4801
              if(LatchByte[0])
4802
                begin
4803
                  Prsd[7:0] <= #Tp {ShiftReg[6:0], Mdi};
4804
                  if(Rgad == 5'h01)
4805
                    LinkFail <= #Tp ~ShiftReg[1];  // this is bit [2], because it is not shifted yet
4806
                end
4807
              else
4808
                begin
4809
                  if(LatchByte[1])
4810
                    Prsd[15:8] <= #Tp {ShiftReg[6:0], Mdi};
4811
                end
4812
            end
4813
        end
4814
    end
4815
end
4816
 
4817
 
4818
assign ShiftedBit = ShiftReg[7];
4819
 
4820
 
4821
endmodule
4822
//////////////////////////////////////////////////////////////////////
4823
////                                                              ////
4824
////  eth_spram_256x32.v                                          ////
4825
////                                                              ////
4826
////  This file is part of the Ethernet IP core project           ////
4827
////  http://www.opencores.org/projects/ethmac/                   ////
4828
////                                                              ////
4829
////  Author(s):                                                  ////
4830
////      - Igor Mohor (igorM@opencores.org)                      ////
4831
////                                                              ////
4832
////  All additional information is available in the Readme.txt   ////
4833
////  file.                                                       ////
4834
////                                                              ////
4835
//////////////////////////////////////////////////////////////////////
4836
////                                                              ////
4837
//// Copyright (C) 2001, 2002 Authors                             ////
4838
////                                                              ////
4839
//// This source file may be used and distributed without         ////
4840
//// restriction provided that this copyright statement is not    ////
4841
//// removed from the file and that any derivative work contains  ////
4842
//// the original copyright notice and the associated disclaimer. ////
4843
////                                                              ////
4844
//// This source file is free software; you can redistribute it   ////
4845
//// and/or modify it under the terms of the GNU Lesser General   ////
4846
//// Public License as published by the Free Software Foundation; ////
4847
//// either version 2.1 of the License, or (at your option) any   ////
4848
//// later version.                                               ////
4849
////                                                              ////
4850
//// This source is distributed in the hope that it will be       ////
4851
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
4852
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
4853
//// PURPOSE.  See the GNU Lesser General Public License for more ////
4854
//// details.                                                     ////
4855
////                                                              ////
4856
//// You should have received a copy of the GNU Lesser General    ////
4857
//// Public License along with this source; if not, download it   ////
4858
//// from http://www.opencores.org/lgpl.shtml                     ////
4859
////                                                              ////
4860
//////////////////////////////////////////////////////////////////////
4861
//
4862
// CVS Revision History
4863
//
4864
// $Log: eth_spram_256x32.v,v $
4865
// Revision 1.10  2005/02/21 12:48:07  igorm
4866
// Warning fixes.
4867
//
4868
// Revision 1.9  2003/12/05 12:43:06  tadejm
4869
// Corrected address mismatch for xilinx RAMB4_S8 model which has wider address than RAMB4_S16.
4870
//
4871
// Revision 1.8  2003/12/04 14:59:13  simons
4872
// Lapsus fixed (!we -> ~we).
4873
//
4874
// Revision 1.7  2003/11/12 18:24:59  tadejm
4875
// WISHBONE slave changed and tested from only 32-bit accesss to byte access.
4876
//
4877
// Revision 1.6  2003/10/17 07:46:15  markom
4878
// mbist signals updated according to newest convention
4879
//
4880
// Revision 1.5  2003/08/14 16:42:58  simons
4881
// Artisan ram instance added.
4882
//
4883
// Revision 1.4  2002/10/18 17:04:20  tadejm
4884
// Changed BIST scan signals.
4885
//
4886
// Revision 1.3  2002/10/10 16:29:30  mohor
4887
// BIST added.
4888
//
4889
// Revision 1.2  2002/09/23 18:24:31  mohor
4890
// ETH_VIRTUAL_SILICON_RAM supported (for ASIC implementation).
4891
//
4892
// Revision 1.1  2002/07/23 16:36:09  mohor
4893
// ethernet spram added. So far a generic ram and xilinx RAMB4 are used.
4894
//
4895
//
4896
//
4897
 
4898
`include "eth_defines.v"
4899
`include "timescale.v"
4900
 
4901
module eth_spram_256x32(
4902
        // Generic synchronous single-port RAM interface
4903
        clk, rst, ce, we, oe, addr, di, do
4904
 
4905
`ifdef ETH_BIST
4906
  ,
4907
  // debug chain signals
4908
  mbist_si_i,       // bist scan serial in
4909
  mbist_so_o,       // bist scan serial out
4910
  mbist_ctrl_i        // bist chain shift control
4911
`endif
4912
 
4913
 
4914
 
4915
);
4916
 
4917
        //
4918
        // Generic synchronous single-port RAM interface
4919
        //
4920
        input           clk;  // Clock, rising edge
4921
        input           rst;  // Reset, active high
4922
        input           ce;   // Chip enable input, active high
4923
        input  [3:0]    we;   // Write enable input, active high
4924
        input           oe;   // Output enable input, active high
4925
        input  [7:0]    addr; // address bus inputs
4926
        input  [31:0]   di;   // input data bus
4927
        output [31:0]   do;   // output data bus
4928
 
4929
 
4930
`ifdef ETH_BIST
4931
  input   mbist_si_i;       // bist scan serial in
4932
  output  mbist_so_o;       // bist scan serial out
4933
  input [`ETH_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;       // bist chain shift control
4934
`endif
4935
 
4936
`ifdef ETH_XILINX_RAMB4
4937
 
4938
    /*RAMB4_S16 ram0
4939
    (
4940
        .DO      (do[15:0]),
4941
        .ADDR    (addr),
4942
        .DI      (di[15:0]),
4943
        .EN      (ce),
4944
        .CLK     (clk),
4945
        .WE      (we),
4946
        .RST     (rst)
4947
    );
4948
 
4949
    RAMB4_S16 ram1
4950
    (
4951
        .DO      (do[31:16]),
4952
        .ADDR    (addr),
4953
        .DI      (di[31:16]),
4954
        .EN      (ce),
4955
        .CLK     (clk),
4956
        .WE      (we),
4957
        .RST     (rst)
4958
    );*/
4959
 
4960
    RAMB4_S8 ram0
4961
    (
4962
        .DO      (do[7:0]),
4963
        .ADDR    ({1'b0, addr}),
4964
        .DI      (di[7:0]),
4965
        .EN      (ce),
4966
        .CLK     (clk),
4967
        .WE      (we[0]),
4968
        .RST     (rst)
4969
    );
4970
 
4971
    RAMB4_S8 ram1
4972
    (
4973
        .DO      (do[15:8]),
4974
        .ADDR    ({1'b0, addr}),
4975
        .DI      (di[15:8]),
4976
        .EN      (ce),
4977
        .CLK     (clk),
4978
        .WE      (we[1]),
4979
        .RST     (rst)
4980
    );
4981
 
4982
    RAMB4_S8 ram2
4983
    (
4984
        .DO      (do[23:16]),
4985
        .ADDR    ({1'b0, addr}),
4986
        .DI      (di[23:16]),
4987
        .EN      (ce),
4988
        .CLK     (clk),
4989
        .WE      (we[2]),
4990
        .RST     (rst)
4991
    );
4992
 
4993
    RAMB4_S8 ram3
4994
    (
4995
        .DO      (do[31:24]),
4996
        .ADDR    ({1'b0, addr}),
4997
        .DI      (di[31:24]),
4998
        .EN      (ce),
4999
        .CLK     (clk),
5000
        .WE      (we[3]),
5001
        .RST     (rst)
5002
    );
5003
 
5004
`else   // !ETH_XILINX_RAMB4
5005
`ifdef  ETH_VIRTUAL_SILICON_RAM
5006
  `ifdef ETH_BIST
5007
      //vs_hdsp_256x32_bist ram0_bist
5008
      vs_hdsp_256x32_bw_bist ram0_bist
5009
  `else
5010
      //vs_hdsp_256x32 ram0
5011
      vs_hdsp_256x32_bw ram0
5012
  `endif
5013
      (
5014
        .CK         (clk),
5015
        .CEN        (!ce),
5016
        .WEN        (~we),
5017
        .OEN        (!oe),
5018
        .ADR        (addr),
5019
        .DI         (di),
5020
        .DOUT       (do)
5021
 
5022
      `ifdef ETH_BIST
5023
        ,
5024
        // debug chain signals
5025
        .mbist_si_i       (mbist_si_i),
5026
        .mbist_so_o       (mbist_so_o),
5027
        .mbist_ctrl_i       (mbist_ctrl_i)
5028
      `endif
5029
      );
5030
 
5031
`else   // !ETH_VIRTUAL_SILICON_RAM
5032
 
5033
`ifdef  ETH_ARTISAN_RAM
5034
  `ifdef ETH_BIST
5035
      //art_hssp_256x32_bist ram0_bist
5036
      art_hssp_256x32_bw_bist ram0_bist
5037
  `else
5038
      //art_hssp_256x32 ram0
5039
      art_hssp_256x32_bw ram0
5040
  `endif
5041
      (
5042
        .CLK        (clk),
5043
        .CEN        (!ce),
5044
        .WEN        (~we),
5045
        .OEN        (!oe),
5046
        .A          (addr),
5047
        .D          (di),
5048
        .Q          (do)
5049
 
5050
      `ifdef ETH_BIST
5051
        ,
5052
        // debug chain signals
5053
        .mbist_si_i       (mbist_si_i),
5054
        .mbist_so_o       (mbist_so_o),
5055
        .mbist_ctrl_i     (mbist_ctrl_i)
5056
      `endif
5057
      );
5058
 
5059
`else   // !ETH_ARTISAN_RAM
5060
`ifdef ETH_ALTERA_ALTSYNCRAM
5061
 
5062
    altera_spram_256x32 altera_spram_256x32_inst
5063
    (
5064
          .address        (addr),
5065
          .wren           (ce & we),
5066
          .clock          (clk),
5067
          .data           (di),
5068
          .q              (do)
5069
        );  //exemplar attribute altera_spram_256x32_inst NOOPT TRUE
5070
 
5071
`else   // !ETH_ALTERA_ALTSYNCRAM
5072
 
5073
 
5074
        //
5075
        // Generic single-port synchronous RAM model
5076
        //
5077
 
5078
        //
5079
        // Generic RAM's registers and wires
5080
        //
5081
`ifdef ETH_SPRAM_BYTE_ENABLE
5082
        reg  [ 7: 0] mem0 [255:0]; // RAM content
5083
        reg  [15: 8] mem1 [255:0]; // RAM content
5084
        reg  [23:16] mem2 [255:0]; // RAM content
5085
        reg  [31:24] mem3 [255:0]; // RAM content
5086
//      wire [31:0]  q;            // RAM output
5087
        reg  [7:0]   raddr;        // RAM read address
5088
        //
5089
        // Data output drivers
5090
        //
5091
        //assign do = (oe & ce) ? q : {32{1'bz}};
5092
 
5093
        //
5094
        // RAM read and write
5095
        //
5096
 
5097
        // read operation
5098
        always@(posedge clk)
5099
          if (ce) // && !we)
5100
                raddr <= #1 addr;    // read address needs to be registered to read clock
5101
 
5102
//      assign #1 q = rst ? {32{1'b0}} : {mem3[raddr], mem2[raddr], mem1[raddr], mem0[raddr]};
5103
        assign #1 do = {mem3[raddr], mem2[raddr], mem1[raddr], mem0[raddr]};
5104
 
5105
        // write operation
5106
        always@(posedge clk)
5107
        begin
5108
                if (ce && we[3])
5109
                        mem3[addr] <= #1 di[31:24];
5110
                if (ce && we[2])
5111
                        mem2[addr] <= #1 di[23:16];
5112
                if (ce && we[1])
5113
                        mem1[addr] <= #1 di[15: 8];
5114
                if (ce && we[0])
5115
                        mem0[addr] <= #1 di[ 7: 0];
5116
        end
5117
 
5118
        // Task prints range of memory
5119
        // *** Remember that tasks are non reentrant, don't call this task in parallel for multiple instantiations. 
5120
        task print_ram;
5121
        input [7:0] start;
5122
        input [7:0] finish;
5123
        integer rnum;
5124
        begin
5125
                for (rnum=start;rnum<=finish;rnum=rnum+1)
5126
                        $display("Addr %h = %0h %0h %0h %0h",rnum,mem3[rnum],mem2[rnum],mem1[rnum],mem0[rnum]);
5127
        end
5128
        endtask
5129
`else // !`ifdef ETH_SPRAM_BYTE_ENABLE
5130
   reg  [31:0] mem [255:0]; // RAM content
5131
   reg [7:0]   raddr;
5132
   always @ (posedge clk)
5133
     if (ce)
5134
       raddr <= #1 addr;
5135
 
5136
   assign #1 do = mem[raddr];
5137
 
5138
   always @ (posedge clk)
5139
     if (ce && we[0])
5140
       mem[addr] <= #1 di;
5141
 
5142
   // Task prints range of memory
5143
   // *** Remember that tasks are non reentrant, don't call this task in parallel for multiple instantiations. 
5144
   task print_ram;
5145
      input [7:0] start;
5146
      input [7:0] finish;
5147
      integer     rnum;
5148
      begin
5149
         for (rnum=start;rnum<=finish;rnum=rnum+1)
5150
           $display("Addr %h = %0h",rnum,mem[rnum]);
5151
      end
5152
   endtask
5153
 
5154
`endif
5155
`endif  // !ETH_ALTERA_ALTSYNCRAM
5156
`endif  // !ETH_ARTISAN_RAM
5157
`endif  // !ETH_VIRTUAL_SILICON_RAM
5158
`endif  // !ETH_XILINX_RAMB4
5159
 
5160
endmodule
5161
//////////////////////////////////////////////////////////////////////
5162
////                                                              ////
5163
////  eth_transmitcontrol.v                                       ////
5164
////                                                              ////
5165
////  This file is part of the Ethernet IP core project           ////
5166
////  http://www.opencores.org/projects/ethmac/                   ////
5167
////                                                              ////
5168
////  Author(s):                                                  ////
5169
////      - Igor Mohor (igorM@opencores.org)                      ////
5170
////                                                              ////
5171
////  All additional information is avaliable in the Readme.txt   ////
5172
////  file.                                                       ////
5173
////                                                              ////
5174
//////////////////////////////////////////////////////////////////////
5175
////                                                              ////
5176
//// Copyright (C) 2001 Authors                                   ////
5177
////                                                              ////
5178
//// This source file may be used and distributed without         ////
5179
//// restriction provided that this copyright statement is not    ////
5180
//// removed from the file and that any derivative work contains  ////
5181
//// the original copyright notice and the associated disclaimer. ////
5182
////                                                              ////
5183
//// This source file is free software; you can redistribute it   ////
5184
//// and/or modify it under the terms of the GNU Lesser General   ////
5185
//// Public License as published by the Free Software Foundation; ////
5186
//// either version 2.1 of the License, or (at your option) any   ////
5187
//// later version.                                               ////
5188
////                                                              ////
5189
//// This source is distributed in the hope that it will be       ////
5190
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
5191
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
5192
//// PURPOSE.  See the GNU Lesser General Public License for more ////
5193
//// details.                                                     ////
5194
////                                                              ////
5195
//// You should have received a copy of the GNU Lesser General    ////
5196
//// Public License along with this source; if not, download it   ////
5197
//// from http://www.opencores.org/lgpl.shtml                     ////
5198
////                                                              ////
5199
//////////////////////////////////////////////////////////////////////
5200
//
5201
// CVS Revision History
5202
//
5203
// $Log: eth_transmitcontrol.v,v $
5204
// Revision 1.6  2002/11/21 00:16:14  mohor
5205
// When TxUsedData and CtrlMux occur at the same time, byte counter needs
5206
// to be incremented by 2. Signal IncrementByteCntBy2 added for that reason.
5207
//
5208
// Revision 1.5  2002/11/19 17:37:32  mohor
5209
// When control frame (PAUSE) was sent, status was written in the
5210
// eth_wishbone module and both TXB and TXC interrupts were set. Fixed.
5211
// Only TXC interrupt is set.
5212
//
5213
// Revision 1.4  2002/01/23 10:28:16  mohor
5214
// Link in the header changed.
5215
//
5216
// Revision 1.3  2001/10/19 08:43:51  mohor
5217
// eth_timescale.v changed to timescale.v This is done because of the
5218
// simulation of the few cores in a one joined project.
5219
//
5220
// Revision 1.2  2001/09/11 14:17:00  mohor
5221
// Few little NCSIM warnings fixed.
5222
//
5223
// Revision 1.1  2001/08/06 14:44:29  mohor
5224
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
5225
// Include files fixed to contain no path.
5226
// File names and module names changed ta have a eth_ prologue in the name.
5227
// File eth_timescale.v is used to define timescale
5228
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
5229
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
5230
// and Mdo_OE. The bidirectional signal must be created on the top level. This
5231
// is done due to the ASIC tools.
5232
//
5233
// Revision 1.1  2001/07/30 21:23:42  mohor
5234
// Directory structure changed. Files checked and joind together.
5235
//
5236
// Revision 1.1  2001/07/03 12:51:54  mohor
5237
// Initial release of the MAC Control module.
5238
//
5239
//
5240
//
5241
//
5242
//
5243
//
5244
 
5245
 
5246
`include "timescale.v"
5247
 
5248
 
5249
module eth_transmitcontrol (MTxClk, TxReset, TxUsedDataIn, TxUsedDataOut, TxDoneIn, TxAbortIn,
5250
                            TxStartFrmIn, TPauseRq, TxUsedDataOutDetected, TxFlow, DlyCrcEn,
5251
                            TxPauseTV, MAC, TxCtrlStartFrm, TxCtrlEndFrm, SendingCtrlFrm, CtrlMux,
5252
                            ControlData, WillSendControlFrame, BlockTxDone
5253
                           );
5254
 
5255
parameter Tp = 1;
5256
 
5257
 
5258
input         MTxClk;
5259
input         TxReset;
5260
input         TxUsedDataIn;
5261
input         TxUsedDataOut;
5262
input         TxDoneIn;
5263
input         TxAbortIn;
5264
input         TxStartFrmIn;
5265
input         TPauseRq;
5266
input         TxUsedDataOutDetected;
5267
input         TxFlow;
5268
input         DlyCrcEn;
5269
input  [15:0] TxPauseTV;
5270
input  [47:0] MAC;
5271
 
5272
output        TxCtrlStartFrm;
5273
output        TxCtrlEndFrm;
5274
output        SendingCtrlFrm;
5275
output        CtrlMux;
5276
output [7:0]  ControlData;
5277
output        WillSendControlFrame;
5278
output        BlockTxDone;
5279
 
5280
reg           SendingCtrlFrm;
5281
reg           CtrlMux;
5282
reg           WillSendControlFrame;
5283
reg    [3:0]  DlyCrcCnt;
5284
reg    [5:0]  ByteCnt;
5285
reg           ControlEnd_q;
5286
reg    [7:0]  MuxedCtrlData;
5287
reg           TxCtrlStartFrm;
5288
reg           TxCtrlStartFrm_q;
5289
reg           TxCtrlEndFrm;
5290
reg    [7:0]  ControlData;
5291
reg           TxUsedDataIn_q;
5292
reg           BlockTxDone;
5293
 
5294
wire          IncrementDlyCrcCnt;
5295
wire          ResetByteCnt;
5296
wire          IncrementByteCnt;
5297
wire          ControlEnd;
5298
wire          IncrementByteCntBy2;
5299
wire          EnableCnt;
5300
 
5301
 
5302
// A command for Sending the control frame is active (latched)
5303
always @ (posedge MTxClk or posedge TxReset)
5304
begin
5305
  if(TxReset)
5306
    WillSendControlFrame <= #Tp 1'b0;
5307
  else
5308
  if(TxCtrlEndFrm & CtrlMux)
5309
    WillSendControlFrame <= #Tp 1'b0;
5310
  else
5311
  if(TPauseRq & TxFlow)
5312
    WillSendControlFrame <= #Tp 1'b1;
5313
end
5314
 
5315
 
5316
// Generation of the transmit control packet start frame
5317
always @ (posedge MTxClk or posedge TxReset)
5318
begin
5319
  if(TxReset)
5320
    TxCtrlStartFrm <= #Tp 1'b0;
5321
  else
5322
  if(TxUsedDataIn_q & CtrlMux)
5323
    TxCtrlStartFrm <= #Tp 1'b0;
5324
  else
5325
  if(WillSendControlFrame & ~TxUsedDataOut & (TxDoneIn | TxAbortIn | TxStartFrmIn | (~TxUsedDataOutDetected)))
5326
    TxCtrlStartFrm <= #Tp 1'b1;
5327
end
5328
 
5329
 
5330
 
5331
// Generation of the transmit control packet end frame
5332
always @ (posedge MTxClk or posedge TxReset)
5333
begin
5334
  if(TxReset)
5335
    TxCtrlEndFrm <= #Tp 1'b0;
5336
  else
5337
  if(ControlEnd | ControlEnd_q)
5338
    TxCtrlEndFrm <= #Tp 1'b1;
5339
  else
5340
    TxCtrlEndFrm <= #Tp 1'b0;
5341
end
5342
 
5343
 
5344
// Generation of the multiplexer signal (controls muxes for switching between
5345
// normal and control packets)
5346
always @ (posedge MTxClk or posedge TxReset)
5347
begin
5348
  if(TxReset)
5349
    CtrlMux <= #Tp 1'b0;
5350
  else
5351
  if(WillSendControlFrame & ~TxUsedDataOut)
5352
    CtrlMux <= #Tp 1'b1;
5353
  else
5354
  if(TxDoneIn)
5355
    CtrlMux <= #Tp 1'b0;
5356
end
5357
 
5358
 
5359
 
5360
// Generation of the Sending Control Frame signal (enables padding and CRC)
5361
always @ (posedge MTxClk or posedge TxReset)
5362
begin
5363
  if(TxReset)
5364
    SendingCtrlFrm <= #Tp 1'b0;
5365
  else
5366
  if(WillSendControlFrame & TxCtrlStartFrm)
5367
    SendingCtrlFrm <= #Tp 1'b1;
5368
  else
5369
  if(TxDoneIn)
5370
    SendingCtrlFrm <= #Tp 1'b0;
5371
end
5372
 
5373
 
5374
always @ (posedge MTxClk or posedge TxReset)
5375
begin
5376
  if(TxReset)
5377
    TxUsedDataIn_q <= #Tp 1'b0;
5378
  else
5379
    TxUsedDataIn_q <= #Tp TxUsedDataIn;
5380
end
5381
 
5382
 
5383
 
5384
// Generation of the signal that will block sending the Done signal to the eth_wishbone module
5385
// While sending the control frame
5386
always @ (posedge MTxClk or posedge TxReset)
5387
begin
5388
  if(TxReset)
5389
    BlockTxDone <= #Tp 1'b0;
5390
  else
5391
  if(TxCtrlStartFrm)
5392
    BlockTxDone <= #Tp 1'b1;
5393
  else
5394
  if(TxStartFrmIn)
5395
    BlockTxDone <= #Tp 1'b0;
5396
end
5397
 
5398
 
5399
always @ (posedge MTxClk)
5400
begin
5401
  ControlEnd_q     <= #Tp ControlEnd;
5402
  TxCtrlStartFrm_q <= #Tp TxCtrlStartFrm;
5403
end
5404
 
5405
 
5406
assign IncrementDlyCrcCnt = CtrlMux & TxUsedDataIn &  ~DlyCrcCnt[2];
5407
 
5408
 
5409
// Delayed CRC counter
5410
always @ (posedge MTxClk or posedge TxReset)
5411
begin
5412
  if(TxReset)
5413
    DlyCrcCnt <= #Tp 4'h0;
5414
  else
5415
  if(ResetByteCnt)
5416
    DlyCrcCnt <= #Tp 4'h0;
5417
  else
5418
  if(IncrementDlyCrcCnt)
5419
    DlyCrcCnt <= #Tp DlyCrcCnt + 1'b1;
5420
end
5421
 
5422
 
5423
assign ResetByteCnt = TxReset | (~TxCtrlStartFrm & (TxDoneIn | TxAbortIn));
5424
assign IncrementByteCnt = CtrlMux & (TxCtrlStartFrm & ~TxCtrlStartFrm_q & ~TxUsedDataIn | TxUsedDataIn & ~ControlEnd);
5425
assign IncrementByteCntBy2 = CtrlMux & TxCtrlStartFrm & (~TxCtrlStartFrm_q) & TxUsedDataIn;     // When TxUsedDataIn and CtrlMux are set at the same time
5426
 
5427
assign EnableCnt = (~DlyCrcEn | DlyCrcEn & (&DlyCrcCnt[1:0]));
5428
// Byte counter
5429
always @ (posedge MTxClk or posedge TxReset)
5430
begin
5431
  if(TxReset)
5432
    ByteCnt <= #Tp 6'h0;
5433
  else
5434
  if(ResetByteCnt)
5435
    ByteCnt <= #Tp 6'h0;
5436
  else
5437
  if(IncrementByteCntBy2 & EnableCnt)
5438
    ByteCnt <= #Tp (ByteCnt[5:0] ) + 2'h2;
5439
  else
5440
  if(IncrementByteCnt & EnableCnt)
5441
    ByteCnt <= #Tp (ByteCnt[5:0] ) + 1'b1;
5442
end
5443
 
5444
 
5445
assign ControlEnd = ByteCnt[5:0] == 6'h22;
5446
 
5447
 
5448
// Control data generation (goes to the TxEthMAC module)
5449
always @ (ByteCnt or DlyCrcEn or MAC or TxPauseTV or DlyCrcCnt)
5450
begin
5451
  case(ByteCnt)
5452
    6'h0:    if(~DlyCrcEn | DlyCrcEn & (&DlyCrcCnt[1:0]))
5453
               MuxedCtrlData[7:0] = 8'h01;                   // Reserved Multicast Address
5454
             else
5455
                                                         MuxedCtrlData[7:0] = 8'h0;
5456
    6'h2:      MuxedCtrlData[7:0] = 8'h80;
5457
    6'h4:      MuxedCtrlData[7:0] = 8'hC2;
5458
    6'h6:      MuxedCtrlData[7:0] = 8'h00;
5459
    6'h8:      MuxedCtrlData[7:0] = 8'h00;
5460
    6'hA:      MuxedCtrlData[7:0] = 8'h01;
5461
    6'hC:      MuxedCtrlData[7:0] = MAC[47:40];
5462
    6'hE:      MuxedCtrlData[7:0] = MAC[39:32];
5463
    6'h10:     MuxedCtrlData[7:0] = MAC[31:24];
5464
    6'h12:     MuxedCtrlData[7:0] = MAC[23:16];
5465
    6'h14:     MuxedCtrlData[7:0] = MAC[15:8];
5466
    6'h16:     MuxedCtrlData[7:0] = MAC[7:0];
5467
    6'h18:     MuxedCtrlData[7:0] = 8'h88;                   // Type/Length
5468
    6'h1A:     MuxedCtrlData[7:0] = 8'h08;
5469
    6'h1C:     MuxedCtrlData[7:0] = 8'h00;                   // Opcode
5470
    6'h1E:     MuxedCtrlData[7:0] = 8'h01;
5471
    6'h20:     MuxedCtrlData[7:0] = TxPauseTV[15:8];         // Pause timer value
5472
    6'h22:     MuxedCtrlData[7:0] = TxPauseTV[7:0];
5473
    default:   MuxedCtrlData[7:0] = 8'h0;
5474
  endcase
5475
end
5476
 
5477
 
5478
// Latched Control data
5479
always @ (posedge MTxClk or posedge TxReset)
5480
begin
5481
  if(TxReset)
5482
    ControlData[7:0] <= #Tp 8'h0;
5483
  else
5484
  if(~ByteCnt[0])
5485
    ControlData[7:0] <= #Tp MuxedCtrlData[7:0];
5486
end
5487
 
5488
 
5489
 
5490
endmodule
5491
//////////////////////////////////////////////////////////////////////
5492
////                                                              ////
5493
////  eth_txcounters.v                                            ////
5494
////                                                              ////
5495
////  This file is part of the Ethernet IP core project           ////
5496
////  http://www.opencores.org/projects/ethmac/                   ////
5497
////                                                              ////
5498
////  Author(s):                                                  ////
5499
////      - Igor Mohor (igorM@opencores.org)                      ////
5500
////      - Novan Hartadi (novan@vlsi.itb.ac.id)                  ////
5501
////      - Mahmud Galela (mgalela@vlsi.itb.ac.id)                ////
5502
////                                                              ////
5503
////  All additional information is avaliable in the Readme.txt   ////
5504
////  file.                                                       ////
5505
////                                                              ////
5506
//////////////////////////////////////////////////////////////////////
5507
////                                                              ////
5508
//// Copyright (C) 2001 Authors                                   ////
5509
////                                                              ////
5510
//// This source file may be used and distributed without         ////
5511
//// restriction provided that this copyright statement is not    ////
5512
//// removed from the file and that any derivative work contains  ////
5513
//// the original copyright notice and the associated disclaimer. ////
5514
////                                                              ////
5515
//// This source file is free software; you can redistribute it   ////
5516
//// and/or modify it under the terms of the GNU Lesser General   ////
5517
//// Public License as published by the Free Software Foundation; ////
5518
//// either version 2.1 of the License, or (at your option) any   ////
5519
//// later version.                                               ////
5520
////                                                              ////
5521
//// This source is distributed in the hope that it will be       ////
5522
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
5523
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
5524
//// PURPOSE.  See the GNU Lesser General Public License for more ////
5525
//// details.                                                     ////
5526
////                                                              ////
5527
//// You should have received a copy of the GNU Lesser General    ////
5528
//// Public License along with this source; if not, download it   ////
5529
//// from http://www.opencores.org/lgpl.shtml                     ////
5530
////                                                              ////
5531
//////////////////////////////////////////////////////////////////////
5532
//
5533
// CVS Revision History
5534
//
5535
// $Log: eth_txcounters.v,v $
5536
// Revision 1.6  2005/02/21 11:25:27  igorm
5537
// Delayed CRC fixed.
5538
//
5539
// Revision 1.5  2002/04/22 14:54:14  mohor
5540
// FCS should not be included in NibbleMinFl.
5541
//
5542
// Revision 1.4  2002/01/23 10:28:16  mohor
5543
// Link in the header changed.
5544
//
5545
// Revision 1.3  2001/10/19 08:43:51  mohor
5546
// eth_timescale.v changed to timescale.v This is done because of the
5547
// simulation of the few cores in a one joined project.
5548
//
5549
// Revision 1.2  2001/09/11 14:17:00  mohor
5550
// Few little NCSIM warnings fixed.
5551
//
5552
// Revision 1.1  2001/08/06 14:44:29  mohor
5553
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
5554
// Include files fixed to contain no path.
5555
// File names and module names changed ta have a eth_ prologue in the name.
5556
// File eth_timescale.v is used to define timescale
5557
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
5558
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
5559
// and Mdo_OE. The bidirectional signal must be created on the top level. This
5560
// is done due to the ASIC tools.
5561
//
5562
// Revision 1.1  2001/07/30 21:23:42  mohor
5563
// Directory structure changed. Files checked and joind together.
5564
//
5565
// Revision 1.4  2001/06/27 21:27:45  mohor
5566
// Few typos fixed.
5567
//
5568
// Revision 1.2  2001/06/19 10:38:07  mohor
5569
// Minor changes in header.
5570
//
5571
// Revision 1.1  2001/06/19 10:27:57  mohor
5572
// TxEthMAC initial release.
5573
//
5574
//
5575
//
5576
 
5577
 
5578
`include "timescale.v"
5579
 
5580
 
5581
module eth_txcounters (StatePreamble, StateIPG, StateData, StatePAD, StateFCS, StateJam,
5582
                       StateBackOff, StateDefer, StateIdle, StartDefer, StartIPG, StartFCS,
5583
                       StartJam, StartBackoff, TxStartFrm, MTxClk, Reset, MinFL, MaxFL, HugEn,
5584
                       ExDfrEn, PacketFinished_q, DlyCrcEn, StateSFD, ByteCnt, NibCnt,
5585
                       ExcessiveDefer, NibCntEq7, NibCntEq15, MaxFrame, NibbleMinFl, DlyCrcCnt
5586
                      );
5587
 
5588
parameter Tp = 1;
5589
 
5590
input MTxClk;             // Tx clock
5591
input Reset;              // Reset
5592
input StatePreamble;      // Preamble state
5593
input StateIPG;           // IPG state
5594
input [1:0] StateData;    // Data state
5595
input StatePAD;           // PAD state
5596
input StateFCS;           // FCS state
5597
input StateJam;           // Jam state
5598
input StateBackOff;       // Backoff state
5599
input StateDefer;         // Defer state
5600
input StateIdle;          // Idle state
5601
input StateSFD;           // SFD state
5602
input StartDefer;         // Defer state will be activated in next clock
5603
input StartIPG;           // IPG state will be activated in next clock
5604
input StartFCS;           // FCS state will be activated in next clock
5605
input StartJam;           // Jam state will be activated in next clock
5606
input StartBackoff;       // Backoff state will be activated in next clock
5607
input TxStartFrm;         // Tx start frame
5608
input [15:0] MinFL;       // Minimum frame length (in bytes)
5609
input [15:0] MaxFL;       // Miximum frame length (in bytes)
5610
input HugEn;              // Pakets bigger then MaxFL enabled
5611
input ExDfrEn;            // Excessive deferral enabled
5612
input PacketFinished_q;
5613
input DlyCrcEn;           // Delayed CRC enabled
5614
 
5615
output [15:0] ByteCnt;    // Byte counter
5616
output [15:0] NibCnt;     // Nibble counter
5617
output ExcessiveDefer;    // Excessive Deferral occuring
5618
output NibCntEq7;         // Nibble counter is equal to 7
5619
output NibCntEq15;        // Nibble counter is equal to 15
5620
output MaxFrame;          // Maximum frame occured
5621
output NibbleMinFl;       // Nibble counter is greater than the minimum frame length
5622
output [2:0] DlyCrcCnt;   // Delayed CRC Count
5623
 
5624
wire ExcessiveDeferCnt;
5625
wire ResetNibCnt;
5626
wire IncrementNibCnt;
5627
wire ResetByteCnt;
5628
wire IncrementByteCnt;
5629
wire ByteCntMax;
5630
 
5631
reg [15:0] NibCnt;
5632
reg [15:0] ByteCnt;
5633
reg  [2:0] DlyCrcCnt;
5634
 
5635
 
5636
 
5637
assign IncrementNibCnt = StateIPG | StatePreamble | (|StateData) | StatePAD
5638
                       | StateFCS | StateJam | StateBackOff | StateDefer & ~ExcessiveDefer & TxStartFrm;
5639
 
5640
 
5641
assign ResetNibCnt = StateDefer & ExcessiveDefer & ~TxStartFrm | StatePreamble & NibCntEq15
5642
                   | StateJam & NibCntEq7 | StateIdle | StartDefer | StartIPG | StartFCS | StartJam;
5643
 
5644
// Nibble Counter
5645
always @ (posedge MTxClk or posedge Reset)
5646
begin
5647
  if(Reset)
5648
    NibCnt <= #Tp 16'h0;
5649
  else
5650
    begin
5651
      if(ResetNibCnt)
5652
        NibCnt <= #Tp 16'h0;
5653
      else
5654
      if(IncrementNibCnt)
5655
        NibCnt <= #Tp NibCnt + 1'b1;
5656
     end
5657
end
5658
 
5659
 
5660
assign NibCntEq7   = &NibCnt[2:0];
5661
assign NibCntEq15  = &NibCnt[3:0];
5662
 
5663
assign NibbleMinFl = NibCnt >= (((MinFL-3'h4)<<1) -1);  // FCS should not be included in NibbleMinFl
5664
 
5665
assign ExcessiveDeferCnt = NibCnt[13:0] == 16'h17b7;
5666
 
5667
assign ExcessiveDefer  = NibCnt[13:0] == 16'h17b7 & ~ExDfrEn;   // 6071 nibbles
5668
 
5669
assign IncrementByteCnt = StateData[1] & ~ByteCntMax
5670
                        | StateBackOff & (&NibCnt[6:0])
5671
                        | (StatePAD | StateFCS) & NibCnt[0] & ~ByteCntMax;
5672
 
5673
assign ResetByteCnt = StartBackoff | StateIdle & TxStartFrm | PacketFinished_q;
5674
 
5675
 
5676
// Transmit Byte Counter
5677
always @ (posedge MTxClk or posedge Reset)
5678
begin
5679
  if(Reset)
5680
    ByteCnt[15:0] <= #Tp 16'h0;
5681
  else
5682
    begin
5683
      if(ResetByteCnt)
5684
        ByteCnt[15:0] <= #Tp 16'h0;
5685
      else
5686
      if(IncrementByteCnt)
5687
        ByteCnt[15:0] <= #Tp ByteCnt[15:0] + 1'b1;
5688
    end
5689
end
5690
 
5691
 
5692
assign MaxFrame = ByteCnt[15:0] == MaxFL[15:0] & ~HugEn;
5693
 
5694
assign ByteCntMax = &ByteCnt[15:0];
5695
 
5696
 
5697
// Delayed CRC counter
5698
always @ (posedge MTxClk or posedge Reset)
5699
begin
5700
  if(Reset)
5701
    DlyCrcCnt <= #Tp 3'h0;
5702
  else
5703
    begin
5704
      if(StateData[1] & DlyCrcCnt == 3'h4 | StartJam | PacketFinished_q)
5705
        DlyCrcCnt <= #Tp 3'h0;
5706
      else
5707
      if(DlyCrcEn & (StateSFD | StateData[1] & (|DlyCrcCnt[2:0])))
5708
        DlyCrcCnt <= #Tp DlyCrcCnt + 1'b1;
5709
    end
5710
end
5711
 
5712
 
5713
 
5714
endmodule
5715
//////////////////////////////////////////////////////////////////////
5716
////                                                              ////
5717
////  eth_txethmac.v                                              ////
5718
///                                                              ////
5719
////  This file is part of the Ethernet IP core project           ////
5720
////  http://www.opencores.org/projects/ethmac/                   ////
5721
////                                                              ////
5722
////  Author(s):                                                  ////
5723
////      - Igor Mohor (igorM@opencores.org)                      ////
5724
////      - Novan Hartadi (novan@vlsi.itb.ac.id)                  ////
5725
////      - Mahmud Galela (mgalela@vlsi.itb.ac.id)                ////
5726
////                                                              ////
5727
////  All additional information is avaliable in the Readme.txt   ////
5728
////  file.                                                       ////
5729
////                                                              ////
5730
//////////////////////////////////////////////////////////////////////
5731
////                                                              ////
5732
//// Copyright (C) 2001 Authors                                   ////
5733
////                                                              ////
5734
//// This source file may be used and distributed without         ////
5735
//// restriction provided that this copyright statement is not    ////
5736
//// removed from the file and that any derivative work contains  ////
5737
//// the original copyright notice and the associated disclaimer. ////
5738
////                                                              ////
5739
//// This source file is free software; you can redistribute it   ////
5740
//// and/or modify it under the terms of the GNU Lesser General   ////
5741
//// Public License as published by the Free Software Foundation; ////
5742
//// either version 2.1 of the License, or (at your option) any   ////
5743
//// later version.                                               ////
5744
////                                                              ////
5745
//// This source is distributed in the hope that it will be       ////
5746
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
5747
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
5748
//// PURPOSE.  See the GNU Lesser General Public License for more ////
5749
//// details.                                                     ////
5750
////                                                              ////
5751
//// You should have received a copy of the GNU Lesser General    ////
5752
//// Public License along with this source; if not, download it   ////
5753
//// from http://www.opencores.org/lgpl.shtml                     ////
5754
////                                                              ////
5755
//////////////////////////////////////////////////////////////////////
5756
//
5757
// CVS Revision History
5758
//
5759
// $Log: eth_txethmac.v,v $
5760
// Revision 1.9  2005/02/21 11:25:28  igorm
5761
// Delayed CRC fixed.
5762
//
5763
// Revision 1.8  2003/01/30 13:33:24  mohor
5764
// When padding was enabled and crc disabled, frame was not ended correctly.
5765
//
5766
// Revision 1.7  2002/02/26 16:24:01  mohor
5767
// RetryCntLatched was unused and removed from design
5768
//
5769
// Revision 1.6  2002/02/22 12:56:35  mohor
5770
// Retry is not activated when a Tx Underrun occured
5771
//
5772
// Revision 1.5  2002/02/11 09:18:22  mohor
5773
// Tx status is written back to the BD.
5774
//
5775
// Revision 1.4  2002/01/23 10:28:16  mohor
5776
// Link in the header changed.
5777
//
5778
// Revision 1.3  2001/10/19 08:43:51  mohor
5779
// eth_timescale.v changed to timescale.v This is done because of the
5780
// simulation of the few cores in a one joined project.
5781
//
5782
// Revision 1.2  2001/09/11 14:17:00  mohor
5783
// Few little NCSIM warnings fixed.
5784
//
5785
// Revision 1.1  2001/08/06 14:44:29  mohor
5786
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
5787
// Include files fixed to contain no path.
5788
// File names and module names changed ta have a eth_ prologue in the name.
5789
// File eth_timescale.v is used to define timescale
5790
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
5791
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
5792
// and Mdo_OE. The bidirectional signal must be created on the top level. This
5793
// is done due to the ASIC tools.
5794
//
5795
// Revision 1.1  2001/07/30 21:23:42  mohor
5796
// Directory structure changed. Files checked and joind together.
5797
//
5798
// Revision 1.3  2001/06/19 18:16:40  mohor
5799
// TxClk changed to MTxClk (as discribed in the documentation).
5800
// Crc changed so only one file can be used instead of two.
5801
//
5802
// Revision 1.2  2001/06/19 10:38:08  mohor
5803
// Minor changes in header.
5804
//
5805
// Revision 1.1  2001/06/19 10:27:58  mohor
5806
// TxEthMAC initial release.
5807
//
5808
//
5809
//
5810
 
5811
`include "timescale.v"
5812
 
5813
 
5814
module eth_txethmac (MTxClk, Reset, TxStartFrm, TxEndFrm, TxUnderRun, TxData, CarrierSense,
5815
                     Collision, Pad, CrcEn, FullD, HugEn, DlyCrcEn, MinFL, MaxFL, IPGT,
5816
                     IPGR1, IPGR2, CollValid, MaxRet, NoBckof, ExDfrEn,
5817
                     MTxD, MTxEn, MTxErr, TxDone, TxRetry, TxAbort, TxUsedData, WillTransmit,
5818
                     ResetCollision, RetryCnt, StartTxDone, StartTxAbort, MaxCollisionOccured,
5819
                     LateCollision, DeferIndication, StatePreamble, StateData
5820
 
5821
                    );
5822
 
5823
parameter Tp = 1;
5824
 
5825
 
5826
input MTxClk;                   // Transmit clock (from PHY)
5827
input Reset;                    // Reset
5828
input TxStartFrm;               // Transmit packet start frame
5829
input TxEndFrm;                 // Transmit packet end frame
5830
input TxUnderRun;               // Transmit packet under-run
5831
input [7:0] TxData;             // Transmit packet data byte
5832
input CarrierSense;             // Carrier sense (synchronized)
5833
input Collision;                // Collision (synchronized)
5834
input Pad;                      // Pad enable (from register)
5835
input CrcEn;                    // Crc enable (from register)
5836
input FullD;                    // Full duplex (from register)
5837
input HugEn;                    // Huge packets enable (from register)
5838
input DlyCrcEn;                 // Delayed Crc enabled (from register)
5839
input [15:0] MinFL;             // Minimum frame length (from register)
5840
input [15:0] MaxFL;             // Maximum frame length (from register)
5841
input [6:0] IPGT;               // Back to back transmit inter packet gap parameter (from register)
5842
input [6:0] IPGR1;              // Non back to back transmit inter packet gap parameter IPGR1 (from register)
5843
input [6:0] IPGR2;              // Non back to back transmit inter packet gap parameter IPGR2 (from register)
5844
input [5:0] CollValid;          // Valid collision window (from register)
5845
input [3:0] MaxRet;             // Maximum retry number (from register)
5846
input NoBckof;                  // No backoff (from register)
5847
input ExDfrEn;                  // Excessive defferal enable (from register)
5848
 
5849
output [3:0] MTxD;              // Transmit nibble (to PHY)
5850
output MTxEn;                   // Transmit enable (to PHY)
5851
output MTxErr;                  // Transmit error (to PHY)
5852
output TxDone;                  // Transmit packet done (to RISC)
5853
output TxRetry;                 // Transmit packet retry (to RISC)
5854
output TxAbort;                 // Transmit packet abort (to RISC)
5855
output TxUsedData;              // Transmit packet used data (to RISC)
5856
output WillTransmit;            // Will transmit (to RxEthMAC)
5857
output ResetCollision;          // Reset Collision (for synchronizing collision)
5858
output [3:0] RetryCnt;          // Latched Retry Counter for tx status purposes
5859
output StartTxDone;
5860
output StartTxAbort;
5861
output MaxCollisionOccured;
5862
output LateCollision;
5863
output DeferIndication;
5864
output StatePreamble;
5865
output [1:0] StateData;
5866
 
5867
reg [3:0] MTxD;
5868
reg MTxEn;
5869
reg MTxErr;
5870
reg TxDone;
5871
reg TxRetry;
5872
reg TxAbort;
5873
reg TxUsedData;
5874
reg WillTransmit;
5875
reg ColWindow;
5876
reg StopExcessiveDeferOccured;
5877
reg [3:0] RetryCnt;
5878
reg [3:0] MTxD_d;
5879
reg StatusLatch;
5880
reg PacketFinished_q;
5881
reg PacketFinished;
5882
 
5883
 
5884
wire ExcessiveDeferOccured;
5885
wire StartIPG;
5886
wire StartPreamble;
5887
wire [1:0] StartData;
5888
wire StartFCS;
5889
wire StartJam;
5890
wire StartDefer;
5891
wire StartBackoff;
5892
wire StateDefer;
5893
wire StateIPG;
5894
wire StateIdle;
5895
wire StatePAD;
5896
wire StateFCS;
5897
wire StateJam;
5898
wire StateJam_q;
5899
wire StateBackOff;
5900
wire StateSFD;
5901
wire StartTxRetry;
5902
wire UnderRun;
5903
wire TooBig;
5904
wire [31:0] Crc;
5905
wire CrcError;
5906
wire [2:0] DlyCrcCnt;
5907
wire [15:0] NibCnt;
5908
wire NibCntEq7;
5909
wire NibCntEq15;
5910
wire NibbleMinFl;
5911
wire ExcessiveDefer;
5912
wire [15:0] ByteCnt;
5913
wire MaxFrame;
5914
wire RetryMax;
5915
wire RandomEq0;
5916
wire RandomEqByteCnt;
5917
wire PacketFinished_d;
5918
 
5919
 
5920
 
5921
assign ResetCollision = ~(StatePreamble | (|StateData) | StatePAD | StateFCS);
5922
 
5923
assign ExcessiveDeferOccured = TxStartFrm & StateDefer & ExcessiveDefer & ~StopExcessiveDeferOccured;
5924
 
5925
assign StartTxDone = ~Collision & (StateFCS & NibCntEq7 | StateData[1] & TxEndFrm & (~Pad | Pad & NibbleMinFl) & ~CrcEn);
5926
 
5927
assign UnderRun = StateData[0] & TxUnderRun & ~Collision;
5928
 
5929
assign TooBig = ~Collision & MaxFrame & (StateData[0] & ~TxUnderRun | StateFCS);
5930
 
5931
// assign StartTxRetry = StartJam & (ColWindow & ~RetryMax);
5932
assign StartTxRetry = StartJam & (ColWindow & ~RetryMax) & ~UnderRun;
5933
 
5934
assign LateCollision = StartJam & ~ColWindow & ~UnderRun;
5935
 
5936
assign MaxCollisionOccured = StartJam & ColWindow & RetryMax;
5937
 
5938
assign StateSFD = StatePreamble & NibCntEq15;
5939
 
5940
assign StartTxAbort = TooBig | UnderRun | ExcessiveDeferOccured | LateCollision | MaxCollisionOccured;
5941
 
5942
 
5943
// StopExcessiveDeferOccured
5944
always @ (posedge MTxClk or posedge Reset)
5945
begin
5946
  if(Reset)
5947
    StopExcessiveDeferOccured <= #Tp 1'b0;
5948
  else
5949
    begin
5950
      if(~TxStartFrm)
5951
        StopExcessiveDeferOccured <= #Tp 1'b0;
5952
      else
5953
      if(ExcessiveDeferOccured)
5954
        StopExcessiveDeferOccured <= #Tp 1'b1;
5955
    end
5956
end
5957
 
5958
 
5959
// Collision Window
5960
always @ (posedge MTxClk or posedge Reset)
5961
begin
5962
  if(Reset)
5963
    ColWindow <= #Tp 1'b1;
5964
  else
5965
    begin
5966
      if(~Collision & ByteCnt[5:0] == CollValid[5:0] & (StateData[1] | StatePAD & NibCnt[0] | StateFCS & NibCnt[0]))
5967
        ColWindow <= #Tp 1'b0;
5968
      else
5969
      if(StateIdle | StateIPG)
5970
        ColWindow <= #Tp 1'b1;
5971
    end
5972
end
5973
 
5974
 
5975
// Start Window
5976
always @ (posedge MTxClk or posedge Reset)
5977
begin
5978
  if(Reset)
5979
    StatusLatch <= #Tp 1'b0;
5980
  else
5981
    begin
5982
      if(~TxStartFrm)
5983
        StatusLatch <= #Tp 1'b0;
5984
      else
5985
      if(ExcessiveDeferOccured | StateIdle)
5986
        StatusLatch <= #Tp 1'b1;
5987
     end
5988
end
5989
 
5990
 
5991
// Transmit packet used data
5992
always @ (posedge MTxClk or posedge Reset)
5993
begin
5994
  if(Reset)
5995
    TxUsedData <= #Tp 1'b0;
5996
  else
5997
    TxUsedData <= #Tp |StartData;
5998
end
5999
 
6000
 
6001
// Transmit packet done
6002
always @ (posedge MTxClk or posedge Reset)
6003
begin
6004
  if(Reset)
6005
    TxDone <= #Tp 1'b0;
6006
  else
6007
    begin
6008
      if(TxStartFrm & ~StatusLatch)
6009
        TxDone <= #Tp 1'b0;
6010
      else
6011
      if(StartTxDone)
6012
        TxDone <= #Tp 1'b1;
6013
    end
6014
end
6015
 
6016
 
6017
// Transmit packet retry
6018
always @ (posedge MTxClk or posedge Reset)
6019
begin
6020
  if(Reset)
6021
    TxRetry <= #Tp 1'b0;
6022
  else
6023
    begin
6024
      if(TxStartFrm & ~StatusLatch)
6025
        TxRetry <= #Tp 1'b0;
6026
      else
6027
      if(StartTxRetry)
6028
        TxRetry <= #Tp 1'b1;
6029
     end
6030
end
6031
 
6032
 
6033
// Transmit packet abort
6034
always @ (posedge MTxClk or posedge Reset)
6035
begin
6036
  if(Reset)
6037
    TxAbort <= #Tp 1'b0;
6038
  else
6039
    begin
6040
      if(TxStartFrm & ~StatusLatch & ~ExcessiveDeferOccured)
6041
        TxAbort <= #Tp 1'b0;
6042
      else
6043
      if(StartTxAbort)
6044
        TxAbort <= #Tp 1'b1;
6045
    end
6046
end
6047
 
6048
 
6049
// Retry counter
6050
always @ (posedge MTxClk or posedge Reset)
6051
begin
6052
  if(Reset)
6053
    RetryCnt[3:0] <= #Tp 4'h0;
6054
  else
6055
    begin
6056
      if(ExcessiveDeferOccured | UnderRun | TooBig | StartTxDone | TxUnderRun
6057
          | StateJam & NibCntEq7 & (~ColWindow | RetryMax))
6058
        RetryCnt[3:0] <= #Tp 4'h0;
6059
      else
6060
      if(StateJam & NibCntEq7 & ColWindow & (RandomEq0 | NoBckof) | StateBackOff & RandomEqByteCnt)
6061
        RetryCnt[3:0] <= #Tp RetryCnt[3:0] + 1'b1;
6062
    end
6063
end
6064
 
6065
 
6066
assign RetryMax = RetryCnt[3:0] == MaxRet[3:0];
6067
 
6068
 
6069
// Transmit nibble
6070
always @ (StatePreamble or StateData or StateData or StateFCS or StateJam or StateSFD or TxData or
6071
          Crc or NibCntEq15)
6072
begin
6073
  if(StateData[0])
6074
    MTxD_d[3:0] = TxData[3:0];                                  // Lower nibble
6075
  else
6076
  if(StateData[1])
6077
    MTxD_d[3:0] = TxData[7:4];                                  // Higher nibble
6078
  else
6079
  if(StateFCS)
6080
    MTxD_d[3:0] = {~Crc[28], ~Crc[29], ~Crc[30], ~Crc[31]};     // Crc
6081
  else
6082
  if(StateJam)
6083
    MTxD_d[3:0] = 4'h9;                                         // Jam pattern
6084
  else
6085
  if(StatePreamble)
6086
    if(NibCntEq15)
6087
      MTxD_d[3:0] = 4'hd;                                       // SFD
6088
    else
6089
      MTxD_d[3:0] = 4'h5;                                       // Preamble
6090
  else
6091
    MTxD_d[3:0] = 4'h0;
6092
end
6093
 
6094
 
6095
// Transmit Enable
6096
always @ (posedge MTxClk or posedge Reset)
6097
begin
6098
  if(Reset)
6099
    MTxEn <= #Tp 1'b0;
6100
  else
6101
    MTxEn <= #Tp StatePreamble | (|StateData) | StatePAD | StateFCS | StateJam;
6102
end
6103
 
6104
 
6105
// Transmit nibble
6106
always @ (posedge MTxClk or posedge Reset)
6107
begin
6108
  if(Reset)
6109
    MTxD[3:0] <= #Tp 4'h0;
6110
  else
6111
    MTxD[3:0] <= #Tp MTxD_d[3:0];
6112
end
6113
 
6114
 
6115
// Transmit error
6116
always @ (posedge MTxClk or posedge Reset)
6117
begin
6118
  if(Reset)
6119
    MTxErr <= #Tp 1'b0;
6120
  else
6121
    MTxErr <= #Tp TooBig | UnderRun;
6122
end
6123
 
6124
 
6125
// WillTransmit
6126
always @ (posedge MTxClk or posedge Reset)
6127
begin
6128
  if(Reset)
6129
    WillTransmit <= #Tp  1'b0;
6130
  else
6131
    WillTransmit <= #Tp StartPreamble | StatePreamble | (|StateData) | StatePAD | StateFCS | StateJam;
6132
end
6133
 
6134
 
6135
assign PacketFinished_d = StartTxDone | TooBig | UnderRun | LateCollision | MaxCollisionOccured | ExcessiveDeferOccured;
6136
 
6137
 
6138
// Packet finished
6139
always @ (posedge MTxClk or posedge Reset)
6140
begin
6141
  if(Reset)
6142
    begin
6143
      PacketFinished <= #Tp 1'b0;
6144
      PacketFinished_q  <= #Tp 1'b0;
6145
    end
6146
  else
6147
    begin
6148
      PacketFinished <= #Tp PacketFinished_d;
6149
      PacketFinished_q  <= #Tp PacketFinished;
6150
    end
6151
end
6152
 
6153
 
6154
// Connecting module Counters
6155
eth_txcounters txcounters1 (.StatePreamble(StatePreamble), .StateIPG(StateIPG), .StateData(StateData),
6156
                            .StatePAD(StatePAD), .StateFCS(StateFCS), .StateJam(StateJam), .StateBackOff(StateBackOff),
6157
                            .StateDefer(StateDefer), .StateIdle(StateIdle), .StartDefer(StartDefer), .StartIPG(StartIPG),
6158
                            .StartFCS(StartFCS), .StartJam(StartJam), .TxStartFrm(TxStartFrm), .MTxClk(MTxClk),
6159
                            .Reset(Reset), .MinFL(MinFL), .MaxFL(MaxFL), .HugEn(HugEn), .ExDfrEn(ExDfrEn),
6160
                            .PacketFinished_q(PacketFinished_q), .DlyCrcEn(DlyCrcEn), .StartBackoff(StartBackoff),
6161
                            .StateSFD(StateSFD), .ByteCnt(ByteCnt), .NibCnt(NibCnt), .ExcessiveDefer(ExcessiveDefer),
6162
                            .NibCntEq7(NibCntEq7), .NibCntEq15(NibCntEq15), .MaxFrame(MaxFrame), .NibbleMinFl(NibbleMinFl),
6163
                            .DlyCrcCnt(DlyCrcCnt)
6164
                           );
6165
 
6166
 
6167
// Connecting module StateM
6168
eth_txstatem txstatem1 (.MTxClk(MTxClk), .Reset(Reset), .ExcessiveDefer(ExcessiveDefer), .CarrierSense(CarrierSense),
6169
                        .NibCnt(NibCnt[6:0]), .IPGT(IPGT), .IPGR1(IPGR1), .IPGR2(IPGR2), .FullD(FullD),
6170
                        .TxStartFrm(TxStartFrm), .TxEndFrm(TxEndFrm), .TxUnderRun(TxUnderRun), .Collision(Collision),
6171
                        .UnderRun(UnderRun), .StartTxDone(StartTxDone), .TooBig(TooBig), .NibCntEq7(NibCntEq7),
6172
                        .NibCntEq15(NibCntEq15), .MaxFrame(MaxFrame), .Pad(Pad), .CrcEn(CrcEn),
6173
                        .NibbleMinFl(NibbleMinFl), .RandomEq0(RandomEq0), .ColWindow(ColWindow), .RetryMax(RetryMax),
6174
                        .NoBckof(NoBckof), .RandomEqByteCnt(RandomEqByteCnt), .StateIdle(StateIdle),
6175
                        .StateIPG(StateIPG), .StatePreamble(StatePreamble), .StateData(StateData), .StatePAD(StatePAD),
6176
                        .StateFCS(StateFCS), .StateJam(StateJam), .StateJam_q(StateJam_q), .StateBackOff(StateBackOff),
6177
                        .StateDefer(StateDefer), .StartFCS(StartFCS), .StartJam(StartJam), .StartBackoff(StartBackoff),
6178
                        .StartDefer(StartDefer), .DeferIndication(DeferIndication), .StartPreamble(StartPreamble), .StartData(StartData), .StartIPG(StartIPG)
6179
                       );
6180
 
6181
 
6182
wire Enable_Crc;
6183
wire [3:0] Data_Crc;
6184
wire Initialize_Crc;
6185
 
6186
assign Enable_Crc = ~StateFCS;
6187
 
6188
assign Data_Crc[0] = StateData[0]? TxData[3] : StateData[1]? TxData[7] : 1'b0;
6189
assign Data_Crc[1] = StateData[0]? TxData[2] : StateData[1]? TxData[6] : 1'b0;
6190
assign Data_Crc[2] = StateData[0]? TxData[1] : StateData[1]? TxData[5] : 1'b0;
6191
assign Data_Crc[3] = StateData[0]? TxData[0] : StateData[1]? TxData[4] : 1'b0;
6192
 
6193
assign Initialize_Crc = StateIdle | StatePreamble | (|DlyCrcCnt);
6194
 
6195
 
6196
// Connecting module Crc
6197
eth_crc txcrc (.Clk(MTxClk), .Reset(Reset), .Data(Data_Crc), .Enable(Enable_Crc), .Initialize(Initialize_Crc),
6198
               .Crc(Crc), .CrcError(CrcError)
6199
              );
6200
 
6201
 
6202
// Connecting module Random
6203
eth_random random1 (.MTxClk(MTxClk), .Reset(Reset), .StateJam(StateJam), .StateJam_q(StateJam_q), .RetryCnt(RetryCnt),
6204
                    .NibCnt(NibCnt), .ByteCnt(ByteCnt[9:0]), .RandomEq0(RandomEq0), .RandomEqByteCnt(RandomEqByteCnt));
6205
 
6206
 
6207
 
6208
 
6209
endmodule
6210
//////////////////////////////////////////////////////////////////////
6211
////                                                              ////
6212
////  eth_txstatem.v                                              ////
6213
////                                                              ////
6214
////  This file is part of the Ethernet IP core project           ////
6215
////  http://www.opencores.org/projects/ethmac/                   ////
6216
////                                                              ////
6217
////  Author(s):                                                  ////
6218
////      - Igor Mohor (igorM@opencores.org)                      ////
6219
////      - Novan Hartadi (novan@vlsi.itb.ac.id)                  ////
6220
////      - Mahmud Galela (mgalela@vlsi.itb.ac.id)                ////
6221
////                                                              ////
6222
////  All additional information is avaliable in the Readme.txt   ////
6223
////  file.                                                       ////
6224
////                                                              ////
6225
//////////////////////////////////////////////////////////////////////
6226
////                                                              ////
6227
//// Copyright (C) 2001 Authors                                   ////
6228
////                                                              ////
6229
//// This source file may be used and distributed without         ////
6230
//// restriction provided that this copyright statement is not    ////
6231
//// removed from the file and that any derivative work contains  ////
6232
//// the original copyright notice and the associated disclaimer. ////
6233
////                                                              ////
6234
//// This source file is free software; you can redistribute it   ////
6235
//// and/or modify it under the terms of the GNU Lesser General   ////
6236
//// Public License as published by the Free Software Foundation; ////
6237
//// either version 2.1 of the License, or (at your option) any   ////
6238
//// later version.                                               ////
6239
////                                                              ////
6240
//// This source is distributed in the hope that it will be       ////
6241
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
6242
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
6243
//// PURPOSE.  See the GNU Lesser General Public License for more ////
6244
//// details.                                                     ////
6245
////                                                              ////
6246
//// You should have received a copy of the GNU Lesser General    ////
6247
//// Public License along with this source; if not, download it   ////
6248
//// from http://www.opencores.org/lgpl.shtml                     ////
6249
////                                                              ////
6250
//////////////////////////////////////////////////////////////////////
6251
//
6252
// CVS Revision History
6253
//
6254
// $Log: eth_txstatem.v,v $
6255
// Revision 1.6  2003/01/30 13:29:08  tadejm
6256
// Defer indication changed.
6257
//
6258
// Revision 1.5  2002/10/30 12:54:50  mohor
6259
// State machine goes from idle to the defer state when CarrierSense is 1. FCS (CRC appending) fixed to check the CrcEn bit also when padding is necessery.
6260
//
6261
// Revision 1.4  2002/01/23 10:28:16  mohor
6262
// Link in the header changed.
6263
//
6264
// Revision 1.3  2001/10/19 08:43:51  mohor
6265
// eth_timescale.v changed to timescale.v This is done because of the
6266
// simulation of the few cores in a one joined project.
6267
//
6268
// Revision 1.2  2001/09/11 14:17:00  mohor
6269
// Few little NCSIM warnings fixed.
6270
//
6271
// Revision 1.1  2001/08/06 14:44:29  mohor
6272
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
6273
// Include files fixed to contain no path.
6274
// File names and module names changed ta have a eth_ prologue in the name.
6275
// File eth_timescale.v is used to define timescale
6276
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
6277
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
6278
// and Mdo_OE. The bidirectional signal must be created on the top level. This
6279
// is done due to the ASIC tools.
6280
//
6281
// Revision 1.1  2001/07/30 21:23:42  mohor
6282
// Directory structure changed. Files checked and joind together.
6283
//
6284
// Revision 1.3  2001/06/19 18:16:40  mohor
6285
// TxClk changed to MTxClk (as discribed in the documentation).
6286
// Crc changed so only one file can be used instead of two.
6287
//
6288
// Revision 1.2  2001/06/19 10:38:07  mohor
6289
// Minor changes in header.
6290
//
6291
// Revision 1.1  2001/06/19 10:27:57  mohor
6292
// TxEthMAC initial release.
6293
//
6294
//
6295
//
6296
//
6297
 
6298
 
6299
`include "timescale.v"
6300
 
6301
 
6302
module eth_txstatem  (MTxClk, Reset, ExcessiveDefer, CarrierSense, NibCnt, IPGT, IPGR1,
6303
                      IPGR2, FullD, TxStartFrm, TxEndFrm, TxUnderRun, Collision, UnderRun,
6304
                      StartTxDone, TooBig, NibCntEq7, NibCntEq15, MaxFrame, Pad, CrcEn,
6305
                      NibbleMinFl, RandomEq0, ColWindow, RetryMax, NoBckof, RandomEqByteCnt,
6306
                      StateIdle, StateIPG, StatePreamble, StateData, StatePAD, StateFCS,
6307
                      StateJam, StateJam_q, StateBackOff, StateDefer, StartFCS, StartJam,
6308
                      StartBackoff, StartDefer, DeferIndication, StartPreamble, StartData, StartIPG
6309
                     );
6310
 
6311
parameter Tp = 1;
6312
 
6313
input MTxClk;
6314
input Reset;
6315
input ExcessiveDefer;
6316
input CarrierSense;
6317
input [6:0] NibCnt;
6318
input [6:0] IPGT;
6319
input [6:0] IPGR1;
6320
input [6:0] IPGR2;
6321
input FullD;
6322
input TxStartFrm;
6323
input TxEndFrm;
6324
input TxUnderRun;
6325
input Collision;
6326
input UnderRun;
6327
input StartTxDone;
6328
input TooBig;
6329
input NibCntEq7;
6330
input NibCntEq15;
6331
input MaxFrame;
6332
input Pad;
6333
input CrcEn;
6334
input NibbleMinFl;
6335
input RandomEq0;
6336
input ColWindow;
6337
input RetryMax;
6338
input NoBckof;
6339
input RandomEqByteCnt;
6340
 
6341
 
6342
output StateIdle;         // Idle state
6343
output StateIPG;          // IPG state
6344
output StatePreamble;     // Preamble state
6345
output [1:0] StateData;   // Data state
6346
output StatePAD;          // PAD state
6347
output StateFCS;          // FCS state
6348
output StateJam;          // Jam state
6349
output StateJam_q;        // Delayed Jam state
6350
output StateBackOff;      // Backoff state
6351
output StateDefer;        // Defer state
6352
 
6353
output StartFCS;          // FCS state will be activated in next clock
6354
output StartJam;          // Jam state will be activated in next clock
6355
output StartBackoff;      // Backoff state will be activated in next clock
6356
output StartDefer;        // Defer state will be activated in next clock
6357
output DeferIndication;
6358
output StartPreamble;     // Preamble state will be activated in next clock
6359
output [1:0] StartData;   // Data state will be activated in next clock
6360
output StartIPG;          // IPG state will be activated in next clock
6361
 
6362
wire StartIdle;           // Idle state will be activated in next clock
6363
wire StartPAD;            // PAD state will be activated in next clock
6364
 
6365
 
6366
reg StateIdle;
6367
reg StateIPG;
6368
reg StatePreamble;
6369
reg [1:0] StateData;
6370
reg StatePAD;
6371
reg StateFCS;
6372
reg StateJam;
6373
reg StateJam_q;
6374
reg StateBackOff;
6375
reg StateDefer;
6376
reg Rule1;
6377
 
6378
 
6379
// Defining the next state
6380
assign StartIPG = StateDefer & ~ExcessiveDefer & ~CarrierSense;
6381
 
6382
assign StartIdle = StateIPG & (Rule1 & NibCnt[6:0] >= IPGT | ~Rule1 & NibCnt[6:0] >= IPGR2);
6383
 
6384
assign StartPreamble = StateIdle & TxStartFrm & ~CarrierSense;
6385
 
6386
assign StartData[0] = ~Collision & (StatePreamble & NibCntEq15 | StateData[1] & ~TxEndFrm);
6387
 
6388
assign StartData[1] = ~Collision & StateData[0] & ~TxUnderRun & ~MaxFrame;
6389
 
6390
assign StartPAD = ~Collision & StateData[1] & TxEndFrm & Pad & ~NibbleMinFl;
6391
 
6392
assign StartFCS = ~Collision & StateData[1] & TxEndFrm & (~Pad | Pad & NibbleMinFl) & CrcEn
6393
                | ~Collision & StatePAD & NibbleMinFl & CrcEn;
6394
 
6395
assign StartJam = (Collision | UnderRun) & ((StatePreamble & NibCntEq15) | (|StateData[1:0]) | StatePAD | StateFCS);
6396
 
6397
assign StartBackoff = StateJam & ~RandomEq0 & ColWindow & ~RetryMax & NibCntEq7 & ~NoBckof;
6398
 
6399
assign StartDefer = StateIPG & ~Rule1 & CarrierSense & NibCnt[6:0] <= IPGR1 & NibCnt[6:0] != IPGR2
6400
                  | StateIdle & CarrierSense
6401
                  | StateJam & NibCntEq7 & (NoBckof | RandomEq0 | ~ColWindow | RetryMax)
6402
                  | StateBackOff & (TxUnderRun | RandomEqByteCnt)
6403
                  | StartTxDone | TooBig;
6404
 
6405
assign DeferIndication = StateIdle & CarrierSense;
6406
 
6407
// Tx State Machine
6408
always @ (posedge MTxClk or posedge Reset)
6409
begin
6410
  if(Reset)
6411
    begin
6412
      StateIPG        <= #Tp 1'b0;
6413
      StateIdle       <= #Tp 1'b0;
6414
      StatePreamble   <= #Tp 1'b0;
6415
      StateData[1:0]  <= #Tp 2'b0;
6416
      StatePAD        <= #Tp 1'b0;
6417
      StateFCS        <= #Tp 1'b0;
6418
      StateJam        <= #Tp 1'b0;
6419
      StateJam_q      <= #Tp 1'b0;
6420
      StateBackOff    <= #Tp 1'b0;
6421
      StateDefer      <= #Tp 1'b1;
6422
    end
6423
  else
6424
    begin
6425
      StateData[1:0] <= #Tp StartData[1:0];
6426
      StateJam_q <= #Tp StateJam;
6427
 
6428
      if(StartDefer | StartIdle)
6429
        StateIPG <= #Tp 1'b0;
6430
      else
6431
      if(StartIPG)
6432
        StateIPG <= #Tp 1'b1;
6433
 
6434
      if(StartDefer | StartPreamble)
6435
        StateIdle <= #Tp 1'b0;
6436
      else
6437
      if(StartIdle)
6438
        StateIdle <= #Tp 1'b1;
6439
 
6440
      if(StartData[0] | StartJam)
6441
        StatePreamble <= #Tp 1'b0;
6442
      else
6443
      if(StartPreamble)
6444
        StatePreamble <= #Tp 1'b1;
6445
 
6446
      if(StartFCS | StartJam)
6447
        StatePAD <= #Tp 1'b0;
6448
      else
6449
      if(StartPAD)
6450
        StatePAD <= #Tp 1'b1;
6451
 
6452
      if(StartJam | StartDefer)
6453
        StateFCS <= #Tp 1'b0;
6454
      else
6455
      if(StartFCS)
6456
        StateFCS <= #Tp 1'b1;
6457
 
6458
      if(StartBackoff | StartDefer)
6459
        StateJam <= #Tp 1'b0;
6460
      else
6461
      if(StartJam)
6462
        StateJam <= #Tp 1'b1;
6463
 
6464
      if(StartDefer)
6465
        StateBackOff <= #Tp 1'b0;
6466
      else
6467
      if(StartBackoff)
6468
        StateBackOff <= #Tp 1'b1;
6469
 
6470
      if(StartIPG)
6471
        StateDefer <= #Tp 1'b0;
6472
      else
6473
      if(StartDefer)
6474
        StateDefer <= #Tp 1'b1;
6475
    end
6476
end
6477
 
6478
 
6479
// This sections defines which interpack gap rule to use
6480
always @ (posedge MTxClk or posedge Reset)
6481
begin
6482
  if(Reset)
6483
    Rule1 <= #Tp 1'b0;
6484
  else
6485
    begin
6486
      if(StateIdle | StateBackOff)
6487
        Rule1 <= #Tp 1'b0;
6488
      else
6489
      if(StatePreamble | FullD)
6490
        Rule1 <= #Tp 1'b1;
6491
    end
6492
end
6493
 
6494
 
6495
 
6496
endmodule
6497
//////////////////////////////////////////////////////////////////////
6498
////                                                              ////
6499
////  eth_wishbone.v                                              ////
6500
////                                                              ////
6501
////  This file is part of the Ethernet IP core project           ////
6502
////  http://www.opencores.org/projects/ethmac/                   ////
6503
////                                                              ////
6504
////  Author(s):                                                  ////
6505
////      - Igor Mohor (igorM@opencores.org)                      ////
6506
////                                                              ////
6507
////  All additional information is available in the Readme.txt   ////
6508
////  file.                                                       ////
6509
////                                                              ////
6510
//////////////////////////////////////////////////////////////////////
6511
////                                                              ////
6512
//// Copyright (C) 2001, 2002 Authors                             ////
6513
////                                                              ////
6514
//// This source file may be used and distributed without         ////
6515
//// restriction provided that this copyright statement is not    ////
6516
//// removed from the file and that any derivative work contains  ////
6517
//// the original copyright notice and the associated disclaimer. ////
6518
////                                                              ////
6519
//// This source file is free software; you can redistribute it   ////
6520
//// and/or modify it under the terms of the GNU Lesser General   ////
6521
//// Public License as published by the Free Software Foundation; ////
6522
//// either version 2.1 of the License, or (at your option) any   ////
6523
//// later version.                                               ////
6524
////                                                              ////
6525
//// This source is distributed in the hope that it will be       ////
6526
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
6527
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
6528
//// PURPOSE.  See the GNU Lesser General Public License for more ////
6529
//// details.                                                     ////
6530
////                                                              ////
6531
//// You should have received a copy of the GNU Lesser General    ////
6532
//// Public License along with this source; if not, download it   ////
6533
//// from http://www.opencores.org/lgpl.shtml                     ////
6534
////                                                              ////
6535
//////////////////////////////////////////////////////////////////////
6536
//
6537
// CVS Revision History
6538
//
6539
// $Log: eth_wishbone.v,v $
6540
// Revision 1.58  2005/03/21 20:07:18  igorm
6541
// Some small fixes + some troubles fixed.
6542
//
6543
// Revision 1.57  2005/02/21 11:35:33  igorm
6544
// Defer indication fixed.
6545
//
6546
// Revision 1.56  2004/04/30 10:30:00  igorm
6547
// Accidently deleted line put back.
6548
//
6549
// Revision 1.55  2004/04/26 15:26:23  igorm
6550
// - Bug connected to the TX_BD_NUM_Wr signal fixed (bug came in with the
6551
//   previous update of the core.
6552
// - TxBDAddress is set to 0 after the TX is enabled in the MODER register.
6553
// - RxBDAddress is set to r_TxBDNum<<1 after the RX is enabled in the MODER
6554
//   register. (thanks to Mathias and Torbjorn)
6555
// - Multicast reception was fixed. Thanks to Ulrich Gries
6556
//
6557
// Revision 1.54  2003/11/12 18:24:59  tadejm
6558
// WISHBONE slave changed and tested from only 32-bit accesss to byte access.
6559
//
6560
// Revision 1.53  2003/10/17 07:46:17  markom
6561
// mbist signals updated according to newest convention
6562
//
6563
// Revision 1.52  2003/01/30 14:51:31  mohor
6564
// Reset has priority in some flipflops.
6565
//
6566
// Revision 1.51  2003/01/30 13:36:22  mohor
6567
// A new bug (entered with previous update) fixed. When abort occured sometimes
6568
// data transmission was blocked.
6569
//
6570
// Revision 1.50  2003/01/22 13:49:26  tadejm
6571
// When control packets were received, they were ignored in some cases.
6572
//
6573
// Revision 1.49  2003/01/21 12:09:40  mohor
6574
// When receiving normal data frame and RxFlow control was switched on, RXB
6575
// interrupt was not set.
6576
//
6577
// Revision 1.48  2003/01/20 12:05:26  mohor
6578
// When in full duplex, transmit was sometimes blocked. Fixed.
6579
//
6580
// Revision 1.47  2002/11/22 13:26:21  mohor
6581
// Registers RxStatusWrite_rck and RxStatusWriteLatched were not used
6582
// anywhere. Removed.
6583
//
6584
// Revision 1.46  2002/11/22 01:57:06  mohor
6585
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
6586
// synchronized.
6587
//
6588
// Revision 1.45  2002/11/19 17:33:34  mohor
6589
// AddressMiss status is connecting to the Rx BD. AddressMiss is identifying
6590
// that a frame was received because of the promiscous mode.
6591
//
6592
// Revision 1.44  2002/11/13 22:21:40  tadejm
6593
// RxError is not generated when small frame reception is enabled and small
6594
// frames are received.
6595
//
6596
// Revision 1.43  2002/10/18 20:53:34  mohor
6597
// case changed to casex.
6598
//
6599
// Revision 1.42  2002/10/18 17:04:20  tadejm
6600
// Changed BIST scan signals.
6601
//
6602
// Revision 1.41  2002/10/18 15:42:09  tadejm
6603
// Igor added WB burst support and repaired BUG when handling TX under-run and retry.
6604
//
6605
// Revision 1.40  2002/10/14 16:07:02  mohor
6606
// TxStatus is written after last access to the TX fifo is finished (in case of abort
6607
// or retry). TxDone is fixed.
6608
//
6609
// Revision 1.39  2002/10/11 15:35:20  mohor
6610
// txfifo_cnt and rxfifo_cnt counters width is defined in the eth_define.v file,
6611
// TxDone and TxRetry are generated after the current WISHBONE access is
6612
// finished.
6613
//
6614
// Revision 1.38  2002/10/10 16:29:30  mohor
6615
// BIST added.
6616
//
6617
// Revision 1.37  2002/09/11 14:18:46  mohor
6618
// Sometimes both RxB_IRQ and RxE_IRQ were activated. Bug fixed.
6619
//
6620
// Revision 1.36  2002/09/10 13:48:46  mohor
6621
// Reception is possible after RxPointer is read and not after BD is read. For
6622
// that reason RxBDReady is changed to RxReady.
6623
// Busy_IRQ interrupt connected. When there is no RxBD ready and frame
6624
// comes, interrupt is generated.
6625
//
6626
// Revision 1.35  2002/09/10 10:35:23  mohor
6627
// Ethernet debug registers removed.
6628
//
6629
// Revision 1.34  2002/09/08 16:31:49  mohor
6630
// Async reset for WB_ACK_O removed (when core was in reset, it was
6631
// impossible to access BDs).
6632
// RxPointers and TxPointers names changed to be more descriptive.
6633
// TxUnderRun synchronized.
6634
//
6635
// Revision 1.33  2002/09/04 18:47:57  mohor
6636
// Debug registers reg1, 2, 3, 4 connected. Synchronization of many signals
6637
// changed (bugs fixed). Access to un-alligned buffers fixed. RxAbort signal
6638
// was not used OK.
6639
//
6640
// Revision 1.32  2002/08/14 19:31:48  mohor
6641
// Register TX_BD_NUM is changed so it contains value of the Tx buffer descriptors. No
6642
// need to multiply or devide any more.
6643
//
6644
// Revision 1.31  2002/07/25 18:29:01  mohor
6645
// WriteRxDataToMemory signal changed so end of frame (when last word is
6646
// written to fifo) is changed.
6647
//
6648
// Revision 1.30  2002/07/23 15:28:31  mohor
6649
// Ram , used for BDs changed from generic_spram to eth_spram_256x32.
6650
//
6651
// Revision 1.29  2002/07/20 00:41:32  mohor
6652
// ShiftEnded synchronization changed.
6653
//
6654
// Revision 1.28  2002/07/18 16:11:46  mohor
6655
// RxBDAddress takes `ETH_TX_BD_NUM_DEF value after reset.
6656
//
6657
// Revision 1.27  2002/07/11 02:53:20  mohor
6658
// RxPointer bug fixed.
6659
//
6660
// Revision 1.26  2002/07/10 13:12:38  mohor
6661
// Previous bug wasn't succesfully removed. Now fixed.
6662
//
6663
// Revision 1.25  2002/07/09 23:53:24  mohor
6664
// Master state machine had a bug when switching from master write to
6665
// master read.
6666
//
6667
// Revision 1.24  2002/07/09 20:44:41  mohor
6668
// m_wb_cyc_o signal released after every single transfer.
6669
//
6670
// Revision 1.23  2002/05/03 10:15:50  mohor
6671
// Outputs registered. Reset changed for eth_wishbone module.
6672
//
6673
// Revision 1.22  2002/04/24 08:52:19  mohor
6674
// Compiler directives added. Tx and Rx fifo size incremented. A "late collision"
6675
// bug fixed.
6676
//
6677
// Revision 1.21  2002/03/29 16:18:11  lampret
6678
// Small typo fixed.
6679
//
6680
// Revision 1.20  2002/03/25 16:19:12  mohor
6681
// Any address can be used for Tx and Rx BD pointers. Address does not need
6682
// to be aligned.
6683
//
6684
// Revision 1.19  2002/03/19 12:51:50  mohor
6685
// Comments in Slovene language removed.
6686
//
6687
// Revision 1.18  2002/03/19 12:46:52  mohor
6688
// casex changed with case, fifo reset changed.
6689
//
6690
// Revision 1.17  2002/03/09 16:08:45  mohor
6691
// rx_fifo was not always cleared ok. Fixed.
6692
//
6693
// Revision 1.16  2002/03/09 13:51:20  mohor
6694
// Status was not latched correctly sometimes. Fixed.
6695
//
6696
// Revision 1.15  2002/03/08 06:56:46  mohor
6697
// Big Endian problem when sending frames fixed.
6698
//
6699
// Revision 1.14  2002/03/02 19:12:40  mohor
6700
// Byte ordering changed (Big Endian used). casex changed with case because
6701
// Xilinx Foundation had problems. Tested in HW. It WORKS.
6702
//
6703
// Revision 1.13  2002/02/26 16:59:55  mohor
6704
// Small fixes for external/internal DMA missmatches.
6705
//
6706
// Revision 1.12  2002/02/26 16:22:07  mohor
6707
// Interrupts changed
6708
//
6709
// Revision 1.11  2002/02/15 17:07:39  mohor
6710
// Status was not written correctly when frames were discarted because of
6711
// address mismatch.
6712
//
6713
// Revision 1.10  2002/02/15 12:17:39  mohor
6714
// RxStartFrm cleared when abort or retry comes.
6715
//
6716
// Revision 1.9  2002/02/15 11:59:10  mohor
6717
// Changes that were lost when updating from 1.5 to 1.8 fixed.
6718
//
6719
// Revision 1.8  2002/02/14 20:54:33  billditt
6720
// Addition  of new module eth_addrcheck.v
6721
//
6722
// Revision 1.7  2002/02/12 17:03:47  mohor
6723
// RxOverRun added to statuses.
6724
//
6725
// Revision 1.6  2002/02/11 09:18:22  mohor
6726
// Tx status is written back to the BD.
6727
//
6728
// Revision 1.5  2002/02/08 16:21:54  mohor
6729
// Rx status is written back to the BD.
6730
//
6731
// Revision 1.4  2002/02/06 14:10:21  mohor
6732
// non-DMA host interface added. Select the right configutation in eth_defines.
6733
//
6734
// Revision 1.3  2002/02/05 16:44:39  mohor
6735
// Both rx and tx part are finished. Tested with wb_clk_i between 10 and 200
6736
// MHz. Statuses, overrun, control frame transmission and reception still  need
6737
// to be fixed.
6738
//
6739
// Revision 1.2  2002/02/01 12:46:51  mohor
6740
// Tx part finished. TxStatus needs to be fixed. Pause request needs to be
6741
// added.
6742
//
6743
// Revision 1.1  2002/01/23 10:47:59  mohor
6744
// Initial version. Equals to eth_wishbonedma.v at this moment.
6745
//
6746
//
6747
//
6748
 
6749
`include "eth_defines.v"
6750
`include "timescale.v"
6751
 
6752
 
6753
module eth_wishbone
6754
   (
6755
 
6756
    // WISHBONE common
6757
    WB_CLK_I, WB_DAT_I, WB_DAT_O,
6758
 
6759
    // WISHBONE slave
6760
                WB_ADR_I, WB_WE_I, WB_ACK_O,
6761
    BDCs,
6762
 
6763
    Reset,
6764
 
6765
    // WISHBONE master
6766
    m_wb_adr_o, m_wb_sel_o, m_wb_we_o,
6767
    m_wb_dat_o, m_wb_dat_i, m_wb_cyc_o,
6768
    m_wb_stb_o, m_wb_ack_i, m_wb_err_i,
6769
 
6770
`ifdef ETH_WISHBONE_B3
6771
    m_wb_cti_o, m_wb_bte_o,
6772
`endif
6773
 
6774
    //TX
6775
    MTxClk, TxStartFrm, TxEndFrm, TxUsedData, TxData,
6776
    TxRetry, TxAbort, TxUnderRun, TxDone, PerPacketCrcEn,
6777
    PerPacketPad,
6778
 
6779
    //RX
6780
    MRxClk, RxData, RxValid, RxStartFrm, RxEndFrm, RxAbort, RxStatusWriteLatched_sync2,
6781
 
6782
    // Register
6783
    r_TxEn, r_RxEn, r_TxBDNum, r_RxFlow, r_PassAll,
6784
 
6785
    // Interrupts
6786
    TxB_IRQ, TxE_IRQ, RxB_IRQ, RxE_IRQ, Busy_IRQ,
6787
 
6788
    // Rx Status
6789
    InvalidSymbol, LatchedCrcError, RxLateCollision, ShortFrame, DribbleNibble,
6790
    ReceivedPacketTooBig, RxLength, LoadRxStatus, ReceivedPacketGood, AddressMiss,
6791
    ReceivedPauseFrm,
6792
 
6793
    // Tx Status
6794
    RetryCntLatched, RetryLimit, LateCollLatched, DeferLatched, RstDeferLatched, CarrierSenseLost
6795
 
6796
    // Bist
6797
`ifdef ETH_BIST
6798
    ,
6799
    // debug chain signals
6800
    mbist_si_i,       // bist scan serial in
6801
    mbist_so_o,       // bist scan serial out
6802
    mbist_ctrl_i        // bist chain shift control
6803
`endif
6804
 
6805
 
6806
 
6807
                );
6808
 
6809
 
6810
parameter Tp = 1;
6811
 
6812
 
6813
// WISHBONE common
6814
input           WB_CLK_I;       // WISHBONE clock
6815
input  [31:0]   WB_DAT_I;       // WISHBONE data input
6816
output [31:0]   WB_DAT_O;       // WISHBONE data output
6817
 
6818
// WISHBONE slave
6819
input   [9:2]   WB_ADR_I;       // WISHBONE address input
6820
input           WB_WE_I;        // WISHBONE write enable input
6821
input   [3:0]   BDCs;           // Buffer descriptors are selected
6822
output          WB_ACK_O;       // WISHBONE acknowledge output
6823
 
6824
// WISHBONE master
6825
output  [29:0]  m_wb_adr_o;     // 
6826
output   [3:0]  m_wb_sel_o;     // 
6827
output          m_wb_we_o;      // 
6828
output  [31:0]  m_wb_dat_o;     // 
6829
output          m_wb_cyc_o;     // 
6830
output          m_wb_stb_o;     // 
6831
input   [31:0]  m_wb_dat_i;     // 
6832
input           m_wb_ack_i;     // 
6833
input           m_wb_err_i;     // 
6834
 
6835
`ifdef ETH_WISHBONE_B3
6836
output   [2:0]  m_wb_cti_o;     // Cycle Type Identifier
6837
output   [1:0]  m_wb_bte_o;     // Burst Type Extension
6838
reg      [2:0]  m_wb_cti_o;     // Cycle Type Identifier
6839
`endif
6840
 
6841
input           Reset;       // Reset signal
6842
 
6843
// Rx Status signals
6844
input           InvalidSymbol;    // Invalid symbol was received during reception in 100 Mbps mode
6845
input           LatchedCrcError;  // CRC error
6846
input           RxLateCollision;  // Late collision occured while receiving frame
6847
input           ShortFrame;       // Frame shorter then the minimum size (r_MinFL) was received while small packets are enabled (r_RecSmall)
6848
input           DribbleNibble;    // Extra nibble received
6849
input           ReceivedPacketTooBig;// Received packet is bigger than r_MaxFL
6850
input    [15:0] RxLength;         // Length of the incoming frame
6851
input           LoadRxStatus;     // Rx status was loaded
6852
input           ReceivedPacketGood;// Received packet's length and CRC are good
6853
input           AddressMiss;      // When a packet is received AddressMiss status is written to the Rx BD
6854
input           r_RxFlow;
6855
input           r_PassAll;
6856
input           ReceivedPauseFrm;
6857
 
6858
// Tx Status signals
6859
input     [3:0] RetryCntLatched;  // Latched Retry Counter
6860
input           RetryLimit;       // Retry limit reached (Retry Max value + 1 attempts were made)
6861
input           LateCollLatched;  // Late collision occured
6862
input           DeferLatched;     // Defer indication (Frame was defered before sucessfully sent)
6863
output          RstDeferLatched;
6864
input           CarrierSenseLost; // Carrier Sense was lost during the frame transmission
6865
 
6866
// Tx
6867
input           MTxClk;         // Transmit clock (from PHY)
6868
input           TxUsedData;     // Transmit packet used data
6869
input           TxRetry;        // Transmit packet retry
6870
input           TxAbort;        // Transmit packet abort
6871
input           TxDone;         // Transmission ended
6872
output          TxStartFrm;     // Transmit packet start frame
6873
output          TxEndFrm;       // Transmit packet end frame
6874
output  [7:0]   TxData;         // Transmit packet data byte
6875
output          TxUnderRun;     // Transmit packet under-run
6876
output          PerPacketCrcEn; // Per packet crc enable
6877
output          PerPacketPad;   // Per packet pading
6878
 
6879
// Rx
6880
input           MRxClk;         // Receive clock (from PHY)
6881
input   [7:0]   RxData;         // Received data byte (from PHY)
6882
input           RxValid;        // 
6883
input           RxStartFrm;     // 
6884
input           RxEndFrm;       // 
6885
input           RxAbort;        // This signal is set when address doesn't match.
6886
output          RxStatusWriteLatched_sync2;
6887
 
6888
//Register
6889
input           r_TxEn;         // Transmit enable
6890
input           r_RxEn;         // Receive enable
6891
input   [7:0]   r_TxBDNum;      // Receive buffer descriptor number
6892
 
6893
// Interrupts
6894
output TxB_IRQ;
6895
output TxE_IRQ;
6896
output RxB_IRQ;
6897
output RxE_IRQ;
6898
output Busy_IRQ;
6899
 
6900
 
6901
// Bist
6902
`ifdef ETH_BIST
6903
input   mbist_si_i;       // bist scan serial in
6904
output  mbist_so_o;       // bist scan serial out
6905
input [`ETH_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;       // bist chain shift control
6906
`endif
6907
 
6908
reg TxB_IRQ;
6909
reg TxE_IRQ;
6910
reg RxB_IRQ;
6911
reg RxE_IRQ;
6912
 
6913
reg             TxStartFrm;
6914
reg             TxEndFrm;
6915
reg     [7:0]   TxData;
6916
 
6917
reg             TxUnderRun;
6918
reg             TxUnderRun_wb;
6919
 
6920
reg             TxBDRead;
6921
wire            TxStatusWrite;
6922
 
6923
reg     [1:0]   TxValidBytesLatched;
6924
 
6925
reg    [15:0]   TxLength;
6926
reg    [15:0]   LatchedTxLength;
6927
reg   [14:11]   TxStatus;
6928
 
6929
reg   [14:13]   RxStatus;
6930
 
6931
reg             TxStartFrm_wb;
6932
reg             TxRetry_wb;
6933
reg             TxAbort_wb;
6934
reg             TxDone_wb;
6935
 
6936
reg             TxDone_wb_q;
6937
reg             TxAbort_wb_q;
6938
reg             TxRetry_wb_q;
6939
reg             TxRetryPacket;
6940
reg             TxRetryPacket_NotCleared;
6941
reg             TxDonePacket;
6942
reg             TxDonePacket_NotCleared;
6943
reg             TxAbortPacket;
6944
reg             TxAbortPacket_NotCleared;
6945
reg             RxBDReady;
6946
reg             RxReady;
6947
reg             TxBDReady;
6948
 
6949
reg             RxBDRead;
6950
 
6951
reg    [31:0]   TxDataLatched;
6952
reg     [1:0]   TxByteCnt;
6953
reg             LastWord;
6954
reg             ReadTxDataFromFifo_tck;
6955
 
6956
reg             BlockingTxStatusWrite;
6957
reg             BlockingTxBDRead;
6958
 
6959
reg             Flop;
6960
 
6961
reg     [7:1]   TxBDAddress;
6962
reg     [7:1]   RxBDAddress;
6963
 
6964
reg             TxRetrySync1;
6965
reg             TxAbortSync1;
6966
reg             TxDoneSync1;
6967
 
6968
reg             TxAbort_q;
6969
reg             TxRetry_q;
6970
reg             TxUsedData_q;
6971
 
6972
reg    [31:0]   RxDataLatched2;
6973
 
6974
reg    [31:8]   RxDataLatched1;     // Big Endian Byte Ordering
6975
 
6976
reg     [1:0]   RxValidBytes;
6977
reg     [1:0]   RxByteCnt;
6978
reg             LastByteIn;
6979
reg             ShiftWillEnd;
6980
 
6981
reg             WriteRxDataToFifo;
6982
reg    [15:0]   LatchedRxLength;
6983
reg             RxAbortLatched;
6984
 
6985
reg             ShiftEnded;
6986
reg             RxOverrun;
6987
 
6988
reg     [3:0]   BDWrite;                    // BD Write Enable for access from WISHBONE side
6989
reg             BDRead;                     // BD Read access from WISHBONE side
6990
wire   [31:0]   RxBDDataIn;                 // Rx BD data in
6991
wire   [31:0]   TxBDDataIn;                 // Tx BD data in
6992
 
6993
reg             TxEndFrm_wb;
6994
 
6995
wire            TxRetryPulse;
6996
wire            TxDonePulse;
6997
wire            TxAbortPulse;
6998
 
6999
wire            StartRxBDRead;
7000
 
7001
wire            StartTxBDRead;
7002
 
7003
wire            TxIRQEn;
7004
wire            WrapTxStatusBit;
7005
 
7006
wire            RxIRQEn;
7007
wire            WrapRxStatusBit;
7008
 
7009
wire    [1:0]   TxValidBytes;
7010
 
7011
wire    [7:1]   TempTxBDAddress;
7012
wire    [7:1]   TempRxBDAddress;
7013
 
7014
wire            RxStatusWrite;
7015
wire            RxBufferFull;
7016
wire            RxBufferAlmostEmpty;
7017
wire            RxBufferEmpty;
7018
 
7019
reg             WB_ACK_O;
7020
 
7021
wire    [8:0]   RxStatusIn;
7022
reg     [8:0]   RxStatusInLatched;
7023
 
7024
reg WbEn, WbEn_q;
7025
reg RxEn, RxEn_q;
7026
reg TxEn, TxEn_q;
7027
reg r_TxEn_q;
7028
reg r_RxEn_q;
7029
 
7030
wire ram_ce;
7031
wire [3:0]  ram_we;
7032
wire ram_oe;
7033
reg [7:0]   ram_addr;
7034
reg [31:0]  ram_di;
7035
wire [31:0] ram_do;
7036
 
7037
wire StartTxPointerRead;
7038
reg  TxPointerRead;
7039
reg TxEn_needed;
7040
reg RxEn_needed;
7041
 
7042
wire StartRxPointerRead;
7043
reg RxPointerRead;
7044
 
7045
`ifdef ETH_WISHBONE_B3
7046
assign m_wb_bte_o = 2'b00;    // Linear burst
7047
`endif
7048
 
7049
assign m_wb_stb_o = m_wb_cyc_o;
7050
 
7051
always @ (posedge WB_CLK_I)
7052
begin
7053
  WB_ACK_O <=#Tp (|BDWrite) & WbEn & WbEn_q | BDRead & WbEn & ~WbEn_q;
7054
end
7055
 
7056
assign WB_DAT_O = ram_do;
7057
 
7058
// Generic synchronous single-port RAM interface
7059
eth_spram_256x32 bd_ram (
7060
        .clk(WB_CLK_I), .rst(Reset), .ce(ram_ce), .we(ram_we), .oe(ram_oe), .addr(ram_addr), .di(ram_di), .do(ram_do)
7061
`ifdef ETH_BIST
7062
  ,
7063
  .mbist_si_i       (mbist_si_i),
7064
  .mbist_so_o       (mbist_so_o),
7065
  .mbist_ctrl_i       (mbist_ctrl_i)
7066
`endif
7067
);
7068
 
7069
assign ram_ce = 1'b1;
7070
assign ram_we = (BDWrite & {4{(WbEn & WbEn_q)}}) | {4{(TxStatusWrite | RxStatusWrite)}};
7071
assign ram_oe = BDRead & WbEn & WbEn_q | TxEn & TxEn_q & (TxBDRead | TxPointerRead) | RxEn & RxEn_q & (RxBDRead | RxPointerRead);
7072
 
7073
 
7074
always @ (posedge WB_CLK_I or posedge Reset)
7075
begin
7076
  if(Reset)
7077
    TxEn_needed <=#Tp 1'b0;
7078
  else
7079
  if(~TxBDReady & r_TxEn & WbEn & ~WbEn_q)
7080
    TxEn_needed <=#Tp 1'b1;
7081
  else
7082
  if(TxPointerRead & TxEn & TxEn_q)
7083
    TxEn_needed <=#Tp 1'b0;
7084
end
7085
 
7086
// Enabling access to the RAM for three devices.
7087
always @ (posedge WB_CLK_I or posedge Reset)
7088
begin
7089
  if(Reset)
7090
    begin
7091
      WbEn <=#Tp 1'b1;
7092
      RxEn <=#Tp 1'b0;
7093
      TxEn <=#Tp 1'b0;
7094
      ram_addr <=#Tp 8'h0;
7095
      ram_di <=#Tp 32'h0;
7096
      BDRead <=#Tp 1'b0;
7097
      BDWrite <=#Tp 1'b0;
7098
    end
7099
  else
7100
    begin
7101
      // Switching between three stages depends on enable signals
7102
      case ({WbEn_q, RxEn_q, TxEn_q, RxEn_needed, TxEn_needed})  // synopsys parallel_case
7103
        5'b100_10, 5'b100_11 :
7104
          begin
7105
            WbEn <=#Tp 1'b0;
7106
            RxEn <=#Tp 1'b1;  // wb access stage and r_RxEn is enabled
7107
            TxEn <=#Tp 1'b0;
7108
            ram_addr <=#Tp {RxBDAddress, RxPointerRead};
7109
            ram_di <=#Tp RxBDDataIn;
7110
          end
7111
        5'b100_01 :
7112
          begin
7113
            WbEn <=#Tp 1'b0;
7114
            RxEn <=#Tp 1'b0;
7115
            TxEn <=#Tp 1'b1;  // wb access stage, r_RxEn is disabled but r_TxEn is enabled
7116
            ram_addr <=#Tp {TxBDAddress, TxPointerRead};
7117
            ram_di <=#Tp TxBDDataIn;
7118
          end
7119
        5'b010_00, 5'b010_10 :
7120
          begin
7121
            WbEn <=#Tp 1'b1;  // RxEn access stage and r_TxEn is disabled
7122
            RxEn <=#Tp 1'b0;
7123
            TxEn <=#Tp 1'b0;
7124
            ram_addr <=#Tp WB_ADR_I[9:2];
7125
            ram_di <=#Tp WB_DAT_I;
7126
            BDWrite <=#Tp BDCs[3:0] & {4{WB_WE_I}};
7127
            BDRead <=#Tp (|BDCs) & ~WB_WE_I;
7128
          end
7129
        5'b010_01, 5'b010_11 :
7130
          begin
7131
            WbEn <=#Tp 1'b0;
7132
            RxEn <=#Tp 1'b0;
7133
            TxEn <=#Tp 1'b1;  // RxEn access stage and r_TxEn is enabled
7134
            ram_addr <=#Tp {TxBDAddress, TxPointerRead};
7135
            ram_di <=#Tp TxBDDataIn;
7136
          end
7137
        5'b001_00, 5'b001_01, 5'b001_10, 5'b001_11 :
7138
          begin
7139
            WbEn <=#Tp 1'b1;  // TxEn access stage (we always go to wb access stage)
7140
            RxEn <=#Tp 1'b0;
7141
            TxEn <=#Tp 1'b0;
7142
            ram_addr <=#Tp WB_ADR_I[9:2];
7143
            ram_di <=#Tp WB_DAT_I;
7144
            BDWrite <=#Tp BDCs[3:0] & {4{WB_WE_I}};
7145
            BDRead <=#Tp (|BDCs) & ~WB_WE_I;
7146
          end
7147
        5'b100_00 :
7148
          begin
7149
            WbEn <=#Tp 1'b0;  // WbEn access stage and there is no need for other stages. WbEn needs to be switched off for a bit
7150
          end
7151
        5'b000_00 :
7152
          begin
7153
            WbEn <=#Tp 1'b1;  // Idle state. We go to WbEn access stage.
7154
            RxEn <=#Tp 1'b0;
7155
            TxEn <=#Tp 1'b0;
7156
            ram_addr <=#Tp WB_ADR_I[9:2];
7157
            ram_di <=#Tp WB_DAT_I;
7158
            BDWrite <=#Tp BDCs[3:0] & {4{WB_WE_I}};
7159
            BDRead <=#Tp (|BDCs) & ~WB_WE_I;
7160
          end
7161
      endcase
7162
    end
7163
end
7164
 
7165
 
7166
// Delayed stage signals
7167
always @ (posedge WB_CLK_I or posedge Reset)
7168
begin
7169
  if(Reset)
7170
    begin
7171
      WbEn_q <=#Tp 1'b0;
7172
      RxEn_q <=#Tp 1'b0;
7173
      TxEn_q <=#Tp 1'b0;
7174
      r_TxEn_q <=#Tp 1'b0;
7175
      r_RxEn_q <=#Tp 1'b0;
7176
    end
7177
  else
7178
    begin
7179
      WbEn_q <=#Tp WbEn;
7180
      RxEn_q <=#Tp RxEn;
7181
      TxEn_q <=#Tp TxEn;
7182
      r_TxEn_q <=#Tp r_TxEn;
7183
      r_RxEn_q <=#Tp r_RxEn;
7184
    end
7185
end
7186
 
7187
// Changes for tx occur every second clock. Flop is used for this manner.
7188
always @ (posedge MTxClk or posedge Reset)
7189
begin
7190
  if(Reset)
7191
    Flop <=#Tp 1'b0;
7192
  else
7193
  if(TxDone | TxAbort | TxRetry_q)
7194
    Flop <=#Tp 1'b0;
7195
  else
7196
  if(TxUsedData)
7197
    Flop <=#Tp ~Flop;
7198
end
7199
 
7200
wire ResetTxBDReady;
7201
assign ResetTxBDReady = TxDonePulse | TxAbortPulse | TxRetryPulse;
7202
 
7203
// Latching READY status of the Tx buffer descriptor
7204
always @ (posedge WB_CLK_I or posedge Reset)
7205
begin
7206
  if(Reset)
7207
    TxBDReady <=#Tp 1'b0;
7208
  else
7209
  if(TxEn & TxEn_q & TxBDRead)
7210
    TxBDReady <=#Tp ram_do[15] & (ram_do[31:16] > 4); // TxBDReady is sampled only once at the beginning.
7211
  else                                                // Only packets larger then 4 bytes are transmitted.
7212
  if(ResetTxBDReady)
7213
    TxBDReady <=#Tp 1'b0;
7214
end
7215
 
7216
 
7217
// Reading the Tx buffer descriptor
7218
assign StartTxBDRead = (TxRetryPacket_NotCleared | TxStatusWrite) & ~BlockingTxBDRead & ~TxBDReady;
7219
 
7220
always @ (posedge WB_CLK_I or posedge Reset)
7221
begin
7222
  if(Reset)
7223
    TxBDRead <=#Tp 1'b1;
7224
  else
7225
  if(StartTxBDRead)
7226
    TxBDRead <=#Tp 1'b1;
7227
  else
7228
  if(TxBDReady)
7229
    TxBDRead <=#Tp 1'b0;
7230
end
7231
 
7232
 
7233
// Reading Tx BD pointer
7234
assign StartTxPointerRead = TxBDRead & TxBDReady;
7235
 
7236
// Reading Tx BD Pointer
7237
always @ (posedge WB_CLK_I or posedge Reset)
7238
begin
7239
  if(Reset)
7240
    TxPointerRead <=#Tp 1'b0;
7241
  else
7242
  if(StartTxPointerRead)
7243
    TxPointerRead <=#Tp 1'b1;
7244
  else
7245
  if(TxEn_q)
7246
    TxPointerRead <=#Tp 1'b0;
7247
end
7248
 
7249
 
7250
// Writing status back to the Tx buffer descriptor
7251
assign TxStatusWrite = (TxDonePacket_NotCleared | TxAbortPacket_NotCleared) & TxEn & TxEn_q & ~BlockingTxStatusWrite;
7252
 
7253
 
7254
 
7255
// Status writing must occur only once. Meanwhile it is blocked.
7256
always @ (posedge WB_CLK_I or posedge Reset)
7257
begin
7258
  if(Reset)
7259
    BlockingTxStatusWrite <=#Tp 1'b0;
7260
  else
7261
  if(~TxDone_wb & ~TxAbort_wb)
7262
    BlockingTxStatusWrite <=#Tp 1'b0;
7263
  else
7264
  if(TxStatusWrite)
7265
    BlockingTxStatusWrite <=#Tp 1'b1;
7266
end
7267
 
7268
 
7269
reg BlockingTxStatusWrite_sync1;
7270
reg BlockingTxStatusWrite_sync2;
7271
reg BlockingTxStatusWrite_sync3;
7272
 
7273
// Synchronizing BlockingTxStatusWrite to MTxClk
7274
always @ (posedge MTxClk or posedge Reset)
7275
begin
7276
  if(Reset)
7277
    BlockingTxStatusWrite_sync1 <=#Tp 1'b0;
7278
  else
7279
    BlockingTxStatusWrite_sync1 <=#Tp BlockingTxStatusWrite;
7280
end
7281
 
7282
// Synchronizing BlockingTxStatusWrite to MTxClk
7283
always @ (posedge MTxClk or posedge Reset)
7284
begin
7285
  if(Reset)
7286
    BlockingTxStatusWrite_sync2 <=#Tp 1'b0;
7287
  else
7288
    BlockingTxStatusWrite_sync2 <=#Tp BlockingTxStatusWrite_sync1;
7289
end
7290
 
7291
// Synchronizing BlockingTxStatusWrite to MTxClk
7292
always @ (posedge MTxClk or posedge Reset)
7293
begin
7294
  if(Reset)
7295
    BlockingTxStatusWrite_sync3 <=#Tp 1'b0;
7296
  else
7297
    BlockingTxStatusWrite_sync3 <=#Tp BlockingTxStatusWrite_sync2;
7298
end
7299
 
7300
assign RstDeferLatched = BlockingTxStatusWrite_sync2 & ~BlockingTxStatusWrite_sync3;
7301
 
7302
// TxBDRead state is activated only once. 
7303
always @ (posedge WB_CLK_I or posedge Reset)
7304
begin
7305
  if(Reset)
7306
    BlockingTxBDRead <=#Tp 1'b0;
7307
  else
7308
  if(StartTxBDRead)
7309
    BlockingTxBDRead <=#Tp 1'b1;
7310
  else
7311
  if(~StartTxBDRead & ~TxBDReady)
7312
    BlockingTxBDRead <=#Tp 1'b0;
7313
end
7314
 
7315
 
7316
// Latching status from the tx buffer descriptor
7317
// Data is avaliable one cycle after the access is started (at that time signal TxEn is not active)
7318
always @ (posedge WB_CLK_I or posedge Reset)
7319
begin
7320
  if(Reset)
7321
    TxStatus <=#Tp 4'h0;
7322
  else
7323
  if(TxEn & TxEn_q & TxBDRead)
7324
    TxStatus <=#Tp ram_do[14:11];
7325
end
7326
 
7327
reg ReadTxDataFromMemory;
7328
wire WriteRxDataToMemory;
7329
 
7330
reg MasterWbTX;
7331
reg MasterWbRX;
7332
 
7333
reg [29:0] m_wb_adr_o;
7334
reg        m_wb_cyc_o;
7335
reg  [3:0] m_wb_sel_o;
7336
reg        m_wb_we_o;
7337
 
7338
wire TxLengthEq0;
7339
wire TxLengthLt4;
7340
 
7341
reg BlockingIncrementTxPointer;
7342
reg [31:2] TxPointerMSB;
7343
reg [1:0]  TxPointerLSB;
7344
reg [1:0]  TxPointerLSB_rst;
7345
reg [31:2] RxPointerMSB;
7346
reg [1:0]  RxPointerLSB_rst;
7347
 
7348
wire RxBurstAcc;
7349
wire RxWordAcc;
7350
wire RxHalfAcc;
7351
wire RxByteAcc;
7352
 
7353
//Latching length from the buffer descriptor;
7354
always @ (posedge WB_CLK_I or posedge Reset)
7355
begin
7356
  if(Reset)
7357
    TxLength <=#Tp 16'h0;
7358
  else
7359
  if(TxEn & TxEn_q & TxBDRead)
7360
    TxLength <=#Tp ram_do[31:16];
7361
  else
7362
  if(MasterWbTX & m_wb_ack_i)
7363
    begin
7364
      if(TxLengthLt4)
7365
        TxLength <=#Tp 16'h0;
7366
      else
7367
      if(TxPointerLSB_rst==2'h0)
7368
        TxLength <=#Tp TxLength - 3'h4;    // Length is subtracted at the data request
7369
      else
7370
      if(TxPointerLSB_rst==2'h1)
7371
        TxLength <=#Tp TxLength - 3'h3;    // Length is subtracted at the data request
7372
      else
7373
      if(TxPointerLSB_rst==2'h2)
7374
        TxLength <=#Tp TxLength - 3'h2;    // Length is subtracted at the data request
7375
      else
7376
      if(TxPointerLSB_rst==2'h3)
7377
        TxLength <=#Tp TxLength - 3'h1;    // Length is subtracted at the data request
7378
    end
7379
end
7380
 
7381
 
7382
 
7383
//Latching length from the buffer descriptor;
7384
always @ (posedge WB_CLK_I or posedge Reset)
7385
begin
7386
  if(Reset)
7387
    LatchedTxLength <=#Tp 16'h0;
7388
  else
7389
  if(TxEn & TxEn_q & TxBDRead)
7390
    LatchedTxLength <=#Tp ram_do[31:16];
7391
end
7392
 
7393
assign TxLengthEq0 = TxLength == 0;
7394
assign TxLengthLt4 = TxLength < 4;
7395
 
7396
reg cyc_cleared;
7397
reg IncrTxPointer;
7398
 
7399
 
7400
// Latching Tx buffer pointer from buffer descriptor. Only 30 MSB bits are latched
7401
// because TxPointerMSB is only used for word-aligned accesses.
7402
always @ (posedge WB_CLK_I or posedge Reset)
7403
begin
7404
  if(Reset)
7405
    TxPointerMSB <=#Tp 30'h0;
7406
  else
7407
  if(TxEn & TxEn_q & TxPointerRead)
7408
    TxPointerMSB <=#Tp ram_do[31:2];
7409
  else
7410
  if(IncrTxPointer & ~BlockingIncrementTxPointer)
7411
    TxPointerMSB <=#Tp TxPointerMSB + 1'b1;     // TxPointer is word-aligned
7412
end
7413
 
7414
 
7415
// Latching 2 MSB bits of the buffer descriptor. Since word accesses are performed,
7416
// valid data does not necesserly start at byte 0 (could be byte 0, 1, 2 or 3). This
7417
// signals are used for proper selection of the start byte (TxData and TxByteCnt) are
7418
// set by this two bits.
7419
always @ (posedge WB_CLK_I or posedge Reset)
7420
begin
7421
  if(Reset)
7422
    TxPointerLSB[1:0] <=#Tp 0;
7423
  else
7424
  if(TxEn & TxEn_q & TxPointerRead)
7425
    TxPointerLSB[1:0] <=#Tp ram_do[1:0];
7426
end
7427
 
7428
 
7429
// Latching 2 MSB bits of the buffer descriptor. 
7430
// After the read access, TxLength needs to be decremented for the number of the valid
7431
// bytes (1 to 4 bytes are valid in the first word). After the first read all bytes are 
7432
// valid so this two bits are reset to zero. 
7433
always @ (posedge WB_CLK_I or posedge Reset)
7434
begin
7435
  if(Reset)
7436
    TxPointerLSB_rst[1:0] <=#Tp 0;
7437
  else
7438
  if(TxEn & TxEn_q & TxPointerRead)
7439
    TxPointerLSB_rst[1:0] <=#Tp ram_do[1:0];
7440
  else
7441
  if(MasterWbTX & m_wb_ack_i)                 // After first access pointer is word alligned
7442
    TxPointerLSB_rst[1:0] <=#Tp 0;
7443
end
7444
 
7445
 
7446
reg  [3:0] RxByteSel;
7447
wire MasterAccessFinished;
7448
 
7449
 
7450
always @ (posedge WB_CLK_I or posedge Reset)
7451
begin
7452
  if(Reset)
7453
    BlockingIncrementTxPointer <=#Tp 0;
7454
  else
7455
  if(MasterAccessFinished)
7456
    BlockingIncrementTxPointer <=#Tp 0;
7457
  else
7458
  if(IncrTxPointer)
7459
    BlockingIncrementTxPointer <=#Tp 1'b1;
7460
end
7461
 
7462
 
7463
wire TxBufferAlmostFull;
7464
wire TxBufferFull;
7465
wire TxBufferEmpty;
7466
wire TxBufferAlmostEmpty;
7467
wire SetReadTxDataFromMemory;
7468
 
7469
reg BlockReadTxDataFromMemory;
7470
 
7471
assign SetReadTxDataFromMemory = TxEn & TxEn_q & TxPointerRead;
7472
 
7473
always @ (posedge WB_CLK_I or posedge Reset)
7474
begin
7475
  if(Reset)
7476
    ReadTxDataFromMemory <=#Tp 1'b0;
7477
  else
7478
  if(TxLengthEq0 | TxAbortPulse | TxRetryPulse)
7479
    ReadTxDataFromMemory <=#Tp 1'b0;
7480
  else
7481
  if(SetReadTxDataFromMemory)
7482
    ReadTxDataFromMemory <=#Tp 1'b1;
7483
end
7484
 
7485
reg tx_burst_en;
7486
reg rx_burst_en;
7487
 
7488
wire ReadTxDataFromMemory_2 = ReadTxDataFromMemory & ~BlockReadTxDataFromMemory;
7489
wire tx_burst = ReadTxDataFromMemory_2 & tx_burst_en;
7490
 
7491
wire [31:0] TxData_wb;
7492
wire ReadTxDataFromFifo_wb;
7493
 
7494
always @ (posedge WB_CLK_I or posedge Reset)
7495
begin
7496
  if(Reset)
7497
    BlockReadTxDataFromMemory <=#Tp 1'b0;
7498
  else
7499
  if((TxBufferAlmostFull | TxLength <= 4)& MasterWbTX & (~cyc_cleared) & (!(TxAbortPacket_NotCleared | TxRetryPacket_NotCleared)))
7500
    BlockReadTxDataFromMemory <=#Tp 1'b1;
7501
  else
7502
  if(ReadTxDataFromFifo_wb | TxDonePacket | TxAbortPacket | TxRetryPacket)
7503
    BlockReadTxDataFromMemory <=#Tp 1'b0;
7504
end
7505
 
7506
 
7507
assign MasterAccessFinished = m_wb_ack_i | m_wb_err_i;
7508
wire [`ETH_TX_FIFO_CNT_WIDTH-1:0] txfifo_cnt;
7509
wire [`ETH_RX_FIFO_CNT_WIDTH-1:0] rxfifo_cnt;
7510
reg  [`ETH_BURST_CNT_WIDTH-1:0] tx_burst_cnt;
7511
reg  [`ETH_BURST_CNT_WIDTH-1:0] rx_burst_cnt;
7512
 
7513
wire rx_burst;
7514
wire enough_data_in_rxfifo_for_burst;
7515
wire enough_data_in_rxfifo_for_burst_plus1;
7516
 
7517
// Enabling master wishbone access to the memory for two devices TX and RX.
7518
always @ (posedge WB_CLK_I or posedge Reset)
7519
begin
7520
  if(Reset)
7521
    begin
7522
      MasterWbTX <=#Tp 1'b0;
7523
      MasterWbRX <=#Tp 1'b0;
7524
      m_wb_adr_o <=#Tp 30'h0;
7525
      m_wb_cyc_o <=#Tp 1'b0;
7526
      m_wb_we_o  <=#Tp 1'b0;
7527
      m_wb_sel_o <=#Tp 4'h0;
7528
      cyc_cleared<=#Tp 1'b0;
7529
      tx_burst_cnt<=#Tp 0;
7530
      rx_burst_cnt<=#Tp 0;
7531
      IncrTxPointer<=#Tp 1'b0;
7532
      tx_burst_en<=#Tp 1'b1;
7533
      rx_burst_en<=#Tp 1'b0;
7534
      `ifdef ETH_WISHBONE_B3
7535
        m_wb_cti_o <=#Tp 3'b0;
7536
      `endif
7537
    end
7538
  else
7539
    begin
7540
      // Switching between two stages depends on enable signals
7541
      casex ({MasterWbTX, MasterWbRX, ReadTxDataFromMemory_2, WriteRxDataToMemory, MasterAccessFinished, cyc_cleared, tx_burst, rx_burst})  // synopsys parallel_case
7542
        8'b00_10_00_10,             // Idle and MRB needed
7543
        8'b10_1x_10_1x,             // MRB continues
7544
        8'b10_10_01_10,             // Clear (previously MR) and MRB needed
7545
        8'b01_1x_01_1x :            // Clear (previously MW) and MRB needed
7546
          begin
7547
            MasterWbTX <=#Tp 1'b1;  // tx burst
7548
            MasterWbRX <=#Tp 1'b0;
7549
            m_wb_cyc_o <=#Tp 1'b1;
7550
            m_wb_we_o  <=#Tp 1'b0;
7551
            m_wb_sel_o <=#Tp 4'hf;
7552
            cyc_cleared<=#Tp 1'b0;
7553
            IncrTxPointer<=#Tp 1'b1;
7554
            tx_burst_cnt <=#Tp tx_burst_cnt+3'h1;
7555
            if(tx_burst_cnt==0)
7556
              m_wb_adr_o <=#Tp TxPointerMSB;
7557
            else
7558
              m_wb_adr_o <=#Tp m_wb_adr_o+1'b1;
7559
 
7560
            if(tx_burst_cnt==(`ETH_BURST_LENGTH-1))
7561
              begin
7562
                tx_burst_en<=#Tp 1'b0;
7563
              `ifdef ETH_WISHBONE_B3
7564
                m_wb_cti_o <=#Tp 3'b111;
7565
              `endif
7566
              end
7567
            else
7568
              begin
7569
              `ifdef ETH_WISHBONE_B3
7570
                m_wb_cti_o <=#Tp 3'b010;
7571
              `endif
7572
              end
7573
          end
7574
        8'b00_x1_00_x1,             // Idle and MWB needed
7575
        8'b01_x1_10_x1,             // MWB continues
7576
        8'b01_01_01_01,             // Clear (previously MW) and MWB needed
7577
        8'b10_x1_01_x1 :            // Clear (previously MR) and MWB needed
7578
          begin
7579
            MasterWbTX <=#Tp 1'b0;  // rx burst
7580
            MasterWbRX <=#Tp 1'b1;
7581
            m_wb_cyc_o <=#Tp 1'b1;
7582
            m_wb_we_o  <=#Tp 1'b1;
7583
            m_wb_sel_o <=#Tp RxByteSel;
7584
            IncrTxPointer<=#Tp 1'b0;
7585
            cyc_cleared<=#Tp 1'b0;
7586
            rx_burst_cnt <=#Tp rx_burst_cnt+3'h1;
7587
 
7588
            if(rx_burst_cnt==0)
7589
              m_wb_adr_o <=#Tp RxPointerMSB;
7590
            else
7591
              m_wb_adr_o <=#Tp m_wb_adr_o+1'b1;
7592
 
7593
            if(rx_burst_cnt==(`ETH_BURST_LENGTH-1))
7594
              begin
7595
                rx_burst_en<=#Tp 1'b0;
7596
              `ifdef ETH_WISHBONE_B3
7597
                m_wb_cti_o <=#Tp 3'b111;
7598
              `endif
7599
              end
7600
            else
7601
              begin
7602
              `ifdef ETH_WISHBONE_B3
7603
                m_wb_cti_o <=#Tp 3'b010;
7604
              `endif
7605
              end
7606
          end
7607
        8'b00_x1_00_x0 :            // idle and MW is needed (data write to rx buffer)
7608
          begin
7609
            MasterWbTX <=#Tp 1'b0;
7610
            MasterWbRX <=#Tp 1'b1;
7611
            m_wb_adr_o <=#Tp RxPointerMSB;
7612
            m_wb_cyc_o <=#Tp 1'b1;
7613
            m_wb_we_o  <=#Tp 1'b1;
7614
            m_wb_sel_o <=#Tp RxByteSel;
7615
            IncrTxPointer<=#Tp 1'b0;
7616
          end
7617
        8'b00_10_00_00 :            // idle and MR is needed (data read from tx buffer)
7618
          begin
7619
            MasterWbTX <=#Tp 1'b1;
7620
            MasterWbRX <=#Tp 1'b0;
7621
            m_wb_adr_o <=#Tp TxPointerMSB;
7622
            m_wb_cyc_o <=#Tp 1'b1;
7623
            m_wb_we_o  <=#Tp 1'b0;
7624
            m_wb_sel_o <=#Tp 4'hf;
7625
            IncrTxPointer<=#Tp 1'b1;
7626
          end
7627
        8'b10_10_01_00,             // MR and MR is needed (data read from tx buffer)
7628
        8'b01_1x_01_0x  :           // MW and MR is needed (data read from tx buffer)
7629
          begin
7630
            MasterWbTX <=#Tp 1'b1;
7631
            MasterWbRX <=#Tp 1'b0;
7632
            m_wb_adr_o <=#Tp TxPointerMSB;
7633
            m_wb_cyc_o <=#Tp 1'b1;
7634
            m_wb_we_o  <=#Tp 1'b0;
7635
            m_wb_sel_o <=#Tp 4'hf;
7636
            cyc_cleared<=#Tp 1'b0;
7637
            IncrTxPointer<=#Tp 1'b1;
7638
          end
7639
        8'b01_01_01_00,             // MW and MW needed (data write to rx buffer)
7640
        8'b10_x1_01_x0  :           // MR and MW is needed (data write to rx buffer)
7641
          begin
7642
            MasterWbTX <=#Tp 1'b0;
7643
            MasterWbRX <=#Tp 1'b1;
7644
            m_wb_adr_o <=#Tp RxPointerMSB;
7645
            m_wb_cyc_o <=#Tp 1'b1;
7646
            m_wb_we_o  <=#Tp 1'b1;
7647
            m_wb_sel_o <=#Tp RxByteSel;
7648
            cyc_cleared<=#Tp 1'b0;
7649
            IncrTxPointer<=#Tp 1'b0;
7650
          end
7651
        8'b01_01_10_00,             // MW and MW needed (cycle is cleared between previous and next access)
7652
        8'b01_1x_10_x0,             // MW and MW or MR or MRB needed (cycle is cleared between previous and next access)
7653
        8'b10_10_10_00,             // MR and MR needed (cycle is cleared between previous and next access)
7654
        8'b10_x1_10_0x :            // MR and MR or MW or MWB (cycle is cleared between previous and next access)
7655
          begin
7656
            m_wb_cyc_o <=#Tp 1'b0;  // whatever and master read or write is needed. We need to clear m_wb_cyc_o before next access is started
7657
            cyc_cleared<=#Tp 1'b1;
7658
            IncrTxPointer<=#Tp 1'b0;
7659
            tx_burst_cnt<=#Tp 0;
7660
            tx_burst_en<=#Tp txfifo_cnt<(`ETH_TX_FIFO_DEPTH-`ETH_BURST_LENGTH) & (TxLength>(`ETH_BURST_LENGTH*4+4));
7661
            rx_burst_cnt<=#Tp 0;
7662
            rx_burst_en<=#Tp MasterWbRX ? enough_data_in_rxfifo_for_burst_plus1 : enough_data_in_rxfifo_for_burst;  // Counter is not decremented, yet, so plus1 is used.
7663
            `ifdef ETH_WISHBONE_B3
7664
              m_wb_cti_o <=#Tp 3'b0;
7665
            `endif
7666
          end
7667
        8'bxx_00_10_00,             // whatever and no master read or write is needed (ack or err comes finishing previous access)
7668
        8'bxx_00_01_00 :            // Between cyc_cleared request was cleared
7669
          begin
7670
            MasterWbTX <=#Tp 1'b0;
7671
            MasterWbRX <=#Tp 1'b0;
7672
            m_wb_cyc_o <=#Tp 1'b0;
7673
            cyc_cleared<=#Tp 1'b0;
7674
            IncrTxPointer<=#Tp 1'b0;
7675
            rx_burst_cnt<=#Tp 0;
7676
            rx_burst_en<=#Tp MasterWbRX ? enough_data_in_rxfifo_for_burst_plus1 : enough_data_in_rxfifo_for_burst;  // Counter is not decremented, yet, so plus1 is used.
7677
            `ifdef ETH_WISHBONE_B3
7678
              m_wb_cti_o <=#Tp 3'b0;
7679
            `endif
7680
          end
7681
        8'b00_00_00_00:             // whatever and no master read or write is needed (ack or err comes finishing previous access)
7682
          begin
7683
            tx_burst_cnt<=#Tp 0;
7684
            tx_burst_en<=#Tp txfifo_cnt<(`ETH_TX_FIFO_DEPTH-`ETH_BURST_LENGTH) & (TxLength>(`ETH_BURST_LENGTH*4+4));
7685
          end
7686
        default:                    // Don't touch
7687
          begin
7688
            MasterWbTX <=#Tp MasterWbTX;
7689
            MasterWbRX <=#Tp MasterWbRX;
7690
            m_wb_cyc_o <=#Tp m_wb_cyc_o;
7691
            m_wb_sel_o <=#Tp m_wb_sel_o;
7692
            IncrTxPointer<=#Tp IncrTxPointer;
7693
          end
7694
      endcase
7695
    end
7696
end
7697
 
7698
 
7699
wire TxFifoClear;
7700
 
7701
assign TxFifoClear = (TxAbortPacket | TxRetryPacket);
7702
 
7703
eth_fifo #(`ETH_TX_FIFO_DATA_WIDTH, `ETH_TX_FIFO_DEPTH, `ETH_TX_FIFO_CNT_WIDTH)
7704
tx_fifo ( .data_in(m_wb_dat_i),                             .data_out(TxData_wb),
7705
          .clk(WB_CLK_I),                                   .reset(Reset),
7706
          .write(MasterWbTX & m_wb_ack_i),                  .read(ReadTxDataFromFifo_wb & ~TxBufferEmpty),
7707
          .clear(TxFifoClear),                              .full(TxBufferFull),
7708
          .almost_full(TxBufferAlmostFull),                 .almost_empty(TxBufferAlmostEmpty),
7709
          .empty(TxBufferEmpty),                            .cnt(txfifo_cnt)
7710
        );
7711
 
7712
 
7713
reg StartOccured;
7714
reg TxStartFrm_sync1;
7715
reg TxStartFrm_sync2;
7716
reg TxStartFrm_syncb1;
7717
reg TxStartFrm_syncb2;
7718
 
7719
 
7720
 
7721
// Start: Generation of the TxStartFrm_wb which is then synchronized to the MTxClk
7722
always @ (posedge WB_CLK_I or posedge Reset)
7723
begin
7724
  if(Reset)
7725
    TxStartFrm_wb <=#Tp 1'b0;
7726
  else
7727
  if(TxBDReady & ~StartOccured & (TxBufferFull | TxLengthEq0))
7728
    TxStartFrm_wb <=#Tp 1'b1;
7729
  else
7730
  if(TxStartFrm_syncb2)
7731
    TxStartFrm_wb <=#Tp 1'b0;
7732
end
7733
 
7734
// StartOccured: TxStartFrm_wb occurs only ones at the beginning. Then it's blocked.
7735
always @ (posedge WB_CLK_I or posedge Reset)
7736
begin
7737
  if(Reset)
7738
    StartOccured <=#Tp 1'b0;
7739
  else
7740
  if(TxStartFrm_wb)
7741
    StartOccured <=#Tp 1'b1;
7742
  else
7743
  if(ResetTxBDReady)
7744
    StartOccured <=#Tp 1'b0;
7745
end
7746
 
7747
// Synchronizing TxStartFrm_wb to MTxClk
7748
always @ (posedge MTxClk or posedge Reset)
7749
begin
7750
  if(Reset)
7751
    TxStartFrm_sync1 <=#Tp 1'b0;
7752
  else
7753
    TxStartFrm_sync1 <=#Tp TxStartFrm_wb;
7754
end
7755
 
7756
always @ (posedge MTxClk or posedge Reset)
7757
begin
7758
  if(Reset)
7759
    TxStartFrm_sync2 <=#Tp 1'b0;
7760
  else
7761
    TxStartFrm_sync2 <=#Tp TxStartFrm_sync1;
7762
end
7763
 
7764
always @ (posedge WB_CLK_I or posedge Reset)
7765
begin
7766
  if(Reset)
7767
    TxStartFrm_syncb1 <=#Tp 1'b0;
7768
  else
7769
    TxStartFrm_syncb1 <=#Tp TxStartFrm_sync2;
7770
end
7771
 
7772
always @ (posedge WB_CLK_I or posedge Reset)
7773
begin
7774
  if(Reset)
7775
    TxStartFrm_syncb2 <=#Tp 1'b0;
7776
  else
7777
    TxStartFrm_syncb2 <=#Tp TxStartFrm_syncb1;
7778
end
7779
 
7780
always @ (posedge MTxClk or posedge Reset)
7781
begin
7782
  if(Reset)
7783
    TxStartFrm <=#Tp 1'b0;
7784
  else
7785
  if(TxStartFrm_sync2)
7786
    TxStartFrm <=#Tp 1'b1;
7787
  else
7788
  if(TxUsedData_q | ~TxStartFrm_sync2 & (TxRetry & (~TxRetry_q) | TxAbort & (~TxAbort_q)))
7789
    TxStartFrm <=#Tp 1'b0;
7790
end
7791
// End: Generation of the TxStartFrm_wb which is then synchronized to the MTxClk
7792
 
7793
 
7794
// TxEndFrm_wb: indicator of the end of frame
7795
always @ (posedge WB_CLK_I or posedge Reset)
7796
begin
7797
  if(Reset)
7798
    TxEndFrm_wb <=#Tp 1'b0;
7799
  else
7800
  if(TxLengthEq0 & TxBufferAlmostEmpty & TxUsedData)
7801
    TxEndFrm_wb <=#Tp 1'b1;
7802
  else
7803
  if(TxRetryPulse | TxDonePulse | TxAbortPulse)
7804
    TxEndFrm_wb <=#Tp 1'b0;
7805
end
7806
 
7807
 
7808
// Marks which bytes are valid within the word.
7809
assign TxValidBytes = TxLengthLt4 ? TxLength[1:0] : 2'b0;
7810
 
7811
reg LatchValidBytes;
7812
reg LatchValidBytes_q;
7813
 
7814
always @ (posedge WB_CLK_I or posedge Reset)
7815
begin
7816
  if(Reset)
7817
    LatchValidBytes <=#Tp 1'b0;
7818
  else
7819
  if(TxLengthLt4 & TxBDReady)
7820
    LatchValidBytes <=#Tp 1'b1;
7821
  else
7822
    LatchValidBytes <=#Tp 1'b0;
7823
end
7824
 
7825
always @ (posedge WB_CLK_I or posedge Reset)
7826
begin
7827
  if(Reset)
7828
    LatchValidBytes_q <=#Tp 1'b0;
7829
  else
7830
    LatchValidBytes_q <=#Tp LatchValidBytes;
7831
end
7832
 
7833
 
7834
// Latching valid bytes
7835
always @ (posedge WB_CLK_I or posedge Reset)
7836
begin
7837
  if(Reset)
7838
    TxValidBytesLatched <=#Tp 2'h0;
7839
  else
7840
  if(LatchValidBytes & ~LatchValidBytes_q)
7841
    TxValidBytesLatched <=#Tp TxValidBytes;
7842
  else
7843
  if(TxRetryPulse | TxDonePulse | TxAbortPulse)
7844
    TxValidBytesLatched <=#Tp 2'h0;
7845
end
7846
 
7847
 
7848
assign TxIRQEn          = TxStatus[14];
7849
assign WrapTxStatusBit  = TxStatus[13];
7850
assign PerPacketPad     = TxStatus[12];
7851
assign PerPacketCrcEn   = TxStatus[11];
7852
 
7853
 
7854
assign RxIRQEn         = RxStatus[14];
7855
assign WrapRxStatusBit = RxStatus[13];
7856
 
7857
 
7858
// Temporary Tx and Rx buffer descriptor address 
7859
assign TempTxBDAddress[7:1] = {7{ TxStatusWrite     & ~WrapTxStatusBit}}   & (TxBDAddress + 1'b1) ; // Tx BD increment or wrap (last BD)
7860
assign TempRxBDAddress[7:1] = {7{ WrapRxStatusBit}} & (r_TxBDNum[6:0])     | // Using first Rx BD
7861
                              {7{~WrapRxStatusBit}} & (RxBDAddress + 1'b1) ; // Using next Rx BD (incremenrement address)
7862
 
7863
 
7864
// Latching Tx buffer descriptor address
7865
always @ (posedge WB_CLK_I or posedge Reset)
7866
begin
7867
  if(Reset)
7868
    TxBDAddress <=#Tp 7'h0;
7869
  else if (r_TxEn & (~r_TxEn_q))
7870
    TxBDAddress <=#Tp 7'h0;
7871
  else if (TxStatusWrite)
7872
    TxBDAddress <=#Tp TempTxBDAddress;
7873
end
7874
 
7875
 
7876
// Latching Rx buffer descriptor address
7877
always @ (posedge WB_CLK_I or posedge Reset)
7878
begin
7879
  if(Reset)
7880
    RxBDAddress <=#Tp 7'h0;
7881
  else if(r_RxEn & (~r_RxEn_q))
7882
    RxBDAddress <=#Tp r_TxBDNum[6:0];
7883
  else if(RxStatusWrite)
7884
    RxBDAddress <=#Tp TempRxBDAddress;
7885
end
7886
 
7887
wire [8:0] TxStatusInLatched = {TxUnderRun, RetryCntLatched[3:0], RetryLimit, LateCollLatched, DeferLatched, CarrierSenseLost};
7888
 
7889
assign RxBDDataIn = {LatchedRxLength, 1'b0, RxStatus, 4'h0, RxStatusInLatched};
7890
assign TxBDDataIn = {LatchedTxLength, 1'b0, TxStatus, 2'h0, TxStatusInLatched};
7891
 
7892
 
7893
// Signals used for various purposes
7894
assign TxRetryPulse   = TxRetry_wb   & ~TxRetry_wb_q;
7895
assign TxDonePulse    = TxDone_wb    & ~TxDone_wb_q;
7896
assign TxAbortPulse   = TxAbort_wb   & ~TxAbort_wb_q;
7897
 
7898
 
7899
 
7900
// Generating delayed signals
7901
always @ (posedge MTxClk or posedge Reset)
7902
begin
7903
  if(Reset)
7904
    begin
7905
      TxAbort_q      <=#Tp 1'b0;
7906
      TxRetry_q      <=#Tp 1'b0;
7907
      TxUsedData_q   <=#Tp 1'b0;
7908
    end
7909
  else
7910
    begin
7911
      TxAbort_q      <=#Tp TxAbort;
7912
      TxRetry_q      <=#Tp TxRetry;
7913
      TxUsedData_q   <=#Tp TxUsedData;
7914
    end
7915
end
7916
 
7917
// Generating delayed signals
7918
always @ (posedge WB_CLK_I or posedge Reset)
7919
begin
7920
  if(Reset)
7921
    begin
7922
      TxDone_wb_q   <=#Tp 1'b0;
7923
      TxAbort_wb_q  <=#Tp 1'b0;
7924
      TxRetry_wb_q  <=#Tp 1'b0;
7925
    end
7926
  else
7927
    begin
7928
      TxDone_wb_q   <=#Tp TxDone_wb;
7929
      TxAbort_wb_q  <=#Tp TxAbort_wb;
7930
      TxRetry_wb_q  <=#Tp TxRetry_wb;
7931
    end
7932
end
7933
 
7934
 
7935
reg TxAbortPacketBlocked;
7936
always @ (posedge WB_CLK_I or posedge Reset)
7937
begin
7938
  if(Reset)
7939
    TxAbortPacket <=#Tp 1'b0;
7940
  else
7941
  if(TxAbort_wb & (~tx_burst_en) & MasterWbTX & MasterAccessFinished & (~TxAbortPacketBlocked) |
7942
     TxAbort_wb & (~MasterWbTX) & (~TxAbortPacketBlocked))
7943
    TxAbortPacket <=#Tp 1'b1;
7944
  else
7945
    TxAbortPacket <=#Tp 1'b0;
7946
end
7947
 
7948
 
7949
always @ (posedge WB_CLK_I or posedge Reset)
7950
begin
7951
  if(Reset)
7952
    TxAbortPacket_NotCleared <=#Tp 1'b0;
7953
  else
7954
  if(TxEn & TxEn_q & TxAbortPacket_NotCleared)
7955
    TxAbortPacket_NotCleared <=#Tp 1'b0;
7956
  else
7957
  if(TxAbort_wb & (~tx_burst_en) & MasterWbTX & MasterAccessFinished & (~TxAbortPacketBlocked) |
7958
     TxAbort_wb & (~MasterWbTX) & (~TxAbortPacketBlocked))
7959
    TxAbortPacket_NotCleared <=#Tp 1'b1;
7960
end
7961
 
7962
 
7963
always @ (posedge WB_CLK_I or posedge Reset)
7964
begin
7965
  if(Reset)
7966
    TxAbortPacketBlocked <=#Tp 1'b0;
7967
  else
7968
  if(!TxAbort_wb & TxAbort_wb_q)
7969
    TxAbortPacketBlocked <=#Tp 1'b0;
7970
  else
7971
  if(TxAbortPacket)
7972
    TxAbortPacketBlocked <=#Tp 1'b1;
7973
end
7974
 
7975
 
7976
reg TxRetryPacketBlocked;
7977
always @ (posedge WB_CLK_I or posedge Reset)
7978
begin
7979
  if(Reset)
7980
    TxRetryPacket <=#Tp 1'b0;
7981
  else
7982
  if(TxRetry_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished & !TxRetryPacketBlocked |
7983
     TxRetry_wb & !MasterWbTX & !TxRetryPacketBlocked)
7984
    TxRetryPacket <=#Tp 1'b1;
7985
  else
7986
    TxRetryPacket <=#Tp 1'b0;
7987
end
7988
 
7989
 
7990
always @ (posedge WB_CLK_I or posedge Reset)
7991
begin
7992
  if(Reset)
7993
    TxRetryPacket_NotCleared <=#Tp 1'b0;
7994
  else
7995
  if(StartTxBDRead)
7996
    TxRetryPacket_NotCleared <=#Tp 1'b0;
7997
  else
7998
  if(TxRetry_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished & !TxRetryPacketBlocked |
7999
     TxRetry_wb & !MasterWbTX & !TxRetryPacketBlocked)
8000
    TxRetryPacket_NotCleared <=#Tp 1'b1;
8001
end
8002
 
8003
 
8004
always @ (posedge WB_CLK_I or posedge Reset)
8005
begin
8006
  if(Reset)
8007
    TxRetryPacketBlocked <=#Tp 1'b0;
8008
  else
8009
  if(!TxRetry_wb & TxRetry_wb_q)
8010
    TxRetryPacketBlocked <=#Tp 1'b0;
8011
  else
8012
  if(TxRetryPacket)
8013
    TxRetryPacketBlocked <=#Tp 1'b1;
8014
end
8015
 
8016
 
8017
reg TxDonePacketBlocked;
8018
always @ (posedge WB_CLK_I or posedge Reset)
8019
begin
8020
  if(Reset)
8021
    TxDonePacket <=#Tp 1'b0;
8022
  else
8023
  if(TxDone_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished & !TxDonePacketBlocked |
8024
     TxDone_wb & !MasterWbTX & !TxDonePacketBlocked)
8025
    TxDonePacket <=#Tp 1'b1;
8026
  else
8027
    TxDonePacket <=#Tp 1'b0;
8028
end
8029
 
8030
 
8031
always @ (posedge WB_CLK_I or posedge Reset)
8032
begin
8033
  if(Reset)
8034
    TxDonePacket_NotCleared <=#Tp 1'b0;
8035
  else
8036
  if(TxEn & TxEn_q & TxDonePacket_NotCleared)
8037
    TxDonePacket_NotCleared <=#Tp 1'b0;
8038
  else
8039
  if(TxDone_wb & !tx_burst_en & MasterWbTX & MasterAccessFinished & (~TxDonePacketBlocked) |
8040
     TxDone_wb & !MasterWbTX & (~TxDonePacketBlocked))
8041
    TxDonePacket_NotCleared <=#Tp 1'b1;
8042
end
8043
 
8044
 
8045
always @ (posedge WB_CLK_I or posedge Reset)
8046
begin
8047
  if(Reset)
8048
    TxDonePacketBlocked <=#Tp 1'b0;
8049
  else
8050
  if(!TxDone_wb & TxDone_wb_q)
8051
    TxDonePacketBlocked <=#Tp 1'b0;
8052
  else
8053
  if(TxDonePacket)
8054
    TxDonePacketBlocked <=#Tp 1'b1;
8055
end
8056
 
8057
 
8058
// Indication of the last word
8059
always @ (posedge MTxClk or posedge Reset)
8060
begin
8061
  if(Reset)
8062
    LastWord <=#Tp 1'b0;
8063
  else
8064
  if((TxEndFrm | TxAbort | TxRetry) & Flop)
8065
    LastWord <=#Tp 1'b0;
8066
  else
8067
  if(TxUsedData & Flop & TxByteCnt == 2'h3)
8068
    LastWord <=#Tp TxEndFrm_wb;
8069
end
8070
 
8071
 
8072
// Tx end frame generation
8073
always @ (posedge MTxClk or posedge Reset)
8074
begin
8075
  if(Reset)
8076
    TxEndFrm <=#Tp 1'b0;
8077
  else
8078
  if(Flop & TxEndFrm | TxAbort | TxRetry_q)
8079
    TxEndFrm <=#Tp 1'b0;
8080
  else
8081
  if(Flop & LastWord)
8082
    begin
8083
      case (TxValidBytesLatched)  // synopsys parallel_case
8084
        1 : TxEndFrm <=#Tp TxByteCnt == 2'h0;
8085
        2 : TxEndFrm <=#Tp TxByteCnt == 2'h1;
8086
        3 : TxEndFrm <=#Tp TxByteCnt == 2'h2;
8087
 
8088
        default : TxEndFrm <=#Tp 1'b0;
8089
      endcase
8090
    end
8091
end
8092
 
8093
 
8094
// Tx data selection (latching)
8095
always @ (posedge MTxClk or posedge Reset)
8096
begin
8097
  if(Reset)
8098
    TxData <=#Tp 0;
8099
  else
8100
  if(TxStartFrm_sync2 & ~TxStartFrm)
8101
    case(TxPointerLSB)  // synopsys parallel_case
8102
      2'h0 : TxData <=#Tp TxData_wb[31:24];                  // Big Endian Byte Ordering
8103
      2'h1 : TxData <=#Tp TxData_wb[23:16];                  // Big Endian Byte Ordering
8104
      2'h2 : TxData <=#Tp TxData_wb[15:08];                  // Big Endian Byte Ordering
8105
      2'h3 : TxData <=#Tp TxData_wb[07:00];                  // Big Endian Byte Ordering
8106
    endcase
8107
  else
8108
  if(TxStartFrm & TxUsedData & TxPointerLSB==2'h3)
8109
    TxData <=#Tp TxData_wb[31:24];                           // Big Endian Byte Ordering
8110
  else
8111
  if(TxUsedData & Flop)
8112
    begin
8113
      case(TxByteCnt)  // synopsys parallel_case
8114
 
8115
        1 : TxData <=#Tp TxDataLatched[23:16];
8116
        2 : TxData <=#Tp TxDataLatched[15:8];
8117
        3 : TxData <=#Tp TxDataLatched[7:0];
8118
      endcase
8119
    end
8120
end
8121
 
8122
 
8123
// Latching tx data
8124
always @ (posedge MTxClk or posedge Reset)
8125
begin
8126
  if(Reset)
8127
    TxDataLatched[31:0] <=#Tp 32'h0;
8128
  else
8129
 if(TxStartFrm_sync2 & ~TxStartFrm | TxUsedData & Flop & TxByteCnt == 2'h3 | TxStartFrm & TxUsedData & Flop & TxByteCnt == 2'h0)
8130
    TxDataLatched[31:0] <=#Tp TxData_wb[31:0];
8131
end
8132
 
8133
 
8134
// Tx under run
8135
always @ (posedge WB_CLK_I or posedge Reset)
8136
begin
8137
  if(Reset)
8138
    TxUnderRun_wb <=#Tp 1'b0;
8139
  else
8140
  if(TxAbortPulse)
8141
    TxUnderRun_wb <=#Tp 1'b0;
8142
  else
8143
  if(TxBufferEmpty & ReadTxDataFromFifo_wb)
8144
    TxUnderRun_wb <=#Tp 1'b1;
8145
end
8146
 
8147
 
8148
reg TxUnderRun_sync1;
8149
 
8150
// Tx under run
8151
always @ (posedge MTxClk or posedge Reset)
8152
begin
8153
  if(Reset)
8154
    TxUnderRun_sync1 <=#Tp 1'b0;
8155
  else
8156
  if(TxUnderRun_wb)
8157
    TxUnderRun_sync1 <=#Tp 1'b1;
8158
  else
8159
  if(BlockingTxStatusWrite_sync2)
8160
    TxUnderRun_sync1 <=#Tp 1'b0;
8161
end
8162
 
8163
// Tx under run
8164
always @ (posedge MTxClk or posedge Reset)
8165
begin
8166
  if(Reset)
8167
    TxUnderRun <=#Tp 1'b0;
8168
  else
8169
  if(BlockingTxStatusWrite_sync2)
8170
    TxUnderRun <=#Tp 1'b0;
8171
  else
8172
  if(TxUnderRun_sync1)
8173
    TxUnderRun <=#Tp 1'b1;
8174
end
8175
 
8176
 
8177
// Tx Byte counter
8178
always @ (posedge MTxClk or posedge Reset)
8179
begin
8180
  if(Reset)
8181
    TxByteCnt <=#Tp 2'h0;
8182
  else
8183
  if(TxAbort_q | TxRetry_q)
8184
    TxByteCnt <=#Tp 2'h0;
8185
  else
8186
  if(TxStartFrm & ~TxUsedData)
8187
    case(TxPointerLSB)  // synopsys parallel_case
8188
      2'h0 : TxByteCnt <=#Tp 2'h1;
8189
      2'h1 : TxByteCnt <=#Tp 2'h2;
8190
      2'h2 : TxByteCnt <=#Tp 2'h3;
8191
      2'h3 : TxByteCnt <=#Tp 2'h0;
8192
    endcase
8193
  else
8194
  if(TxUsedData & Flop)
8195
    TxByteCnt <=#Tp TxByteCnt + 1'b1;
8196
end
8197
 
8198
 
8199
// Start: Generation of the ReadTxDataFromFifo_tck signal and synchronization to the WB_CLK_I
8200
reg ReadTxDataFromFifo_sync1;
8201
reg ReadTxDataFromFifo_sync2;
8202
reg ReadTxDataFromFifo_sync3;
8203
reg ReadTxDataFromFifo_syncb1;
8204
reg ReadTxDataFromFifo_syncb2;
8205
reg ReadTxDataFromFifo_syncb3;
8206
 
8207
 
8208
always @ (posedge MTxClk or posedge Reset)
8209
begin
8210
  if(Reset)
8211
    ReadTxDataFromFifo_tck <=#Tp 1'b0;
8212
  else
8213
  if(TxStartFrm_sync2 & ~TxStartFrm | TxUsedData & Flop & TxByteCnt == 2'h3 & ~LastWord | TxStartFrm & TxUsedData & Flop & TxByteCnt == 2'h0)
8214
     ReadTxDataFromFifo_tck <=#Tp 1'b1;
8215
  else
8216
  if(ReadTxDataFromFifo_syncb2 & ~ReadTxDataFromFifo_syncb3)
8217
    ReadTxDataFromFifo_tck <=#Tp 1'b0;
8218
end
8219
 
8220
// Synchronizing TxStartFrm_wb to MTxClk
8221
always @ (posedge WB_CLK_I or posedge Reset)
8222
begin
8223
  if(Reset)
8224
    ReadTxDataFromFifo_sync1 <=#Tp 1'b0;
8225
  else
8226
    ReadTxDataFromFifo_sync1 <=#Tp ReadTxDataFromFifo_tck;
8227
end
8228
 
8229
always @ (posedge WB_CLK_I or posedge Reset)
8230
begin
8231
  if(Reset)
8232
    ReadTxDataFromFifo_sync2 <=#Tp 1'b0;
8233
  else
8234
    ReadTxDataFromFifo_sync2 <=#Tp ReadTxDataFromFifo_sync1;
8235
end
8236
 
8237
always @ (posedge MTxClk or posedge Reset)
8238
begin
8239
  if(Reset)
8240
    ReadTxDataFromFifo_syncb1 <=#Tp 1'b0;
8241
  else
8242
    ReadTxDataFromFifo_syncb1 <=#Tp ReadTxDataFromFifo_sync2;
8243
end
8244
 
8245
always @ (posedge MTxClk or posedge Reset)
8246
begin
8247
  if(Reset)
8248
    ReadTxDataFromFifo_syncb2 <=#Tp 1'b0;
8249
  else
8250
    ReadTxDataFromFifo_syncb2 <=#Tp ReadTxDataFromFifo_syncb1;
8251
end
8252
 
8253
always @ (posedge MTxClk or posedge Reset)
8254
begin
8255
  if(Reset)
8256
    ReadTxDataFromFifo_syncb3 <=#Tp 1'b0;
8257
  else
8258
    ReadTxDataFromFifo_syncb3 <=#Tp ReadTxDataFromFifo_syncb2;
8259
end
8260
 
8261
always @ (posedge WB_CLK_I or posedge Reset)
8262
begin
8263
  if(Reset)
8264
    ReadTxDataFromFifo_sync3 <=#Tp 1'b0;
8265
  else
8266
    ReadTxDataFromFifo_sync3 <=#Tp ReadTxDataFromFifo_sync2;
8267
end
8268
 
8269
assign ReadTxDataFromFifo_wb = ReadTxDataFromFifo_sync2 & ~ReadTxDataFromFifo_sync3;
8270
// End: Generation of the ReadTxDataFromFifo_tck signal and synchronization to the WB_CLK_I
8271
 
8272
 
8273
// Synchronizing TxRetry signal (synchronized to WISHBONE clock)
8274
always @ (posedge WB_CLK_I or posedge Reset)
8275
begin
8276
  if(Reset)
8277
    TxRetrySync1 <=#Tp 1'b0;
8278
  else
8279
    TxRetrySync1 <=#Tp TxRetry;
8280
end
8281
 
8282
always @ (posedge WB_CLK_I or posedge Reset)
8283
begin
8284
  if(Reset)
8285
    TxRetry_wb <=#Tp 1'b0;
8286
  else
8287
    TxRetry_wb <=#Tp TxRetrySync1;
8288
end
8289
 
8290
 
8291
// Synchronized TxDone_wb signal (synchronized to WISHBONE clock)
8292
always @ (posedge WB_CLK_I or posedge Reset)
8293
begin
8294
  if(Reset)
8295
    TxDoneSync1 <=#Tp 1'b0;
8296
  else
8297
    TxDoneSync1 <=#Tp TxDone;
8298
end
8299
 
8300
always @ (posedge WB_CLK_I or posedge Reset)
8301
begin
8302
  if(Reset)
8303
    TxDone_wb <=#Tp 1'b0;
8304
  else
8305
    TxDone_wb <=#Tp TxDoneSync1;
8306
end
8307
 
8308
// Synchronizing TxAbort signal (synchronized to WISHBONE clock)
8309
always @ (posedge WB_CLK_I or posedge Reset)
8310
begin
8311
  if(Reset)
8312
    TxAbortSync1 <=#Tp 1'b0;
8313
  else
8314
    TxAbortSync1 <=#Tp TxAbort;
8315
end
8316
 
8317
always @ (posedge WB_CLK_I or posedge Reset)
8318
begin
8319
  if(Reset)
8320
    TxAbort_wb <=#Tp 1'b0;
8321
  else
8322
    TxAbort_wb <=#Tp TxAbortSync1;
8323
end
8324
 
8325
 
8326
reg RxAbortSync1;
8327
reg RxAbortSync2;
8328
reg RxAbortSync3;
8329
reg RxAbortSync4;
8330
reg RxAbortSyncb1;
8331
reg RxAbortSyncb2;
8332
 
8333
assign StartRxBDRead = RxStatusWrite | RxAbortSync3 & ~RxAbortSync4 | r_RxEn & ~r_RxEn_q;
8334
 
8335
// Reading the Rx buffer descriptor
8336
always @ (posedge WB_CLK_I or posedge Reset)
8337
begin
8338
  if(Reset)
8339
    RxBDRead <=#Tp 1'b0;
8340
  else
8341
  if(StartRxBDRead & ~RxReady)
8342
    RxBDRead <=#Tp 1'b1;
8343
  else
8344
  if(RxBDReady)
8345
    RxBDRead <=#Tp 1'b0;
8346
end
8347
 
8348
 
8349
// Reading of the next receive buffer descriptor starts after reception status is
8350
// written to the previous one.
8351
 
8352
// Latching READY status of the Rx buffer descriptor
8353
always @ (posedge WB_CLK_I or posedge Reset)
8354
begin
8355
  if(Reset)
8356
    RxBDReady <=#Tp 1'b0;
8357
  else
8358
  if(RxPointerRead)
8359
    RxBDReady <=#Tp 1'b0;
8360
  else
8361
  if(RxEn & RxEn_q & RxBDRead)
8362
    RxBDReady <=#Tp ram_do[15]; // RxBDReady is sampled only once at the beginning
8363
end
8364
 
8365
// Latching Rx buffer descriptor status
8366
// Data is avaliable one cycle after the access is started (at that time signal RxEn is not active)
8367
always @ (posedge WB_CLK_I or posedge Reset)
8368
begin
8369
  if(Reset)
8370
    RxStatus <=#Tp 2'h0;
8371
  else
8372
  if(RxEn & RxEn_q & RxBDRead)
8373
    RxStatus <=#Tp ram_do[14:13];
8374
end
8375
 
8376
 
8377
// RxReady generation
8378
always @ (posedge WB_CLK_I or posedge Reset)
8379
begin
8380
  if(Reset)
8381
    RxReady <=#Tp 1'b0;
8382
  else
8383
  if(ShiftEnded | RxAbortSync2 & ~RxAbortSync3 | ~r_RxEn & r_RxEn_q)
8384
    RxReady <=#Tp 1'b0;
8385
  else
8386
  if(RxEn & RxEn_q & RxPointerRead)
8387
    RxReady <=#Tp 1'b1;
8388
end
8389
 
8390
 
8391
// Reading Rx BD pointer
8392
 
8393
 
8394
assign StartRxPointerRead = RxBDRead & RxBDReady;
8395
 
8396
// Reading Tx BD Pointer
8397
always @ (posedge WB_CLK_I or posedge Reset)
8398
begin
8399
  if(Reset)
8400
    RxPointerRead <=#Tp 1'b0;
8401
  else
8402
  if(StartRxPointerRead)
8403
    RxPointerRead <=#Tp 1'b1;
8404
  else
8405
  if(RxEn & RxEn_q)
8406
    RxPointerRead <=#Tp 1'b0;
8407
end
8408
 
8409
 
8410
//Latching Rx buffer pointer from buffer descriptor;
8411
always @ (posedge WB_CLK_I or posedge Reset)
8412
begin
8413
  if(Reset)
8414
    RxPointerMSB <=#Tp 30'h0;
8415
  else
8416
  if(RxEn & RxEn_q & RxPointerRead)
8417
    RxPointerMSB <=#Tp ram_do[31:2];
8418
  else
8419
  if(MasterWbRX & m_wb_ack_i)
8420
      RxPointerMSB <=#Tp RxPointerMSB + 1'b1; // Word access  (always word access. m_wb_sel_o are used for selecting bytes)
8421
end
8422
 
8423
 
8424
//Latching last addresses from buffer descriptor (used as byte-half-word indicator);
8425
always @ (posedge WB_CLK_I or posedge Reset)
8426
begin
8427
  if(Reset)
8428
    RxPointerLSB_rst[1:0] <=#Tp 0;
8429
  else
8430
  if(MasterWbRX & m_wb_ack_i)                 // After first write all RxByteSel are active
8431
    RxPointerLSB_rst[1:0] <=#Tp 0;
8432
  else
8433
  if(RxEn & RxEn_q & RxPointerRead)
8434
    RxPointerLSB_rst[1:0] <=#Tp ram_do[1:0];
8435
end
8436
 
8437
 
8438
always @ (RxPointerLSB_rst)
8439
begin
8440
  case(RxPointerLSB_rst[1:0])  // synopsys parallel_case
8441
    2'h0 : RxByteSel[3:0] = 4'hf;
8442
    2'h1 : RxByteSel[3:0] = 4'h7;
8443
    2'h2 : RxByteSel[3:0] = 4'h3;
8444
    2'h3 : RxByteSel[3:0] = 4'h1;
8445
  endcase
8446
end
8447
 
8448
 
8449
always @ (posedge WB_CLK_I or posedge Reset)
8450
begin
8451
  if(Reset)
8452
    RxEn_needed <=#Tp 1'b0;
8453
  else
8454
  if(~RxReady & r_RxEn & WbEn & ~WbEn_q)
8455
    RxEn_needed <=#Tp 1'b1;
8456
  else
8457
  if(RxPointerRead & RxEn & RxEn_q)
8458
    RxEn_needed <=#Tp 1'b0;
8459
end
8460
 
8461
 
8462
// Reception status is written back to the buffer descriptor after the end of frame is detected.
8463
assign RxStatusWrite = ShiftEnded & RxEn & RxEn_q;
8464
 
8465
reg RxEnableWindow;
8466
 
8467
// Indicating that last byte is being reveived
8468
always @ (posedge MRxClk or posedge Reset)
8469
begin
8470
  if(Reset)
8471
    LastByteIn <=#Tp 1'b0;
8472
  else
8473
  if(ShiftWillEnd & (&RxByteCnt) | RxAbort)
8474
    LastByteIn <=#Tp 1'b0;
8475
  else
8476
  if(RxValid & RxReady & RxEndFrm & ~(&RxByteCnt) & RxEnableWindow)
8477
    LastByteIn <=#Tp 1'b1;
8478
end
8479
 
8480
reg ShiftEnded_rck;
8481
reg ShiftEndedSync1;
8482
reg ShiftEndedSync2;
8483
reg ShiftEndedSync3;
8484
reg ShiftEndedSync_c1;
8485
reg ShiftEndedSync_c2;
8486
 
8487
wire StartShiftWillEnd;
8488
assign StartShiftWillEnd = LastByteIn  | RxValid & RxEndFrm & (&RxByteCnt) & RxEnableWindow;
8489
 
8490
// Indicating that data reception will end
8491
always @ (posedge MRxClk or posedge Reset)
8492
begin
8493
  if(Reset)
8494
    ShiftWillEnd <=#Tp 1'b0;
8495
  else
8496
  if(ShiftEnded_rck | RxAbort)
8497
    ShiftWillEnd <=#Tp 1'b0;
8498
  else
8499
  if(StartShiftWillEnd)
8500
    ShiftWillEnd <=#Tp 1'b1;
8501
end
8502
 
8503
 
8504
 
8505
// Receive byte counter
8506
always @ (posedge MRxClk or posedge Reset)
8507
begin
8508
  if(Reset)
8509
    RxByteCnt <=#Tp 2'h0;
8510
  else
8511
  if(ShiftEnded_rck | RxAbort)
8512
    RxByteCnt <=#Tp 2'h0;
8513
  else
8514
  if(RxValid & RxStartFrm & RxReady)
8515
    case(RxPointerLSB_rst)  // synopsys parallel_case
8516
      2'h0 : RxByteCnt <=#Tp 2'h1;
8517
      2'h1 : RxByteCnt <=#Tp 2'h2;
8518
      2'h2 : RxByteCnt <=#Tp 2'h3;
8519
      2'h3 : RxByteCnt <=#Tp 2'h0;
8520
    endcase
8521
  else
8522
  if(RxValid & RxEnableWindow & RxReady | LastByteIn)
8523
    RxByteCnt <=#Tp RxByteCnt + 1'b1;
8524
end
8525
 
8526
 
8527
// Indicates how many bytes are valid within the last word
8528
always @ (posedge MRxClk or posedge Reset)
8529
begin
8530
  if(Reset)
8531
    RxValidBytes <=#Tp 2'h1;
8532
  else
8533
  if(RxValid & RxStartFrm)
8534
    case(RxPointerLSB_rst)  // synopsys parallel_case
8535
      2'h0 : RxValidBytes <=#Tp 2'h1;
8536
      2'h1 : RxValidBytes <=#Tp 2'h2;
8537
      2'h2 : RxValidBytes <=#Tp 2'h3;
8538
      2'h3 : RxValidBytes <=#Tp 2'h0;
8539
    endcase
8540
  else
8541
  if(RxValid & ~LastByteIn & ~RxStartFrm & RxEnableWindow)
8542
    RxValidBytes <=#Tp RxValidBytes + 1'b1;
8543
end
8544
 
8545
 
8546
always @ (posedge MRxClk or posedge Reset)
8547
begin
8548
  if(Reset)
8549
    RxDataLatched1       <=#Tp 24'h0;
8550
  else
8551
  if(RxValid & RxReady & ~LastByteIn)
8552
    if(RxStartFrm)
8553
    begin
8554
      case(RxPointerLSB_rst)     // synopsys parallel_case
8555
        2'h0:        RxDataLatched1[31:24] <=#Tp RxData;            // Big Endian Byte Ordering
8556
        2'h1:        RxDataLatched1[23:16] <=#Tp RxData;
8557
        2'h2:        RxDataLatched1[15:8]  <=#Tp RxData;
8558
        2'h3:        RxDataLatched1        <=#Tp RxDataLatched1;
8559
      endcase
8560
    end
8561
    else if (RxEnableWindow)
8562
    begin
8563
      case(RxByteCnt)     // synopsys parallel_case
8564
        2'h0:        RxDataLatched1[31:24] <=#Tp RxData;            // Big Endian Byte Ordering
8565
        2'h1:        RxDataLatched1[23:16] <=#Tp RxData;
8566
        2'h2:        RxDataLatched1[15:8]  <=#Tp RxData;
8567
        2'h3:        RxDataLatched1        <=#Tp RxDataLatched1;
8568
      endcase
8569
    end
8570
end
8571
 
8572
wire SetWriteRxDataToFifo;
8573
 
8574
// Assembling data that will be written to the rx_fifo
8575
always @ (posedge MRxClk or posedge Reset)
8576
begin
8577
  if(Reset)
8578
    RxDataLatched2 <=#Tp 32'h0;
8579
  else
8580
  if(SetWriteRxDataToFifo & ~ShiftWillEnd)
8581
    RxDataLatched2 <=#Tp {RxDataLatched1[31:8], RxData};              // Big Endian Byte Ordering
8582
  else
8583
  if(SetWriteRxDataToFifo & ShiftWillEnd)
8584
    case(RxValidBytes)  // synopsys parallel_case
8585
 
8586
      1 : RxDataLatched2 <=#Tp {RxDataLatched1[31:24], 24'h0};
8587
      2 : RxDataLatched2 <=#Tp {RxDataLatched1[31:16], 16'h0};
8588
      3 : RxDataLatched2 <=#Tp {RxDataLatched1[31:8],   8'h0};
8589
    endcase
8590
end
8591
 
8592
 
8593
reg WriteRxDataToFifoSync1;
8594
reg WriteRxDataToFifoSync2;
8595
reg WriteRxDataToFifoSync3;
8596
 
8597
 
8598
// Indicating start of the reception process
8599
assign SetWriteRxDataToFifo = (RxValid & RxReady & ~RxStartFrm & RxEnableWindow & (&RxByteCnt)) |
8600
                              (RxValid & RxReady &  RxStartFrm & (&RxPointerLSB_rst))           |
8601
                              (ShiftWillEnd & LastByteIn & (&RxByteCnt));
8602
 
8603
always @ (posedge MRxClk or posedge Reset)
8604
begin
8605
  if(Reset)
8606
    WriteRxDataToFifo <=#Tp 1'b0;
8607
  else
8608
  if(SetWriteRxDataToFifo & ~RxAbort)
8609
    WriteRxDataToFifo <=#Tp 1'b1;
8610
  else
8611
  if(WriteRxDataToFifoSync2 | RxAbort)
8612
    WriteRxDataToFifo <=#Tp 1'b0;
8613
end
8614
 
8615
 
8616
 
8617
always @ (posedge WB_CLK_I or posedge Reset)
8618
begin
8619
  if(Reset)
8620
    WriteRxDataToFifoSync1 <=#Tp 1'b0;
8621
  else
8622
  if(WriteRxDataToFifo)
8623
    WriteRxDataToFifoSync1 <=#Tp 1'b1;
8624
  else
8625
    WriteRxDataToFifoSync1 <=#Tp 1'b0;
8626
end
8627
 
8628
always @ (posedge WB_CLK_I or posedge Reset)
8629
begin
8630
  if(Reset)
8631
    WriteRxDataToFifoSync2 <=#Tp 1'b0;
8632
  else
8633
    WriteRxDataToFifoSync2 <=#Tp WriteRxDataToFifoSync1;
8634
end
8635
 
8636
always @ (posedge WB_CLK_I or posedge Reset)
8637
begin
8638
  if(Reset)
8639
    WriteRxDataToFifoSync3 <=#Tp 1'b0;
8640
  else
8641
    WriteRxDataToFifoSync3 <=#Tp WriteRxDataToFifoSync2;
8642
end
8643
 
8644
wire WriteRxDataToFifo_wb;
8645
assign WriteRxDataToFifo_wb = WriteRxDataToFifoSync2 & ~WriteRxDataToFifoSync3;
8646
 
8647
 
8648
reg LatchedRxStartFrm;
8649
reg SyncRxStartFrm;
8650
reg SyncRxStartFrm_q;
8651
reg SyncRxStartFrm_q2;
8652
wire RxFifoReset;
8653
 
8654
always @ (posedge MRxClk or posedge Reset)
8655
begin
8656
  if(Reset)
8657
    LatchedRxStartFrm <=#Tp 0;
8658
  else
8659
  if(RxStartFrm & ~SyncRxStartFrm_q)
8660
    LatchedRxStartFrm <=#Tp 1;
8661
  else
8662
  if(SyncRxStartFrm_q)
8663
    LatchedRxStartFrm <=#Tp 0;
8664
end
8665
 
8666
 
8667
always @ (posedge WB_CLK_I or posedge Reset)
8668
begin
8669
  if(Reset)
8670
    SyncRxStartFrm <=#Tp 0;
8671
  else
8672
  if(LatchedRxStartFrm)
8673
    SyncRxStartFrm <=#Tp 1;
8674
  else
8675
    SyncRxStartFrm <=#Tp 0;
8676
end
8677
 
8678
 
8679
always @ (posedge WB_CLK_I or posedge Reset)
8680
begin
8681
  if(Reset)
8682
    SyncRxStartFrm_q <=#Tp 0;
8683
  else
8684
    SyncRxStartFrm_q <=#Tp SyncRxStartFrm;
8685
end
8686
 
8687
always @ (posedge WB_CLK_I or posedge Reset)
8688
begin
8689
  if(Reset)
8690
    SyncRxStartFrm_q2 <=#Tp 0;
8691
  else
8692
    SyncRxStartFrm_q2 <=#Tp SyncRxStartFrm_q;
8693
end
8694
 
8695
 
8696
assign RxFifoReset = SyncRxStartFrm_q & ~SyncRxStartFrm_q2;
8697
 
8698
 
8699
eth_fifo #(`ETH_RX_FIFO_DATA_WIDTH, `ETH_RX_FIFO_DEPTH, `ETH_RX_FIFO_CNT_WIDTH)
8700
rx_fifo (.data_in(RxDataLatched2),                      .data_out(m_wb_dat_o),
8701
         .clk(WB_CLK_I),                                .reset(Reset),
8702
         .write(WriteRxDataToFifo_wb & ~RxBufferFull),  .read(MasterWbRX & m_wb_ack_i),
8703
         .clear(RxFifoReset),                           .full(RxBufferFull),
8704
         .almost_full(),                                .almost_empty(RxBufferAlmostEmpty),
8705
         .empty(RxBufferEmpty),                         .cnt(rxfifo_cnt)
8706
        );
8707
 
8708
assign enough_data_in_rxfifo_for_burst = rxfifo_cnt>=`ETH_BURST_LENGTH;
8709
assign enough_data_in_rxfifo_for_burst_plus1 = rxfifo_cnt>`ETH_BURST_LENGTH;
8710
assign WriteRxDataToMemory = ~RxBufferEmpty;
8711
assign rx_burst = rx_burst_en & WriteRxDataToMemory;
8712
 
8713
 
8714
// Generation of the end-of-frame signal
8715
always @ (posedge MRxClk or posedge Reset)
8716
begin
8717
  if(Reset)
8718
    ShiftEnded_rck <=#Tp 1'b0;
8719
  else
8720
  if(~RxAbort & SetWriteRxDataToFifo & StartShiftWillEnd)
8721
    ShiftEnded_rck <=#Tp 1'b1;
8722
  else
8723
  if(RxAbort | ShiftEndedSync_c1 & ShiftEndedSync_c2)
8724
    ShiftEnded_rck <=#Tp 1'b0;
8725
end
8726
 
8727
always @ (posedge WB_CLK_I or posedge Reset)
8728
begin
8729
  if(Reset)
8730
    ShiftEndedSync1 <=#Tp 1'b0;
8731
  else
8732
    ShiftEndedSync1 <=#Tp ShiftEnded_rck;
8733
end
8734
 
8735
always @ (posedge WB_CLK_I or posedge Reset)
8736
begin
8737
  if(Reset)
8738
    ShiftEndedSync2 <=#Tp 1'b0;
8739
  else
8740
    ShiftEndedSync2 <=#Tp ShiftEndedSync1;
8741
end
8742
 
8743
always @ (posedge WB_CLK_I or posedge Reset)
8744
begin
8745
  if(Reset)
8746
    ShiftEndedSync3 <=#Tp 1'b0;
8747
  else
8748
  if(ShiftEndedSync1 & ~ShiftEndedSync2)
8749
    ShiftEndedSync3 <=#Tp 1'b1;
8750
  else
8751
  if(ShiftEnded)
8752
    ShiftEndedSync3 <=#Tp 1'b0;
8753
end
8754
 
8755
// Generation of the end-of-frame signal
8756
always @ (posedge WB_CLK_I or posedge Reset)
8757
begin
8758
  if(Reset)
8759
    ShiftEnded <=#Tp 1'b0;
8760
  else
8761
  if(ShiftEndedSync3 & MasterWbRX & m_wb_ack_i & RxBufferAlmostEmpty & ~ShiftEnded)
8762
    ShiftEnded <=#Tp 1'b1;
8763
  else
8764
  if(RxStatusWrite)
8765
    ShiftEnded <=#Tp 1'b0;
8766
end
8767
 
8768
always @ (posedge MRxClk or posedge Reset)
8769
begin
8770
  if(Reset)
8771
    ShiftEndedSync_c1 <=#Tp 1'b0;
8772
  else
8773
    ShiftEndedSync_c1 <=#Tp ShiftEndedSync2;
8774
end
8775
 
8776
always @ (posedge MRxClk or posedge Reset)
8777
begin
8778
  if(Reset)
8779
    ShiftEndedSync_c2 <=#Tp 1'b0;
8780
  else
8781
    ShiftEndedSync_c2 <=#Tp ShiftEndedSync_c1;
8782
end
8783
 
8784
// Generation of the end-of-frame signal
8785
always @ (posedge MRxClk or posedge Reset)
8786
begin
8787
  if(Reset)
8788
    RxEnableWindow <=#Tp 1'b0;
8789
  else
8790
  if(RxStartFrm)
8791
    RxEnableWindow <=#Tp 1'b1;
8792
  else
8793
  if(RxEndFrm | RxAbort)
8794
    RxEnableWindow <=#Tp 1'b0;
8795
end
8796
 
8797
 
8798
always @ (posedge WB_CLK_I or posedge Reset)
8799
begin
8800
  if(Reset)
8801
    RxAbortSync1 <=#Tp 1'b0;
8802
  else
8803
    RxAbortSync1 <=#Tp RxAbortLatched;
8804
end
8805
 
8806
always @ (posedge WB_CLK_I or posedge Reset)
8807
begin
8808
  if(Reset)
8809
    RxAbortSync2 <=#Tp 1'b0;
8810
  else
8811
    RxAbortSync2 <=#Tp RxAbortSync1;
8812
end
8813
 
8814
always @ (posedge WB_CLK_I or posedge Reset)
8815
begin
8816
  if(Reset)
8817
    RxAbortSync3 <=#Tp 1'b0;
8818
  else
8819
    RxAbortSync3 <=#Tp RxAbortSync2;
8820
end
8821
 
8822
always @ (posedge WB_CLK_I or posedge Reset)
8823
begin
8824
  if(Reset)
8825
    RxAbortSync4 <=#Tp 1'b0;
8826
  else
8827
    RxAbortSync4 <=#Tp RxAbortSync3;
8828
end
8829
 
8830
always @ (posedge MRxClk or posedge Reset)
8831
begin
8832
  if(Reset)
8833
    RxAbortSyncb1 <=#Tp 1'b0;
8834
  else
8835
    RxAbortSyncb1 <=#Tp RxAbortSync2;
8836
end
8837
 
8838
always @ (posedge MRxClk or posedge Reset)
8839
begin
8840
  if(Reset)
8841
    RxAbortSyncb2 <=#Tp 1'b0;
8842
  else
8843
    RxAbortSyncb2 <=#Tp RxAbortSyncb1;
8844
end
8845
 
8846
 
8847
always @ (posedge MRxClk or posedge Reset)
8848
begin
8849
  if(Reset)
8850
    RxAbortLatched <=#Tp 1'b0;
8851
  else
8852
  if(RxAbortSyncb2)
8853
    RxAbortLatched <=#Tp 1'b0;
8854
  else
8855
  if(RxAbort)
8856
    RxAbortLatched <=#Tp 1'b1;
8857
end
8858
 
8859
 
8860
always @ (posedge MRxClk or posedge Reset)
8861
begin
8862
  if(Reset)
8863
    LatchedRxLength[15:0] <=#Tp 16'h0;
8864
  else
8865
  if(LoadRxStatus)
8866
    LatchedRxLength[15:0] <=#Tp RxLength[15:0];
8867
end
8868
 
8869
 
8870
assign RxStatusIn = {ReceivedPauseFrm, AddressMiss, RxOverrun, InvalidSymbol, DribbleNibble, ReceivedPacketTooBig, ShortFrame, LatchedCrcError, RxLateCollision};
8871
 
8872
always @ (posedge MRxClk or posedge Reset)
8873
begin
8874
  if(Reset)
8875
    RxStatusInLatched <=#Tp 'h0;
8876
  else
8877
  if(LoadRxStatus)
8878
    RxStatusInLatched <=#Tp RxStatusIn;
8879
end
8880
 
8881
 
8882
// Rx overrun
8883
always @ (posedge WB_CLK_I or posedge Reset)
8884
begin
8885
  if(Reset)
8886
    RxOverrun <=#Tp 1'b0;
8887
  else
8888
  if(RxStatusWrite)
8889
    RxOverrun <=#Tp 1'b0;
8890
  else
8891
  if(RxBufferFull & WriteRxDataToFifo_wb)
8892
    RxOverrun <=#Tp 1'b1;
8893
end
8894
 
8895
 
8896
 
8897
wire TxError;
8898
assign TxError = TxUnderRun | RetryLimit | LateCollLatched | CarrierSenseLost;
8899
 
8900
wire RxError;
8901
 
8902
// ShortFrame (RxStatusInLatched[2]) can not set an error because short frames
8903
// are aborted when signal r_RecSmall is set to 0 in MODER register. 
8904
// AddressMiss is identifying that a frame was received because of the promiscous
8905
// mode and is not an error
8906
assign RxError = (|RxStatusInLatched[6:3]) | (|RxStatusInLatched[1:0]);
8907
 
8908
 
8909
 
8910
reg RxStatusWriteLatched;
8911
reg RxStatusWriteLatched_sync1;
8912
reg RxStatusWriteLatched_sync2;
8913
reg RxStatusWriteLatched_syncb1;
8914
reg RxStatusWriteLatched_syncb2;
8915
 
8916
 
8917
// Latching and synchronizing RxStatusWrite signal. This signal is used for clearing the ReceivedPauseFrm signal
8918
always @ (posedge WB_CLK_I or posedge Reset)
8919
begin
8920
  if(Reset)
8921
    RxStatusWriteLatched <=#Tp 1'b0;
8922
  else
8923
  if(RxStatusWriteLatched_syncb2)
8924
    RxStatusWriteLatched <=#Tp 1'b0;
8925
  else
8926
  if(RxStatusWrite)
8927
    RxStatusWriteLatched <=#Tp 1'b1;
8928
end
8929
 
8930
 
8931
always @ (posedge MRxClk or posedge Reset)
8932
begin
8933
  if(Reset)
8934
    begin
8935
      RxStatusWriteLatched_sync1 <=#Tp 1'b0;
8936
      RxStatusWriteLatched_sync2 <=#Tp 1'b0;
8937
    end
8938
  else
8939
    begin
8940
      RxStatusWriteLatched_sync1 <=#Tp RxStatusWriteLatched;
8941
      RxStatusWriteLatched_sync2 <=#Tp RxStatusWriteLatched_sync1;
8942
    end
8943
end
8944
 
8945
 
8946
always @ (posedge WB_CLK_I or posedge Reset)
8947
begin
8948
  if(Reset)
8949
    begin
8950
      RxStatusWriteLatched_syncb1 <=#Tp 1'b0;
8951
      RxStatusWriteLatched_syncb2 <=#Tp 1'b0;
8952
    end
8953
  else
8954
    begin
8955
      RxStatusWriteLatched_syncb1 <=#Tp RxStatusWriteLatched_sync2;
8956
      RxStatusWriteLatched_syncb2 <=#Tp RxStatusWriteLatched_syncb1;
8957
    end
8958
end
8959
 
8960
 
8961
 
8962
// Tx Done Interrupt
8963
always @ (posedge WB_CLK_I or posedge Reset)
8964
begin
8965
  if(Reset)
8966
    TxB_IRQ <=#Tp 1'b0;
8967
  else
8968
  if(TxStatusWrite & TxIRQEn)
8969
    TxB_IRQ <=#Tp ~TxError;
8970
  else
8971
    TxB_IRQ <=#Tp 1'b0;
8972
end
8973
 
8974
 
8975
// Tx Error Interrupt
8976
always @ (posedge WB_CLK_I or posedge Reset)
8977
begin
8978
  if(Reset)
8979
    TxE_IRQ <=#Tp 1'b0;
8980
  else
8981
  if(TxStatusWrite & TxIRQEn)
8982
    TxE_IRQ <=#Tp TxError;
8983
  else
8984
    TxE_IRQ <=#Tp 1'b0;
8985
end
8986
 
8987
 
8988
// Rx Done Interrupt
8989
always @ (posedge WB_CLK_I or posedge Reset)
8990
begin
8991
  if(Reset)
8992
    RxB_IRQ <=#Tp 1'b0;
8993
  else
8994
  if(RxStatusWrite & RxIRQEn & ReceivedPacketGood & (~ReceivedPauseFrm | ReceivedPauseFrm & r_PassAll & (~r_RxFlow)))
8995
    RxB_IRQ <=#Tp (~RxError);
8996
  else
8997
    RxB_IRQ <=#Tp 1'b0;
8998
end
8999
 
9000
 
9001
// Rx Error Interrupt
9002
always @ (posedge WB_CLK_I or posedge Reset)
9003
begin
9004
  if(Reset)
9005
    RxE_IRQ <=#Tp 1'b0;
9006
  else
9007
  if(RxStatusWrite & RxIRQEn & (~ReceivedPauseFrm | ReceivedPauseFrm & r_PassAll & (~r_RxFlow)))
9008
    RxE_IRQ <=#Tp RxError;
9009
  else
9010
    RxE_IRQ <=#Tp 1'b0;
9011
end
9012
 
9013
 
9014
// Busy Interrupt
9015
 
9016
reg Busy_IRQ_rck;
9017
reg Busy_IRQ_sync1;
9018
reg Busy_IRQ_sync2;
9019
reg Busy_IRQ_sync3;
9020
reg Busy_IRQ_syncb1;
9021
reg Busy_IRQ_syncb2;
9022
 
9023
 
9024
always @ (posedge MRxClk or posedge Reset)
9025
begin
9026
  if(Reset)
9027
    Busy_IRQ_rck <=#Tp 1'b0;
9028
  else
9029
  if(RxValid & RxStartFrm & ~RxReady)
9030
    Busy_IRQ_rck <=#Tp 1'b1;
9031
  else
9032
  if(Busy_IRQ_syncb2)
9033
    Busy_IRQ_rck <=#Tp 1'b0;
9034
end
9035
 
9036
always @ (posedge WB_CLK_I)
9037
begin
9038
    Busy_IRQ_sync1 <=#Tp Busy_IRQ_rck;
9039
    Busy_IRQ_sync2 <=#Tp Busy_IRQ_sync1;
9040
    Busy_IRQ_sync3 <=#Tp Busy_IRQ_sync2;
9041
end
9042
 
9043
always @ (posedge MRxClk)
9044
begin
9045
    Busy_IRQ_syncb1 <=#Tp Busy_IRQ_sync2;
9046
    Busy_IRQ_syncb2 <=#Tp Busy_IRQ_syncb1;
9047
end
9048
 
9049
assign Busy_IRQ = Busy_IRQ_sync2 & ~Busy_IRQ_sync3;
9050
 
9051
 
9052
 
9053
 
9054
 
9055
endmodule
9056
//////////////////////////////////////////////////////////////////////
9057
////                                                              ////
9058
////  eth_top.v                                                   ////
9059
////                                                              ////
9060
////  This file is part of the Ethernet IP core project           ////
9061
////  http://www.opencores.org/projects/ethmac/                   ////
9062
////                                                              ////
9063
////  Author(s):                                                  ////
9064
////      - Igor Mohor (igorM@opencores.org)                      ////
9065
////                                                              ////
9066
////  All additional information is available in the Readme.txt   ////
9067
////  file.                                                       ////
9068
////                                                              ////
9069
//////////////////////////////////////////////////////////////////////
9070
////                                                              ////
9071
//// Copyright (C) 2001, 2002 Authors                             ////
9072
////                                                              ////
9073
//// This source file may be used and distributed without         ////
9074
//// restriction provided that this copyright statement is not    ////
9075
//// removed from the file and that any derivative work contains  ////
9076
//// the original copyright notice and the associated disclaimer. ////
9077
////                                                              ////
9078
//// This source file is free software; you can redistribute it   ////
9079
//// and/or modify it under the terms of the GNU Lesser General   ////
9080
//// Public License as published by the Free Software Foundation; ////
9081
//// either version 2.1 of the License, or (at your option) any   ////
9082
//// later version.                                               ////
9083
////                                                              ////
9084
//// This source is distributed in the hope that it will be       ////
9085
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
9086
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
9087
//// PURPOSE.  See the GNU Lesser General Public License for more ////
9088
//// details.                                                     ////
9089
////                                                              ////
9090
//// You should have received a copy of the GNU Lesser General    ////
9091
//// Public License along with this source; if not, download it   ////
9092
//// from http://www.opencores.org/lgpl.shtml                     ////
9093
////                                                              ////
9094
//////////////////////////////////////////////////////////////////////
9095
//
9096
// CVS Revision History
9097
//
9098
// $Log: eth_top.v,v $
9099
// Revision 1.52  2005/03/21 20:07:18  igorm
9100
// Some small fixes + some troubles fixed.
9101
//
9102
// Revision 1.51  2005/02/21 11:13:17  igorm
9103
// Defer indication fixed.
9104
//
9105
// Revision 1.50  2004/04/26 15:26:23  igorm
9106
// - Bug connected to the TX_BD_NUM_Wr signal fixed (bug came in with the
9107
//   previous update of the core.
9108
// - TxBDAddress is set to 0 after the TX is enabled in the MODER register.
9109
// - RxBDAddress is set to r_TxBDNum<<1 after the RX is enabled in the MODER
9110
//   register. (thanks to Mathias and Torbjorn)
9111
// - Multicast reception was fixed. Thanks to Ulrich Gries
9112
//
9113
// Revision 1.49  2003/11/12 18:24:59  tadejm
9114
// WISHBONE slave changed and tested from only 32-bit accesss to byte access.
9115
//
9116
// Revision 1.48  2003/10/17 07:46:16  markom
9117
// mbist signals updated according to newest convention
9118
//
9119
// Revision 1.47  2003/10/06 15:43:45  knguyen
9120
// Update RxEnSync only when mrxdv_pad_i is inactive (LOW).
9121
//
9122
// Revision 1.46  2003/01/30 13:30:22  tadejm
9123
// Defer indication changed.
9124
//
9125
// Revision 1.45  2003/01/22 13:49:26  tadejm
9126
// When control packets were received, they were ignored in some cases.
9127
//
9128
// Revision 1.44  2003/01/21 12:09:40  mohor
9129
// When receiving normal data frame and RxFlow control was switched on, RXB
9130
// interrupt was not set.
9131
//
9132
// Revision 1.43  2002/11/22 01:57:06  mohor
9133
// Rx Flow control fixed. CF flag added to the RX buffer descriptor. RxAbort
9134
// synchronized.
9135
//
9136
// Revision 1.42  2002/11/21 00:09:19  mohor
9137
// TPauseRq synchronized to tx_clk.
9138
//
9139
// Revision 1.41  2002/11/19 18:13:49  mohor
9140
// r_MiiMRst is not used for resetting the MIIM module. wb_rst used instead.
9141
//
9142
// Revision 1.40  2002/11/19 17:34:25  mohor
9143
// AddressMiss status is connecting to the Rx BD. AddressMiss is identifying
9144
// that a frame was received because of the promiscous mode.
9145
//
9146
// Revision 1.39  2002/11/18 17:31:55  mohor
9147
// wb_rst_i is used for MIIM reset.
9148
//
9149
// Revision 1.38  2002/11/14 18:37:20  mohor
9150
// r_Rst signal does not reset any module any more and is removed from the design.
9151
//
9152
// Revision 1.37  2002/11/13 22:25:36  tadejm
9153
// All modules are reset with wb_rst instead of the r_Rst. Exception is MII module.
9154
//
9155
// Revision 1.36  2002/10/18 17:04:20  tadejm
9156
// Changed BIST scan signals.
9157
//
9158
// Revision 1.35  2002/10/11 13:36:58  mohor
9159
// Typo error fixed. (When using Bist)
9160
//
9161
// Revision 1.34  2002/10/10 16:49:50  mohor
9162
// Signals for WISHBONE B3 compliant interface added.
9163
//
9164
// Revision 1.33  2002/10/10 16:29:30  mohor
9165
// BIST added.
9166
//
9167
// Revision 1.32  2002/09/20 17:12:58  mohor
9168
// CsMiss added. When address between 0x800 and 0xfff is accessed within
9169
// Ethernet Core, error acknowledge is generated.
9170
//
9171
// Revision 1.31  2002/09/12 14:50:17  mohor
9172
// CarrierSenseLost bug fixed when operating in full duplex mode.
9173
//
9174
// Revision 1.30  2002/09/10 10:35:23  mohor
9175
// Ethernet debug registers removed.
9176
//
9177
// Revision 1.29  2002/09/09 13:03:13  mohor
9178
// Error acknowledge is generated when accessing BDs and RST bit in the
9179
// MODER register (r_Rst) is set.
9180
//
9181
// Revision 1.28  2002/09/04 18:44:10  mohor
9182
// Signals related to the control frames connected. Debug registers reg1, 2, 3, 4
9183
// connected.
9184
//
9185
// Revision 1.27  2002/07/25 18:15:37  mohor
9186
// RxAbort changed. Packets received with MRxErr (from PHY) are also
9187
// aborted.
9188
//
9189
// Revision 1.26  2002/07/17 18:51:50  mohor
9190
// EXTERNAL_DMA removed. External DMA not supported.
9191
//
9192
// Revision 1.25  2002/05/03 10:15:50  mohor
9193
// Outputs registered. Reset changed for eth_wishbone module.
9194
//
9195
// Revision 1.24  2002/04/22 14:15:42  mohor
9196
// Wishbone signals are registered when ETH_REGISTERED_OUTPUTS is
9197
// selected in eth_defines.v
9198
//
9199
// Revision 1.23  2002/03/25 13:33:53  mohor
9200
// md_padoen_o changed to md_padoe_o. Signal was always active high, just
9201
// name was incorrect.
9202
//
9203
// Revision 1.22  2002/02/26 16:59:54  mohor
9204
// Small fixes for external/internal DMA missmatches.
9205
//
9206
// Revision 1.21  2002/02/26 16:21:00  mohor
9207
// Interrupts changed in the top file
9208
//
9209
// Revision 1.20  2002/02/18 10:40:17  mohor
9210
// Small fixes.
9211
//
9212
// Revision 1.19  2002/02/16 14:03:44  mohor
9213
// Registered trimmed. Unused registers removed.
9214
//
9215
// Revision 1.18  2002/02/16 13:06:33  mohor
9216
// EXTERNAL_DMA used instead of WISHBONE_DMA.
9217
//
9218
// Revision 1.17  2002/02/16 07:15:27  mohor
9219
// Testbench fixed, code simplified, unused signals removed.
9220
//
9221
// Revision 1.16  2002/02/15 13:49:39  mohor
9222
// RxAbort is connected differently.
9223
//
9224
// Revision 1.15  2002/02/15 11:38:26  mohor
9225
// Changes that were lost when updating from 1.11 to 1.14 fixed.
9226
//
9227
// Revision 1.14  2002/02/14 20:19:11  billditt
9228
// Modified for Address Checking,
9229
// addition of eth_addrcheck.v
9230
//
9231
// Revision 1.13  2002/02/12 17:03:03  mohor
9232
// HASH0 and HASH1 registers added. Registers address width was
9233
// changed to 8 bits.
9234
//
9235
// Revision 1.12  2002/02/11 09:18:22  mohor
9236
// Tx status is written back to the BD.
9237
//
9238
// Revision 1.11  2002/02/08 16:21:54  mohor
9239
// Rx status is written back to the BD.
9240
//
9241
// Revision 1.10  2002/02/06 14:10:21  mohor
9242
// non-DMA host interface added. Select the right configutation in eth_defines.
9243
//
9244
// Revision 1.9  2002/01/23 10:28:16  mohor
9245
// Link in the header changed.
9246
//
9247
// Revision 1.8  2001/12/05 15:00:16  mohor
9248
// RX_BD_NUM changed to TX_BD_NUM (holds number of TX descriptors
9249
// instead of the number of RX descriptors).
9250
//
9251
// Revision 1.7  2001/12/05 10:45:59  mohor
9252
// ETH_RX_BD_ADR register deleted. ETH_RX_BD_NUM is used instead.
9253
//
9254
// Revision 1.6  2001/10/19 11:24:29  mohor
9255
// Number of addresses (wb_adr_i) minimized.
9256
//
9257
// Revision 1.5  2001/10/19 08:43:51  mohor
9258
// eth_timescale.v changed to timescale.v This is done because of the
9259
// simulation of the few cores in a one joined project.
9260
//
9261
// Revision 1.4  2001/10/18 12:07:11  mohor
9262
// Status signals changed, Adress decoding changed, interrupt controller
9263
// added.
9264
//
9265
// Revision 1.3  2001/09/24 15:02:56  mohor
9266
// Defines changed (All precede with ETH_). Small changes because some
9267
// tools generate warnings when two operands are together. Synchronization
9268
// between two clocks domains in eth_wishbonedma.v is changed (due to ASIC
9269
// demands).
9270
//
9271
// Revision 1.2  2001/08/15 14:03:59  mohor
9272
// Signal names changed on the top level for easier pad insertion (ASIC).
9273
//
9274
// Revision 1.1  2001/08/06 14:44:29  mohor
9275
// A define FPGA added to select between Artisan RAM (for ASIC) and Block Ram (For Virtex).
9276
// Include files fixed to contain no path.
9277
// File names and module names changed ta have a eth_ prologue in the name.
9278
// File eth_timescale.v is used to define timescale
9279
// All pin names on the top module are changed to contain _I, _O or _OE at the end.
9280
// Bidirectional signal MDIO is changed to three signals (Mdc_O, Mdi_I, Mdo_O
9281
// and Mdo_OE. The bidirectional signal must be created on the top level. This
9282
// is done due to the ASIC tools.
9283
//
9284
// Revision 1.2  2001/08/02 09:25:31  mohor
9285
// Unconnected signals are now connected.
9286
//
9287
// Revision 1.1  2001/07/30 21:23:42  mohor
9288
// Directory structure changed. Files checked and joind together.
9289
//
9290
//
9291
//
9292
// 
9293
 
9294
 
9295
`include "eth_defines.v"
9296
`include "timescale.v"
9297
 
9298
 
9299
module eth_top
9300
(
9301
  // WISHBONE common
9302
  wb_clk_i, wb_rst_i, wb_dat_i, wb_dat_o,
9303
 
9304
  // WISHBONE slave
9305
  wb_adr_i, wb_sel_i, wb_we_i, wb_cyc_i, wb_stb_i, wb_ack_o, wb_err_o,
9306
 
9307
  // WISHBONE master
9308
  m_wb_adr_o, m_wb_sel_o, m_wb_we_o,
9309
  m_wb_dat_o, m_wb_dat_i, m_wb_cyc_o,
9310
  m_wb_stb_o, m_wb_ack_i, m_wb_err_i,
9311
 
9312
`ifdef ETH_WISHBONE_B3
9313
  m_wb_cti_o, m_wb_bte_o,
9314
`endif
9315
 
9316
  //TX
9317
  mtx_clk_pad_i, mtxd_pad_o, mtxen_pad_o, mtxerr_pad_o,
9318
 
9319
  //RX
9320
  mrx_clk_pad_i, mrxd_pad_i, mrxdv_pad_i, mrxerr_pad_i, mcoll_pad_i, mcrs_pad_i,
9321
 
9322
  // MIIM
9323
  mdc_pad_o, md_pad_i, md_pad_o, md_padoe_o,
9324
 
9325
  int_o
9326
 
9327
  // Bist
9328
`ifdef ETH_BIST
9329
  ,
9330
  // debug chain signals
9331
  mbist_si_i,       // bist scan serial in
9332
  mbist_so_o,       // bist scan serial out
9333
  mbist_ctrl_i        // bist chain shift control
9334
`endif
9335
 
9336
);
9337
 
9338
 
9339
parameter Tp = 1;
9340
 
9341
 
9342
// WISHBONE common
9343
input           wb_clk_i;     // WISHBONE clock
9344
input           wb_rst_i;     // WISHBONE reset
9345
input   [31:0]  wb_dat_i;     // WISHBONE data input
9346
output  [31:0]  wb_dat_o;     // WISHBONE data output
9347
output          wb_err_o;     // WISHBONE error output
9348
 
9349
// WISHBONE slave
9350
input   [11:2]  wb_adr_i;     // WISHBONE address input
9351
input    [3:0]  wb_sel_i;     // WISHBONE byte select input
9352
input           wb_we_i;      // WISHBONE write enable input
9353
input           wb_cyc_i;     // WISHBONE cycle input
9354
input           wb_stb_i;     // WISHBONE strobe input
9355
output          wb_ack_o;     // WISHBONE acknowledge output
9356
 
9357
// WISHBONE master
9358
output  [31:0]  m_wb_adr_o;
9359
output   [3:0]  m_wb_sel_o;
9360
output          m_wb_we_o;
9361
input   [31:0]  m_wb_dat_i;
9362
output  [31:0]  m_wb_dat_o;
9363
output          m_wb_cyc_o;
9364
output          m_wb_stb_o;
9365
input           m_wb_ack_i;
9366
input           m_wb_err_i;
9367
 
9368
wire    [29:0]  m_wb_adr_tmp;
9369
 
9370
`ifdef ETH_WISHBONE_B3
9371
output   [2:0]  m_wb_cti_o;   // Cycle Type Identifier
9372
output   [1:0]  m_wb_bte_o;   // Burst Type Extension
9373
`endif
9374
 
9375
// Tx
9376
input           mtx_clk_pad_i; // Transmit clock (from PHY)
9377
output   [3:0]  mtxd_pad_o;    // Transmit nibble (to PHY)
9378
output          mtxen_pad_o;   // Transmit enable (to PHY)
9379
output          mtxerr_pad_o;  // Transmit error (to PHY)
9380
 
9381
// Rx
9382
input           mrx_clk_pad_i; // Receive clock (from PHY)
9383
input    [3:0]  mrxd_pad_i;    // Receive nibble (from PHY)
9384
input           mrxdv_pad_i;   // Receive data valid (from PHY)
9385
input           mrxerr_pad_i;  // Receive data error (from PHY)
9386
 
9387
// Common Tx and Rx
9388
input           mcoll_pad_i;   // Collision (from PHY)
9389
input           mcrs_pad_i;    // Carrier sense (from PHY)
9390
 
9391
// MII Management interface
9392
input           md_pad_i;      // MII data input (from I/O cell)
9393
output          mdc_pad_o;     // MII Management data clock (to PHY)
9394
output          md_pad_o;      // MII data output (to I/O cell)
9395
output          md_padoe_o;    // MII data output enable (to I/O cell)
9396
 
9397
output          int_o;         // Interrupt output
9398
 
9399
// Bist
9400
`ifdef ETH_BIST
9401
input   mbist_si_i;       // bist scan serial in
9402
output  mbist_so_o;       // bist scan serial out
9403
input [`ETH_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;       // bist chain shift control
9404
`endif
9405
 
9406
wire     [7:0]  r_ClkDiv;
9407
wire            r_MiiNoPre;
9408
wire    [15:0]  r_CtrlData;
9409
wire     [4:0]  r_FIAD;
9410
wire     [4:0]  r_RGAD;
9411
wire            r_WCtrlData;
9412
wire            r_RStat;
9413
wire            r_ScanStat;
9414
wire            NValid_stat;
9415
wire            Busy_stat;
9416
wire            LinkFail;
9417
wire    [15:0]  Prsd;             // Read Status Data (data read from the PHY)
9418
wire            WCtrlDataStart;
9419
wire            RStatStart;
9420
wire            UpdateMIIRX_DATAReg;
9421
 
9422
wire            TxStartFrm;
9423
wire            TxEndFrm;
9424
wire            TxUsedData;
9425
wire     [7:0]  TxData;
9426
wire            TxRetry;
9427
wire            TxAbort;
9428
wire            TxUnderRun;
9429
wire            TxDone;
9430
 
9431
 
9432
reg             WillSendControlFrame_sync1;
9433
reg             WillSendControlFrame_sync2;
9434
reg             WillSendControlFrame_sync3;
9435
reg             RstTxPauseRq;
9436
 
9437
reg             TxPauseRq_sync1;
9438
reg             TxPauseRq_sync2;
9439
reg             TxPauseRq_sync3;
9440
reg             TPauseRq;
9441
 
9442
 
9443
// Connecting Miim module
9444
eth_miim miim1
9445
(
9446
  .Clk(wb_clk_i),                         .Reset(wb_rst_i),                   .Divider(r_ClkDiv),
9447
  .NoPre(r_MiiNoPre),                     .CtrlData(r_CtrlData),              .Rgad(r_RGAD),
9448
  .Fiad(r_FIAD),                          .WCtrlData(r_WCtrlData),            .RStat(r_RStat),
9449
  .ScanStat(r_ScanStat),                  .Mdi(md_pad_i),                     .Mdo(md_pad_o),
9450
  .MdoEn(md_padoe_o),                     .Mdc(mdc_pad_o),                    .Busy(Busy_stat),
9451
  .Prsd(Prsd),                            .LinkFail(LinkFail),                .Nvalid(NValid_stat),
9452
  .WCtrlDataStart(WCtrlDataStart),        .RStatStart(RStatStart),            .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg)
9453
);
9454
 
9455
 
9456
 
9457
 
9458
wire  [3:0] RegCs;          // Connected to registers
9459
wire [31:0] RegDataOut;     // Multiplexed to wb_dat_o
9460
wire        r_RecSmall;     // Receive small frames
9461
wire        r_LoopBck;      // Loopback
9462
wire        r_TxEn;         // Tx Enable
9463
wire        r_RxEn;         // Rx Enable
9464
 
9465
wire        MRxDV_Lb;       // Muxed MII receive data valid
9466
wire        MRxErr_Lb;      // Muxed MII Receive Error
9467
wire  [3:0] MRxD_Lb;        // Muxed MII Receive Data
9468
wire        Transmitting;   // Indication that TxEthMAC is transmitting
9469
wire        r_HugEn;        // Huge packet enable
9470
wire        r_DlyCrcEn;     // Delayed CRC enabled
9471
wire [15:0] r_MaxFL;        // Maximum frame length
9472
 
9473
wire [15:0] r_MinFL;        // Minimum frame length
9474
wire        ShortFrame;
9475
wire        DribbleNibble;  // Extra nibble received
9476
wire        ReceivedPacketTooBig; // Received packet is too big
9477
wire [47:0] r_MAC;          // MAC address
9478
wire        LoadRxStatus;   // Rx status was loaded
9479
wire [31:0] r_HASH0;        // HASH table, lower 4 bytes
9480
wire [31:0] r_HASH1;        // HASH table, upper 4 bytes
9481
wire  [7:0] r_TxBDNum;      // Receive buffer descriptor number
9482
wire  [6:0] r_IPGT;         // 
9483
wire  [6:0] r_IPGR1;        // 
9484
wire  [6:0] r_IPGR2;        // 
9485
wire  [5:0] r_CollValid;    // 
9486
wire [15:0] r_TxPauseTV;    // Transmit PAUSE value
9487
wire        r_TxPauseRq;    // Transmit PAUSE request
9488
 
9489
wire  [3:0] r_MaxRet;       //
9490
wire        r_NoBckof;      // 
9491
wire        r_ExDfrEn;      // 
9492
wire        r_TxFlow;       // Tx flow control enable
9493
wire        r_IFG;          // Minimum interframe gap for incoming packets
9494
 
9495
wire        TxB_IRQ;        // Interrupt Tx Buffer
9496
wire        TxE_IRQ;        // Interrupt Tx Error
9497
wire        RxB_IRQ;        // Interrupt Rx Buffer
9498
wire        RxE_IRQ;        // Interrupt Rx Error
9499
wire        Busy_IRQ;       // Interrupt Busy (lack of buffers)
9500
 
9501
//wire        DWord;
9502
wire        ByteSelected;
9503
wire        BDAck;
9504
wire [31:0] BD_WB_DAT_O;    // wb_dat_o that comes from the Wishbone module (for buffer descriptors read/write)
9505
wire  [3:0] BDCs;           // Buffer descriptor CS
9506
wire        CsMiss;         // When access to the address between 0x800 and 0xfff occurs, acknowledge is set
9507
                            // but data is not valid.
9508
wire        r_Pad;
9509
wire        r_CrcEn;
9510
wire        r_FullD;
9511
wire        r_Pro;
9512
wire        r_Bro;
9513
wire        r_NoPre;
9514
wire        r_RxFlow;
9515
wire        r_PassAll;
9516
wire        TxCtrlEndFrm;
9517
wire        StartTxDone;
9518
wire        SetPauseTimer;
9519
wire        TxUsedDataIn;
9520
wire        TxDoneIn;
9521
wire        TxAbortIn;
9522
wire        PerPacketPad;
9523
wire        PadOut;
9524
wire        PerPacketCrcEn;
9525
wire        CrcEnOut;
9526
wire        TxStartFrmOut;
9527
wire        TxEndFrmOut;
9528
wire        ReceivedPauseFrm;
9529
wire        ControlFrmAddressOK;
9530
wire        RxStatusWriteLatched_sync2;
9531
wire        LateCollision;
9532
wire        DeferIndication;
9533
wire        LateCollLatched;
9534
wire        DeferLatched;
9535
wire        RstDeferLatched;
9536
wire        CarrierSenseLost;
9537
 
9538
wire        temp_wb_ack_o;
9539
wire [31:0] temp_wb_dat_o;
9540
wire        temp_wb_err_o;
9541
 
9542
`ifdef ETH_REGISTERED_OUTPUTS
9543
  reg         temp_wb_ack_o_reg;
9544
  reg [31:0]  temp_wb_dat_o_reg;
9545
  reg         temp_wb_err_o_reg;
9546
`endif
9547
 
9548
//assign DWord = &wb_sel_i;
9549
assign ByteSelected = |wb_sel_i;
9550
assign RegCs[3] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[3];   // 0x0   - 0x3FF
9551
assign RegCs[2] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[2];   // 0x0   - 0x3FF
9552
assign RegCs[1] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[1];   // 0x0   - 0x3FF
9553
assign RegCs[0] = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] & ~wb_adr_i[10] & wb_sel_i[0];   // 0x0   - 0x3FF
9554
assign BDCs[3]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[3];   // 0x400 - 0x7FF
9555
assign BDCs[2]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[2];   // 0x400 - 0x7FF
9556
assign BDCs[1]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[1];   // 0x400 - 0x7FF
9557
assign BDCs[0]  = wb_stb_i & wb_cyc_i & ByteSelected & ~wb_adr_i[11] &  wb_adr_i[10] & wb_sel_i[0];   // 0x400 - 0x7FF
9558
assign CsMiss = wb_stb_i & wb_cyc_i & ByteSelected & wb_adr_i[11];                   // 0x800 - 0xfFF
9559
assign temp_wb_dat_o = ((|RegCs) & ~wb_we_i)? RegDataOut : BD_WB_DAT_O;
9560
assign temp_wb_err_o = wb_stb_i & wb_cyc_i & (~ByteSelected | CsMiss);
9561
 
9562
`ifdef ETH_REGISTERED_OUTPUTS
9563
  assign wb_ack_o = temp_wb_ack_o_reg;
9564
  assign wb_dat_o[31:0] = temp_wb_dat_o_reg;
9565
  assign wb_err_o = temp_wb_err_o_reg;
9566
`else
9567
  assign wb_ack_o = temp_wb_ack_o;
9568
  assign wb_dat_o[31:0] = temp_wb_dat_o;
9569
  assign wb_err_o = temp_wb_err_o;
9570
`endif
9571
 
9572
`ifdef ETH_AVALON_BUS
9573
  // As Avalon has no corresponding "error" signal, I (erroneously) will
9574
  // send an ack to Avalon, even when accessing undefined memory. This
9575
  // is a grey area in Avalon vs. Wishbone specs: My understanding
9576
  // is that Avalon expects all memory addressable by the addr bus feeding
9577
  // a slave to be, at the very minimum, readable.
9578
  assign temp_wb_ack_o = (|RegCs) | BDAck | CsMiss;
9579
`else // WISHBONE
9580
  assign temp_wb_ack_o = (|RegCs) | BDAck;
9581
`endif
9582
 
9583
`ifdef ETH_REGISTERED_OUTPUTS
9584
  always @ (posedge wb_clk_i or posedge wb_rst_i)
9585
  begin
9586
    if(wb_rst_i)
9587
      begin
9588
        temp_wb_ack_o_reg <=#Tp 1'b0;
9589
        temp_wb_dat_o_reg <=#Tp 32'h0;
9590
        temp_wb_err_o_reg <=#Tp 1'b0;
9591
      end
9592
    else
9593
      begin
9594
        temp_wb_ack_o_reg <=#Tp temp_wb_ack_o & ~temp_wb_ack_o_reg;
9595
        temp_wb_dat_o_reg <=#Tp temp_wb_dat_o;
9596
        temp_wb_err_o_reg <=#Tp temp_wb_err_o & ~temp_wb_err_o_reg;
9597
      end
9598
  end
9599
`endif
9600
 
9601
 
9602
// Connecting Ethernet registers
9603
eth_registers ethreg1
9604
(
9605
  .DataIn(wb_dat_i),                      .Address(wb_adr_i[9:2]),                    .Rw(wb_we_i),
9606
  .Cs(RegCs),                             .Clk(wb_clk_i),                             .Reset(wb_rst_i),
9607
  .DataOut(RegDataOut),                   .r_RecSmall(r_RecSmall),
9608
  .r_Pad(r_Pad),                          .r_HugEn(r_HugEn),                          .r_CrcEn(r_CrcEn),
9609
  .r_DlyCrcEn(r_DlyCrcEn),                .r_FullD(r_FullD),
9610
  .r_ExDfrEn(r_ExDfrEn),                  .r_NoBckof(r_NoBckof),                      .r_LoopBck(r_LoopBck),
9611
  .r_IFG(r_IFG),                          .r_Pro(r_Pro),                              .r_Iam(),
9612
  .r_Bro(r_Bro),                          .r_NoPre(r_NoPre),                          .r_TxEn(r_TxEn),
9613
  .r_RxEn(r_RxEn),                        .Busy_IRQ(Busy_IRQ),                        .RxE_IRQ(RxE_IRQ),
9614
  .RxB_IRQ(RxB_IRQ),                      .TxE_IRQ(TxE_IRQ),                          .TxB_IRQ(TxB_IRQ),
9615
  .r_IPGT(r_IPGT),
9616
  .r_IPGR1(r_IPGR1),                      .r_IPGR2(r_IPGR2),                          .r_MinFL(r_MinFL),
9617
  .r_MaxFL(r_MaxFL),                      .r_MaxRet(r_MaxRet),                        .r_CollValid(r_CollValid),
9618
  .r_TxFlow(r_TxFlow),                    .r_RxFlow(r_RxFlow),                        .r_PassAll(r_PassAll),
9619
  .r_MiiNoPre(r_MiiNoPre),                .r_ClkDiv(r_ClkDiv),
9620
  .r_WCtrlData(r_WCtrlData),              .r_RStat(r_RStat),                          .r_ScanStat(r_ScanStat),
9621
  .r_RGAD(r_RGAD),                        .r_FIAD(r_FIAD),                            .r_CtrlData(r_CtrlData),
9622
  .NValid_stat(NValid_stat),              .Busy_stat(Busy_stat),
9623
  .LinkFail(LinkFail),                    .r_MAC(r_MAC),                              .WCtrlDataStart(WCtrlDataStart),
9624
  .RStatStart(RStatStart),                .UpdateMIIRX_DATAReg(UpdateMIIRX_DATAReg),  .Prsd(Prsd),
9625
  .r_TxBDNum(r_TxBDNum),                  .int_o(int_o),
9626
  .r_HASH0(r_HASH0),                      .r_HASH1(r_HASH1),                          .r_TxPauseRq(r_TxPauseRq),
9627
  .r_TxPauseTV(r_TxPauseTV),              .RstTxPauseRq(RstTxPauseRq),                .TxCtrlEndFrm(TxCtrlEndFrm),
9628
  .StartTxDone(StartTxDone),              .TxClk(mtx_clk_pad_i),                      .RxClk(mrx_clk_pad_i),
9629
  .SetPauseTimer(SetPauseTimer)
9630
 
9631
);
9632
 
9633
 
9634
 
9635
wire  [7:0] RxData;
9636
wire        RxValid;
9637
wire        RxStartFrm;
9638
wire        RxEndFrm;
9639
wire        RxAbort;
9640
 
9641
wire        WillTransmit;            // Will transmit (to RxEthMAC)
9642
wire        ResetCollision;          // Reset Collision (for synchronizing collision)
9643
wire  [7:0] TxDataOut;               // Transmit Packet Data (to TxEthMAC)
9644
wire        WillSendControlFrame;
9645
wire        ReceiveEnd;
9646
wire        ReceivedPacketGood;
9647
wire        ReceivedLengthOK;
9648
wire        InvalidSymbol;
9649
wire        LatchedCrcError;
9650
wire        RxLateCollision;
9651
wire  [3:0] RetryCntLatched;
9652
wire  [3:0] RetryCnt;
9653
wire        StartTxAbort;
9654
wire        MaxCollisionOccured;
9655
wire        RetryLimit;
9656
wire        StatePreamble;
9657
wire  [1:0] StateData;
9658
 
9659
// Connecting MACControl
9660
eth_maccontrol maccontrol1
9661
(
9662
  .MTxClk(mtx_clk_pad_i),                       .TPauseRq(TPauseRq),
9663
  .TxPauseTV(r_TxPauseTV),                      .TxDataIn(TxData),
9664
  .TxStartFrmIn(TxStartFrm),                    .TxEndFrmIn(TxEndFrm),
9665
  .TxUsedDataIn(TxUsedDataIn),                  .TxDoneIn(TxDoneIn),
9666
  .TxAbortIn(TxAbortIn),                        .MRxClk(mrx_clk_pad_i),
9667
  .RxData(RxData),                              .RxValid(RxValid),
9668
  .RxStartFrm(RxStartFrm),                      .RxEndFrm(RxEndFrm),
9669
  .ReceiveEnd(ReceiveEnd),                      .ReceivedPacketGood(ReceivedPacketGood),
9670
  .TxFlow(r_TxFlow),
9671
  .RxFlow(r_RxFlow),                            .DlyCrcEn(r_DlyCrcEn),
9672
  .MAC(r_MAC),                                  .PadIn(r_Pad | PerPacketPad),
9673
  .PadOut(PadOut),                              .CrcEnIn(r_CrcEn | PerPacketCrcEn),
9674
  .CrcEnOut(CrcEnOut),                          .TxReset(wb_rst_i),
9675
  .RxReset(wb_rst_i),                           .ReceivedLengthOK(ReceivedLengthOK),
9676
  .TxDataOut(TxDataOut),                        .TxStartFrmOut(TxStartFrmOut),
9677
  .TxEndFrmOut(TxEndFrmOut),                    .TxUsedDataOut(TxUsedData),
9678
  .TxDoneOut(TxDone),                           .TxAbortOut(TxAbort),
9679
  .WillSendControlFrame(WillSendControlFrame),  .TxCtrlEndFrm(TxCtrlEndFrm),
9680
  .ReceivedPauseFrm(ReceivedPauseFrm),          .ControlFrmAddressOK(ControlFrmAddressOK),
9681
  .SetPauseTimer(SetPauseTimer),
9682
  .RxStatusWriteLatched_sync2(RxStatusWriteLatched_sync2),                .r_PassAll(r_PassAll)
9683
);
9684
 
9685
 
9686
 
9687
wire TxCarrierSense;          // Synchronized CarrierSense (to Tx clock)
9688
wire Collision;               // Synchronized Collision
9689
 
9690
reg CarrierSense_Tx1;
9691
reg CarrierSense_Tx2;
9692
reg Collision_Tx1;
9693
reg Collision_Tx2;
9694
 
9695
reg RxEnSync;                 // Synchronized Receive Enable
9696
reg WillTransmit_q;
9697
reg WillTransmit_q2;
9698
 
9699
 
9700
 
9701
// Muxed MII receive data valid
9702
assign MRxDV_Lb = r_LoopBck? mtxen_pad_o : mrxdv_pad_i & RxEnSync;
9703
 
9704
// Muxed MII Receive Error
9705
assign MRxErr_Lb = r_LoopBck? mtxerr_pad_o : mrxerr_pad_i & RxEnSync;
9706
 
9707
// Muxed MII Receive Data
9708
assign MRxD_Lb[3:0] = r_LoopBck? mtxd_pad_o[3:0] : mrxd_pad_i[3:0];
9709
 
9710
 
9711
 
9712
// Connecting TxEthMAC
9713
eth_txethmac txethmac1
9714
(
9715
  .MTxClk(mtx_clk_pad_i),             .Reset(wb_rst_i),                   .CarrierSense(TxCarrierSense),
9716
  .Collision(Collision),              .TxData(TxDataOut),                 .TxStartFrm(TxStartFrmOut),
9717
  .TxUnderRun(TxUnderRun),            .TxEndFrm(TxEndFrmOut),             .Pad(PadOut),
9718
  .MinFL(r_MinFL),                    .CrcEn(CrcEnOut),                   .FullD(r_FullD),
9719
  .HugEn(r_HugEn),                    .DlyCrcEn(r_DlyCrcEn),              .IPGT(r_IPGT),
9720
  .IPGR1(r_IPGR1),                    .IPGR2(r_IPGR2),                    .CollValid(r_CollValid),
9721
  .MaxRet(r_MaxRet),                  .NoBckof(r_NoBckof),                .ExDfrEn(r_ExDfrEn),
9722
  .MaxFL(r_MaxFL),                    .MTxEn(mtxen_pad_o),                .MTxD(mtxd_pad_o),
9723
  .MTxErr(mtxerr_pad_o),              .TxUsedData(TxUsedDataIn),          .TxDone(TxDoneIn),
9724
  .TxRetry(TxRetry),                  .TxAbort(TxAbortIn),                .WillTransmit(WillTransmit),
9725
  .ResetCollision(ResetCollision),    .RetryCnt(RetryCnt),                .StartTxDone(StartTxDone),
9726
  .StartTxAbort(StartTxAbort),        .MaxCollisionOccured(MaxCollisionOccured), .LateCollision(LateCollision),
9727
  .DeferIndication(DeferIndication),  .StatePreamble(StatePreamble),      .StateData(StateData)
9728
);
9729
 
9730
 
9731
 
9732
 
9733
wire  [15:0]  RxByteCnt;
9734
wire          RxByteCntEq0;
9735
wire          RxByteCntGreat2;
9736
wire          RxByteCntMaxFrame;
9737
wire          RxCrcError;
9738
wire          RxStateIdle;
9739
wire          RxStatePreamble;
9740
wire          RxStateSFD;
9741
wire   [1:0]  RxStateData;
9742
wire          AddressMiss;
9743
 
9744
 
9745
 
9746
// Connecting RxEthMAC
9747
eth_rxethmac rxethmac1
9748
(
9749
  .MRxClk(mrx_clk_pad_i),               .MRxDV(MRxDV_Lb),                     .MRxD(MRxD_Lb),
9750
  .Transmitting(Transmitting),          .HugEn(r_HugEn),                      .DlyCrcEn(r_DlyCrcEn),
9751
  .MaxFL(r_MaxFL),                      .r_IFG(r_IFG),                        .Reset(wb_rst_i),
9752
  .RxData(RxData),                      .RxValid(RxValid),                    .RxStartFrm(RxStartFrm),
9753
  .RxEndFrm(RxEndFrm),                  .ByteCnt(RxByteCnt),
9754
  .ByteCntEq0(RxByteCntEq0),            .ByteCntGreat2(RxByteCntGreat2),      .ByteCntMaxFrame(RxByteCntMaxFrame),
9755
  .CrcError(RxCrcError),                .StateIdle(RxStateIdle),              .StatePreamble(RxStatePreamble),
9756
  .StateSFD(RxStateSFD),                .StateData(RxStateData),
9757
  .MAC(r_MAC),                          .r_Pro(r_Pro),                        .r_Bro(r_Bro),
9758
  .r_HASH0(r_HASH0),                    .r_HASH1(r_HASH1),                    .RxAbort(RxAbort),
9759
  .AddressMiss(AddressMiss),            .PassAll(r_PassAll),                  .ControlFrmAddressOK(ControlFrmAddressOK)
9760
);
9761
 
9762
 
9763
// MII Carrier Sense Synchronization
9764
always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
9765
begin
9766
  if(wb_rst_i)
9767
    begin
9768
      CarrierSense_Tx1 <= #Tp 1'b0;
9769
      CarrierSense_Tx2 <= #Tp 1'b0;
9770
    end
9771
  else
9772
    begin
9773
      CarrierSense_Tx1 <= #Tp mcrs_pad_i;
9774
      CarrierSense_Tx2 <= #Tp CarrierSense_Tx1;
9775
    end
9776
end
9777
 
9778
assign TxCarrierSense = ~r_FullD & CarrierSense_Tx2;
9779
 
9780
 
9781
// MII Collision Synchronization
9782
always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
9783
begin
9784
  if(wb_rst_i)
9785
    begin
9786
      Collision_Tx1 <= #Tp 1'b0;
9787
      Collision_Tx2 <= #Tp 1'b0;
9788
    end
9789
  else
9790
    begin
9791
      Collision_Tx1 <= #Tp mcoll_pad_i;
9792
      if(ResetCollision)
9793
        Collision_Tx2 <= #Tp 1'b0;
9794
      else
9795
      if(Collision_Tx1)
9796
        Collision_Tx2 <= #Tp 1'b1;
9797
    end
9798
end
9799
 
9800
 
9801
// Synchronized Collision
9802
assign Collision = ~r_FullD & Collision_Tx2;
9803
 
9804
 
9805
 
9806
// Delayed WillTransmit
9807
always @ (posedge mrx_clk_pad_i)
9808
begin
9809
  WillTransmit_q <= #Tp WillTransmit;
9810
  WillTransmit_q2 <= #Tp WillTransmit_q;
9811
end
9812
 
9813
 
9814
assign Transmitting = ~r_FullD & WillTransmit_q2;
9815
 
9816
 
9817
 
9818
// Synchronized Receive Enable
9819
always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
9820
begin
9821
  if(wb_rst_i)
9822
    RxEnSync <= #Tp 1'b0;
9823
  else
9824
  if(~mrxdv_pad_i)
9825
    RxEnSync <= #Tp r_RxEn;
9826
end
9827
 
9828
 
9829
 
9830
// Synchronizing WillSendControlFrame to WB_CLK;
9831
always @ (posedge wb_clk_i or posedge wb_rst_i)
9832
begin
9833
  if(wb_rst_i)
9834
    WillSendControlFrame_sync1 <= 1'b0;
9835
  else
9836
    WillSendControlFrame_sync1 <=#Tp WillSendControlFrame;
9837
end
9838
 
9839
always @ (posedge wb_clk_i or posedge wb_rst_i)
9840
begin
9841
  if(wb_rst_i)
9842
    WillSendControlFrame_sync2 <= 1'b0;
9843
  else
9844
    WillSendControlFrame_sync2 <=#Tp WillSendControlFrame_sync1;
9845
end
9846
 
9847
always @ (posedge wb_clk_i or posedge wb_rst_i)
9848
begin
9849
  if(wb_rst_i)
9850
    WillSendControlFrame_sync3 <= 1'b0;
9851
  else
9852
    WillSendControlFrame_sync3 <=#Tp WillSendControlFrame_sync2;
9853
end
9854
 
9855
always @ (posedge wb_clk_i or posedge wb_rst_i)
9856
begin
9857
  if(wb_rst_i)
9858
    RstTxPauseRq <= 1'b0;
9859
  else
9860
    RstTxPauseRq <=#Tp WillSendControlFrame_sync2 & ~WillSendControlFrame_sync3;
9861
end
9862
 
9863
 
9864
 
9865
 
9866
// TX Pause request Synchronization
9867
always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
9868
begin
9869
  if(wb_rst_i)
9870
    begin
9871
      TxPauseRq_sync1 <= #Tp 1'b0;
9872
      TxPauseRq_sync2 <= #Tp 1'b0;
9873
      TxPauseRq_sync3 <= #Tp 1'b0;
9874
    end
9875
  else
9876
    begin
9877
      TxPauseRq_sync1 <= #Tp (r_TxPauseRq & r_TxFlow);
9878
      TxPauseRq_sync2 <= #Tp TxPauseRq_sync1;
9879
      TxPauseRq_sync3 <= #Tp TxPauseRq_sync2;
9880
    end
9881
end
9882
 
9883
 
9884
always @ (posedge mtx_clk_pad_i or posedge wb_rst_i)
9885
begin
9886
  if(wb_rst_i)
9887
    TPauseRq <= #Tp 1'b0;
9888
  else
9889
    TPauseRq <= #Tp TxPauseRq_sync2 & (~TxPauseRq_sync3);
9890
end
9891
 
9892
 
9893
wire LatchedMRxErr;
9894
reg RxAbort_latch;
9895
reg RxAbort_sync1;
9896
reg RxAbort_wb;
9897
reg RxAbortRst_sync1;
9898
reg RxAbortRst;
9899
 
9900
// Synchronizing RxAbort to the WISHBONE clock
9901
always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
9902
begin
9903
  if(wb_rst_i)
9904
    RxAbort_latch <= #Tp 1'b0;
9905
  else if(RxAbort | (ShortFrame & ~r_RecSmall) | LatchedMRxErr & ~InvalidSymbol | (ReceivedPauseFrm & (~r_PassAll)))
9906
    RxAbort_latch <= #Tp 1'b1;
9907
  else if(RxAbortRst)
9908
    RxAbort_latch <= #Tp 1'b0;
9909
end
9910
 
9911
always @ (posedge wb_clk_i or posedge wb_rst_i)
9912
begin
9913
  if(wb_rst_i)
9914
    begin
9915
      RxAbort_sync1 <= #Tp 1'b0;
9916
      RxAbort_wb    <= #Tp 1'b0;
9917
      RxAbort_wb    <= #Tp 1'b0;
9918
    end
9919
  else
9920
    begin
9921
      RxAbort_sync1 <= #Tp RxAbort_latch;
9922
      RxAbort_wb    <= #Tp RxAbort_sync1;
9923
    end
9924
end
9925
 
9926
always @ (posedge mrx_clk_pad_i or posedge wb_rst_i)
9927
begin
9928
  if(wb_rst_i)
9929
    begin
9930
      RxAbortRst_sync1 <= #Tp 1'b0;
9931
      RxAbortRst       <= #Tp 1'b0;
9932
    end
9933
  else
9934
    begin
9935
      RxAbortRst_sync1 <= #Tp RxAbort_wb;
9936
      RxAbortRst       <= #Tp RxAbortRst_sync1;
9937
    end
9938
end
9939
 
9940
 
9941
 
9942
// Connecting Wishbone module
9943
eth_wishbone wishbone
9944
(
9945
  .WB_CLK_I(wb_clk_i),                .WB_DAT_I(wb_dat_i),
9946
  .WB_DAT_O(BD_WB_DAT_O),
9947
 
9948
  // WISHBONE slave
9949
  .WB_ADR_I(wb_adr_i[9:2]),           .WB_WE_I(wb_we_i),
9950
  .BDCs(BDCs),                        .WB_ACK_O(BDAck),
9951
 
9952
  .Reset(wb_rst_i),
9953
 
9954
  // WISHBONE master
9955
  .m_wb_adr_o(m_wb_adr_tmp),          .m_wb_sel_o(m_wb_sel_o),                  .m_wb_we_o(m_wb_we_o),
9956
  .m_wb_dat_i(m_wb_dat_i),            .m_wb_dat_o(m_wb_dat_o),                  .m_wb_cyc_o(m_wb_cyc_o),
9957
  .m_wb_stb_o(m_wb_stb_o),            .m_wb_ack_i(m_wb_ack_i),                  .m_wb_err_i(m_wb_err_i),
9958
 
9959
`ifdef ETH_WISHBONE_B3
9960
  .m_wb_cti_o(m_wb_cti_o),            .m_wb_bte_o(m_wb_bte_o),
9961
`endif
9962
 
9963
 
9964
    //TX
9965
  .MTxClk(mtx_clk_pad_i),             .TxStartFrm(TxStartFrm),                  .TxEndFrm(TxEndFrm),
9966
  .TxUsedData(TxUsedData),            .TxData(TxData),
9967
  .TxRetry(TxRetry),                  .TxAbort(TxAbort),                        .TxUnderRun(TxUnderRun),
9968
  .TxDone(TxDone),
9969
  .PerPacketCrcEn(PerPacketCrcEn),    .PerPacketPad(PerPacketPad),
9970
 
9971
  // Register
9972
  .r_TxEn(r_TxEn),                    .r_RxEn(r_RxEn),                          .r_TxBDNum(r_TxBDNum),
9973
  .r_RxFlow(r_RxFlow),                      .r_PassAll(r_PassAll),
9974
 
9975
  //RX
9976
  .MRxClk(mrx_clk_pad_i),             .RxData(RxData),                          .RxValid(RxValid),
9977
  .RxStartFrm(RxStartFrm),            .RxEndFrm(RxEndFrm),
9978
  .Busy_IRQ(Busy_IRQ),                .RxE_IRQ(RxE_IRQ),                        .RxB_IRQ(RxB_IRQ),
9979
  .TxE_IRQ(TxE_IRQ),                  .TxB_IRQ(TxB_IRQ),
9980
 
9981
  .RxAbort(RxAbort_wb),               .RxStatusWriteLatched_sync2(RxStatusWriteLatched_sync2),
9982
 
9983
  .InvalidSymbol(InvalidSymbol),      .LatchedCrcError(LatchedCrcError),        .RxLength(RxByteCnt),
9984
  .RxLateCollision(RxLateCollision),  .ShortFrame(ShortFrame),                  .DribbleNibble(DribbleNibble),
9985
  .ReceivedPacketTooBig(ReceivedPacketTooBig), .LoadRxStatus(LoadRxStatus),     .RetryCntLatched(RetryCntLatched),
9986
  .RetryLimit(RetryLimit),            .LateCollLatched(LateCollLatched),        .DeferLatched(DeferLatched),
9987
  .RstDeferLatched(RstDeferLatched),
9988
  .CarrierSenseLost(CarrierSenseLost),.ReceivedPacketGood(ReceivedPacketGood),  .AddressMiss(AddressMiss),
9989
  .ReceivedPauseFrm(ReceivedPauseFrm)
9990
 
9991
`ifdef ETH_BIST
9992
  ,
9993
  .mbist_si_i       (mbist_si_i),
9994
  .mbist_so_o       (mbist_so_o),
9995
  .mbist_ctrl_i       (mbist_ctrl_i)
9996
`endif
9997
);
9998
 
9999
assign m_wb_adr_o = {m_wb_adr_tmp, 2'h0};
10000
 
10001
// Connecting MacStatus module
10002
eth_macstatus macstatus1
10003
(
10004
  .MRxClk(mrx_clk_pad_i),             .Reset(wb_rst_i),
10005
  .ReceiveEnd(ReceiveEnd),            .ReceivedPacketGood(ReceivedPacketGood),     .ReceivedLengthOK(ReceivedLengthOK),
10006
  .RxCrcError(RxCrcError),            .MRxErr(MRxErr_Lb),                          .MRxDV(MRxDV_Lb),
10007
  .RxStateSFD(RxStateSFD),            .RxStateData(RxStateData),                   .RxStatePreamble(RxStatePreamble),
10008
  .RxStateIdle(RxStateIdle),          .Transmitting(Transmitting),                 .RxByteCnt(RxByteCnt),
10009
  .RxByteCntEq0(RxByteCntEq0),        .RxByteCntGreat2(RxByteCntGreat2),           .RxByteCntMaxFrame(RxByteCntMaxFrame),
10010
  .InvalidSymbol(InvalidSymbol),
10011
  .MRxD(MRxD_Lb),                     .LatchedCrcError(LatchedCrcError),           .Collision(mcoll_pad_i),
10012
  .CollValid(r_CollValid),            .RxLateCollision(RxLateCollision),           .r_RecSmall(r_RecSmall),
10013
  .r_MinFL(r_MinFL),                  .r_MaxFL(r_MaxFL),                           .ShortFrame(ShortFrame),
10014
  .DribbleNibble(DribbleNibble),      .ReceivedPacketTooBig(ReceivedPacketTooBig), .r_HugEn(r_HugEn),
10015
  .LoadRxStatus(LoadRxStatus),        .RetryCnt(RetryCnt),                         .StartTxDone(StartTxDone),
10016
  .StartTxAbort(StartTxAbort),        .RetryCntLatched(RetryCntLatched),           .MTxClk(mtx_clk_pad_i),
10017
  .MaxCollisionOccured(MaxCollisionOccured), .RetryLimit(RetryLimit),              .LateCollision(LateCollision),
10018
  .LateCollLatched(LateCollLatched),  .DeferIndication(DeferIndication),           .DeferLatched(DeferLatched),
10019
  .RstDeferLatched(RstDeferLatched),
10020
  .TxStartFrm(TxStartFrmOut),         .StatePreamble(StatePreamble),               .StateData(StateData),
10021
  .CarrierSense(CarrierSense_Tx2),    .CarrierSenseLost(CarrierSenseLost),         .TxUsedData(TxUsedDataIn),
10022
  .LatchedMRxErr(LatchedMRxErr),      .Loopback(r_LoopBck),                        .r_FullD(r_FullD)
10023
);
10024
 
10025
 
10026
endmodule

powered by: WebSVN 2.1.0

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