SURF  1.0
SaciSlave.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : SaciSlave.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2012-07-12
5 -- Last update: 2016-06-17
6 -------------------------------------------------------------------------------
7 -- Description: Slave module for SACI interface.
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.numeric_std.all;
21 use work.StdRtlPkg.all;
22 
23 --! @see entity
24  --! @ingroup protocols_saci
25 entity SaciSlave is
26 
27  generic (
28  TPD_G : time := 1 ns);
29 
30  port (
31  rstL : in sl; -- ASIC global reset
32 
33  -- Serial Interface
34  saciClk : in sl;
35  saciSelL : in sl; -- chipSelect
36  saciCmd : in sl;
37  saciRsp : out sl;
38 
39  -- Silly reset hack to get saciSelL | rst onto dedicated reset bar
40  rstOutL : out sl;
41  rstInL : in sl;
42 
43  -- Detector (Parallel) Interface
44  exec : out sl;
45  ack : in sl;
46  readL : out sl;
47  cmd : out slv(6 downto 0);
48  addr : out slv(11 downto 0);
49  wrData : out slv(31 downto 0);
50  rdData : in slv(31 downto 0));
51 
52 end entity SaciSlave;
53 
54 architecture rtl of SaciSlave is
55 
56  type StateType is (WAIT_START_S, SHIFT_IN_S);
57 
58  type RegType is record
59  shiftReg : slv(54 downto 0);
60  state : StateType;
61  exec : sl;
62  readL : sl;
63  end record RegType;
64 
65  signal r, rin : RegType;
66  signal saciCmdFall : sl;
67 
68  procedure shiftInLeft (
69  i : in sl;
70  v : inout slv) is
71  begin
72  v := v(v'high-1 downto v'low) & i;
73  end procedure shiftInLeft;
74 
75 begin
76 
77  -- Chip select also functions as async reset
78  rstOutL <= rstL and not saciSelL;
79 
80 
81  -- Clock in serial input on falling edge
82  fall : process (saciClk, rstInL) is
83  begin
84  if (rstInL = '0') then
85  saciCmdFall <= '0' after TPD_G;
86  elsif (falling_edge(saciClk)) then
87  saciCmdFall <= saciCmd after TPD_G;
88  end if;
89  end process fall;
90 
91 
92  seq : process (saciClk, rstInL) is
93  begin
94  if (rstInL = '0') then
95  r.shiftReg <= (others => '0') after TPD_G;
96  r.state <= WAIT_START_S after TPD_G;
97  r.exec <= '0' after TPD_G;
98  r.readL <= '0' after TPD_G;
99  elsif (rising_edge(saciClk)) then
100  r <= rin after TPD_G;
101  end if;
102  end process seq;
103 
104  comb : process (r, saciCmdFall, ack, rdData, saciSelL) is
105  variable v : RegType;
106  begin
107  v := r;
108 
109  shiftInLeft(saciCmdFall, v.shiftReg);
110 
111  -- Main state machine
112  case (r.state) is
113 
114  when WAIT_START_S =>
115 
116  -- Shift data out and look for next start bit
117  if (r.shiftReg(0) = '1') then
118  v.state := SHIFT_IN_S;
119  end if;
120 
121  when SHIFT_IN_S =>
122  -- Wait for start bit to shift all the way in then assert exec and readL
123  if (r.shiftReg(52) = '1') then
124  v.exec := '1';
125  v.readL := r.shiftReg(51);
126  end if;
127 
128  if (r.exec = '1') then
129  v.shiftReg := r.shiftReg; -- Pause shifting when exec high
130  v.readL := r.readL;
131  end if;
132 
133  if (ack = '1') then
134  v.exec := '0';
135  v.state := WAIT_START_S;
136  if (r.shiftReg(52) = '1') then
137  v.shiftReg(32 downto 1) := (others => '0'); -- write
138  else
139  v.shiftReg(32 downto 1) := rdData; -- read
140  end if;
141  end if;
142 
143 
144  when others =>
145  v.shiftReg := (others => '0');
146  v.state := WAIT_START_S;
147  v.exec := '0';
148  v.readL := '0';
149 
150  end case;
151 
152 
153  rin <= v;
154 
155  -- Assign outputs from registers
156  exec <= r.exec;
157  readL <= r.readL;
158  saciRsp <= r.shiftReg(54); -- 52 = start, 51 = r/w at time of exec
159  cmd <= r.shiftReg(51 downto 45);
160  addr <= r.shiftReg(44 downto 33);
161  wrData <= r.shiftReg(32 downto 1);
162 
163  end process comb;
164 
165 
166 end architecture rtl;
167 
in rstInLsl
Definition: SaciSlave.vhd:41
out saciRspsl
Definition: SaciSlave.vhd:37
in saciCmdsl
Definition: SaciSlave.vhd:36
in acksl
Definition: SaciSlave.vhd:45
std_logic sl
Definition: StdRtlPkg.vhd:28
_library_ IEEEIEEE
Definition: StdRtlPkg.vhd:18
out addrslv( 11 downto 0)
Definition: SaciSlave.vhd:48
in saciSelLsl
Definition: SaciSlave.vhd:35
in rstLsl
Definition: SaciSlave.vhd:31
_library_ ieeeieee
TPD_Gtime := 1 ns
Definition: SaciSlave.vhd:28
out cmdslv( 6 downto 0)
Definition: SaciSlave.vhd:47
in saciClksl
Definition: SaciSlave.vhd:34
out readLsl
Definition: SaciSlave.vhd:46
in rdDataslv( 31 downto 0)
Definition: SaciSlave.vhd:50
out rstOutLsl
Definition: SaciSlave.vhd:40
out wrDataslv( 31 downto 0)
Definition: SaciSlave.vhd:49
out execsl
Definition: SaciSlave.vhd:44
std_logic_vector slv
Definition: StdRtlPkg.vhd:29