SURF  1.0
AxiSy56040Reg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiSy56040Reg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2015-06-12
5 -- Last update: 2016-09-20
6 -------------------------------------------------------------------------------
7 -- Description: This controller is designed around the Micrel SY56040AR.
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.AxiLitePkg.all;
25 
26 --! @see entity
27  --! @ingroup devices_Microchip_sy56040
28 entity AxiSy56040Reg is
29  generic (
30  TPD_G : time := 1 ns;
31  AXI_CLK_FREQ_G : real := 200.0E+6; -- units of Hz
32  XBAR_DEFAULT_G : Slv2Array(3 downto 0) := ("11", "10", "01", "00");
34  port (
35  -- XBAR Ports
36  xBarSin : out slv(1 downto 0);
37  xBarSout : out slv(1 downto 0);
38  xBarConfig : out sl;
39  xBarLoad : out sl;
40  -- AXI-Lite Register Interface
45  -- Clocks and Resets
46  axiClk : in sl;
47  axiRst : in sl);
48 end AxiSy56040Reg;
49 
50 architecture rtl of AxiSy56040Reg is
51 
52  constant PULSE_WIDTH_C : real := 10.0E-9; -- units of seconds
53  constant PULSE_FREQ_C : real := 1.0 / PULSE_WIDTH_C; -- units of Hz
54  constant MAX_CNT_C : natural := getTimeRatio(AXI_CLK_FREQ_G, PULSE_FREQ_C);
55 
56  type stateType is (
57  IDLE_S,
58  SETUP_S,
59  LOAD_S,
60  HOLD_S);
61 
62  type RegType is record
63  sin : slv(1 downto 0);
64  sout : slv(1 downto 0);
65  load : sl;
66  config : Slv2Array(3 downto 0);
67  cnt : natural range 0 to MAX_CNT_C;
68  index : natural range 0 to 3;
69  -- AXI-Lite Signals
72  -- Status Machine
73  state : StateType;
74  end record RegType;
75 
76  constant REG_INIT_C : RegType := (
77  sin => (others => '0'),
78  sout => (others => '0'),
79  load => '0',
80  config => XBAR_DEFAULT_G,
81  cnt => 0,
82  index => 0,
83  -- AXI-Lite Signals
86  -- Status Machine
87  state => SETUP_S);
88 
89  signal r : RegType := REG_INIT_C;
90  signal rin : RegType;
91 
92  -- attribute dont_touch : string;
93  -- attribute dont_touch of r : signal is "true";
94 
95 begin
96 
97  comb : process (axiReadMaster, axiRst, axiWriteMaster, r) is
98  variable v : RegType;
99  variable axiStatus : AxiLiteStatusType;
100  variable axiWriteResp : slv(1 downto 0);
101  variable axiReadResp : slv(1 downto 0);
102  begin
103  -- Latch the current value
104  v := r;
105 
106  -- Determine the transaction type
108 
109  -- State Machine
110  case r.state is
111  ----------------------------------------------------------------------
112  when IDLE_S =>
113  -- Check for a read request
114  if (axiStatus.readEnable = '1') then
115  -- Reset the register
116  v.axiReadSlave.rdata := (others => '0');
117  axiReadResp := AXI_RESP_OK_C;
118  -- Decode address and assign read data
119  case (axiReadMaster.araddr(3 downto 0)) is
120  when x"0" => -- OUT[0] Mapping
121  v.axiReadSlave.rdata(1 downto 0) := r.config(0);
122  when x"4" => -- OUT[1] Mapping
123  v.axiReadSlave.rdata(1 downto 0) := r.config(1);
124  when x"8" => -- OUT[2] Mapping
125  v.axiReadSlave.rdata(1 downto 0) := r.config(2);
126  when x"C" => -- OUT[3] Mapping
127  v.axiReadSlave.rdata(1 downto 0) := r.config(3);
128  when others =>
129  axiReadResp := AXI_ERROR_RESP_G;
130  end case;
131  -- Send AXI-Lite Response
132  axiSlaveReadResponse(v.axiReadSlave, axiReadResp);
133  -- Check for a write request
134  elsif (axiStatus.writeEnable = '1') then
135  axiWriteResp := AXI_RESP_OK_C;
136  -- Decode address and perform write
137  case (axiWriteMaster.awaddr(3 downto 0)) is
138  when x"0" => -- OUT[0] Mapping
139  v.config(0) := axiWriteMaster.wdata(1 downto 0);
140  v.state := SETUP_S;
141  when x"4" => -- OUT[1] Mapping
142  v.config(1) := axiWriteMaster.wdata(1 downto 0);
143  v.state := SETUP_S;
144  when x"8" => -- OUT[2] Mapping
145  v.config(2) := axiWriteMaster.wdata(1 downto 0);
146  v.state := SETUP_S;
147  when x"C" => -- OUT[3] Mapping
148  v.config(3) := axiWriteMaster.wdata(1 downto 0);
149  v.state := SETUP_S;
150  when others =>
151  axiWriteResp := AXI_ERROR_RESP_G;
152  end case;
153  -- Send AXI-Lite response
154  axiSlaveWriteResponse(v.axiWriteSlave, axiWriteResp);
155  end if;
156  ----------------------------------------------------------------------
157  when SETUP_S =>
158  v.sin := r.config(r.index);
159  v.sout := toSLv(r.index, 2);
160  v.load := '0';
161  -- Increment the counter
162  v.cnt := r.cnt + 1;
163  -- Check the counter
164  if r.cnt = MAX_CNT_C then
165  -- Reset the counter
166  v.cnt := 0;
167  -- Next state
168  v.state := LOAD_S;
169  end if;
170  ----------------------------------------------------------------------
171  when LOAD_S =>
172  v.load := '1';
173  -- Increment the counter
174  v.cnt := r.cnt + 1;
175  -- Check the counter
176  if r.cnt = MAX_CNT_C then
177  -- Reset the counter
178  v.cnt := 0;
179  -- Next state
180  v.state := HOLD_S;
181  end if;
182  ----------------------------------------------------------------------
183  when HOLD_S =>
184  v.load := '0';
185  -- Increment the counter
186  v.cnt := r.cnt + 1;
187  -- Check the counter
188  if r.cnt = MAX_CNT_C then
189  -- Reset the counter
190  v.cnt := 0;
191  -- Increment the counter
192  v.index := r.index + 1;
193  -- Check the counter
194  if r.index = 3 then
195  -- Reset the counter
196  v.index := 0;
197  -- Next state
198  v.state := IDLE_S;
199  else
200  -- Next state
201  v.state := SETUP_S;
202  end if;
203  end if;
204  ----------------------------------------------------------------------
205  end case;
206 
207  -- Synchronous Reset
208  if axiRst = '1' then
209  v := REG_INIT_C;
210  end if;
211 
212  -- Register the variable for next clock cycle
213  rin <= v;
214 
215  -- Outputs
218  xBarSin <= r.sin;
219  xBarSout <= r.sout;
220  xBarConfig <= r.load;
221  xBarLoad <= r.load;
222 
223  end process comb;
224 
225  seq : process (axiClk) is
226  begin
227  if rising_edge(axiClk) then
228  r <= rin after TPD_G;
229  end if;
230  end process seq;
231 
232 end rtl;
_library_ ieeeieee
out xBarSoutslv( 1 downto 0)
AxiLiteWriteMasterType
Definition: AxiLitePkg.vhd:111
std_logic sl
Definition: StdRtlPkg.vhd:28
slv( 31 downto 0) rdata
Definition: AxiLitePkg.vhd:89
out axiReadSlaveAxiLiteReadSlaveType
slv( 31 downto 0) wdata
Definition: AxiLitePkg.vhd:117
AxiLiteStatusType axiStatus
Definition: AxiLitePkg.vhd:183
slv( 1 downto 0) := "10" AXI_RESP_SLVERR_C
Definition: AxiLitePkg.vhd:36
AxiLiteReadMasterType
Definition: AxiLitePkg.vhd:59
slv( 31 downto 0) awaddr
Definition: AxiLitePkg.vhd:113
in axiWriteMasterAxiLiteWriteMasterType
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:95
AXI_CLK_FREQ_Greal := 200.0E+6
AxiLiteReadSlaveType
Definition: AxiLitePkg.vhd:85
out xBarSinslv( 1 downto 0)
XBAR_DEFAULT_GSlv2Array( 3 downto 0) :=( "11", "10", "01", "00")
slv( 1 downto 0) := "00" AXI_RESP_OK_C
Definition: AxiLitePkg.vhd:31
in axiReadMasterAxiLiteReadMasterType
slv( 31 downto 0) araddr
Definition: AxiLitePkg.vhd:61
AXI_ERROR_RESP_Gslv( 1 downto 0) := AXI_RESP_SLVERR_C
AxiLiteWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0') AXI_LITE_WRITE_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:156
out axiWriteSlaveAxiLiteWriteSlaveType
TPD_Gtime := 1 ns
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
array(natural range <> ) of slv( 1 downto 0) Slv2Array
Definition: StdRtlPkg.vhd:409