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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [src/] [mANCtrl.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         :       No Support for Next Page
21
Revision        :
22
        Date    Author          Description
23
02/09/12        Jefflieu
24
*/
25
 
26
`include "SGMIIDefs.v"
27
 
28
`timescale 1ns/100ps
29
 
30
 
31
`define c10ms           (10_000_000/`cSystemClkPeriod)
32
`define c1p6ms          (00_001_000/`cSystemClkPeriod)
33
 
34
 
35
 
36
 
37
module mANCtrl(
38
        input   i_Clk,
39
        input   i_ARst_L,
40
        input   i_Cke,
41
        input   i_RestartAN,
42
        input   i_SyncStatus,
43
        input   i_ANEnable,
44
 
45
        input   [20:00] i21_LinkTimer,
46
        output  [15:00] o16_LpAdvAbility,
47
        input   [16:01] i16_LcAdvAbility,
48
 
49
        input   [15:00] i16_RxConfigReg,
50
        input   i_RUDIConfig,
51
        input   i_RUDIIdle,
52
        input   i_RUDIInvalid,
53
        output  o_ANComplete,
54
        output  reg [02:00]     o3_Xmit,
55
        output  reg [15:00]     o16_TxConfigReg);
56
 
57
 
58
        localparam      stAN_ENABLE     = 8'h01,
59
                                stAN_RESTART    = 8'h02,
60
                                stABILITY_DTECT = 8'h04,
61
                                stACK_DTECT             = 8'h08,
62
                                stCMPLT_ACK             = 8'h10,
63
                                stIDLE_DTECT    = 8'h20,
64
                                stLINK_OK               = 8'h40,
65
                                stAN_DIS_LINKOK = 8'h80;
66
 
67
 
68
 
69
        reg     [20:00] r21_LinkTimer;
70
        reg     [02:00] r2_RxCfgRegMchCntr;
71
        wire    w_AbiMatch;
72
        reg             r_ConsistencyMatch;
73
        wire    w_AckMatch;
74
        reg [07:00] r8_State;
75
        reg r_ANEable;
76
        wire    w_LinkTimerDone;
77
        reg [16:01] r16_LpAdvAbility;   //Link partner Advertised Ability, updated every time RUDIConfig is valid
78
        reg     r_NxtPage;
79
        reg r_NxtPageLoaded;
80
        reg r_ToggleTx;
81
        reg r_ToggleRx;
82
        reg [01:00] r2_AbilityMatchCnt;
83
        reg [01:00] r2_ConsistMatchCnt;
84
        reg [01:00] r2_AcknowlMatchCnt;
85
        reg [15:00] r16_AbilityReg;             //Captured of Partner Ability before going to Acknowledge Detect
86
        reg [01:00] r2_IdleMatchCnt;
87
        wire w_IdleMatch;
88
 
89
        assign w_LinkTimerDone = (r21_LinkTimer==i21_LinkTimer)?1'b1:1'b0;
