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

Subversion Repositories i2c_to_wb

[/] [i2c_to_wb/] [trunk/] [sim/] [models/] [i2c_master_model.v] - Diff between revs 3 and 4

Show entire file | Details | Blame | View Log

Rev 3 Rev 4
Line 1... Line 1...
// --------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
//
////                                                              ////
// --------------------------------------------------------------------
//// Copyright (C) 2009 Authors and OPENCORES.ORG                 ////
 
////                                                              ////
 
//// 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 source file is free software; you can redistribute it   ////
 
//// and/or modify it under the terms of the GNU Lesser General   ////
 
//// Public License as published by the Free Software Foundation; ////
 
//// either version 2.1 of the License, or (at your option) any   ////
 
//// later version.                                               ////
 
////                                                              ////
 
//// This source is distributed in the hope that it will be       ////
 
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
 
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
 
//// PURPOSE.  See the GNU Lesser General Public License for more ////
 
//// details.                                                     ////
 
////                                                              ////
 
//// You should have received a copy of the GNU Lesser General    ////
 
//// Public License along with this source; if not, download it   ////
 
//// from http://www.opencores.org/lgpl.shtml                     ////
 
////                                                              ////
 
//////////////////////////////////////////////////////////////////////
 
 
 
 
`timescale 1ns/10ps
`timescale 1ns/10ps
 
 
 
 
module
module
Line 47... Line 71...
    end
    end
 
 
 
 
  // --------------------------------------------------------------------
  // --------------------------------------------------------------------
  //  start
  //  start
 
  reg start_r = 1'b0;
 
 
  task start;
  task start;
    begin
    begin
 
 
 
      start_r = 1'b1;
 
 
      if( LOG_LEVEL > 2 )
      if( LOG_LEVEL > 2 )
        $display( "###- %m: I2C start at time %t. ", $time );
        $display( "###- %m: I2C start at time %t. ", $time );
 
 
//       i2c_data_out  = 1'b1;
 
//       i2c_clk_out   = 1'b1;
 
 
 
      #tBUF;
      #tBUF;
 
 
      i2c_data_oe = 1'b1;
 
      i2c_clk_oe  = 1'b1;
 
 
 
      if( i2c_data != 1'b1 )
      if( i2c_data != 1'b1 )
        begin
        begin
 
          if( i2c_clk != 1'b0 )
 
            #tHIGH;
 
 
 
          i2c_clk_out = 1'b0;
 
          i2c_clk_oe  = 1'b1;
          #tHD_DAT;
          #tHD_DAT;
          i2c_data_out = 1'b1;
          i2c_data_out = 1'b1;
 
          i2c_data_oe  = 1'b1;
        end
        end
 
 
      if( i2c_clk != 1'b1 )
      if( i2c_clk != 1'b1 )
        begin
 
          i2c_clk_out = 1'b1;
 
          #tLOW;
          #tLOW;
        end
 
 
 
 
      i2c_clk_out = 1'b1;
 
      i2c_clk_oe  = 1'b1;
      #tSU_STA;
      #tSU_STA;
      i2c_data_out = 1'b0;
      i2c_data_out = 1'b0;
 
      i2c_data_oe  = 1'b1;
 
 
 
      start_r = 1'b0;
 
 
    end
    end
  endtask
  endtask
 
 
 
 
Line 172... Line 202...
          else
          else
            $display( "###- %m: I2C ACK at time %t. ", $time );
            $display( "###- %m: I2C ACK at time %t. ", $time );
 
 
        #tHIGH;
        #tHIGH;
        i2c_clk_out = 1'b0;
        i2c_clk_out = 1'b0;
 
        #tHD_DAT;
 
        i2c_data_oe = 1'b1;
 
        #tLOW;
 
 
        write_byte_r = 1'b0;
        write_byte_r = 1'b0;
        #1;
 
 
 
      end
      end
  endtask
  endtask
 
 
 
 
Line 206... Line 238...
 
 
 
 
  // --------------------------------------------------------------------
  // --------------------------------------------------------------------
  //  read_byte
  //  read_byte
  task read_byte;
  task read_byte;
 
    input ack;
      begin
      begin
 
 
        #tHD_STA;
        #tHD_STA;
 
 
        i2c_clk_out = 1'b0;
        i2c_clk_out = 1'b0;
Line 222... Line 255...
        read_bit( 3 );
        read_bit( 3 );
        read_bit( 2 );
        read_bit( 2 );
        read_bit( 1 );
        read_bit( 1 );
        read_bit( 0 );
        read_bit( 0 );
 
 
        i2c_data_oe = 1'b1;
 
        #tHD_DAT;
        #tHD_DAT;
        i2c_data_out = 1'b0;
        i2c_data_out = ack;
 
        i2c_data_oe = 1'b1;
        #(tLOW - tHD_DAT);
        #(tLOW - tHD_DAT);
        i2c_clk_out = 1'b1;
        i2c_clk_out = 1'b1;
 
 
        if( LOG_LEVEL > 2 )
        if( LOG_LEVEL > 2 )
          $display( "###- %m: I2C read 0x%h at time %t. ", i2c_buffer_in, $time );
          $display( "###- %m: I2C read 0x%h at time %t. ", i2c_buffer_in, $time );
 
 
        #tHIGH;
        #tHIGH;
        i2c_clk_out = 1'b0;
        i2c_clk_out = 1'b0;
 
        #tLOW;
 
 
      end
      end
  endtask
  endtask
 
 
 
 

powered by: WebSVN 2.1.0

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