SURF  1.0
DS2411Core.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : DS2411Core.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2007-12-19
5 -- Last update: 2015-01-14
6 -------------------------------------------------------------------------------
7 -- Description: Controller for DS2411 64-bit serial ID PROM
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_arith.all;
21 use ieee.std_logic_unsigned.all;
22 
23 library UNISIM;
24 use UNISIM.VCOMPONENTS.all;
25 
26 use work.StdRtlPkg.all;
27 
28 --! @see entity
29  --! @ingroup base_general
30 entity DS2411Core is
31  generic (
32  TPD_G : time := 1 ns;
33  SIMULATION_G : boolean := false;
34  SIM_OUTPUT_G : slv(63 downto 0) := x"0123456789ABCDEF";
35  CLK_PERIOD_G : real := 6.4E-9); --units of seconds
36  port (
37  -- Clock & Reset Signals
38  clk : in sl;
39  rst : in sl;
40  -- ID Prom Signals
41  fdSerSdio : inout sl;
42  -- Serial Number
43  fdValue : out slv(63 downto 0);
44  fdValid : out sl);
45 end DS2411Core;
46 
47 architecture rtl of DS2411Core is
48  type StateType is (
49  ST_START,
50  ST_RESET,
51  ST_WAIT,
52  ST_WRITE,
53  ST_PAUSE,
54  ST_READ,
55  ST_DONE);
56  signal curState,
57  nxtState : StateType := ST_START;
58 
59  signal setOutLow,
60  fdValidSet,
61  fdSerDin,
62  bitSet,
63  bitCntEn : sl := '0';
64  signal bitCntRst,
65  timeCntRst : sl := '1';
66  signal timeCnt : slv(31 downto 0) := (others => '0');
67  signal bitCnt : slv(5 downto 0) := (others => '0');
68  signal setOutLowInv : sl;
69  signal fdSerial : slv(63 downto 0) := (others => '0');
70 
71 begin
72 
73  fdValue <= fdSerial when(fdValidSet = '1') else (others => '0');
74 
75  SIN_GEN : if (SIMULATION_G = true) generate
76  fdSerSdio <= 'Z';
77  fdValid <= '1';
78  fdValidSet <= '1';
79  fdSerial <= SIM_OUTPUT_G;
80  end generate;
81 
82  NORMAL_GEN : if (SIMULATION_G = false) generate
83 
84  setOutLowInv <= not setOutLow;
85  FD_SER_SDIO_BUFT : IOBUF
86  port map (
87  I => '0',
88  O => fdSerDin,
89  IO => fdSerSdio,
90  T => setOutLowInv);
91 
92 -- fdSerSdio <= '0' when(setOutLow = '1') else 'Z';
93 -- fdSerDin <= fdSerSdio;
94 
95  -- Sync state logic
96  process (clk, rst)
97  begin
98  if rst = '1' then
99  fdSerial <= (others => '0') after TPD_G;
100  fdValid <= '0' after TPD_G;
101  timeCnt <= (others => '0') after TPD_G;
102  bitCnt <= (others => '0') after TPD_G;
103  curState <= ST_START after TPD_G;
104  elsif rising_edge(clk) then
105 
106  -- Shift new serial data
107  if fdValidSet = '1' then
108  fdValid <= '1' after TPD_G;
109  end if;
110 
111  -- Bit Set Of Received Data
112  if bitSet = '1' then
113  fdSerial(conv_integer(bitCnt)) <= fdSerDin after TPD_G;
114  end if;
115 
116  -- Bit Counter
117  if bitCntRst = '1' then
118  bitCnt <= (others => '0') after TPD_G;
119  elsif bitCntEn = '1' then
120  bitCnt <= bitCnt + 1 after TPD_G;
121  end if;
122 
123  -- Time Counter
124  if timeCntRst = '1' then
125  timeCnt <= (others => '0') after TPD_G;
126  else
127  timeCnt <= timeCnt + 1 after TPD_G;
128  end if;
129 
130  -- State
131  curState <= nxtState after TPD_G;
132 
133  end if;
134  end process;
135 
136 
137  -- State Machine
138  process (bitCnt, curState, timeCnt)
139  begin
140 
141  -- State machine
142  case curState is
143 
144  -- Start State
145  when ST_START =>
146  setOutLow <= '0';
147  fdValidSet <= '0';
148  bitSet <= '0';
149  bitCntRst <= '1';
150  bitCntEn <= '0';
151 
152  -- Wait 830us
153  if timeCnt = toSlv(getTimeRatio(830.0E-6, CLK_PERIOD_G), 32) then
154  nxtState <= ST_RESET;
155  timeCntRst <= '1';
156  else
157  nxtState <= curState;
158  timeCntRst <= '0';
159  end if;
160 
161  -- Reset Link
162  when ST_RESET =>
163  setOutLow <= '1';
164  fdValidSet <= '0';
165  bitSet <= '0';
166  bitCntRst <= '1';
167  bitCntEn <= '0';
168 
169  -- Continue for 500us
170  if timeCnt = toSlv(getTimeRatio(500.0E-6, CLK_PERIOD_G), 32) then
171  nxtState <= ST_WAIT;
172  timeCntRst <= '1';
173  else
174  nxtState <= curState;
175  timeCntRst <= '0';
176  end if;
177 
178  -- Wait after reset
179  when ST_WAIT =>
180  setOutLow <= '0';
181  fdValidSet <= '0';
182  bitSet <= '0';
183  bitCntRst <= '1';
184  bitCntEn <= '0';
185 
186  -- Wait 500us
187  if timeCnt = toSlv(getTimeRatio(500.0E-6, CLK_PERIOD_G), 32) then
188  nxtState <= ST_WRITE;
189  timeCntRst <= '1';
190  else
191  nxtState <= curState;
192  timeCntRst <= '0';
193  end if;
194 
195  -- Write Command Bits To PROM (0x33)
196  when ST_WRITE =>
197  fdValidSet <= '0';
198  bitSet <= '0';
199 
200  -- Assert start pulse for 12us
201  if timeCnt < toSlv(getTimeRatio(12.0E-6, CLK_PERIOD_G), 32) then
202  timeCntRst <= '0';
203  bitCntEn <= '0';
204  bitCntRst <= '0';
205  setOutLow <= '1';
206  bitCntEn <= '0';
207  nxtState <= curState;
208 
209  -- Output write value for 52uS
210  elsif timeCnt < toSlv(getTimeRatio(52.0E-6, CLK_PERIOD_G), 32) then
211  if bitCnt = 2 or bitCnt = 3 or bitCnt = 6 or bitCnt = 7 then
212  setOutLow <= '1';
213  else
214  setOutLow <= '0';
215  end if;
216  nxtState <= curState;
217  timeCntRst <= '0';
218  bitCntRst <= '0';
219  bitCntEn <= '0';
220 
221  -- Recovery Time of 62.4us
222  elsif timeCnt < toSlv(getTimeRatio(62.4E-6, CLK_PERIOD_G), 32) then
223  setOutLow <= '0';
224  nxtState <= curState;
225  timeCntRst <= '0';
226  bitCntRst <= '0';
227  bitCntEn <= '0';
228 
229  -- Done with bit
230  else
231  timeCntRst <= '1';
232  bitCntEn <= '1';
233  setOutLow <= '0';
234 
235  -- Done with write
236  if bitCnt = 7 then
237  bitCntRst <= '1';
238  nxtState <= ST_PAUSE;
239  else
240  bitCntRst <= '0';
241  nxtState <= curState;
242  end if;
243  end if;
244 
245  -- Delay after write
246  when ST_PAUSE =>
247  setOutLow <= '0';
248  fdValidSet <= '0';
249  bitSet <= '0';
250  bitCntRst <= '1';
251  bitCntEn <= '0';
252 
253  -- Wait 60us
254  if timeCnt = toSlv(getTimeRatio(60.0E-6, CLK_PERIOD_G), 32) then
255  nxtState <= ST_READ;
256  timeCntRst <= '1';
257  else
258  nxtState <= curState;
259  timeCntRst <= '0';
260  end if;
261 
262  -- Read Data Bits From Prom
263  when ST_READ =>
264  fdValidSet <= '0';
265 
266  -- Assert start pulse for 12us
267  if timeCnt < toSlv(getTimeRatio(12.0E-6, CLK_PERIOD_G), 32) then
268  timeCntRst <= '0';
269  bitCntEn <= '0';
270  bitCntRst <= '0';
271  setOutLow <= '1';
272  bitSet <= '0';
273  nxtState <= curState;
274 
275  -- Sample data at 13.1uS
276  elsif timeCnt = toSlv(getTimeRatio(13.1E-6, CLK_PERIOD_G), 32) then
277  setOutLow <= '0';
278  bitCntEn <= '0';
279  timeCntRst <= '0';
280  bitCntRst <= '0';
281  bitSet <= '1';
282  nxtState <= curState;
283 
284  -- Recovery Time of 62.4us
285  elsif timeCnt < toSlv(getTimeRatio(62.4E-6, CLK_PERIOD_G), 32) then
286  setOutLow <= '0';
287  timeCntRst <= '0';
288  bitCntEn <= '0';
289  bitSet <= '0';
290  bitCntRst <= '0';
291  nxtState <= curState;
292 
293  -- Done with bit
294  else
295  setOutLow <= '0';
296  timeCntRst <= '1';
297  bitCntEn <= '1';
298  bitSet <= '0';
299 
300  -- Done with write
301  if bitCnt = 63 then
302  bitCntRst <= '1';
303  nxtState <= ST_DONE;
304  else
305  bitCntRst <= '0';
306  nxtState <= curState;
307  end if;
308  end if;
309 
310  -- Done with read
311  when ST_DONE =>
312  fdValidSet <= '1';
313  timeCntRst <= '1';
314  bitCntRst <= '1';
315  bitCntEn <= '0';
316  setOutLow <= '0';
317  bitSet <= '0';
318  nxtState <= curState;
319 
320  when others =>
321  fdValidSet <= '0';
322  timeCntRst <= '1';
323  bitCntRst <= '1';
324  bitCntEn <= '0';
325  setOutLow <= '0';
326  bitSet <= '0';
327  nxtState <= ST_START;
328  end case;
329  end process;
330  end generate;
331 end rtl;
std_logic sl
Definition: StdRtlPkg.vhd:28
SIM_OUTPUT_Gslv( 63 downto 0) := x"0123456789ABCDEF"
Definition: DS2411Core.vhd:34
CLK_PERIOD_Greal := 6.4E-9
Definition: DS2411Core.vhd:35
in clksl
Definition: DS2411Core.vhd:38
in rstsl
Definition: DS2411Core.vhd:39
inout fdSerSdiosl
Definition: DS2411Core.vhd:41
SIMULATION_Gboolean := false
Definition: DS2411Core.vhd:33
_library_ ieeeieee
out fdValidsl
Definition: DS2411Core.vhd:44
TPD_Gtime := 1 ns
Definition: DS2411Core.vhd:32
out fdValueslv( 63 downto 0)
Definition: DS2411Core.vhd:43
std_logic_vector slv
Definition: StdRtlPkg.vhd:29