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

Subversion Repositories i2c

[/] [i2c/] [trunk/] [rtl/] [verilog/] [i2c_master_byte_ctrl.v] - Diff between revs 13 and 14

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

Rev 13 Rev 14
Line 1... Line 1...
 
/////////////////////////////////////////////////////////////////////
 
////                                                             ////
 
////  WISHBONE rev.B2 compliant I2C Master byte-controller       ////
 
////                                                             ////
 
////                                                             ////
 
////  Author: Richard Herveille                                  ////
 
////          richard@asics.ws                                   ////
 
////          www.asics.ws                                       ////
 
////                                                             ////
 
////  Downloaded from: http://www.opencores.org/projects/i2c/    ////
 
////                                                             ////
 
/////////////////////////////////////////////////////////////////////
 
////                                                             ////
 
//// Copyright (C) 2001 Richard Herveille                        ////
 
////                    richard@asics.ws                         ////
 
////                                                             ////
 
//// This source file may be used and distributed without        ////
 
//// restriction provided that this copyright statement is not   ////
 
//// removed from the file and that any derivative work contains ////
 
//// the original copyright notice and the associated disclaimer.////
 
////                                                             ////
 
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
 
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
 
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
 
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
 
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
 
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
 
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
 
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
 
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
 
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
 
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
 
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
 
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
 
////                                                             ////
 
/////////////////////////////////////////////////////////////////////
 
 
 
//  CVS Log
 
//
 
//  $Id: i2c_master_byte_ctrl.v,v 1.3 2001-11-05 11:59:25 rherveille Exp $
 
//
 
//  $Date: 2001-11-05 11:59:25 $
 
//  $Revision: 1.3 $
 
//  $Author: rherveille $
 
//  $Locker:  $
 
//  $State: Exp $
//
//
// WISHBONE revB2 compiant I2C master core
// Change History:
//
//               $Log: not supported by cvs2svn $
// author: Richard Herveille
 
// rev. 0.1 August  24th, 2001. Initial Verilog release.
 
// rev. 0.2 October 25th, 2001. Fixed some synthesis warnings.
 
//
 
 
 
`include "timescale.v"
`include "timescale.v"
`include "i2c_master_defines.v"
`include "i2c_master_defines.v"
 
 
module i2c_master_byte_ctrl (
module i2c_master_byte_ctrl (
Line 69... Line 111...
        reg [7:0] sr; //8bit shift register
        reg [7:0] sr; //8bit shift register
        reg       shift, ld;
        reg       shift, ld;
 
 
        // signals for state machine
        // signals for state machine
        wire       go;
        wire       go;
        reg  [3:0] dcnt;
        reg  [2:0] dcnt;
        wire       cnt_done;
        wire       cnt_done;
 
 
        //
        //
        // Module body
        // Module body
        //
        //
Line 116... Line 158...
                        sr <= #1 {sr[6:0], core_rxd};
                        sr <= #1 {sr[6:0], core_rxd};
 
 
        // generate counter
        // generate counter
        always@(posedge clk or negedge nReset)
        always@(posedge clk or negedge nReset)
                if (!nReset)
                if (!nReset)
                        dcnt <= #1 4'h0;
                        dcnt <= #1 3'h0;
                else if (rst)
                else if (rst)
                        dcnt <= #1 4'h0;
                        dcnt <= #1 3'h0;
                else if (ld)
                else if (ld)
                        dcnt <= #1 4'h7;
                        dcnt <= #1 3'h7;
                else if (shift)
                else if (shift)
                        dcnt <= #1 dcnt - 4'h1;
                        dcnt <= #1 dcnt - 3'h1;
 
 
        assign cnt_done = !(|dcnt);
        assign cnt_done = !(|dcnt);
 
 
        //
        //
        // state machine
        // state machine
Line 142... Line 184...
                                shift    <= #1 1'b0;
                                shift    <= #1 1'b0;
                                ld       <= #1 1'b0;
                                ld       <= #1 1'b0;
 
 
                                cmd_ack  <= #1 1'b0;
                                cmd_ack  <= #1 1'b0;
                                c_state  <= #1 ST_IDLE;
                                c_state  <= #1 ST_IDLE;
 
 
 
                                ack_out  <= #1 1'b0;
                        end
                        end
                else if (rst)
                else if (rst)
                        begin
                        begin
                                core_cmd <= #1 `I2C_CMD_NOP;
                                core_cmd <= #1 `I2C_CMD_NOP;
                                core_txd <= #1 1'b0;
                                core_txd <= #1 1'b0;
Line 153... Line 197...
                                shift    <= #1 1'b0;
                                shift    <= #1 1'b0;
                                ld       <= #1 1'b0;
                                ld       <= #1 1'b0;
 
 
                                cmd_ack  <= #1 1'b0;
                                cmd_ack  <= #1 1'b0;
                                c_state  <= #1 ST_IDLE;
                                c_state  <= #1 ST_IDLE;
 
 
 
                                ack_out  <= #1 1'b0;
                        end
                        end
        else
        else
                begin
                begin
                        // initially reset all signals
                        // initially reset all signals
                        core_txd <= #1 sr[7];
                        core_txd <= #1 sr[7];
Line 242... Line 288...
                                                                                c_state  <= #1 ST_READ;       // stay in same state
                                                                                c_state  <= #1 ST_READ;       // stay in same state
                                                                                core_cmd <= #1 `I2C_CMD_READ; // read next bit
                                                                                core_cmd <= #1 `I2C_CMD_READ; // read next bit
                                                                        end
                                                                        end
 
 
                                                                shift    <= #1 1'b1;
                                                                shift    <= #1 1'b1;
 
                                                                core_txd <= #1 ack_in;
                                                        end
                                                        end
 
 
                                ST_ACK:
                                ST_ACK:
                                        if (core_ack)
                                        if (core_ack)
                                                begin
                                                begin
Line 259... Line 306...
                                                                        c_state  <= #1 ST_IDLE;
                                                                        c_state  <= #1 ST_IDLE;
                                                                        core_cmd <= #1 `I2C_CMD_NOP;
                                                                        core_cmd <= #1 `I2C_CMD_NOP;
                                                                end
                                                                end
 
 
                                                        // assign ack_out output to bit_controller_rxd (contains last received bit)
                                                        // assign ack_out output to bit_controller_rxd (contains last received bit)
                                                        ack_out = core_rxd;
                                                        ack_out <= #1 core_rxd;
 
 
                                                        // generate command acknowledge signal
                                                        // generate command acknowledge signal
                                                        cmd_ack  <= #1 1'b1;
                                                        cmd_ack  <= #1 1'b1;
 
 
                                                        core_txd <= #1 1'b1;
                                                        core_txd <= #1 1'b1;

powered by: WebSVN 2.1.0

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