SURF  1.0
AxiI2cRegMaster.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiI2cRegMaster.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-07-08
5 -- Last update: 2017-05-09
6 -------------------------------------------------------------------------------
7 -- Description: AXI-Lite I2C Register Master
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 library ieee;
19 use ieee.std_logic_1164.all;
20 
21 use work.StdRtlPkg.all;
22 use work.AxiLitePkg.all;
23 use work.I2cPkg.all;
24 
25 library unisim;
26 use unisim.vcomponents.all;
27 
28 --! @see entity
29  --! @ingroup protocols_i2c
30 entity AxiI2cRegMaster is
31  generic (
32  TPD_G : time := 1 ns;
34  I2C_SCL_FREQ_G : real := 100.0E+3; -- units of Hz
35  I2C_MIN_PULSE_G : real := 100.0E-9; -- units of seconds
36  AXI_CLK_FREQ_G : real := 156.25E+6; -- units of Hz
38  port (
39  -- I2C Ports
40  scl : inout sl;
41  sda : inout sl;
42  -- AXI-Lite Register Interface
47  -- Clocks and Resets
48  axiClk : in sl;
49  axiRst : in sl);
50 end AxiI2cRegMaster;
51 
52 architecture mapping of AxiI2cRegMaster is
53 
54  -- Note: PRESCALE_G = (clk_freq / (5 * i2c_freq)) - 1
55  -- FILTER_G = (min_pulse_time / clk_period) + 1
56  constant I2C_SCL_5xFREQ_C : real := 5.0 * I2C_SCL_FREQ_G;
57  constant PRESCALE_C : natural := (getTimeRatio(AXI_CLK_FREQ_G, I2C_SCL_5xFREQ_C)) - 1;
58  constant FILTER_C : natural := natural(AXI_CLK_FREQ_G * I2C_MIN_PULSE_G) + 1;
59 
62 
63  signal i2ci : i2c_in_type;
64  signal i2co : i2c_out_type;
65 
66 begin
67 
68  I2cRegMasterAxiBridge_Inst : entity work.I2cRegMasterAxiBridge
69  generic map (
70  TPD_G => TPD_G,
73  port map (
74  -- I2C Register Interface
77  -- AXI-Lite Register Interface
82  -- Clocks and Resets
83  axiClk => axiClk,
84  axiRst => axiRst);
85 
86  I2cRegMaster_Inst : entity work.I2cRegMaster
87  generic map(
88  TPD_G => TPD_G,
90  FILTER_G => FILTER_C,
92  port map (
93  -- I2C Port Interface
94  i2ci => i2ci,
95  i2co => i2co,
96  -- I2C Register Interface
99  -- Clock and Reset
100  clk => axiClk,
101  srst => axiRst);
102 
103  IOBUF_SCL : IOBUF
104  port map (
105  O => i2ci.scl, -- Buffer output
106  IO => scl, -- Buffer inout port (connect directly to top-level port)
107  I => i2co.scl, -- Buffer input
108  T => i2co.scloen); -- 3-state enable input, high=input, low=output
109 
110  IOBUF_SDA : IOBUF
111  port map (
112  O => i2ci.sda, -- Buffer output
113  IO => sda, -- Buffer inout port (connect directly to top-level port)
114  I => i2co.sda, -- Buffer input
115  T => i2co.sdaoen); -- 3-state enable input, high=input, low=output
116 
117 end mapping;
in regInI2cRegMasterInType
natural :=( getTimeRatio( AXI_CLK_FREQ_G, I2C_SCL_5xFREQ_C))- 1 PRESCALE_C
AXI_CLK_FREQ_Greal := 156.25E+6
AXI_ERROR_RESP_Gslv( 1 downto 0) := AXI_RESP_SLVERR_C
out axiWriteSlaveAxiLiteWriteSlaveType
AXI_ERROR_RESP_Gslv( 1 downto 0) := AXI_RESP_SLVERR_C
in i2cii2c_in_type
i2c_in_type
Definition: I2cPkg.vhd:34
AxiLiteWriteMasterType
Definition: AxiLitePkg.vhd:111
std_logic sl
Definition: StdRtlPkg.vhd:28
natural := natural( AXI_CLK_FREQ_G* I2C_MIN_PULSE_G)+ 1 FILTER_C
in srstsl := '0'
I2cRegMasterOutType i2cRegMasterOut
TPD_Gtime := 1 ns
out axiReadSlaveAxiLiteReadSlaveType
I2cRegMasterInType i2cRegMasterIn
array(natural range <> ) of I2cAxiLiteDevType I2cAxiLiteDevArray
Definition: I2cPkg.vhd:176
I2C_SCL_FREQ_Greal := 100.0E+3
OUTPUT_EN_POLARITY_Ginteger range 0 to 1:= 0
DEVICE_MAP_GI2cAxiLiteDevArray := I2C_AXIL_DEV_ARRAY_DEFAULT_C
in axiWriteMasterAxiLiteWriteMasterType
TPD_Gtime := 1 ns
out axiReadSlaveAxiLiteReadSlaveType
_library_ ieeeieee
slv( 1 downto 0) := "10" AXI_RESP_SLVERR_C
Definition: AxiLitePkg.vhd:36
I2cRegMasterOutType
Definition: I2cPkg.vhd:110
in axiReadMasterAxiLiteReadMasterType
i2c_out_type
Definition: I2cPkg.vhd:41
I2C_MIN_PULSE_Greal := 100.0E-9
AxiLiteReadMasterType
Definition: AxiLitePkg.vhd:59
DEVICE_MAP_GI2cAxiLiteDevArray := I2C_AXIL_DEV_ARRAY_DEFAULT_C
I2cRegMasterInType
Definition: I2cPkg.vhd:79
in i2cRegMasterOutI2cRegMasterOutType
in axiWriteMasterAxiLiteWriteMasterType
real := 5.0* I2C_SCL_FREQ_G I2C_SCL_5xFREQ_C
AxiLiteReadSlaveType
Definition: AxiLitePkg.vhd:85
in axiReadMasterAxiLiteReadMasterType
out axiWriteSlaveAxiLiteWriteSlaveType
I2cAxiLiteDevArray( 0 to 3) :=( 0=>( MakeI2cAxiLiteDevType( "0000000", 8, 8, '0')), 1=>( MakeI2cAxiLiteDevType( "0000010", 16, 16, '0')), 2=>( MakeI2cAxiLiteDevType( "0000100", 32, 8, '0')), 3=>( MakeI2cAxiLiteDevType( "0001000", 32, 32, '0'))) I2C_AXIL_DEV_ARRAY_DEFAULT_C
Definition: I2cPkg.vhd:178
out i2cRegMasterInI2cRegMasterInType
out i2coi2c_out_type
FILTER_Ginteger range 2 to 512:= 8
out regOutI2cRegMasterOutType
PRESCALE_Ginteger range 0 to 655535:= 62
std_logic_vector slv
Definition: StdRtlPkg.vhd:29