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

Subversion Repositories apbi2c

[/] [apbi2c/] [trunk/] [rtl/] [module_i2c.v] - Diff between revs 21 and 22

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

Rev 21 Rev 22
Line 194... Line 194...
        //STATE CONTROL 
        //STATE CONTROL 
        reg [5:0] state_tx;
        reg [5:0] state_tx;
        reg [5:0] next_state_tx;
        reg [5:0] next_state_tx;
 
 
//ASSIGN REGISTERS TO BIDIRETIONAL PORTS
//ASSIGN REGISTERS TO BIDIRETIONAL PORTS
assign SDA = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b0)?SDA_OUT:1'bz;
assign SDA =(DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b0 & state_tx != RESPONSE_CIN & state_tx != RESPONSE_ADDRESS & state_tx != RESPONSE_DATA0_1 & state_tx != RESPONSE_DATA1_1)?SDA_OUT:SDA_OUT_RX;
assign SCL = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b0)?BR_CLK_O:1'bz;
 
 
 
 
assign SCL = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b0)?BR_CLK_O:BR_CLK_O_RX;
 
 
//STANDARD ERROR
//STANDARD ERROR
assign ERROR = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b1)?1'b1:1'b0;
assign ERROR = (DATA_CONFIG_REG[0] == 1'b1 & DATA_CONFIG_REG[1] == 1'b1)?1'b1:1'b0;
 
 
 
 
Line 916... Line 918...
 
 
                end
                end
                CONTROLIN_4:
                CONTROLIN_4:
                begin
                begin
 
 
 
 
 
 
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        begin
                        begin
                                count_send_data <= count_send_data + 12'd1;
                                count_send_data <= count_send_data + 12'd1;
                                SDA_OUT<=fifo_tx_data_out[3:3];
                                SDA_OUT<=fifo_tx_data_out[3:3];
 
 
                                if(count_receive_data < DATA_CONFIG_REG[13:2]/12'd4)
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
                                begin
                                begin
                                        BR_CLK_O <= 1'b0;
                                        BR_CLK_O <= 1'b0;
                                end
                                end
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
                                begin
                                begin
Line 954... Line 954...
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        begin
                        begin
                                count_send_data <= count_send_data + 12'd1;
                                count_send_data <= count_send_data + 12'd1;
                                SDA_OUT<=fifo_tx_data_out[4:4];
                                SDA_OUT<=fifo_tx_data_out[4:4];
 
 
                                if(count_receive_data < DATA_CONFIG_REG[13:2]/12'd4)
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
                                begin
                                begin
                                        BR_CLK_O <= 1'b0;
                                        BR_CLK_O <= 1'b0;
                                end
                                end
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
                                begin
                                begin
Line 974... Line 974...
                                count_send_data <= 12'd0;
                                count_send_data <= 12'd0;
                                SDA_OUT<=fifo_tx_data_out[5:5];
                                SDA_OUT<=fifo_tx_data_out[5:5];
                        end
                        end
 
 
                end
                end
 
 
 
 
                CONTROLIN_6:
                CONTROLIN_6:
                begin
                begin
 
 
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        begin
                        begin
Line 1074... Line 1072...
                                count_send_data <= count_send_data + 12'd1;
                                count_send_data <= count_send_data + 12'd1;
 
 
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
                                //LETS TRY USE THIS BUT I DONT THINK IF WORKS  
                                RESPONSE<= SDA;
                                RESPONSE<= SDA;
 
 
                                if(count_receive_data < DATA_CONFIG_REG[13:2]/12'd4)
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
                                begin
                                begin
                                        BR_CLK_O <= 1'b0;
                                        BR_CLK_O <= 1'b0;
                                end
                                end
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
                                else if(count_send_data >= DATA_CONFIG_REG[13:2]/12'd4 && count_send_data < (DATA_CONFIG_REG[13:2]-(DATA_CONFIG_REG[13:2]/12'd4))-12'd1)
                                begin
                                begin
Line 1210... Line 1208...
                ADDRESS_5:
                ADDRESS_5:
                begin
                begin
 
 
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        begin
                        begin
                                count_send_data <= count_receive_data + 12'd1;
                                count_send_data <= count_send_data + 12'd1;
                                SDA_OUT<=fifo_tx_data_out[12:12];
                                SDA_OUT<=fifo_tx_data_out[12:12];
 
 
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
                                begin
                                begin
                                        BR_CLK_O <= 1'b0;
                                        BR_CLK_O <= 1'b0;
Line 1381... Line 1379...
                DATA0_2:
                DATA0_2:
                begin
                begin
 
 
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        begin
                        begin
                                count_send_data <= count_receive_data + 12'd1;
                                count_send_data <= count_send_data + 12'd1;
                                SDA_OUT<=fifo_tx_data_out[17:17];
                                SDA_OUT<=fifo_tx_data_out[17:17];
 
 
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd4)
                                begin
                                begin
                                        BR_CLK_O <= 1'b0;
                                        BR_CLK_O <= 1'b0;
Line 1979... Line 1977...
 
 
                        BR_CLK_O <= 1'b1;
                        BR_CLK_O <= 1'b1;
 
 
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        if(count_send_data < DATA_CONFIG_REG[13:2])
                        begin
                        begin
                                count_send_data <= count_receive_data + 12'd1;
                                count_send_data <= count_send_data + 12'd1;
 
 
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2-12'd2)
                                if(count_send_data < DATA_CONFIG_REG[13:2]/12'd2-12'd2)
                                begin
                                begin
                                        SDA_OUT<=1'b0;
                                        SDA_OUT<=1'b0;
                                end
                                end
Line 2180... Line 2178...
 
 
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                begin
                begin
                        next_state_rx =   RESPONSE_CIN;
                        next_state_rx =   RESPONSE_CIN;
                end
                end
                else
                else if(RESPONSE == 1'b0)//ACK
                begin
                begin
                        next_state_rx =   ADDRESS_1;
                        next_state_rx  =   DELAY_BYTES;
 
                end
 
                else if(RESPONSE == 1'b1)//NACK
 
                begin
 
                        next_state_rx  =   NACK;
                end
                end
 
 
        end
        end
        //NOW SENDING ADDRESS
        //NOW SENDING ADDRESS
          ADDRESS_1:
          ADDRESS_1:
Line 2281... Line 2283...
        begin
        begin
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                begin
                begin
                        next_state_rx =   RESPONSE_ADDRESS;
                        next_state_rx =   RESPONSE_ADDRESS;
                end
                end
                else
                else if(RESPONSE == 1'b0)//ACK
                begin
                begin
                        next_state_rx =   DATA0_1;
                        next_state_rx  =   DELAY_BYTES;
 
                end
 
                else if(RESPONSE == 1'b1)//NACK
 
                begin
 
                        next_state_rx  =   NACK;
                end
                end
        end
        end
        //data in
        //data in
          DATA0_1:
          DATA0_1:
        begin
        begin
Line 2377... Line 2383...
                        next_state_rx =   RESPONSE_DATA0_1;
                        next_state_rx =   RESPONSE_DATA0_1;
                end
                end
        end
        end
          RESPONSE_DATA0_1:
          RESPONSE_DATA0_1:
        begin
        begin
 
 
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                begin
                begin
                        next_state_rx =   RESPONSE_DATA0_1;
                        next_state_rx =   RESPONSE_DATA0_1;
                end
                end
                else
                else if(RESPONSE == 1'b0)//ACK
                begin
                begin
                        next_state_rx =   DATA1_1;
                        next_state_rx  =   DELAY_BYTES;
 
                end
 
                else if(RESPONSE == 1'b1)//NACK
 
                begin
 
                        next_state_rx  =   NACK;
                end
                end
        end
        end
 
 
        //second byte
        //second byte
          DATA1_1:
          DATA1_1:
        begin
        begin
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                begin
                begin
Line 2480... Line 2490...
        end
        end
          RESPONSE_DATA1_1:
          RESPONSE_DATA1_1:
        begin
        begin
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                if(  count_receive_data != DATA_CONFIG_REG[13:2])
                begin
                begin
                        next_state_rx =   RESPONSE_DATA1_1;
                        next_state_rx =   RESPONSE_DATA0_1;
                end
                end
                else
                else if(RESPONSE == 1'b0)//ACK
                begin
                begin
                        next_state_rx =   DELAY_BYTES;
                        next_state_rx =   DELAY_BYTES;
                end
                end
 
                else if(RESPONSE == 1'b1)//NACK
 
                begin
 
                        next_state_rx  =   NACK;
 
                end
 
 
        end
        end
          DELAY_BYTES://THIS FORM WORKS 
          DELAY_BYTES://THIS FORM WORKS 
        begin
        begin
 
 
Line 3282... Line 3296...
                        begin
                        begin
                                  count_receive_data <=   count_receive_data + 12'd1;
                                  count_receive_data <=   count_receive_data + 12'd1;
                        end
                        end
                        else
                        else
                        begin
                        begin
 
 
 
 
 
                                if(count_rx == 2'd0)
 
                                begin
 
                                        count_rx <= count_rx + 2'd1;
 
                                        //SDA_OUT<=fifo_tx_data_out[8:8];
 
                                end
 
                                else if(count_rx   == 2'd1)
 
                                begin
 
                                        count_rx <= count_tx + 2'd1;
 
                                        //SDA_OUT<=fifo_tx_data_out[16:16];
 
                                end
 
                                else if(count_rx == 2'd2)
 
                                begin
 
                                        count_rx <= count_rx + 2'd1;
 
                                        //SDA_OUT<=fifo_tx_data_out[24:24];
 
                                end
 
                                else if(count_rx == 2'd3)
 
                                begin
 
                                        count_rx <= 2'd0;
 
                                end
 
 
                                  count_receive_data <= 12'd0;
                                  count_receive_data <= 12'd0;
                                fifo_rx_wr_en <= 1'b1;
 
                        end
                        end
 
 
 
 
                end
                end
                  STOP:
                  STOP:

powered by: WebSVN 2.1.0

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