SURF  1.0
JesdSyncFsmTx.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : JesdSyncFsmTx.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-04-14
5 -- Last update: 2015-04-14
6 -------------------------------------------------------------------------------
7 -- Description: Synchronizer TX Finite state machine
8 -- Finite state machine for sub-class 1 and sub-class 0 deterministic latency
9 -- lane synchronization.
10 -------------------------------------------------------------------------------
11 -- This file is part of 'SLAC Firmware Standard Library'.
12 -- It is subject to the license terms in the LICENSE.txt file found in the
13 -- top-level directory of this distribution and at:
14 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
15 -- No part of 'SLAC Firmware Standard Library', including this file,
16 -- may be copied, modified, propagated, or distributed except according to
17 -- the terms contained in the LICENSE.txt file.
18 -------------------------------------------------------------------------------
19 
20 library ieee;
21 use ieee.std_logic_1164.all;
22 use ieee.std_logic_arith.all;
23 use ieee.std_logic_unsigned.all;
24 
25 use work.StdRtlPkg.all;
26 use work.Jesd204bPkg.all;
27 
28 --! @see entity
29  --! @ingroup protocols_jesd204b
30 entity JesdSyncFsmTx is
31  generic (
32  TPD_G : time := 1 ns;
33  --JESD204B class (0 and 1 supported)
34 
35  -- Number of multi-frames in ILA sequence (4-255)
36  NUM_ILAS_MF_G : positive := 4);
37  port (
38  -- Clocks and Resets
39  clk : in sl;
40  rst : in sl;
41 
42  -- JESD subclass selection: '0' or '1'(default)
43  subClass_i : in sl;
44 
45  -- Enable the module
46  enable_i : in sl;
47 
48  -- Local multi frame clock
49  lmfc_i : in sl;
50 
51  -- Synchronization request
52  nSync_i : in sl;
53 
54  -- GT is ready to transmit data after reset
56 
57  -- SYSREF for subclass 1 fixed latency
58  sysRef_i : in sl;
59 
60  -- Synchronization process is complete start sending data
61  dataValid_o : out sl;
62 
63  -- sysref received
64  sysref_o : out sl;
65 
66  -- Initial lane synchronization sequence indicator
67  ila_o : out sl
68  );
69 end JesdSyncFsmTx;
70 
71 architecture rtl of JesdSyncFsmTx is
72 
73  type stateType is (
74  IDLE_S,
75  SYNC_S,
76  ILA_S,
77  DATA_S
78  );
79 
80  type RegType is record
81  -- Synchronous FSM control outputs
82  dataValid : sl;
83  ila : sl;
84  sysref : sl;
85  -- Count
86  cnt : slv(7 downto 0);
87 
88  -- Status Machine
89  state : StateType;
90  end record RegType;
91 
92  constant REG_INIT_C : RegType := (
93  dataValid => '0',
94  ila => '0',
95  sysref => '0',
96  cnt => (others => '0'),
97 
98  -- Status Machine
99  state => IDLE_S
100  );
101 
102  signal r : RegType := REG_INIT_C;
103  signal rin : RegType;
104 
105 begin
106 
107  -- State machine
108  comb : process (rst, r, enable_i, lmfc_i, nSync_i, gtTxReady_i, sysRef_i, subClass_i) is
109  variable v : RegType;
110  begin
111  -- Latch the current value
112  v := r;
113 
114  -- State Machine
115  case r.state is
116  ----------------------------------------------------------------------
117  when IDLE_S =>
118 
119  -- Outputs
120  v.cnt := (others => '0');
121  v.dataValid := '0';
122  v.ila := '0';
123  v.sysref := '0';
124 
125  -- Next state condition (depending on subclass)
126  if subClass_i = '1' then
127  if sysRef_i = '1' and enable_i = '1' and gtTxReady_i = '1' then
128  v.state := SYNC_S;
129  end if;
130  else
131  if enable_i = '1' and gtTxReady_i = '1' then
132  v.state := SYNC_S;
133  end if;
134  end if;
135  ----------------------------------------------------------------------
136  when SYNC_S =>
137 
138  -- Outputs
139  v.cnt := (others => '0');
140  v.dataValid := '0';
141  v.ila := '0';
142  v.sysref := '1';
143 
144  -- Next state condition
145  if nSync_i = '1' and lmfc_i = '1' then
146  v.state := ILA_S;
147  elsif enable_i = '0' then
148  v.state := IDLE_S;
149  end if;
150  ----------------------------------------------------------------------
151  when ILA_S =>
152 
153  -- Outputs
154  v.dataValid := '0';
155  v.ila := '1';
156  v.sysref := '1';
157 
158  -- Increase lmfc counter.
159  if (lmfc_i = '1') then
160  v.cnt := r.cnt + 1;
161  end if;
162 
163  -- Next state condition
164  -- After NUM_ILAS_MF_G LMFC clocks the ILA sequence ends and relevant ADC data is being received.
165  if v.cnt = NUM_ILAS_MF_G then
166  v.state := DATA_S;
167  elsif nSync_i = '0' or enable_i = '0' then
168  v.state := IDLE_S;
169  end if;
170  ----------------------------------------------------------------------
171  when DATA_S =>
172 
173  -- Outputs
174  v.cnt := r.cnt+GT_WORD_SIZE_C; -- two or four data bytes sent in parallel
175  v.dataValid := '1';
176  v.ila := '0';
177  v.sysref := '1';
178 
179  -- Next state condition
180  if nSync_i = '0' or enable_i = '0' or gtTxReady_i = '0' then
181  v.state := IDLE_S;
182  end if;
183  ----------------------------------------------------------------------
184  when others =>
185 
186  -- Outputs
187  v.cnt := (others => '0');
188  v.dataValid := '0';
189  v.ila := '0';
190  v.sysref := '0';
191 
192  -- Next state condition
193  v.state := IDLE_S;
194  ----------------------------------------------------------------------
195  end case;
196 
197  -- Synchronous Reset
198  if rst = '1' then
199  v := REG_INIT_C;
200  end if;
201 
202  -- Register the variable for next clock cycle
203  rin <= v;
204 
205  end process comb;
206 
207  seq : process (clk) is
208  begin
209  if rising_edge(clk) then
210  r <= rin after TPD_G;
211  end if;
212  end process seq;
213 
214  -- Output assignment
215  dataValid_o <= r.dataValid;
216  ila_o <= r.ila;
217  sysref_o <= r.sysref;
218 ----------------------------------------------
219 end rtl;
TPD_Gtime := 1 ns
std_logic sl
Definition: StdRtlPkg.vhd:28
out dataValid_osl
NUM_ILAS_MF_Gpositive := 4
positive := 4 GT_WORD_SIZE_C
Definition: Jesd204bPkg.vhd:31
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
_library_ ieeeieee