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

Subversion Repositories smii

[/] [smii/] [trunk/] [rtl/] [verilog/] [smii.v] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  SMII                                                        ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  Low pin count serial MII ethernet interface                 ////
7
////                                                              ////
8
////  To Do:                                                      ////
9
////   -                                                          ////
10
////                                                              ////
11
////  Author(s):                                                  ////
12
////      - Michael Unneback, unneback@opencores.org              ////
13
////        ORSoC AB          michael.unneback@orsoc.se           ////
14
////                                                              ////
15
//////////////////////////////////////////////////////////////////////
16
////                                                              ////
17
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
18
////                                                              ////
19
//// This source file may be used and distributed without         ////
20
//// restriction provided that this copyright statement is not    ////
21
//// removed from the file and that any derivative work contains  ////
22
//// the original copyright notice and the associated disclaimer. ////
23
////                                                              ////
24
//// This source file is free software; you can redistribute it   ////
25
//// and/or modify it under the terms of the GNU Lesser General   ////
26
//// Public License as published by the Free Software Foundation; ////
27
//// either version 2.1 of the License, or (at your option) any   ////
28
//// later version.                                               ////
29
////                                                              ////
30
//// This source is distributed in the hope that it will be       ////
31
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
32
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
33
//// PURPOSE.  See the GNU Lesser General Public License for more ////
34
//// details.                                                     ////
35
////                                                              ////
36
//// You should have received a copy of the GNU Lesser General    ////
37
//// Public License along with this source; if not, download it   ////
38
//// from http://www.opencores.org/lgpl.shtml                     ////
39
////                                                              ////
40
//////////////////////////////////////////////////////////////////////
41
module obufdff
42
  (
43
   input d,
44
   output reg pad,
45
   input clk,
46
   input rst
47
   );
48
   always @ (posedge clk or posedge rst)
49
     if (rst)
50
       pad <= #1 1'b0;
51
     else
52
       pad <= #1 d;
53
endmodule
54
module ibufdff
55
  (
56
   input pad,
57
   output reg q,
58
   input clk,
59
   input rst
60
   );
61
   always @ (posedge clk or posedge rst)
62
     if (rst)
63
       q <= #1 1'b0;
64
     else
65
       q <= #1 pad;
66
endmodule
67
module iobuftri
68
  (
69
   input i,
70
   input oe,
71
   output o,
72
   inout pad
73
   );
74
   assign #1 pad = oe ? i : 1'bz;
75
   assign #1 i = pad;
76
endmodule
77
module obuf
78
  (
79
   input i,
80
   inout pad
81
   );
82
   assign #1 pad = i;
83
endmodule
84
module smii_sync
85
  (
86
    output            sync,
87
    output reg [1:10] state,
88
    input             clk,
89
    input             rst
90
   );
91
   always @ (posedge clk or posedge rst)
92
     if (rst)
93
       state <= 10'b0000000001;
94
     else
95
       state <= {state[10],state[1:9]};
96
   assign sync = state[1];
97
endmodule
98
module smii_txrx
99
  (
100
    output     tx,
101
    input      rx,
102
    input [3:0] mtxd,
103
    input       mtxen,
104
    input       mtxerr,
105
    output      mtx_clk,
106
    output reg [3:0] mrxd,
107
    output reg   mrxdv,
108
    output reg   mrxerr,
109
    output       mrx_clk,
110
    output       mcoll,
111
    output reg   mcrs,
112
    input [1:10] state,
113
    input        clk,
114
    input        rst
115
   );
116
   reg [0:7]              tx_data_reg;
117
   reg                   tx_data_reg_valid;
118
   reg                   a0;
119
   reg                   state_data;
120
   reg [3:0]      rx_tmp;
121
   reg           speed;
122
   reg           duplex;
123
   reg           link;
124
   reg           jabber;
125
   reg           mtx_clk_tmp, mrx_clk_tmp;
126
   reg [3:0]      tx_cnt;
127
   reg [3:0]      rx_cnt;
128
   always @ (posedge clk or posedge rst)
129
     if (rst)
130
       tx_cnt <= 4'd0;
131
     else
132
       if (speed)
133
         tx_cnt <= 4'd0;
134
       else if (state[10])
