SURF  1.0
I2cRegMasterMux.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : I2cRegMasterMux.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-09-21
5 -- Last update: 2013-11-20
6 -------------------------------------------------------------------------------
7 -- Description: Multiplexes access to a single I2cRegMaster module
8 -- Attached devices may also lock others out in order to execute multiple
9 -- transactions in a row. To do this, lockReq must be set high for the first
10 -- transaction and set low for the last transaction.
11 -------------------------------------------------------------------------------
12 -- This file is part of 'SLAC Firmware Standard Library'.
13 -- It is subject to the license terms in the LICENSE.txt file found in the
14 -- top-level directory of this distribution and at:
15 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
16 -- No part of 'SLAC Firmware Standard Library', including this file,
17 -- may be copied, modified, propagated, or distributed except according to
18 -- the terms contained in the LICENSE.txt file.
19 -------------------------------------------------------------------------------
20 
21 library ieee;
22 use ieee.std_logic_1164.all;
23 use ieee.std_logic_arith.all;
24 use ieee.std_logic_unsigned.all;
25 
26 use work.StdRtlPkg.all;
27 use work.I2cPkg.all;
28 
29 --! @see entity
30  --! @ingroup protocols_i2c
31 entity I2cRegMasterMux is
32 
33  generic (
34  TPD_G : time := 1 ns;
35  NUM_INPUTS_C : natural range 2 to 8 := 2);
36  port (
37  clk : in sl;
38  srst : in sl := '0';
39  arst : in sl := '0';
40  lockReq : in slv(NUM_INPUTS_C-1 downto 0) := (others => '0');
41  regIn : in I2cRegMasterInArray(0 to NUM_INPUTS_C-1);
42  regOut : out I2cRegMasterOutArray(0 to NUM_INPUTS_C-1);
45 
46 end entity I2cRegMasterMux;
47 
48 architecture rtl of I2cRegMasterMux is
49 
50  type RegType is record
51  locked : sl;
52  sel : slv(log2(NUM_INPUTS_C)-1 downto 0);
53  regOut : I2cRegMasterOutArray(0 to NUM_INPUTS_C-1);
55  end record RegType;
56 
57  constant REG_INIT_C : RegType := (
58  locked => '0',
59  sel => (others => '0'),
60  regOut => (others => I2C_REG_MASTER_OUT_INIT_C),
62 
63  signal r : RegType := REG_INIT_C;
64  signal rin : RegType;
65 
66 begin
67 
68  comb : process (lockReq, masterOut, r, regIn, srst) is
69  variable v : RegType;
70  variable selInt : integer;
71  begin
72  v := r;
73 
74  selInt := conv_integer(r.sel);
75 
76  if (r.locked = '0') then
77  v.sel := r.sel + 1; -- Increment only if no channel has a lock
78  end if;
79 
80  v.masterIn.regReq := '0';
81 
82  v.regOut := (others => I2C_REG_MASTER_OUT_INIT_C);
83 
84  if (regIn(selInt).regReq = '1') then
85  v.locked := lockReq(selInt); -- Grant lock if requested
86  v.sel := r.sel;
87  v.masterIn := regIn(selInt);
88  v.regOut(selInt) := masterOut;
89  end if;
90 
91  if (srst = '1') then
92  v := REG_INIT_C;
93  end if;
94 
95  rin <= v;
96 
97  regOut <= r.regOut;
98  masterIn <= r.masterIn;
99 
100  end process comb;
101 
102  seq : process (clk, arst) is
103  begin
104  if (arst = '1') then
105  r <= REG_INIT_C after TPD_G;
106  elsif (rising_edge(clk)) then
107  r <= rin after TPD_G;
108  end if;
109  end process seq;
110 
111 end architecture rtl;
I2cRegMasterOutType :=(regAck => '0',regFail => '0',regFailCode =>( others => '0'),regRdData =>( others => '0')) I2C_REG_MASTER_OUT_INIT_C
Definition: I2cPkg.vhd:117
NUM_INPUTS_Cnatural range 2 to 8:= 2
std_logic sl
Definition: StdRtlPkg.vhd:28
out masterInI2cRegMasterInType
in lockReqslv( NUM_INPUTS_C- 1 downto 0) :=( others => '0')
out regOutI2cRegMasterOutArray( 0 to NUM_INPUTS_C- 1)
TPD_Gtime := 1 ns
I2cRegMasterOutType
Definition: I2cPkg.vhd:110
in masterOutI2cRegMasterOutType
in arstsl := '0'
I2cRegMasterInType :=(i2cAddr =>( others => '0'),tenbit => '0',regAddr =>( others => '0'),regWrData =>( others => '0'),regOp => '0',regAddrSkip => '0',regAddrSize =>( others => '0'),regDataSize =>( others => '0'),regReq => '0',busReq => '0',endianness => '0',repeatStart => '0') I2C_REG_MASTER_IN_INIT_C
Definition: I2cPkg.vhd:94
sl regReq
Definition: I2cPkg.vhd:88
in srstsl := '0'
I2cRegMasterInType
Definition: I2cPkg.vhd:79
in regInI2cRegMasterInArray( 0 to NUM_INPUTS_C- 1)
std_logic_vector slv
Definition: StdRtlPkg.vhd:29