Advertisement
Guest User

Untitled

a guest
Aug 17th, 2018
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 24.91 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Engineer: Mike Field <[email protected]>
  3. --
  4. -- Create Date:    14:09:12 09/15/2013
  5. -- Module Name:    SDRAM_Controller - Behavioral
  6. -- Description:    Simple SDRAM controller for a Micron 48LC16M16A2-7E
  7. --                 or Micron 48LC4M16A2-7E @ 100MHz      
  8. -- Revision:
  9. -- Revision 0.1 - Initial version
  10. -- Revision 0.2 - Removed second clock signal that isn't needed.
  11. -- Revision 0.3 - Added back-to-back reads and writes.
  12. -- Revision 0.4 - Allow refeshes to be delayed till next PRECHARGE is issued,
  13. --                Unless they get really, really delayed. If a delay occurs multiple
  14. --                refreshes might get pushed out, but it will have avioded about
  15. --                50% of the refresh overhead
  16. -- Revision 0.5 - Add more paramaters to the design, allowing it to work for both the
  17. --                Papilio Pro and Logi-Pi
  18. -- Revision 0.6 - Fixed bugs in back-to-back reads (thanks Scotty!)
  19. --
  20. -- Worst case performance (single accesses to different rows or banks) is:
  21. -- Writes 16 cycles = 6,250,000 writes/sec = 25.0MB/s (excluding refresh overhead)
  22. -- Reads  17 cycles = 5,882,352 reads/sec  = 23.5MB/s (excluding refresh overhead)
  23. --
  24. -- For 1:1 mixed reads and writes into the same row it is around 88MB/s
  25. -- For reads or wries to the same it is can be as high as 184MB/s
  26. ----------------------------------------------------------------------------------
  27. library IEEE;
  28. use IEEE.STD_LOGIC_1164.ALL;
  29. use IEEE.NUMERIC_STD.ALL;
  30.  
  31.  
  32. entity SDRAM_Controller is
  33.     generic (
  34.       constant sdram_address_width : natural;
  35.       constant sdram_column_bits   : natural;
  36.       constant sdram_startup_cycles: natural; -- 100us, plus a little more
  37.       constant cycles_per_refresh  : natural;
  38.       constant HIGH_Z              : std_logic := '0'
  39.     );
  40.     Port ( clk           : in  STD_LOGIC;
  41.            reset         : in  STD_LOGIC;
  42.            
  43.            -- Interface to issue reads or write data
  44.            cmd_ready         : out STD_LOGIC;                     -- '1' when a new command will be acted on
  45.            cmd_enable        : in  STD_LOGIC;                     -- Set to '1' to issue new command (only acted on when cmd_read = '1')
  46.            cmd_wr            : in  STD_LOGIC;                     -- Is this a write?
  47.            cmd_address       : in  STD_LOGIC_VECTOR(sdram_address_width-1 downto 0); -- address to read/write
  48.            cmd_byte_enable   : in  STD_LOGIC_VECTOR(3 downto 0);  -- byte masks for the write command
  49.            cmd_data_in       : in  STD_LOGIC_VECTOR(15 downto 0); -- data for the write command
  50.            
  51.            data_out          : out STD_LOGIC_VECTOR(15 downto 0); -- word read from SDRAM
  52.            data_out_ready    : out STD_LOGIC;                     -- is new data ready?
  53.            
  54.            -- SDRAM signals
  55.            SDRAM_CLK     : out   STD_LOGIC;
  56.            SDRAM_CKE     : out   STD_LOGIC;
  57.            SDRAM_CS      : out   STD_LOGIC;
  58.            SDRAM_RAS     : out   STD_LOGIC;
  59.            SDRAM_CAS     : out   STD_LOGIC;
  60.            SDRAM_WE      : out   STD_LOGIC;
  61.            SDRAM_DQM     : out   STD_LOGIC_VECTOR( 1 downto 0);
  62.            SDRAM_ADDR    : out   STD_LOGIC_VECTOR(12 downto 0);
  63.            SDRAM_BA      : out   STD_LOGIC_VECTOR( 1 downto 0);
  64.            SDRAM_DATA    : inout STD_LOGIC_VECTOR(15 downto 0));
  65. end SDRAM_Controller;
  66.  
  67. architecture Behavioral of SDRAM_Controller is
  68.    -- From page 37 of MT48LC16M16A2 datasheet
  69.    -- Name (Function)       CS# RAS# CAS# WE# DQM  Addr    Data
  70.    -- COMMAND INHIBIT (NOP)  H   X    X    X   X     X       X
  71.    -- NO OPERATION (NOP)     L   H    H    H   X     X       X
  72.    -- ACTIVE                 L   L    H    H   X  Bank/row   X
  73.    -- READ                   L   H    L    H  L/H Bank/col   X
  74.    -- WRITE                  L   H    L    L  L/H Bank/col Valid
  75.    -- BURST TERMINATE        L   H    H    L   X     X     Active
  76.    -- PRECHARGE              L   L    H    L   X   Code      X
  77.    -- AUTO REFRESH           L   L    L    H   X     X       X
  78.    -- LOAD MODE REGISTER     L   L    L    L   X  Op-code    X
  79.    -- Write enable           X   X    X    X   L     X     Active
  80.    -- Write inhibit          X   X    X    X   H     X     High-Z
  81.  
  82.    -- Here are the commands mapped to constants  
  83.    constant CMD_UNSELECTED    : std_logic_vector(3 downto 0) := "1000";
  84.    constant CMD_NOP           : std_logic_vector(3 downto 0) := "0111";
  85.    constant CMD_ACTIVE        : std_logic_vector(3 downto 0) := "0011";
  86.    constant CMD_READ          : std_logic_vector(3 downto 0) := "0101";
  87.    constant CMD_WRITE         : std_logic_vector(3 downto 0) := "0100";
  88.    constant CMD_TERMINATE     : std_logic_vector(3 downto 0) := "0110";
  89.    constant CMD_PRECHARGE     : std_logic_vector(3 downto 0) := "0010";
  90.    constant CMD_REFRESH       : std_logic_vector(3 downto 0) := "0001";
  91.    constant CMD_LOAD_MODE_REG : std_logic_vector(3 downto 0) := "0000";
  92.  
  93.    constant MODE_REG          : std_logic_vector(12 downto 0) :=
  94.     -- Reserved, wr bust, OpMode, CAS Latency (2), Burst Type, Burst Length (2)
  95.          "000" &   "0"  &  "00"  &    "010"      &     "0"    &   "000";
  96.  
  97.    signal iob_command     : std_logic_vector( 3 downto 0) := CMD_NOP;
  98.    signal iob_address     : std_logic_vector(12 downto 0) := (others => '0');
  99.    signal iob_data        : std_logic_vector(15 downto 0) := (others => '0');
  100.    signal iob_dqm         : std_logic_vector( 1 downto 0) := (others => '0');
  101.    signal iob_cke         : std_logic := '0';
  102.    signal iob_bank        : std_logic_vector( 1 downto 0) := (others => '0');
  103.    
  104.    attribute IOB: string;
  105.    attribute IOB of iob_command: signal is "true";
  106.    attribute IOB of iob_address: signal is "true";
  107.    attribute IOB of iob_dqm    : signal is "true";
  108.    attribute IOB of iob_cke    : signal is "true";
  109.    attribute IOB of iob_bank   : signal is "true";
  110.    attribute IOB of iob_data   : signal is "true";
  111.    
  112.    signal iob_data_next      : std_logic_vector(15 downto 0) := (others => '0');
  113.    signal captured_data      : std_logic_vector(15 downto 0) := (others => '0');
  114.    signal captured_data_last : std_logic_vector(15 downto 0) := (others => '0');
  115.    signal sdram_din          : std_logic_vector(15 downto 0);
  116.    attribute IOB of captured_data : signal is "true";
  117.    
  118.    type fsm_state is (s_startup,
  119.                       s_idle_in_8, s_idle_in_7, s_idle_in_6, s_idle_in_5, s_idle_in_4,   s_idle_in_3, s_idle_in_2, s_idle_in_1,
  120.                       s_idle,
  121.                       s_open_in_2, s_open_in_1,
  122.                       s_write_1, s_write_2, s_write_3,
  123.                       s_read_1,  s_read_2,  s_read_3,  s_read_4,  
  124.                       s_precharge
  125.                       );
  126.  
  127.    signal state              : fsm_state := s_startup;
  128.    attribute FSM_ENCODING : string;
  129.    attribute FSM_ENCODING of state : signal is "ONE-HOT";
  130.    
  131.    -- dual purpose counter, it counts up during the startup phase, then is used to trigger refreshes.
  132.    constant startup_refresh_max   : unsigned(15 downto 0) := (others => '1');  
  133.    signal   startup_refresh_count : unsigned(15 downto 0) := startup_refresh_max-to_unsigned(sdram_startup_cycles,16);
  134.  
  135.    -- logic to decide when to refresh
  136.    signal pending_refresh : std_logic := '0';
  137.    signal forcing_refresh : std_logic := '0';
  138.  
  139.    -- The incoming address is split into these three values
  140.    signal addr_row         : std_logic_vector(12 downto 0) := (others => '0');
  141.    signal addr_col         : std_logic_vector(12 downto 0) := (others => '0');
  142.    signal addr_bank        : std_logic_vector( 1 downto 0) := (others => '0');
  143.    
  144.    signal dqm_sr           : std_logic_vector( 3 downto 0) := (others => '1'); -- an extra two bits in case CAS=3
  145.    
  146.    -- signals to hold the requested transaction before it is completed
  147.    signal save_wr          : std_logic := '0';
  148.    signal save_row         : std_logic_vector(12 downto 0);
  149.    signal save_bank        : std_logic_vector( 1 downto 0);
  150.    signal save_col         : std_logic_vector(12 downto 0);
  151.    signal save_data_in     : std_logic_vector(15 downto 0);
  152.    signal save_byte_enable : std_logic_vector( 3 downto 0);
  153.    
  154.    -- control when new transactions are accepted
  155.    signal ready_for_new    : std_logic := '0';
  156.    signal got_transaction  : std_logic := '0';
  157.    
  158.    signal can_back_to_back : std_logic := '0';
  159.  
  160.    -- signal to control the Hi-Z state of the DQ bus
  161.    signal iob_dq_hiz       : std_logic := HIGH_Z;
  162.  
  163.    -- signals for when to read the data off of the bus
  164.    -- signal data_ready_delay : std_logic_vector( 4 downto 0);  
  165.    
  166.    signal data_ready_delay : std_logic_vector( 3 downto 0);  
  167.    
  168.    -- bit indexes used when splitting the address into row/colum/bank.
  169.    constant start_of_col  : natural := 0;
  170.    constant end_of_col    : natural := sdram_column_bits-1;
  171.    constant start_of_row  : natural := sdram_column_bits;
  172.    constant end_of_row    : natural := sdram_address_width-3;
  173.    constant start_of_bank : natural := sdram_address_width-2;
  174.    constant end_of_bank   : natural := sdram_address_width-1;
  175.    constant prefresh_cmd  : natural := 10;
  176.    
  177.     component IOBUF
  178.         port(
  179.             datain      : IN STD_LOGIC_VECTOR (0 DOWNTO 0);
  180.         oe      : IN STD_LOGIC_VECTOR (0 DOWNTO 0);
  181.         dataio      : INOUT STD_LOGIC_VECTOR (0 DOWNTO 0);
  182.         dataout     : OUT STD_LOGIC_VECTOR (0 DOWNTO 0)
  183.         );
  184.     end component;
  185.    
  186.     component shifted_pll
  187.         Port(
  188.             inclk0  : in std_logic;
  189.             c0          : out std_logic
  190.         );
  191.     end component;
  192.    
  193. begin
  194.  
  195.    -- Indicate the need to refresh when the counter is 2048,
  196.    -- Force a refresh when the counter is 4096 - (if a refresh is forced,
  197.    -- multiple refresshes will be forced until the counter is below 2048
  198.    pending_refresh <= startup_refresh_count(11);
  199.    forcing_refresh <= startup_refresh_count(12);
  200.  
  201.    -- tell the outside world when we can accept a new transaction;
  202.    cmd_ready <= ready_for_new;
  203.    ----------------------------------------------------------------------------
  204.    -- Seperate the address into row / bank / address
  205.    ----------------------------------------------------------------------------
  206.    addr_row(end_of_row-start_of_row downto 0) <= cmd_address(end_of_row  downto start_of_row);       -- 12:0 <=  22:10
  207.    addr_bank                                  <= cmd_address(end_of_bank downto start_of_bank);      -- 1:0  <=  9:8
  208.    addr_col(sdram_column_bits-1 downto 0)     <= cmd_address(end_of_col  downto start_of_col); -- 8:0  <=  7:0 & '0'
  209.  
  210.    -----------------------------------------------
  211.    --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  212.    --!! Ensure that all outputs are registered. !!
  213.    --!! Check the pinout report to be sure      !!
  214.    --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  215.    -----------------------------------------------
  216.    sdram_cke  <= iob_cke;
  217.    sdram_CS   <= iob_command(3);
  218.    sdram_RAS  <= iob_command(2);
  219.    sdram_CAS  <= iob_command(1);
  220.    sdram_WE   <= iob_command(0);
  221.    sdram_dqm  <= iob_dqm;
  222.    sdram_ba   <= iob_bank;
  223.    sdram_addr <= iob_address;
  224.    
  225.    ---------------------------------------------------------------
  226.    -- Explicitly set up the tristate I/O buffers on the DQ signals
  227.    ---------------------------------------------------------------
  228. iob_dq_g: for i in 0 to 15 generate
  229. begin
  230.     IOBUF_inst : IOBUF PORT MAP (
  231.         datain(0)    => iob_data(i),
  232.         oe(0)    => iob_dq_hiz,
  233.         dataio(0)    => SDRAM_DATA(i),
  234.         dataout(0)   => sdram_din(i)
  235.     );
  236. end generate;
  237.  
  238. shifted_pll_inst : shifted_pll PORT MAP (
  239.         inclk0   => clk,
  240.         c0   => SDRAM_CLK
  241.   );
  242.  
  243. capture_proc: process(clk)
  244.    begin
  245.      if rising_edge(clk) then
  246.          captured_data      <= sdram_din;
  247.          
  248.       end if;
  249.    end process;
  250.  
  251. main_proc: process(clk)
  252.    begin
  253.       if rising_edge(clk) then
  254.      
  255.          ------------------------------------------------
  256.          -- Default state is to do nothing
  257.          ------------------------------------------------
  258.          iob_command     <= CMD_NOP;
  259.          iob_address     <= (others => '0');
  260.          iob_bank        <= (others => '0');
  261.  
  262.          ------------------------------------------------
  263.          -- countdown for initialisation & refresh
  264.          ------------------------------------------------
  265.          startup_refresh_count <= startup_refresh_count+1;
  266.                  
  267.          -------------------------------------------------------------------
  268.          -- It we are ready for a new tranasction and one is being presented
  269.          -- then accept it. Also remember what we are reading or writing,
  270.          -- and if it can be back-to-backed with the last transaction
  271.          -------------------------------------------------------------------
  272.          if ready_for_new = '1' and cmd_enable = '1' then
  273.             if save_bank = addr_bank and save_row = addr_row then
  274.                can_back_to_back <= '1';
  275.             else
  276.                can_back_to_back <= '0';
  277.             end if;
  278.             save_row         <= addr_row;
  279.             save_bank        <= addr_bank;
  280.             save_col         <= addr_col;
  281.             save_wr          <= cmd_wr;
  282.             save_data_in     <= cmd_data_in;
  283.             save_byte_enable <= cmd_byte_enable;
  284.             got_transaction  <= '1';
  285.             ready_for_new    <= '0';
  286.          end if;
  287.  
  288.          ------------------------------------------------
  289.          -- Handle the data coming back from the
  290.          -- SDRAM for the Read transaction
  291.          ------------------------------------------------
  292.          data_out_ready <= '0';
  293.          if data_ready_delay(0) = '1' then
  294.             data_out       <= captured_data;
  295.             data_out_ready <= '1';
  296.          end if;
  297.          
  298.          ----------------------------------------------------------------------------
  299.          -- update shift registers used to choose when to present data to/from memory
  300.          ----------------------------------------------------------------------------
  301.          data_ready_delay <= '0' & data_ready_delay(data_ready_delay'high downto 1);
  302.          iob_dqm          <= dqm_sr(1 downto 0);
  303.          dqm_sr           <= "11" & dqm_sr(dqm_sr'high downto 2);
  304.          
  305.          case state is
  306.             when s_startup =>
  307.                ------------------------------------------------------------------------
  308.                -- This is the initial startup state, where we wait for at least 100us
  309.                -- before starting the start sequence
  310.                --
  311.                -- The initialisation is sequence is
  312.                --  * de-assert SDRAM_CKE
  313.                --  * 100us wait,
  314.                --  * assert SDRAM_CKE
  315.                --  * wait at least one cycle,
  316.                --  * PRECHARGE
  317.                --  * wait 2 cycles
  318.                --  * REFRESH,
  319.                --  * tREF wait
  320.                --  * REFRESH,
  321.                --  * tREF wait
  322.                --  * LOAD_MODE_REG
  323.                --  * 2 cycles wait
  324.                ------------------------------------------------------------------------
  325.                iob_CKE <= '1';
  326.                
  327.                -- All the commands during the startup are NOPS, except these
  328.                if startup_refresh_count = startup_refresh_max-35 then      
  329.                   -- ensure all rows are closed
  330.                   iob_command     <= CMD_PRECHARGE;
  331.                   iob_address(prefresh_cmd) <= '1';  -- all banks
  332.                   iob_bank        <= (others => '0');
  333.                elsif startup_refresh_count = startup_refresh_max-27 then  
  334.                   -- these refreshes need to be at least tREF (66ns) apart
  335.                   iob_command     <= CMD_REFRESH;
  336.                elsif startup_refresh_count = startup_refresh_max-17 then
  337.                   iob_command     <= CMD_REFRESH;
  338.                elsif startup_refresh_count = startup_refresh_max-7 then    
  339.                   -- Now load the mode register
  340.                   iob_command     <= CMD_LOAD_MODE_REG;
  341.                   iob_address     <= MODE_REG;
  342.                end if;
  343.  
  344.                ------------------------------------------------------
  345.                -- if startup is coomplete then go into idle mode,
  346.                -- get prepared to accept a new command, and schedule
  347.                -- the first refresh cycle
  348.                ------------------------------------------------------
  349.                if startup_refresh_count = 0 then
  350.                   state           <= s_idle;
  351.                   ready_for_new   <= '1';
  352.                   got_transaction <= '0';
  353.                   startup_refresh_count <= to_unsigned(2048 - cycles_per_refresh+1,16);
  354.                end if;
  355.                
  356.             when s_idle_in_8 => state <= s_idle_in_7;
  357.             when s_idle_in_7 => state <= s_idle_in_6;
  358.             when s_idle_in_6 => state <= s_idle_in_5;
  359.             when s_idle_in_5 => state <= s_idle_in_4;
  360.             when s_idle_in_4 => state <= s_idle_in_3;
  361.             when s_idle_in_3 => state <= s_idle_in_2;
  362.             when s_idle_in_2 => state <= s_idle_in_1;
  363.             when s_idle_in_1 => state <= s_idle;
  364.  
  365.             when s_idle =>
  366.                -- Priority is to issue a refresh if one is outstanding
  367.                if pending_refresh = '1' or forcing_refresh = '1' then
  368.                  ------------------------------------------------------------------------
  369.                   -- Start the refresh cycle.
  370.                   -- This tasks tRFC (66ns), so 8 idle cycles are needed @ 133MHz
  371.                   ------------------------------------------------------------------------
  372.                   state       <= s_idle_in_8;
  373.                   iob_command <= CMD_REFRESH;
  374.                   startup_refresh_count <= startup_refresh_count - cycles_per_refresh+1;
  375.                elsif got_transaction = '1' then
  376.                   --------------------------------
  377.                   -- Start the read or write cycle.
  378.                   -- First task is to open the row
  379.                   --------------------------------
  380.                   state       <= s_open_in_2;
  381.                   iob_command <= CMD_ACTIVE;
  382.                   iob_address <= save_row;
  383.                   iob_bank    <= save_bank;
  384.                end if;              
  385.                
  386.             --------------------------------------------
  387.             -- Opening the row ready for reads or writes
  388.             --------------------------------------------
  389.             when s_open_in_2 => state <= s_open_in_1;
  390.  
  391.             when s_open_in_1 =>
  392.                -- still waiting for row to open
  393.                if save_wr = '1' then
  394.                   state       <= s_write_1;
  395.                   iob_dq_hiz  <= not HIGH_Z;
  396.                   iob_data    <= save_data_in(15 downto 0); -- get the DQ bus out of HiZ early
  397.                else
  398.                   iob_dq_hiz  <= HIGH_Z;
  399.                   state       <= s_read_1;
  400.                end if;
  401.                -- we will be ready for a new transaction next cycle!
  402.                ready_for_new   <= '1';
  403.                got_transaction <= '0';                  
  404.  
  405.             ----------------------------------
  406.             -- Processing the read transaction
  407.             ----------------------------------
  408.             when s_read_1 =>
  409.                state           <= s_read_2;
  410.                iob_command     <= CMD_READ;
  411.                iob_address     <= save_col;
  412.                iob_bank        <= save_bank;
  413.                iob_address(prefresh_cmd) <= '0'; -- A10 actually matters - it selects auto precharge
  414.                
  415.                -- Schedule reading the data values off the bus
  416.                data_ready_delay(data_ready_delay'high)   <= '1';
  417.                
  418.                -- Set the data masks to read all bytes
  419.                iob_dqm            <= (others => '0');
  420.                dqm_sr(1 downto 0) <= (others => '0');
  421.                
  422.             when s_read_2 =>
  423.                state <= s_read_3;
  424.                if forcing_refresh = '0' and got_transaction = '1' and can_back_to_back = '1' then
  425.                   if save_wr = '0' then
  426.                      state           <= s_read_1;
  427.                      ready_for_new   <= '1'; -- we will be ready for a new transaction next cycle!
  428.                      got_transaction <= '0';
  429.                   end if;
  430.                end if;
  431.                
  432.             when s_read_3 =>
  433.                state <= s_read_4;
  434.                if forcing_refresh = '0' and got_transaction = '1' and can_back_to_back = '1' then
  435.                   if save_wr = '0' then
  436.                      state           <= s_read_1;
  437.                      ready_for_new   <= '1'; -- we will be ready for a new transaction next cycle!
  438.                      got_transaction <= '0';
  439.                   end if;
  440.                end if;
  441.  
  442.             when s_read_4 =>
  443.                state <= s_precharge;
  444.                -- can we do back-to-back read?
  445.                if forcing_refresh = '0' and got_transaction = '1' and can_back_to_back = '1' then
  446.                   if save_wr = '0' then
  447.                      state           <= s_read_1;
  448.                      ready_for_new   <= '1'; -- we will be ready for a new transaction next cycle!
  449.                      got_transaction <= '0';
  450.                   else
  451.                      state <= s_open_in_2; -- we have to wait for the read data to come back before we swutch the bus into HiZ
  452.                   end if;
  453.                end if;
  454.  
  455.             ------------------------------------------------------------------
  456.             -- Processing the write transaction
  457.             -------------------------------------------------------------------
  458.             when s_write_1 =>
  459.                state              <= s_write_2;
  460.                iob_command        <= CMD_WRITE;
  461.                iob_address        <= save_col;
  462.                iob_address(prefresh_cmd)    <= '0'; -- A10 actually matters - it selects auto precharge
  463.                iob_bank           <= save_bank;
  464.                iob_dqm            <= NOT save_byte_enable(1 downto 0);    
  465.                dqm_sr(1 downto 0) <= NOT save_byte_enable(3 downto 2);    
  466.                iob_data           <= save_data_in(15 downto 0);
  467.                --iob_data_next      <= save_data_in(15 downto 16);
  468.                
  469.             when s_write_2 =>
  470.                state           <= s_write_3;
  471.                -- iob_data        <= iob_data_next;
  472.                -- can we do a back-to-back write?
  473.                if forcing_refresh = '0' and got_transaction = '1' and can_back_to_back = '1' then
  474.                   if save_wr = '1' then
  475.                      -- back-to-back write?
  476.                      state           <= s_write_1;
  477.                      ready_for_new   <= '1';
  478.                      got_transaction <= '0';
  479.                   end if;
  480.                   -- Although it looks right in simulation you can't go write-to-read
  481.                   -- here due to bus contention, as iob_dq_hiz takes a few ns.
  482.                end if;
  483.          
  484.             when s_write_3 =>  -- must wait tRDL, hence the extra idle state
  485.                -- back to back transaction?
  486.                if forcing_refresh = '0' and got_transaction = '1' and can_back_to_back = '1' then
  487.                   if save_wr = '1' then
  488.                      -- back-to-back write?
  489.                      state           <= s_write_1;
  490.                      ready_for_new   <= '1';
  491.                      got_transaction <= '0';
  492.                   else
  493.                     -- write-to-read switch?
  494.                     iob_dq_hiz      <= HIGH_Z;  
  495.                     state           <= s_read_1;
  496.                     ready_for_new   <= '1'; -- we will be ready for a new transaction next cycle!
  497.                     got_transaction <= '0';
  498.                   end if;
  499.                else
  500.                   iob_dq_hiz         <= not HIGH_Z;
  501.                   state              <= s_precharge;
  502.                end if;
  503.             --------------------------------
  504.             -- Closing the row off (this closes all banks)
  505.             -------------------------------------------------------------------
  506.             when s_precharge =>
  507.                state           <= s_idle_in_3;
  508.                iob_command     <= CMD_PRECHARGE;
  509.                iob_address(prefresh_cmd) <= '1'; -- A10 actually matters - it selects all banks or just one
  510.  
  511.             -------------------------------------------------------------------
  512.             -- We should never get here, but if we do then reset the memory
  513.             -------------------------------------------------------------------
  514.             when others =>
  515.                state                 <= s_startup;
  516.                ready_for_new         <= '0';
  517.                startup_refresh_count <= startup_refresh_max-to_unsigned(sdram_startup_cycles,14);
  518.          end case;
  519.  
  520.          if reset = '1' then  -- Sync reset
  521.             state                 <= s_startup;
  522.             ready_for_new         <= '0';
  523.             startup_refresh_count <= startup_refresh_max-to_unsigned(sdram_startup_cycles,14);
  524.          end if;
  525.       end if;      
  526.    end process;
  527. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement