SURF  1.0
AxiXcf128Reg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiXcf128Reg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-04-18
5 -- Last update: 2015-01-13
6 -------------------------------------------------------------------------------
7 -- Description: AXI-Lite Register Access
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 use work.AxiXcf128Pkg.all;
26 
27 --! @see entity
28  --! @ingroup devices_Xilinx_xcf128
29 entity AxiXcf128Reg is
30  generic (
31  TPD_G : time := 1 ns;
32  AXI_CLK_FREQ_G : real := 200.0E+6; -- units of Hz
34  port (
35  -- AXI-Lite Register Interface
40  -- Register Inputs/Outputs
42  config : out AxiXcf128ConfigType;
43  -- Global Signals
44  axiClk : in sl;
45  axiRst : in sl);
46 end AxiXcf128Reg;
47 
48 architecture rtl of AxiXcf128Reg is
49 
50  constant MAX_CNT_C : natural := (getTimeRatio(AXI_CLK_FREQ_G, 10.0E+6))-1;
51 
52  type stateType is (
53  IDLE_S,
54  CMD_LOW_S,
55  CMD_HIGH_S,
56  WAIT_S,
57  DATA_LOW_S,
58  DATA_HIGH_S);
59 
60  type RegType is record
61  dataReg : slv(15 downto 0);
62  wrData : Slv16Array(0 to 1);
63  RnW : sl;
64  cnt : natural range 0 to MAX_CNT_C;
65  config : AxiXcf128ConfigType;
66  state : StateType;
69  end record RegType;
70 
71  constant REG_INIT_C : RegType := (
72  (others => '0'),
73  (others => (others => '0')),
74  '0',
75  0,
77  IDLE_S,
80 
81  signal r : RegType := REG_INIT_C;
82  signal rin : RegType;
83 
84 begin
85 
86  -------------------------------
87  -- Configuration Register
88  -------------------------------
89  comb : process (axiReadMaster, axiRst, axiWriteMaster, r, status) is
90  variable v : RegType;
91  variable axiStatus : AxiLiteStatusType;
92  variable axiWriteResp : slv(1 downto 0);
93  variable axiReadResp : slv(1 downto 0);
94  begin
95  -- Latch the current value
96  v := r;
97 
98  -- Determine the transaction type
100 
101  -- Reset strobe signals
102  -- *** place holder ***
103 
104  if (axiStatus.writeEnable = '1') and (r.state = IDLE_S) then
105  -- Check for an out of 32 bit aligned address
106  if axiWriteMaster.awaddr(1 downto 0) /= "00" then
107  -- Send AXI response
108  axiSlaveWriteResponse(v.axiWriteSlave, AXI_ERROR_RESP_G);
109  else
110  -- Check the write address
111  if axiWriteMaster.awaddr(3 downto 2) = 0 then
112  -- Set the write data bus
113  v.wrData(1) := axiWriteMaster.wdata(31 downto 16);
114  v.wrData(0) := axiWriteMaster.wdata(15 downto 0);
115  -- Send AXI response
116  axiSlaveWriteResponse(v.axiWriteSlave);
117  elsif axiWriteMaster.awaddr(3 downto 2) = 1 then
118  -- Set the RnW
119  v.RnW := axiWriteMaster.wdata(31);
120  -- Set the address bus
121  v.config.addr := axiWriteMaster.wdata(22 downto 0);
122  -- Next state
123  v.state := CMD_LOW_S;
124  else
125  -- Send AXI response
126  axiSlaveWriteResponse(v.axiWriteSlave, AXI_ERROR_RESP_G);
127  end if;
128  end if;
129  elsif (axiStatus.readEnable = '1') and (r.state = IDLE_S) then
130  -- Check for an out of 32 bit aligned address
131  axiReadResp := ite(axiReadMaster.araddr(1 downto 0) = "00", AXI_RESP_OK_C, AXI_ERROR_RESP_G);
132  -- Reset the register
133  v.axiReadSlave.rdata := (others => '0');
134  -- Check the read address
135  if axiReadMaster.araddr(3 downto 2) = 0 then
136  -- Get the write data bus
137  v.axiReadSlave.rdata(15 downto 0) := r.config.data;
138  elsif axiReadMaster.araddr(3 downto 2) = 1 then
139  -- Get the address bus
140  v.axiReadSlave.rdata(22 downto 0) := r.config.addr;
141  elsif axiReadMaster.araddr(3 downto 2) = 2 then
142  -- Get the read data bus
143  v.axiReadSlave.rdata(15 downto 0) := r.dataReg;
144  else
145  axiReadResp := AXI_ERROR_RESP_G;
146  end if;
147  -- Send AXI Response
148  axiSlaveReadResponse(v.axiReadSlave, axiReadResp);
149  end if;
150 
151  -- State Machine
152  case (r.state) is
153  ----------------------------------------------------------------------
154  when IDLE_S =>
155  v.config.ceL := '1';
156  v.config.oeL := '1';
157  v.config.weL := '1';
158  v.config.tristate := '1';
159  ----------------------------------------------------------------------
160  when CMD_LOW_S =>
161  v.config.ceL := '0';
162  v.config.oeL := '1';
163  v.config.weL := '0';
164  v.config.tristate := '0';
165  v.config.data := r.wrData(1);
166  -- Increment the counter
167  v.cnt := r.cnt + 1;
168  -- Check the counter
169  if r.cnt = MAX_CNT_C then
170  -- Reset the counter
171  v.cnt := 0;
172  -- Next state
173  v.state := CMD_HIGH_S;
174  end if;
175  ----------------------------------------------------------------------
176  when CMD_HIGH_S =>
177  v.config.ceL := '1';
178  v.config.oeL := '1';
179  v.config.weL := '1';
180  v.config.tristate := '0';
181  v.config.data := r.wrData(1);
182  -- Increment the counter
183  v.cnt := r.cnt + 1;
184  -- Check the counter
185  if r.cnt = MAX_CNT_C then
186  -- Reset the counter
187  v.cnt := 0;
188  -- Next state
189  v.state := WAIT_S;
190  end if;
191  ----------------------------------------------------------------------
192  when WAIT_S =>
193  v.config.ceL := '1';
194  v.config.oeL := '1';
195  v.config.weL := '1';
196  v.config.tristate := '1';
197  v.config.data := r.wrData(0);
198  -- Increment the counter
199  v.cnt := r.cnt + 1;
200  -- Check the counter
201  if r.cnt = MAX_CNT_C then
202  -- Reset the counter
203  v.cnt := 0;
204  -- Next state
205  v.state := DATA_LOW_S;
206  end if;
207  ----------------------------------------------------------------------
208  when DATA_LOW_S =>
209  v.config.ceL := '0';
210  v.config.oeL := not(r.RnW);
211  v.config.weL := r.RnW;
212  v.config.tristate := r.RnW;
213  v.config.data := r.wrData(0);
214  -- Increment the counter
215  v.cnt := r.cnt + 1;
216  -- Check the counter
217  if r.cnt = MAX_CNT_C then
218  -- Reset the counter
219  v.cnt := 0;
220  -- Latch the data bus value
221  v.dataReg := status.data;
222  -- Next state
223  v.state := DATA_HIGH_S;
224  end if;
225  ----------------------------------------------------------------------
226  when DATA_HIGH_S =>
227  v.config.ceL := '1';
228  v.config.oeL := '1';
229  v.config.weL := '1';
230  v.config.tristate := r.RnW;
231  v.config.data := r.wrData(0);
232  -- Increment the counter
233  v.cnt := r.cnt + 1;
234  -- Check the counter
235  if r.cnt = MAX_CNT_C then
236  -- Reset the counter
237  v.cnt := 0;
238  -- Send AXI Response
239  axiSlaveReadResponse(v.axiReadSlave);
240  -- Next state
241  v.state := IDLE_S;
242  end if;
243  ----------------------------------------------------------------------
244  end case;
245 
246  -- Synchronous Reset
247  if axiRst = '1' then
248  v := REG_INIT_C;
249  end if;
250 
251  -- Register the variable for next clock cycle
252  rin <= v;
253 
254  -- Outputs
257 
258  config <= r.config;
259 
260  end process comb;
261 
262  seq : process (axiClk) is
263  begin
264  if rising_edge(axiClk) then
265  r <= rin after TPD_G;
266  end if;
267  end process seq;
268 
269 end rtl;
TPD_Gtime := 1 ns
AxiLiteWriteMasterType
Definition: AxiLitePkg.vhd:111
std_logic sl
Definition: StdRtlPkg.vhd:28
slv( 31 downto 0) rdata
Definition: AxiLitePkg.vhd:89
out axiReadSlaveAxiLiteReadSlaveType
in axiWriteMasterAxiLiteWriteMasterType
in statusAxiXcf128StatusType
in axiReadMasterAxiLiteReadMasterType
out configAxiXcf128ConfigType
slv( 31 downto 0) wdata
Definition: AxiLitePkg.vhd:117
AxiLiteStatusType axiStatus
Definition: AxiLitePkg.vhd:183
AXI_ERROR_RESP_Gslv( 1 downto 0) := AXI_RESP_SLVERR_C
slv( 1 downto 0) := "10" AXI_RESP_SLVERR_C
Definition: AxiLitePkg.vhd:36
slv( 15 downto 0) data
AxiXcf128ConfigType :=( '1', '1', '1', '0',( others => '1'), '1',( others => '1')) AXI_XCF128_CONFIG_INIT_C
AxiLiteReadMasterType
Definition: AxiLitePkg.vhd:59
slv( 31 downto 0) awaddr
Definition: AxiLitePkg.vhd:113
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:95
array(natural range <> ) of slv( 15 downto 0) Slv16Array
Definition: StdRtlPkg.vhd:395
out axiWriteSlaveAxiLiteWriteSlaveType
AxiLiteReadSlaveType
Definition: AxiLitePkg.vhd:85
slv( 22 downto 0) addr
slv( 1 downto 0) := "00" AXI_RESP_OK_C
Definition: AxiLitePkg.vhd:31
slv( 31 downto 0) araddr
Definition: AxiLitePkg.vhd:61
_library_ ieeeieee
AxiLiteWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0') AXI_LITE_WRITE_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:156
AXI_CLK_FREQ_Greal := 200.0E+6
std_logic_vector slv
Definition: StdRtlPkg.vhd:29