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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [build/] [sgmii_demo_88e1111.v] - Blame information for rev 24

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jefflieu
/*
2
Copyright © 2012 JeffLieu-lieumychuong@gmail.com
3
 
4
        This file is part of SGMII-IP-Core.
5
    SGMII-IP-Core is free software: you can redistribute it and/or modify
6
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation, either version 3 of the License, or
8
    (at your option) any later version.
9
 
10
    SGMII-IP-Core is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU General Public License for more details.
14
 
15
    You should have received a copy of the GNU General Public License
16
    along with SGMII-IP-Core.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
File            :       sgmii_demo.v
19
Description     :       This file implements top-level file to test SGMII core
20
 
21
Remarks         :
22
 
23
Revision        :
24
        Date    Author  Description
25
 
26
*/
27
 
28
module sgmii_demo_88e1111(
29
        input   i_Clkin,
30
        input   i_ARst_L,
31
        output  o_SGMIITx,
32
        input   i_SGMIIRx,
33
        output  o_LedANDone,
34
        output  o_LedSpeed1000Mbps,
35
        output  o_LedLinkUp,
36
        output  o_LedHeartBeat,
37
 
38
        output  o_Mdc,
39
        inout   io_Mdio,
40
        output  o_PhyRst_L,
41
 
42
        input   [7:0] i8_TxD,
43
        input   i_TxEN,
44
        input   i_TxER,
45
        output  [7:0] o8_RxD,
46
        output  o_RxDV,
47
        output  o_RxER,
48
        output  o_GMIIClk,
49
        output  o_MIIClk,
50
        output  o_Col,
51
        output  o_Crs);
52
 
53
 
54
        wire w_ARst_L;
55
        //Bus Interface
56
        wire w_Cyc,w_Stb,w_WEn,w_Ack;
57
        wire w_SgmiiAck,w_MdioAck;
58
        wire [31:0] w32_RdData,w32_WrData;
59
        wire [31:0] w32_RdDataSgmii,w32_RdDataMdio;
60
        wire [7:0] w8_Addr;
61
        wire [1:0] w2_SGMIISpeed;
62
        wire w_Duplex;
63
        wire w_LinkUp,w_ANDone;
64
        wire [1:0] w2_CS;
65
        wire w_SysRst_L;
66
        reg r_SysRstD1_L,r_SysRstD2_L;
67
 
68
        wire [31:0] w32_RxMacD,w32_TxMacD;
69
        wire w_RxMacRa,w_RxMacRd,w_RxMacPa,w_RxMacSop,w_RxMacEop;
70
        wire w_TxMacWa,w_TxMacWr,w_TxMacPa,w_TxMacSop,w_TxMacEop;
71
        wire [1:0] w2_RxMacBE,w2_TxMacBE;
72
        wire [7:0] w8_TxD,w8_RxD;
73
        wire w_TxEn,w_TxEr,w_RxDv,w_RxEr;
74
        reg r_TxEn,r_TxEr;
75
        reg [7:0] r8_TxD;
76
        wire [15:0] w16_PktLength;
77
        reg [31:0] r32_PacketLengthCntr;
78
        reg r_ReadPktLength;
79
        reg r_ReadPkt;
80
        reg [31:0] r32_PktCntr;
81
 
82
        mPshBtnDbnce u0Dbncer(.i_Clk(i_Clkin),.i_PshBtn(i_ARst_L),.o_Dbnced(w_ARst_L));
83
 
84
        //SGMII Core
85
        mSGMII u0SGMII
