1 ------------------------------------------------------------------------------- 2 -- File : AxiMicronN25QReg.vhd 3 -- Company : SLAC National Accelerator Laboratory 4 -- Created : 2014-04-25 5 -- Last update: 2017-06-14 6 ------------------------------------------------------------------------------- 7 -- Description: MicronN25Q 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 ------------------------------------------------------------------------------- 19 use ieee.std_logic_1164.
all;
20 use ieee.std_logic_unsigned.
all;
21 use ieee.std_logic_arith.
all;
27 --! @ingroup devices_Micron_n25q 41 -- AXI-Lite Register Interface 54 constant SCK_HALF_PERIOD_C : := (getTimeRatio(AXI_CLK_FREQ_G, DOUBLE_SCK_FREQ_C))-1;
55 constant MIN_CS_WIDTH_C : := (getTimeRatio(AXI_CLK_FREQ_G, 2.
0E+7));
56 constant MAX_SCK_CNT_C : := ite((SCK_HALF_PERIOD_C > MIN_CS_WIDTH_C), SCK_HALF_PERIOD_C, MIN_CS_WIDTH_C);
58 constant PRESET_32BIT_ADDR_C : slv(8 downto 0) := "111111011";
59 constant PRESET_24BIT_ADDR_C : slv(8 downto 0) := "111111100";
70 type RegType is record 71 test : slv(31 downto 0);
72 wrData : slv(31 downto 0);
73 addr : slv(31 downto 0);
75 cmd : slv(7 downto 0);
76 status : slv(7 downto 0);
81 cnt : slv(8 downto 0);
82 waddr : slv(8 downto 0);
83 raddr : slv(8 downto 0);
84 xferSize : slv(8 downto 0);
85 ramDin : slv(7 downto 0);
90 sckCnt : range 0 to MAX_SCK_CNT_C;
91 bitPntr : range 0 to 7;
99 constant REG_INIT_C : RegType := ( 100 test => (others => '0'), 101 wrData => (others => '0'), 102 addr => (others => '0'), 103 addr32BitMode => '0', 104 cmd => (others => '0'), 105 status => (others => '0'), 110 cnt => (others => '0'), 111 waddr => (others => '0'), 112 raddr => (others => '0'), 113 xferSize => (others => '0'), 114 ramDin => (others => '0'), 127 signal r : RegType := REG_INIT_C;
128 signal rin : RegType;
130 signal ramDout : slv(7 downto 0);
132 -- attribute dont_touch : string; 133 -- attribute dont_touch of r : signal is "true"; 137 ------------------------------- 138 -- Configuration Register 139 ------------------------------- 141 variable v : RegType;
143 variable axiWriteResp : slv(1 downto 0);
144 variable axiReadResp : slv(1 downto 0);
146 -- Latch the current value 149 -- Reset the strobing signals 158 -- Determine the transaction type 163 ---------------------------------------------------------------------- 165 -- Reset the signals in IDLE state 168 v.cnt := (others => '0');
169 v.waddr := (others => '0');
170 v.raddr := (others => '0');
171 -- Check for a write request 174 -- Latch the write data and write address 179 v.state := WORD_WRITE_S;
181 -- Decode address and perform write 193 -- Check address mode 194 if r.addr32BitMode = '1' then 195 -- 32-bit Address Mode 196 v.raddr := PRESET_32BIT_ADDR_C;
198 -- 24-bit Address Mode 199 v.raddr := PRESET_24BIT_ADDR_C;
202 v.state := SCK_LOW_S;
207 -- Send AXI-Lite response 209 -- Check for a read request 212 -- Set the read address 217 v.state := WORD_READ_S;
219 -- Reset the register 221 -- Decode address and assign read data 234 -- Send AXI-Lite Response 238 ---------------------------------------------------------------------- 240 -- Write a byte to the RAM 243 v.ramDin := r.wrData(31 downto 24);
245 v.wrData(31 downto 8) := r.wrData(23 downto 0);
246 v.wrData(7 downto 0) := x"00";
247 -- Increment the counters 248 v.raddr := r.raddr + 1;
250 -- Check the counter size 253 v.cnt := (others => '0');
257 ---------------------------------------------------------------------- 259 -- Check if the RAM data is updated 266 -- Increment the counters 267 v.raddr := r.raddr + 1;
269 -- Check the counter size 272 v.cnt := (others => '0');
274 v.state := WORD_READ_HOLD_S;
277 ---------------------------------------------------------------------- 278 when WORD_READ_HOLD_S => 279 -- Send AXI-Lite Response 281 -- Wait for read request to complete 283 -- Reset the counters 284 v.waddr := (others => '0');
285 v.raddr := (others => '0');
289 ---------------------------------------------------------------------- 291 -- Assert the chip select 293 -- Serial Clock low phase 295 -- Check if the RAM data is updated 297 -- 32-bit Address Mode 298 if r.addr32BitMode = '1' then 300 v.mosi := r.cmd(7-r.bitPntr);
310 v.mosi := ramDout(7-r.bitPntr);
312 -- 24-bit Address Mode 315 v.mosi := r.cmd(7-r.bitPntr);
323 v.mosi := ramDout(7-r.bitPntr);
326 -- Increment the counter 327 v.sckCnt := r.sckCnt + 1;
328 -- Check the counter value 329 if r.sckCnt = SCK_HALF_PERIOD_C then 333 v.state := SCK_HIGH_S;
336 ---------------------------------------------------------------------- 338 -- Serial Clock high phase 340 -- Increment the counter 341 v.sckCnt := r.sckCnt + 1;
342 -- Check the counter value 343 if r.sckCnt = SCK_HALF_PERIOD_C then 344 -- Set the default state 345 v.state := SCK_LOW_S;
348 -- Update the ram data bus 349 v.ramDin(7 downto 1) := r.ramDin(6 downto 0);
351 -- Increment the counter 352 v.bitPntr := r.bitPntr + 1;
353 -- Check the counter value 354 if r.bitPntr = 7 then 360 -- Increment the counters 361 v.raddr := r.raddr + 1;
365 -- Check the xfer size 366 if r.cnt = r.xferSize then 368 v.cnt := (others => '0');
370 v.state := MIN_CS_WIDTH_S;
374 ---------------------------------------------------------------------- 375 when MIN_CS_WIDTH_S => 376 -- De-assert the chip select 378 -- Serial Clock low phase 380 -- Increment the counter 381 v.sckCnt := r.sckCnt + 1;
383 if r.sckCnt = MIN_CS_WIDTH_C then 384 -- Latch the last write value 385 v.status := r.ramDin;
391 ---------------------------------------------------------------------- 399 -- Register the variable for next clock cycle 414 if rising_edge(axiClk) then 415 r <= rin after TPD_G;
in addrbslv( ADDR_WIDTH_G- 1 downto 0) :=( others => '0')
out doutbslv( DATA_WIDTH_G- 1 downto 0)
DATA_WIDTH_Ginteger range 1 to ( 2** 24):= 16
out axiWriteSlaveAxiLiteWriteSlaveType
AxiLiteStatusType axiStatus
SPI_CLK_FREQ_Greal := 25.0E+6
AXI_CLK_FREQ_Greal := 200.0E+6
slv( 1 downto 0) := "10" AXI_RESP_SLVERR_C
in axiReadMasterAxiLiteReadMasterType
ADDR_WIDTH_Ginteger range 1 to ( 2** 24):= 4
in axiWriteMasterAxiLiteWriteMasterType
in addraslv( ADDR_WIDTH_G- 1 downto 0) :=( others => '0')
AxiLiteReadSlaveType :=(arready => '0',rdata =>( others => '0'),rresp =>( others => '0'),rvalid => '0') AXI_LITE_READ_SLAVE_INIT_C
out axiReadSlaveAxiLiteReadSlaveType
slv( 1 downto 0) := "00" AXI_RESP_OK_C
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
MEM_ADDR_MASK_Gslv( 31 downto 0) := x"00000000"
in dinaslv( DATA_WIDTH_G- 1 downto 0) :=( others => '0')