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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [src/] [mRegisters.v] - Blame information for rev 15

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jefflieu
/*
2 15 jefflieu
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 2 jefflieu
File            :
19
Description     :
20
Remarks         :
21
Revision        :
22
        Date    Author          Description
23
02/09/12        Jefflieu
24
*/
25
`timescale 1ns/100ps
26
`include "SGMIIDefs.v"
27
module mRegisters(
28
        input w_ARstLogic_L,
29
        input i_Clk,
30
        input i_Cyc,
31
        input i_Stb,
32
        input i_WEn,
33
        input [07:00] i8_Addr,
34
        input [31:00] i32_WrData,
35
        output reg [31:00] o32_RdData,
36
        output reg o_Ack,
37
        output o_Stall,
38
 
39
        inout io_Mdio,
40
        input i_Mdc,
41
 
42
        //This is used in Phy-Side SGMII 
43
        input   i_PhyLink,
44
        input   i_PhyDuplex,
45
        input   [1:0] i2_PhySpeed,
46
 
47
        //MAC-Side Speed,
48
        output  [01:00] o2_SGMIISpeed,
49
        //MAC-Side Duplex,
50
        output  o_SGMIIDuplex,
51
 
52
 
53
        //Register in and out,
54
        output  [20:00] o21_LinkTimer,
55
 
56
        input   [02:00] i3_XmitState,
57
        input   [15:00] i16_TxConfigReg,
58
        output o_MIIRst_L,
59
        output o_ANEnable,
60
        output o_ANRestart,
61
        output o_Loopback,
62
        output o_GXBPowerDown,
63
        output [15:00] o16_LcAdvAbility,
64
        input   i_ANComplete,
65
        input   i_SyncStatus,
66
        input [15:00] i16_LpAdvAbility);
67
 
68
        //TODO: Local BUs interface to setup registers
69
        //Register Write        
70
        wire    w_Write;
71
        reg     r_Write;
72
        wire    w_WritePulse;
73
        wire    [04:00] w5_Addr;
74
        wire    [15:00] w16_WrData;
75
        reg     [15:00] r16_CtrlReg0;
76
        reg     [15:00] r16_CtrlReg4;
77
        wire    [15:00] w16_StatusReg1;
78
        reg             [15:00] r16_ModeReg;
79
        wire    [15:00] w16_LcAdvAbility;
80
        wire    w_UseAsSGMII;
81
        reg     r_Read;
82
        wire    w_Read;
83
        wire    w_ReadPulse;
84
        wire    w_SGMII_PHY;
85
        reg [20:00] r21_LinkTimer;
86
        reg [15:00] r16_ScratchRev;
87
        wire w_UseLcConfig;
88
 
89
        assign o21_LinkTimer = r21_LinkTimer;
90
        assign w5_Addr = i8_Addr[6:2];
91
        assign w16_WrData = i32_WrData[15:00];
92
        assign w_Write = (i_Cyc & i_Stb & i_WEn);
93
        assign w_WritePulse = w_Write & (~r_Write);
94
        assign w_Read = (i_Cyc & i_Stb & (~i_WEn));
95
        assign w_ReadPulse = w_Read & (~r_Read);
96
        assign o_Stall = (w_Write|w_Read)&(~o_Ack);
97
        always@(posedge i_Clk or negedge w_ARstLogic_L)
