SURF  1.0
AxiDac7654Reg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : AxiDac7654Reg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-09-24
5 -- Last update: 2014-09-25
6 -------------------------------------------------------------------------------
7 -- Description: AXI-Lite Register Access 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.AxiLitePkg.all;
25 use work.AxiDac7654Pkg.all;
26 
27 --! @see entity
28  --! @ingroup devices_Ti_dac7654
29 entity AxiDac7654Reg is
30  generic (
31  TPD_G : time := 1 ns;
32  STATUS_CNT_WIDTH_G : natural range 1 to 32 := 32;
34  port (
35  -- AXI-Lite Register Interface (axiClk domain)
36  axiClk : in sl;
37  axiRst : in sl;
42  -- Register Inputs/Outputs (axiClk domain)
44  config : out AxiDac7654ConfigType);
45 end AxiDac7654Reg;
46 
47 architecture rtl of AxiDac7654Reg is
48 
49  type StateType is (
50  IDLE_S,
51  REQ_S,
52  ACK_S);
53 
54  type RegType is record
55  config : AxiDac7654ConfigType;
56  state : StateType;
59  end record RegType;
60 
61  constant REG_INIT_C : RegType := (
63  IDLE_S,
66 
67  signal r : RegType := REG_INIT_C;
68  signal rin : RegType;
69 
71 
72 begin
73 
74  -------------------------------
75  -- Configuration Register
76  -------------------------------
77  comb : process (axiReadMaster, axiRst, axiWriteMaster, r, syncIn) is
78  variable v : RegType;
79  variable axiStatus : AxiLiteStatusType;
80  variable axiWriteResp : slv(1 downto 0);
81  variable axiReadResp : slv(1 downto 0);
82  begin
83  -- Latch the current value
84  v := r;
85 
86  -- Determine the transaction type
88 
89  if (axiStatus.writeEnable = '1') and (r.state = IDLE_S) then
90  -- Check for an out of 32 bit aligned address
91  axiWriteResp := ite(axiWriteMaster.awaddr(1 downto 0) = "00", AXI_RESP_OK_C, AXI_ERROR_RESP_G);
92  -- Decode address and perform write
93  case (axiWriteMaster.awaddr(9 downto 2)) is
94  when x"80" =>
95  if axiWriteMaster.wdata(15 downto 0) /= r.config.spi.data(0) then
96  v.config.spi.data(0) := axiWriteMaster.wdata(15 downto 0);
97  v.state := REQ_S;
98  end if;
99  when x"81" =>
100  if axiWriteMaster.wdata(15 downto 0) /= r.config.spi.data(1) then
101  v.config.spi.data(1) := axiWriteMaster.wdata(15 downto 0);
102  v.state := REQ_S;
103  end if;
104  when x"82" =>
105  if axiWriteMaster.wdata(15 downto 0) /= r.config.spi.data(2) then
106  v.config.spi.data(2) := axiWriteMaster.wdata(15 downto 0);
107  v.state := REQ_S;
108  end if;
109  when x"83" =>
110  if axiWriteMaster.wdata(15 downto 0) /= r.config.spi.data(3) then
111  v.config.spi.data(3) := axiWriteMaster.wdata(15 downto 0);
112  v.state := REQ_S;
113  end if;
114  when others =>
115  axiWriteResp := AXI_ERROR_RESP_G;
116  end case;
117  -- Send AXI response
118  axiSlaveWriteResponse(v.axiWriteSlave, axiWriteResp);
119  elsif (axiStatus.readEnable = '1') and (r.state = IDLE_S) then
120  -- Check for an out of 32 bit aligned address
121  axiReadResp := ite(axiReadMaster.araddr(1 downto 0) = "00", AXI_RESP_OK_C, AXI_ERROR_RESP_G);
122  -- Reset the register
123  v.axiReadSlave.rdata := (others => '0');
124  -- Decode address and assign read data
125  case (axiReadMaster.araddr(9 downto 2)) is
126  when x"80" =>
127  v.axiReadSlave.rdata(15 downto 0) := r.config.spi.data(0);
128  when x"81" =>
129  v.axiReadSlave.rdata(15 downto 0) := r.config.spi.data(1);
130  when x"82" =>
131  v.axiReadSlave.rdata(15 downto 0) := r.config.spi.data(2);
132  when x"83" =>
133  v.axiReadSlave.rdata(15 downto 0) := r.config.spi.data(3);
134  when others =>
135  axiReadResp := AXI_ERROR_RESP_G;
136  end case;
137  -- Send AXI Response
138  axiSlaveReadResponse(v.axiReadSlave, axiReadResp);
139  end if;
140 
141  -- State Machine
142  case (r.state) is
143  ----------------------------------------------------------------------
144  when IDLE_S =>
145  null;
146  ----------------------------------------------------------------------
147  when REQ_S =>
148  -- Assert the flag
149  v.config.spi.req := '1';
150  -- Next State
151  v.state := ACK_S;
152  ----------------------------------------------------------------------
153  when ACK_S =>
154  -- De-assert the flag
155  v.config.spi.req := '0';
156  -- Check for ACK strobe
157  if syncIn.spi.ack = '1' then
158  -- Next State
159  v.state := IDLE_S;
160  end if;
161  ----------------------------------------------------------------------
162  end case;
163 
164  -- Synchronous Reset
165  if axiRst = '1' then
166  v := REG_INIT_C;
167  end if;
168 
169  -- Register the variable for next clock cycle
170  rin <= v;
171 
172  -- Outputs
175 
176  end process comb;
177 
178  seq : process (axiClk) is
179  begin
180  if rising_edge(axiClk) then
181  r <= rin after TPD_G;
182  end if;
183  end process seq;
184 
185  -------------------------------
186  -- Synchronization: Outputs
187  -------------------------------
188  config.spi <= r.config.spi;
189 
190  -------------------------------
191  -- Synchronization: Inputs
192  -------------------------------
193  syncIn.spi <= status.spi;
194 
195 end rtl;
AxiLiteWriteMasterType
Definition: AxiLitePkg.vhd:111
std_logic sl
Definition: StdRtlPkg.vhd:28
STATUS_CNT_WIDTH_Gnatural range 1 to 32:= 32
_library_ ieeeieee
slv( 31 downto 0) rdata
Definition: AxiLitePkg.vhd:89
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
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:95
AXI_ERROR_RESP_Gslv( 1 downto 0) := AXI_RESP_SLVERR_C
in axiReadMasterAxiLiteReadMasterType
AxiLiteReadSlaveType
Definition: AxiLitePkg.vhd:85
TPD_Gtime := 1 ns
slv( 1 downto 0) := "00" AXI_RESP_OK_C
Definition: AxiLitePkg.vhd:31
slv( 31 downto 0) araddr
Definition: AxiLitePkg.vhd:61
out configAxiDac7654ConfigType
out axiWriteSlaveAxiLiteWriteSlaveType
in axiWriteMasterAxiLiteWriteMasterType
AxiDac7654SpiOutType spi
in statusAxiDac7654StatusType
AxiLiteWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0') AXI_LITE_WRITE_SLAVE_INIT_C
Definition: AxiLitePkg.vhd:156
out axiReadSlaveAxiLiteReadSlaveType
AxiDac7654StatusType :=(spi => AXI_DAC7654_SPI_OUT_INIT_C) AXI_DAC7654_STATUS_INIT_C
std_logic_vector slv
Definition: StdRtlPkg.vhd:29
Slv16Array( 0 to 3) data
AxiDac7654ConfigType :=(spi => AXI_DAC7654_SPI_IN_INIT_C) AXI_DAC7654_CONFIG_INIT_C