SURF  1.0
AxiReadEmulate.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiReadEmulate.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-04-02
5 -- Last update: 2016-04-26
6 -------------------------------------------------------------------------------
7 -- Description: AXI4 Read Emulation Module
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 use ieee.std_logic_arith.all;
21 use ieee.std_logic_unsigned.all;
22 
23 use work.TextUtilPkg.all;
24 use work.StdRtlPkg.all;
25 use work.AxiPkg.all;
26 
27 --! @see entity
28  --! @ingroup axi
29 entity AxiReadEmulate is
30  generic (
31  TPD_G : time := 1 ns;
32  LATENCY_G : natural := 31;
34  SIM_DEBUG_G : boolean := false);
35  port (
36  -- Clock/Reset
37  axiClk : in sl;
38  axiRst : in sl;
39  -- AXI Interface
42 end AxiReadEmulate;
43 
44 architecture structure of AxiReadEmulate is
45 
46  type StateType is (
47  IDLE_S,
48  DATA_S);
49 
50  type RegType is record
51  latency : natural range 0 to LATENCY_G;
53  cnt : slv(31 downto 0);
56  end record RegType;
57 
58  constant REG_INIT_C : RegType := (
59  latency => 0,
60  state => IDLE_S,
61  cnt => (others => '0'),
64 
65  signal r : RegType := REG_INIT_C;
66  signal rin : RegType;
67 
70 
71 begin
72 
73  U_AxiReadPathFifo : entity work.AxiReadPathFifo
74  generic map (
75  TPD_G => TPD_G,
77  port map (
78  sAxiClk => axiClk,
79  sAxiRst => axiRst,
82  mAxiClk => axiClk,
83  mAxiRst => axiRst,
86 
87  comb : process (axiRst, intReadMaster, r) is
88  variable v : RegType;
89  begin
90  -- Latch the current value
91  v := r;
92 
93  -- Reset the variables
95 
96  -- State machine
97  case r.state is
98  ----------------------------------------------------------------------
99  when IDLE_S =>
100  -- Reset the counter
101  v.cnt := (others => '0');
102  -- Check the latency
103  if r.latency = LATENCY_G then
104  -- Reset the counter
105  v.latency := 0;
106  -- Check for a memory request
107  if intReadMaster.arvalid = '1' then
108  -- Latch the value
109  v.iMaster := intReadMaster;
110  -- Accept the data
111  v.iSlave.arready := '1';
112  -- Next state
113  v.state := DATA_s;
114  end if;
115  else
116  -- Increment the counter
117  v.latency := r.latency + 1;
118  end if;
119  ----------------------------------------------------------------------
120  when DATA_s =>
121  -- Check if ready to move data
122  if intReadMaster.rready = '1' then
123  -- Move the data
124  v.iSlave.rvalid := '1';
125  -- Send counter data
126  for i in 0 to (2**conv_integer(r.iMaster.arsize))-1 loop
127  v.iSlave.rdata(i*8+7 downto i*8) := v.cnt(7 downto 0);
128  v.cnt := v.cnt + 1;
129  end loop;
130  print(SIM_DEBUG_G, "AxiReadEmulate( addr:" & hstr(r.iMaster.araddr+r.cnt) & ", data: " & hstr(v.iSlave.rdata(AXI_CONFIG_G.DATA_BYTES_C-1 downto 0)) & ")");
131 
132  -- Echo the read ID
133  v.iSlave.rid := r.iMaster.arid;
134  -- Check if transaction is completed
135  if r.iMaster.arlen = 0 then
136  -- Set the flag
137  v.iSlave.rlast := '1';
138  -- Check if request in pipeline
139  if intReadMaster.arvalid = '1' then
140  -- Preset the counter
141  v.latency := LATENCY_G;
142  end if;
143  -- Next state
144  v.state := IDLE_S;
145  else
146  v.iMaster.arlen := r.iMaster.arlen - 1;
147  end if;
148  end if;
149  ----------------------------------------------------------------------
150  end case;
151 
152  -- Reset
153  if (axiRst = '1') then
154  v := REG_INIT_C;
155  end if;
156 
157  -- Register the variable for next clock cycle
158  rin <= v;
159 
160  -- Outputs
161  intReadSlave <= v.iSlave;
162 
163  end process comb;
164 
165  seq : process (axiClk) is
166  begin
167  if (rising_edge(axiClk)) then
168  r <= rin after TPD_G;
169  end if;
170  end process seq;
171 
172 end structure;
173 
slv( 7 downto 0) arlen
Definition: AxiPkg.vhd:37
(IDLE_S,DATA_S) StateType
AxiReadMasterType :=(arvalid => '0',araddr =>( others => '0'),arid =>( others => '0'),arlen =>( others => '0'),arsize =>( others => '0'),arburst =>( others => '0'),arlock =>( others => '0'),arprot =>( others => '0'),arcache =>( others => '0'),arqos =>( others => '0'),arregion =>( others => '0'),rready => '0') AXI_READ_MASTER_INIT_C
Definition: AxiPkg.vhd:49
out sAxiReadSlaveAxiReadSlaveType
slv( 1023 downto 0) rdata
Definition: AxiPkg.vhd:83
sl rready
Definition: AxiPkg.vhd:46
slv( 31 downto 0) rid
Definition: AxiPkg.vhd:86
in mAxiReadSlaveAxiReadSlaveType
_library_ ieeeieee
Definition: AxiPkg.vhd:18
sl rvalid
Definition: AxiPkg.vhd:85
std_logic sl
Definition: StdRtlPkg.vhd:28
SIM_DEBUG_Gboolean := false
TPD_Gtime := 1 ns
TPD_Gtime := 1 ns
sl arready
Definition: AxiPkg.vhd:81
out mAxiReadMasterAxiReadMasterType
AxiReadSlaveType
Definition: AxiPkg.vhd:79
in axiReadMasterAxiReadMasterType
slv( 31 downto 0) cnt
AXI_CONFIG_GAxiConfigType := AXI_CONFIG_INIT_C
out axiReadSlaveAxiReadSlaveType
slv( 31 downto 0) arid
Definition: AxiPkg.vhd:36
LATENCY_Gnatural := 31
RegType :=(latency => 0,state => IDLE_S,cnt =>( others => '0'),iMaster => AXI_READ_MASTER_INIT_C,iSlave => AXI_READ_SLAVE_INIT_C) REG_INIT_C
AxiReadMasterType iMaster
slv( 63 downto 0) araddr
Definition: AxiPkg.vhd:35
AxiConfigType
Definition: AxiPkg.vhd:213
slv( 2 downto 0) arsize
Definition: AxiPkg.vhd:38
natural range 0 to LATENCY_G latency
AxiReadMasterType intReadMaster
in sAxiReadMasterAxiReadMasterType
positive range 1 to 128 DATA_BYTES_C
Definition: AxiPkg.vhd:215
sl rlast
Definition: AxiPkg.vhd:84
AxiConfigType :=axiConfig(ADDR_WIDTH_C => 32,DATA_BYTES_C => 4,ID_BITS_C => 12,LEN_BITS_C => 4) AXI_CONFIG_INIT_C
Definition: AxiPkg.vhd:227
AxiReadSlaveType intReadSlave
AxiReadSlaveType iSlave
AXI_CONFIG_GAxiConfigType := AXI_CONFIG_INIT_C
AxiReadMasterType
Definition: AxiPkg.vhd:32
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
sl arvalid
Definition: AxiPkg.vhd:34
AxiReadSlaveType :=(arready => '0',rdata =>( others => '0'),rlast => '0',rvalid => '0',rid =>( others => '0'),rresp =>( others => '0')) AXI_READ_SLAVE_INIT_C
Definition: AxiPkg.vhd:90
RegType := REG_INIT_C r