SURF  1.0
AxiLiteSaciMaster.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiLiteSaciMaster2.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2016-06-01
5 -- Last update: 2016-11-15
6 -------------------------------------------------------------------------------
7 -- Description: New and improved version of the AxiLiteSaciMaster.
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_unsigned.all;
21 use ieee.std_logic_arith.all;
22 
23 use work.StdRtlPkg.all;
24 use work.AxiLitePkg.all;
25 use work.SaciMasterPkg.all;
26 
27 --! @see entity
28  --! @ingroup protocols_saci
30  generic (
31  TPD_G : time := 1 ns;
33  AXIL_CLK_PERIOD_G : real := 8.0e-9; -- In units of seconds
34  AXIL_TIMEOUT_G : real := 1.0E-3; -- In units of seconds
35  SACI_CLK_PERIOD_G : real := 1.0e-6; -- In units of seconds
36  SACI_CLK_FREERUN_G : boolean := false;
37  SACI_NUM_CHIPS_G : positive range 1 to 4 := 1;
38  SACI_RSP_BUSSED_G : boolean := false);
39  port (
40  -- SACI interface
41  saciClk : out sl;
42  saciCmd : out sl;
43  saciSelL : out slv(SACI_NUM_CHIPS_G-1 downto 0);
44  saciRsp : in slv(ite(SACI_RSP_BUSSED_G, 0, SACI_NUM_CHIPS_G-1) downto 0);
45  -- AXI-Lite Register Interface
46  axilClk : in sl;
47  axilRst : in sl;
52 end AxiLiteSaciMaster;
53 
54 architecture rtl of AxiLiteSaciMaster is
55 
56  constant CHIP_BITS_C : integer := log2(SACI_NUM_CHIPS_G);
57  constant TIMEOUT_C : integer := integer(AXIL_TIMEOUT_G/AXIL_CLK_PERIOD_G)-1;
58 
59  type StateType is (
60  IDLE_S,
61  SACI_REQ_S,
62  SACI_ACK_S);
63 
64  type RegType is record
65  state : StateType;
66  saciRst : sl;
67  req : sl;
68  chip : slv(log2(SACI_NUM_CHIPS_G)-1 downto 0);
69  op : sl;
70  cmd : slv(6 downto 0);
71  addr : slv(11 downto 0);
72  wrData : slv(31 downto 0);
73  timer : integer range 0 to TIMEOUT_C;
76 
77  end record RegType;
78 
79  constant REG_INIT_C : RegType := (
80  state => IDLE_S,
81  saciRst => '1',
82  req => '0',
83  chip => (others => '0'),
84  op => '0',
85  cmd => (others => '0'),
86  addr => (others => '0'),
87  wrData => (others => '0'),
88  timer => 0,
91 
92  signal r : RegType := REG_INIT_C;
93  signal rin : RegType;
94 
95  signal ack : sl;
96  signal fail : sl;
97  signal rdData : slv(31 downto 0);
98 
99  -- attribute dont_touch : string;
100  -- attribute dont_touch of r : signal is "true";
101 
102 begin
103 
104  assert (AXIL_CLK_PERIOD_G < 1.0)
105  report "AXIL_CLK_PERIOD_G must be < 1.0 seconds" severity failure;
106  assert (AXIL_TIMEOUT_G < 1.0)
107  report "AXIL_TIMEOUT_G must be < 1.0 seconds" severity failure;
108  assert (SACI_CLK_PERIOD_G < 1.0)
109  report "SACI_CLK_PERIOD_G must be < 1.0 seconds" severity failure;
111  report "AXIL_CLK_PERIOD_G must be < AXIL_TIMEOUT_G" severity failure;
113  report "AXIL_CLK_PERIOD_G must be < SACI_CLK_PERIOD_G" severity failure;
115  report "SACI_CLK_PERIOD_G must be < AXIL_TIMEOUT_G" severity failure;
116 
117  U_SaciMaster2_1 : entity work.SaciMaster2
118  generic map (
119  TPD_G => TPD_G,
125  port map (
126  sysClk => axilClk, -- [in]
127  sysRst => r.saciRst, -- [in]
128  req => r.req, -- [in]
129  ack => ack, -- [out]
130  fail => fail, -- [out]
131  chip => r.chip, -- [in]
132  op => r.op, -- [in]
133  cmd => r.cmd, -- [in]
134  addr => r.addr, -- [in]
135  wrData => r.wrData, -- [in]
136  rdData => rdData, -- [out]
137  saciClk => saciClk, -- [out]
138  saciSelL => saciSelL, -- [out]
139  saciCmd => saciCmd, -- [out]
140  saciRsp => saciRsp); -- [in]
141 
142  comb : process (ack, axilReadMaster, axilRst, axilWriteMaster, fail, r, rdData) is
143  variable v : RegType;
144  variable axilStatus : AxiLiteStatusType;
145  variable resp : slv(1 downto 0);
146  begin
147  -- Latch the current value
148  v := r;
149 
150  -- Reset the strobing signals
151  resp := AXI_RESP_OK_C;
152 
153  -- Check the timer
154  if r.timer /= TIMEOUT_C then
155  -- Increment the counter
156  v.timer := r.timer + 1;
157  end if;
158 
159  -- Determine the transaction type
160  axiSlaveWaitTxn(axilWriteMaster, axilReadMaster, v.axilWriteSlave, v.axilReadSlave, axilStatus);
161 
162  -- State Machine
163  case (r.state) is
164  ----------------------------------------------------------------------
165  when IDLE_S =>
166  -- Reset the timer
167  v.saciRst := '0';
168  v.timer := 0;
169  -- Check for a write request
170  if (axilStatus.writeEnable = '1') then
171  -- SACI Commands
172  v.req := '1';
173  v.op := '1';
174  v.chip := axilWriteMaster.awaddr(22+CHIP_BITS_C-1 downto 22);
175  if (SACI_NUM_CHIPS_G = 1) then
176  v.chip := "0";
177  end if;
178  v.cmd := axilWriteMaster.awaddr(20 downto 14);
179  v.addr := axilWriteMaster.awaddr(13 downto 2);
181  -- Next state
182  v.state := SACI_REQ_S;
183  -- Check for a read request
184  elsif (axilStatus.readEnable = '1') then
185  -- SACI Commands
186  v.req := '1';
187  v.op := '0';
188  v.chip := axilReadMaster.araddr(22+CHIP_BITS_C-1 downto 22);
189  if (SACI_NUM_CHIPS_G = 1) then
190  v.chip := "0";
191  end if;
192  v.cmd := axilReadMaster.araddr(20 downto 14);
193  v.addr := axilReadMaster.araddr(13 downto 2);
194  v.wrData := (others => '0');
195  -- Next state
196  v.state := SACI_REQ_S;
197  end if;
198  ----------------------------------------------------------------------
199  when SACI_REQ_S =>
200  if (ack = '1' and fail = '1') or (r.timer = TIMEOUT_C) then
201  -- Set the error flags
202  resp := AXIL_ERROR_RESP_G;
203  v.req := '0';
204  v.saciRst := '1';
205  elsif (ack = '1') then
206  -- Reset the flag
207  v.req := '0';
208  end if;
209 
210 
211  if (v.req = '0') then
212  -- Check for Write operation
213  if (r.op = '1') then
214  --- Send AXI-Lite response
215  axiSlaveWriteResponse(v.axilWriteSlave, resp);
216  else
217  -- Return the read data bus
219  -- Send AXI-Lite Response
220  axiSlaveReadResponse(v.axilReadSlave, resp);
221  end if;
222  -- Next state
223  v.state := SACI_ACK_S;
224  end if;
225  ----------------------------------------------------------------------
226  when SACI_ACK_S =>
227  -- Check status of ACK flag
228  if (ack = '0') then
229  -- Next state
230  v.state := IDLE_S;
231  end if;
232  ----------------------------------------------------------------------
233  end case;
234 
235  -- Synchronous Reset
236  if axilRst = '1' then
237  v := REG_INIT_C;
238  end if;
239 
240  -- Register the variable for next clock cycle
241  rin <= v;
242 
243  -- Outputs
246 
247  end process comb;
248 
249  seq : process (axilClk) is
250  begin
251  if rising_edge(axilClk) then
252  r <= rin after TPD_G;
253  end if;
254  end process seq;
255 
256 end rtl;
TPD_Gtime := 1 ns
Definition: SaciMaster2.vhd:30
SYS_CLK_PERIOD_Greal := 8.0e-9
Definition: SaciMaster2.vhd:31
out axilWriteSlaveAxiLiteWriteSlaveType
slv( 11 downto 0) addr
AxiLiteWriteMasterType
Definition: AxiLitePkg.vhd:111
std_logic sl
Definition: StdRtlPkg.vhd:28
slv( 31 downto 0) wrData
in axilWriteMasterAxiLiteWriteMasterType
in saciRspslv( ite( SACI_RSP_BUSSED_G, 0, SACI_NUM_CHIPS_G- 1) downto 0)
Definition: SaciMaster2.vhd:55
out saciCmdsl
Definition: SaciMaster2.vhd:54
slv( 6 downto 0) cmd
in sysRstsl
Definition: SaciMaster2.vhd:38
slv( 31 downto 0) rdata
Definition: AxiLitePkg.vhd:89
in addrslv( 11 downto 0)
Definition: SaciMaster2.vhd:47
in sysClksl
Definition: SaciMaster2.vhd:37
AXIL_CLK_PERIOD_Greal := 8.0e-9
SACI_CLK_FREERUN_Gboolean := false
slv( 31 downto 0) wdata
Definition: AxiLitePkg.vhd:117
SACI_RSP_BUSSED_Gboolean := false
out saciSelLslv( SACI_NUM_CHIPS_G- 1 downto 0)
in axilReadMasterAxiLiteReadMasterType
slv( 1 downto 0) := "11" AXI_RESP_DECERR_C
Definition: AxiLitePkg.vhd:49
out rdDataslv( 31 downto 0)
Definition: SaciMaster2.vhd:49
SACI_RSP_BUSSED_Gboolean := false
Definition: SaciMaster2.vhd:35
_library_ ieeeieee
Definition: TxFSM.vhd:41
SACI_NUM_CHIPS_Gpositive range 1 to 4:= 1
AxiLiteReadMasterType
Definition: AxiLitePkg.vhd:59
in chipslv( log2(SACI_NUM_CHIPS_G )- 1 downto 0)
Definition: SaciMaster2.vhd:44
slv( 31 downto 0) awaddr
Definition: AxiLitePkg.vhd:113
in wrDataslv( 31 downto 0)
Definition: SaciMaster2.vhd:48
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:95
AXIL_TIMEOUT_Greal := 1.0E-3
AxiLiteReadSlaveType
Definition: AxiLitePkg.vhd:85
out saciClksl
Definition: SaciMaster2.vhd:52
SACI_CLK_FREERUN_Gboolean := false
Definition: SaciMaster2.vhd:33
slv( 1 downto 0) := "00" AXI_RESP_OK_C
Definition: AxiLitePkg.vhd:31
slv( 31 downto 0) araddr
Definition: AxiLitePkg.vhd:61
in cmdslv( 6 downto 0)
Definition: SaciMaster2.vhd:46
out failsl
Definition: SaciMaster2.vhd:43
AXIL_ERROR_RESP_Gslv( 1 downto 0) := AXI_RESP_DECERR_C
in saciRspslv( ite( SACI_RSP_BUSSED_G, 0, SACI_NUM_CHIPS_G- 1) downto 0)
slv( 31 downto 0) rdData
SACI_NUM_CHIPS_Gpositive := 1
Definition: SaciMaster2.vhd:34
out acksl
Definition: SaciMaster2.vhd:42
out saciSelLslv( SACI_NUM_CHIPS_G- 1 downto 0)
Definition: SaciMaster2.vhd:53
AxiLiteWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0') AXI_LITE_WRITE_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:156
out axilReadSlaveAxiLiteReadSlaveType
SACI_CLK_PERIOD_Greal := 1.0e-6
Definition: SaciMaster2.vhd:32
slv( SACI_CHIP_WIDTH_C- 1 downto 0) chip
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
SACI_CLK_PERIOD_Greal := 1.0e-6