98
        if(w_ARstLogic_L==1'b0)
99
                begin
100
                        r16_CtrlReg4 <= `cReg4Default;
101
                        r16_CtrlReg0 <= `cReg0Default;
102
                        r16_ModeReg  <= `cRegXDefault;
103
                        r21_LinkTimer <= `cRegLinkTimerDefault;
104
                        r16_ScratchRev <= 16'h1_0_00;
105
                end
106
        else
107
        begin
108
                //Write Controller
109
                r_Write <= w_Write;
110
                o_Ack  <= w_WritePulse|w_ReadPulse;
111
                //Control Register 0
112
                if(w_WritePulse && w5_Addr==5'b00000) r16_CtrlReg0 <= w16_WrData;
113
                else begin
114
                        if(i3_XmitState==`cXmitCONFIG) r16_CtrlReg0[9] <= 1'b0;
115
                        r16_CtrlReg0[15] <= 1'b0;
116
                end
117
 
118
 
119
                if(w_WritePulse && w5_Addr==5'b00100) r16_CtrlReg4 <= w16_WrData;
120
 
121
                if(w_WritePulse && w5_Addr==5'b01000) r21_LinkTimer[15:00] <= w16_WrData;
122
                if(w_WritePulse && w5_Addr==5'b01001) r21_LinkTimer[20:16] <= w16_WrData[4:0];
123
                if(w_WritePulse && w5_Addr==5'b01010) r16_ScratchRev    <= w16_WrData;
124
                if(w_WritePulse && w5_Addr==5'b11111) r16_ModeReg               <= w16_WrData;
125
 
126
                //Read Controller
127
                r_Read <= w_Read;
128
 
129
                if(w_ReadPulse)
130
                        case(w5_Addr)
131
                        5'h00:          o32_RdData <= {16'h0,r16_CtrlReg0};
132
                        5'h01:          o32_RdData <= {16'h0,w16_StatusReg1};
133
                        5'h02:          o32_RdData <= 32'h0;
134
                        5'h03:          o32_RdData <= 32'h0;
135
                        5'h04:          o32_RdData <= {16'h0,w16_LcAdvAbility};
136
                        5'h05:          o32_RdData <= {16'h0,i16_LpAdvAbility};
137
                        5'h08:          o32_RdData <= {16'h0,r21_LinkTimer[15:00]};
138
                        5'h09:          o32_RdData <= {16'h0,11'h0,r21_LinkTimer[20:16]};
139
                        5'h0A:          o32_RdData <= r16_ScratchRev;
140
                        5'h1F:          o32_RdData <= r16_ModeReg;
141
                        default:        o32_RdData <= 32'h0;
142
                        endcase
143
        end
144
        assign o_ANRestart              = r16_CtrlReg0[9];
145
        assign o_MIIRst_L               = ~r16_CtrlReg0[15];
146
        assign o_ANEnable               = r16_CtrlReg0[12];
147
        assign o_Loopback               = r16_CtrlReg0[14];
148 13 jefflieu
        assign o_GXBPowerDown   = r16_CtrlReg0[11];
149 2 jefflieu
        assign o16_LcAdvAbility = w16_LcAdvAbility;
150
 
151
        assign w16_LcAdvAbility = (w_UseAsSGMII==1'b0)?({1'b0,i16_TxConfigReg[15],r16_CtrlReg4[13:12],3'b000,r16_CtrlReg4[8:7],2'b01,5'b00000})://1000-X mode
152 3 jefflieu
                                                                ((w_SGMII_PHY==1'b1)?({i_PhyLink,i16_TxConfigReg[15],1'b0,(i_PhyDuplex|r16_CtrlReg4[12]),(i2_PhySpeed|r16_CtrlReg4[11:10]),10'h1})://SGMII mode - PHY Side
153 2 jefflieu
                                                                ({1'b0,i16_TxConfigReg[15],1'b0,3'b000,10'h1}));//SGMII mode - MAC Side
154
 
155
        assign w16_StatusReg1 = {9'h0,i_ANComplete,2'b01,i_SyncStatus,2'b0};
156
        assign w_UseAsSGMII     = r16_ModeReg[0];
157
        assign w_SGMII_PHY              = r16_ModeReg[1];
158
        assign w_UseLcConfig    = r16_ModeReg[2];
159 10 jefflieu
        assign o2_SGMIISpeed    = (w_UseAsSGMII==1'b0)?2'b10:((w_UseLcConfig==1'b0)?i16_LpAdvAbility[11:10]:{r16_CtrlReg0[6]|i2_PhySpeed[1],r16_CtrlReg0[13]|i2_PhySpeed[0]});
160
        assign o_SGMIIDuplex    = (w_UseAsSGMII==1'b0)?1'b1:((w_UseLcConfig==1'b0)?i16_LpAdvAbility[12]:{r16_CtrlReg0[8]|i_PhyDuplex});
161 2 jefflieu
 
162
endmodule

powered by: WebSVN 2.1.0

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