SURF  1.0
JesdSyncFsmTxTest.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : JesdSyncFsmTxTest.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-04-14
5 -- Last update: 2015-04-14
6 -------------------------------------------------------------------------------
7 -- Description: Synchronizer for simple TX Finite state machine
8 -- Finite state machine for sub-class 1 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
31  generic (
32  TPD_G : time := 1 ns);
33  port (
34  -- Clocks and Resets
35  clk : in sl;
36  rst : in sl;
37 
38  -- Enable the module
39  enable_i : in sl;
40 
41  -- JESD subclass selection: '0' or '1'(default)
42  subClass_i : in sl;
43 
44  -- Local multi frame clock
45  lmfc_i : in sl;
46 
47  -- Synchronization request
48  nSync_i : in sl;
49 
50  testCntr_o : out slv(7 downto 0);
51 
52  -- Synchronization process is complete start sending data
53  dataValid_o : out sl;
54  -- First data
55  align_o : out sl
56  );
57 end JesdSyncFsmTxTest;
58 
59 architecture rtl of JesdSyncFsmTxTest is
60 
61  type stateType is (
62  IDLE_S,
63  SYNC_S,
64  ALIGN_S,
65  DATA_S
66  );
67 
68  type RegType is record
69  -- Synchronous FSM control outputs
70  dataValid : sl;
71  align : sl;
72  cnt : slv(7 downto 0);
73 
74  -- Status Machine
75  state : StateType;
76  end record RegType;
77 
78  constant REG_INIT_C : RegType := (
79  dataValid => '0',
80  align => '0',
81  cnt => (others => '0'),
82 
83  -- Status Machine
84  state => IDLE_S
85  );
86 
87  signal r : RegType := REG_INIT_C;
88  signal rin : RegType;
89 
90 begin
91 
92  -- State machine
93  comb : process (rst, r, enable_i, lmfc_i, nSync_i) is
94  variable v : RegType;
95  begin
96  -- Latch the current value
97  v := r;
98 
99  -- State Machine
100  case r.state is
101  ----------------------------------------------------------------------
102  when IDLE_S =>
103 
104  -- Outputs
105  v.cnt := (others => '0');
106  v.dataValid := '0';
107  v.align := '0';
108 
109  -- Next state condition
110  if nSync_i = '0' then
111  v.state := SYNC_S;
112  end if;
113  ----------------------------------------------------------------------
114  when SYNC_S =>
115 
116  -- Outputs
117  v.cnt := (others => '0');
118  v.dataValid := '0';
119  v.align := '0';
120 
121  -- Next state condition
122  if subClass_i = '1' then
123  if nSync_i = '1' and enable_i = '1' and lmfc_i = '1' then
124  v.state := ALIGN_S;
125  elsif enable_i = '0' then
126  v.state := IDLE_S;
127  end if;
128  else
129  if nSync_i = '1' and enable_i = '1' then
130  v.state := ALIGN_S;
131  elsif enable_i = '0' then
132  v.state := IDLE_S;
133  end if;
134  end if;
135  ----------------------------------------------------------------------
136  when ALIGN_S =>
137 
138  -- Outputs
139  v.cnt := (others => '0');
140  v.dataValid := '0';
141  v.align := '1';
142 
143  -- Next state condition
144  v.state := DATA_S;
145  ----------------------------------------------------------------------
146  when DATA_S =>
147 
148  -- Outputs
149  v.cnt := r.cnt+GT_WORD_SIZE_C; -- two or four data bytes sent in parallel
150  v.dataValid := '1';
151  v.align := '0';
152 
153  -- Next state condition
154  if nSync_i = '0' or enable_i = '0' then
155  v.state := IDLE_S;
156  end if;
157  ----------------------------------------------------------------------
158  when others =>
159 
160  -- Outputs
161  v.cnt := (others => '0');
162  v.dataValid := '0';
163  v.align := '0';
164 
165  -- Next state condition
166  v.state := IDLE_S;
167  ----------------------------------------------------------------------
168  end case;
169 
170  -- Synchronous Reset
171  if rst = '1' then
172  v := REG_INIT_C;
173  end if;
174 
175  -- Register the variable for next clock cycle
176  rin <= v;
177 
178  end process comb;
179 
180  seq : process (clk) is
181  begin
182  if rising_edge(clk) then
183  r <= rin after TPD_G;
184  end if;
185  end process seq;
186 
187  -- Output assignment
188  testCntr_o <= r.cnt;
189  dataValid_o <= r.dataValid;
190  align_o <= r.align;
191 ----------------------------------------------
192 end rtl;
std_logic sl
Definition: StdRtlPkg.vhd:28
positive := 4 GT_WORD_SIZE_C
Definition: Jesd204bPkg.vhd:31
_library_ ieeeieee
out testCntr_oslv( 7 downto 0)
std_logic_vector slv
Definition: StdRtlPkg.vhd:29