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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [enetctrl.v] - Diff between revs 3 and 30

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 3 Rev 30
Line 45... Line 45...
`define ECTRL_READ      3'h3
`define ECTRL_READ      3'h3
`define ECTRL_WRITE     3'h4
`define ECTRL_WRITE     3'h4
module  enetctrl(i_clk, i_rst,
module  enetctrl(i_clk, i_rst,
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
                i_wb_cyc, i_wb_stb, i_wb_we, i_wb_addr, i_wb_data,
                        o_wb_ack, o_wb_stall, o_wb_data,
                        o_wb_ack, o_wb_stall, o_wb_data,
                o_mdclk, o_mdio, i_mdio, o_mdwe);
                o_mdclk, o_mdio, i_mdio, o_mdwe,
 
                o_debug);
        parameter       CLKBITS=3; // = 3 for 200MHz source clock, 2 for 100 MHz
        parameter       CLKBITS=3; // = 3 for 200MHz source clock, 2 for 100 MHz
        input   i_clk, i_rst;
        input   i_clk, i_rst;
        input                   i_wb_cyc, i_wb_stb, i_wb_we;
        input                   i_wb_cyc, i_wb_stb, i_wb_we;
        input           [4:0]    i_wb_addr;
        input           [4:0]    i_wb_addr;
        input           [15:0]   i_wb_data;
        input           [15:0]   i_wb_data;
Line 58... Line 59...
        //
        //
        input                   i_mdio;
        input                   i_mdio;
        output  wire            o_mdclk;
        output  wire            o_mdclk;
        output  reg             o_mdio, o_mdwe;
        output  reg             o_mdio, o_mdwe;
        //
        //
 
        output  wire    [31:0]   o_debug;
 
        //
        parameter       PHYADDR = 5'h01;
        parameter       PHYADDR = 5'h01;
 
 
 
 
        reg             read_pending, write_pending;
        reg             read_pending, write_pending;
        reg     [4:0]    r_addr;
        reg     [4:0]    r_addr;
Line 81... Line 84...
 
 
        // Step 2: Generate strobes for when to move, given the clock
        // Step 2: Generate strobes for when to move, given the clock
        reg     rclk, zclk;
        reg     rclk, zclk;
        initial zclk = 0;
        initial zclk = 0;
        always @(posedge i_clk)
        always @(posedge i_clk)
                zclk <= &clk_counter;
                zclk <= (&clk_counter[(CLKBITS-1):1])&&(!clk_counter[0]);
        initial rclk = 0;
        initial rclk = 0;
        always @(posedge i_clk)
        always @(posedge i_clk)
                rclk <= (~clk_counter[(CLKBITS-1)])&&(&clk_counter[(CLKBITS-2):0]);
                rclk <= (~clk_counter[(CLKBITS-1)])&&(&clk_counter[(CLKBITS-2):0]);
 
 
        // Step 3: Read from our input port
        // Step 3: Read from our input port
        //      Note: I read on the falling edge, he changes on the rising edge
        //      Note: I read on the falling edge, he changes on the rising edge
 
        reg     in_idle;
        always @(posedge i_clk)
        always @(posedge i_clk)
                if (zclk)
                if (zclk)
                        read_reg <= { read_reg[14:0], i_mdio };
                        read_reg <= { read_reg[14:0], i_mdio };
        always @(posedge i_clk)
        always @(posedge i_clk)
                zreg_pos <= (reg_pos == 0);
                zreg_pos <= (reg_pos == 0);
Line 105... Line 109...
        //      Note: I change on the falling edge,
        //      Note: I change on the falling edge,
        always @(posedge i_clk)
        always @(posedge i_clk)
                if (zclk)
                if (zclk)
                        o_mdio <= write_reg[15];
                        o_mdio <= write_reg[15];
 
 
        reg     in_idle;
 
        initial in_idle = 1'b0;
        initial in_idle = 1'b0;
        always @(posedge i_clk)
        always @(posedge i_clk)
                in_idle <= (ctrl_state == `ECTRL_IDLE);
                in_idle <= (ctrl_state == `ECTRL_IDLE);
        initial o_wb_stall = 1'b0;
        initial o_wb_stall = 1'b0;
        always @(posedge i_clk)
        always @(posedge i_clk)
Line 143... Line 146...
        initial ctrl_state = `ECTRL_RESET;
        initial ctrl_state = `ECTRL_RESET;
        initial write_reg = 16'hffff;
        initial write_reg = 16'hffff;
        always @(posedge i_clk)
        always @(posedge i_clk)
        begin
        begin
                o_wb_ack <= 1'b0;
                o_wb_ack <= 1'b0;
                if ((zclk)&&(~zreg_pos))
                if ((zclk)&&(!zreg_pos))
                        reg_pos <= reg_pos - 1;
                        reg_pos <= reg_pos - 1;
                if (zclk)
                if (zclk)
                        write_reg <= { write_reg[14:0], 1'b1 };
                        write_reg <= { write_reg[14:0], 1'b1 };
                if (i_rst)
                if (i_rst)
                begin // Must go for 167 ms before our 32 clocks
                begin // Must go for 167 ms before our 32 clocks
Line 163... Line 166...
                        end
                        end
                `ECTRL_IDLE: begin
                `ECTRL_IDLE: begin
                        o_mdwe <= 1'b1; // Write
                        o_mdwe <= 1'b1; // Write
                        write_reg <= { 4'he, PHYADDR, r_addr, 2'b11 };
                        write_reg <= { 4'he, PHYADDR, r_addr, 2'b11 };
                        if (write_pending)
                        if (write_pending)
 
                        begin
                                write_reg[15:12] <= { 4'h5 };
                                write_reg[15:12] <= { 4'h5 };
                        else if (read_pending)
                                write_reg[0] <= 1'b0;
 
                        end else if (read_pending)
                                write_reg[15:12] <= { 4'h6 };
                                write_reg[15:12] <= { 4'h6 };
                        if (read_pending || write_pending)
                        if (!zclk)
                        begin
                                write_reg[15] <= 1'b1;
                                reg_pos <= 6'h0f;
                                reg_pos <= 6'h0f;
 
                        if ((zclk)&&(read_pending || write_pending))
 
                        begin
                                ctrl_state <= `ECTRL_ADDRESS;
                                ctrl_state <= `ECTRL_ADDRESS;
                        end end
                        end end
                `ECTRL_ADDRESS: begin
                `ECTRL_ADDRESS: begin
                        o_mdwe <= 1'b1; // Write
                        o_mdwe <= 1'b1; // Write
                        if ((zreg_pos)&&(zclk))
                        if ((zreg_pos)&&(zclk))
Line 204... Line 211...
                        ctrl_state <= `ECTRL_RESET;
                        ctrl_state <= `ECTRL_RESET;
                        end
                        end
                endcase
                endcase
        end
        end
 
 
 
        assign  o_debug = {
 
                        o_wb_stall,i_wb_stb,i_wb_we, i_wb_addr, // 8 bits
 
                        o_wb_ack, rclk, o_wb_data[5:0],          // 8 bits
 
                        zreg_pos, zclk, reg_pos,                // 8 bits
 
                        read_pending, ctrl_state,               // 4 bits
 
                        o_mdclk, o_mdwe, o_mdio, i_mdio         // 4 bits
 
                };
 
 
endmodule
endmodule
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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