forked from cores/microwatt
				
			litedram: Add orangecrab-85-0.2 target
Parameters are based on https://github.com/gregdavill/OrangeCrab-test-sw/blob/main/hw/OrangeCrab-bitstream.py and litex-boards orangecrab.py rtt_nom and cmd_delay are overridden for OrangeCrab, we do the same here. Generated with litedram and litex 62abf9c ("litedram_gen: Add block_until_ready port parameter to control blocking behaviour.") add2746a ("tools/litex_cli: Rename wb to bus.") Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>fpu-constant
							parent
							
								
									08021ae28e
								
							
						
					
					
						commit
						8901e84d8d
					
				@ -0,0 +1,39 @@
 | 
			
		||||
# Matt Johnston 2021
 | 
			
		||||
# Based on parameters from Greg Davill's Orangecrab-test-sw
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    "cpu":        "None",  # CPU type (ex vexriscv, serv, None)
 | 
			
		||||
    "device": "LFE5U-85F-8MG285C",
 | 
			
		||||
    "memtype":    "DDR3",      # DRAM type
 | 
			
		||||
 | 
			
		||||
    "sdram_module":    "MT41K256M16", # SDRAM modules of the board or SO-DIMM
 | 
			
		||||
    "sdram_module_nb": 2,             # Number of byte groups
 | 
			
		||||
    "sdram_rank_nb":   1,             # Number of ranks
 | 
			
		||||
    "sdram_phy":       "ECP5DDRPHY",    # Type of FPGA PHY
 | 
			
		||||
 | 
			
		||||
    # Electrical ---------------------------------------------------------------
 | 
			
		||||
    "rtt_nom": "disabled",  # Nominal termination. ("disabled" from orangecrab)
 | 
			
		||||
    "rtt_wr":  "60ohm",  # Write termination. (Default)
 | 
			
		||||
    "ron":     "34ohm",  # Output driver impedance. (Default)
 | 
			
		||||
 | 
			
		||||
    # Frequency ----------------------------------------------------------------
 | 
			
		||||
    "init_clk_freq":   24e6,
 | 
			
		||||
    "input_clk_freq":   48e6, # Input clock frequency
 | 
			
		||||
    "sys_clk_freq":     48e6, # System clock frequency (DDR_clk = 4 x sys_clk)
 | 
			
		||||
 | 
			
		||||
    # 0 if freq >64e6 else 100. https://github.com/enjoy-digital/litedram/issues/130
 | 
			
		||||
    "cmd_delay": 100,
 | 
			
		||||
 | 
			
		||||
    # Core ---------------------------------------------------------------------
 | 
			
		||||
    "cmd_buffer_depth": 16,    # Depth of the command buffer
 | 
			
		||||
 | 
			
		||||
    "dm_swap": true,
 | 
			
		||||
 | 
			
		||||
    # User Ports ---------------------------------------------------------------
 | 
			
		||||
    "user_ports": {
 | 
			
		||||
        "native_0": {
 | 
			
		||||
            "type": "native",
 | 
			
		||||
            "block_until_ready": False,
 | 
			
		||||
        },
 | 
			
		||||
    },
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,123 @@
 | 
			
		||||
library ieee;
 | 
			
		||||
use ieee.std_logic_1164.all;
 | 
			
		||||
use ieee.numeric_std.all;
 | 
			
		||||
use std.textio.all;
 | 
			
		||||
 | 
			
		||||
library work;
 | 
			
		||||
use work.wishbone_types.all;
 | 
			
		||||
use work.utils.all;
 | 
			
		||||
 | 
			
		||||
entity dram_init_mem is
 | 
			
		||||
    generic (
 | 
			
		||||
        EXTRA_PAYLOAD_FILE : string   := "";
 | 
			
		||||
        EXTRA_PAYLOAD_SIZE : integer  := 0
 | 
			
		||||
        );
 | 
			
		||||
    port (
 | 
			
		||||
        clk     : in std_ulogic;
 | 
			
		||||
        wb_in   : in wb_io_master_out;
 | 
			
		||||
        wb_out  : out wb_io_slave_out
 | 
			
		||||
      );
 | 
			
		||||
end entity dram_init_mem;
 | 
			
		||||
 | 
			
		||||
