1 --------------------------------------------------------------------- 3 ---- WISHBONE revB2 compl. I2C Master Core; byte-controller ---- 6 ---- Author: Richard Herveille ---- 7 ---- richard@asics.ws ---- 10 ---- Downloaded from: http://www.opencores.org/projects/i2c/ ---- 12 --------------------------------------------------------------------- 14 ---- Copyright (C) 2000 Richard Herveille ---- 15 ---- richard@asics.ws ---- 17 ---- This source file may be used and distributed without ---- 18 ---- restriction provided that this copyright statement is not ---- 19 ---- removed from the file and that any derivative work contains ---- 20 ---- the original copyright notice and the associated disclaimer.---- 22 ---- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ---- 23 ---- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ---- 24 ---- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ---- 25 ---- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ---- 26 ---- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ---- 27 ---- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ---- 28 ---- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ---- 29 ---- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ---- 30 ---- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ---- 31 ---- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ---- 32 ---- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ---- 33 ---- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ---- 34 ---- POSSIBILITY OF SUCH DAMAGE. ---- 36 --------------------------------------------------------------------- 40 -- $Id: i2c_master_byte_ctrl.vhd,v 1.5 2004/02/18 11:41:48 rherveille Exp $ 42 -- $Date: 2004/02/18 11:41:48 $ 44 -- $Author: rherveille $ 49 -- $Log: i2c_master_byte_ctrl.vhd,v $ 50 -- Revision 1.5 2004/02/18 11:41:48 rherveille 51 -- Fixed a potential bug in the statemachine. During a 'stop' 2 cmd_ack signals were generated. Possibly canceling a new start command. 53 -- Revision 1.4 2003/08/09 07:01:13 rherveille 54 -- Fixed a bug in the Arbitration Lost generation caused by delay on the (external) sda line. 55 -- Fixed a potential bug in the byte controller's host-acknowledge generation. 57 -- Revision 1.3 2002/12/26 16:05:47 rherveille 58 -- Core is now a Multimaster I2C controller. 60 -- Revision 1.2 2002/11/30 22:24:37 rherveille 63 -- Revision 1.1 2001/11/05 12:02:33 rherveille 65 --! @ingroup protocols_i2c 66 -- Split i2c_master_core.vhd into separate files for each entity; same layout as verilog version. 67 -- Code updated, is now up-to-date to doc. rev.0.4. 71 -- Modified by Jan Andersson (jan@gaisler.com:. 72 -- Changed std_logic_arith to numeric_std. 73 -- Propagate filter generic 76 ------------------------------------------ 77 -- Byte controller section 78 ------------------------------------------ 81 use ieee.std_logic_1164.
all;
89 rst : in ;
-- synchronous active high reset (WISHBONE compatible) 90 nReset : in ;
-- asynchornous active low reset (FPGA compatible) 91 ena : in ;
-- core enable signal 112 scl_i : in ;
-- i2c clock line input 113 scl_o : out ;
-- i2c clock line output 114 scl_oen : out ;
-- i2c clock line output enable, active low 116 sda_o : out ;
-- i2c data line output 117 sda_oen : out -- i2c data line output enable, active low 119 end entity i2c_master_byte_ctrl;
128 ena :
in ;
-- core enable signal 130 clk_cnt :
in (
15 downto 0);
-- clock prescale value 132 cmd :
in (
3 downto 0);
133 cmd_ack :
out ;
-- command done 134 busy :
out ;
-- i2c bus busy 135 al :
out ;
-- arbitration lost 143 scl_i :
in ;
-- i2c clock line input 144 scl_o :
out ;
-- i2c clock line output 145 scl_oen :
out ;
-- i2c clock line output enable, active low 146 sda_i :
in ;
-- i2c data line input 147 sda_o :
out ;
-- i2c data line output 148 sda_oen :
out -- i2c data line output enable, active low 152 -- commands for bit_controller block 159 -- signals for bit_controller 164 -- signals for shift register 165 signal sr : (7 downto 0);
-- 8bit shift register 168 -- signals for state machine 170 -- Added init value to dcnt to prevent simulation meta-value 172 -- removed init value as it is not compatible with Formality 173 -- - jiri@gaisler.com 174 signal dcnt : (2 downto 0) 175 -- pragma translate_off 177 -- pragma translate_on 182 -- hookup bit_controller 207 -- generate host-command-acknowledge 210 -- generate go-signal 213 -- assign Dout output to shift-register 216 -- generate shift register 220 sr <= (others => '0');
221 elsif (clk'event and clk = '1') then 223 sr <= (others => '0');
224 elsif (ld = '1') then 226 elsif (shift = '1') then 230 end process shift_register;
232 -- generate data-counter 236 dcnt <= (others => '0');
237 elsif (clk'event and clk = '1') then 239 dcnt <= (others => '0');
240 elsif (ld = '1') then 241 dcnt <= (others => '1');
-- load counter with 7 242 elsif (shift = '1') then 246 end process data_cnt;
254 type states is (st_idle, st_start, st_read, st_write, st_ack, st_stop);
258 -- command interpreter, translate complex commands into simpler I2C commands 270 elsif (clk'event and clk = '1') then 271 if (rst = '1' or al = '1') then 280 -- initialy reset all signal 289 if (start = '1') then 292 elsif (read = '1') then 295 elsif (write = '1') then 325 c_state <= st_write;
-- stay in same state 337 c_state <= st_read;
-- stay in same state 347 -- check for stop; Should a STOP command be generated ? 355 -- generate command acknowledge signal 359 -- assign ack_out output to core_rxd (contains last received bit) 372 -- generate command acknowledge signal 376 when others => -- illegal states 379 --report ("Byte controller entered illegal state."); 385 end process nxt_state_decoder;
387 end block statemachine;
389 end architecture structural;
in filtstd_logic_vector(( filter- 1)* dynfilt downto 0)
in clk_cntstd_logic_vector( 15 downto 0)
std_logic_vector( 3 downto 0) := "0010" I2C_CMD_STOP
std_logic_vector( 2 downto 0) :=( others => '0') dcnt
in clk_cntstd_logic_vector( 15 downto 0)
std_logic_vector( 3 downto 0) := "0000" I2C_CMD_NOP
i2c_master_bit_ctrl bit_ctrlbit_ctrl
in filtstd_logic_vector(( filter- 1)* dynfilt downto 0)
std_logic_vector( 3 downto 0) := "1000" I2C_CMD_WRITE
std_logic_vector( 3 downto 0) := "0001" I2C_CMD_START
(st_idle,st_start,st_read,st_write,st_ack,st_stop) states
out doutstd_logic_vector( 7 downto 0)
in dinstd_logic_vector( 7 downto 0)
std_logic_vector( 7 downto 0) sr
in cmdstd_logic_vector( 3 downto 0)
std_logic_vector( 3 downto 0) core_cmd
std_logic_vector( 3 downto 0) := "0100" I2C_CMD_READ