OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [rtl/] [techmap/] [mem/] [sram8_inferred_init.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
----------------------------------------------------------------------------
2
--! @file
3
--! @copyright  Copyright 2015 GNSS Sensor Ltd. All right reserved.
4
--! @author     Sergey Khabarov
5
--! @brief      8-bits memory block with the generic data size parameter.
6
--! @details    This module absolutely similar to the 'inferred' implementation
7
--!             but it support initialization of the SRAM.
8
--!             This feature is very useful during RTL simulation so that
9
--!             current FW supports skipping of the copying FwImage state.
10
------------------------------------------------------------------------------
11
library ieee;
12
use ieee.std_logic_1164.all;
13
use ieee.numeric_std.ALL;
14
use IEEE.STD_LOGIC_TEXTIO.ALL;
15
use std.textio.all;
16
library commonlib;
17
use commonlib.types_common.all;
18
--! AMBA system bus specific library.
19
library ambalib;
20
--! AXI4 configuration constants.
21
use ambalib.types_amba4.all;
22
 
23
entity sram8_inferred_init is
24
  generic (
25
    abits     : integer := 12;
26
    byte_idx  : integer := 0;
27
    init_file : string
28
  );
29
  port (
30
    clk     : in  std_ulogic;
31
    address : in  std_logic_vector(abits-1 downto 0);
32
    rdata   : out std_logic_vector(7 downto 0);
33
    we      : in  std_logic;
34
    wdata   : in  std_logic_vector(7 downto 0)
35
  );
36
end;
37
 
38
architecture arch_sram8_inferred_init of sram8_inferred_init is
39
 
40
 
41
constant SRAM_LENGTH : integer := 2**abits;
42
-- romimage only 256 KB, but SRAM is 512 KB so we initialize one
43
-- half of sram = 32768 * 8 = 256 KB
44
constant FILE_IMAGE_LINES_TOTAL : integer := 32768;
45
type ram_type is array (0 to SRAM_LENGTH-1) of std_logic_vector(7 downto 0);
46
 
47
impure function init_ram(file_name : in string) return ram_type is
48
    file ram_file : text open read_mode is file_name;
49
    variable ram_line : line;
50
    variable temp_bv : std_logic_vector(CFG_NASTI_DATA_BITS-1 downto 0);
51
    variable temp_mem : ram_type;
52
begin
53
    for i in 0 to (FILE_IMAGE_LINES_TOTAL-1) loop
54
        readline(ram_file, ram_line);
55
        hread(ram_line, temp_bv);
56
        temp_mem(i) := temp_bv((byte_idx+1)*8-1 downto 8*byte_idx);
57
    end loop;
58
    return temp_mem;
59
end function;
60
 
61
--! @warning SIMULATION INITIALIZATION
62
signal ram : ram_type := init_ram(init_file);
63
signal adr : std_logic_vector(abits-1 downto 0);
64
 
65
begin
66
 
67
  reg : process (clk, address, wdata) begin
68
    if rising_edge(clk) then
69
      if we = '1' then
70
        ram(conv_integer(address)) <= wdata;
71
      end if;
72
      adr <= address;
73
    end if;
74
  end process;
75
 
76
  rdata <= ram(conv_integer(adr));
77
end;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.