1 ------------------------------------------------------------------------------- 2 -- File : AxiSpiMaster.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2015-01-12 5 -- Last update: 2017-07-10 6 ------------------------------------------------------------------------------- 7 -- Description: Axi lite interface for a single chip "generic SPI master" 8 -- For multiple chips on single bus connect multiple cores 9 -- to multiple AXI crossbar slaves and use Chip select outputs 10 -- (coreCsb) to multiplex select the addressed outputs (coreSDout and 12 -- The coreCsb is active low. And active only if the corresponding 13 -- Axi Crossbar Slave is addressed. 14 -- DATA_SIZE_G - Corresponds to total read or write command size (not just data size). 15 -- Example: DATA_SIZE_G = 24 16 -- 1-bit command, 15-bit address word and 8-bit data 17 ------------------------------------------------------------------------------- 18 -- This file is part of 'SLAC Firmware Standard Library'. 19 -- It is subject to the license terms in the LICENSE.txt file found in the 20 -- top-level directory of this distribution and at: 21 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html. 22 -- No part of 'SLAC Firmware Standard Library', including this file, 23 -- may be copied, modified, propagated, or distributed except according to 24 -- the terms contained in the LICENSE.txt file. 25 ------------------------------------------------------------------------------- 28 use ieee.std_logic_1164.
all;
29 use ieee.std_logic_arith.
all;
30 use ieee.std_logic_unsigned.
all;
39 --! @ingroup protocols_spi 46 MODE_G : := "RW";
-- Or "WO" (write only), "RO" (read only) 65 coreCsb : out sl;
-- coreCsb is for legacy firmware without SPI_NUM_CHIPS_G generic 68 end entity AxiSpiMaster;
76 signal rdData : slv(PACKET_SIZE_C-1 downto 0);
79 type StateType is (WAIT_AXI_TXN_S, WAIT_CYCLE_S, WAIT_SPI_TXN_DONE_S);
82 type RegType is record 87 wrData : slv(PACKET_SIZE_C-1 downto 0);
88 chipSel : slv(CHIP_BITS_C-1 downto 0);
92 constant REG_INIT_C : RegType := ( 93 state => WAIT_AXI_TXN_S, 96 wrData => (others => '0'), 97 chipSel => (others => '0'), 100 signal r : RegType := REG_INIT_C;
101 signal rin : RegType;
107 variable v : RegType;
115 when WAIT_AXI_TXN_S => 122 -- No write bit when mode is write-only 124 v.wrData(PACKET_SIZE_C-1) := '0';
127 -- Address (make sure that the assigned AXI address in the crossbar is big enough) 136 v.state := WAIT_CYCLE_S;
145 -- No read bit when mode is read-only 147 v.wrData(PACKET_SIZE_C-1) := '1';
153 -- Setting data segment to all 1 allows it to float so that slave side can drive it 154 -- in shared sdio configurations 155 v.wrData(DATA_SIZE_G-1 downto 0) := (others => '1');
158 -- If there are no address bits, readback will reuse the last wrData when shifting 161 v.state := WAIT_CYCLE_S;
166 -- Wait for rdEn to drop 169 v.state := WAIT_SPI_TXN_DONE_S;
172 when WAIT_SPI_TXN_DONE_S => 175 v.state := WAIT_AXI_TXN_S;
176 if (r.wrData(PACKET_SIZE_C-1) = '0') then 190 -- Check if single access 192 v.chipSel := (others => '0');
208 if (rising_edge(axiClk)) then 209 r <= rin after TPD_G;
238 end architecture rtl;
out axiReadSlaveAxiLiteReadSlaveType
in axiWriteMasterAxiLiteWriteMasterType
out spiCsLslv( NUM_CHIPS_G- 1 downto 0)
in wrDataslv( DATA_SIZE_G- 1 downto 0)
in axiReadMasterAxiLiteReadMasterType
CLK_PERIOD_Greal := 6.4E-9
out rdDataslv( DATA_SIZE_G- 1 downto 0)
SPI_NUM_CHIPS_Gpositive := 1
SPI_SCLK_PERIOD_Greal := 1.0E-6
AXI_ERROR_RESP_Gslv( 1 downto 0) := AXI_RESP_DECERR_C
AxiLiteStatusType axiStatus
in chipSelslv( log2(NUM_CHIPS_G )- 1 downto 0)
slv( 1 downto 0) := "11" AXI_RESP_DECERR_C
NUM_CHIPS_Gpositive range 1 to 8:= 4
ADDRESS_SIZE_Gnatural := 15
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
SPI_SCLK_PERIOD_Greal := 100.0E-6
out coreMCsbslv( SPI_NUM_CHIPS_G- 1 downto 0)
out axiWriteSlaveAxiLiteWriteSlaveType
CLK_PERIOD_Greal := 8.0E-9
AxiLiteWriteSlaveType :=(awready => '0',wready => '0',bresp =>( others => '0'),bvalid => '0') AXI_LITE_WRITE_SLAVE_INIT_C