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

Subversion Repositories p9813_rgb_led_string_driver

[/] [p9813_rgb_led_string_driver/] [trunk/] [rtl/] [VHDL/] [block_ram_pack.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jclaytons
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.NUMERIC_STD.ALL;
4
use IEEE.MATH_REAL.ALL;
5
 
6
package block_ram_pack is
7
 
8
  constant INIT_FILE_DEF : string := ".\foo.txt"; -- RAM init default filename, (*not a real file*)
9
 
10
-- Component declarations not provided any more.
11
-- With VHDL '93 and newer, component declarations are allowed,
12
-- but not required.
13
--
14
-- Please to try direct instantiation instead, for example:
15
--
16
--   instance_name : entity work.entity_name(beh)
17
--
18
 
19
end block_ram_pack;
20
 
21
------------------------------------------------------------------
22
library IEEE;
23
use IEEE.STD_LOGIC_1164.ALL;
24
use IEEE.NUMERIC_STD.ALL;
25
use IEEE.MATH_REAL.ALL;
26
use IEEE.STD_LOGIC_TEXTIO.ALL;
27
 
28
library std;
29
use std.textio.all;
30
 
31
library work;
32
use work.block_ram_pack.all;
33
 
34
entity swiss_army_ram is
35
    generic(
36
      USE_BRAM  : integer := 0; -- Set to nonzero value for BRAM, zero for distributed RAM
37
      WRITETHRU : integer := 1; -- Set to nonzero value for writethrough mode
38
      USE_FILE  : integer := 0; -- Set to nonzero value to use INIT_FILE
39
      INIT_VAL  : integer := 0; -- Value used when INIT_FILE is not used
40
      INIT_SEL  : natural := 0; -- Can be used with generate loop variable to select a segment of the (larger) init file
41
      INIT_FILE : string  := INIT_FILE_DEF;  -- ASCII hexadecimal initialization file name
42
      FIL_WIDTH : integer := 32; -- 4x the number of hex digits per line in INIT_FILE
43
      ADR_WIDTH : integer := 3;
44
      DAT_WIDTH : integer := 32
45
    );
46
    port (
47
       clk_a    : in  std_logic;
48
       adr_a_i  : in  unsigned(adr_width-1 downto 0);
49
       we_a_i   : in  std_logic;
50
       en_a_i   : in  std_logic;
51
       dat_a_i  : in  unsigned(dat_width-1 downto 0);
52
       dat_a_o  : out unsigned(dat_width-1 downto 0);
53
 
54
       clk_b    : in  std_logic;
55
       adr_b_i  : in  unsigned(adr_width-1 downto 0);
56
       we_b_i   : in  std_logic;
57
       en_b_i   : in  std_logic;
58
       dat_b_i  : in  unsigned(dat_width-1 downto 0);
59
       dat_b_o  : out unsigned(dat_width-1 downto 0)
60
    );
61
end swiss_army_ram;
62
 
63
architecture beh of swiss_army_ram is
64
 
65
  -- Constants
66
 
67
  -- Functions & associated types
68
    type ram_array is array(0 to 2**ADR_WIDTH-1) of unsigned(DAT_WIDTH-1 downto 0);
69
 
70
    impure function ram_file_init (INIT_FILE : in string) return ram_array is
71
      --FILE F1 : text is in INIT_FILE; -- VHDL '87 syntax
72
      --FILE F1 : text open read_mode is INIT_FILE; -- VHDL '93 syntax
73
      FILE F1 : text;
74
      variable ligne : line;
75
      variable rambo : ram_array;
76
      variable vect  : std_ulogic_vector(FIL_WIDTH-1 downto 0);
77
      variable uvect : unsigned(DAT_WIDTH-1 downto 0);
78
      variable I,J   : integer;
79
    begin
80
      -- If using the file, then index through the file to the desired selection
81
      if (USE_FILE/=0) then
82
        file_open(F1,INIT_FILE,read_mode);
83
        if (INIT_SEL>0) then
84
          for I in 0 to INIT_SEL-1 loop
85
            for J in ram_array'range loop
86
              readline(F1,ligne);
87
            end loop;
88
          end loop;
89
        end if;
90
      end if;
91
      -- Obtain the desired initialization values
92
      for I in ram_array'range loop
93
        if (USE_FILE/=0) then
94
          readline(F1,ligne);
95
          hread(ligne,vect);
96
          --IEEE.STD_LOGIC_TEXTIO.HREAD(ligne,vect);
97
          for J in uvect'range loop
98
            if (vect(J)='1') then
99
              uvect(J):='1';
100
            else
101
              uvect(J):='0';
102
            end if;
103
          end loop;
104
        else
105
          uvect := to_unsigned(INIT_VAL,DAT_WIDTH);
106
        end if;
107
        rambo(I):=uvect;
108
      end loop;
109
      if (USE_FILE/=0) then
110
        file_close(F1);
111
      end if;
112
      return rambo;
113
    end function;
114
 
115
  -- Variable Declarations
116
  shared variable ram1 : ram_array := ram_file_init(INIT_FILE);
117
 
118
  -- Signal Declarations
119
  signal dat_a_wt : unsigned(DAT_WIDTH-1 downto 0);
120
  signal dat_b_wt : unsigned(DAT_WIDTH-1 downto 0);
121
  signal dat_a_l  : unsigned(DAT_WIDTH-1 downto 0);
122
  signal dat_b_l  : unsigned(DAT_WIDTH-1 downto 0);
123
 
124
begin
125
 
126
process (clk_a)
127
variable i : integer;
128
begin
129
  if (clk_a'event and clk_a='1') then
130
    if (en_a_i='1') then
131
      dat_a_l <= ram1(to_integer(adr_a_i));
132
      if (we_a_i='1') then
133
        ram1(to_integer(adr_a_i)) := dat_a_i;
134
        dat_a_wt <= dat_a_i;
135
      else
136
        dat_a_wt <= ram1(to_integer(adr_a_i));
137
      end if;
138
    end if;
139
  end if;
140
end process;
141
dat_a_o <= ram1(to_integer(adr_a_i)) when USE_BRAM=0   else
142
           dat_a_l                   when WRITETHRU=0  else
143
           dat_a_wt;
144
 
145
process (clk_b)
146
variable i : integer;
147
begin
148
  if (clk_b'event and clk_b='1') then
149
    if (en_b_i='1') then
150
      dat_b_l <= ram1(to_integer(adr_b_i));
151
      if (we_b_i='1') then
152
        ram1(to_integer(adr_b_i)) := dat_b_i;
153
        dat_b_wt <= dat_b_i;
154
      end if;
155
      dat_b_wt <= ram1(to_integer(adr_b_i));
156
    end if;
157
  end if;
158
end process;
159
dat_b_o <= ram1(to_integer(adr_b_i)) when USE_BRAM=0  else
160
           dat_b_l                   when WRITETHRU=0 else
161
           dat_b_wt;
162
 
163
end beh;
164
 

powered by: WebSVN 2.1.0

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