90
        assign w_AbiMatch = (r2_AbilityMatchCnt==2'b11)?1'b1:1'b0;
91
        assign w_AckMatch = (r2_AcknowlMatchCnt==2'b11)?1'b1:1'b0;
92
        assign w_IdleMatch = (r2_IdleMatchCnt==2'b11)?1'b1:1'b0;
93
        assign o16_LpAdvAbility = r16_LpAdvAbility;
94
        assign o_ANComplete = (r8_State==stLINK_OK)?1'b1:1'b0;
95
        always@(posedge i_Clk or negedge i_ARst_L)
96
        if(i_ARst_L==1'b0) begin
97
                r8_State <= stAN_ENABLE;
98
        end else begin
99
                r_ANEable <= i_ANEnable;
100
                if((~i_Cke) || i_RestartAN || (~i_SyncStatus) || i_RUDIInvalid || (r_ANEable^i_ANEnable))
101
                        r8_State <= stAN_ENABLE;
102
                else
103
                        case(r8_State)
104
                        stAN_ENABLE             :       if(i_ANEnable) r8_State <= stAN_RESTART; else r8_State <= stAN_DIS_LINKOK;
105
                        stAN_RESTART    :       if(w_LinkTimerDone) r8_State <= stABILITY_DTECT;
106
                        stABILITY_DTECT :       if(w_AbiMatch && r16_LpAdvAbility!=16'h0000) r8_State <= stACK_DTECT;
107
                        stACK_DTECT             :       if((w_AckMatch && (~r_ConsistencyMatch))||(w_AbiMatch && i16_RxConfigReg==16'h0000 && i_RUDIConfig))
108
                                                                        r8_State <= stAN_ENABLE;
109
                                                                else if(w_AckMatch && r_ConsistencyMatch)
110
                                                                        r8_State <= stCMPLT_ACK;
111
                        stCMPLT_ACK             :       if(w_AbiMatch && r16_LpAdvAbility==16'h0000) r8_State <= stAN_ENABLE;
112
                                                                else if(w_LinkTimerDone && (~w_AbiMatch||(r16_LpAdvAbility!=16'h0000)))
113
                                                                                                r8_State <= stIDLE_DTECT;
114
                        stIDLE_DTECT    :       if(w_IdleMatch && w_LinkTimerDone) r8_State <= stLINK_OK; else
115 15 jefflieu
                                                                        if(w_AbiMatch && r16_LpAdvAbility==16'h0000) r8_State <= stAN_ENABLE;
116 2 jefflieu
 
117
                        stLINK_OK               :       if(w_AbiMatch) r8_State <= stAN_ENABLE;
118
                        stAN_DIS_LINKOK :       r8_State <= stAN_DIS_LINKOK;
119
                        endcase
120
        end
121
 
122
        always@(posedge i_Clk or negedge i_ARst_L)
123
        if(!i_ARst_L) begin
124
                r16_LpAdvAbility        <= 16'h0000;
125
                o3_Xmit                         <= `cXmitIDLE;
126
                r21_LinkTimer           <= 21'h0;
127
                o16_TxConfigReg         <= 16'h0;
128
                r2_IdleMatchCnt         <= 2'b00;
129
                r16_AbilityReg          <= 16'h0;
130
        end else begin
131
                //Xmit 
132
                case(r8_State)
133
                stAN_ENABLE : if(i_ANEnable) o3_Xmit <= `cXmitCONFIG; else o3_Xmit <= `cXmitIDLE;
134
                stIDLE_DTECT: o3_Xmit <= `cXmitIDLE;
135
                stLINK_OK       : o3_Xmit <= `cXmitDATA;
136
                stAN_DIS_LINKOK: o3_Xmit <= `cXmitDATA;
137
                endcase
138
 
139
                case(r8_State)
140
                stAN_ENABLE: r21_LinkTimer <= 21'h0;
141
                stAN_RESTART: if(w_LinkTimerDone==1'b0) r21_LinkTimer <= r21_LinkTimer+21'h1;
142
                stACK_DTECT : r21_LinkTimer <= 21'h0;
143
                stCMPLT_ACK     : if(w_LinkTimerDone && (~w_AbiMatch||(r16_LpAdvAbility!=16'h0000))) r21_LinkTimer <= 21'h0; else
144
                                                if(w_LinkTimerDone==1'b0) r21_LinkTimer <= r21_LinkTimer+21'h1;
145
                stIDLE_DTECT: if(w_LinkTimerDone==1'b0) r21_LinkTimer <= r21_LinkTimer+21'h1;
146
                stLINK_OK       : r21_LinkTimer <= 21'h0;
147
                endcase
148
 
149
 
150
                case(r8_State)
151
                stAN_ENABLE: if(i_ANEnable) o16_TxConfigReg <= 16'h0000;
152
                stAN_RESTART: if(w_LinkTimerDone) begin
153
                                                o16_TxConfigReg[15] <= i16_LcAdvAbility[16];
154
                                                o16_TxConfigReg[14] <= 1'b0;
155
                                                o16_TxConfigReg[13:0] <= i16_LcAdvAbility[14:1];
156
                                                end
157
                stACK_DTECT : o16_TxConfigReg[14] <= 1'b1;
158
                endcase
159
 
160
 
161
                if(r8_State==stABILITY_DTECT) r_ToggleTx <= i16_LcAdvAbility[12];
162
                else if(r8_State==stCMPLT_ACK) r_ToggleTx <= ~r_ToggleTx;
163
 
164
                if(r8_State==stCMPLT_ACK) r_ToggleRx<=i16_RxConfigReg[11];
165
 
166
                //Sync Reset
167
                if(r8_State==stAN_RESTART)
168
                begin
169
                        r2_AbilityMatchCnt      <= 2'b00;
170
                        r16_AbilityReg          <= 16'h0;
171
                        r16_LpAdvAbility        <= 16'h0;
172
                        r2_AcknowlMatchCnt      <= 2'b00;
173
                        r_ConsistencyMatch      <= 1'b0;
174
                        r2_IdleMatchCnt         <= 2'b00;
175
                end else
176
                begin
177
                        //w_AbiMatch            
178
                        if(i_RUDIIdle)
179
                                r2_AbilityMatchCnt <= 2'b00;
180
                        else if(i_RUDIConfig) begin
181
                                if(i16_RxConfigReg[13:00] == r16_LpAdvAbility[14:01] && i16_RxConfigReg[15]==r16_LpAdvAbility[16])
182
                                        begin
183
                                        if(r2_AbilityMatchCnt!=2'b11) r2_AbilityMatchCnt<=r2_AbilityMatchCnt+1;
184
                                        end
185
                                else
186
                                        r2_AbilityMatchCnt <= 2'b01;
187
                        end
188
 
189
                        if(r8_State==stABILITY_DTECT && w_AbiMatch && r16_LpAdvAbility!=16'h00) r16_AbilityReg <= r16_LpAdvAbility;
190
 
191
                        //Ack Match
192
                        if(i_RUDIIdle)
193
                                r2_AcknowlMatchCnt <= 2'b00;
194
                        else if(i_RUDIConfig) begin
195
                                if(i16_RxConfigReg[15:00] == r16_LpAdvAbility[16:01] && (i16_RxConfigReg[14]==1'b1))
196
                                        begin
197
                                        if(r2_AcknowlMatchCnt!=2'b11) r2_AcknowlMatchCnt<=r2_AcknowlMatchCnt+1;
198
                                        //Consistency Match
199
                                        //When the flag acknowledge match is about to be set
200 15 jefflieu
                                        //If the bits are same as r16_LpAdvAbility , consistent
201 2 jefflieu
                                        //Else Not consistent;
202
                                        //Consistency match is set at the same time as Acknowledge match
203
                                        if(r2_AcknowlMatchCnt==2'b10 && (i16_RxConfigReg[13:00] == r16_AbilityReg[13:00] && i16_RxConfigReg[15]==r16_AbilityReg[15]))
204
                                                r_ConsistencyMatch <= 1'b1; else r_ConsistencyMatch<=1'b0;
205
                                        end
206
                                else
207
                                        r2_AcknowlMatchCnt <= 2'b01;
208
                        end
209
 
210
 
211
                        if(i_RUDIConfig)
212
                                r16_LpAdvAbility <= i16_RxConfigReg;
213
 
214
                        if(i_RUDIIdle) r2_IdleMatchCnt <= r2_IdleMatchCnt+2'b01;
215
                                else if(i_RUDIConfig|i_RUDIInvalid) r2_IdleMatchCnt<=2'b00;
216
 
217
                end
218
        end
219
 
220
        //synopsys synthesis_off
221
        reg [239:0] r240_ANStateName;
222
        always@(*)
223
        case(r8_State)
224
        stAN_ENABLE     :r240_ANStateName<="stAN_ENABLE         ";
225
        stAN_RESTART    :r240_ANStateName<="stAN_RESTART        ";
226
        stABILITY_DTECT :r240_ANStateName<="stABILITY_DTECT     ";
227
        stACK_DTECT             :r240_ANStateName<="stACK_DTECT         ";
228
        stCMPLT_ACK             :r240_ANStateName<="stCMPLT_ACK         ";
229
        stIDLE_DTECT    :r240_ANStateName<="stIDLE_DTECT        ";
230
        stLINK_OK               :r240_ANStateName<="stLINK_OK           ";
231
        stAN_DIS_LINKOK :r240_ANStateName<="stAN_DIS_LINKOK     ";
232
        endcase
233
        //synopsys synthesis_on
234
 
235
endmodule

powered by: WebSVN 2.1.0

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