SURF  1.0
JesdTestStreamTx.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : JesdTestStreamTx.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-04-15
5 -- Last update: 2015-04-15
6 -------------------------------------------------------------------------------
7 -- Description: Test Data Stream Generator
8 -- Outputs a saw, ramp, or square wave test signal data stream for testing
9 -- Saw signal increment (type_i = 00): Ramp step is determined by rampStep_i.
10 -- Saw signal decrement (type_i = 01): Ramp step is determined by rampStep_i.
11 -- Square wave(type_i = 10): Period is squarePeriod_i. Duty cycle is 50%.
12 -- Amplitude is determined by posAmplitude_i and negAmplitude_i.
13 -- pulse_o is a binary equivalent of the analogue square wave.
14 -------------------------------------------------------------------------------
15 -- This file is part of 'SLAC Firmware Standard Library'.
16 -- It is subject to the license terms in the LICENSE.txt file found in the
17 -- top-level directory of this distribution and at:
18 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
19 -- No part of 'SLAC Firmware Standard Library', including this file,
20 -- may be copied, modified, propagated, or distributed except according to
21 -- the terms contained in the LICENSE.txt file.
22 -------------------------------------------------------------------------------
23 
24 library ieee;
25 use ieee.std_logic_1164.all;
26 use ieee.std_logic_unsigned.all;
27 
28 use ieee.numeric_std.all;
29 
30 use work.StdRtlPkg.all;
31 use work.jesd204bpkg.all;
32 
33 --! @see entity
34  --! @ingroup protocols_jesd204b
36  generic (
37  TPD_G : time := 1 ns;
38  F_G : positive := 2
39  );
40  port (
41  clk : in sl;
42  rst : in sl;
43 
44  -- Enable signal generation
45  -- when switching between signal types the module has to be
46  -- disabled and re-enabled in order to align signals
47  enable_i : in sl;
48 
49  -- Signal type
50  type_i : in slv(1 downto 0);
51 
52  -- Increase counter by the step
53  rampStep_i : in slv(PER_STEP_WIDTH_C-1 downto 0);
54  squarePeriod_i : in slv(PER_STEP_WIDTH_C-1 downto 0);
55 
56  -- Positive and negative amplitude square wave
57  posAmplitude_i : in slv(F_G*8-1 downto 0);
58  negAmplitude_i : in slv(F_G*8-1 downto 0);
59 
60  -- Sample data containing test signal
61  sampleData_o : out slv(GT_WORD_SIZE_C*8-1 downto 0);
62  -- Digital out pulse for latency debug
63  pulse_o : out sl
64  );
65 end entity JesdTestStreamTx;
66 
67 architecture rtl of JesdTestStreamTx is
68 
69  constant SAM_IN_WORD_C : positive := (GT_WORD_SIZE_C/F_G);
70 
71  type RegType is record
72  squareCnt : slv(PER_STEP_WIDTH_C-1 downto 0);
73  rampCnt : signed(F_G*8-1 downto 0);
74  testData : slv (sampleData_o'range);
75  inc : sl;
76  sign : sl;
77  end record RegType;
78 
79  constant REG_INIT_C : RegType := (
80  squareCnt => (others => '0'),
81  rampCnt => (others => '0'),
82  testData => (others => '0'),
83  inc => '1',
84  sign => '0'
85  );
86 
87  signal r : RegType := REG_INIT_C;
88  signal rin : RegType;
89  --
90 begin
91 
93  variable v : RegType;
94  begin
95  v := r;
96 
97  -- Ramp generator
98  -------------------------------------------------------------
99  if (type_i = "00" or type_i = "01") then
100 
101  -- Saw tooth increment
102  if (type_i = "00") then
103  v.inc := '1';
104  end if;
105 
106  -- Saw tooth decrement
107  if (type_i = "01") then
108  v.inc := '0';
109  end if;
110 
111  -- Ramp up or down counter
112  if (v.inc = '1') then
113  -- Increment sample base
114  v.rampCnt := r.rampCnt + slvToInt(rampStep_i)*SAM_IN_WORD_C;
115 
116  -- Increment samples within the word
117  for I in (SAM_IN_WORD_C-1) downto 0 loop
118  v.testData((F_G*8*I)+(F_G*8-1) downto F_G*8*I) := std_logic_vector(r.rampCnt(F_G*8-1 downto 0)+((SAM_IN_WORD_C-1)-I)*slvToInt(rampStep_i));
119  end loop;
120  else
121  -- Decrement sample base
122  v.rampCnt := r.rampCnt - slvToInt(rampStep_i)*SAM_IN_WORD_C;
123 
124  -- Decrement samples within the word
125  for I in (SAM_IN_WORD_C-1) downto 0 loop
126  v.testData((F_G*8*I)+(F_G*8-1) downto F_G*8*I) := std_logic_vector(r.rampCnt(F_G*8-1 downto 0)-((SAM_IN_WORD_C-1)-I)*slvToInt(rampStep_i));
127  end loop;
128  end if;
129 
130  -- Initialize square parameters
131  v.squareCnt := (others=>'0');
132  v.sign := '0';
133  elsif (type_i = "10") then
134  v.squareCnt := r.squareCnt+1;
135  if (r.squareCnt = squarePeriod_i) then
136  v.squareCnt := (others=>'0');
137  v.sign := not r.sign;
138  if (r.sign = '0') then
139  for I in (SAM_IN_WORD_C-1) downto 0 loop
140  v.testData((F_G*8*I)+(F_G*8-1) downto F_G*8*I) := negAmplitude_i;
141  end loop;
142  elsif (r.sign = '1') then
143  for I in (SAM_IN_WORD_C-1) downto 0 loop
144  v.testData((F_G*8*I)+(F_G*8-1) downto F_G*8*I) := posAmplitude_i;
145  end loop;
146  end if;
147  end if;
148 
149  -- Initialize ramp parameters
150  v.rampCnt := (others=>'0');
151  v.inc := '1';
152  else
153  v.testData := (others=>'0');
154 
155  -- Initialize square parameters
156  v.squareCnt := (others=>'0');
157  v.sign := '0';
158 
159  -- Initialize ramp parameters
160  v.rampCnt := (others=>'0');
161  v.inc := '1';
162  end if;
163 
164  if (enable_i = '0') then
165  v := REG_INIT_C;
166  end if;
167 
168  if (rst = '1') then
169  v := REG_INIT_C;
170  end if;
171 
172  rin <= v;
173 
174  end process comb;
175 
176  seq : process (clk) is
177  begin
178  if (rising_edge(clk)) then
179  r <= rin after TPD_G;
180  end if;
181  end process seq;
182 
183  -- Digital square waveform out
184  pulse_o <= r.sign;
185  -- Output data assignment
186  sampleData_o <= r.testData;
187 ---------------------------------------
188 end architecture rtl;
std_logic sl
Definition: StdRtlPkg.vhd:28
in squarePeriod_islv( PER_STEP_WIDTH_C- 1 downto 0)
out sampleData_oslv( GT_WORD_SIZE_C* 8- 1 downto 0)
in negAmplitude_islv( F_G* 8- 1 downto 0)
in type_islv( 1 downto 0)
in posAmplitude_islv( F_G* 8- 1 downto 0)
_library_ ieeeieee
in rampStep_islv( PER_STEP_WIDTH_C- 1 downto 0)
std_logic_vector slv
Definition: StdRtlPkg.vhd:29