1 ------------------------------------------------------------------------------- 2 -- File : SaciMasterSync.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2012-08-10 5 -- Last update: 2017-05-10 6 ------------------------------------------------------------------------------- 7 -- Description: Saci Master Synchronization Wrapper 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 ------------------------------------------------------------------------------- 19 use IEEE.std_logic_1164.
all;
20 use ieee.numeric_std.
all;
22 -- use work.SynchronizePkg.all; 26 --! @ingroup protocols_saci 50 end entity SaciMasterSync;
54 type SynchronizerType is record 59 constant SYNCHRONIZER_INIT_0_C : SynchronizerType := (tmp => '0', sync => '0', last => '0');
60 constant SYNCHRONIZER_INIT_1_C : SynchronizerType := (tmp => '1', sync => '1', last => '1');
61 procedure synchronize (
63 current :
in SynchronizerType;
64 nextOut :
out SynchronizerType)
is 67 nextOut.sync := current.tmp;
68 nextOut.last := current.sync;
71 type StateType is (IDLE_S, CHIP_SELECT_S, TX_S, RX_START_S, RX_HEADER_S, RX_DATA_S, ACK_S);
73 type RegType is record 74 reqSync : SynchronizerType;
75 resetSync : SynchronizerType;
77 shiftReg : slv(52 downto 0);
78 shiftCount : (5 downto 0);
85 signal r, rin : RegType;
86 signal saciRspFall : sl;
88 signal saciClkCnt : (31 downto 0);
89 signal saciClkCntRst : ;
90 signal saciClkRising : ;
91 signal saciClkFalling : ;
97 -------------------------------------------------------------------------------------------------- 99 -------------------------------------------------------------------------------------------------- 100 saci_clk_p :
process (
clk,
rst)
is 102 if rising_edge(clk) then 104 if rst = '1' or saciClkCntRst = '1' then 105 saciClkCnt <= (others=>'0') after TPD_G;
107 saciClkCnt <= (others=>'0') after TPD_G;
109 saciClkCnt <= saciClkCnt + 1 after TPD_G;
112 if rst = '1' or saciClkCntRst = '1' then 113 iSaciClk <= '0' after TPD_G;
115 iSaciClk <= not iSaciClk after TPD_G;
118 if rst = '1' or saciClkCntRst = '1' then 119 iSaciClkD <= '0' after TPD_G;
121 iSaciClkD <= iSaciClk after TPD_G;
128 saciClkRising <= iSaciClk and not iSaciClkD;
129 saciClkFalling <= iSaciClkD and not iSaciClk;
132 -------------------------------------------------------------------------------------------------- 133 -- Capture serial input 134 -------------------------------------------------------------------------------------------------- 135 fall :
process (
clk,
rst)
is 138 saciRspFall <= '0' after TPD_G;
139 elsif (rising_edge(clk)) then 144 seq :
process (
clk,
rst)
is 147 r.reqSync <= SYNCHRONIZER_INIT_0_C after TPD_G;
148 r.resetSync <= SYNCHRONIZER_INIT_0_C after TPD_G;
149 r.state <= IDLE_S after TPD_G;
150 r.shiftReg <= (others => '0') after TPD_G;
151 r.shiftCount <= (others => '0') after TPD_G;
157 elsif (rising_edge(clk)) then 158 r <= rin after TPD_G;
162 comb :
process (r, saciRspFall,
saciMasterIn, saciClkRising)
is 163 variable rVar : RegType;
164 variable reqVar : sl;
165 variable resetVar : sl;
169 -- Synchronize control inputs to serial clock 173 reqVar := r.reqSync.sync;
174 resetVar := r.resetSync.sync;
180 rVar.shiftCount := (others => '0');
183 saciClkCntRst <= '0';
185 if (resetVar = '1') then 187 rVar.shiftReg := (others => '0');
188 rVar.shiftCount := (others => '0');
189 rVar.state := IDLE_S;
195 saciClkCntRst <= '1';
198 rVar.shiftReg := (others => '0');
199 rVar.shiftCount := (others => '0');
200 if (reqVar = '1') then 201 saciClkCntRst <= '0';
202 -- New command, load shift reg 203 rVar.shiftReg(52) := '1';
-- Start bit 210 rVar.shiftReg(31 downto 0) := (others => '0');
212 rVar.state := CHIP_SELECT_S;
215 when CHIP_SELECT_S => 218 if saciClkRising = '1' then 221 rVar.state := CHIP_SELECT_S;
225 -- Shift out data on saciCmd 226 rVar.saciCmd := r.shiftReg(52);
227 if saciClkRising = '1' then 228 rVar.shiftReg := r.shiftReg(51 downto 0) & '0';
229 rVar.shiftCount := r.shiftCount + 1;
231 rVar.shiftReg := r.shiftReg;
232 rVar.shiftCount := r.shiftCount;
236 rVar.state := RX_START_S;
238 rVar.state := RX_START_S;
243 -- Wait for saciRsp start bit 244 rVar.shiftCount := (others => '0');
245 if (saciRspFall = '1' and saciClkRising = '1') then 246 rVar.state := RX_HEADER_S;
248 rVar.state := RX_START_S;
252 -- Shift data in and check that header is correct 253 if saciClkRising = '1' then 254 rVar.shiftCount := r.shiftCount + 1;
255 --shiftInLeft(saciRspFall, r.shiftReg, rVar.shiftReg); 256 rVar.shiftReg := r.shiftReg(r.shiftReg'high-1 downto r.shiftReg'low) & saciRspFall;
258 rVar.shiftCount := r.shiftCount;
259 rVar.shiftReg := r.shiftReg;
261 if (r.shiftCount = 20) then 268 rVar.state := RX_DATA_S;
275 if saciClkRising = '1' then 276 rVar.shiftCount := r.shiftCount + 1;
277 --shiftInLeft(saciRspFall, r.shiftReg, rVar.shiftReg); 278 rVar.shiftReg := r.shiftReg(r.shiftReg'high-1 downto r.shiftReg'low) & saciRspFall;
279 if (r.shiftCount = 51) then 283 rVar.shiftCount := r.shiftCount;
284 rVar.shiftReg := r.shiftReg;
292 if (reqVar = '0') then 295 rVar.state := IDLE_S;
311 end architecture rtl;
SYNCHRONIZE_CONTROL_Gboolean := true
out saciMasterOutSaciMasterOutType
out saciSelLslv( SACI_NUM_SLAVES_C- 1 downto 0)
positive := 4 SACI_NUM_SLAVES_C
in saciHalfClkslv( 7 downto 0)
in saciMasterInSaciMasterInType
slv( SACI_CHIP_WIDTH_C- 1 downto 0) chip