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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [src/] [mANCtrl.v] - Blame information for rev 2

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

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

powered by: WebSVN 2.1.0

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