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

Subversion Repositories sgmii

[/] [sgmii/] [trunk/] [build/] [mWishboneMaster88E1111.v] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 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
`define CMD_NOP 3'b000
28
`define CMD_RD  3'b001
29
`define CMD_WR  3'b010
30
`define CMD_WT  3'b011
31
`define CMD_JMP 3'b100
32
`define CMD_JEQ 3'b101
33
`define CMD_END 3'b111
34
`define MDIO_RD 2'b10
35
`define MDIO_WR 2'b01
36
`define MDIO_RD_FRAME(RDWR,PHYADDR,REGADDR) {16'h0,2'b01,RDWR,PHYADDR,REGADDR,2'b11}
37
`define MDIO_WR_FRAME(RDWR,PHYADDR,REGADDR) {16'h0,2'b01,RDWR,PHYADDR,REGADDR,2'b10}
38
`define MDIO_RD_REG27 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_RD_FRAME(`MDIO_RD,5'b0,5'd27)}
39
`define MDIO_RD_REG17 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_RD_FRAME(`MDIO_RD,5'b0,5'd17)}
40
`define MDIO_RD_REG00 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_WR_FRAME(`MDIO_RD,5'b0,5'd0)}
41
`define MDIO_RD_REG01 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_RD_FRAME(`MDIO_RD,5'b0,5'd01)}
42
`define MDIO_RD_REG04 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_RD_FRAME(`MDIO_RD,5'b0,5'd04)}
43
`define MDIO_RD_REG22 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_RD_FRAME(`MDIO_RD,5'b0,5'd22)}
44
`define MDIO_WR_REG27 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_WR_FRAME(`MDIO_WR,5'b0,5'd27)}
45
`define MDIO_WR_REG00 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_WR_FRAME(`MDIO_WR,5'b0,5'd0)}
46
`define MDIO_WR_REG22 {2'b10,8'hFF,`CMD_WR      ,8'h00  ,`MDIO_WR_FRAME(`MDIO_WR,5'b0,5'd22)}
47
 
48
 
49
module mWishboneMaster88E1111#(parameter pCommands=32,pAddrW=8,pChipSelect=2)
50
(
51
        output [pChipSelect-1:0] ov_CSel,
52
        output o_Cyc,
53
        output o_Stb,
54
        output o_WEn,
55
        output  [31:0]   o32_WrData,
56
        input   [31:0]   i32_RdData,
57
        output [pAddrW-1:0] ov_Addr,
58
        input   i_Ack,
59
        input   i_ARst_L,
60
        input   i_Clk);
61
 
62
        localparam pInstrWidth = pAddrW+32+3+8+pChipSelect;
63
        localparam      pFETCH  = 4'b0001,
64
                                pEXECU  = 4'b0010,
65
                                pNEXTI  = 4'b0100,
66
                                pWAIT   = 4'b1000;
67
 
68
 
69
        reg [3:0]        r4_State;
70
        reg [pInstrWidth-1:0]    rv_InstrReg;
71
        reg [pInstrWidth-1:0]    rv_MicroCodes[0:pCommands-1];
72
        reg [31:0] r32_ReadData;
73
 
74
        reg [7:0]        r8_InstrCnt;
75
        reg [31:0]       r32_WaitTmr;
76
        wire [2:0]       w3_Opcode;
77
        wire [7:0]       w8_WaitTime;
78
 
79
        /*Instruction Format
80
                        y-bit chipslect, 8-bit WaitTime, 3bit-Opcode, x-bit Address, 32-bit Data
81
        */
82
        assign ov_CSel          = rv_InstrReg[pInstrWidth-1-:pChipSelect];
83
        assign w8_WaitTime      = rv_InstrReg[pInstrWidth-1-pChipSelect-:8];
84
        assign w3_Opcode        = rv_InstrReg[pInstrWidth-1-pChipSelect-8-:3];
85
        assign ov_Addr          = rv_InstrReg[pInstrWidth-1-pChipSelect-8-3-:pAddrW];
86
        assign o32_WrData       = rv_InstrReg[31:0];
87
 
88
 
89
        always@(posedge i_Clk or negedge i_ARst_L)
90
        if(!i_ARst_L) begin
91
                        r8_InstrCnt <= 8'h0;
92
                        r4_State <= pFETCH;
93
                        r32_WaitTmr <= 32'h0;
94
                end
95
        else begin
96
                case(r4_State)
97
                pFETCH  :       begin
98
                                                rv_InstrReg <= rv_MicroCodes[r8_InstrCnt];
99
                                                r4_State <= pEXECU;
100
                                        end
101
                pEXECU  :       begin
102
                                                if(w3_Opcode==`CMD_WT)
103
                                                        begin
104
                                                        r4_State<=pWAIT;
105
                                                        r32_WaitTmr <= o32_WrData[31:0];
106
                                                        end
107
                                                else if(w3_Opcode==`CMD_RD||w3_Opcode==`CMD_WR) begin
108
                                                        if(i_Ack)
109
                                                                begin
110
                                                                r4_State<=pWAIT;
111
                                                                r32_WaitTmr <= {24'h0,w8_WaitTime};
112
                                                                if(w3_Opcode==`CMD_RD)  r32_ReadData <= i32_RdData;
113
                                                                end
114
                                                        end
115
                                                else begin
116
                                                        r4_State<=pWAIT;
117
                                                        r32_WaitTmr <= {24'h0,w8_WaitTime};
118
                                                        end
119
                                        end
120
                pNEXTI  :       begin
121
                                                if(w3_Opcode==`CMD_JMP)
122
                                                        r8_InstrCnt <= ov_Addr;
123
                                                else
124
                                                        if(w3_Opcode==`CMD_JEQ) begin
125
                                                                if(r32_ReadData==o32_WrData)
126
                                                                        r8_InstrCnt <= ov_Addr;
127
                                                                else
128
                                                                        r8_InstrCnt <= r8_InstrCnt+8'h1;
129
                                                        end
130
                                                        else
131
                                                                r8_InstrCnt <= r8_InstrCnt+8'h1;
132
                                                r4_State <= pFETCH;
133
                                        end
134
                pWAIT   :       if(w3_Opcode==`CMD_END)
135
                                                r4_State <= pWAIT;
136
                                        else
137
                                                if(r32_WaitTmr==0) r4_State <= pNEXTI; else r32_WaitTmr<=r32_WaitTmr-16'h1;
138
                endcase
139
                end
140
 
141
        assign o_Cyc = (r4_State==pEXECU)?1'b1:1'b0;
142
        assign o_Stb = (r4_State==pEXECU)?1'b1:1'b0;
143
        assign o_WEn = (r4_State==pEXECU&&w3_Opcode==`CMD_WR)?1'b1:1'b0;
144
 
145
 
146
 
147
        always@(posedge i_Clk)
148
        begin
149
                rv_MicroCodes[0] <={2'b01,8'h4,`CMD_RD   ,8'h28  ,32'h0                  };
150
                rv_MicroCodes[1]        <={2'b01,8'h4,`CMD_WR   ,8'h20  ,32'hFFFF               };//Set link timer to 1.6ms
151
                rv_MicroCodes[2]        <={2'b01,8'h4,`CMD_WR   ,8'h24  ,32'h001F               };//
152
                rv_MicroCodes[3]        <={2'b01,8'h4,`CMD_WR   ,8'h7C  ,32'h0001               };//Enable SGMII Mode, MAC Side
153
                rv_MicroCodes[4]        <={2'b01,8'h4,`CMD_WR   ,8'h00  ,32'h1340               };//Restart                     
154
 
155
                rv_MicroCodes[5]        <=`MDIO_RD_REG27;
156
                rv_MicroCodes[6]        <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd2048               };
157
 
158
                rv_MicroCodes[7]        <={2'b10,8'h4,`CMD_RD   ,8'h02  ,32'h1340               };//Read MDIO Registers         
159
 
160
                rv_MicroCodes[8]        <={2'b10,8'h4,`CMD_WR   ,8'h01  ,{r32_ReadData[31:4],4'h4}};//Write to Register 27 to change mode
161
                rv_MicroCodes[9]        <=`MDIO_WR_REG27;
162
                rv_MicroCodes[10]       <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd2048               };
163
 
164
                rv_MicroCodes[11]       <=`MDIO_RD_REG22;
165
                rv_MicroCodes[12]       <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd2048               };
166
 
167
                rv_MicroCodes[13]       <={2'b10,8'h4,`CMD_RD   ,8'h02  ,32'h1340               };//Read MDIO Registers         
168
 
169
                rv_MicroCodes[14]       <={2'b10,8'h4,`CMD_WR   ,8'h01  ,{r32_ReadData[31:8],8'h01}     };//Switch Page
170
                rv_MicroCodes[15]       <=`MDIO_WR_REG22;
171
                rv_MicroCodes[16]       <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd2048               };
172
 
173
                rv_MicroCodes[17]       <={2'b10,8'h4,`CMD_WR   ,8'h01  ,32'h0000_9000  };//Soft Reset, Disable Auto Negotiation
174
                rv_MicroCodes[18]       <=`MDIO_WR_REG00;
175
                rv_MicroCodes[19]       <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd125_000_000};
176
 
177
                rv_MicroCodes[20]       <=`MDIO_RD_REG04;
178
                rv_MicroCodes[21]       <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd2048               };
179
 
180
                rv_MicroCodes[22]       <=`MDIO_RD_REG00;
181
                rv_MicroCodes[23]       <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd2048               };
182
 
183
                rv_MicroCodes[24]       <=`MDIO_RD_REG01;
184
                rv_MicroCodes[25]       <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd2048};
185
 
186
                rv_MicroCodes[26]       <=`MDIO_RD_REG17;
187
                rv_MicroCodes[27]       <={2'b00,8'hFF,`CMD_WT  ,8'h00  ,32'd2048};
188
 
189
                rv_MicroCodes[28]       <={2'b00,8'hFF,`CMD_JMP ,8'd20  ,32'b0                  };
190
        end
191
endmodule

powered by: WebSVN 2.1.0

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