OpenCores
URL https://opencores.org/ocsvn/1000base-x/1000base-x/trunk

Subversion Repositories 1000base-x

[/] [1000base-x/] [trunk/] [testbench/] [rtl/] [verilog/] [mdio_serial_model.v] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 dwp
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  File name "mdio_serial_model.v"                             ////
4
////                                                              ////
5
////  This file is part of the :                                  ////
6
////                                                              ////
7
//// "1000BASE-X IEEE 802.3-2008 Clause 36 - PCS project"         ////
8
////                                                              ////
9
////  http://opencores.org/project,1000base-x                     ////
10
////                                                              ////
11
////  Author(s):                                                  ////
12
////      - D.W.Pegler Cambridge Broadband Networks Ltd           ////
13
////                                                              ////
14
////      { peglerd@gmail.com, dwp@cambridgebroadand.com }        ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2009 AUTHORS. All rights reserved.             ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
////                                                              ////
43
//// Model of the  IEEE 802.3-2008 Clause 22 MDIO/MDC management  ////
44
////                                                              ////
45
//////////////////////////////////////////////////////////////////////
46
 
47
 
48
`include "timescale_tb.v"
49
 
50
module mdio_serial_model #(
51
  parameter PHY_ADDR    = 5'b00000,
52
  parameter out_delay   = 5,
53
  parameter in_delay    = 2
54
)(
55
  interface cmd_intf,
56
 
57
  input  mdc,
58
  input  reset,
59
  inout  mdio
60
);
61
 
62
   reg [15:0] tmp_data;
63
 
64
   wire  tmp_mdio_data_in;
65
   reg   tmp_mdio_data_out;
66
   reg   tmp_mdio_n_oe;
67
 
68
   assign #out_delay mdio_n_oe = tmp_mdio_n_oe;
69
 
70
   assign #out_delay mdio = !mdio_n_oe ? tmp_mdio_data_out : 1'bz;
71
 
72
   assign #in_delay tmp_mdio_data_in = mdio;
73
 
74
   // Reset all registers
75
  always @ ( posedge mdc or posedge reset )
76
    begin
77
    if (reset)
78
      begin
79
         tmp_data <= 16'h0000; tmp_mdio_n_oe <= 1'b0; tmp_mdio_data_out  <= 1'b0;
80
      end
81
    end
82
 
83
 
84
  //----------------------------------------------------------------------------
85
  // Write operation
86
  //----------------------------------------------------------------------------
87
 
88
  task automatic cmd_intf.write(input [4:0] regaddr, input [15:0] data);
89
 
90
     int i;
91
 
92
     $display("%m: %02h : %04h", regaddr, data);
93
 
94
     // PREAMBLE
95
     for (i=0; i < 32; i++) begin
96
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = 1'b1;
97
     end
98
 
99
     // ST
100
     for (i=0; i < 2; i++) begin
101
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = (i==0) ? 1'b0 : 1'b1;
102
     end;
103
 
104
     // OP - Write
105
      for (i=0; i < 2; i++) begin
106
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = (i==0) ? 1'b0 : 1'b1;
107
      end;
108
 
109
     // PHYADDR
110
     for (i=0; i < 5; i++) begin
111
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = PHY_ADDR[4-i];
112
     end
113
 
114
     // REGADDR
115
     for (i=0; i < 5; i++) begin
116
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = regaddr[4-i];
117
     end
118
 
119
     // TA
120
     for (i=0; i < 2; i++) begin
121
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = (i==0) ? 1'b1 : 1'b0;
122
     end
123
 
124
     // DATA
125
     for (i=0; i < 16; i++) begin
126
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = data[15-i];
127
     end
128
 
129
     // IDLE
130
     for (i=0; i < 2; i++) @(posedge mdc) tmp_mdio_n_oe = 1'b0;
131
 
132
  endtask
133
 
134
 //----------------------------------------------------------------------------
135
  // Write operation
136
  //----------------------------------------------------------------------------
137
 
138
  task automatic cmd_intf.read(input [4:0] regaddr, output [15:0] data);
139
 
140
     int i;
141
 
142
     tmp_data[15:0] = 16'h0000;
143
 
144
     // PREAMBLE
145
     for (i=0; i < 32; i++) begin
146
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = 1'b1;
147
     end
148
 
149
     // ST
150
     for (i=0; i < 2; i++) begin
151
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = (i==0) ? 1'b0 : 1'b1;
152
     end;
153
 
154
     // OP - Read
155
      for (i=0; i < 2; i++) begin
156
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = (i==0) ? 1'b1 : 1'b0;
157
      end;
158
 
159
     // PHYADDR
160
     for (i=0; i < 5; i++) begin
161
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = PHY_ADDR[4-i];
162
     end
163
 
164
     // REGADDR
165
     for (i=0; i < 5; i++) begin
166
         @(posedge mdc); tmp_mdio_n_oe = 1'b0; tmp_mdio_data_out = regaddr[4-i];
167
     end
168
 
169
     // TA
170
      for (i=0; i < 2; i++) begin
171
         @(posedge mdc); tmp_mdio_n_oe = 1'b1;
172
      end
173
 
174
     @(posedge mdc); tmp_mdio_n_oe = 1'b1;
175
 
176
     // DATA
177
     for (i=0; i < 16; i++) begin
178
 
179
        @(posedge mdc); tmp_mdio_n_oe = 1'b1; data[15-i] = tmp_mdio_data_in;  tmp_data[15-i] = tmp_mdio_data_in;
180
 
181
     end
182
 
183
     // IDLE
184
     for (i=0; i < 2; i++) @(posedge mdc) tmp_mdio_n_oe = 1'b0;
185
 
186
     $display("%m: Read %04h & %04h from location %02h", tmp_data, data, regaddr);
187
 
188
 
189
  endtask
190
 
191
  function automatic string cmd_intf.whoami();
192
    string buffer;
193
    $sformat(buffer, "%m");
194
    return buffer.substr(0, buffer.len()-17);
195
  endfunction
196
 
197
endmodule

powered by: WebSVN 2.1.0

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