SURF  1.0
AxiWriteEmulate.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiWriteEmulate.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-04-02
5 -- Last update: 2016-04-26
6 -------------------------------------------------------------------------------
7 -- Description: AXI4 Write 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 AxiWriteEmulate 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 AxiWriteEmulate;
43 
44 architecture structure of AxiWriteEmulate is
45 
46  type StateType is (
47  IDLE_S,
48  DATA_S,
49  WAIT_S,
50  RESP_S);
51 
52  type RegType is record
53  latency : natural range 0 to LATENCY_G;
54  cnt : slv(15 downto 0);
58  end record RegType;
59 
60  constant REG_INIT_C : RegType := (
61  latency => 0,
62  cnt => (others=>'0'),
63  state => IDLE_S,
66 
67  signal r : RegType := REG_INIT_C;
68  signal rin : RegType;
69 
72 
73 begin
74 
75  U_AxiWritePathFifo : entity work.AxiWritePathFifo
76  generic map (
77  TPD_G => TPD_G,
79  port map (
80  sAxiClk => axiClk,
81  sAxiRst => axiRst,
84  mAxiClk => axiClk,
85  mAxiRst => axiRst,
88 
89  comb : process (axiRst, intWriteMaster, r) is
90  variable v : RegType;
91  begin
92  -- Latch the current value
93  v := r;
94 
95  -- Reset the variables
97 
98  -- State machine
99  case r.state is
100  ----------------------------------------------------------------------
101  when IDLE_S =>
102  v.cnt := (others=>'0');
103  v.latency := 0;
104  -- Check for a memory request
105  if intWriteMaster.awvalid = '1' then
106  -- Latch the value
107  v.iMaster := intWriteMaster;
108  -- Accept the data
109  v.iSlave.awready := '1';
110  -- Next state
111  v.state := DATA_s;
112  end if;
113  ----------------------------------------------------------------------
114  when DATA_s =>
115  -- Check for data
116  if intWriteMaster.wvalid = '1' then
117  -- Write data channel
118  v.iSlave.wready := '1';
119  -- Increment counter
121  -- Show data
122  print(SIM_DEBUG_G, "AxiWriteEmulate( addr:" & hstr(r.iMaster.awaddr+r.cnt) & ", data: " & hstr(intWriteMaster.wdata(AXI_CONFIG_G.DATA_BYTES_C-1 downto 0)) & ")");
123  -- Detect last
124  if intWriteMaster.wLast = '1' then
125  v.state := WAIT_S;
126  end if;
127  end if;
128  ----------------------------------------------------------------------
129  when WAIT_S =>
130  -- Check the latency
131  if r.latency = LATENCY_G then
132  v.state := RESP_S;
133  else
134  -- Increment the counter
135  v.latency := r.latency + 1;
136  end if;
137  ----------------------------------------------------------------------
138  when RESP_s =>
139  v.iSlave.bresp := (others=>'0');
140  v.iSlave.bvalid := '1';
141  v.iSlave.bid := r.iMaster.awid;
142  if intWriteMaster.bready = '1' then
143  v.state := IDLE_S;
144  end if;
145  end case;
146 
147  -- Reset
148  if (axiRst = '1') then
149  v := REG_INIT_C;
150  end if;
151 
152  -- Register the variable for next clock cycle
153  rin <= v;
154 
155  -- Outputs
156  intWriteSlave <= v.iSlave;
157 
158  end process comb;
159 
160  seq : process (axiClk) is
161  begin
162  if (rising_edge(axiClk)) then
163  r <= rin after TPD_G;
164  end if;
165  end process seq;
166 
167 end structure;
168 
AxiWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0',bid =>( others => '0')) AXI_WRITE_SLAVE_INIT_C
Definition: AxiPkg.vhd:182
out sAxiWriteSlaveAxiWriteSlaveType
sl wvalid
Definition: AxiPkg.vhd:124
sl bvalid
Definition: AxiPkg.vhd:178
std_logic sl
Definition: StdRtlPkg.vhd:28
slv( 1023 downto 0) wdata
Definition: AxiPkg.vhd:122
natural range 0 to LATENCY_G latency
sl awready
Definition: AxiPkg.vhd:173
sl bready
Definition: AxiPkg.vhd:128
in axiWriteMasterAxiWriteMasterType
AxiWriteSlaveType intWriteSlave
AXI_CONFIG_GAxiConfigType := AXI_CONFIG_INIT_C
slv( 31 downto 0) bid
Definition: AxiPkg.vhd:179
AxiWriteMasterType
Definition: AxiPkg.vhd:108
RegType :=(latency => 0,cnt =>( others => '0'),state => IDLE_S,iMaster => AXI_WRITE_MASTER_INIT_C,iSlave => AXI_WRITE_SLAVE_INIT_C) REG_INIT_C
(IDLE_S,DATA_S,WAIT_S,RESP_S) StateType
sl wready
Definition: AxiPkg.vhd:175
LATENCY_Gnatural := 31
AxiWriteMasterType iMaster
sl awvalid
Definition: AxiPkg.vhd:110
TPD_Gtime := 1 ns
in mAxiWriteSlaveAxiWriteSlaveType
AxiConfigType
Definition: AxiPkg.vhd:213
SIM_DEBUG_Gboolean := false
AxiWriteSlaveType
Definition: AxiPkg.vhd:171
RegType := REG_INIT_C r
slv( 63 downto 0) awaddr
Definition: AxiPkg.vhd:111
positive range 1 to 128 DATA_BYTES_C
Definition: AxiPkg.vhd:215
AxiWriteSlaveType iSlave
_library_ ieeeieee
Definition: AxiVersion.vhd:19
out axiWriteSlaveAxiWriteSlaveType
slv( 31 downto 0) awid
Definition: AxiPkg.vhd:112
slv( 1 downto 0) bresp
Definition: AxiPkg.vhd:177
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
AxiWriteMasterType intWriteMaster
AxiWriteMasterType :=(awvalid => '0',awaddr =>( others => '0'),awid =>( others => '0'),awlen =>( others => '0'),awsize =>( others => '0'),awburst =>( others => '0'),awlock =>( others => '0'),awprot =>( others => '0'),awcache =>( others => '0'),awqos =>( others => '0'),awregion =>( others => '0'),wdata =>( others => '0'),wlast => '0',wvalid => '0',wid =>( others => '0'),wstrb =>( others => '0'),bready => '0') AXI_WRITE_MASTER_INIT_C
Definition: AxiPkg.vhd:131
in sAxiWriteMasterAxiWriteMasterType
AXI_CONFIG_GAxiConfigType := AXI_CONFIG_INIT_C
out mAxiWriteMasterAxiWriteMasterType
std_logic_vector slv
Definition: StdRtlPkg.vhd:29