SURF  1.0
SaciPrepRdout.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SaciPrepRdout.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 07/21/2016
5 -- Last update: 07/21/2016
6 -------------------------------------------------------------------------------
7 -- Description: The AXI lite master to issue SACI prepare for readout command
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.StdRtlPkg.all;
24 use work.AxiLitePkg.all;
25 
26 --! @see entity
27  --! @ingroup protocols_saci
28 entity SaciPrepRdout is
29  generic (
30  TPD_G : time := 1 ns;
31  MASK_REG_ADDR_G : slv(31 downto 0) := x"00000034";
32  SACI_BASE_ADDR_G : slv(31 downto 0) := x"02000000";
34  SACI_NUM_CHIPS_G : natural range 1 to 4 := 4
35  );
36  port (
37  axilClk : in sl;
38  axilRst : in sl;
39 
40  -- Prepare for readout req/ack
43 
44  -- Optional AXI lite slave port for status readout
49 
50  -- AXI lite master port for command issue
55  );
56 
57 end SaciPrepRdout;
58 
59 architecture rtl of SaciPrepRdout is
60 
61  type StateType is (S_IDLE_C, S_IS_ASIC_C, S_WRITE_C, S_WRITE_AXI_C, S_READ_C, S_READ_AXI_C);
62 
63  type RegType is record
64  asicMask : slv(SACI_NUM_CHIPS_G-1 downto 0);
65  state : StateType;
66  timer : slv(23 downto 0);
67  asicCnt : natural;
68  rdTimeout : slv(31 downto 0);
69  rdFail : slv(31 downto 0);
70  wrTimeout : slv(31 downto 0);
71  wrFail : slv(31 downto 0);
72  prepRdoutAck : sl;
77  end record RegType;
78 
79  constant REG_INIT_C : RegType := (
80  asicMask => (others=>'0'),
81  state => S_IDLE_C,
82  timer => (others => '1'),
83  asicCnt => 0,
84  rdTimeout => (others=>'0'),
85  rdFail => (others=>'0'),
86  wrTimeout => (others=>'0'),
87  wrFail => (others=>'0'),
88  prepRdoutAck => '0',
93 
94  signal r : RegType := REG_INIT_C;
95  signal rin : RegType;
96 
97  function asicBaseAddr(asic : natural) return slv is
98  begin
99  return toSlv(asic*(2**22), 32);
100  end function;
101 
102 begin
103 
105  variable v : RegType;
106  variable regCon : AxiLiteEndPointType;
107  begin
108  v := r;
109 
110  v.sAxilReadSlave.rdata := (others => '0');
111  axiSlaveWaitTxn(regCon, sAxilWriteMaster, sAxilReadMaster, v.sAxilWriteSlave, v.sAxilReadSlave);
112 
113  -- error counters
114  axiSlaveRegisterR(regCon, x"00", 0, r.rdFail);
115  axiSlaveRegisterR(regCon, x"04", 0, r.rdTimeout);
116  axiSlaveRegisterR(regCon, x"08", 0, r.wrFail);
117  axiSlaveRegisterR(regCon, x"0C", 0, r.wrTimeout);
118  axiSlaveRegisterR(regCon, x"10", 0, r.asicMask);
119 
120  axiSlaveDefault(regCon, v.sAxilWriteSlave, v.sAxilReadSlave, AXIL_ERR_RESP_G);
121 
122  -- State machine for SACI mediation
123  -- SACI command is issued via the AXI lite master bus
124  case(r.state) is
125  when S_IDLE_C =>
128  v.asicCnt := 0;
129  v.prepRdoutAck := '0';
130 
131  -- If we see a multi-pixel write request, handle it
132  if (prepRdoutReq = '1') then
133  v.state := S_READ_C;
134  end if;
135 
136  -- Read the ASIC mask
137  when S_READ_C =>
139  v.mAxilReadMaster.arprot := (others => '0');
140  v.timer := (others => '1');
141 
142  -- Start AXI transaction
143  v.mAxilReadMaster.arvalid := '1';
144  v.mAxilReadMaster.rready := '1';
145  v.state := S_READ_AXI_C;
146 
147  -- Read AXI
148  when S_READ_AXI_C =>
149  v.timer := r.timer - 1;
150 
151  -- Clear control signals on ack
152  if mAxilReadSlave.arready = '1' then
153  v.mAxilReadMaster.arvalid := '0';
154  end if;
155  if mAxilReadSlave.rvalid = '1' then
156  v.mAxilReadMaster.rready := '0';
157  v.asicMask := mAxilReadSlave.rdata(SACI_NUM_CHIPS_G-1 downto 0);
158 
160  v.rdFail := r.rdFail + 1;
161  end if;
162  end if;
163 
164  -- End transaction on timeout
165  if r.timer = 0 then
166  v.mAxilReadMaster.arvalid := '0';
167  v.mAxilReadMaster.rready := '0';
168  v.rdTimeout := r.rdTimeout + 1;
169  end if;
170 
171  -- Transaction is done
172  if v.mAxilReadMaster.arvalid = '0' and v.mAxilReadMaster.rready = '0' then
173  if mAxilReadSlave.rresp /= AXI_RESP_OK_C or r.timer = 0 then
174  v.state := S_IDLE_C;
175  else
176  v.state := S_IS_ASIC_C;
177  end if;
178  end if;
179 
180  -- Check if ASIC is enabled
181  when S_IS_ASIC_C =>
182  if r.asicCnt >= SACI_NUM_CHIPS_G then
183  v.prepRdoutAck := '1';
184  v.state := S_IDLE_C;
185  elsif (r.asicMask(r.asicCnt) = '1') then
186  v.state := S_WRITE_C;
187  else
188  v.asicCnt := r.asicCnt + 1;
189  end if;
190 
191  -- Prepare Write Transactions
192  when S_WRITE_C =>
193  -- Prepare for readout: CMD = 0, ADDR = 0, DATA = 0
194  v.mAxilWriteMaster.awaddr := SACI_BASE_ADDR_G + asicBaseAddr(r.asicCnt);
195  v.mAxilWriteMaster.wdata := x"00000000";
196  v.mAxilWriteMaster.awprot := (others => '0');
197  v.mAxilWriteMaster.wstrb := (others => '1');
198  v.timer := (others => '1');
199 
200  v.mAxilWriteMaster.awvalid := '1';
201  v.mAxilWriteMaster.wvalid := '1';
202  v.mAxilWriteMaster.bready := '1';
203  v.state := S_WRITE_AXI_C;
204 
205  -- Write Transaction, AXI
206  when S_WRITE_AXI_C =>
207  v.timer := r.timer - 1;
208 
209  -- Clear control signals on ack
210  if mAxilWriteSlave.awready = '1' then
211  v.mAxilWriteMaster.awvalid := '0';
212  end if;
213  if mAxilWriteSlave.wready = '1' then
214  v.mAxilWriteMaster.wvalid := '0';
215  end if;
216  if mAxilWriteSlave.bvalid = '1' then
217  v.mAxilWriteMaster.bready := '0';
218 
220  v.wrFail := r.wrFail + 1;
221  end if;
222  end if;
223 
224  -- End transaction on timeout
225  if r.timer = 0 then
226  v.mAxilWriteMaster.awvalid := '0';
227  v.mAxilWriteMaster.wvalid := '0';
228  v.mAxilWriteMaster.bready := '0';
229  v.wrTimeout := r.wrTimeout + 1;
230  end if;
231 
232  -- Transaction is done
233  if v.mAxilWriteMaster.awvalid = '0' and
234  v.mAxilWriteMaster.wvalid = '0' and
235  v.mAxilWriteMaster.bready = '0' then
236 
237  if mAxilWriteSlave.bresp /= AXI_RESP_OK_C or r.timer = 0 then
238  v.state := S_IDLE_C;
239  else
240  v.asicCnt := r.asicCnt + 1;
241  v.state := S_IS_ASIC_C;
242  end if;
243 
244  end if;
245 
246  end case;
247 
248  if (axilRst = '1') then
249  v := REG_INIT_C;
250  end if;
251 
252  rin <= v;
253 
258 
260 
261  end process comb;
262 
263  seq : process (axilClk) is
264  begin
265  if (rising_edge(axilClk)) then
266  r <= rin after TPD_G;
267  end if;
268  end process seq;
269 
270 end rtl;
271 
slv( 2 downto 0) arprot
Definition: AxiLitePkg.vhd:62
in mAxilWriteSlaveAxiLiteWriteSlaveType
AXIL_ERR_RESP_Gslv( 1 downto 0) := AXI_RESP_DECERR_C
slv( 1 downto 0) rresp
Definition: AxiLitePkg.vhd:90
out mAxilReadMasterAxiLiteReadMasterType
AxiLiteWriteMasterType
Definition: AxiLitePkg.vhd:111
std_logic sl
Definition: StdRtlPkg.vhd:28
MASK_REG_ADDR_Gslv( 31 downto 0) := x"00000034"
slv( 31 downto 0) rdata
Definition: AxiLitePkg.vhd:89
in sAxilReadMasterAxiLiteReadMasterType
out sAxilWriteSlaveAxiLiteWriteSlaveType
slv( 31 downto 0) wdata
Definition: AxiLitePkg.vhd:117
in sAxilWriteMasterAxiLiteWriteMasterType
slv( 1 downto 0) := "11" AXI_RESP_DECERR_C
Definition: AxiLitePkg.vhd:49
slv( 2 downto 0) awprot
Definition: AxiLitePkg.vhd:114
SACI_BASE_ADDR_Gslv( 31 downto 0) := x"02000000"
AxiLiteReadMasterType
Definition: AxiLitePkg.vhd:59
out sAxilReadSlaveAxiLiteReadSlaveType
slv( 31 downto 0) awaddr
Definition: AxiLitePkg.vhd:113
TPD_Gtime := 1 ns
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:95
slv( 1 downto 0) bresp
Definition: AxiLitePkg.vhd:150
AxiLiteReadMasterType :=(araddr =>( others => '0'),arprot =>( others => '0'),arvalid => '0',rready => '1') AXI_LITE_READ_MASTER_INIT_C
Definition: AxiLitePkg.vhd:69
AxiLiteReadSlaveType
Definition: AxiLitePkg.vhd:85
AxiLiteWriteMasterType :=(awaddr =>( others => '0'),awprot =>( others => '0'),awvalid => '0',wdata =>( others => '0'),wstrb =>( others => '1'),wvalid => '0',bready => '1') AXI_LITE_WRITE_MASTER_INIT_C
Definition: AxiLitePkg.vhd:125
slv( 1 downto 0) := "00" AXI_RESP_OK_C
Definition: AxiLitePkg.vhd:31
SACI_NUM_CHIPS_Gnatural range 1 to 4:= 4
slv( 31 downto 0) araddr
Definition: AxiLitePkg.vhd:61
in mAxilReadSlaveAxiLiteReadSlaveType
slv( 3 downto 0) wstrb
Definition: AxiLitePkg.vhd:118
out mAxilWriteMasterAxiLiteWriteMasterType
AxiLiteWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0') AXI_LITE_WRITE_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:156
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
out prepRdoutAcksl