86
        (
87
        //Tranceiver Interface
88
        .i_SerRx                        (i_SGMIIRx),
89
        .o_SerTx                        (o_SGMIITx),
90
        .i_CalClk                       (1'b0),
91
        .i_RefClk125M           (i_Clkin),
92
        .i_ARstHardware_L       (r_SysRstD2_L),
93
 
94
        //Local BUS interface
95
        //Wishbonebus, single transaction mode (non-pipeline slave)
96
        .i_Cyc                  (w_Cyc&w2_CS[0]),
97
        .i_Stb                  (w_Stb&w2_CS[0]),
98
        .i_WEn                  (w_WEn&w2_CS[0]),
99
        .i32_WrData             (w32_WrData),
100
        .iv_Addr                (w8_Addr),
101
        .o32_RdData             (w32_RdDataSgmii),
102
        .o_Ack                  (w_SgmiiAck),
103
 
104
        .i_Mdc          (1'b0),
105
        .io_Mdio        (),
106
 
107
        .o_Linkup       (w_LinkUp),
108
        .o_ANDone       (w_ANDone),
109
        //This is used in Phy-Side SGMII 
110
        .i_PhyLink              (1'b0),
111
        .i_PhyDuplex    (1'b0),
112
        .i2_PhySpeed    (2'b0),
113
 
114
 
115
        .o2_SGMIISpeed  (w2_SGMIISpeed),
116
        .o_SGMIIDuplex  (w_Duplex),
117
 
118
        //GMII Interface
119
        .o_TxClk        (w_TxClk        ),
120
        .o_RxClk        (w_RxClk        ),
121
        .i8_TxD         (w8_TxD         ),
122
        .i_TxEN         (w_TxEn         ),
123
        .i_TxER         (w_TxEr         ),
124
        .o8_RxD         (w8_RxD         ),
125
        .o_RxDV         (w_RxDv         ),
126
        .o_RxER         (w_RxEr         ),
127
        .o_GMIIClk      (w_GMIIClk      ),
128
        .o_MIIClk       (o_MIIClk       ),
129
        .o_Col          (o_Col          ),
130
        .o_Crs          (o_Crs          ));
131
 
132
        //Initializer
133
        mWishboneMaster88E1111  u0WishboneMaster(
134
                        .ov_CSel(w2_CS),
135
                        .o_Cyc(w_Cyc),
136
                        .o_Stb(w_Stb),
137
                        .o_WEn(w_WEn),
138
                        .i_Ack(w_Ack),
139
                        .o32_WrData(w32_WrData),
140
                        .i32_RdData(w32_RdData),
141
                        .ov_Addr(w8_Addr),
142
                        .i_Clk(w_GMIIClk),
143
                        .i_ARst_L(r_SysRstD2_L));
144
 
145
        assign w_Ack = (w2_CS[0]&w_SgmiiAck)|(w2_CS[1]&w_MdioAck);
146
        assign w32_RdData = (w2_CS==2'b01)?w32_RdDataSgmii:((w2_CS==2'b10)?w32_RdDataMdio:32'h0);
147
 
148
 
149
        mMdioMstr u0MdioMstr(
150
        .i_Clk          (w_GMIIClk      ),
151
        .i_ARst_L       (r_SysRstD2_L),
152
        //Wishbone interface
153
        .i_Cyc          (w_Cyc&w2_CS[1]),
154
        .i_Stb          (w_Stb&w2_CS[1]),
155
        .i_WEn          (w_WEn&w2_CS[1]),
156
        .o_Ack          (w_MdioAck),
157
        .i2_Addr        (w8_Addr[1:0]),
158
        .i32_WrData     (w32_WrData),
159
        .o32_RdData     (w32_RdDataMdio),
160
 
161
        //MDIO Interface
162
        .o_Mdc          (o_Mdc),
163
        .io_Mdio        (io_Mdio));
164
 
165
        assign o_LedANDone = ~w_ANDone;
166
        assign o_LedLinkUp = ~w_LinkUp;
167
        assign o_LedSpeed1000Mbps = (w2_SGMIISpeed==2'b10)?1'b0:1'b1;
168
 
169
        //PowerOnPhyReset
170
        reg [24:0] r25_PhyRstCntr;
171
        always@(posedge i_Clkin or negedge w_ARst_L)
172
        if(~w_ARst_L)
173
                r25_PhyRstCntr<=20'h0;
174
        else if(~w_SysRst_L)
175
                r25_PhyRstCntr<=r25_PhyRstCntr+20'h1;
176
        assign o_PhyRst_L = r25_PhyRstCntr[24]?1'bz:1'b0;
177
        assign w_SysRst_L = (&r25_PhyRstCntr);
178
 
179
 
180
        always@(posedge w_GMIIClk)
181
                begin
182
                        r_SysRstD1_L <= w_SysRst_L;
183
                        r_SysRstD2_L <= r_SysRstD1_L;
184
                end
185
 
186
        //////////////////////////////////////////////////
187
        //Open core MAC
188
        //////////////////////////////////////////////////
189
 
190
 
191
        MAC_top OpenCoreMac(
192
    //system signals
193
        .Reset                  ( ~w_SysRst_L),
194
 
195
        .Clk_user       (w_TxClk),
196
        .Clk_reg        (w_GMIIClk),
197
 
198
        .Speed                  (),
199
        .GMII_Tx_clk    (w_TxClk),
200
        .GMII_Rx_clk    (w_RxClk),
201
 
202
    //user interface 
203
        .Rx_mac_ra              (w_RxMacRa),
204
        .Rx_mac_rd              (w_RxMacRd),
205
        .Rx_mac_data    (w32_RxMacD),
206
        .Rx_mac_BE              (w2_RxMacBE),
207
        .Rx_mac_pa              (w_RxMacPa),
208
        .Rx_mac_sop             (w_RxMacSop),
209
        .Rx_mac_eop             (w_RxMacEop),
210
                //user interface 
211
        .Tx_mac_wa               (w_TxMacWa),
212
        .Tx_mac_wr               (w_TxMacWr),
213
        .Tx_mac_data             (w32_TxMacD),
214
        .Tx_mac_BE               (w2_TxMacBE),//big endian
215
        .Tx_mac_sop              (w_TxMacSop),
216
        .Tx_mac_eop              (w_TxMacEop),
217
        //pkg_lgth fifo         ()
218
        .Pkg_lgth_fifo_rd        (w_PktLengthRd),
219
        .Pkg_lgth_fifo_ra        (w_PktLengthRa),
220
        .Pkg_lgth_fifo_data      (w16_PktLength),
221
                //Phy interface          
222
                //Phy interface         
223
        .Gtx_clk_d      (),//shifted clock
224
        .Gtx_clk        (),//used only in GMII mode
225
 
226
        .Rx_clk         (o_MIIClk),
227
        .Tx_clk         (),//used only in MII mode
228
        .Tx_er          (w_TxEr),
229
        .Tx_en          (w_TxEn),
230
        .Txd            (w8_TxD),
231
        .Rx_er          (w_RxEr ),
232
        .Rx_dv          (w_RxDv ),
233
        .Rxd            (w8_RxD ),
234
        .Crs            (w_Crs  ),
235
        .Col            (w_Col  ),
236
                //host interface
237
        .CSB            (1'b1),
238
        .WRB            (1'b1),
239
        .CD_in          (0),
240
        .CD_out         (),
241
        .CA             (0),
242
 
243
        .Monitoring     (),
244
 
245
        .Mdo    (),                     // MII Management Data Output
246
        .MdoEn  (),                     // MII Management Data Output Enable
247
        .Mdi    (1'b0),
248
        .Mdc    ()                      // MII Management Data Clock       
249
 
250
);
251
        /////////////////////////////////////////////
252
        //Packet Generator
253
        //A little state machine to push to the packet
254
        ////////////////////////////////////////////
255
        reg r_Transmit;
256
        wire w_PktReady;
257
        always@(posedge w_TxClk or negedge w_SysRst_L)
258
        if(~w_SysRst_L)
259
                begin
260
                        r_Transmit <= 1'b0;
261
                end
262
        else
263
                begin if(w_ANDone)
264
                        if(w_PktReady & w_TxMacWa)
265
                                r_Transmit <= 1'b1;
266
                        else if(w_TxMacEop)
267
                                r_Transmit <= 1'b0;
268
                end
269
 
270
        pkt_gen32 PacketGen(
271
        .clk            (w_TxClk),
272
        .rst            (~w_SysRst_L),
273
        .control        (16'h1),
274
        .status         (),
275
        .config_1       (32'hF_0200),
276
        .config_2       (32'h0_FFFF),
277
        .i32_Payload1(r32_PacketLengthCntr),
278
        .i32_Payload2(r32_PktCntr),
279
        .i32_Payload3(0),
280
        .i32_Payload4(0),
281
        .pkt_rdy        (w_PktReady),
282
        .pkt_dv         (w_TxMacWr),
283
        .pkt_sop        (w_TxMacSop),
284
        .pkt_eop        (w_TxMacEop),
285
        .pkt_data       (w32_TxMacD),
286
        .pkt_rd         (r_Transmit),
287
        .pkt_BE         (w2_TxMacBE),
288
        .pkt_len_rd             (),
289
        .pkt_len_rdy    (),
290
        .pkt_len                ());
291
 
292
 
293
                always@(posedge w_TxClk or negedge w_SysRst_L)
294
                if(~w_SysRst_L)
295
                        begin
296
                                r32_PacketLengthCntr <= 0;
297
                                r_ReadPkt <= 1'b0;
298
                                r32_PktCntr <= 0;
299
                        end
300
                else begin
301
                        if(w_PktLengthRa & (~r_ReadPkt))
302
                                begin
303
                                r_ReadPkt <= 1'b1;
304
                                end
305
                        else
306
                                if(w_RxMacEop)
307
                                        r_ReadPkt <= 1'b0;
308
 
309
                        if(w_RxMacSop) begin
310
                                r32_PktCntr<=r32_PktCntr+32'h1;
311
                                r32_PacketLengthCntr<=r32_PacketLengthCntr+{16'h0,w16_PktLength};
312
                                end
313
 
314
 
315
                        end
316
 
317
                assign w_PktLengthRd = w_RxMacSop;
318
                assign w_RxMacRd = r_ReadPkt;
319
 
320
 
321
endmodule

powered by: WebSVN 2.1.0

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