135
         if (tx_cnt == 4'd9)
136
           tx_cnt <= 4'd0;
137
         else
138
           tx_cnt <= tx_cnt + 4'd1;
139
     always @ (posedge clk or posedge rst)
140
     if (rst)
141
       mtx_clk_tmp <= 1'b0;
142
     else
143
       if ((state[10] | state[5]) & (tx_cnt == 4'd0))
144
         mtx_clk_tmp <= 1'b1;
145
       else if (state[2] | state[7])
146
         mtx_clk_tmp <= 1'b0;
147
   gbuf bufg1
148
     (
149
      .CLK(mtx_clk_tmp),
150
      .GL(mtx_clk)
151
      );
152
   always @ (posedge clk or posedge rst)
153
     if (rst)
154
       begin
155
          tx_data_reg <= 8'd0;
156
          tx_data_reg_valid <= 1'b0;
157
          a0 <= 1'b0;
158
       end
159
     else
160
       if ((state[4] | state[9]) & (tx_cnt == 4'd0))
161
         begin
162
            if (!mtxen)
163
              a0 <= 1'b0;
164
            else
165
              a0 <= ~a0;
166
            if (!mtxen & !a0)
167
              tx_data_reg_valid <= 1'b0;
168
            else if (a0)
169
              tx_data_reg_valid <= 1'b1;
170
            if (mtxen & !a0)
171
              tx_data_reg[0:3] <= {mtxd[0],mtxd[1],mtxd[2],mtxd[3]};
172
            else if (mtxen & a0)
173
              tx_data_reg[4:7] <= {mtxd[0],mtxd[1],mtxd[2],mtxd[3]};
174
         end
175
   always @ (posedge clk or posedge rst)
176
     if (rst)
177
       state_data <= 1'b0;
178
     else
179
       if (state[1] & (tx_cnt == 4'd0))
180
         state_data <= tx_data_reg_valid;
181
   assign tx = state[1] ? mtxerr :
182
               state[2] ? ((tx_data_reg_valid & (tx_cnt == 4'd0)) | state_data) :
183
               state_data ? |(state[2:10] & tx_data_reg) :
184
               |(state[2:10] & {mtxerr,speed,duplex,link,jabber,3'b111});
185
   always @ (posedge clk or posedge rst)
186
     if (rst)
187
       rx_cnt <= 4'd0;
188
     else
189
       if (speed)
190
         rx_cnt <= 4'd0;
191
       else if (!mrxdv & state[8] & rx_tmp[3])
192
         rx_cnt <= 4'd9;
193
       else if (state[10])
194
         if (rx_cnt == 4'd9)
195
           rx_cnt <= 4'd0;
196
         else
197
           rx_cnt <= rx_cnt + 4'd1;
198
   always @ (posedge clk or posedge rst)
199
     if (rst)
200
       begin
201
          {mcrs, mrxdv, mrxerr, speed, duplex, link, jabber} <= 7'b0001110;
202
          rx_tmp <= 4'h0;
203
          mrxd <= 4'h0;
204
       end
205
     else
206
       begin
207
          rx_tmp[2:0] <= {rx,rx_tmp[2:1]};
208
          if (state[3])
209
            mcrs <= rx;
210
          if (state[4])
211
            rx_tmp[3] <= rx;
212
          if (rx_tmp[3])
213
            begin
214
               if (state[8])
215
                 {mrxdv,mrxd} <= #1 {rx_tmp[3],rx,rx_tmp[2:0]};
216
               else if (state[2])
217
                 mrxd <= #1 {rx,rx_tmp[2:0]};
218
            end
219
          else
220
            begin
221
               if (state[5])
222
                 mrxerr <= #1 rx;
223
               if (state[6])
224
                 speed <= #1 rx;
225
               if (state[7])
226
                 duplex <= #1 rx;
227
               if (state[8])
228
                 begin
229
                    link <= #1 rx;
230
                    mrxdv <= #1 1'b0;
231
                 end
232
               if (state[9])
233
                 jabber <= #1 rx;
234
            end
235
       end
236
   always @ (posedge clk or posedge rst)
237
     if (rst)
238
       mrx_clk_tmp <= 1'b0;
239
     else
240
       if ((state[1] | state[6]) & (rx_cnt == 4'd0))
241
         mrx_clk_tmp <= 1'b1;
242
       else if (state[3] | state[8])
243
         mrx_clk_tmp <= 1'b0;
244
   gbuf bufg2
245
     (
246
      .CLK(mrx_clk_tmp),
247
      .GL(mrx_clk)
248
      );
249
   assign mcoll = mcrs & mtxen;
250
endmodule

powered by: WebSVN 2.1.0

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