SURF  1.0
AxiDac7654Spi.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiDac7654Spi.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2013-05-22
5 -- Last update: 2016-09-20
6 -------------------------------------------------------------------------------
7 -- Description: SPI Interface Module
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_unsigned.all;
21 use ieee.std_logic_arith.all;
22 
23 use work.StdRtlPkg.all;
24 use work.AxiDac7654Pkg.all;
25 
26 --! @see entity
27  --! @ingroup devices_Ti_dac7654
28 entity AxiDac7654Spi is
29  generic (
30  TPD_G : time := 1 ns;
31  AXI_CLK_FREQ_G : real := 125.0E+6);
32  port (
33  -- Parallel interface
36  --DAC I/O ports
37  dacCs : out sl;
38  dacSck : out sl;
39  dacSdi : out sl;
40  dacSdo : in sl;
41  dacLoad : out sl;
42  dacLdac : out sl;
43  dacRst : out sl;
44  --Global Signals
45  axiClk : in sl;
46  axiRst : in sl);
47 end AxiDac7654Spi;
48 
49 architecture rtl of AxiDac7654Spi is
50 
51  constant AXI_CLK_PERIOD_C : real := 1.0 / AXI_CLK_FREQ_G;
52  constant MAX_CNT_C : natural := getTimeRatio(166.4E-9, AXI_CLK_PERIOD_C);
53 
54  type StateType is (
55  RST_S,
56  IDLE_S,
57  SCK_LOW_S,
58  SCK_HIGH_S,
59  LOAD_S,
60  TLD2_WAIT_S,
61  LDAC_S,
62  HANDSHAKE_S);
63 
64  signal state : StateType := RST_S;
65  signal ack,
66  cs,
67  sck,
68  sdi,
69  load,
70  ldac,
71  rst : sl := '0';
72  signal ch : slv(1 downto 0) := (others => '0');
73  signal pntr : natural range 0 to 23 := 0;
74  signal cnt : natural range 0 to MAX_CNT_C := 0;
75 
76 begin
77 
78  dacCs <= cs;
79  dacSck <= sck;
80  dacSdi <= sdi;
81  dacLoad <= load;
82  dacLdac <= ldac;
83  dacRst <= rst;
84  spiOut.ack <= ack;
85 
86  process(axiClk)
87  begin
88  if rising_edge(axiClk) then
89  if axiRst = '1' then
90  cs <= '1' after TPD_G;
91  sck <= '1' after TPD_G;
92  sdi <= '0' after TPD_G;
93  load <= '1' after TPD_G;
94  ldac <= '0' after TPD_G;
95  rst <= '0' after TPD_G;
96  cnt <= 0 after TPD_G;
97  pntr <= 0 after TPD_G;
98  ch <= (others => '0') after TPD_G;
99  ack <= '0' after TPD_G;
100  state <= RST_S after TPD_G;
101  else
102  case (state) is
103  ----------------------------------------------------------------------
104  when RST_S =>
105  cnt <= cnt + 1 after TPD_G;
106  if cnt = getTimeRatio(19.2E-9, AXI_CLK_PERIOD_C) then -- 19.2ns wait
107  rst <= '1' after TPD_G;
108  cnt <= 0 after TPD_G;
109  state <= IDLE_S after TPD_G;
110  end if;
111  ----------------------------------------------------------------------
112  when IDLE_S =>
113  if spiIn.req = '1' then
114  cs <= '0' after TPD_G;
115  state <= SCK_LOW_S after TPD_G;
116  end if;
117  ----------------------------------------------------------------------
118  when SCK_LOW_S =>
119  sck <= '0' after TPD_G;
120  if pntr = 0 then
121  sdi <= ch(1) after TPD_G;
122  elsif pntr = 1 then
123  sdi <= ch(0) after TPD_G;
124  elsif pntr > 7 then
125  sdi <= spiIn.data(conv_integer(ch))(23-pntr) after TPD_G;
126  else
127  sdi <= '0' after TPD_G;
128  end if;
129  cnt <= cnt + 1 after TPD_G;
130  if cnt = getTimeRatio(32.0E-9, AXI_CLK_PERIOD_C) then -- 32ns wait
131  cnt <= 0 after TPD_G;
132  state <= SCK_HIGH_S after TPD_G;
133  end if;
134  ----------------------------------------------------------------------
135  when SCK_HIGH_S =>
136  sck <= '1' after TPD_G;
137  cnt <= cnt + 1 after TPD_G;
138  if cnt = getTimeRatio(32.0E-9, AXI_CLK_PERIOD_C) then -- 32ns wait
139  cnt <= 0 after TPD_G;
140  pntr <= pntr + 1 after TPD_G;
141  if pntr = 23 then
142  cs <= '1' after TPD_G;
143  pntr <= 0 after TPD_G;
144  state <= TLD2_WAIT_S after TPD_G;
145  else
146  state <= SCK_LOW_S after TPD_G;
147  end if;
148  end if;
149  ----------------------------------------------------------------------
150  when TLD2_WAIT_S => --required settling time between rising edge of SCK and falling of LOAD
151  cnt <= cnt + 1 after TPD_G;
152  if cnt = getTimeRatio(12.8E-9, AXI_CLK_PERIOD_C) then -- 12.8ns wait
153  cnt <= 0 after TPD_G;
154  state <= LOAD_S after TPD_G;
155  end if;
156  ----------------------------------------------------------------------
157  when LOAD_S =>
158  load <= '0' after TPD_G;
159  cnt <= cnt + 1 after TPD_G;
160  if cnt = getTimeRatio(51.2E-9, AXI_CLK_PERIOD_C) then -- 51.2ns wait
161  load <= '1' after TPD_G;
162  cnt <= 0 after TPD_G;
163  state <= LDAC_S after TPD_G;
164  end if;
165  ----------------------------------------------------------------------
166  when LDAC_S =>
167  ldac <= '1' after TPD_G;
168  cnt <= cnt + 1 after TPD_G;
169  if cnt = getTimeRatio(166.4E-9, AXI_CLK_PERIOD_C) then -- 166.4 ns wait
170  ldac <= '0' after TPD_G;
171  cnt <= 0 after TPD_G;
172  ch <= ch + 1 after TPD_G;
173  if ch = 3 then
174  ch <= (others => '0') after TPD_G;
175  ack <= '1' after TPD_G;
176  state <= HANDSHAKE_S after TPD_G;
177  else
178  cs <= '0' after TPD_G;
179  state <= SCK_LOW_S after TPD_G;
180  end if;
181  end if;
182  ----------------------------------------------------------------------
183  when HANDSHAKE_S =>
184  if spiIn.req = '0' then
185  ack <= '0' after TPD_G;
186  state <= IDLE_S after TPD_G;
187  end if;
188  ----------------------------------------------------------------------
189  end case;
190  end if;
191  end if;
192  end process;
193 end rtl;
AXI_CLK_FREQ_Greal := 125.0E+6
std_logic sl
Definition: StdRtlPkg.vhd:28
_library_ ieeeieee
in spiInAxiDac7654SpiInType
TPD_Gtime := 1 ns
out spiOutAxiDac7654SpiOutType
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
Slv16Array( 0 to 3) data