architecture rtl of dram_init_mem is
 | 
			
		||||
 | 
			
		||||
    constant INIT_RAM_SIZE    : integer := 24576;
 | 
			
		||||
    constant RND_PAYLOAD_SIZE : integer := round_up(EXTRA_PAYLOAD_SIZE, 8);
 | 
			
		||||
    constant TOTAL_RAM_SIZE   : integer := INIT_RAM_SIZE + RND_PAYLOAD_SIZE;
 | 
			
		||||
    constant INIT_RAM_ABITS   : integer := log2ceil(TOTAL_RAM_SIZE-1);
 | 
			
		||||
    constant INIT_RAM_FILE    : string := "litedram_core.init";
 | 
			
		||||
 | 
			
		||||
    type ram_t is array(0 to (TOTAL_RAM_SIZE / 4) - 1) of std_logic_vector(31 downto 0);
 | 
			
		||||
 | 
			
		||||
    -- XXX FIXME: Have a single init function called twice with
 | 
			
		||||
    -- an offset as argument
 | 
			
		||||
    procedure init_load_payload(ram: inout ram_t; filename: string) is
 | 
			
		||||
        file payload_file : text open read_mode is filename;
 | 
			
		||||
        variable ram_line : line;
 | 
			
		||||
        variable temp_word : std_logic_vector(63 downto 0);
 | 
			
		||||
    begin
 | 
			
		||||
        for i in 0 to RND_PAYLOAD_SIZE-1 loop
 | 
			
		||||
            exit when endfile(payload_file);
 | 
			
		||||
            readline(payload_file, ram_line);
 | 
			
		||||
            hread(ram_line, temp_word);
 | 
			
		||||
            ram((INIT_RAM_SIZE/4) + i*2) := temp_word(31 downto 0);
 | 
			
		||||
            ram((INIT_RAM_SIZE/4) + i*2+1) := temp_word(63 downto 32);
 | 
			
		||||
        end loop;
 | 
			
		||||
        assert endfile(payload_file) report "Payload too big !" severity failure;
 | 
			
		||||
    end procedure;
 | 
			
		||||
 | 
			
		||||
    impure function init_load_ram(name : string) return ram_t is
 | 
			
		||||
        file ram_file : text open read_mode is name;
 | 
			
		||||
        variable temp_word : std_logic_vector(63 downto 0);
 | 
			
		||||
        variable temp_ram : ram_t := (others => (others => '0'));
 | 
			
		||||
        variable ram_line : line;
 | 
			
		||||
    begin
 | 
			
		||||
        report "Payload size:" & integer'image(EXTRA_PAYLOAD_SIZE) &
 | 
			
		||||
            " rounded to:" & integer'image(RND_PAYLOAD_SIZE);
 | 
			
		||||
        report "Total RAM size:" & integer'image(TOTAL_RAM_SIZE) &
 | 
			
		||||
            " bytes using " & integer'image(INIT_RAM_ABITS) &
 | 
			
		||||
            " address bits";
 | 
			
		||||
        for i in 0 to (INIT_RAM_SIZE/8)-1 loop
 | 
			
		||||
            exit when endfile(ram_file);
 | 
			
		||||
            readline(ram_file, ram_line);
 | 
			
		||||
            hread(ram_line, temp_word);
 | 
			
		||||
            temp_ram(i*2) := temp_word(31 downto 0);
 | 
			
		||||
            temp_ram(i*2+1) := temp_word(63 downto 32);
 | 
			
		||||
        end loop;
 | 
			
		||||
        if RND_PAYLOAD_SIZE /= 0 then
 | 
			
		||||
            init_load_payload(temp_ram, EXTRA_PAYLOAD_FILE);
 | 
			
		||||
        end if;
 | 
			
		||||
        return temp_ram;
 | 
			
		||||
    end function;
 | 
			
		||||
 | 
			
		||||
    impure function init_zero return ram_t is
 | 
			
		||||
        variable temp_ram : ram_t := (others => (others => '0'));
 | 
			
		||||
    begin
 | 
			
		||||
        return temp_ram;
 | 
			
		||||
    end function;
 | 
			
		||||
 | 
			
		||||
    impure function initialize_ram(filename: string) return ram_t is
 | 
			
		||||
    begin
 | 
			
		||||
        report "Opening file " & filename;
 | 
			
		||||
        if filename'length = 0 then
 | 
			
		||||
            return init_zero;
 | 
			
		||||
        else
 | 
			
		||||
            return init_load_ram(filename);
 | 
			
		||||
        end if;
 | 
			
		||||
    end function;
 | 
			
		||||
    signal init_ram : ram_t := initialize_ram(INIT_RAM_FILE);
 | 
			
		||||
 | 
			
		||||
    attribute ram_style : string;
 | 
			
		||||
    attribute ram_style of init_ram: signal is "block";
 | 
			
		||||
 | 
			
		||||
    signal obuf : std_ulogic_vector(31 downto 0);
 | 
			
		||||
    signal oack : std_ulogic;
 | 
			
		||||
begin
 | 
			
		||||
 | 
			
		||||
    init_ram_0: process(clk)
 | 
			
		||||
        variable adr  : integer;
 | 
			
		||||
    begin
 | 
			
		||||
        if rising_edge(clk) then
 | 
			
		||||
            oack <= '0';
 | 
			
		||||
            if (wb_in.cyc and wb_in.stb) = '1' then
 | 
			
		||||
                adr := to_integer((unsigned(wb_in.adr(INIT_RAM_ABITS - 3 downto 0))));
 | 
			
		||||
                if wb_in.we = '0' then
 | 
			
		||||
                   obuf <= init_ram(adr);
 | 
			
		||||
                else
 | 
			
		||||
                    for i in 0 to 3 loop
 | 
			
		||||
                        if wb_in.sel(i) = '1' then
 | 
			
		||||
                            init_ram(adr)(((i + 1) * 8) - 1 downto i * 8) <=
 | 
			
		||||
                                wb_in.dat(((i + 1) * 8) - 1 downto i * 8);
 | 
			
		||||
                        end if;
 | 
			
		||||
                    end loop;
 | 
			
		||||
                end if;
 | 
			
		||||
                oack <= '1';
 | 
			
		||||
            end if;
 | 
			
		||||
            wb_out.ack <= oack;
 | 
			
		||||
            wb_out.dat <= obuf;
 | 
			
		||||
        end if;
 | 
			
		||||
    end process;
 | 
			
		||||
 | 
			
		||||
    wb_out.stall <= '0';
 | 
			
		||||
 | 
			
		||||
end architecture rtl;
 | 
			
		||||
											
												
													File diff suppressed because it is too large
													Load Diff
												
											
										
									
								
											
												
													File diff suppressed because one or more lines are too long
												
											
										
									
								
					Loading…
					
					
				
		Reference in New Issue